Stream: questionnaire
Topic: answerExpression and a valueset
Diane (Dec 09 2021 at 03:06):
I am trying to do something similar to Brian's @Brian Postlethwaite "explanation.7 Options from a coding expanded using a fhir query, and a fhirpath expression. Useful when the expression is effected by other values on the form" at https://sqlonfhir-r4.azurewebsites.net/fhir/Questionnaire/coding-sampler
The example uses https://r4.ontoserver.csiro.au/fhir terminology server, but do I need to use one? If I want to get the valueset for my answer expression from value set http://hl7.org/fhir/ValueSet/languages can I just expand it in the expression without the ontoserver? Or does expansion require a terminology server in order to call the $expand operation?
<extension url="http://hl7.org/fhir/StructureDefinition/variable" >
<valueExpression >
<description value="Variable to hold the results of the expansion"/>
<name value="vsListOfLanguages"/>
<language value="application/x-fhir-query"/>
<expression value="$expand?url=http://hl7.org/fhir/ValueSet/languages"/>
</valueExpression>
</extension>
Alternately, if I have used a contained and expanded valueset (like the contained valueset #pre-expanded at https://sqlonfhir-r4.azurewebsites.net/fhir/Questionnaire/coding-sampler), how can I include that in my answer expression?
Do I create a variable first? If yes, would this be the syntax? I don't know how to get the contained valueset
#pre-expanded into the variable.
<extension url="http://hl7.org/fhir/StructureDefinition/variable" >
<valueExpression >
<description value="Variable for #pre-expanded valueset "/>
<name value="vsPreExpanded"/>
<language value="text/fhirpath"/>
<expression value="#pre-expanded"/>
</valueExpression>
</extension>
Or do I skip the variable creation? Can I refer to the #pre-expanded contained valueset in the answerExpression without putting it into a variable?
<extension url="http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression" >
<valueExpression >
<description value="select the coded values from the expansion results in the above expression"/>
<name value="ListOfLanguages"/>
<language value="text/fhirpath"/>
<expression value="#pre-expanded.expansion.contains"/>
</valueExpression>
</extension>
Brian Postlethwaite (Dec 09 2021 at 05:13):
That's an option I hadn't considered, but I believe you should be able to reference that through $questionnaire.contained[0].expansion....
Diane (Dec 09 2021 at 23:50):
Yes, I think that is a better way to reference the contained resource. It seems like it should work.
My answerExpression is iif(%resource.descendants().where(linkId = 'Q1').answer.value.exists(), %resource.descendants().where(linkId = 'Q1').answer.value, %resource.contained[0].expansion.contains) but this doesn't work
%resource.contained[0].expansion.contains by itself doesn't work either . No drop down appears with these values.
I am trying to prepopulate from Q1 if it exists; otherwise show the contained expanded valueset.
I sent an email to LHC Forms support (Paul) in case it has something to do with LHC Forms specifically. Maybe the answerExpression is not compatible with expanded contained valuesets in LHC forms? Or in the SDC standard?
If that is the case, my only option is to use a terminology server with the $expand operation? How do I pick a terminology server?
Brian Postlethwaite (Dec 10 2021 at 06:09):
might need to check on if %resource or %questionnaire is the appropriate thing to connect to (not sure on the context of the path execution you've got there, if its on the QR, then %questionaire is the right one.)
Paul Lynch (Dec 10 2021 at 15:38):
I think the issue is %questionnaire.contained is needed instead of %resource.contained.
Diane (Dec 13 2021 at 07:51):
questionnaire.contained[0].expansion.contains is what worked. Thanks!
Before posting, I tried:
%resource.contained...
resource.contained...
%Questionnaire.contained...
Questionnaire.contained...
%questionnaire.contained...
In the fhirpath testers (Brian's and fhirpath js):
Questionnaire.title works but not questionnaire.title
Questionnaire.contained[0].expansion.contains works but not questionnaire.contained[0].expansion.contains
%resource.contained[0].expansion.contains works in Brian's fhirpath tester, but not fhirpath js tester
So why is the answerExpression using questionnaire... when the fhirpath testers use Questionnaire...? Do the answerExpressions only use lowercase versions of the resource name for the fhirpath expression? This is very confusing.
Paul Lynch (Dec 13 2021 at 16:46):
I am assume that you mean for the fhirpath.js tester, the demo at https://hl7.github.io/fhirpath.js/. That demo won't have %questionnaire defined, because %questionnaire is only set by a form renderer when a user is filling out a Questionnaire. FHIRPath can be used in a lot of contexts in which there isn't a Questionnaire (or even a resource), so the demo only defines things like %context that are defined in the FHIRPath specification. I suppose it would be helpful if the demo listed the variables that are defined.
Diane (Dec 13 2021 at 19:59):
Yes, the fhirpath demo. When should I be using questionnaire (lowercase q) vs. Questionnaire in my answerExpressions?
Paul Lynch (Dec 13 2021 at 20:02):
Starting an expression with a resource name like "Questionnaire" means that the object in %context should be checked to make sure it is a resource of that type. In nearly all cases in a QuestionnaireResponse (all that I can think of), %context will not have a Questionnaire, so it would probably not be useful to start it that way.
Diane (Dec 13 2021 at 20:14):
OK. So what does questionnaire (not the resource name "Questionnaire") do? I am trying to use an included value set for the answerExpression, so I need to refer to this included valueset. How does the expression know what %context to use? Why does questionnaire.contained[0].expansion.contains work? Why doesn't %questionnaire.contained[0]... work?
Paul Lynch (Dec 13 2021 at 20:15):
Do you mean %questionnaire? "questionnaire.contained..." (without the %) would not work, I don't think.
Diane (Dec 13 2021 at 20:44):
Never mind. %questionnaire is correct. I understand why. I was confusing myself. And you. :frown:
Paul Lynch (Dec 13 2021 at 20:45):
No problem.
Brian Postlethwaite (Dec 14 2021 at 22:48):
Yeah, the fhirpath tester doesn't have a way to define variables, but have been thinking how to do that.
Brian Postlethwaite (Dec 14 2021 at 22:48):
(UI suggestions welcomed there)
Last updated: Apr 12 2022 at 19:14 UTC