Skip to content
Daniel Carbone edited this page May 3, 2026 · 5 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 Documentation
DSTU1 (v0.0.82) DSTU1 Docs
DSTU2 (v1.0.2) DSTU2 Docs
STU3 (v3.0.2) STU3 Docs
R4 (v4.0.1) R4 Docs
R4B (v4.3.0) R4B Docs
R5 (v5.0.0) R5 Docs
R6 ballot (pre-release) R6 Docs

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