FHIRPath Function: exists
This is a scoped function: The
criteriaargument is evaluated for each item (setting$thisand$indexbefore each iteration); if any returntruethen the function returnstrue, otherwisefalse.
Returns true if the input collection has any items (optionally filtered by the criteria), and false otherwise.
This is the opposite of empty(), and as such is a shorthand for empty().not(). If the input collection is empty ({ }), the result is false.
Using the optional criteria can be considered a shorthand for where(criteria).exists().
Note that a common term for this function is any.
The following examples illustrate some potential uses of the exists() function:
Patient.name.exists()
Patient.identifier.exists(use = 'official')
Patient.telecom.exists(system = 'phone' and use = 'mobile')
Patient.generalPractitioner.exists(resolve() is Practitioner)
The first example returns true if the Patient has any name elements.
The second example returns true if the Patient has any identifier elements that have a use element equal to 'official'.
The third example returns true if the Patient has any telecom elements that have a system element equal to 'phone' and a use element equal to 'mobile'.
And finally, the fourth example returns true if the Patient has any generalPractitioner elements of type Practitioner.
Summary
- Category: Existence
- Section:
5.1.2 - Return Type:
Boolean - Empty Input Result:
false - Errors on Multiple Input:
false
Description
Returns true if the input collection has any elements (optionally filtered by the criteria), and false otherwise. This is the opposite of empty(), and as such is a shorthand for empty().not().
Arguments
Type Mapping
Example
Patient.name.exists()
Patient.identifier.exists(use = 'official')
Patient.telecom.exists(system = 'phone' and use = 'mobile')