--- type: "fhirpath-function" title: "FHIRPath Function: iif" function: "iif" category: "Conversion" section: "5.5.1" source: "fhirpath/functions.json" --- # FHIRPath Function: iif > This is a [scoped function](#scoped-functions): The `criterion` argument is evaluated once (with `$this` set to the input value, and $index will be set to `0`).
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,
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 - **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 evaluate - `true-result`: `collection` - Result if criterion is true - `otherwise-result` (optional): `collection` - Result if criterion is false (optional) ## Type Mapping - `Any-Any` ## Example ```fhirpath iif(Patient.active, 'Active', 'Inactive') // returns 'Active' if patient is active, 'Inactive' otherwise ```