All notebooks
Populate Questionnaire with
Populate QuestionnaireResponse using logical reference
Description
13 cells · updated Jul 8, 2025
This is a read-only view. Responses shown were saved when the notebook was published —
open it in your own Aidbox to run the cells against live data.
Create a Patient with two identifiers
REST
Send
Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
PUT /Patient/e226f188-ea26-4a60-9375-8a8e625cfc16
content-type: application/yaml
name:
- given:
- Morgan
family: James
identifier:
- value: '938111'
system: passport
- value: '818811'
system: driver-license
id: >-
e226f188-ea26-4a60-9375-8a8e625cfc16
resourceType: Patient
Response:
Body
Status:
200
name:
- given: [Morgan]
family: James
identifier:
- {value: '938111', system: passport}
- {value: '818811', system: driver-license}
id: e226f188-ea26-4a60-9375-8a8e625cfc16
resourceType: Patient
meta: {lastUpdated: '2025-07-08T13:11:34.551776Z', createdAt: '2025-07-08T13:11:34.551776Z', versionId: '930'}
Create a Questionnaire with the item prefilled with subject's name
REST
Send
Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
PUT /Questionnaire/f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39
content-type: application/yaml
url: https://example.com/forms/patient-populate
item:
- text: Given
type: string
linkId: uT1ylWqY
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression:
language: text/fhirpath
expression: '%subject.name.given'
- text: Family
type: string
linkId: OOh83OEj
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression:
language: text/fhirpath
expression: '%subject.name.family'
title: Patient Populate
status: draft
id: >-
f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39
resourceType: Questionnaire
Response:
Body
Status:
200
url: https://example.com/forms/patient-populate
item:
- text: Given
type: string
linkId: uT1ylWqY
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression: {language: text/fhirpath, expression: '%subject.name.given'}
- text: Family
type: string
linkId: OOh83OEj
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression: {language: text/fhirpath, expression: '%subject.name.family'}
title: Patient Populate
status: draft
id: f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39
resourceType: Questionnaire
meta: {lastUpdated: '2025-07-08T14:15:24.237450Z', createdAt: '2025-07-08T13:14:52.687261Z', versionId: '1112'}
Populate Questionnaire with $populate
Send identifier in subject parameter. It's important to send local: true
REST
Send
Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /fhir/Questionnaire/f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39/$populate
content-type: application/yaml
resourceType: Parameters
parameter:
- name: subject
valueReference:
identifier:
system: passport
value: '938111'
- name: local
valueBoolean: true
Response:
Body
Status:
200
resourceType: Parameters
parameter:
- name: response
resource:
resourceType: QuestionnaireResponse
questionnaire: https://example.com/forms/patient-populate
status: in-progress
subject:
identifier: {system: passport, value: '938111'}
item:
- linkId: uT1ylWqY
text: Given
answer:
- {valueString: Morgan}
- linkId: OOh83OEj
text: Family
answer:
- {valueString: James}
QuestionnaireResponse items were filled with the patient's name
Populate Questionnaire with Encounter data
We need to create Encounter with some identifier and update the Questionnaire
REST
Send
Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
PUT /Encounter/b99f4913-9c43-4ce8-a860-b9e418fbe47d
content-type: application/yaml
class:
code: example
system: http://example.com
period:
start: '2025-12-29T13:30:00.000Z'
status: planned
identifier:
- value: my-first-encounter
system: external-system-id
id: b99f4913-9c43-4ce8-a860-b9e418fbe47d
resourceType: Encounter
Response:
Body
Status:
200
class: {code: example, system: 'http://example.com'}
period: {start: '2025-12-29T13:30:00.000Z'}
status: planned
identifier:
- {value: my-first-encounter, system: external-system-id}
id: b99f4913-9c43-4ce8-a860-b9e418fbe47d
resourceType: Encounter
meta: {lastUpdated: '2025-07-08T14:32:49.677692Z', createdAt: '2025-07-08T13:52:44.690456Z', versionId: '1135'}
Update QuestionnaireResponse
Add a new group with populate context where we get full Encounter resource by identifier. Then add item inside this group to populate Encounter.period.start
REST
Send
Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
PUT /Questionnaire/f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39
content-type: application/yaml
url: https://example.com/forms/patient-populate
item:
- text: Given
type: string
linkId: uT1ylWqY
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression:
language: text/fhirpath
expression: '%subject.name.given'
- text: Family
type: string
linkId: OOh83OEj
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression:
language: text/fhirpath
expression: '%subject.name.family'
- item:
- text: String Input
type: string
linkId: MGJEtt5f
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression:
language: text/fhirpath
expression: '%encounter.identifier.value'
- text: Start date
type: dateTime
linkId: SvHSMZvv
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression:
language: text/fhirpath
expression: '%EncounterFull.period.start'
text: Encounter
type: group
linkId: encounter
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemPopulationContext
value:
Expression:
name: EncounterFull
language: application/x-fhir-query
expression: /Encounter?identifier={{%encounter.identifier.value}}
title: Patient Populate
status: draft
extension:
- url: >-
http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext
extension:
- url: name
value:
Coding:
code: encounter
system: http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext
- url: type
value:
code: Encounter
id: >-
f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39
resourceType: Questionnaire
Response:
Body
Status:
200
url: https://example.com/forms/patient-populate
item:
- text: Given
type: string
linkId: uT1ylWqY
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression: {language: text/fhirpath, expression: '%subject.name.given'}
- text: Family
type: string
linkId: OOh83OEj
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression: {language: text/fhirpath, expression: '%subject.name.family'}
- item:
- text: String Input
type: string
linkId: MGJEtt5f
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression: {language: text/fhirpath, expression: '%encounter.identifier.value'}
- text: Start date
type: dateTime
linkId: SvHSMZvv
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression
value:
Expression: {language: text/fhirpath, expression: '%EncounterFull.period.start'}
text: Encounter
type: group
linkId: encounter
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemPopulationContext
value:
Expression: {name: EncounterFull, language: application/x-fhir-query, expression: '/Encounter?identifier={{%encounter.identifier.value}}'}
title: Patient Populate
status: draft
extension:
- url: http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext
extension:
- url: name
value:
Coding: {code: encounter, system: 'http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext'}
- url: type
value: {code: Encounter}
id: f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39
resourceType: Questionnaire
meta: {lastUpdated: '2025-07-08T14:31:29.449617Z', createdAt: '2025-07-08T13:14:52.687261Z', versionId: '1126'}
Other incoming parameters goes to context
REST
Send
Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /fhir/Questionnaire/f4e90dc4-facd-4bb5-be4e-ff9b0a48ec39/$populate
content-type: application/yaml
resourceType: Parameters
parameter:
- name: subject
valueReference:
identifier:
system: passport
value: '938111'
- name: local
valueBoolean: true
- name: context
part:
- name: name
valueString: encounter
- name: content
valueReference:
identifier:
value: my-first-encounter
system: external-system-id
Response:
Body
Status:
200
resourceType: Parameters
parameter:
- name: response
resource:
resourceType: QuestionnaireResponse
questionnaire: https://example.com/forms/patient-populate
status: in-progress
subject:
identifier: {system: passport, value: '938111'}
encounter:
identifier: {value: my-first-encounter, system: external-system-id}
item:
- linkId: uT1ylWqY
text: Given
answer:
- {valueString: Morgan}
- linkId: OOh83OEj
text: Family
answer:
- {valueString: James}
- linkId: encounter
text: Encounter
item:
- linkId: MGJEtt5f
text: String Input
answer:
- {valueString: my-first-encounter}
- linkId: SvHSMZvv
text: Start date
answer:
- {valueDateTime: '2025-12-29T13:30:00'}