Skip to main content

Crate er7

Crate er7 

Source
Expand description

§ER7

websitedocumentationsourcecrateemail

ER7 — the pipe-hat encoding that carries HL7 v2 messages between healthcare systems — parsed, queried, edited, and written back, with no dependencies.

ER7 is compact and everywhere, and it is also unforgiving: a value’s meaning comes entirely from its position, so one misplaced | silently shifts everything after it. This crate exists to make that structure explicit and to keep it intact — text is stored exactly as it arrived, and decoded only when you ask for a value.

Example:

let text = "MSH|^~\\&|LAB|ACME|EHR|CLINIC|20260815120000||ORU^R01|MSG9|P|2.5\r\
            PID|1||12345^^^ACME^MR||SMITH^JOHN^Q||19800101|M\r\
            OBX|1|NM|2093-3^Cholesterol^LN||187|mg/dL|||||F";

let message = er7::parse(text)?;
assert_eq!(message.control_id().as_deref(), Some("MSG9"));
assert_eq!(message.query("PID-5.1")?.as_deref(), Some("SMITH"));
assert_eq!(message.query("OBX-3.2")?.as_deref(), Some("Cholesterol"));

// What went in comes back out, byte for byte.
assert_eq!(message.to_er7(), text);

§What is here

ItemPurpose
parse(), parse_withread text into a Message
Message, Segment, Field, Repetition, Component, Subcomponentthe six-level value tree
Message::query, Message::query_allread values by HL7 Path, e.g. PID-5.1 or OBX[2]-5
Message::to_er7, Segment::to_text and siblingswrite the tree back out, as sent or decoded
split_messagescut a batch file or concatenated messages into individual ones
escape::unescape, escape::escape, escape::escapesthe escape-sequence vocabulary
Separatorsthe delimiter set, read from each message’s own header rather than assumed

§What is deliberately not here

This crate is an encoding, not a dictionary. It does not know which fields a segment should have, what data type each one carries, which message structures exist, or what any code table means — all of that is version-specific and belongs in a layer above. It performs no validation and no transport.

The one exception is a handful of MSH accessors such as Message::control_id, because routing a message requires reading them and their positions have never moved in any HL7 v2 release.

§The crate family

Each layer above this one is its own crate, so a caller pays only for what they use:

CrateAdds
er7-redactredaction: remove patient detail without changing the shape of the message
serde-er7Serde support for every type in this tree
hl7-2-5-to-xml, hl7-2-5-to-jsonthe HL7 v2.5 dictionary

spec/01-purpose-and-scope.md §1.3.1 is the source of truth for that list, and https://er7-rust.github.io/ecosystem/ presents it.

§Documentation

spec/index.md in the repository is the normative specification of everything above; where this documentation and that document disagree, that document is right. Section references such as “spec §6.2” and rule IDs such as “R16” throughout these docs point into it.

The repository also holds a tutorial (docs/usage/), references for paths (docs/paths/) and escape sequences (docs/escapes/), an FAQ (docs/faq/), and runnable programs (examples/).

Re-exports§

pub use crate::message::Component;
pub use crate::message::Field;
pub use crate::message::Message;
pub use crate::message::Repetition;
pub use crate::message::Segment;
pub use crate::message::Subcomponent;
pub use crate::parse::parse;
pub use crate::parse::parse_with;
pub use crate::parse::split_messages;
pub use crate::path::Path;
pub use crate::render::RenderOptions;
pub use crate::separators::Separators;
pub use crate::separators::Terminator;

Modules§

escape
ER7 escape sequences: the way a value carries characters that would otherwise be read as structure.
message
The ER7 value tree: message, segment, field, repetition, component, subcomponent.
parse
Reading ER7 text into the value tree.
path
HL7 paths: the short notation interface engineers use to name one place in a message, such as PID-5.1 or OBX[2]-5.1.2.
render
Writing the value tree back out, either as ER7 or as readable text.
separators
The ER7 delimiter set, read from a message’s own header segment.

Enums§

Error
What can go wrong.