Expand description
FHIR R4 for Rust.
Typed models for every R4 resource and datatype, generated from the
official specification package, read from and written to JSON without
losing anything (decimal precision, extensions on primitives, key
order), and checked while reading: every problem comes back as an
Issue with the element’s path, not as the first error only.
use fhirkit::r4::{Patient, Resource};
let json = r#"{
"resourceType": "Patient",
"id": "example",
"name": [{"family": "Chalmers", "given": ["Peter", "James"]}],
"birthDate": "1974-12-25",
"_birthDate": {"extension": [{"url": "http://hl7.org/fhir/StructureDefinition/patient-birthTime",
"valueDateTime": "1974-12-25T14:35:45-05:00"}]}
}"#;
let patient: Patient = fhirkit::from_json_strict(json).unwrap();
assert_eq!(patient.name[0].family.as_ref().unwrap().value.as_deref(), Some("Chalmers"));
assert_eq!(patient.birth_date.as_ref().unwrap().extension.len(), 1);
// Any resource, dispatched on resourceType; problems are reported with paths.
let (resource, issues) = fhirkit::from_json::<Resource>(r#"{"resourceType": "Patient", "gender": "x y ", "foo": 1}"#).unwrap();
assert_eq!(resource.unwrap().resource_type(), "Patient");
let paths: Vec<_> = issues.iter().map(|i| i.path.as_str()).collect();
assert_eq!(paths, ["Patient.gender", "Patient.foo"]);Resources come in five Cargo features, as the specification groups
them: foundation, base, clinical, financial, specialized
(all on by default). Datatypes are always included.
Re-exports§
pub use decode::Decoder;pub use decode::FhirJson;pub use decode::Issue;pub use decode::Severity;pub use json::Json;pub use json::JsonError;pub use primitive::Decimal;pub use primitive::Kind;pub use primitive::Primitive;
Modules§
- decode
- Reading and writing FHIR JSON for generated types.
- json
- A small JSON reader and writer that keeps what FHIR needs kept.
- primitive
- FHIR primitive types: the value, and the element parts a primitive can
carry beside it (
"birthDate": "1970"plus"_birthDate": {"id": .., "extension": [..]}). - r4
- FHIR R4 (4.0.1): 146 resources and 39 datatypes, generated from the official specification package.
Enums§
- Error
- Why a document could not be read at all.
Functions§
- decode_
json - Read a value from parsed JSON, as
from_json. - from_
json - Read a value from FHIR JSON. Returns what could be read and every
problem found;
Nonewhen the document was not usable at all. - from_
json_ many - Read many documents at once, on up to
threadsthreads (0means one per available core). Results come back in input order, each asfrom_jsonwould return it. - from_
json_ strict - Read a value from FHIR JSON, failing on any error-level issue.
- to_json
- Write a value as compact FHIR JSON.
- to_
json_ pretty - Write a value as FHIR JSON indented by two spaces.
Type Aliases§
- Decoded
- What reading gives back: the value, if it was usable at all, and every problem found on the way.