Skip to main content

Questionnaire responses

Use createQuestionnaireResponseWithObservations() to submit one QuestionnaireResponse together with the Observations produced by that questionnaire. The SDK sends them in a single FHIR transaction, so the related resources are handled as one submission.

Prepare the resources​

Pass a completed QuestionnaireResponse resource and an array of Observation resources. Build the resources from the user's answers and the measurement values your application has collected. The QuestionnaireResponse and each Observation must use the resource fields and coding expected by the target project.

See the FHIR QuestionnaireResponse reference for the response structure and the FHIR Observation reference for observation structure.

Save the response and observations together​

const transactionResponse = await client.createQuestionnaireResponseWithObservations(
questionnaireResponse,
observations,
);

showSubmissionComplete(transactionResponse);

In this example, questionnaireResponse is the completed response resource, observations contains the associated Observation resources, and showSubmissionComplete() is application UI code. The observations array can be empty when the questionnaire does not produce observations.

Handle the transaction result​

The method returns the server's transaction Bundle response. Use that response to confirm the submission and capture the returned resource entries if the application needs their server-assigned references. If the transaction fails, handle it as a failed questionnaire submission and let the user review or retry according to your app's workflow.

Keep the QuestionnaireResponse and its associated observations together when they represent one questionnaire submission. For standalone measurement saves and their typed payloads, see Measurements and health data.