FHIR Chat · FHIRPATH SDC implementation · questionnaire

Stream: questionnaire

Topic: FHIRPATH SDC implementation


view this post on Zulip Tilo Christ (Oct 16 2021 at 09:10):

Is there a FHIRPath implementation which has a known good reference-quality implementation of the SDC add-ons - answers() in particular? I am trying to see whether I am interpreting the specification correctly, but the fhirpath.js implementation doesn't have answers() implemented and also fails on the equivalent from the spec descendants().where($this is QuestionnaireResponse.item.answer.value).

view this post on Zulip Lloyd McKenzie (Oct 16 2021 at 15:55):

Those functions were only exposed in the CI-build about a month ago, so quite possibly not. @Brian Postlethwaite @Grahame Grieve

view this post on Zulip Grahame Grieve (Oct 16 2021 at 19:36):

I haven't done it

view this post on Zulip Brian Postlethwaite (Oct 16 2021 at 21:25):

I don't remember the answers() function, but can take a look at it.
What context are you running that expression?
I've found the fhirpathjs one to be quite good.
And the dotnet one is also very good (I'm using both of them, and have extended the dotnet one recently too)

view this post on Zulip Tilo Christ (Oct 16 2021 at 22:11):

I am trying to get the PHQ9 scoring example to work: https://github.com/HL7/sdc/blob/master/input/examples/questionnaire-sdc-profile-example-PHQ9.json - the expression %resource.answers().value.ordinal().sum(). I'm trying to implement the answers() function in terms of the descendants() function which again is short-hand for repeat(children()). I'm seeing wildly different results for the same expressions in different FHIRPath implementations (repeat(children()) on the same QuestionnaireResponse resource returning 58, 75, and 78 items on three different implementations). Hence my hope for a reference implementation that I can reliably compare against.

view this post on Zulip Brian Postlethwaite (Oct 17 2021 at 00:31):

.sum()?

view this post on Zulip Brian Postlethwaite (Oct 17 2021 at 00:31):

I'm actually working in this specific implementation right now too.

view this post on Zulip Brian Postlethwaite (Oct 17 2021 at 00:34):

That query you're looking at I'd be more likely to do something like this
%resource.item.where(linkId='groupofqs').item.answer.value.aggregate($this+$total,0)

view this post on Zulip Brian Postlethwaite (Oct 17 2021 at 00:35):

At the moment my implementation will be specifying the link ids explicitly that it will be summing so that the change detection can be marked.

view this post on Zulip Brian Postlethwaite (Oct 17 2021 at 00:37):

Also, there isn't a great ordinal() implementation too, so instead I'm summing the extension in the coded answer.
answer.value.extension('...ordinal').value.aggregate

view this post on Zulip Brian Postlethwaite (Oct 17 2021 at 00:37):

(and put the full extension name in there)

view this post on Zulip Raazia Tariq (Mar 14 2022 at 13:35):

I am trying to evaluate this expression "patient.name.where(use='official').family()" using FhirPathEngine and I am getting the following error,
org.hl7.fhir.r4.utils.FHIRLexer$FHIRLexerException: Error in ?? at 1, 1: The name family is not a valid function name
at org.hl7.fhir.r4.utils.FHIRLexer.error(FHIRLexer.java:145)
at org.hl7.fhir.r4.utils.FHIRLexer.error(FHIRLexer.java:141)
at org.hl7.fhir.r4.utils.FHIRPathEngine.parseExpression(FHIRPathEngine.java:873)
at org.hl7.fhir.r4.utils.FHIRPathEngine.parseExpression(FHIRPathEngine.java:907)
at org.hl7.fhir.r4.utils.FHIRPathEngine.parseExpression(FHIRPathEngine.java:907)
at org.hl7.fhir.r4.utils.FHIRPathEngine.parseExpression(FHIRPathEngine.java:907)
at org.hl7.fhir.r4.utils.FHIRPathEngine.parse(FHIRPathEngine.java:338)
at org.hl7.fhir.r4.utils.FHIRPathEngine.parse(FHIRPathEngine.java:331)
at org.hl7.fhir.r4.utils.FHIRPathEngine.evaluate(FHIRPathEngine.java:520)
It seems like FHIRLexer does not support 'where' and functions call. Am I doing something wrong here or there's a missing support of mentioned operations.

view this post on Zulip Notification Bot (Mar 14 2022 at 13:36):

Raazia Tariq has marked this topic as resolved.

view this post on Zulip Notification Bot (Mar 14 2022 at 13:36):

Raazia Tariq has marked this topic as unresolved.

view this post on Zulip Paul Lynch (Mar 14 2022 at 14:16):

I think it's complaining that family() is not a function. Try removing the (). Also, if the context you are running the expression against is a Patient resource, then "Patient" should be capitalized in the expression.

view this post on Zulip Raazia Tariq (Mar 14 2022 at 15:02):

Paul Lynch said:

I think it's complaining that family() is not a function. Try removing the (). Also, if the context you are running the expression against is a Patient resource, then "Patient" should be capitalized in the expression.

Thanks Paul, I did your suggested changes and it works fine now.

view this post on Zulip Shoaib Mushtaq (Mar 21 2022 at 14:30):

I want to know about that either FHIRPath supports variables to evaluate an expression or not?

For example, we have a weight variable with the expression given below

{
      "url": "http://hl7.org/fhir/StructureDefinition/variable",
      "valueExpression": {
        "name": "weight",
        "language": "text/fhirpath",
        "expression": "%resource.repeat(item).where(linkId='3.3.1').item.answer.valueDecimal"
      }
}

And first, we evaluate the value of this expression using the FHIRPath evaluate method, and then we want to use this variable value in the calculation of BMI given below,
You can see that %weight is used as a variable, so do we have any such capability in FHIRPath to pass these variables(weight and height here) as input to evaluate this given expression (%weight/(%height.power(2))).round(1)?

{
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
              "valueExpression": {
                "description": "BMI Calculation",
                "language": "text/fhirpath",
                "expression": "(%weight/(%height.power(2))).round(1)"
              }
 }

view this post on Zulip Lloyd McKenzie (Mar 21 2022 at 15:37):

So long as the variables are declared on the root of the Questionnaire or on an item that's an ancestor of the item that uses the calculatedExpression, yes that should work.

view this post on Zulip Brian Postlethwaite (Mar 21 2022 at 18:52):

And several implementations support it, including the lhc forms

view this post on Zulip Shoaib Mushtaq (Mar 22 2022 at 06:37):

Brian Postlethwaite said:

And several implementations support it, including the lhc forms

Thanks @Brian Postlethwaite for it.
Can you please mention some other implementations as well that support this other than LHC forms? Thanks

view this post on Zulip Brian Postlethwaite (Mar 22 2022 at 06:39):

The 2 others I k ow of aren't open source at this stage.
And there are a few out of Europe too, however not sure if they do expression.

view this post on Zulip Raazia Tariq (Mar 24 2022 at 18:21):

public boolean evaluateToBoolean(Resource focusResource, Resource rootResource, Base base, String path) throws FHIRException {
return convertToBoolean(evaluate(null, focusResource, rootResource, base, path));
}
Does anyone know what focusResource and rootResource are in this method? It is a FhirPathEngine method.
Actually I want to use this method to evaluate enableWhenExpression (http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression).

view this post on Zulip Lloyd McKenzie (Mar 24 2022 at 19:18):

focusResource is the resource you're dealing with and rootResource is typically the same, though if you're dealing with stuff in Bundles or Parameters or other resources that can contain other resources, it'll be the outermost resource for the instance. See here: https://hl7.org/fhir/fhirpath.html#variables

view this post on Zulip Raazia Tariq (Mar 24 2022 at 20:59):

Lloyd McKenzie said:

focusResource is the resource you're dealing with and rootResource is typically the same, though if you're dealing with stuff in Bundles or Parameters or other resources that can contain other resources, it'll be the outermost resource for the instance. See here: https://hl7.org/fhir/fhirpath.html#variables

Currently, I could have multiple resources or a single resource, so If I have a single resource I'll pass the same resource to all of the parameters. and if I have multiple resources I first need determine the context of each resource in the expression. Is this statement correct?

view this post on Zulip Lloyd McKenzie (Mar 25 2022 at 02:21):

Pretty much. %rootResource isn't so much about "multiple resources" as specifically about resources that nest within other resources.

view this post on Zulip David Winters (Mar 25 2022 at 12:36):

@Shoaib Mushtaq I have a library that can handle expressions written in CQL, which is similar to FHIRPath.

view this post on Zulip David Winters (Mar 25 2022 at 12:39):

I don't think it would be too hard to add support for FHIRPath.

view this post on Zulip Tilo Christ (Mar 25 2022 at 18:00):

My European implementation supports it. Although it has a Japanese name and a FHIRPath of American ancestry.
https://legentix.com/faidashu/#/
https://github.com/tiloc/faiadashu

Brian Postlethwaite said:

The 2 others I k ow of aren't open source at this stage.
And there are a few out of Europe too, however not sure if they do expression.

view this post on Zulip Shoaib Mushtaq (Apr 06 2022 at 16:45):

Is there a way to pass variable/list of variables with its/their values to fhirPath evaluate method with the expression having variables in it?

For example, the expression is "expression": "%X + 2", in this questionnaire. So can we pass the value of %X variable as parameter to evaluate method? is it supported or any other way to cater it?
P.S, I am using fhirPathEngine on Android to evaluate these expressions in the questionnaires.
Thanks
@Lloyd McKenzie @Grahame Grieve cc: @Jing Tang

view this post on Zulip Lloyd McKenzie (Apr 06 2022 at 17:17):

Within a Questionnaire, there are several extensions that allow defining variables, including 'variable' and 'launchParameter'. All the expression names that are 'in context' of another expression are available for reference. Take a look at this page in SDC: http://build.fhir.org/ig/HL7/sdc/expressions.html

view this post on Zulip Paul Lynch (Apr 06 2022 at 20:03):

"in context" means the variable is on the item or a parent of the item that contains the expression referring to it.

view this post on Zulip Lloyd McKenzie (Apr 06 2022 at 20:37):

Technically 'ancestor' rather than 'parent'. And if it's on the item, it needs to be earlier in the list than the extension doing the reference.

view this post on Zulip Brian Postlethwaite (Apr 06 2022 at 20:42):

This is an example of a BMI form that has some variables in it.
http://sqlonfhir-r4.azurewebsites.net/fhir/Questionnaire/55418-8-x/_history/13?_format=html


Last updated: Apr 12 2022 at 19:14 UTC