Skip to main content

serde_hl7/
lib.rs

1//! Serde support for Health Level Seven (HL7®) messages in Rust.
2//!
3//! The `hl7` crate organizes HL7 by standard, one module each — `hl7::v2`
4//! is the `hl7-2` crate, `hl7::v3` is `hl7-3` — because a "message" or a
5//! "code" in one standard is a different thing in another. This crate is
6//! the same shape one layer up: Serde support for each standard's types,
7//! one module each, so a parsed message can flow through `serde_json`,
8//! `serde_yaml`, `bincode`, or any other Serde data format.
9//!
10//! - [`v2`] — the `serde-hl7-v2` crate: `Serialize`/`Deserialize` wrappers
11//!   for `hl7-2`'s message, generic-mode tree, validation diagnostics, and
12//!   release. Behind the `v2` feature, on by default.
13//! - [`v3`] — the `serde-hl7-v3` crate: wrappers for `hl7-3`'s message
14//!   envelope, RIM backbone classes, data types, and the XML element tree
15//!   beneath them. Behind the `v3` feature, on by default.
16//!
17//! ```
18//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
19//! use serde_hl7::v2;
20//!
21//! let text = "MSH|^~\\&|LAB||EPIC||20240101||ORU^R01|1|P|2.5\r\
22//!             PID|1||241900||SMITH^JOHN";
23//! let message = v2::Message::parse(text)?;
24//!
25//! let json = serde_json::to_string(&message)?;
26//! let back: v2::Message = serde_json::from_str(&json)?;
27//! assert_eq!(back.to_er7(), text);
28//! # Ok(())
29//! # }
30//! ```
31//!
32//! Each module is its own crate underneath, so a caller who wants only one
33//! standard can depend on that crate directly instead of this umbrella —
34//! or keep this crate and turn the other off:
35//!
36//! ```toml
37//! [dependencies]
38//! serde-hl7 = { version = "0.1", default-features = false, features = ["v2"] }
39//! ```
40//!
41//! Nothing lives at the root but the modules. Every wrapper is hand-written
42//! against Serde's low-level traits in the per-standard crate, with exactly
43//! two runtime dependencies each — `serde` and the `hl7-*` crate it wraps —
44//! and no format crate anywhere but in tests. See each module's own
45//! documentation for the wire shape of every type, and `serde-hl7-v2`'s
46//! and `serde-hl7-v3`'s `spec/index.md` for the normative rules.
47//!
48//! # Trademarks
49//!
50//! HL7®, and FHIR® are the registered trademarks of Health Level Seven
51//! International and their use of these trademarks does not constitute an
52//! endorsement by HL7.
53
54// No `unsafe` anywhere in this crate, enforced rather than merely true:
55// `forbid` cannot be lifted by an `allow` further down, so this is a
56// property a reviewer can rely on without reading the sources. See
57// SECURITY.md.
58#![forbid(unsafe_code)]
59#![warn(missing_docs, clippy::pedantic)]
60
61#[cfg(feature = "v2")]
62pub use serde_hl7_v2 as v2;
63
64#[cfg(feature = "v3")]
65pub use serde_hl7_v3 as v3;