Stream: dotnet
Topic: FHIRPath slice() in .NET FHIR API
Vladimir Smirnov (May 31 2021 at 17:10):
Hello!
We found the slice() function implementation missing in current .NET FHIR API, and are attempting to write our own. We found we can add to the DefaultSymbolTable that is declared public on FhirPathCompiler. In principle, it should be possible to add any custom function this way.
However, implementing slice() requires that the code handling this function call would have access to the path within the context resource of the element on which the function is being called. For example, say, we're evaluating "Observation.component.slice('http://profileUrl', 'systolic').value". The callback behind the slice() would need to resolve the StructureDefinition by its url, then navigate to the element id given by current resource path at the point of invocation (in this case, "Observation.component"), then read its slicing definition and locate the necessary child node of the context resource based on discriminator.
Is there any way in current .NET FHIR API to access current context element path from within the delegate implementing a fhirpath function? So far my understanding there isn't, and it would require modifications to the library itself. Is this one of the reasons why slice() wasn't implemented yet, unlike all the other functions?
Brian Postlethwaite (May 31 2021 at 22:04):
The reason it's not implemented as there are multiple ways to do it, and specifically as it reaches outside the instance.
The path is available to the instance through the wrapper classes and interfaces that the fhirpath engine uses.
I'll have to go look it up to work it out.
I've done this for several other things in the fhirpathtester app.
Vladimir Smirnov (Jun 01 2021 at 10:12):
@Brian Postlethwaite thank you for reference to fhirpath tester! We looked up in your code, and turns out fhirpath function delegates operate on instances of ITypedElement, which has the property Location containing current element path.
Brian Postlethwaite (Jun 01 2021 at 11:17):
Yup, that's exactly right.
You can also see how I added some other functions in there like short path and commonpath for some custom stuff for myself.
Last updated: Apr 12 2022 at 19:14 UTC