Skip to main content

Crate hl7_2_from_xml_into_er7

Crate hl7_2_from_xml_into_er7 

Source
Expand description

Convert HL7 v2.5 messages from the HL7 v2.xml XML representation (urn:hl7-org:v2xml) back to ER7 (pipe-delimited) encoding.

This is the inverse of the sibling hl7-2-from-er7-into-xml crate. That crate names every XML element after either an HL7 v2.5 data type or a bare position, but in both cases the number after an element name’s last dot is always the 1-based position at that level — field under a segment, component under a field, subcomponent under a component. Reconstruction leans on that one fact rather than an HL7 v2.5 data-type dictionary, so this crate carries none; see spec/index.md for the exact rules and their limits.

let xml = r#"<ORM_O01 xmlns="urn:hl7-org:v2xml">
  <MSH>
    <MSH.1>|</MSH.1>
    <MSH.2>^~\&amp;</MSH.2>
    <MSH.9><MSG.1>ORM</MSG.1><MSG.2>O01</MSG.2></MSH.9>
  </MSH>
  <ORM_O01.PATIENT>
    <PID><PID.5><XPN.1><FN.1>TEST</FN.1></XPN.1><XPN.2>FOUAZ</XPN.2></PID.5></PID>
  </ORM_O01.PATIENT>
</ORM_O01>"#;
let er7 = hl7_2_from_xml_into_er7::convert(xml).unwrap();
assert!(er7.starts_with(r"MSH|^~\&|"));
assert!(er7.contains("PID|||||TEST^FOUAZ"));

Re-exports§

pub use hl7_2_xml_lite_helper as xml;
pub use er7;

Modules§

reconstruct
Rebuilding the ER7 value tree from the parsed XML Element tree.

Enums§

Hl7Error
Errors that can occur while turning v2.xml into an er7::Message.

Functions§

convert
Convert one v2.xml document to ER7 text, with default rendering: carriage-return segment terminators, and no trailing terminator.
convert_with_options
Convert one v2.xml document to ER7 text, choosing the segment terminator and whether the last segment gets one too — see er7::RenderOptions.
parse
Parse a v2.xml document into an er7::Message, reconstructing its full ER7 value tree — segments, fields, repetitions, components, and subcomponents.