pub struct Component(pub Component);Expand description
A Serde-enabled er7::Component.
A component is nothing but its subcomponents in order
(er7::Component::subcomponents), so it serializes as a plain array
rather than as a one-field object: ACME&1.2.3&ISO becomes
["ACME", "1.2.3", "ISO"]. The same shape Subcomponent chose for
itself, one level up.
Example:
use serde_er7::Component;
let message = er7::parse(r"MSH|^~\&|LAB|ACME&1.2.3&ISO")?;
let component = er7::Component {
subcomponents: vec![
er7::Subcomponent::new("ACME"),
er7::Subcomponent::new("1.2.3"),
er7::Subcomponent::new("ISO"),
],
};
let wrapped = Component(component);
assert_eq!(serde_json::to_string(&wrapped)?, r#"["ACME","1.2.3","ISO"]"#);
let back: Component = serde_json::from_str(r#"["ACME","1.2.3","ISO"]"#)?;
// Subcomponents join on `&`, one level below where components join on `^`.
assert_eq!(back.to_er7(&message.separators), "ACME&1.2.3&ISO");Tuple Fields§
§0: ComponentMethods from Deref<Target = Component>§
Sourcepub fn subcomponent(&self, n: usize) -> Option<&Subcomponent>
pub fn subcomponent(&self, n: usize) -> Option<&Subcomponent>
The 1-based subcomponent n, if the message carried one.
Index 0 returns None rather than element 1: HL7 numbering starts
at 1, so a 0 is a caller’s off-by-one and must not read as a valid
position (spec §5.4).
Example:
let message = er7::parse("MSH|^~\\&|LAB\rPID|1||9^^^ACME&1.2.3&ISO")?;
let assigning = message.segment("PID").unwrap().component(3, 4).unwrap();
assert_eq!(assigning.subcomponent(1).unwrap().raw, "ACME");
assert_eq!(assigning.subcomponent(2).unwrap().raw, "1.2.3");
assert!(assigning.subcomponent(9).is_none());
assert!(assigning.subcomponent(0).is_none());See also Component::subcomponent_mut to edit one.
Sourcepub fn subcomponent_mut(&mut self, n: usize) -> Option<&mut Subcomponent>
pub fn subcomponent_mut(&mut self, n: usize) -> Option<&mut Subcomponent>
Mutable access to the 1-based subcomponent n, for editing it with
Subcomponent::set.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when every subcomponent is empty. See Component::is_null
for the distinction that matters.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
True when this component is exactly the explicit null "" — one
subcomponent, and that subcomponent null.
Example:
let message = er7::parse("MSH|^~\\&|LAB\rPID|\"\"^X")?;
let repetition = message.segment("PID").unwrap()
.field(1).unwrap().repetition(1).unwrap();
assert!(repetition.component(1).unwrap().is_null());
assert!(!repetition.component(2).unwrap().is_null());Sourcepub fn to_er7(&self, separators: &Separators) -> String
pub fn to_er7(&self, separators: &Separators) -> String
Write this component as ER7, exactly as a receiver would read it.
Escape sequences are left intact, so the result can be sent, stored, or parsed again. This is the form the round-trip guarantee applies to (R16).
Example:
let message = er7::parse(r"MSH|^~\&|LAB|Smith \T\ Jones^X")?;
let separators = &message.separators;
let field = message.segment("MSH").unwrap().field(4).unwrap();
assert_eq!(field.to_er7(separators), r"Smith \T\ Jones^X");Sourcepub fn to_text(&self, separators: &Separators) -> String
pub fn to_text(&self, separators: &Separators) -> String
Write this component with its leaf text escape-decoded.
Structural delimiters remain, so the result shows the shape
of the value as well as its content (R17). That also means
the result is not re-parseable: a decoded \F\ becomes a
literal field separator. Use this for display, logging, and
database writes; use to_er7 for anything that goes back
into a message.
Example:
let message = er7::parse(r"MSH|^~\&|LAB|Smith \T\ Jones^X")?;
let separators = &message.separators;
let field = message.segment("MSH").unwrap().field(4).unwrap();
// The escape decodes; the component separator stays.
assert_eq!(field.to_text(separators), "Smith & Jones^X");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Component
impl<'de> Deserialize<'de> for Component
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>,
Read an array of strings into subcomponents.
impl Eq for Component
Source§impl Serialize for Component
impl Serialize for Component
Source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Write each subcomponent as one array element.
This clones every subcomponent to borrow it as a Subcomponent,
which is the price of keeping one owning wrapper type per tree level
instead of a second, borrowing family — a fair trade for an HL7
message, which is kilobytes, not gigabytes.