Crates
serde-hl7
Serde support for HL7, one module per standard
What it is
The shape of the `hl7` umbrella, one layer up: `serde_hl7::v2` is the `serde-hl7-v2` crate and `serde_hl7::v3` is `serde-hl7-v3`, each behind a Cargo feature of the same name, both on by default. Nothing lives at the root, for the same reason nothing lives at the root of `hl7`.
// serde-hl7/src/lib.rs, in full, minus the documentation
#[cfg(feature = "v2")]
pub use serde_hl7_v2 as v2;
#[cfg(feature = "v3")]
pub use serde_hl7_v3 as v3;That is the entire crate. The hl7 crate organizes HL7 by standard because a
“message” or a “code” in one standard is a different thing in another; this crate is the same
shape one layer up, so a caller can depend on “Serde for HL7” and reach the standard they need
by module.
Cargo features
cargo add serde-hl7 # v2 and v3
cargo add serde-hl7 --no-default-features --features v2 # v2 onlyv2 and v3 are both on by default, mirroring hl7, which
always carries both modules. Turn one off to skip the other's dependency tree entirely; a
build with neither is an empty crate, which is allowed and useless.
Use
use serde_hl7::v2;
let text = "MSH|^~\\&|LAB||EPIC||20240101||ORU^R01|1|P|2.5\r\
PID|1||241900||SMITH^JOHN";
let message = v2::Message::parse(text)?;
let json = serde_json::to_string(&message)?;
let back: v2::Message = serde_json::from_str(&json)?;
assert_eq!(back.to_er7(), text);Any Serde format works the same way — serde_json is used here only because JSON is
the easiest format to read on a page. Neither this crate nor the modules beneath it name a
format in their runtime dependencies.
The modules
serde_hl7::v2 wraps hl7-2: the
message (as its ER7 text plus the release it was read as), the dictionary-named tree,
validation findings, and the release. serde_hl7::v3 wraps hl7-3: the three-level envelope, the six RIM backbone classes, the data
types, and the raw XML element tree. Each is its own crate with its own normative spec.
What both modules share
Exactly two runtime dependencies each, serde and the hl7-* crate
wrapped. Every Serialize/Deserialize impl hand-written against Serde's
low-level traits, no derive, no proc-macro crate. A same-named wrapper per type that Derefs to the type it wraps, so the wrapped crate's whole API is reachable on the
wrapper. Unknown keys ignored by default, and an opt-in Strict<T> that
rejects them — the pattern serde-er7 established over er7.
Related crates
serde-hl7-v2
Serde for hl7-2: the message, its tree, and its findings
serde-hl7-v3
Serde for hl7-3: the envelope, the RIM, the data types, the elements
hl7
The umbrella crate: one module per HL7 standard