FHIR Chat · iif criterium · fhirpath

Stream: fhirpath

Topic: iif criterium


view this post on Zulip Paul Lynch (Aug 07 2018 at 21:27):

In 5.5.1 of http://hl7.org/fhirpath/ (the definition of "iif") it says what to do if the "crterium" expression evalutes to true or false (which I guess means [true] or [false]). What should happen if it evaluates to something else, like [5.72], [true, true], [true, false], or [ ]?

view this post on Zulip Grahame Grieve (Aug 07 2018 at 21:28):

the expression will always be evaulatable to one of the following values: true | false | null

view this post on Zulip Grahame Grieve (Aug 07 2018 at 21:28):

I guess that if it evaluates to null, do neither true or false

view this post on Zulip Paul Lynch (Aug 07 2018 at 21:35):

I thought expressions returned collections. What rule is used to convert a collection to one of true, false, or null?

Does doing neither true nor false mean terminating in an error (as the Math functions in 6.6 do)?

view this post on Zulip Grahame Grieve (Aug 07 2018 at 21:37):

null will propagate. collection boolean evaluation is explicitly described

view this post on Zulip Grahame Grieve (Aug 07 2018 at 21:37):

section 4.5

view this post on Zulip Paul Lynch (Aug 07 2018 at 21:49):

Thanks. I was looking for something like 4.5.

In 4.4, it says "There is no concept of null in FHIRPath." So, I think you meant true | false | empty collection. (I guess null is less to type.) If I understand correctly then, it sounds like any value other than a single "true", or "false", or an empty collection will raise an error, and if the result is the empty collection, then that is also the result of the iif.

view this post on Zulip Grahame Grieve (Aug 07 2018 at 21:55):

I'm not sure about the iif bit - @Bryn Rhodes ?

view this post on Zulip Bryn Rhodes (Aug 08 2018 at 00:51):

That's correct, if criterion evaluates to true, the result is the value of the true-result argument, otherwise, the result is the value of the otherwise-result argument (or empty if no otherwise-result is provided).

view this post on Zulip nicola (RIO/SS) (Aug 08 2018 at 09:43):

do you mean condition expression should always be of type bool? what if expression returns [1,2], should i always call exists() or empty() otherwise throw exception? and do you mean that in case of null none of branches are executed and just empty result is returned?

view this post on Zulip Paul Lynch (Aug 08 2018 at 21:23):

@nicola (RIO/SS) I think Grahame was saying we use the procedure in 4.5 to force criterion into either true, false, or empty collection (or raising an error) and then Bryn was saying (and 5.5.1 says) the false and empty collection cases are handled the same.

view this post on Zulip nicola (RIO/SS) (Aug 09 2018 at 07:45):

@Grahame Grieve @Bryn Rhodes just confirm empty means false?

view this post on Zulip Bryn Rhodes (Aug 11 2018 at 20:37):

@nicola (RIO/SS) sorry for the delay, I've been on vacation. I wouldn't characterize it this way, I would say that for iif, empty is interpreted in the same way that false is, but I wouldn't say that empty means false.

view this post on Zulip Bryn Rhodes (Aug 11 2018 at 20:39):

The rationale for having ternary logic is that the data is incomplete and so you have to deal with that possibility, and it's invalid to always treat missing information as false. We use the same semantics for missing information and ternary logic that SQL and XQuery do.

view this post on Zulip nicola (RIO/SS) (Aug 11 2018 at 20:39):

But non of programming languages?

view this post on Zulip Bryn Rhodes (Aug 11 2018 at 20:40):

Everything is a collection does have pros and cons, but for a path selection language, it makes really good sense, and the semantics we've imposed for singleton evaluation of collections provides a clear interpretation for operations that expect singletons.

view this post on Zulip Bryn Rhodes (Aug 11 2018 at 20:41):

Not sure what you mean.

view this post on Zulip nicola (RIO/SS) (Aug 11 2018 at 20:41):

with singleton semantic should we treat everything with more than 1 element as runtime error?

view this post on Zulip nicola (RIO/SS) (Aug 11 2018 at 20:45):

implement maybe monad as vector of one element is not the only way to do it :)

view this post on Zulip nicola (RIO/SS) (Aug 11 2018 at 20:47):

So in fhirpath there is maybe monad for ordinary programming language expressions like plus, logic etc - which is represented as collection of at most one element and list monad with implicit flattening for chaining

view this post on Zulip nicola (RIO/SS) (Aug 11 2018 at 20:51):

I see, in 4.5 runtime error is stated.

view this post on Zulip nicola (RIO/SS) (Aug 11 2018 at 20:57):

What i see in xpath/xquery not everything is a collection - for arithmetic and boolean logic they define just ordinary programming language types and semantic.

view this post on Zulip Paul Lynch (Oct 23 2019 at 19:00):

I just stumbled over this again. I don't see anything in 5.5.1 - iif that says the criterion is supposed to be coerced into a boolean. So, perhaps the description needs an update, or if not, then what is the result of iif(5, 1, 2)?

view this post on Zulip Paul Lynch (Oct 24 2019 at 14:30):

@Brian Postlethwaite Perhaps that belongs on a new topic?

view this post on Zulip Brian Postlethwaite (Oct 24 2019 at 20:57):

Yes, sorry.

view this post on Zulip Paul Lynch (Oct 24 2019 at 22:13):

@Bryn Rhodes ?

view this post on Zulip Bryn Rhodes (Oct 28 2019 at 16:37):

The general guidance in Singleton Evaluation of Collections applies to the expression argument. Since the conversion is defined as explicit, existence is interpreted as true, so the result of iif(5, 1, 2) is 1. Note that this means the result of iff(0, 1, 2) is also 1.

view this post on Zulip Bryn Rhodes (Oct 28 2019 at 16:37):

Seems like it would be worth a clarifying comment in the specification.

view this post on Zulip Paul Lynch (Oct 28 2019 at 16:40):

The clarifying comment I would like to see is that the iif criterion is expected to return a Boolean.

view this post on Zulip Bryn Rhodes (Oct 28 2019 at 17:17):

Agreed, submit a tracker?

view this post on Zulip Paul Lynch (Oct 28 2019 at 17:30):

Sure -- GF#25059

view this post on Zulip Grahame Grieve (Oct 28 2019 at 20:59):

So iif(, 1, 2 = 2?

view this post on Zulip Paul Lynch (Oct 28 2019 at 22:41):

I think you are missing some symbols.

view this post on Zulip Grahame Grieve (Oct 28 2019 at 22:54):

ok: iif(, 1, 2) = 2?

view this post on Zulip Bryn Rhodes (Oct 28 2019 at 23:41):

I think that would actually result in a syntax error, but this iif({ }, 1, 2) would result in 2, yes, because the empty collection would evaluate to an empty collection, which would result in the iif returning the _otherwise-result_ argument.

view this post on Zulip Paul Lynch (Oct 29 2019 at 15:23):

Also, I think iif(5, 1,2) would be an error, because the 5 is not "explicitly" cast to a Boolean.


Last updated: Apr 12 2022 at 19:14 UTC