PHPackages                             ardenexal/fhir-path - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ardenexal/fhir-path

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ardenexal/fhir-path
===================

FHIRPath 2.0 expression evaluation for PHP

0.2(2mo ago)24201MITPHPPHP &gt;=8.2

Since Feb 17Pushed 2mo agoCompare

[ Source](https://github.com/Ardenexal/fhir-path)[ Packagist](https://packagist.org/packages/ardenexal/fhir-path)[ RSS](/packages/ardenexal-fhir-path/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (13)Versions (7)Used By (1)

FHIRPath Component
==================

[](#fhirpath-component)

PHP implementation of the [FHIRPath 2.0 specification](http://hl7.org/fhirpath/N1/) for evaluating path expressions against FHIR resources.

Features
--------

[](#features)

- FHIRPath 2.0 compliant expression evaluation
- 50+ built-in functions (existence, filtering, string, math, date/time, type conversion)
- 20+ operators with correct precedence
- FHIR-aligned type system with `is`/`as` operators
- Expression caching with LRU eviction
- Pre-compilation for repeated evaluation

Quick Start
-----------

[](#quick-start)

```
use Ardenexal\FHIRTools\Component\FHIRPath\Service\FHIRPathService;

$service = new FHIRPathService();

// Evaluate against FHIR data
$result = $service->evaluate('Patient.name.given', $patient);

// Filtering
$result = $service->evaluate('name.where(use = "official").given.first()', $patient);

// Boolean check
$hasPhone = $service->evaluate('telecom.where(system = "phone").exists()', $patient);
```

### Compilation and Caching

[](#compilation-and-caching)

```
// Compile once, evaluate many times
$compiled = $service->compile('name.where(use = "official").given.first()');

foreach ($patients as $patient) {
    $result = $compiled->evaluate($patient);
}

// Cache statistics
$stats = $service->getCacheStats();
// ['hits' => 10, 'misses' => 2, 'size' => 5]
```

### Validation

[](#validation)

```
$isValid = $service->validate('name.given');        // true
$isValid = $service->validate('name.given.???');     // false
```

Supported Operations
--------------------

[](#supported-operations)

### Functions

[](#functions)

```
// Existence
$service->evaluate('name.exists()', $patient);
$service->evaluate('name.empty()', $patient);
$service->evaluate('telecom.all(system = "phone")', $patient);

// Filtering and projection
$service->evaluate('name.where(use = "official")', $patient);
$service->evaluate('name.select(given)', $patient);
$service->evaluate('name.first()', $patient);

// String
$service->evaluate('name.given.upper()', $patient);
$service->evaluate('name.family.substring(0, 3)', $patient);
$service->evaluate('name.given.matches("[A-Z].*")', $patient);

// Math
$service->evaluate('(42).abs()', null);
$service->evaluate('Observation.value.sum()', $bundle);

// Type
$service->evaluate('value.toInteger()', $observation);
$service->evaluate('value is Quantity', $observation);
```

### Operators

[](#operators)

```
// Comparison
$service->evaluate('age > 18', $patient);
$service->evaluate('status = "active"', $patient);

// Logical
$service->evaluate('age > 18 and status = "active"', $patient);
$service->evaluate('value > 100 or value < 0', $observation);

// Arithmetic
$service->evaluate('value * 2', $observation);
$service->evaluate('(value + 10) / 2', $observation);

// Union
$service->evaluate('name | telecom', $patient);
```

Error Handling
--------------

[](#error-handling)

```
use Ardenexal\FHIRTools\Component\FHIRPath\Exception\FHIRPathException;

try {
    $result = $service->evaluate('invalid..path', $patient);
} catch (FHIRPathException $e) {
    echo "FHIRPath error: {$e->getMessage()}";
}
```

Console Commands
----------------

[](#console-commands)

When used with the FHIRBundle:

```
# Evaluate expression
php bin/console fhir:path:evaluate "Patient.name.given" patient.json

# Validate syntax
php bin/console fhir:path:validate "name.where(use = 'official').given.first()"
```

Requirements
------------

[](#requirements)

- **PHP**: 8.3 or higher

Testing
-------

[](#testing)

This component includes comprehensive test coverage:

### Unit Tests

[](#unit-tests)

```
composer test:fhir-path
```

### Specification Conformance Tests

[](#specification-conformance-tests)

The component includes official FHIR FHIRPath specification conformance tests that validate compliance against the FHIR specification test cases:

```
# Run FHIRPath specification tests
composer test-fhirpath-spec
```

**Note**: These tests are currently in development as the FHIRPath evaluator implementation is being completed. The tests automatically load test cases from the official `fhir/fhir-test-cases` package and track implementation progress.

The specification tests are maintained in a separate test suite to:

- Allow focused development on specific FHIRPath features
- Track progress toward full specification compliance
- Prevent blocking other integration tests during development

License
-------

[](#license)

This component is released under the MIT License. See the [LICENSE](../../../LICENSE) file for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

6

Last Release

60d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/40bdcfdbd80eda272029a422eee67464bf9b82f26271252e9425a1d583c03d34?d=identicon)[Ardenexal](/maintainers/Ardenexal)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![Ardenexal](https://avatars.githubusercontent.com/u/2852475?v=4)](https://github.com/Ardenexal "Ardenexal (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ardenexal-fhir-path/health.svg)

```
[![Health](https://phpackages.com/badges/ardenexal-fhir-path/health.svg)](https://phpackages.com/packages/ardenexal-fhir-path)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

81733.7k](/packages/flow-php-flow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
