Stream: fhirpath
Topic: do all functions work on repeating fields?
Lee Surprenant (Mar 16 2022 at 12:25):
In our implementation, only certain functions will work on repeating fields (i.e. an "input collection" with more than one item).
I am never sure if this is correct or not...are all functions supposed to work over multiple elements?
If not, is there a way to tell if a function should work over multiple inputs?
Recently this came up on https://chat.fhir.org/#narrow/stream/179175-argonaut/topic/Conditions.20warning.20constraint.20bug and so I thought that would be a good example to drive discussion.
Bryn Rhodes (Mar 16 2022 at 14:24):
In the type system, yes, everything is a collection, but certain functions require singleton collections, as documented in the signature of the function. From the Functions topic:
If the function expects the argument passed to a parameter to be a single value (e.g. startsWith(prefix: String)) and it is passed an argument that evaluates to a collection with multiple items, or to a collection with an item that is not of the required type (or cannot be converted to the required type), the evaluation of the expression will end and an error will be signaled to the calling environment.
Bryn Rhodes (Mar 16 2022 at 14:25):
So if the signature indicates the argument is of some type, rather than a collection
, then it expects a singleton of that type.
Lee Surprenant (Mar 16 2022 at 15:58):
thanks Bryn. I read that section as being specific to the arguments/parameters of a function (passed within ()
) and not to the input collection. is that wrong?
Lee Surprenant (Mar 16 2022 at 16:12):
In some cases, the function definition explicitly states that an input collection must have a single item.
For example, for toString() : String
it says:
If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
Lee Surprenant (Mar 16 2022 at 16:13):
But other methods, like length() : Integer
have no indication one way or the other
Returns the length of the input string. If the input collection is empty ({ }), the result is empty.
Lee Surprenant (Mar 16 2022 at 16:14):
What should length()
do if the input is a collection?
Lee Surprenant (Mar 16 2022 at 16:27):
FWIW there are just a few functions that don't define what they should do (I thought there were more)...so maybe the answer is to open a JIRA so that we can get clarifications on each one individually?
Last updated: Apr 12 2022 at 19:14 UTC