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
impl ParsedMessageOwned
Sourcepub fn parse<'s, S: ToString + 's>(
source: S,
lenient_segment_separators: bool,
) -> Result<ParsedMessageOwned, ParseError>
pub fn parse<'s, S: ToString + 's>( source: S, lenient_segment_separators: bool, ) -> Result<ParsedMessageOwned, ParseError>
Parse a string to obtain the underlying message
Sourcepub fn has_segment<S: AsRef<str>>(&self, segment: S) -> bool
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)
Sourcepub fn segment<S: AsRef<str>>(&self, segment: S) -> Option<&Segment>
pub fn segment<S: AsRef<str>>(&self, segment: S) -> Option<&Segment>
Access the first segment identified by segment
Sourcepub fn segment_mut<S: AsRef<str>>(&mut self, segment: S) -> Option<&mut Segment>
pub fn segment_mut<S: AsRef<str>>(&mut self, segment: S) -> Option<&mut Segment>
Mutable access to the first segment identified by segment
Sourcepub fn segment_count<S: AsRef<str>>(&self, segment: S) -> usize
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
Sourcepub fn segment_n<S: AsRef<str>>(&self, segment: S, n: usize) -> Option<&Segment>
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)
)
Sourcepub fn segment_n_mut<S: AsRef<str>>(
&mut self,
segment: S,
n: usize,
) -> Option<&mut Segment>
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)
)
Sourcepub fn get_field_source<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
) -> Option<&str>
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");
Sourcepub fn get_field<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
) -> Option<&Field>
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.
Sourcepub fn get_field_mut<S: AsRef<str>>(
&mut self,
segment: (S, usize),
field: NonZeroUsize,
) -> Option<&mut Field>
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.
Sourcepub fn get_repeat_source<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
) -> Option<&str>
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");
Sourcepub fn get_repeat<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
) -> Option<&Repeat>
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
Sourcepub fn get_repeat_mut<S: AsRef<str>>(
&mut self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
) -> Option<&mut Repeat>
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
Sourcepub fn get_component_source<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize,
) -> Option<&str>
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");
Sourcepub fn get_component<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize,
) -> Option<&Component>
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
Sourcepub fn get_component_mut<S: AsRef<str>>(
&mut self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize,
) -> Option<&mut Component>
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
Sourcepub fn get_sub_component_source<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize,
sub_component: NonZeroUsize,
) -> Option<&str>
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");
Sourcepub fn get_sub_component<S: AsRef<str>>(
&self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize,
sub_component: NonZeroUsize,
) -> Option<&SubComponent>
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
Sourcepub 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>
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
Sourcepub fn segment_at_cursor(
&self,
cursor: usize,
) -> Option<(&str, usize, &Segment)>
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
Sourcepub fn locate_cursor(&self, cursor: usize) -> LocatedData<'_>
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)
Sourcepub fn query_value<Q, QErr>(&self, query: Q) -> Result<Option<&str>, QErr>where
Q: TryInto<LocationQuery, Error = QErr>,
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
query
- a LocationQuery targeting you want to access
§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"));
Sourcepub fn query<Q, QErr>(&self, query: Q) -> Result<Option<Range<usize>>, QErr>where
Q: TryInto<LocationQuery, Error = QErr>,
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
query
- a LocationQuery targeting you want to access
§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
impl Clone for ParsedMessageOwned
Source§fn clone(&self) -> ParsedMessageOwned
fn clone(&self) -> ParsedMessageOwned
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ParsedMessageOwned
impl Debug for ParsedMessageOwned
Source§impl<'de> Deserialize<'de> for ParsedMessageOwned
impl<'de> Deserialize<'de> for ParsedMessageOwned
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'s> From<ParsedMessage<'s>> for ParsedMessageOwned
impl<'s> From<ParsedMessage<'s>> for ParsedMessageOwned
Source§fn from(value: ParsedMessage<'s>) -> Self
fn from(value: ParsedMessage<'s>) -> Self
Source§impl PartialEq for ParsedMessageOwned
impl PartialEq for ParsedMessageOwned
Source§impl Serialize for ParsedMessageOwned
impl Serialize for ParsedMessageOwned
impl Eq for ParsedMessageOwned
impl StructuralPartialEq for ParsedMessageOwned
Auto Trait Implementations§
impl Freeze for ParsedMessageOwned
impl RefUnwindSafe for ParsedMessageOwned
impl Send for ParsedMessageOwned
impl Sync for ParsedMessageOwned
impl Unpin for ParsedMessageOwned
impl UnwindSafe for ParsedMessageOwned
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.