pub struct Node { /* private fields */ }Expand description
One node of the generic tree.
A node is either a container (a group, a segment, or a field/component
whose type the dictionary can break apart) or a leaf holding text.
Node::text answers for both: on a container it is the decoded text
of everything beneath, delimiters included, so PID.5 reads as
SMITH^JOHN whether or not the dictionary knew what an XPN is.
Implementations§
Source§impl Node
impl Node
Sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
The er7 path that locates this node in the message, e.g.
PID[1]-5[1].1.2. Pass it to crate::Message::get,
crate::Message::set, or er7’s own query API.
The root node has an empty path: it is the message itself.
Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
The decoded text of this node and everything beneath it, with structural delimiters intact.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
True when the sender wrote the HL7 explicit null "" here, meaning
“clear this value” rather than “I have nothing to say”. The
difference matters on the way to a database, so it survives parsing.
Sourcepub fn child(&self, name: &str) -> Option<&Node>
pub fn child(&self, name: &str) -> Option<&Node>
The first child named name.
let message = hl7_2::parse("MSH|^~\\&|A||||1||ADT^A01|1|P|2.5\rPID|1||9||SMITH^JOHN")?;
let tree = message.tree();
let pid = tree.find("PID").unwrap();
assert_eq!(pid.child("PID.5").unwrap().child("XPN.2").unwrap().text(), "JOHN");Sourcepub fn children_named<'a>(
&'a self,
name: &'a str,
) -> impl Iterator<Item = &'a Node>
pub fn children_named<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = &'a Node>
Every child named name, in order. This is how repetitions are
read: a field sent as A~B is two PID.3 children, not one.
Sourcepub fn find(&self, name: &str) -> Option<&Node>
pub fn find(&self, name: &str) -> Option<&Node>
The first node named name anywhere beneath this one, searched
depth-first. Handy for reaching a segment without knowing which
groups a structure nests it in.
Sourcepub fn find_all<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a Node>
pub fn find_all<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a Node>
Every node named name anywhere beneath this one, in message order.
Sourcepub fn descendants(&self) -> Descendants<'_> ⓘ
pub fn descendants(&self) -> Descendants<'_> ⓘ
Every node beneath this one, depth-first, excluding this node.