pub struct ParsedMessageOwned {
    pub source: String,
    pub separators: Separators,
    pub segments: IndexMap<String, Segments>,
}
Expand description

A parsed message that owns its string slice. The message structure is valid, but the contents may or may not be.

Fields§

§source: String

The original source message, generally used to extract items using ranges

§separators: Separators

The separators & encoding characters defined at the beginning of the MSH segment

§segments: IndexMap<String, Segments>

All the segments stored within the message

Implementations§

source§

impl ParsedMessageOwned

source

pub fn parse<'s, S: ToString + 's>( source: S, lenient_segment_separators: bool ) -> Result<ParsedMessageOwned, ParseError>

Parse a string to obtain the underlying message

source

pub fn has_segment<S: AsRef<str>>(&self, segment: S) -> bool

Whether the message contains any of the given segment identifier (MSH, PID, PV1, etc)

source

pub fn segment<S: AsRef<str>>(&self, segment: S) -> Option<&Segment>

Access the first segment identified by segment

source

pub fn segment_mut<S: AsRef<str>>(&mut self, segment: S) -> Option<&mut Segment>

Mutable access to the first segment identified by segment

source

pub fn segment_count<S: AsRef<str>>(&self, segment: S) -> usize

Return the number of times segments identified by segment are present in the message

source

pub fn segment_n<S: AsRef<str>>(&self, segment: S, n: usize) -> Option<&Segment>

Get the 0-based nth segment identified by segment (i.e., if there were two OBX segments and you wanted the second one, call message.segment_n("OBX", 1))

source

pub fn segment_n_mut<S: AsRef<str>>( &mut self, segment: S, n: usize ) -> Option<&mut Segment>

Mutable access to the 0-based nth segment identified by segment (i.e., if there were two OBX Segments and you wanted the second one, call message.segment_n_mut("OBX", 1))

source

pub fn get_field_source<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize ) -> Option<&str>

Directly get the source (not yet decoded) for a given field, if it exists in the message. The field is identified by the segment identifier, segment repeat identifier, and 1-based field identifier.

Examples
let message = include_str!("../test_assets/sample_adt_a01.hl7");
let message = ParsedMessageOwned::parse(&message, true).expect("can parse message");

let message_type = message.get_field_source(("MSH", 0), NonZeroUsize::new(9).unwrap());
assert_eq!(message_type.unwrap(), "ADT^A01");
source

pub fn get_field<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize ) -> Option<&Field>

Get the field for a given field, if it exists in the message. The field is identified by the segment identifier, segment repeat identifier, and 1-based field identifier.

source

pub fn get_field_mut<S: AsRef<str>>( &mut self, segment: (S, usize), field: NonZeroUsize ) -> Option<&mut Field>

Get a mutable reference to a field for a given field, if it exists in the message. The field is identified by the segment identifier, segment repeat identifier, and 1-based field identifier.

source

pub fn get_repeat_source<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize ) -> Option<&str>

Directly get the source (not yet decoded) for a given field and repeat, if it exists in the message. The field is identified by the segment identifier, segment repeat identifier, 1-based field identifier, and the repeat identifier

Examples
let message = include_str!("../test_assets/sample_adt_a04.hl7");
let message = ParsedMessageOwned::parse(&message, true).expect("can parse message");

let allergy_reaction_2 = message.get_repeat_source(
    ("AL1", 0),
    NonZeroUsize::new(5).unwrap(),
    NonZeroUsize::new(2).unwrap());
assert_eq!(allergy_reaction_2.unwrap(), "RASH");
source

pub fn get_repeat<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize ) -> Option<&Repeat>

Directly get the repeat for a given field and repeat, if it exists in the message. The field is identified by the segment identifier, segment repeat identifier, 1-based field identifier, and the repeat identifier

source

pub fn get_repeat_mut<S: AsRef<str>>( &mut self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize ) -> Option<&mut Repeat>

Get a mutable reference to the repeat for a given field and repeat, if it exists in the message. The field is identified by the segment identifier, segment repeat identifier, 1-based field identifier, and the repeat identifier

source

pub fn get_component_source<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize ) -> Option<&str>

Directly get the source (not yet decoded) for a given component, if it exists in the message. The component is identified by the segment identifier, segment repeat identifier, 1-based field identifier, and 1-based component identifier

Examples
let message = include_str!("../test_assets/sample_adt_a01.hl7");
let message = ParsedMessageOwned::parse(&message, true).expect("can parse message");

let trigger_event = message.get_component_source(
    ("MSH", 0),
    NonZeroUsize::new(9).unwrap(),
    NonZeroUsize::new(1).unwrap(),
    NonZeroUsize::new(2).unwrap());
assert_eq!(trigger_event.unwrap(), "A01");
source

pub fn get_component<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize ) -> Option<&Component>

Directly get the component for a given component, if it exists in the message. The component is identified by the segment identifier, segment repeat identifier, 1-based field identifier, and 1-based component identifier

source

pub fn get_component_mut<S: AsRef<str>>( &mut self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize ) -> Option<&mut Component>

Get a mutable reference to a component for a given component, if it exists in the message. The component is identified by the segment identifier, segment repeat identifier, 1-based field identifier, and 1-based component identifier

source

pub fn get_sub_component_source<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize, sub_component: NonZeroUsize ) -> Option<&str>

Directly get the source (not yet decoded) for a given sub-component, if it exists in the message. The component is identified by the segment identifier, segment repeat identifier, 1-based field identifier, 1-based component identifier, and 1-based sub-component identifier

Examples
let message = include_str!("../test_assets/sample_oru_r01_generic.hl7");
let message = ParsedMessageOwned::parse(message, true).expect("can parse message");

let universal_id = message.get_sub_component_source(
    ("PID", 0),
    NonZeroUsize::new(3).unwrap(),
    NonZeroUsize::new(1).unwrap(),
    NonZeroUsize::new(4).unwrap(),
    NonZeroUsize::new(2).unwrap());
assert_eq!(universal_id.unwrap(), "1.2.840.114398.1.100");
source

pub fn get_sub_component<S: AsRef<str>>( &self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize, sub_component: NonZeroUsize ) -> Option<&SubComponent>

Directly get the sub-component for a given sub-component, if it exists in the message. The component is identified by the segment identifier, segment repeat identifier, 1-based field identifier, 1-based component identifier, and 1-based sub-component identifier

source

pub fn get_sub_component_mut<S: AsRef<str>>( &mut self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize, sub_component: NonZeroUsize ) -> Option<&mut SubComponent>

Get a mutable reference to the sub-component for a given sub-component, if it exists in the message. The component is identified by the segment identifier, segment repeat identifier, 1-based field identifier, 1-based component identifier, and 1-based sub-component identifier

source

pub fn segment_at_cursor( &self, cursor: usize ) -> Option<(&str, usize, &Segment)>

Locate a segment at the cursor position

Arguments
  • cursor - The cursor location (0-based character index of the original message)
Returns

A tuple containing the HL7 segment identifier, 0-based segment repeat number and a reference to the field. If the segment doesn’t contain the cursor, returns None

source

pub fn locate_cursor(&self, cursor: usize) -> LocatedData<'_>

Deeply locate the cursor by returning the sub-component, component, field, and segment that the cursor is located in (if any)

source

pub fn query_value<Q, QErr>(&self, query: Q) -> Result<Option<&str>, QErr>
where Q: TryInto<LocationQuery, Error = QErr>,

Query the message for a given segment, field, component, or sub-comonent.

Arguments
Returns
  • Result::Err if the location query couldn’t be parsed
  • Result::Ok if the item location query could be parsed message
    • Option::Some containing the item source if the queried item was found in the message
    • Option::None if the queried item was not found in the message
Examples
let message = include_str!("../test_assets/sample_adt_a01.hl7");
let message = ParsedMessageOwned::parse(message, true).expect("can parse message");

let trigger_event = message.query_value("MSH.9.2").expect("can parse location query");
assert_eq!(trigger_event, Some("A01"));
source

pub fn query<Q, QErr>(&self, query: Q) -> Result<Option<Range<usize>>, QErr>
where Q: TryInto<LocationQuery, Error = QErr>,

Query the message for a given segment, field, component, or sub-comonent, returning the range in the source string that the item occupies.

Arguments
Returns
  • Result::Err if the location query couldn’t be parsed
  • Result::Ok if the item location query could be parsed message
    • Option::Some containing the item source if the queried item was found in the message
    • Option::None if the queried item was not found in the message
Examples
let message = include_str!("../test_assets/sample_adt_a01.hl7");
let message = ParsedMessageOwned::parse(message, true).expect("can parse message");

let trigger_event = message.query("MSH.9.2").expect("can parse location query");
assert_eq!(trigger_event, Some(40..43));

Trait Implementations§

source§

impl Clone for ParsedMessageOwned

source§

fn clone(&self) -> ParsedMessageOwned

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for ParsedMessageOwned

source§

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

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

impl<'de> Deserialize<'de> for ParsedMessageOwned

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'s> From<ParsedMessage<'s>> for ParsedMessageOwned

source§

fn from(value: ParsedMessage<'s>) -> Self

Converts to this type from the input type.
source§

impl PartialEq for ParsedMessageOwned

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for ParsedMessageOwned

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for ParsedMessageOwned

source§

impl StructuralEq for ParsedMessageOwned

source§

impl StructuralPartialEq for ParsedMessageOwned

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,

§

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>,

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,