Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
FHIR
The helios-fhir crate is the comprehensive FHIR (Fast Healthcare Interoperability Resources) specification model implementation that contains strongly-typed Rust representations of all FHIR data types, and resourcess for each supported version of the FHIR specification.
Purpose and Scope
fhir serves as the central module for FHIR specification model code, providing:
- Complete FHIR Type System: Rust implementations of all FHIR resources, data types, and primitive types
- Multi-Version Support: Support for FHIR R4, R4B, R5, and R6 specifications
- Type Safety: Compile-time guarantees for FHIR data structure correctness
- Serialization/Deserialization: Full JSON compatibility with official FHIR examples
- FHIRPath Integration: Native support for FHIRPath expressions through generated traits
The crate transforms the official HL7 FHIR specifications into idiomatic, type-safe Rust code that can be used in healthcare applications, research tools, and interoperability systems.
Architecture Overview
Version-Based Module Structure
The crate is organized around FHIR specification versions, with each version contained in its own module:
// Access different FHIR versions
use Patient; // FHIR R4 Patient resource
use Patient; // FHIR R4B Patient resource
use Patient; // FHIR R5 Patient resource
use Patient; // FHIR R6 Patient resource
Generated vs Hand-Coded Content
The crate combines:
-
Generated Code (95%): Version-specific modules (
r4.rs,r4b.rs,r5.rs,r6.rs) containing:- All FHIR resource types (Patient, Observation, Encounter, etc.)
- All FHIR data types (HumanName, Address, CodeableConcept, etc.)
- All FHIR primitive types (string, integer, decimal, boolean, etc.)
- Choice type enums for polymorphic elements
- Resource collection enums
-
Hand-Coded Infrastructure (
lib.rs): Foundational types that support the generated code:Element<T, Extension>- Base container for FHIR elements with extensionsDecimalElement<Extension>- Specialized decimal handling with precision preservationPreciseDecimal- High-precision decimal arithmeticFhirVersion- Version enumeration and utilities
Code Generation Process
The FHIR types are generated from official HL7 specification files by the helios-fhir-gen crate:
- Source: Official FHIR StructureDefinition JSON files from HL7
- Processing:
helios-fhir-genparses specifications and generates Rust code - Output: Complete type-safe Rust implementations in version-specific modules
- Integration: Generated code uses hand-coded infrastructure types
Supported FHIR Versions
Version Coverage
| FHIR Version | Status | Module | Resources | Data Types | Features |
|---|---|---|---|---|---|
| R4 | ✅ Current Default | fhir::r4 |
~150 resources | ~60 data types | Mature, widely adopted |
| R4B | ✅ Supported | fhir::r4b |
~150 resources | ~60 data types | Errata and clarifications |
| R5 | ✅ Current Standard | fhir::r5 |
~180 resources | ~70 data types | Latest features |
| R6 | ✅ Latest | fhir::r6 |
~190 resources | ~75 data types | Cutting-edge development |
Feature Flag System
The crate uses Cargo feature flags to control which FHIR versions are compiled. For example:
[]
= { = "0.1.0", = ["R5"] } # R5 only
= { = "0.1.0", = ["R4", "R5"] } # R4 and R5
= { = "0.1.0" } # R4 (default)
Generated Code Features
Resource Types
Every FHIR resource is represented as a strongly-typed Rust struct:
use ;
let patient = Patient ;
Data Types
All FHIR data types are available as Rust structs:
use ;
let address = Address ;
Primitive Types
FHIR primitive types are implemented with proper constraint handling:
use ;
// FHIR primitives include extension support
let enabled: Boolean = true.into;
let name: FhirString = "Patient Name".to_string.into;
let count: Integer = 42.into;
Choice Types (Polymorphic Elements)
FHIR choice elements (ending in [x]) are represented as enums:
use ;
let observation = Observation ;
Resource Collection
Each version provides a unified Resource enum containing all resource types:
use Resource;
let resource = Patient;
let json = to_string?;
// Deserialize from JSON
let parsed: Resource = from_str?;
Serialization and Deserialization
JSON Compatibility
All generated types are fully compatible with official FHIR JSON representations:
use Patient;
use serde_json;
// Deserialize from FHIR JSON
let fhir_json = r#"{
"resourceType": "Patient",
"id": "example",
"name": [
{
"family": "Doe",
"given": ["John"]
}
]
}"#;
let patient: Patient = from_str?;
// Serialize back to JSON
let json = to_string_pretty?;
Precision Handling
The crate includes specialized handling for FHIR's decimal precision requirements:
use Decimal;
use Decimal as RustDecimal;
// Preserves original string precision
let precise_value = from_string;
// Mathematical operations maintain precision
// RustDecimal::new(1, 1) creates 1 × 10^(-1) = 0.1
let calculated = precise_value + new; // add 0.1 = 12.440
FHIRPath Integration
Generated Traits
All FHIR types automatically implement FHIRPath-compatible traits:
use Patient;
use IntoEvaluationResult;
let patient = default;
// Convert to FHIRPath evaluation context
let result = patient.to_evaluation_result;
// Use with FHIRPath expressions
let name_result = evaluate?;
Property Access
Generated types support FHIRPath property access patterns:
// FHIRPath: Patient.name.family
let family_names = patient.name
.unwrap_or_default
.into_iter
.filter_map
.;
Testing and Validation
Comprehensive Test Suite
The crate includes extensive testing against official FHIR examples:
# Test all versions with official examples
# Test specific version
# Test serialization/deserialization
Example Data
Each FHIR version includes hundreds of official example resources:
- R4: 2,000+ official examples from HL7
- R4B: Updated examples with errata fixes
- R5: 2,500+ examples with new resource types
- R6: Latest examples from ongoing development
Validation Coverage
Tests verify:
- Round-trip serialization: JSON → Rust → JSON consistency
- Schema compliance: Generated types match FHIR specifications
- Example compatibility: All official examples deserialize correctly
- Type safety: Compile-time guarantees for data structure integrity
Usage Patterns
Basic Resource Creation
use ;
let patient = Patient ;
Working with Extensions
use ;
let mut patient = default;
// Add custom extension
patient.extension = Some;
Resource Collections and Bundles
use ;
let bundle = Bundle ;