pub struct Dictionary { /* private fields */ }Expand description
Segment field types, composite component types, and message structures for one HL7 release or one vendor dialect.
Build one with crate::Version::dictionary for a bundled release, or
Dictionary::from_json for schema mode.
Implementations§
Source§impl Dictionary
impl Dictionary
Sourcepub fn empty(name: impl Into<String>) -> Dictionary
pub fn empty(name: impl Into<String>) -> Dictionary
An empty dictionary under which everything falls back to generic positional names. Useful as a base to build on, and as the honest answer for a message whose dialect is entirely unknown.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Where this dictionary came from, for error and diagnostic messages:
"v2.5" for a bundled release, or whatever name the caller gave.
Sourcepub fn version(&self) -> Option<&str>
pub fn version(&self) -> Option<&str>
The HL7 release this dictionary declares in its "version" member,
if any. A vendor dialect need not declare one.
Sourcepub fn composite_components(&self, data_type: &str) -> Option<&[String]>
pub fn composite_components(&self, data_type: &str) -> Option<&[String]>
The component data types of composite type data_type, or None
when it is primitive (ST, NM, DTM, …) or simply unknown —
the two are indistinguishable here on purpose, because both mean
“treat the value as a scalar”.
Sourcepub fn is_composite(&self, data_type: &str) -> bool
pub fn is_composite(&self, data_type: &str) -> bool
True when data_type is a composite this dictionary can break apart.
Sourcepub fn segment_fields(&self, segment: &str) -> Option<&[String]>
pub fn segment_fields(&self, segment: &str) -> Option<&[String]>
The field data types of segment, index 0 being field 1. None for
a segment the dictionary does not list, including Z-segments.
Sourcepub fn field_type(&self, segment: &str, field: usize) -> Option<&str>
pub fn field_type(&self, segment: &str, field: usize) -> Option<&str>
The data type of segment-field (1-based), or None when either
the segment or the field number is outside the dictionary, or when a
sparse delta left this position unstated.
May return the VARIABLE sentinel; see Dictionary::variable_type.
Sourcepub fn field_cardinality(&self, segment: &str, field: usize) -> Cardinality
pub fn field_cardinality(&self, segment: &str, field: usize) -> Cardinality
What the schema says about how often segment-field (1-based) may
appear.
Defaults to optional and non-repeating, which is both the XML Schema
default for an unstated maxOccurs and the honest answer for a
dictionary that never mentioned cardinality at all.
Sourcepub fn variable_type(&self, segment: &Segment) -> Option<&str>
pub fn variable_type(&self, segment: &Segment) -> Option<&str>
Resolve a VARIABLE field’s real type from the message.
Only OBX-5 works this way: OBX-2 names the data type of the value in
OBX-5, so an OBX|1|NM|... carries a number where an OBX|1|CE|...
carries a coded element. Returns None when OBX-2 is empty or names
a type this dictionary does not know as a composite, in which case
the value is treated as a scalar.
Sourcepub fn structure(&self, id: &str) -> Option<&[Item]>
pub fn structure(&self, id: &str) -> Option<&[Item]>
The abstract message structure named id, e.g. ORU_R01.
Sourcepub fn structure_id(&self, code: &str, trigger: &str) -> String
pub fn structure_id(&self, code: &str, trigger: &str) -> String
The message structure ID for a message-type code and trigger event,
e.g. ("ADT", "A04") -> ADT_A01.
Several trigger events share one structure — an A04 admit and an A08
update are both carried by ADT_A01 — and which ones is dictionary
knowledge, so it lives in the "aliases" section rather than in
code. Resolution order: an alias, then a structure named
CODE_TRIGGER, then one named CODE (which is how ACK^A01
reaches ACK), then CODE_TRIGGER unresolved, so an unknown
message type still gets the name HL7 would give it.
Sourcepub fn structure_ids(&self) -> impl Iterator<Item = &str>
pub fn structure_ids(&self) -> impl Iterator<Item = &str>
Every structure ID this dictionary defines, in name order.
Sourcepub fn segment_names(&self) -> impl Iterator<Item = &str>
pub fn segment_names(&self) -> impl Iterator<Item = &str>
Every segment name this dictionary defines, in name order.
Sourcepub fn type_names(&self) -> impl Iterator<Item = &str>
pub fn type_names(&self) -> impl Iterator<Item = &str>
Every composite data type this dictionary defines, in name order.
Sourcepub fn from_json(
text: &str,
name: impl Into<String>,
) -> Result<Dictionary, Error>
pub fn from_json( text: &str, name: impl Into<String>, ) -> Result<Dictionary, Error>
Load a dictionary from JSON, resolving an "inherits" member
against this crate’s bundled releases.
This is schema mode’s entry point: write the shape of the vendor’s messages as JSON, load it at runtime, and no recompile is needed when the business adds a field.
let dictionary = hl7_2::Dictionary::from_json(r#"{
"inherits": "2.5",
"segments": { "ZPD": ["ST", "XPN", "TS"] }
}"#, "acme").unwrap();
assert_eq!(dictionary.field_type("ZPD", 2), Some("XPN"));
assert_eq!(dictionary.field_type("PID", 5), Some("XPN")); // inherited§Errors
Error::Json when the text is not valid JSON, Error::Field or
Error::Missing when a member is the wrong shape or absent, and
Error::UnknownBase when inherits names a release this crate has
no dictionary for.
Sourcepub fn from_json_over(
text: &str,
name: impl Into<String>,
base: &Dictionary,
) -> Result<Dictionary, Error>
pub fn from_json_over( text: &str, name: impl Into<String>, base: &Dictionary, ) -> Result<Dictionary, Error>
Load a dictionary from JSON, layering it over base rather than
over a bundled release. An "inherits" member is ignored.
§Errors
Error::Json when the text is not valid JSON, Error::Field or
Error::Missing when a member is the wrong shape or absent, and
Error::UnknownBase when inherits names a release this crate has
no dictionary for.
Sourcepub fn from_json_resolving(
text: &str,
name: impl Into<String>,
resolve: impl Fn(&str) -> Option<Arc<Dictionary>>,
) -> Result<Dictionary, Error>
pub fn from_json_resolving( text: &str, name: impl Into<String>, resolve: impl Fn(&str) -> Option<Arc<Dictionary>>, ) -> Result<Dictionary, Error>
Load a dictionary from JSON, resolving "inherits" through
resolve. Used internally to load the bundled releases (where
resolution must not recurse back through the public entry point) and
available to callers who keep their own set of base dictionaries.
§Errors
Error::Json when the text is not valid JSON, Error::Field or
Error::Missing when a member is the wrong shape or absent, and
Error::UnknownBase when inherits names a release this crate has
no dictionary for.
Trait Implementations§
Source§impl Clone for Dictionary
impl Clone for Dictionary
Source§fn clone(&self) -> Dictionary
fn clone(&self) -> Dictionary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more