Stream: conformance
Topic: Checking document Bundle completeness with Invariant
Simone Heckmann (Jun 02 2020 at 15:08):
I want to check a document type Bundle for completeness (as in: all Resources referenced by the Composition shall be contained in the Bundle).
The Invariant I came up with does exactly that when I run it through the FHIRPath.js demo tool:
Bundle.entry.descendants().reference.distinct().subsetOf(Bundle.entry.fullUrl)
It picks up missing Ressources but allows for additional content in the Bundle.
However it doesn not work in Simplifier. I picked this up with support and they said (if I understand it correctly) that the evaluation failes because the datatypes of reference (string) and fullUrl (uri) don't match.
I tried a couple more variants, e.g. Bundle.entry.descendants().reference.distinct().all(Bundle.entry.fullUrl.contains($this))
but I keep running into the same error.
I can't figure out a way to work around this, but I assume that checking the completeness of Bundles is a universal use case. It shouldn't be that hard...
How can I make this work?
Lloyd McKenzie (Jun 02 2020 at 15:24):
I don't know that 'reference' is unique only to Reference.reference. Also, the reference can be a local reference, which wouldn't match the fullUrl. I don't think there's a good way to express this in FHIRPath.
Simone Heckmann (Jun 03 2020 at 07:04):
Oh, you mean a contained reference? I think that could be easily caught by adding
Bundle.entry.descendants().reference.distinct().where($this.contains('#').not())...
(or something similar)...
Matthijs van der Wielen (Jun 03 2020 at 07:59):
The way I tested this is that the first part "Bundle.entry.descendants().reference.distinct()" returns "string value" and the second part "entry.fullUrl()" returns a "uri value".
The use of "subsetOf" seems pretty straightforward in the spec, however it does not allow the comparison of string and uri values (it seems). And I couldn't figure out how to use a cast to transform the uri into a string or vice versa, to see if the "subsetOf" would work.
Simone Heckmann (Jun 03 2020 at 08:33):
The funny thing is however, that the JavaScript implementation doesn't seem to run into that issue. So I wonder which one is the expected behavior and which one isn't...
Simone Heckmann (Jun 03 2020 at 08:35):
Hm, I guess the Specification doesn't take sides here:
Because FHIRPath may be used in different situations and environments requiring different levels of type safety, implementations may make different choices about how much type checking should be done at compile-time versus run-time, and in what situations. Some implementations requiring a high degree of type-safety may choose to perform strict type-checking at compile-time for all invocations. On the other hand, some implementations may be unconcerned with compile-time versus run-time checking and may choose to defer all correctness checks to run-time.
Source: http://hl7.org/fhirpath/N1/#type-safety-and-strict-evaluation
Simone Heckmann (Jun 03 2020 at 08:39):
The Conversion Table doesn't even mention the URI Type: http://hl7.org/fhirpath/N1/#conversion
Simone Heckmann (Jun 03 2020 at 08:44):
Although, the more I read about types and conversion, the more I think that URI types shouldn't even exist in FHIRPath and just simply be treated as strings... There is no mention whatsoever of URI types in the FHIRPath spec...
Simone Heckmann (Jun 03 2020 at 08:44):
Ah. There it is!
http://hl7.org/fhir/fhirpath.html#types
Simone Heckmann (Jun 03 2020 at 08:45):
Simone Heckmann (Jun 03 2020 at 08:46):
So, the FHIR types string and uri should be the same in FHIRPath...
Matthijs van der Wielen (Jun 03 2020 at 08:50):
Interesting! So why won't the subsetOf not work in the fhirpath tester?
Simone Heckmann (Jun 03 2020 at 09:22):
...because there's a bug in the .NET implementation ...?
Simone Heckmann (Jun 03 2020 at 09:36):
Bundle.entry.fullUrl should return a collection of strings instead of a collection of uris, IMO
Matthijs van der Wielen (Jun 03 2020 at 10:21):
I've created a ticket for the .NET team. They will look into it. https://github.com/FirelyTeam/fhir-net-api/issues/1389
Simone Heckmann (Jun 03 2020 at 12:16):
Excellent, thanks!
Lloyd McKenzie (Jun 03 2020 at 17:09):
I don't mean a contained reference. I mean that the references in your instance might say "Patient/5", but the fullUrls you're comparing them against would say "http://somewhere.org/Patient/5" - and thus won't match.
Last updated: Apr 12 2022 at 19:14 UTC