FHIRPath Function: iif
This is a scoped function: The
criterionargument is evaluated once (with$thisset to the input value, and $index will be set to0).<br/> If it returnstrue, then thetrue-resultargument is evaluated (with$thisset to the input value, and$indexset to0) and returned,<br/> otherwise thefalse-resultargument is evaluated (with$thisset to the input value, and$indexset to0) and returned.
The iif function in FHIRPath is an immediate if, also known as a conditional operator (such as the C programming language's ? : operator).
The criterion expression is expected to evaluate to a Boolean.
If criterion is true, the function returns the value of the true-result argument.
If criterion is false or an empty collection, the function returns otherwise-result, unless the optional otherwise-result is not given, in which case the function returns an empty collection.
Note that short-circuit behavior is expected in this function. In other words, true-result should only be evaluated if the criterion evaluates to true, and otherwise-result should only be evaluated otherwise. For implementations, this means delaying evaluation of the output arguments (specifically true-result and otherwise-result) to remove the chance that their evaluation throws an error and terminates the expression early.
If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
Summary
- Category: Conversion
- Section:
5.5.1 - Return Type:
collection - Empty Input Result:
empty - Errors on Multiple Input:
false
Description
The iif function in FHIRPath is an immediate if, also known as a conditional operator. If criterion is true, the function returns the value of the true-result argument. If criterion is false or an empty collection, the function returns otherwise-result.
Arguments
criterion:expression- Boolean expression to evaluatetrue-result:collection- Result if criterion is trueotherwise-result(optional):collection- Result if criterion is false (optional)
Type Mapping
Example
iif(Patient.active, 'Active', 'Inactive') // returns 'Active' if patient is active, 'Inactive' otherwise