hl7v2-types 0.1.128

Generated HL7 v2 message structure trees, segment field tables, data type components and message definitions
Documentation

hl7v2-types

HL7 v2 message structure trees, segment field tables, data type component tables and message definitions as Rust data.

The crate holds the tables a v2 parser walks:

  • structure: every message structure of the HL7 v2 definitions (305 of them, for example ORU_R01-A and ADT_A01-A) as a static tree of segments, segment groups, choice groups and open Hxx slots in definition order, each with its position, its cardinality (minimum, and maximum or unbounded) and, for a segment, its segment status code.

  • segment: every segment definition (190), each with its fields by position: the field name, the data type code, the cardinality (whose maximum is the repetition), the optionality code, the length and conformance length, and the HL7 table its binding names, by table number and value set URL. The batch envelopes (BHS, BTS, FHS, FTS) and the other segments no structure references (ADD, FAC, OVR, PDC, PSH) are in it too.

  • data_type: every data type definition (83: 12 primitive, 71 complex with 448 components), each complex type with its components by position: the component name, its data type, cardinality, optionality code, length and conformance length, and table. A field points at its data type's static; Varies, which no data type definition defines, stays a code.

  • message: every message definition (696), indexed by message code and trigger event (MSH-9.1 and MSH-9.2), each pointing at the message structure variant it names: message::find("ADT", "A04") names ADT_A01-B. The 34 definitions that name no structure carry none.

  • legacy: the message structures the v2.9.1 definitions no longer carry (57 codes, ORM_O01 among them), one tree per earlier version whose tables carry it (218 trees over versions 2.3 to 2.8.2), for example legacy::v2_5_1::structure::orm_o01::ORM_O01. Each carries its version and withdrawn_as_of (ORM_O01: 2.7). The segments a tree names come from the same version's tables, each field with the data type code that version gives it: 495 per-version segments are emitted under the version's segment module, and the 98 references to a segment whose field table agrees with the v2.9.1 one point at the v2.9.1 static. legacy::versions("ORM_O01") lists the trees, and message::find_legacy("ORM", "O01", "2.5.1") finds one by code, event and version (message::LEGACY, 218 entries).

structure::find, segment::find and data_type::find look an entry up by its definition id, and message::find by code and event. A tree node points at the segment's own static, so the field table is one step from the node that places the segment. The shapes are in model, and every one of them compares by value (PartialEq, Eq). Every field, component and node carries the element id of its definition (OBX.1-setId, CX.1, ORU_R01-A.5-PATIENT_RESULT), and every code is carried as the definitions write it.

The crate carries no table contents. The v2 tables are published as FHIR CodeSystem and ValueSet resources in the HL7 terminology package, which a terminology server serves by the value set URL a field names.

Requiring the crate

The crate follows Cargo's SemVer rules: a compatible change moves the patch, and a breaking change moves the minor while the crate is 0.x. Require it with a caret range on its line, so one release serves every crate in your build that uses it:

[dependencies]
hl7v2-types = "0.1"

Name a patch ("0.1.N") when you need the first release that carries what you use; the range is the same caret range.

Examples

Find the structure a message's MSH-9 selects, walk to a segment it places, and read a field's definition:

use hl7v2_types::model::{Max, Node, Optionality};

let adt_a04 = hl7v2_types::message::find("ADT", "A04").expect("a defined message");
let structure = adt_a04.structure.expect("ADT^A04 names a structure");
assert_eq!(structure.id, "ADT_A01-B");

let pid = structure
    .nodes
    .iter()
    .find_map(|node| match node {
        Node::Segment(placed) if placed.segment.id == "PID" => Some(placed.segment),
        _ => None,
    })
    .expect("ADT_A01-B places PID at the top level");
let identifiers = pid.fields.iter().find(|field| field.position == 3).expect("PID-3");
assert_eq!(identifiers.name, "Patient Identifier List");
assert_eq!(identifiers.optionality, Optionality::R);
assert_eq!(identifiers.cardinality.max, Max::Unbounded);
assert_eq!(identifiers.data_type.map(|data_type| data_type.code()), Some("CX"));

A structure the v2.9.1 definitions withdrew is found by the version the message declares in MSH-12:

let orm = hl7v2_types::message::find_legacy("ORM", "O01", "2.5.1").expect("carried at 2.5.1");
assert_eq!(orm.structure.id, "ORM_O01");
assert_eq!(orm.structure.withdrawn_as_of, Some("2.7"));

The crate is on the FerroBRIDGE crate line, which follows Cargo SemVer: require it by the caret range under Requiring the crate above.

Source

Every file is generated by fhir-codegen from the HL7 v2 definitions of HL7/v2ig (input/sourceOfTruth, logical StructureDefinitions derived from HL7 V2.9.1) at the commit the banner of each file names, and marked // @generated. The legacy module is generated from the NIST IGAMT export of HL7's v2 database (usnistgov/igamt-hl7Tools-service, src/main/resources/hl7db), checked against table 0354 of the HL7 terminology package. The definitions and the export are fetched at build time and are not part of this crate. To change the output, change the generator and regenerate; the crate is never hand-edited.

Licence

Apache License 2.0 (LICENSE).