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: StringThe raw message text (normalized after parsing).
version: StringHL7 version from MSH-12.
message_structure: StringMessage structure from MSH-9.3 (or a derived value).
message_control_id: StringMessage control ID from MSH-10.
processing_id: StringProcessing ID from MSH-11.
segment_count: usizeNumber of segments in the message.
encoding: HL7EncodingThe encoding (delimiters) used by the message.
Implementations§
Source§impl Message
impl Message
Sourcepub fn with_message(text: impl Into<String>) -> Self
pub fn with_message(text: impl Into<String>) -> Self
Creates a message wrapping the given raw HL7 text (not yet parsed).
Sourcepub fn parse_str(
text: impl Into<String>,
bypass_validation: bool,
) -> Result<Self, Hl7Error>
pub fn parse_str( text: impl Into<String>, bypass_validation: bool, ) -> Result<Self, Hl7Error>
Convenience: wraps and parses text in one step.
Sourcepub fn parse(&mut self, bypass_validation: bool) -> Result<bool, Hl7Error>
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).
Sourcepub fn get_value(&self, path: &str) -> Result<String, Hl7Error>
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.
Sourcepub fn set_value(&mut self, path: &str, value: &str) -> Result<bool, Hl7Error>
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.
Sourcepub fn is_componentized(&self, path: &str) -> Result<bool, Hl7Error>
pub fn is_componentized(&self, path: &str) -> Result<bool, Hl7Error>
Whether the field at path is componentized.
Sourcepub fn has_repetitions(&self, path: &str) -> Result<bool, Hl7Error>
pub fn has_repetitions(&self, path: &str) -> Result<bool, Hl7Error>
Whether the field at path has repetitions.
Sourcepub fn is_subcomponentized(&self, path: &str) -> Result<bool, Hl7Error>
pub fn is_subcomponentized(&self, path: &str) -> Result<bool, Hl7Error>
Whether the component at path is subcomponentized.
Sourcepub fn add_new_segment(&mut self, segment: Segment) -> bool
pub fn add_new_segment(&mut self, segment: Segment) -> bool
Appends a segment, assigning it the next sequence number.
Sourcepub fn remove_segment(&mut self, segment_name: &str, index: usize) -> bool
pub fn remove_segment(&mut self, segment_name: &str, index: usize) -> bool
Removes the index-th segment with the given name.
Sourcepub fn segments_named(&self, segment_name: &str) -> Vec<&Segment>
pub fn segments_named(&self, segment_name: &str) -> Vec<&Segment>
All segments with the given name, in original order.
Sourcepub fn default_segment(&self, segment_name: &str) -> Option<&Segment>
pub fn default_segment(&self, segment_name: &str) -> Option<&Segment>
The first segment with the given name.
Sourcepub fn segments_named_mut(
&mut self,
segment_name: &str,
) -> Option<&mut Vec<Segment>>
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.
Sourcepub 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>
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.
Sourcepub fn get_ack(&self, bypass_validation: bool) -> Option<Message>
pub fn get_ack(&self, bypass_validation: bool) -> Option<Message>
Builds the positive acknowledgement (ACK, code AA) for this message.