Stream: implementers
Topic: fhirpath contraint for cardinality of meta.profile
Katarina (Jul 06 2021 at 09:33):
Hi,
I want to write a fhirpath constraint that the meta element should have exactly one profile element.
This should work for every resource that is contained as entry in a Bundle.
This seems to work:
<element id="Bundle">
<path value="Bundle"/>
<constraint>
<key value="exactlyOneMetaProfile" />
<severity value="error" />
<human value="Exactly one meta.profile" />
<expression value="entry.all(resource.meta.profile.count()=1)" />
</constraint>
</element>
Or is there a better solution?
Lloyd McKenzie (Jul 06 2021 at 15:18):
First, forcing there to be exactly one profile is generally a bad thing to do. Systems should be able to declare as many profiles as they want - and as a recipient you should just ignore any you don't care about/recognize. It's fine for you to drop any declarations you don't care about/support if you don't have a means to store them. In fact, it's a bad idea to impose upper cardinality limits on most elements because it interferes with interoperability. Source systems should be able to send whatever data they have and receivers should extract the data they care about from whatever's sent, ignoring the rest. Imposing cardinality limits driven by what you can store (as opposed to what's a genuine error to exist at all) means that the system must create and maintain a specific export for your system - which increases costs and complexity.
That said, to constrain cardinality, simply set differential.element.min and max=1 for the path Bundle.meta.profile. No need for an invariant.
Last updated: Apr 12 2022 at 19:14 UTC