1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! 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());
//! # Ok::<(), hl7probe::ParseError>(())
//! ```
//!
//! 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.
// The command line's own presentation, not part of the library API.
pub use ;
pub use ;
/// Parses the first message in `text`.
///
/// Leading batch wrappers and MLLP framing bytes are skipped, and CR, LF or
/// CRLF line endings are all accepted. For a file holding several messages,
/// use [`parser::split_messages`].
///
/// # Errors
///
/// Returns [`ParseError`] when `text` holds no MSH segment, or when the first
/// message's MSH does not declare a usable set of delimiters.
/// Checks a parsed message against the HL7 dictionary.