Skip to content

(Experimental) FHIR library for Rust (and maybe ๐Ÿ”œ JS)

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

lschmierer/fhirbolt

Repository files navigation

Fhirbolt - (Experimental) FHIR library for Rust (and maybe ๐Ÿ”œ JS)

Fhirbolt is an experimental suite of libraries for working with FHIR resources. It currently provides serialization and deserialization of JSON and XML resources for the Rust programming language.

Bindings for other languages shall be added in the future. Primary goal is adding JS bindings by compiling the core Rust crate to WASM.

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

Roadmap

  • JSON (de)serialization
  • XML (de)serialization
  • FHIRPath
  • JS/TS package (by compiling to WASM)

Language Support

Lang JSON ser/de XML ser/de Package
Rust โœ“/โœ“ โœ“/โœ“ Rust Docs
Javascript tbd./tbd. tbd./tbd.

Rust

The Rust crate supports two working modes:

  1. a generic element model
  2. working with fully typed model structs.

The element model is always enabled as it is also used internally for deserializing model structs. Model structs can be optionally enabled by specifying the desried FHIR release as Cargo feature.

You should only include the release that you really need, as this signigicantly increases build time.

[dependencies]
fhirbolt = { version = "0.4", features = ["r4b"] }

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;
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(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()
};

About

(Experimental) FHIR library for Rust (and maybe ๐Ÿ”œ JS)

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages