PHPackages                             romeldev/php-fhir-r5 - 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. [API Development](/categories/api)
4. /
5. romeldev/php-fhir-r5

ActiveLibrary[API Development](/categories/api)

romeldev/php-fhir-r5
====================

HL7 FHIR R5 PHP library, PHP 7.4+ compatible. Generated from dcarbone/php-fhir and downgraded with Rector.

v0.1.0(2mo ago)01Apache-2.0PHPPHP &gt;=7.4

Since Apr 27Pushed 2mo agoCompare

[ Source](https://github.com/romeldev/php-fhir-r5)[ Packagist](https://packagist.org/packages/romeldev/php-fhir-r5)[ RSS](/packages/romeldev-php-fhir-r5/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

romeldev/php-fhir-r5
====================

[](#romeldevphp-fhir-r5)

HL7 FHIR R5 PHP library, compatible with **PHP 7.4+**.

This package is a downgraded build of [dcarbone/php-fhir](https://github.com/dcarbone/php-fhir) (which targets PHP 8.1+), produced with [Rector](https://getrector.com/) so it can be consumed by legacy applications — typically Laravel projects still on PHP 7.4.

It provides fully-typed PHP models for every FHIR R5 resource and data type, JSON &amp; XML (de)serialization, validation rules, and a ready-to-use FHIR REST client.

---

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

[](#requirements)

- PHP **7.4** or newer
- PHP extensions: `ctype`, `curl`, `dom`, `json`, `libxml`, `simplexml`, `xmlreader`, `xmlwriter`

---

Installation
------------

[](#installation)

```
composer require romeldev/php-fhir-r5
```

---

Usage
-----

[](#usage)

All classes live under the `Romeldev\Fhir` namespace. FHIR types for the R5 version are nested under `Romeldev\Fhir\Versions\R5\Types`.

### Parse a FHIR JSON resource

[](#parse-a-fhir-json-resource)

```
use Romeldev\Fhir\Versions\R5\Version;
use Romeldev\Fhir\Versions\R5\Types\FHIRBase\FHIRResource\FHIRDomainResource\FHIRPatient;

$version = new Version();
$json = file_get_contents('/path/to/patient.json');
$decoded = json_decode($json);

$patient = FHIRPatient::jsonUnserialize(
    $decoded,
    $version->getConfig()->getUnserializeConfig()
);

foreach ($patient->getName() as $name) {
    echo $name->getFamily()->getValue() . "\n";
}
```

### Serialize a resource back to JSON

[](#serialize-a-resource-back-to-json)

```
$encoded = json_encode($patient);
```

### Parse FHIR XML

[](#parse-fhir-xml)

```
$xml = simplexml_load_file('/path/to/patient.xml');
$patient = FHIRPatient::xmlUnserialize(
    $xml,
    $version->getConfig()->getUnserializeConfig()
);
```

### Use the REST client

[](#use-the-rest-client)

```
use Romeldev\Fhir\Versions\R5\VersionClient;
use Romeldev\Fhir\Client\Client;
use Romeldev\Fhir\Encoding\SerializeFormatEnum;
use Romeldev\Fhir\Versions\R5\VersionResourceTypeEnum;

$client = new VersionClient(
    new Client('https://my-fhir-server.example.com/fhir'),
    $version
);

$response = $client->read(
    VersionResourceTypeEnum::PATIENT,
    'example-patient-id',
    SerializeFormatEnum::JSON
);

if ($response->getCode() === 200) {
    $patient = FHIRPatient::jsonUnserialize(
        json_decode($response->getResp()),
        $version->getConfig()->getUnserializeConfig()
    );
}
```

---

Namespace layout
----------------

[](#namespace-layout)

```
Romeldev\Fhir\
├── Client\               → HTTP client, response objects, enums (method, sort)
├── Encoding\             → JSON/XML (un)serialization configs, XMLWriter helper
├── Types\                → Shared interfaces (ElementTypeInterface, etc.)
├── Validation\           → Validator + rule classes
└── Versions\R5\
    ├── Version              → entry point for the R5 version
    ├── VersionClient        → R5-specific REST client
    ├── VersionConfig        → config used by (un)serialize
    ├── VersionResourceTypeEnum
    └── Types\               → every FHIR R5 resource and data type

```

---

Compatibility notes
-------------------

[](#compatibility-notes)

- **No PHP 8+ features at runtime.** Enums, union types, `match`, named arguments and `mixed` have been transformed to their PHP 7.4 equivalents (classes with constants, PHPDoc `@return`, `switch`, positional args, untyped).
- **Constants instead of enums.** What was `enum Foo: string` in the original is now `class Foo { public const XML = 'xml'; ... }`. Use `Foo::XML` as before — the API surface is unchanged. Type hints that originally referenced these enums (e.g. `SerializeFormatEnum $format`) have been rewritten to `string` since the constants are now string literals.
- **`#[Attribute]` markers** on classes are preserved as `#[...]` lines — PHP 7.4 parses them as single-line comments, so they are inert.
- **Warnings-free** under PHP 7.4 `php -l` (including `XMLWriter` subclass signature compatibility).
- **Test suite passes on PHP 7.4** — 5368 tests / 19743 assertions, using PHPUnit 9.6 and `symfony/polyfill-php80` (for `preg_last_error_msg()`).

### Running the test suite

[](#running-the-test-suite)

```
composer install
composer test          # 5368 tests, no network required
composer test:all      # all tests, requires a FHIR R5 server at 127.0.0.1:8080/R5
```

---

Upstream &amp; attribution
--------------------------

[](#upstream--attribution)

All generation logic, schemas and the original library architecture belong to **Daniel Carbone** and the [dcarbone/php-fhir](https://github.com/dcarbone/php-fhir) project. This package only:

1. Generates under a different PHP namespace (`Romeldev\Fhir` instead of `DCarbone\PHPFHIRGenerated`).
2. Transpiles the output down to PHP 7.4 with Rector.

If you can run PHP 8.1+, prefer the upstream [dcarbone/php-fhir-generated](https://github.com/dcarbone/php-fhir-generated) directly.

---

License
-------

[](#license)

Apache License 2.0 — same as upstream. See [LICENSE](LICENSE).

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance83

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

88d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/64551435?v=4)[Romel Diaz](/maintainers/romeldev)[@romeldev](https://github.com/romeldev)

---

Top Contributors

[![romeldev](https://avatars.githubusercontent.com/u/64551435?v=4)](https://github.com/romeldev "romeldev (1 commits)")

---

Tags

interoperabilityhl7fhirhealthcarer5php74

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/romeldev-php-fhir-r5/health.svg)

```
[![Health](https://phpackages.com/badges/romeldev-php-fhir-r5/health.svg)](https://phpackages.com/packages/romeldev-php-fhir-r5)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.2k](/packages/composer-composer)[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[dcarbone/php-fhir

Tools for creating PHP classes from the HL7 FHIR Specification

149296.2k1](/packages/dcarbone-php-fhir)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19566.0M1.8k](/packages/drupal-core)[wikimedia/parsoid

Parsoid, a bidirectional parser between wikitext and HTML5

187557.3k3](/packages/wikimedia-parsoid)

PHPackages © 2026

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