HL7® v2 derive
HL7®, and FHIR® are the registered trademarks of Health Level Seven International and their use of these trademarks does not constitute an endorsement by HL7.
This project uses the HL7® name in its package names, its organization name, and its domain, which is beyond fair use; we are requesting permission from HL7® for that.
Derive macros for hl7-2: map a
struct's fields to HL7 v2 message paths once, in the type definition,
instead of writing the same accessor calls at every call site.
You do not depend on this crate directly. hl7-2 re-exports both macros
behind its derive feature:
= { = "0.2", = ["derive"] }
Keeping the macros in a crate of their own is what lets the default build of
hl7-2 keep exactly one dependency: syn and quote are compiled only
for callers who ask for the macros.
Usage
use ;
let admission: Admission = parse?.decode?;
assert_eq!;
// The one vendor field no struct models — same object, no second parse.
assert_eq!;
One attribute per field:
| attribute | on read | on write |
|---|---|---|
#[hl7("PID-5.1")] |
read the path | write the path |
#[hl7(nested)] |
the field's own FromHl7 |
the field's own ToHl7 |
#[hl7(raw)] |
the whole message, as a Raw |
skipped |
| none | Default::default() |
skipped |
Field types convert through hl7_2::FromHl7Value / ToHl7Value:
String, bool, the integer and floating-point types, and Option<T> and
Vec<T> of those — Option for a value that may be absent, Vec for one
that repeats. A plain type is required, and a path that names nothing is
Error::MissingField. Implement hl7_2::FromHl7Text for a domain type of
your own and Option and Vec of it follow.
Writing needs the segments to exist already; build the message with
hl7_2::Builder (whose encode method takes a ToHl7) or add them with
Message::append_segment.
See also
hl7-2— the library these macros are for; itsspec/index.md§6 is the normative description of struct modeer7— the ER7 encoding layer
License
MIT OR Apache-2.0 OR BSD-3-Clause OR GPL-2.0-only OR GPL-3.0-only