View raw Markdown
type: fhirpath-functionfunction: existscategory: Existencesection: 5.1.2source: fhirpath/functions.json

FHIRPath Function: exists

This is a scoped function: The criteria argument is evaluated for each item (setting $this and $index before each iteration); if any return true then the function returns true, otherwise false.

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.

<a name="fn-all"></a>

Summary

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')