FHIR Chat · fhirpath expression · questionnaire

Stream: questionnaire

Topic: fhirpath expression


view this post on Zulip Julia (Dec 15 2021 at 15:32):

Looking for help in constructing a fhirpath expression.
Given the following structure (where answer and answerOption are children of item, and there can be hundreds of items):

-item
---answerOption
-----display (Yes)
-----decimalValue (1)
-----display (No)
-----decimalValue (2)
---providedAnswer
-----display (Yes)

Need to get, for any providedAnswer, the decimal value from the answerOption. Eg, in above example, answer is Yes, therefore decimalValue = 1.
What would be the fhirpath expression?
(using https://hl7.github.io/fhirpath.js/ for testing)

Thank you in advance.

view this post on Zulip Tilo Christ (Dec 15 2021 at 18:22):

The per-spec answer would probably be %resource.answers().value.ordinal(). I believe answers() and ordinal() is not widely implemented yet. You can play with it at http://legentix.com/faiabench/#/ by copying a Questionnaire into the left-middle text box, deleting the QuestionnaireResponse in the left bottom field, answering some questions in the middle, hitting the flame symbol on the right and then entering a FHIRPath expression.
image.png

view this post on Zulip Julia (Dec 15 2021 at 19:17):

Tilo Christ said:

The per-spec answer would probably be %resource.answers().value.ordinal(). I believe answers() and ordinal() is not widely implemented yet. You can play with it at http://legentix.com/faiabench/#/ by copying a Questionnaire into the left-middle text box, deleting the QuestionnaireResponse in the left bottom field, answering some questions in the middle, hitting the flame symbol on the right and then entering a FHIRPath expression.
image.png

So for the above JSON, the entire expression would look like this? item.providedAnswer.where(%resource.item.answerOption().value.ordinal())

view this post on Zulip Tilo Christ (Dec 15 2021 at 19:36):

maybe I'm a bit confused what I'm looking at in your example. I thought it was the QuestionnaireResponse? Is this a piece of Questionnaire or QuestionnaireResponse? What is "providedAnswer" meant to be? answerOption would live in the Questionnaire, but provided answers are part of the response.

view this post on Zulip Julia (Dec 15 2021 at 19:54):

Tilo Christ said:

maybe I'm a bit confused what I'm looking at in your example. I thought it was the QuestionnaireResponse? Is this a piece of Questionnaire or QuestionnaireResponse? What is "providedAnswer" meant to be? answerOption would live in the Questionnaire, but provided answers are part of the response.

Yes, that is right. I need to fetch something from questionnaire.answerOption, based on questionnaireResponse.answer value

view this post on Zulip Tilo Christ (Dec 15 2021 at 19:57):

Not necessarily. If that numerical value is handled as an ordinalValue then it gets passed through into the response and you can pick up everything from the response.

view this post on Zulip Paul Lynch (Dec 16 2021 at 01:06):

@Julia See https://github.com/lhncbc/lforms-fhir-app/blob/master/e2e-tests/data/R4/phq9.json for an example of a PHQ-9, which has a total score calculation that selects the ordinalValue value based on the answer from the QuestionnaireResponse. You can also find the same form in this app: https://lhcforms.nlm.nih.gov/sdc, in the "Featured" list on the left after picking a patient.

view this post on Zulip Tilo Christ (Dec 16 2021 at 11:07):

It's amazing to see how much the complexity of this shrinks once answers() and ordinal() becomes widely available: https://github.com/tiloc/faiadashu/blob/main/example/assets/instruments/phq9_instrument.json

view this post on Zulip Julia (Dec 16 2021 at 14:12):

Paul Lynch said:

Julia See https://github.com/lhncbc/lforms-fhir-app/blob/master/e2e-tests/data/R4/phq9.json for an example of a PHQ-9, which has a total score calculation that selects the ordinalValue value based on the answer from the QuestionnaireResponse. You can also find the same form in this app: https://lhcforms.nlm.nih.gov/sdc, in the "Featured" list on the left after picking a patient.

Thank you so much! This is exactly what I was looking for.

view this post on Zulip Julia (Dec 16 2021 at 14:13):

Tilo Christ said:

Not necessarily. If that numerical value is handled as an ordinalValue then it gets passed through into the response and you can pick up everything from the response.

Thank you very much! This is an interesting approach that I will try out.

view this post on Zulip Paul Lynch (Dec 16 2021 at 19:34):

Tilo Christ said:

It's amazing to see how much the complexity of this shrinks once answers() and ordinal() becomes widely available: https://github.com/tiloc/faiadashu/blob/main/example/assets/instruments/phq9_instrument.json

That is definitely a lot simpler. For anyone else looking for where those functions are defined, see: https://build.fhir.org/ig/HL7/sdc/expressions.html#fhirpath, and also the tracker items https://jira.hl7.org/browse/FHIR-28173 and https://jira.hl7.org/browse/FHIR-33539

view this post on Zulip Brian Postlethwaite (Dec 17 2021 at 02:13):

I have a great scoring demo resource
https://sqlonfhir-r4.azurewebsites.net/fhir/Questionnaire/abbey-pain-scale/_history/5?_format=html
This one uses the ordinal too.
Mind you I used the extension rather than the shortcut method.


Last updated: Apr 12 2022 at 19:14 UTC