Struct ParsedMessageOwned

Source
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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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 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
Source§

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

Source§

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

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

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

Source§

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

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

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

Source§

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,

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

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