Stream: fhirpath
Topic: iif criterium
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 [ ]?
Grahame Grieve (Aug 07 2018 at 21:28):
the expression will always be evaulatable to one of the following values: true | false | null
Grahame Grieve (Aug 07 2018 at 21:28):
I guess that if it evaluates to null, do neither true or false
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)?
Grahame Grieve (Aug 07 2018 at 21:37):
null will propagate. collection boolean evaluation is explicitly described
Grahame Grieve (Aug 07 2018 at 21:37):
section 4.5
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.
Grahame Grieve (Aug 07 2018 at 21:55):
I'm not sure about the iif bit - @Bryn Rhodes ?
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).
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?
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.
nicola (RIO/SS) (Aug 09 2018 at 07:45):
@Grahame Grieve @Bryn Rhodes just confirm empty means false?
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.
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.
nicola (RIO/SS) (Aug 11 2018 at 20:39):
But non of programming languages?
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.
Bryn Rhodes (Aug 11 2018 at 20:41):
Not sure what you mean.
nicola (RIO/SS) (Aug 11 2018 at 20:41):
with singleton semantic should we treat everything with more than 1 element as runtime error?
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 :)
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
nicola (RIO/SS) (Aug 11 2018 at 20:51):
I see, in 4.5 runtime error is stated.
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.
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)
?
Paul Lynch (Oct 24 2019 at 14:30):
@Brian Postlethwaite Perhaps that belongs on a new topic?
Brian Postlethwaite (Oct 24 2019 at 20:57):
Yes, sorry.
Paul Lynch (Oct 24 2019 at 22:13):
@Bryn Rhodes ?
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.
Bryn Rhodes (Oct 28 2019 at 16:37):
Seems like it would be worth a clarifying comment in the specification.
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.
Bryn Rhodes (Oct 28 2019 at 17:17):
Agreed, submit a tracker?
Paul Lynch (Oct 28 2019 at 17:30):
Sure -- GF#25059
Grahame Grieve (Oct 28 2019 at 20:59):
So iif(, 1, 2 = 2?
Paul Lynch (Oct 28 2019 at 22:41):
I think you are missing some symbols.
Grahame Grieve (Oct 28 2019 at 22:54):
ok: iif(, 1, 2)
= 2?
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.
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