| Crates.io | helios-fhir-gen |
| lib.rs | helios-fhir-gen |
| version | 0.1.16 |
| created_at | 2025-08-22 15:27:00.024894+00 |
| updated_at | 2025-09-11 12:52:59.131877+00 |
| description | The helios-fhir-gen crate is module that serves as the cornerstone for generating Rust code from official FHIR (Fast Healthcare Interoperability Resources) specifications. This tool transforms FHIR StructureDefinitions into Rust types, enabling type-safe interaction with FHIR resources across multiple specification versions. |
| homepage | https://github.com/HeliosSoftware/hfs/tree/main/crates/fhir-gen |
| repository | https://github.com/HeliosSoftware/hfs |
| max_upload_size | |
| id | 1806517 |
| size | 191,186 |
The helios-fhir-gen crate is module that serves as the cornerstone for generating Rust code from official FHIR (Fast Healthcare Interoperability Resources) specifications. This tool transforms FHIR StructureDefinitions into Rust types, enabling type-safe interaction with FHIR resources across multiple specification versions.
helios-fhir-gen has a singular, focused responsibility: generate Rust code for each supported FHIR version. It bridges the gap between the JSON-based FHIR specification files and the strongly-typed Rust ecosystem, providing:
The generated code powers the entire FHIR ecosystem in this project, serving as input for the main fhir crate and enabling FHIRPath operations in the fhirpath crate.
The crate includes a carefully curated set of hand-coded Rust structures and enums in src/initial_fhir_model.rs. These types represent the minimal subset necessary to:
Key bootstrap types include:
StructureDefinition - Core FHIR structure definition formatElementDefinition - Individual element specifications within structuresBundle - Container for collections of FHIR resourcesExtension - FHIR extension mechanism with choice typesAddress, Coding, CodeableConcept, etc.)These hand-coded types are the absolute minimum required to read and process the FHIR specification files themselves.
resources/{VERSION}/r4.rs, r5.rs)For released versions of the FHIR Specification (R4, R4B, and R5), specification files are copied from the FHIR Specification
and maintained in this repo in the resources folder.
For the latest upcoming release (R6), the specification files are automatically downloaded from https://build.fhir.org/definitions.json.zip during the build process. To trigger this download, build the crate with the R6 feature enabled:
cargo build -p helios-fhir-gen --features R6
The build script (build.rs) will automatically fetch the latest R6 specification files from HL7's build server and extract them to the resources/R6/ directory, ensuring you always have the most current development version.
The helios-fhir-gen binary provides a simple command-line interface for code generation:
# Generate code for default version (R4)
cargo run -p helios-fhir-gen
# Generate code for a specific FHIR version
cargo run -p helios-fhir-gen R5
cargo run -p helios-fhir-gen R4B
cargo run -p helios-fhir-gen R6
# Generate code for all supported versions
cargo run -p helios-fhir-gen --all
FHIR Generator - Process FHIR definitions
Usage: helios-fhir-gen [OPTIONS] [VERSION]
Arguments:
[VERSION] FHIR version to process
[possible values: R4, R4B, R5, R6]
Options:
-a, --all Process all versions
-h, --help Print help
# Generate only R5 code (for latest standard development)
helios-fhir-gen R5
# Generate all versions (for comprehensive compatibility)
helios-fhir-gen --all
# Use from build scripts or CI/CD
./target/debug/helios-fhir-gen R4
Generated code is written to crates/fhir/src/ with version-specific modules:
crates/fhir/src/r4.rs - R4 generated typescrates/fhir/src/r4b.rs - R4B generated typescrates/fhir/src/r5.rs - R5 generated typescrates/fhir/src/r6.rs - R6 generated typeshelios-fhir-gen --all to generate all version codehelios-fhir-gen R5 for focused developmentThe generated code works with Cargo feature flags in the main fhir crate:
# Build with specific FHIR version
cargo build --features R5
# Build with multiple versions
cargo build --features "R4,R5"
# Default to R4 if no features specified
cargo build
Add to your build script or Makefile:
# Complete build process
export RUST_MIN_STACK=8388608
cargo run -p helios-fhir-gen -- --all
cargo build --features R4,R4B,R5,R6
cargo test --features R4,R4B,R5,R6
Resources are organized by version in resources/{VERSION}/:
resources/
├── R4/
│ ├── profiles-resources.json # Core resources
│ ├── profiles-types.json # Data types
│ ├── profiles-others.json # Extensions
│ ├── valuesets.json # Terminology
│ ├── conceptmaps.json # Mappings
│ ├── search-parameters.json # Search defs
│ └── version.info # Version metadata
├── R4B/ [same structure]
├── R5/ [same structure]
└── R6/ [same structure]
The code generator produces:
value[x])#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Patient {
pub id: Option<String>,
pub extension: Option<Vec<Extension>>,
pub identifier: Option<Vec<Identifier>>,
pub active: Option<bool>,
pub name: Option<Vec<HumanName>>,
pub gender: Option<String>,
pub birth_date: Option<String>,
// ... additional fields
}
The generator includes comprehensive error handling:
Failed parsing of individual files produces warnings but doesn't halt the generation process, allowing partial code generation when possible.
resources/NEW_VERSION/FhirVersion enum in the main fhir crateWhen FHIR introduces new structural elements:
initial_fhir_model.rsAreas for potential enhancement:
helios-fhir-gen maintains minimal dependencies:
serde and serde_json - JSON parsing and serializationclap - Command-line argument parsinghelios-fhir - Access to FhirVersion enum (circular dependency managed carefully)This lean dependency set ensures fast compilation and reduces the risk of dependency conflicts in the broader ecosystem.
helios-fhir-gen is a mature, stable component that successfully generates working Rust code for all supported FHIR versions. Future development focuses on:
The crate serves as the foundation for the entire FHIR ecosystem in this project and maintains backward compatibility while supporting the latest FHIR specifications.