Skip to content

ID-177: Verify all required questions are answered in $next-question requests - #90

Open
abhinandan2012 wants to merge 1 commit into
inferno-framework:support_v2.2.0from
abhinandan2012:ID-177-next-question-required-questions-answered
Open

ID-177: Verify all required questions are answered in $next-question requests#90
abhinandan2012 wants to merge 1 commit into
inferno-framework:support_v2.2.0from
abhinandan2012:ID-177-next-question-required-questions-answered

Conversation

@abhinandan2012

@abhinandan2012 abhinandan2012 commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Partial implementation of requirement spec-146: the DTR client must not indicate that the user is ready for the next question until the answers in the current QuestionnaireResponse pass validation rules. This adds a check that every required question in the QuestionnaireResponse sent to $next-question has been answered.

Changes

  • Factored the QuestionnaireResponse completeness logic out of the v2.2.0 $next-question server simulation into a new shared module, DaVinciDTRTestKit::QuestionnaireResponseCompleteness (lib/davinci_dtr_test_kit/cross_suite/v2.2.0/questionnaire_response_completeness.rb). It exposes contained_questionnaire, questionnaire_response_complete? and unanswered_required_link_ids.

  • MockPayer::FullEHRV220NextQuestionEndpoint now includes the module rather than carrying its own copy of the logic. Behavior is unchanged, including treating a boolean false as a valid answer and only marking a QuestionnaireResponse as completed when no new questions were disclosed.

  • DTRFullEHRV220NextQuestionRequestValidationTest now uses the same module to verify each $next-question request body. The QuestionnaireResponse is taken from either the Parameters wrapper or a bare QuestionnaireResponse body, and the required items in its contained Questionnaire are checked against the answers present. Unanswered required questions are reported per request:

    (Request 2) All required questions must be answered before requesting the next question.
    No answer found for required item(s): `PBD.1`, `PBD.2`, and `LOC.1`.
    

    A QuestionnaireResponse with no contained Questionnaire reports that the check could not be
    performed. The test declares verifies_requirements 'hl7.fhir.us.davinci-dtr_2.2.0@spec-146'.

Note that enableWhen conditions are not taken into account, so a required question is expected to
be answered even when its enabling condition is not met. This matches the existing behavior of the
server simulation and is documented in the module and in the test description.

Tests

New spec spec/davinci_dtr_test_kit/dtr_full_ehr_v220_next_question_request_validation_test_spec.rb
covers the initial request with no questions disclosed yet, a fully answered form, an unanswered
required question, request numbering across multiple requests, a bare QuestionnaireResponse body, a
required question nested under an answered question, a missing contained Questionnaire, unanswered
optional questions, and a boolean false answer.

bundle exec rspec                # 318 examples, 0 failures
bundle exec rubocop lib spec     # 229 files inspected, no offenses detected

Requirements coverage is unchanged (bundle exec inferno requirements check_coverage dtr_full_ehr_v220
reports the coverage CSV is up to date). spec-146 appears in the existing warning list of requirements
not present in the suite's requirement sets, because requirement_sets is still commented out in
dtr_full_ehr_suite.rb for the v2.2.0 suite.

Test IDs

  • Inferno test: dtr_full_ehr_v220_nq_request_validation, shown as 2.2.3.01 Next Question request is valid
    • Full ID: dtr_full_ehr_v220-dtr_full_ehr_basic_workflows-dtr_full_ehr_v220_workflow_adaptive-Group03-dtr_full_ehr_v220_nq_request_validation
  • Group to run: dtr_full_ehr_v220_workflow_adaptive, shown as 2.2 Adaptive Questionnaire
  • Unit tests:
    • bundle exec rspec spec/davinci_dtr_test_kit/dtr_full_ehr_v220_next_question_request_validation_test_spec.rb
    • bundle exec rspec spec/davinci_dtr_test_kit/full_ehr_v220_next_question_endpoint_spec.rb

Where to verify in the UI

Da Vinci DTR Client Test Suite v2.2.0 -> 2 Basic Workflows -> 2.2 Adaptive Questionnaire ->
2.2.3 $next-question -> 2.2.3.01 Next Question request is valid -> MESSAGES tab. The new
check appears as an error message prefixed with the request number. The REQUESTS tab of the same
test shows the $next-question bodies the messages refer to.

Note that with hand made request bodies this test also reports profile conformance errors, so the
result is red either way. The item to verify is the presence or absence of the
"All required questions must be answered" message.

UI testing steps

  1. Start a session on the Da Vinci DTR Client Test Suite v2.2.0 with the SMART Backend Services
    client type, and select the "Run Against the Client Simulation Suite" preset so the Client Id is
    set to demo.

  2. Run 1 Client Registration and complete the attestation so the Client Id is available to the
    rest of the session.

  3. Select 2.2 Adaptive Questionnaire and click RUN TESTS. The Questionnaires wait dialog appears.

  4. Send a $questionnaire-package request followed by two $next-question requests, where the second
    one repeats the form returned by the first without answering the questions that were disclosed:

    CID=demo
    BASE="http://localhost:4567/custom/dtr_full_ehr_v220/fhir/Questionnaire"
    curl -s -X POST "$BASE/\$questionnaire-package?session_path=$CID" \
      -H 'Content-Type: application/fhir+json' \
      --data-binary @spec/fixtures/questionnaire_package_input_params_conformant.json > /dev/null
    curl -s -X POST "$BASE/\$next-question?session_path=$CID" \
      -H 'Content-Type: application/fhir+json' \
      --data-binary @spec/fixtures/next_question_initial_input_params_conformant.json > nq1.json
    curl -s -X POST "$BASE/\$next-question?session_path=$CID" \
      -H 'Content-Type: application/fhir+json' --data-binary @nq1.json > /dev/null

    The session_path query parameter identifies the session without an access token. It also causes
    the existing request URL check to report a wrong URL, which is expected with this shortcut.

  5. Click the continuation link in the wait dialog, then the rendering attestation link.

  6. Open 2.2.3.01 and check the MESSAGES tab. Request 2 reports PBD.1, PBD.2 and LOC.1 as
    unanswered required questions.

  7. To confirm there are no false positives, repeat steps 1 to 6 in a new session, but add answers for
    PBD.1 and PBD.2 under the PBD group and LOC.1 under the LOC group in the third request
    body. The message is no longer reported.

Running the client and server suites against each other

The paired presets let the Client Simulator Suite drive the Client Test Suite, which exercises the
passing path of this check without a real client, because the simulated client answers each disclosed
question before requesting the next one.

  1. Session A: Da Vinci DTR Client Test Suite v2.2.0, SMART Backend Services client type, preset
    "Run Against the Client Simulation Suite". Run 1 Client Registration, then select
    2.2 Adaptive Questionnaire and click RUN TESTS so Inferno waits for requests.
  2. Session B: Da Vinci DTR Client Simulator Suite v2.2.0, preset "Run Against the DTR Client Suite".
    The preset points the Payer FHIR Server Base Url at
    <base_url>/custom/dtr_full_ehr_v220/fhir and uses client id demo. Run 1 Backend Services
    to obtain a token, then run 2 Payer serves Questionnaires, which sends the
    $questionnaire-package and $next-question requests to session A.
  3. Return to session A, click through the attestation dialogs, and review 2.2.3.01. No
    "All required questions must be answered" message is reported for these requests.

UI proof

Test 2.2.3.01 reporting the unanswered required questions for the second $next-question request:

Next Question request is valid reporting unanswered required questions

Location of the test in the Adaptive Questionnaire group:

Location of test 2.2.3.01 within the Adaptive Questionnaire group

The same test for a flow where the disclosed questions were answered. Only profile conformance errors
remain and the completeness message is not present:

Next Question request is valid with all required questions answered

@abhinandan2012
abhinandan2012 force-pushed the ID-177-next-question-required-questions-answered branch from 24add47 to dcb2551 Compare July 28, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant