Stream: questionnaire
Topic: answerExpression and answerOption on same item workaround
Diane (Jan 05 2022 at 06:53):
For many of our choice questions, we want:
If possible, populate the answer for the user using the answer from the parent questionnaire response
If the answer from the parent questionnaire response is not available, then show a list of choices in a dropdown for the user to select from
This seems to be extremely difficult .
I can't populate the answer using the value from the parent questionnaire response with answerExpression and use answerOption to set the dropdown values because I can't have both answerExpression and answerOption on the same item.
If I try to populate the answer using initialExpression, it doesn't seem to work when the question type is choice.
If I change the question type to string, then I can't use the answerOption.
Workaround is to use a choice question type then a conditional fhirpath expression in the answerExpression so that if the answer in the parent questionnaire response exists() then populate with it, otherwise, show the contained valueset to the user.
Now I have a new problem where our HAPI server not liking the contained valueset (issue raised in HAPI stream).
Are there any other suggestions to accomplish what we need?
Also, in some of the FHIR validators, I am getting error messages about loading a contained valueset, but never actually "using" it. I guess calling it conditionally in the answerExpression doesn't count as actually using the contained resource. So, is this going to end up being a problem for the IG?
Tilo Christ (Jan 05 2022 at 10:10):
I'm not sure what you mean by a "parent" response?
But at least initialExpression on a choice type is specified and should work, see this example from @Paul Lynch 's collection: https://github.com/lhncbc/lforms/blob/master/test/data/R4/questionnaire-initialx.json
Paul Lynch (Jan 05 2022 at 14:40):
Diane said:
For many of our choice questions, we want:
If possible, populate the answer for the user using the answer from the parent questionnaire response
If the answer from the parent questionnaire response is not available, then show a list of choices in a dropdown for the user to select from
That sounds like a combination of initialExpression (for the answer) and answerExpression (for the answer list).
Diane said:
I can't populate the answer using the value from the parent questionnaire response with answerExpression
answerExpression does not populate an answer, but the answer list (answer options). Perhaps It would be less confusing if it were called answerOptionExpression.
Diane said:
Also, in some of the FHIR validators, I am getting error messages about loading a contained valueset, but never actually "using" it. I guess calling it conditionally in the answerExpression doesn't count as actually using the contained resource. So, is this going to end up being a problem for the IG?
@Lloyd McKenzie ?
Lloyd McKenzie (Jan 05 2022 at 19:03):
Agree w/ Paul - you use initialExpression for population, never answerExpression. answerExpression is used to populate the list of dropdown options and is mutually exclusive w/ answerOption.
The current invariant in R4 around use of contained resources can detect us in expressions, so in SDC we introduced an extension to accommodate - https://build.fhir.org/ig/HL7/sdc/StructureDefinition-sdc-referencesContained.html. You can see some examples of its use in the CI build.
Diane (Jan 06 2022 at 07:16):
I agree that answerExpression is designed for the list of dropdown options. In the SDC IG, it is clearly explained "An expression (FHIRPath, CQL or FHIR Query) that resolves to a list of permitted answers for the question item or that establishes context for a group item. The user may select from among the list to choose answers for the question.". But, I have been unsuccessful at getting initialExpression to populate when the item type is choice or open-choice. Instead, I end up having to use answerExpression to do the population of the value (and not the permitted answers). I have never understood why I have to do this workaround.
Mostly likely, it is something that I am doing wrong. So, I have now emailed a file to @Paul Lynch to see if he can see what I am doing wrong.
If I don't have to do the workaround of using answerExpression to populate the initialValue, then maybe I will have the ability to utilize initialExpression (for the answer) and answerExpression (for the answer list), which would solve many of my problems.
Diane (Jan 06 2022 at 07:24):
referencesContained is a great extension to accomodate conditionally used contained resources. In case anyone needs a link to one of the examples Lloyd has mentioned, see https://build.fhir.org/ig/HL7/sdc/examples.html#using-answervalueset-with-expressions.
Paul Lynch (Jan 06 2022 at 14:52):
Replied to @Diane via email.
Diane (Jan 06 2022 at 20:37):
Paul Lynch has found and explained the issue to me. Thank you!
You can definitely use initialExpression to do the population of a value when the item type is choice or open-choice.
Posting a summary here in case anyone searches fhir chat in the future with this problem.
When you are populating a choice (or open-choice) item type, the value from initialExpression must be a Coding.
Examples of fhirpath syntax for the expression:
%questionnaire.item.where(linkId = 'Q1.6').answer.value
or
%questionnaire.item.where(linkId = 'Q1.6').answer.valueCoding
What does not work is:
%questionnaire.item.where(linkId = 'Q1.6').answer.value.display
This does not work either:
%questionnaire.item.where(linkId = 'Q1.6').answer.value.code
Another important requirement (wasn't an issue for me but might cause issues for someone else so including it here):
the answer populated must match one of the items in the list (for choice item type)
Brian Postlethwaite (Jan 07 2022 at 19:41):
Those should work too, as the type can be either choosing, or string
Last updated: Apr 12 2022 at 19:14 UTC