Inferensys

Glossary

FHIRPath

A path-based navigation and extraction language, analogous to XPath for XML, designed to operate on and evaluate expressions against FHIR data structures.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
EXPRESSION LANGUAGE

What is FHIRPath?

FHIRPath is a path-based navigation and extraction language, analogous to XPath for XML, specifically designed to evaluate expressions and extract data from FHIR (Fast Healthcare Interoperability Resources) structures.

FHIRPath is a path-based navigation and extraction language for FHIR data. Modeled on XPath, it provides a concise, composable syntax for traversing the hierarchical structure of FHIR resources, evaluating invariants, and extracting specific values. It is the standard expression language used within FHIR profiles, StructureDefinition invariants, and Questionnaire logic to define constraints and calculated fields.

The language operates on a tree model of a FHIR instance, returning a collection of values. It supports boolean logic, string manipulation, collection filtering, and type conversion. FHIRPath is integral to FHIR validation, enabling implementers to express complex cross-field constraints that cannot be defined by simple cardinality or data type rules, ensuring semantic conformance.

EXPRESSION LANGUAGE

Key Features of FHIRPath

A path-based navigation and extraction language, analogous to XPath for XML, designed to evaluate expressions against FHIR data structures for clinical decision support, data validation, and quality measurement.

01

Path-Based Navigation

FHIRPath uses a dot-notation syntax to traverse nested FHIR resources and elements, similar to XPath for XML documents.

  • Navigate complex hierarchies: Patient.name.given
  • Access list indices: Patient.name[0].family
  • Use wildcards: Bundle.entry.resource.*
  • Filter with predicates: Observation.component.where(code.coding.code = '8480-6')

This enables precise extraction of specific clinical data points from deeply nested FHIR structures without custom parsing code.

02

Rich Function Library

FHIRPath includes a comprehensive set of built-in functions for data manipulation and evaluation.

  • String operations: startsWith(), contains(), replace(), substring()
  • Aggregation: count(), sum(), avg(), min(), max()
  • Logical operators: exists(), allTrue(), anyTrue(), all()
  • Type conversion: toString(), toInteger(), toDecimal(), toBoolean()
  • Date/time math: today(), now(), yearsBetween(), monthsBetween()

Example: Observation.valueQuantity.value > 140 evaluates a blood pressure threshold.

03

FHIR-Specific Operators

FHIRPath extends standard expression languages with healthcare-specific operators designed for clinical data types.

  • as operator: Safe type casting, e.g., Observation.value as Quantity
  • is operator: Type checking, e.g., Observation.value is CodeableConcept
  • ~ equivalence: Compares coded concepts semantically, not just string equality
  • $this keyword: References the current context node in nested expressions
  • Extension access: Patient.extension('http://hl7.org/fhir/us/core/StructureDefinition/us-core-race').value

These operators handle the nuances of medical terminologies and FHIR's polymorphic data types.

04

Invariant Validation

FHIRPath is the primary language for defining constraints in FHIR profiles and implementation guides using the constraint element.

  • Define co-occurrence rules: name.given.exists() or name.family.exists()
  • Enforce value ranges: value >= 0 and value <= 100
  • Validate cross-field logic: onsetDateTime.empty() or onsetAge.empty()
  • Check terminology bindings: code.memberOf('http://hl7.org/fhir/ValueSet/observation-codes')

These invariants are evaluated by the FHIR Validator to ensure resource conformance against profiles like US Core.

05

Context-Aware Evaluation

FHIRPath expressions execute against a dynamic evaluation context that includes the focus resource, root resource, and environment variables.

  • %context: Access the current focus node being evaluated
  • %resource: Reference the root resource containing the focus
  • %rootResource: Access the top-level resource in a Bundle
  • %ucum: Access UCUM unit conversion services
  • %terminologies: Access terminology service for code validation

This context model enables expressions that navigate both downward into nested elements and upward to parent structures, critical for complex clinical rules.

06

Integration with CDS Hooks

FHIRPath serves as the expression language for CDS Hooks card rules and prefetch templates, enabling dynamic clinical decision support.

  • Define trigger conditions: Patient.birthDate < today() - 65 years
  • Construct prefetch queries: Observation?patient={{context.patientId}}&code=4548-4
  • Evaluate response cards: MedicationRequest.status = 'active'
  • Link to SMART on FHIR apps for interactive decision support

This integration allows EHR systems to invoke context-aware clinical guidance at specific points in the clinician workflow.

FHIRPATH ESSENTIALS

Frequently Asked Questions

Clear, technical answers to the most common questions about navigating and extracting data from FHIR resources using the FHIRPath expression language.

FHIRPath is a path-based navigation and extraction language, analogous to XPath for XML, designed specifically to evaluate and traverse FHIR (Fast Healthcare Interoperability Resources) data structures. It operates on the logical tree of a FHIR resource, not its serialized JSON or XML format. The language processes a sequence of expressions, where each expression takes a collection of items as input and produces a new collection as output. This functional, side-effect-free design ensures deterministic evaluation. FHIRPath is integral to the FHIR specification itself, used to define invariants in StructureDefinition profiles, express search parameter paths, and power Clinical Quality Language (CQL) logic. It provides a standardized way to write a single expression that works identically across all FHIR serialization formats, abstracting away the syntactic differences between JSON, XML, and RDF representations.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.