Stream: questionnaire
Topic: Questionnaire population for a choice/code
Corey Wen (Jun 02 2021 at 17:02):
I am trying to prepopulate a questionnaire using fhirpath expression to convert a string to a code, specifically populating a patient's gender.
In the example on "https://lhcforms.nlm.nih.gov/lforms-fhir-app/" for "US Surgeon General family health portrait [54127-6]" the resource Questionnaire has an initialExpression for Gender that uses %patient.gender, but this does not populate the questionnaire.
I found this post "https://chat.fhir.org/#narrow/stream/179266-fhirpath/topic/data.20extraction.20for.20Questionnaires" which is relevant but I was not able to find what was being discussed in the post in "http://hl7.org/fhirpath/" or "https://www.hl7.org/fhir/fhirpath.html"
I found %terminologies.subsumes(system, coded1, coded2, params) : code
but wasn't sure if that could be used for this purpose.
How can I populate the questionnaire for choice types?
Lloyd McKenzie (Jun 02 2021 at 17:26):
@Paul Lynch
Paul Lynch (Jun 02 2021 at 18:09):
Until FHIR#29324 is addressed, there isn't a way to create a Coding. However, if you have a Coding somewhere in the Questionnaire, you can use iif statements to pick the Coding you want and assign it via initialExpression.
Paul Lynch (Jun 02 2021 at 18:17):
Example (with calculatedExpression setting a choice item): https://lforms-fhir.nlm.nih.gov/baseR4/Questionnaire/88121-9-x?_format=json
Corey Wen (Jun 03 2021 at 20:55):
I tried following the example but wasn't able to get very far. I read the snippet about iif but still am not sure if I'm following the syntax correctly.
I have the following under the extension for the choice for gender.
{
"type": "choice",
"code": [
{
"code": "LL3324-2",
"display": "Sex assigned at birth",
"system": "http://loinc.org"
}
],
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "drop-down",
"display": "Drop down"
}
],
"text": "Drop down"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "thisItem",
"language": "text/fhirpath",
"expression": "%questionnaire.item.where(linkId = '/LL3324-2')"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "maleCoding",
"language": "text/fhirpath",
"expression": "%thisItem.answerOption.valueCoding.where(code='LA2-8')"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/variable",
"valueExpression": {
"name": "femaleCoding",
"language": "text/fhirpath",
"expression": "%thisItem.answerOption.valueCoding.where(code='LA3-6')"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-calculatedExpression",
"valueExpression": {
"description": "Birthsex from patient resource",
"language": "text/fhirpath",
"expression": "iif(%patient.gender='male', %maleCoding, %femaleCoding)"
}
}
],
"required": false,
"linkId": "/LL3324-2",
"text": "Sex assigned at birth",
"answerOption": [
{
"valueCoding": {
"code": "LA2-8",
"display": "Male"
}
},
{
"valueCoding": {
"code": "LA3-6",
"display": "Female"
}
},
{
"valueCoding": {
"code": "LA4489-6",
"display": "Unknown"
}
}
]
},
Paul Lynch (Jun 03 2021 at 23:44):
That looks good, as far as I can see. Do you have "patient" defined from a launchContext extension somewhere?
Corey Wen (Jun 04 2021 at 14:26):
Yes, I have the following, however the field for gender is not being prepopulated and there are no error messages.
Is the syntax for the comparison "$patient.gender = 'male'
and the syntax for the iif correct?
iif(%patient.gender='male', %maleCoding, %femaleCoding)
Also, is there a way to hardcode a initialExpression for a choice type? It may give me more insight.
launchContext for Patient under extension
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-launchContext",
"extension": [
{
"url": "name",
"valueId": "patient"
},
{
"url": "type",
"valueCode": "Patient"
},
{
"url": "descripton",
"valueString": "For filling in patient information as the subject for the form"
}
]
}
Last updated: Apr 12 2022 at 19:14 UTC