A DTR Questionnaire may define a question and the logic to answer it from the EHR, yet the form will still be blank if the client fetches the wrong resources, lacks access, or evaluates the logic with the wrong context. Da Vinci DTR v2.2.0 describes a concrete retrieval path for clients that execute CQL directly. This guide focuses on that path: identify required data, query narrowly, evaluate the expression, and show the user what remains unresolved.
Start with the Questionnaire and its Library dependencies
In a standard DTR form, the Questionnaire can use launchContext and variable extensions together with initialExpression, contextExpression, calculatedExpression, or candidateExpression. A cqf-library reference connects the form to Library logic. The client should resolve those references in the returned questionnaire package before attempting to fill an answer. A visible question alone does not tell an implementer which FHIR resources the expression needs.
When a DTR client executes CQL directly, the guide requires it to retrieve the FHIR resources specified by a Library dataRequirement. The guide illustrates a Condition requirement with a code filter and value set. Build a dependency inventory for each form: expression, Library version, resource type, applicable filters, launch context, and the Questionnaire item that consumes the result. This is a testable data contract, not a request to search the entire chart.
- Resolve the Questionnaire and referenced Libraries from the same package.
- List each Library dataRequirement and the items that depend on it.
- Record the patient, order, and other launch context used for evaluation.
Fetch only the data needed for the current evaluation
DTR says queries should minimize retrieval of information unnecessary to answer the relevant questions. A medication question about active therapy, for example, should not automatically fetch every historical medication. The client may retrieve data as needed or use a broader strategy, but it should explain why each query and scope is needed. For a SMART app, the launch access token governs what it can read; the client must account for permissions that leave some required data unavailable.
Do not translate an empty query result into a clinical “no.” The DTR specification says a query with no results is not itself a failure, and it notes that data may be absent because access is restricted. Keep separate states for a value found, a successful query with no matching data, a permission or retrieval failure, and an expression error. That separation tells staff whether to review the chart, enter a missing answer, or repair the integration.
- Apply the Library filters and current patient context to each FHIR query.
- Keep query result, access failure, and expression failure distinct.
- Preserve the source resource and evaluation time for a populated answer.
Re-evaluate as the form reveals new dependencies
The DTR client must attempt population of enabled items before displaying the draft response. An answer may enable another item whose expression needs more data, so the guide requires iteration until the form reaches a steady state. If dependencies oscillate and no steady state is possible, the Questionnaire is erroneous and the user must be told. This is a useful validation case for payer-authored form logic.
Adaptive Questionnaires expose questions incrementally through $next-question. DTR requires the client to populate newly available questions after each call. Some Libraries may appear only after a later question is returned. Treat each response as a new dependency checkpoint, and cache evaluated results only while their context and source data remain valid. A previous prefill is not a guarantee that a newly exposed question can be answered.
Test the retrieval boundary before production use
Create fixtures for a matching resource, a nonmatching code, an empty but successful search, a denied read, and a malformed expression. Add an adaptive form in which the second question introduces a new Library. Verify the client fetches that requirement at the right step, retains the raw source and calculated answer, and leaves unresolved answers available for review rather than fabricating a negative response.
Review the final QuestionnaireResponse against the request context and source record. If a form is resumed, DTR has specific rules for re-running CQL and protecting manual or override answers; test that separately from first-pass retrieval. The operational goal is a form whose answers are traceable and whose blanks have a clear reason, so an authorization team can finish the case without guessing what the automation did.
- Test found, empty, inaccessible, and invalid-expression outcomes.
- Exercise standard and adaptive forms with changing dependencies.
- Show reviewers which answers were populated and which remain unresolved.