PHPackages                             ardenexal/fhir-code-generation - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ardenexal/fhir-code-generation

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ardenexal/fhir-code-generation
==============================

FHIR code generation component for PHP FHIRTools

0.2(1mo ago)14201MITPHPPHP &gt;=8.2

Since Feb 17Pushed 2mo agoCompare

[ Source](https://github.com/Ardenexal/fhir-code-generation)[ Packagist](https://packagist.org/packages/ardenexal/fhir-code-generation)[ RSS](/packages/ardenexal-fhir-code-generation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (21)Versions (7)Used By (1)

FHIR Code Generation Component
==============================

[](#fhir-code-generation-component)

PHP library for generating FHIR model classes from StructureDefinitions. Produces PHP classes, data types, primitives, and enums from FHIR Implementation Guide packages.

Features
--------

[](#features)

- Generate PHP classes from FHIR StructureDefinitions
- Generate PHP enums from FHIR ValueSets
- Package management with FHIR registry integration
- Semantic version resolution and dependency handling
- Local package caching with integrity verification
- Offline mode for air-gapped environments

How It Works
------------

[](#how-it-works)

The code generation pipeline:

1. **Package Loading** — Downloads and caches FHIR IG packages (`.tgz`) from `packages.fhir.org`
2. **Definition Parsing** — Reads StructureDefinition and ValueSet JSON resources from the package
3. **Class Generation** — Produces PHP classes using [Nette PhpGenerator](https://github.com/nette/php-generator):
    - Resources (Patient, Observation, etc.)
    - Data Types (HumanName, Address, etc.)
    - Primitives (FHIRString, FHIRInteger, etc.)
    - Backbone Elements (nested within parent resource namespaces)
4. **Enum Generation** — Produces PHP enums from required ValueSets (AdministrativeGender, etc.)

Usage
-----

[](#usage)

Generation is driven through the `fhir:generate` console command:

```
# Generate R4 models
php bin/console fhir:generate --package=hl7.fhir.r4.core -vvv

# Generate R4B models
php bin/console fhir:generate --package=hl7.fhir.r4b.core -vvv

# Generate multiple versions at once
php bin/console fhir:generate --package=hl7.fhir.r4.core --package=hl7.fhir.r4b.core -vvv

# Offline mode (cached packages only)
php bin/console fhir:generate --package=hl7.fhir.r4.core --offline -vvv
```

The terminology package (`hl7.terminology.r4`) is automatically included as a dependency.

### Composer Scripts

[](#composer-scripts)

```
composer run generate-models-r4      # R4 only
composer run generate-models-r4b     # R4B only
composer run generate-models-all     # R4 + R4B + R5
```

Core Classes
------------

[](#core-classes)

### FHIRModelGenerator

[](#fhirmodelgenerator)

Generates PHP classes from individual StructureDefinitions:

```
use Ardenexal\FHIRTools\Component\CodeGeneration\Generator\FHIRModelGenerator;

// Called internally by the generate command for each StructureDefinition
$classType = $generator->generate($structureDefinition, $version, $builderContext);
```

### FHIRValueSetGenerator

[](#fhirvaluesetgenerator)

Generates PHP enums from ValueSet definitions:

```
use Ardenexal\FHIRTools\Component\CodeGeneration\Generator\FHIRValueSetGenerator;

$enumType = $generator->generateEnum($valueSetDefinition, $version, $builderContext);
```

### PackageLoader

[](#packageloader)

Manages FHIR package downloads, caching, and extraction:

```
use Ardenexal\FHIRTools\Component\CodeGeneration\Package\PackageLoader;

// Install a package (downloads if not cached)
$metadata = $loader->installPackage('hl7.fhir.r4.core', '4.0.1');

// Load StructureDefinitions into the build context
$definitions = $loader->loadPackageStructureDefinitions($metadata);

// Check cache
$isCached = $loader->isPackageCached('hl7.fhir.r4.core', '4.0.1');
```

### BuilderContext

[](#buildercontext)

Holds state during generation — loaded definitions, generated classes, namespace registrations:

```
use Ardenexal\FHIRTools\Component\CodeGeneration\Context\BuilderContext;

$context = new BuilderContext();
$context->addDefinition($url, $definition);
```

Error Handling
--------------

[](#error-handling)

```
use Ardenexal\FHIRTools\Component\CodeGeneration\Exception\GenerationException;
use Ardenexal\FHIRTools\Component\CodeGeneration\Exception\PackageException;

try {
    $metadata = $loader->installPackage('hl7.fhir.r4.core');
} catch (PackageException $e) {
    // Package download, extraction, or integrity failures
} catch (GenerationException $e) {
    // Code generation failures
}
```

Non-fatal errors are collected via `ErrorCollector` and reported at the end of generation.

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

[](#requirements)

- **PHP**: 8.3 or higher

License
-------

[](#license)

This component is released under the MIT License. See the [LICENSE](../../../LICENSE) file for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

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

Every ~6 days

Total

6

Last Release

59d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/40bdcfdbd80eda272029a422eee67464bf9b82f26271252e9425a1d583c03d34?d=identicon)[Ardenexal](/maintainers/Ardenexal)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")[![Ardenexal](https://avatars.githubusercontent.com/u/2852475?v=4)](https://github.com/Ardenexal "Ardenexal (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ardenexal-fhir-code-generation/health.svg)

```
[![Health](https://phpackages.com/badges/ardenexal-fhir-code-generation/health.svg)](https://phpackages.com/packages/ardenexal-fhir-code-generation)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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