Expand description
HL7 v2 message parser.
This crate provides parsing functionality for HL7 v2 messages, including:
- Message parsing from raw bytes
- Batch message handling (FHS/BHS/BTS/FTS)
- MLLP-framed message parsing
- Path-based field access (re-exported from hl7v2-query)
§Memory Efficiency
This parser uses a “zero-allocation where possible” approach rather than true zero-copy.
Parsed messages own their data via Vec<u8>, which provides:
- Safe lifetime management without complex borrow checker patterns
- Ergonomic API that doesn’t require managing input lifetimes
- Ability to modify and re-serialize messages
For memory-constrained environments or very large messages, consider using
hl7v2_stream which provides an event-based
streaming parser with bounded memory usage.
§Example
use hl7v2_parser::parse;
let hl7 = b"MSH|^~\\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|20250128152312||ADT^A01|ABC123|P|2.5.1\rPID|1||123456^^^HOSP^MR||Doe^John\r";
let message = parse(hl7).unwrap();
assert_eq!(message.segments.len(), 2);Functions§
- get
- Get value at path (e.g.,
PID.5[1].1) - get_
presence - Get presence semantics for a field at path.
- parse
- Parse HL7 v2 message from bytes.
- parse_
batch - Parse HL7 v2 batch from bytes.
- parse_
file_ batch - Parse HL7 v2 file batch from bytes.
- parse_
mllp - Parse HL7 v2 message from MLLP framed bytes.