Struct hl7_parser::ParsedMessage
source · pub struct ParsedMessage<'s> {
pub source: &'s str,
pub separators: Separators,
pub segments: IndexMap<&'s str, Segments>,
}
Expand description
A parsed message. The message structure is valid, but the contents may or may not be.
Fields§
§source: &'s str
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<&'s str, Segments>
All the segments stored within the message
Implementations§
source§impl<'s> ParsedMessage<'s>
impl<'s> ParsedMessage<'s>
sourcepub fn parse(
source: &'s str,
lenient_segment_separators: bool
) -> Result<ParsedMessage<'s>, ParseError>
pub fn parse( source: &'s str, lenient_segment_separators: bool ) -> Result<ParsedMessage<'s>, ParseError>
Parse a string to obtain the underlying message
sourcepub fn has_segment<S: AsRef<str>>(&'s self, segment: S) -> bool
pub fn has_segment<S: AsRef<str>>(&'s self, segment: S) -> bool
Whether the message contains any of the given segment identifier (MSH
, PID
, PV1
, etc)
sourcepub fn segment<S: AsRef<str>>(&'s self, segment: S) -> Option<&'s Segment>
pub fn segment<S: AsRef<str>>(&'s self, segment: S) -> Option<&'s Segment>
Access the first segment identified by segment
sourcepub fn segment_count<S: AsRef<str>>(&'s self, segment: S) -> usize
pub fn segment_count<S: AsRef<str>>(&'s 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>>(
&'s self,
segment: S,
n: usize
) -> Option<&'s Segment>
pub fn segment_n<S: AsRef<str>>( &'s self, segment: S, n: usize ) -> Option<&'s 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>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize
) -> Option<&'s str>
pub fn get_field_source<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize ) -> Option<&'s 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 = ParsedMessage::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>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize
) -> Option<&'s Field>
pub fn get_field<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize ) -> Option<&'s 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_repeat_source<S: AsRef<str>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize
) -> Option<&'s str>
pub fn get_repeat_source<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize ) -> Option<&'s 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 = ParsedMessage::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>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize
) -> Option<&'s Repeat>
pub fn get_repeat<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize ) -> Option<&'s 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_component_source<S: AsRef<str>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize
) -> Option<&'s str>
pub fn get_component_source<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize ) -> Option<&'s 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 = ParsedMessage::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>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize
) -> Option<&'s Component>
pub fn get_component<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize ) -> Option<&'s 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_sub_component_source<S: AsRef<str>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize,
sub_component: NonZeroUsize
) -> Option<&'s str>
pub fn get_sub_component_source<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize, sub_component: NonZeroUsize ) -> Option<&'s 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 = ParsedMessage::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>>(
&'s self,
segment: (S, usize),
field: NonZeroUsize,
repeat: NonZeroUsize,
component: NonZeroUsize,
sub_component: NonZeroUsize
) -> Option<&'s SubComponent>
pub fn get_sub_component<S: AsRef<str>>( &'s self, segment: (S, usize), field: NonZeroUsize, repeat: NonZeroUsize, component: NonZeroUsize, sub_component: NonZeroUsize ) -> Option<&'s 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 locate_cursor(&'s self, cursor: usize) -> LocatedData<'s>
pub fn locate_cursor(&'s self, cursor: usize) -> LocatedData<'s>
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>(&'s self, query: Q) -> Result<Option<&'s str>, QErr>where
Q: TryInto<LocationQuery, Error = QErr>,
pub fn query_value<Q, QErr>(&'s self, query: Q) -> Result<Option<&'s 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 message
Examples
let message = include_str!("../test_assets/sample_adt_a01.hl7");
let message = ParsedMessage::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 range in the source if the queried item was found in the message
- Option::None if the queried item was not found in the message message
Examples
let message = include_str!("../test_assets/sample_adt_a01.hl7");
let message = ParsedMessage::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<'s> Clone for ParsedMessage<'s>
impl<'s> Clone for ParsedMessage<'s>
source§fn clone(&self) -> ParsedMessage<'s>
fn clone(&self) -> ParsedMessage<'s>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'s> Debug for ParsedMessage<'s>
impl<'s> Debug for ParsedMessage<'s>
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<'s> PartialEq for ParsedMessage<'s>
impl<'s> PartialEq for ParsedMessage<'s>
source§fn eq(&self, other: &ParsedMessage<'s>) -> bool
fn eq(&self, other: &ParsedMessage<'s>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'s> Serialize for ParsedMessage<'s>
impl<'s> Serialize for ParsedMessage<'s>
impl<'s> Eq for ParsedMessage<'s>
impl<'s> StructuralEq for ParsedMessage<'s>
impl<'s> StructuralPartialEq for ParsedMessage<'s>
Auto Trait Implementations§
impl<'s> RefUnwindSafe for ParsedMessage<'s>
impl<'s> Send for ParsedMessage<'s>
impl<'s> Sync for ParsedMessage<'s>
impl<'s> Unpin for ParsedMessage<'s>
impl<'s> UnwindSafe for ParsedMessage<'s>
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.