Stream: implementers
Topic: FHIRPath checking unique values
frank cao (Sep 03 2019 at 15:15):
Hi, I'm trying to specify constraint to make sure patient address does not contain duplicate use and type values. Can this be done in FHIRPath, something like address.select(use, type).isDistinct()? The combination of address use and type needs to be unique. Thanks.
Lloyd McKenzie (Sep 03 2019 at 15:40):
@Bryn Rhodes
Lloyd McKenzie (Sep 03 2019 at 15:42):
Before enforcing the constraint, consider that patients may have multiple home or business addresses and may have 'historic' addresses that are no longer active. It may be better to require that one address of each use+type combination be designated as primary/preferred using an extension. That way you're not preventing the client from sending the addresses they know about.
frank cao (Sep 03 2019 at 16:04):
@Lloyd McKenzie
Thanks Lloyd. I'll give it some thoughts. Can this be done in FHIRPath, though? I need some guidance on the syntax of the expression, especially the select(expression) part.
Lloyd McKenzie (Sep 03 2019 at 16:12):
That's why I drew Bryn's attention to the thread. I'm not super familiar with the 'select' operation. Best to get advice from an expert :)
Grahame Grieve (Sep 03 2019 at 19:07):
address.select(use | type).isDistinct()
the select returns a collections of collections where the inner collection contains the use and the type. The isDistinct() checks that the outer collection has no duplicates.
frank cao (Sep 04 2019 at 15:13):
Thanks Grahame. I'm not sure if isDistinct() can be used here as it will only return true if all the items are distinct. If I have two addresses, one with use = "home", type = "physical", the other one with use = "home", type = "postal", your query will return false, but I want to compare the combination so this should pass. What I need is something like address[0].select(use|type) != address[1].select(use|type), but how do I expand it to work beyond 2 addresses?
Grahame Grieve (Sep 04 2019 at 20:40):
I thought that was how that FHIRPath works. Did you test it?
Bryn Rhodes (Sep 05 2019 at 07:54):
The problem is that the select won't preserve the combinations, it will jut put them all in a single list. So you won't have a list of pairs of use/type elements, which is what you're really trying to say is unique here, if I'm understanding the question correctly.
Bryn Rhodes (Sep 05 2019 at 07:55):
I think without a constructor, you'd have to do something hackish like select(use & type).isDistinct
Grahame Grieve (Sep 05 2019 at 07:58):
ok yes I missed this:
(collections resulting from evaluation of projection are flattened)
So yes, have to hack with &
Last updated: Apr 12 2022 at 19:14 UTC