Stream: fhirpath
Topic: variables
Brian Postlethwaite (Jul 10 2019 at 02:13):
I'm updating the .net fhirpath engine to handle variables for the Questionnaire pre-population code and was wondering if others have already tackled this problem in the java/js implementations?
I'm expecting that these are to be passed into the evaluation engine and referenced in the same way that environment variables are, using the %varname syntax.
My question is around the behaviour if a variable is referneced that doesn't exist in the engine?
Should that throw an Argument exception, or do null propagation.
Brian Postlethwaite (Jul 10 2019 at 02:16):
My test example is a simple Pythagoras calculation (which could be an invariant) where the variables haven't been defined.
%x * %x + %y * %y = %z * %z
Brian Postlethwaite (Jul 10 2019 at 03:27):
And while I'm on the topic, can the variables be collections rather than just single values (the current .net env vars are only single values)
Brian Postlethwaite (Jul 10 2019 at 03:39):
FYI The %ucum variable is one that is set for all environments/contexts
Paul Lynch (Jul 10 2019 at 15:16):
For LHC-Forms, there is an example with "weight" and "height" variables in the SDC app. Click on "Weight & Height tracking panel", and then in the "show as" menu, choose "FHIR Questionnaire from server". Or, if you just want to see the definition, that is here.
In our implementation, "variable" can hold the result of any FHIRPath expression. If it is a structure, then you would need other FHIRPath expressions to pick out the pieces you wanted.
LHC-Forms relies on fhirpath.js for FHIRPath expressions. I just checked the source, and I implemented undefined variable names as resolving to the empty value, [ ].
Brian Postlethwaite (Jul 10 2019 at 21:01):
Thanks @Paul Lynch , that BMI calculation is pretty neat. I'll use it for my testing.
Grahame Grieve (Jul 10 2019 at 22:02):
I pass in an interface that provides services to the engine. variables that are not defined are compile time failures
Paul Lynch (Jul 10 2019 at 22:24):
@Grahame Grieve I think your approach is correct. The FHIRPath spec (May ballot) says, "Attempting to access an undefined environment variable will result in an error, but accessing a defined environment variable that does not have a value specified results in empty ({ })."
Ewout Kramer (Jul 11 2019 at 10:13):
The discussion we are having in the .NET team is: is the name/type/value of the variables supposed to be known at compile time, or just their name and type, so you can vary their value for each call to a compiled statement?
Ewout Kramer (Jul 11 2019 at 10:14):
I think we're talking about the second of these two?
Brian Postlethwaite (Jul 11 2019 at 10:57):
Yes, that's true.
Paul Lynch (Jul 11 2019 at 14:31):
Since I'm working in JavaScript, I am not quite sure what it would mean to compile a FHIRPath expression, or at what point that would be done. An author of a Questionnaire could set up a Questionnaire variable based on a FHIRPath expression that could return more than one type:
iif(today() > @2020, 3, 'why not?')
The questionnaire author has the responsibility make sure that what they are writing makes sense. Whatever used that variable (e.g. other FHIRPath expressions) would need to handle the different types.
Other the other hand, at the the time that multi-type variable was used in a subsequent FHIRPath expression, its type could be checked by the FHIRPath engine and known prior to evaluation (compile time?). Maybe that is what you meant. Certainly its value and type would not change during the evaluation (run time). But, at each run, the type could be different.
Bryn Rhodes (Jul 11 2019 at 17:10):
In theory, checking that the FHIRPath expressions make sense could be part of validation, and that would be the "compile-time". For questions that may have different types, at least the set of possible types is known, and that is handled with a choice type. Since the CQFramework's FHIRPath engine is part of the CQL Engine, there is a separate compile-time step, and that is where that checking would occur.
Paul Lynch (Jul 11 2019 at 22:01):
I was not referring to a question having multiple types, but to Questionnaire variables.
Last updated: Apr 12 2022 at 19:14 UTC