--- type: "fhirpath-function" title: "FHIRPath Function: exists" function: "exists" category: "Existence" section: "5.1.2" source: "fhirpath/functions.json" --- # FHIRPath Function: exists > This is a [scoped function](#scoped-functions): 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: ``` fhirpath 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 - `criteria` (optional): `expression` - Optional criteria to filter the elements ## Type Mapping - `Any-Boolean` ## Example ```fhirpath Patient.name.exists() Patient.identifier.exists(use = 'official') Patient.telecom.exists(system = 'phone' and use = 'mobile') ```