FHIRPath cheat sheet
The FHIRPath expressions you actually reach for day to day: walking into a resource, filtering collections, checking whether something exists, and pulling values out of strings.
FHIRPath is the expression language used across FHIR for invariants, search parameters, and slicing. The examples below run in the Interoperall FHIRPath evaluator and cover the most common patterns.
Paste a resource into the evaluator, type an expression, and you get the matching values back. Every expression here uses functions and operators the evaluator supports.
Navigation and indexing
| Expression | What it does | Example |
|---|---|---|
| Patient.name | Select the name elements of a Patient | Returns the HumanName collection |
| name.family | Walk into a child element | Family name from each name |
| name.given | Select a repeating child element | All given names |
| name[0] | Index into a collection (zero-based) | The first name |
| name.given[0] | Chain navigation and indexing | First given name of each name |
Filtering and projection
| Expression | What it does | Example |
|---|---|---|
| where(use = 'official') | Keep only items matching a condition | name.where(use = 'official') |
| select(family) | Project each item to a sub-expression | name.select(family) |
| distinct() | Remove duplicate values | name.given.distinct() |
| where(system = 'phone') | Filter by a coded field | telecom.where(system = 'phone').value |
Existence and counting
| Expression | What it does | Example |
|---|---|---|
| exists() | True if the collection has any items | identifier.exists() |
| empty() | True if the collection is empty | deceased.empty() |
| count() | Number of items in the collection | name.given.count() |
| first() | First item only | name.first().family |
| last() | Last item only | name.last() |
| single() | The one item (errors if more than one) | identifier.single() |
| not() | Boolean negation | active.not() |
Comparison and logic
| Operator | What it does | Example |
|---|---|---|
| = | Equality | gender = 'female' |
| != | Inequality | use != 'old' |
| < <= > >= | Ordered comparison (numbers, strings) | multipleBirthInteger > 1 |
| and / or | Boolean combination | active = true and gender = 'male' |
| is | Type test | deceased is boolean |
String functions
| Function | What it does | Example |
|---|---|---|
| length() | Length of a string | name.family.length() |
| substring(start, len?) | Substring from a start index | name.family.substring(0, 3) |
| startsWith('x') | True if the string starts with the argument | name.family.startsWith('Sm') |
| endsWith('x') | True if the string ends with the argument | name.family.endsWith('th') |
| contains('x') | True if the string contains the substring | name.family.contains('mit') |
| matches('regex') | Regular-expression test | telecom.value.matches('^04') |
| replace('a', 'b') | Replace all occurrences | name.family.replace('-', ' ') |
Type filtering and conversion
| Function | What it does | Example |
|---|---|---|
| ofType(Type) | Keep items of a given resource type | entry.resource.ofType(Patient) |
| toString() | Convert a single value to a string | multipleBirthInteger.toString() |
| toInteger() | Convert a single value to an integer | '12'.toInteger() |
| iif(cond, then, else?) | Inline conditional | iif(active, 'on', 'off') |
Notes
- FHIRPath collections are zero-indexed: name[0] is the first item.
- The Interoperall evaluator supports the functions and operators listed above. The full FHIRPath specification defines more (such as aggregate() and resolve()); reach for the spec when you need them.
- String functions operate on a single string. Apply them after narrowing to one value, for example with first() or an index.
Frequently asked questions
What is FHIRPath used for?
FHIRPath is the expression language FHIR uses for invariants (constraints), search parameter definitions, slicing discriminators, and extracting values from resources. It is the standard way to navigate and query a FHIR resource.
How do I filter a FHIR collection in FHIRPath?
Use where() with a boolean condition. For example, name.where(use = 'official') keeps only the names whose use is official. Combine it with select() to then project a child element.
Is FHIRPath zero-indexed?
Yes. The first item in a collection is index 0, so name[0] selects the first name.
Can I test these expressions online?
Yes. The Interoperall FHIRPath evaluator runs these expressions in your browser against a resource you paste in, so nothing is uploaded.