Skip to main content

Message

Struct Message 

Source
pub struct Message {
    pub hl7_message: String,
    pub version: String,
    pub message_structure: String,
    pub message_control_id: String,
    pub processing_id: String,
    pub segment_count: usize,
    pub encoding: HL7Encoding,
    /* private fields */
}
Expand description

A parsed HL7 v2 message: a collection of Segments keyed by name, plus the message-level metadata extracted from the MSH segment.

Fields§

§hl7_message: String

The raw message text (normalized after parsing).

§version: String

HL7 version from MSH-12.

§message_structure: String

Message structure from MSH-9.3 (or a derived value).

§message_control_id: String

Message control ID from MSH-10.

§processing_id: String

Processing ID from MSH-11.

§segment_count: usize

Number of segments in the message.

§encoding: HL7Encoding

The encoding (delimiters) used by the message.

Implementations§

Source§

impl Message

Source

pub fn new() -> Self

Creates an empty message with default encoding.

Source

pub fn with_message(text: impl Into<String>) -> Self

Creates a message wrapping the given raw HL7 text (not yet parsed).

Source

pub fn parse_str( text: impl Into<String>, bypass_validation: bool, ) -> Result<Self, Hl7Error>

Convenience: wraps and parses text in one step.

Source

pub fn parse(&mut self, bypass_validation: bool) -> Result<bool, Hl7Error>

Parses Self::hl7_message into segments/fields/components.

Returns true when the message round-trips (re-serializing yields the same text). Pass bypass_validation = true to skip structural validation (do not use for newly constructed messages).

Source

pub fn serialize(&self) -> Result<String, Hl7Error>

Serializes the message back to HL7 text.

Source

pub fn get_value(&self, path: &str) -> Result<String, Hl7Error>

Gets the value at a path such as PID.5.2 (segment.field.component.subcomponent).

A segment occurrence may be supplied as PID(2).5. Returns the decoded value; a “present but null” value is returned as an empty string.

Source

pub fn set_value(&mut self, path: &str, value: &str) -> Result<bool, Hl7Error>

Sets the value at a path such as PID.5.2 in every matching segment.

Source

pub fn is_componentized(&self, path: &str) -> Result<bool, Hl7Error>

Whether the field at path is componentized.

Source

pub fn has_repetitions(&self, path: &str) -> Result<bool, Hl7Error>

Whether the field at path has repetitions.

Source

pub fn is_subcomponentized(&self, path: &str) -> Result<bool, Hl7Error>

Whether the component at path is subcomponentized.

Source

pub fn add_new_segment(&mut self, segment: Segment) -> bool

Appends a segment, assigning it the next sequence number.

Source

pub fn remove_segment(&mut self, segment_name: &str, index: usize) -> bool

Removes the index-th segment with the given name.

Source

pub fn segments(&self) -> Vec<&Segment>

All segments in original order.

Source

pub fn segments_named(&self, segment_name: &str) -> Vec<&Segment>

All segments with the given name, in original order.

Source

pub fn default_segment(&self, segment_name: &str) -> Option<&Segment>

The first segment with the given name.

Source

pub fn segments_named_mut( &mut self, segment_name: &str, ) -> Option<&mut Vec<Segment>>

Mutable access to all segments with the given name, in original order.

Source

pub fn add_segment_msh( &mut self, sending_application: &str, sending_facility: &str, receiving_application: &str, receiving_facility: &str, security: Option<&str>, message_type: &str, message_control_id: &str, processing_id: &str, version: &str, ) -> Result<(), Hl7Error>

Builds and appends an MSH header segment.

Source

pub fn get_ack(&self, bypass_validation: bool) -> Option<Message>

Builds the positive acknowledgement (ACK, code AA) for this message.

Source

pub fn get_nack( &self, code: &str, err_msg: &str, bypass_validation: bool, ) -> Option<Message>

Builds a negative acknowledgement (NACK) with the given code and message.

Source

pub fn get_mllp(&self) -> Result<Vec<u8>, Hl7Error>

Serializes the message into an MLLP-framed byte buffer.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

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 Message

Source§

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

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

impl Default for Message

Source§

fn default() -> Message

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

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.