Stream: IG creation
Topic: fhirpath constraint for Bundle entries
Niklas Haldorn (Mar 04 2022 at 11:48):
Hi all,
I am trying to create a Bundle profile for the requirement, that for every non-provenance resource in the bundle there must be a provenance that references the resource as a target.
I tried to implement this profile with a constraint that iterates over all entries and if the entry is not a provenance it selects the first target reference from all provenances in the bundle and checks if the id of the resource is in this collection.
For the constraint I used the following expression
entry.all((resource is Provenance) or (resource.resourceType.toString() & '/' & resource.id)
.subsetOf(entry.select((resource as Provenance).target.first().reference)))
However, the expression always fails if the bundle contains a non-provenance resource even if a correct provenance is part of the bundle.
Does anyone know how to change the expression to fulfil the requirement or if there is a better way to enforce the requirement in the bundle?
Lloyd McKenzie (Mar 04 2022 at 14:45):
The issue is that your entry.select...
bit is executing in the context of entry.all...
. Try %resource.entry.select...
Note that your expression presumes that all entries in the Bundle will be referenced using relative references and, in general, that's not a safe assumption.
Last updated: Apr 12 2022 at 19:14 UTC