View raw Markdown
type: fhirpath-functionfunction: iifcategory: Conversionsection: 5.5.1source: fhirpath/functions.json

FHIRPath Function: iif

This is a scoped function: The criterion argument is evaluated once (with $this set to the input value, and $index will be set to 0).<br/> If it returns true, then the true-result argument is evaluated (with $this set to the input value, and $index set to 0) and returned,<br/> otherwise the false-result argument is evaluated (with $this set to the input value, and $index set to 0) 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

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

Type Mapping

Example

iif(Patient.active, 'Active', 'Inactive') // returns 'Active' if patient is active, 'Inactive' otherwise