Stream: fhirpath
Topic: Function output as input for next function
Ward Weistra (Jun 21 2021 at 16:23):
In the case where I have a resource with name LogicalModel-Person
:
name.indexOf('-'))
gives me the outcome12
.name.substring(0, 12)
gives me the desired outcomeLogicalModel
.- However,
name.substring(0, name.indexOf('-'))
just gives back an empty string in FHIRPath Tester and the full name in https://hl7.github.io/fhirpath.js/.
Is there a way for this to work instead?
Brian Postlethwaite (Jun 21 2021 at 22:19):
Using quotes around the name
Brian Postlethwaite (Jun 21 2021 at 22:20):
(think its the back tic char)
Ward Weistra (Jun 22 2021 at 16:11):
See that I incorrectly reported what which FHIRPath tool gave back in my first post, updated that above. Sorry.
Ward Weistra (Jun 22 2021 at 16:12):
@Brian Postlethwaite I'm not sure if I understand. Using:
`name`.substring(0, `name`.indexOf('-'))
gives me again the full name in fhirpath.js and an error in your FHIRPath Tester:
Expression compilation error:
Compilation failed: Parsing failure: unexpected '`'; expected Term (Line 1, Column 1); recently consumed:
Brian Postlethwaite (Jun 23 2021 at 04:31):
This should be working - but I don't get why not...
image.png
Ward Weistra (Jun 23 2021 at 14:31):
@Brian Postlethwaite Thought maybe I had an old version of FHIRPath Tester, so uninstalled it and wanted to reinstall.
But now the Microsoft Store 'Install' or 'Get' button doesn't do anything. And the version from https://github.com/brianpos/FhirPathTester/releases/tag/v1.0.4 feels quite a bit older.
Brian Postlethwaite (Jun 23 2021 at 20:11):
Yes, it looks like i've not updated with a new tag when I released it last. :sad:
I should do another release with the 1.9.0 version of the libs - but need to have a local build of the libs due to minor change to remove the emit code in the setters (if that's still in there, as it doesn't work in the App store based code).
Ward Weistra (Jul 02 2021 at 13:01):
@Brian Postlethwaite So the Microsoft Store install/get works again now (I guess a few reboots later).
With the same resource as you're using:
<Organization xmlns="http://hl7.org/fhir">
<name value="postlethwaite-kordic" />
</Organization>
The query
name.substring(0, name.indexOf('-'))
gives an empty string:
image.png
The query
`name`.substring(0, `name`.indexOf('-'))
gives
Expression compilation error:
Compilation failed: Parsing failure: unexpected '`'; expected Term (Line 1, Column 1); recently consumed:
About section says 'New Features in v1.0.8', so I guess that's the version I'm using.
Ward Weistra (Jul 02 2021 at 13:05):
On https://hl7.github.io/fhirpath.js/ both queries just give the full name value...
image.png
image.png
Ward Weistra (Jul 02 2021 at 13:07):
Both tools correctly give back postlethwaite
for:
'postlethwaite-kordic'.substring(0, 'postlethwaite-kordic'.indexOf('-'))
Ward Weistra (Jul 02 2021 at 16:00):
@Brian Postlethwaite Part of the mystery: Backticks are the escape character for the normative FHIRPath, before that it seems to have been double quotes. (As I understand from @Ewout Kramer)
But still also:
"name".substring(0, "name".indexOf('-'))
Gives an empty string in the 1.0.8 of FHIRPath tester. Looking forward to test it with the newer release.
Brian Postlethwaite (Jul 02 2021 at 22:01):
Issue there is the context isn't the parent of name, it's the string. So that name property doesn't exist in the string.
Brian Postlethwaite (Jul 02 2021 at 22:02):
I've actually come across this issue in the last week too!
Brian Postlethwaite (Jul 02 2021 at 22:03):
name.substring(0, %resource.name.indexOf('-')) should work.
Ward Weistra (Jul 05 2021 at 11:23):
Thanks @Brian Postlethwaite. That indeed works in FHIRPath tester. Not on fhirpath.js though.
Should %resource
always be expected to be available when evaluating FHIRPath anywhere?
Is this expected behavior (that the scope there is on the string) for FHIRPath or more a bug in the SDK?
Brian Postlethwaite (Jul 05 2021 at 11:25):
Fhirpath.js is able to handle environment variables, but the host has to provide those to it.
I haven't had a chance to try that out withfhirpath.js yet, but was planning to in the next few weeks.
Brian Postlethwaite (Jul 05 2021 at 11:26):
(after my current project is released)
Ewout Kramer (Jul 05 2021 at 11:26):
I think the simple answer is name.substring(0, indexOf('-'))
.
Ewout Kramer (Jul 05 2021 at 11:28):
(backquote)name(backquote).substring(0, (backquote)name(backquote).indexOf('-'))
(sorry, no idea how to produce a backquote in markdown)
should be exactly the same as name.substring(0,name.indexOf('-'))
and probably return nothing of null.
Ewout Kramer (Jul 05 2021 at 11:31):
This is because %resource.name.substring(0,name.indexOf('-'))
evaluates to %resource.name.substring(0,%resource.name.name.indexOf('-'))
Ewout Kramer (Jul 05 2021 at 11:32):
This double name
returns nothing, so doing indexOf()
on it will return nothing, etc.
Brian Postlethwaite (Jul 05 2021 at 11:32):
The question going on here is what is the $this or %context within the parameters and the string.substring function parameters.
It appears that currently that is the string, and not the parent of the string.
Brian Postlethwaite (Jul 05 2021 at 11:33):
Ewout, that's how I understand it too.
Brian Postlethwaite (Jul 05 2021 at 11:34):
And since their is no parent for the node, you have to go from the top again right?
Ewout Kramer (Jul 05 2021 at 11:36):
Issue there is the context isn't the parent of name, it's the string. So that name property doesn't exist in the string.
Ewout Kramer (Jul 05 2021 at 11:36):
Yes, that's correct!
Ewout Kramer (Jul 05 2021 at 11:36):
But that's not an issue - right, this is the intended behaviour.
Brian Postlethwaite (Jul 05 2021 at 11:36):
@Ward Weistra where are you testing the fhirpath.js code?
Ewout Kramer (Jul 05 2021 at 11:36):
But $this is different
Ewout Kramer (Jul 05 2021 at 11:36):
$this is only set by specific functions like where
Brian Postlethwaite (Jul 05 2021 at 11:37):
So not in this example?
Ewout Kramer (Jul 05 2021 at 11:39):
That's right. Only functions that take an expression as a parameter will (re)introduce the $this.
Ewout Kramer (Jul 05 2021 at 11:41):
Take bla.where(x.indexOf(0, $this.length())
--- after the where
, $this is pointing to each repeating bla
. Within indexOf()
the $this is still referring to a bla
introduced by the where
- not the x
. In x.indexOf(0, length())
, the length()
would use the x
, not the $this
.
Ewout Kramer (Jul 05 2021 at 11:42):
http://hl7.org/fhirpath/#functions - last bullet (for $this).
Ewout Kramer (Jul 05 2021 at 11:45):
Arguments are evaluated with respect to the input collection, and functions taking an expression as an argument introduce a special $this in their scope.
Brian Postlethwaite (Jul 05 2021 at 11:58):
So looking up at the examples above, I think all these are equivalent (assuming that there aren't more then 1 name):
name.text.substring(0, indexOf(','))
name.text.substring(0, %resource.name.text.indexOf(','))
And where the other examples above included the name also, that should not have worked in fhirpath.js, but it does
name.text.substring(0, text.indexOf(','))
image.png
image.png
Brian Postlethwaite (Jul 05 2021 at 12:00):
And note that if you're doing your own fhirpath.js host example content, this is how you're meant to pass in the environment variables (which I just put into my test host page)
var fhirObject = JSON.parse($('#fhirResource').val());
var expression = $('#path').val();
var envVars = [];
envVars["resource"] = fhirObject;
var returnedValue = fhirpath.evaluate(fhirObject, expression, envVars, fhirpath_r4_model);
$('#fhirpathOutput').text(JSON.stringify(returnedValue));
Brian Postlethwaite (Jul 05 2021 at 12:11):
Just deployed it here too
https://smartqedit4.azurewebsites.net/ts/Questionnaire/FhirPath
Ward Weistra (Jul 05 2021 at 16:16):
@Brian Postlethwaite @Ewout Kramer Thanks both!
Ward Weistra (Jul 05 2021 at 16:17):
Brian Postlethwaite said:
Ward Weistra where are you testing the fhirpath.js code?
Via https://hl7.github.io/fhirpath.js/. Not sure who manages that deployment.
Brian Postlethwaite (Jul 05 2021 at 22:15):
@Paul Lynch is that you?
Paul Lynch (Jul 08 2021 at 16:22):
Yes, or actually currently @Yury Sedinkin, but I am the right POC.
Paul Lynch (Jul 08 2021 at 16:28):
If there is a bug with fhirpath.js, please report it at https://github.com/HL7/fhirpath.js/issues
Last updated: Apr 12 2022 at 19:14 UTC