FHIR Chat · Selecting from distinct collection in a specified order · fhirpath

Stream: fhirpath

Topic: Selecting from distinct collection in a specified order


view this post on Zulip Morten Ernebjerg (Mar 12 2021 at 16:27):

Hi :wave: I was playing around with FHIRPath and trying to come up with an expression for reducing a CodeableConcept to a string. The logic I want involves preferences, e.g.

  1. if there are codes that are use selected, take the first display value from those
  2. otherwise, if there are codes from code systems I know, take the display string of the first of those
  3. otherwise take CodeableConcept.text

The generic logic here is I have several expressions that each yield a collection (possibly empty) and I want to go through those collections in a specified order and pick some element from the first non-empty collection. If these were arrays, I would concatenate them in the required order and take the first element, but the union operator does not guarantee to maintain the ordering. I can think of a few very ugly solutions - are there any elegant ones?

view this post on Zulip ryan moehrke (Mar 12 2021 at 16:28):

my first thought is iif() chaining but that could be quite messy and long for all the processing you want to do

view this post on Zulip Morten Ernebjerg (Mar 12 2021 at 16:36):

Yup, that should work. I did consider it, but I was hoping for something that would avoid this sort of nesting and be more functional-style (a hope I could not make come true myself by reading the spec :smirk: )

view this post on Zulip Bryn Rhodes (Mar 12 2021 at 18:13):

Using a unions of firsts should work, but it would be long. It's a prime candidate for a function, but given that you're looking for "code systems you know" it couldn't be a standard function (unless everyone agreed what that meant).

view this post on Zulip ryan moehrke (Mar 12 2021 at 18:16):

but how do you differentiate between the three preferred options in that union'd set?

view this post on Zulip Bryn Rhodes (Mar 12 2021 at 18:26):

Mmmm, yes, that's true, sorry. Yep, iif. We considered coalesce(), like CQL has, but opted against it since it was shorthand for iif.

view this post on Zulip Brian Postlethwaite (Jun 06 2021 at 10:05):

(coding.where(system="blah").code | coding.where(system="blah_2nd").code | coding.where(system="3rd_system").code ).first()


Last updated: Apr 12 2022 at 19:14 UTC