Expand description
A small, dependency-free HL7 v2.x parser.
The parser splits a message into segments, fields, repetitions, components and subcomponents and keeps the byte span of every node, so a caller can point back into the original text (for highlighting, diffing or error reporting) without searching for the value again.
Design constraints:
- No dependencies, no
unsafe, no panics on malformed input. Malformed messages are the normal case in integration work; every failure is a value. - Tolerant of what real interfaces produce:
\r,\r\nand bare\nsegment terminators, MLLP framing bytes, a UTF-8 BOM, a malformed MSH-2. - MSH numbering is handled correctly: MSH-1 is the field separator and
MSH-2 the encoding characters, so
MSH-9is the message type in this crate exactly as it is in the standard. - Encoding characters come from MSH-2, never hardcoded. Escape sequences
(
\F\,\S\,\T\,\R\,\E\,\Xdd..\,\.br\) decode on demand. - Host-target only code: no
web-sys, no I/O. It compiles forwasm32-unknown-unknownunchanged.
use hl7kit::Message;
let text = "MSH|^~\\&|RIS|HOSP|PACS|HOSP|20260905120000||ORM^O01|42|P|2.5.1\r\
PID|1||4MR1^^^HOSP^MR||Doe^Jane||19700101|F\r\
OBR|1|A1001||MR1^MRI HEAD|||20260905|||||||||||A1001|RP-77\r\
ZDS|1.3.6.1.4.1.5962.1.2.4.20040826185059.5457^^Application^DICOM\r";
let msg = Message::parse(text).unwrap();
assert_eq!(msg.get("MSH-9.1"), Some("ORM"));
assert_eq!(msg.get("PID-3.1"), Some("4MR1"));
assert_eq!(msg.get("OBR-18"), Some("A1001"));
assert_eq!(msg.get("ZDS-1.1"), Some("1.3.6.1.4.1.5962.1.2.4.20040826185059.5457"));
// Every value knows where it came from.
let span = msg.get_span("PID-3.1").unwrap();
assert_eq!(&text[span.range()], "4MR1");The order module builds on the parser to extract the four identifiers an
imaging order carries (patient ID, accession number, requested procedure ID
and study instance UID) as defined by the IHE Radiology Technical Framework.
The builder module writes messages: values are set structurally and
delimiter characters inside them are escaped, so what you build parses
back to what you set.
Modules§
- builder
- Building messages.
- order
- Imaging-order identifiers as carried by ORM^O01, OMI^O23 and ORU^R01 messages.
Structs§
- Component
- A component view.
- Encoding
- The five delimiter characters of an HL7 v2 message.
- Field
- A field view.
- Message
- A parsed HL7 v2 message.
- Message
Type - MSH-9, the message type.
- Path
- A parsed query path.
- Repetition
- A repetition view.
- Segment
- A segment view.
- Span
- A byte range into
Message::raw. - Subcomponent
- A subcomponent view.
Enums§
- Parse
Error - Why a message could not be parsed.
- Path
Error - Why a query path such as
PID-3.1could not be parsed. - Warning
- Something the parser tolerated but a reviewer may want to know about.
Functions§
- unescape
- Decode HL7 escape sequences in
textusing the message’s encoding characters.