Skip to main content

Dictionary

Struct Dictionary 

Source
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

Source

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.

Source

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.

Source

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.

Source

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”.

Source

pub fn is_composite(&self, data_type: &str) -> bool

True when data_type is a composite this dictionary can break apart.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn structure(&self, id: &str) -> Option<&[Item]>

The abstract message structure named id, e.g. ORU_R01.

Source

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.

Source

pub fn structure_ids(&self) -> impl Iterator<Item = &str>

Every structure ID this dictionary defines, in name order.

Source

pub fn segment_names(&self) -> impl Iterator<Item = &str>

Every segment name this dictionary defines, in name order.

Source

pub fn type_names(&self) -> impl Iterator<Item = &str>

Every composite data type this dictionary defines, in name order.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Dictionary

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dictionary

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Dictionary

Source§

fn default() -> Dictionary

Returns the “default value” for a type. Read more
Source§

impl Eq for Dictionary

Source§

impl PartialEq for Dictionary

Source§

fn eq(&self, other: &Dictionary) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Dictionary

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.