dcarbone / php-fhir
Tools for creating PHP classes from the HL7 FHIR Specification
Requires
- php: ^8.1
- ext-ctype: *
- ext-curl: *
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-simplexml: *
- ext-xmlreader: *
- ext-xmlwriter: *
- composer/semver: ^3.4
- psr/log: ^3.0
Requires (Dev)
- ext-zlib: *
- monolog/monolog: ^3.2.0
- phpunit/phpunit: ^10.5 || ^11.0
- spatie/temporary-directory: ^1.0 || ^2.0
Replaces
- php-fhir/common: *
- php-fhir/component-tests: *
- php-fhir/elements: *
- php-fhir/object-mapper: *
- php-fhir/parser: *
- php-fhir/resources: *
- php-fhir/utilities: *
- dev-main
- v4.x-dev
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v4.0.0-rc6
- v4.0.0-rc5
- v4.0.0-rc4
- v4.0.0-rc3
- v4.0.0-rc2
- v4.0.0-rc1
- v3.x-dev
- v3.2.0
- v3.1.0
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v3.0.0-rc8
- v3.0.0-rc7
- v3.0.0-rc6
- v3.0.0-rc5
- v3.0.0-rc4
- v3.0.0-rc3
- v3.0.0-rc2
- v3.0.0-rc1
- v2.x-dev
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.x-dev
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- 0.5.x-dev
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.x-dev
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.x-dev
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.2
- 0.1.1
- 0.1.0
- dev-bugfix/dependabot
This package is auto-updated.
Last update: 2026-04-02 03:27:13 UTC
README
Tools for generating PHP classes from the HL7 FHIR specification.
php-fhir reads the official FHIR XSD schema files and produces a fully-typed PHP library — complete with models for every FHIR type, JSON & XML (de)serialization, validation, and a ready-to-use FHIR REST client.
🚀 Just Want the Generated Code?
If you don't need to customise the generation process and just want usable FHIR models in your PHP project, grab the pre-built package:
➡️ dcarbone/php-fhir-generated
📖 Documentation
Full documentation is maintained on the project wiki:
| Page | Description |
|---|---|
| Getting Started | Prerequisites, installation, and downloading FHIR schemas |
| CLI Usage | Running the generator from the command line |
| Configuration Reference | All Config and VersionConfig options |
| Architecture | How the generator pipeline works internally |
| Generated Code | Understanding the output: namespaces, types, client, encoding |
| Testing | Running tests on the generator and on generated code |
| Contributing | Developer workflow and code-style notes |
Support Matrix
| PHPFHIR Version | PHP Versions | FHIR Versions | Supported |
|---|---|---|---|
| v4 | 8.1+ | DSTU1, DSTU2, STU3, R4, R4B, R5 | Yes |
| v3 | 8.1–8.4 | DSTU1, DSTU2, STU3, R4, R4B, R5 | No |
| v2 | 5.4–7.4 | DSTU1, DSTU2, STU3, R4 | No |
Requirements
- PHP 8.1 or newer
- Composer — getcomposer.org
- PHP extensions:
ctype,curl,dom,json,libxml,simplexml,xmlreader,xmlwriter - FHIR schemas: extracted XSD bundles for each version you wish to generate (see the Getting Started wiki page for download links)
Quick Start
1. Install
# Standalone git clone https://github.com/dcarbone/php-fhir.git cd php-fhir && composer install # — or as a Composer dependency in your own project — composer require dcarbone/php-fhir
2. Download FHIR Schemas
mkdir -p fhir-schemas/R4 curl -Lo fhir-schemas/R4.zip https://hl7.org/fhir/R4/fhir-codegen-xsd.zip unzip fhir-schemas/R4.zip -d fhir-schemas/R4
3. Generate
Option A — PHP script:
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use DCarbone\PHPFHIR\Builder; use DCarbone\PHPFHIR\Config; use DCarbone\PHPFHIR\Config\VersionConfig; $config = new Config( libraryPath: __DIR__ . '/output/src', versions: [ new VersionConfig(name: 'R4', schemaPath: __DIR__ . '/fhir-schemas/R4'), ], testsPath: __DIR__ . '/output/tests', // optional ); $builder = new Builder($config); $builder->render();
Option B — CLI (standalone checkout only):
./bin/generate.sh --versions R4 --logLevel info
See the CLI Usage and Configuration Reference wiki pages for full details.
Links
| Source | https://github.com/dcarbone/php-fhir |
| Pre-generated code | https://github.com/dcarbone/php-fhir-generated |
| Wiki / Docs | https://github.com/dcarbone/php-fhir/wiki |
| HL7 FHIR | https://hl7.org/fhir/ |