7 releases
Uses new Rust 2024
| new 0.1.6 | Nov 24, 2025 |
|---|---|
| 0.1.5 | Sep 19, 2025 |
| 0.1.2 | Aug 31, 2025 |
#112 in Science
155 downloads per month
Used in 11 crates
(5 directly)
110KB
2K
SLoC
octofhir-fhir-model
Core FHIR model abstractions and ModelProvider trait for FHIRPath type-aware evaluation.
Overview
This crate provides the foundational types and traits for FHIR model integration with FHIRPath engines. It serves as an intermediate dependency to break circular dependencies between FHIRPath implementations and FHIR schema libraries.
Architecture
The crate is designed around the ModelProvider trait, which abstracts access to FHIR model information including:
- Type reflection and metadata - Introspect FHIR types and their properties
- Structure definitions and conformance validation - Validate resources against profiles
- Constraint definitions and evaluation - Apply and evaluate FHIR constraints
- Reference resolution capabilities - Resolve references between FHIR resources
Features
default- Core functionality without optional dependenciesasync- Enables async support withasync-traitandtokioserde- Adds serialization support viaserde
Installation
Add this to your Cargo.toml:
[dependencies]
octofhir-fhir-model = "0.1.0"
For async support:
[dependencies]
octofhir-fhir-model = { version = "0.1.0", features = ["async"] }
For serialization support:
[dependencies]
octofhir-fhir-model = { version = "0.1.0", features = ["serde"] }
Usage
Basic Usage
use octofhir_fhir_model::{ModelProvider, TypeReflectionInfo, FhirVersion};
// ModelProvider implementations provide type information
fn example_usage(provider: &dyn ModelProvider) {
if let Some(type_info) = provider.get_type_reflection("Patient") {
println!("Patient type: {:?}", type_info);
}
}
Working with Type Reflection
use octofhir_fhir_model::{ModelProvider, TypeReflectionInfo};
fn inspect_type(provider: &dyn ModelProvider, type_name: &str) {
if let Some(reflection) = provider.get_type_reflection(type_name) {
println!("Type: {}", reflection.type_name);
println!("Base type: {:?}", reflection.base_type);
for element in &reflection.elements {
println!(" Element: {} ({})", element.name, element.type_name);
}
}
}
Conformance Validation
use octofhir_fhir_model::{ModelProvider, ConformanceResult};
fn validate_resource(provider: &dyn ModelProvider, resource_data: &str) -> ConformanceResult {
// Implementation would validate the resource against FHIR profiles
// This is typically implemented by concrete ModelProvider implementations
provider.validate_conformance(resource_data)
}
Modules
boxing- Boxed value types and extensions for FHIRPath evaluationconformance- Conformance validation results and violation reportingconstraints- Constraint definitions and evaluation resultserror- Error types and result handlingprovider- Core ModelProvider trait and related typesreflection- Type reflection and metadata structures
FHIR Version Support
This crate is designed to work with multiple FHIR versions through the FhirVersion enum:
- FHIR R4 (4.0.1)
- FHIR R4B (4.3.0)
- FHIR R5 (5.0.0)
Development
Prerequisites
- Rust 2024 edition or later
- just command runner (optional, for convenience)
Building
cargo build
Or using just:
just build
Testing
cargo test --all-features
Or using just:
just test-all
Documentation
Generate and open documentation:
cargo doc --no-deps --all-features --open
Or using just:
just doc-open
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Workflow
- Fork the repository
- Create a feature branch
- Make your changes
- Run the test suite:
just test-all - Run formatting and linting:
just fmtandjust lint - Submit a pull request
License
This project is dual-licensed under either:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Acknowledgments
This project is part of the OctoFHIR ecosystem for FHIR processing in Rust.
Dependencies
~4–19MB
~198K SLoC