php-fhir

April 21, 2026 ยท View on GitHub

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:

PageDescription
Getting StartedPrerequisites, installation, and downloading FHIR schemas
CLI UsageRunning the generator from the command line
Configuration ReferenceAll Config and VersionConfig options
ArchitectureHow the generator pipeline works internally
Generated CodeUnderstanding the output: namespaces, types, client, encoding
TestingRunning tests on the generator and on generated code
ContributingDeveloper workflow and code-style notes

Support Matrix

PHPFHIR VersionPHP VersionsFHIR VersionsSupported
v4>= 8.1DSTU1, DSTU2, STU3, R4, R4B, R5, R6 (pre-release)Yes
v3>= 8.1, < 8.5DSTU1, DSTU2, STU3, R4, R4B, R5No
v25.4โ€“7.4DSTU1, DSTU2, STU3, R4No

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.


Sourcehttps://github.com/dcarbone/php-fhir
Pre-generated codehttps://github.com/dcarbone/php-fhir-generated
Wiki / Docshttps://github.com/dcarbone/php-fhir/wiki
HL7 FHIRhttps://hl7.org/fhir/

License

Apache License 2.0