Expand description
Fhirbolt
Fhirbolt is a library that enables you to work with FHIR resources in Rust. This library includes FHIR data types and methods for (de)serializing these from and to JSON and XML.
More elaborate features like validation (including cardinality and slicing) or full FHIRPath evaluation might be added eventually.
Currenlty supported FHIR releases: R4, R4B and R5
The Rust crate supports two working modes:
- a generic element model
- working with fully typed model structs.
Installation
Add fhirbolt
to your Cargo.toml.
You can select which FHIR release to include model structs for by speficifying them as Cargo features.
[dependencies]
fhirbolt = { version = "0.2", features = ["r4b"] }
By default, no FHIR release is included.
Example
// The `Resource` type is an enum that contains all possible FHIR resources.
// If the resource type is known in advance, you could also use a concrete resource type
// (like e.g. `fhirbolt::model::r4b::resources::Observation`).
use fhirbolt::model::r4b::{
Resource,
resources::{Observation, ObservationValue},
types::{Code, CodeableConcept, Coding, String as FhirString},
};
use fhirbolt::serde::{DeserializationConfig, DeserializationMode};
// The type of `s` is `&str`
let s = r#"{
"resourceType": "Observation",
"status": "final",
"code": {
"text": "some code"
},
"valueString": "some value"
}"#;
let r: Resource = fhirbolt::json::from_str(s, None).unwrap();
match r {
Resource::Observation(ref o) => println!("deserialized observation: {:?}", r),
_ => (),
}
// Use Default::default() or constructing new resources by yourself
let o = Observation {
status: "final".into(),
code: Box::new(CodeableConcept {
text: Some("some code".into()),
..Default::default()
}),
value: Some(ObservationValue::String("some value".into())),
..Default::default()
};
You can pass a DeserializationConfig
to configure the deserialization behavior.
Re-exports
Modules
- Supported FHIR Releases.
- Generic element model.
- Generated structs for FHIR resources.
- (De)serialize FHIR resources from and to JSON and XML.
Type Definitions
- Generic FHIR Release.