Expand description
Read and check HL7 v2 messages.
A message is decomposed into named fields and checked against the HL7 dictionary: required fields, data types, code tables and cross-field consistency. Parsing borrows the text it was given rather than copying it, so a message costs a few hundred bytes on top of the string it came from.
let text = "MSH|^~\\&|HIS|MERCY|LIS|LAB|20240115143200||ADT^A01|MSG1|P|2.5.1\r\
PID|1||123456^^^MERCY^MR||Smith^John||19850312|M\r";
let message = hl7probe::parse(text)?;
assert_eq!(message.version(), "2.5.1");
assert_eq!(message.type_label(), "ADT^A01");
// PID-5.1 is the patient's family name.
let pid = message.first("PID").expect("the message has a PID");
assert_eq!(pid.comp(5, 1), "Smith");
let report = hl7probe::validate(&message);
println!("{} errors, {} warnings", report.errors(), report.warnings());Messages borrow the text they were read from, so keep it alive for as long
as the Message. Use parser::split_messages and
parser::parse_message directly to walk a file holding several messages.
Re-exports§
pub use parser::Component;pub use parser::Field;pub use parser::Message;pub use parser::ParseError;pub use parser::Repetition;pub use parser::Segment;pub use parser::Separators;pub use validate::Category;pub use validate::Finding;pub use validate::Report;pub use validate::Severity;
Modules§
- datetime
- HL7 DT/TM/DTM (a.k.a. TS) handling: strict parsing plus friendly rendering.
- parser
- HL7 v2 lexical parser: MLLP/batch stripping, segment/field/component/subcomponent decomposition and escape-sequence handling.
- spec
- Static HL7 v2 dictionary: segment field definitions, code tables and the abstract message structures used for structural validation.
- validate
- Validation passes: structure against the abstract message grammar, field usage, data types, code tables and cross-field consistency.