Skip to content
Daniel Carbone edited this page Apr 2, 2026 · 4 revisions

php-fhir-generated

Pre-generated PHP classes for HL7 FHIR resources, produced by dcarbone/php-fhir.

This library provides strongly-typed PHP models for every FHIR resource, element, and primitive across multiple FHIR versions, along with built-in serialization, validation, and an HTTP client.

Supported FHIR Versions

Version FHIR Spec
DSTU1 v0.x
DSTU2 v1.x
STU3 v3.x
R4 v4.0
R4B v4.3
R5 v5.x

Requirements

  • PHP 8.1+
  • Extensions: curl, dom, json, libxml, simplexml, xmlreader, xmlwriter

Quick Start

Installation via Composer

composer require dcarbone/php-fhir-generated

Standalone (No Composer)

  1. Clone or download this repository
  2. Require the root autoloader:
require __DIR__ . '/src/DCarbone/PHPFHIRGenerated/Autoloader.php';

Basic Example (R4)

<?php

use DCarbone\PHPFHIRGenerated\Client\Client;
use DCarbone\PHPFHIRGenerated\Client\Config;
use DCarbone\PHPFHIRGenerated\Encoding\SerializeFormatEnum;
use DCarbone\PHPFHIRGenerated\Versions\R4\Types\FHIRElement\FHIRHumanName;
use DCarbone\PHPFHIRGenerated\Versions\R4\Types\FHIRResource\FHIRDomainResource\FHIRPatient;
use DCarbone\PHPFHIRGenerated\Versions\R4\Version;
use DCarbone\PHPFHIRGenerated\Versions\R4\VersionClient;

// Build a Patient locally
$patient = new FHIRPatient(
    id: 'patient-1',
    language: 'en-us',
    name: [
        new FHIRHumanName(given: ['Real'], family: 'Human'),
    ],
);

// Fetch a Patient from a FHIR server
$config = new Config(
    address: 'https://your-r4-fhir-server',
    defaultFormat: SerializeFormatEnum::JSON,
);
$client = new VersionClient(new Client($config), new Version());
$patient = $client->readOnePatient(resourceID: 'patient-2');

Wiki Contents

  • Configuration — Version configuration, serialization and unserialization options
  • Constructing Types — Creating FHIR resource, element, and primitive instances
  • Serialization — Encoding and decoding resources in JSON and XML
  • FHIR Client — Using the built-in HTTP client to interact with FHIR servers
  • Resource Parsing — Automatically parsing arbitrary FHIR responses
  • Validation — Built-in validation rules and custom rule creation
  • Type System — Understanding the type hierarchy and interfaces
  • Autoloading — How class loading works with and without Composer

Related Projects

License

Apache-2.0 — see LICENSE.

Clone this wiki locally