hl7-parser

Parses the structure of HL7v2 messages, but does not validate the correctness of the messages.
[!WARNING]
Although a best effort has been made to make this parse HL7v2 messages correctly, there are no guarantees that it is actually correct. Use at your own risk.
Features
- Parse HL7v2 messages into a structure that can be queried
- Parse HL7v2 timestamps into chrono, time, and jiff types
- Decode HL7v2 encoded strings
- Locate a cursor within a message based on a character index
- Optional lenient parsing of segment separators (allow
\r\n
,\n
, and\r
to count as segment separators instead of just\r
) - Non-ASCII/UTF-8 encodings
(Unchecked features are not yet implemented, but planned for future releases).
Usage
Add this to your Cargo.toml
:
[]
= "0.3"
and then you can parse HL7v2 messages:
use ;
use FromStr;
let message =
parse.unwrap;
let msh = message.segment.unwrap;
assert_eq!;
let message_time = msh.field.unwrap;
let time: TimeStamp = message_time.raw_value.parse.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
Optional Cargo Features
By default, no optional features are enabled.
serde
: enable serde support for all data structurestime
: enable time support for parsing timestampschrono
: enable chrono support for parsing timestampsjiff
: enable jiff support for parsing timestamps
Additional Examples
Querying a Message
let message =
parse.unwrap;
let field = message.query.unwrap.raw_value;
assert_eq!;
let component = message.query.unwrap.raw_value;
assert_eq!;
Locating the Cursor Within A Message
(The cursor being the character index of some point within the buffer)
let message = parse.unwrap;
let cursor = locate_cursor.expect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Decoding Encoded Strings
use Separators;
let separators = default; // or, from a parsed message
let input = "foo|bar^baz&quux~quuz\\corge\rquack\nduck";
let expected = r"foo\F\bar\S\baz\T\quux\R\quuz\E\corge\X0D\quack\X0A\duck";
let actual = separators.encode.to_string;
assert_eq!;
Parsing Timestamps
use ;
let ts: TimeStamp = parse_timestamp.expect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
These TimeStamp
values can then be converted to and from chrono
, time
,
and jiff
types if the corresponding features are enabled using [std::convert::From]
and [std::convert::TryFrom].
Building HL7 messages
use *;
let message = new
.with_segment
.with_segment
.render_with_newlines.to_string;
assert_eq!;