hl7_parser/lib.rs
1//! HL7v2 message parsing in Rust.
2//!
3//! Parses the structure of HL7v2 messages, but does not validate the correctness
4//! of the messages.
5//!
6//! # Examples
7//!
8//! ```
9//! use hl7_parser::{Message, datetime::TimeStamp};
10//! use std::str::FromStr;
11//!
12//! let message =
13//! Message::parse("MSH|^~\\&|foo|bar|baz|quux|20010504094523||ADT^A01|1234|P|2.3|||").unwrap();
14//! let msh = message.segment("MSH").unwrap();
15//! assert_eq!(msh.field(3).unwrap().raw_value(), "foo");
16//!
17//! let message_time = msh.field(7).unwrap();
18//! let time: TimeStamp = message_time.raw_value().parse().unwrap();
19//! assert_eq!(time.year, 2001);
20//! assert_eq!(time.month, Some(5));
21//! assert_eq!(time.day, Some(4));
22//! ```
23
24/// Structs for representing HL7 messages.
25pub mod message;
26pub use message::Message;
27
28pub mod builder;
29
30/// Structs for displaying parsed HL7 message values. Especially useful for decoding
31/// escaped values.
32pub mod display;
33
34/// Utilities for locating a cursor within an HL7 message.
35pub mod locate;
36
37/// Human-readable location queries for HL7 messages.
38///
39/// i.e. parsing "PID.5.1" to get the value of the first component of the fifth field
40pub mod query;
41
42/// Functions to parse various parts of an HL7 message. Probably not useful to you
43/// (use the `Message::parse` method instead).
44pub mod parser;
45
46/// Timestamp parsing and utilities to translate to and from the `chrono` and
47/// `time` crates.
48pub mod datetime;
49
50/// Parses an HL7 message into a structured form. Equivalent to calling `Message::parse(message)`.
51pub fn parse_message(message: &str) -> Result<Message, parser::ParseError> {
52 Message::parse(message)
53}
54
55/// Parses an HL7 message into a structured form, allowing lenient newlines. Equivalent to calling
56/// `Message::parse_with_lenient_newlines(message, true)`.
57pub fn parse_message_with_lenient_newlines(message: &str) -> Result<Message, parser::ParseError> {
58 Message::parse_with_lenient_newlines(message, true)
59}
60
61// TODO list:
62//
63// - [x] Timestamp parsing
64// - [x] Chrono support
65// - [x] Time support
66// - [x] Add lenient parsing for segment separators (e.g. allow \n or \r\n as well as \r)
67// - [x] Add cursor location
68// - [x] Add query functions to get fields, components, etc. by name
69// - [ ] Add ability to convert parsed messages into a mutable form that can be modified and then serialized back into a hl7 message
70// - [X] Add serde support
71// - [x] this_error errors
72// - [x] More tests
73// - [x] More documentation
74// - [x] More examples
75// - [x] benchmarks