pub struct Builder { /* private fields */ }Expand description
Assemble a message segment by segment; see the module documentation.
use hl7_2::{Builder, Version};
let message = Builder::new(Version::V2_5)
.message_type("ADT", "A01")
.control_id("MSG00001")
.timestamp("20240101093851")
.sending("HIS", "HOSPITAL")
.receiving("EPIC", "CLINIC")
.segment("EVN")
.set("EVN-1", "A01")
.segment("PID")
.set("PID-3.1", "241900")
.set("PID-5.1.1", "SMITH")
.set("PID-5.2", "JOHN")
.build()?;
assert_eq!(message.structure_id(), "ADT_A01");
assert!(message.to_er7().contains("PID|||241900||SMITH^JOHN"));Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(version: Version) -> Builder
pub fn new(version: Version) -> Builder
Start a message for version, with the standard delimiters
(|^~\&), a processing ID of P (production), and MSH-12 set.
Everything else — message type, control ID, timestamp, sender,
receiver — is empty until set, and MSH-9 and MSH-10 being empty is
exactly what Message::validate reports, so a half-built message
says so rather than looking finished.
§Panics
Never in practice: the bundled dictionaries are embedded at compile time and parsed on first use, so a failure here would mean this crate shipped a malformed one.
Sourcepub fn with_dictionary(version: Version, dictionary: Arc<Dictionary>) -> Builder
pub fn with_dictionary(version: Version, dictionary: Arc<Dictionary>) -> Builder
Start a message for version, read through dictionary — the
schema-mode counterpart of Builder::new.
§Panics
Never in practice: the bundled dictionaries are embedded at compile time and parsed on first use, so a failure here would mean this crate shipped a malformed one.
Sourcepub fn from_message(message: Message) -> Builder
pub fn from_message(message: Message) -> Builder
Start from an existing message, to add to it or answer it.
Sourcepub fn message_type(self, code: &str, trigger: &str) -> Builder
pub fn message_type(self, code: &str, trigger: &str) -> Builder
Set MSH-9: the message code and trigger event, e.g. ("ADT", "A01"). The structure ID (MSH-9.3) is filled in from the
dictionary, so ADT^A04 correctly declares ADT_A01.
Sourcepub fn control_id(self, id: &str) -> Builder
pub fn control_id(self, id: &str) -> Builder
Set MSH-10, the message control ID: the sender’s own identifier for this message, which the receiver echoes in its acknowledgement.
Sourcepub fn timestamp(self, timestamp: &str) -> Builder
pub fn timestamp(self, timestamp: &str) -> Builder
Set MSH-7, the date and time the message was sent, as HL7 writes it
(YYYYMMDDHHMMSS, optionally with a fraction and an offset).
Sourcepub fn sending(self, application: &str, facility: &str) -> Builder
pub fn sending(self, application: &str, facility: &str) -> Builder
Set MSH-3 and MSH-4, the sending application and facility.
Sourcepub fn receiving(self, application: &str, facility: &str) -> Builder
pub fn receiving(self, application: &str, facility: &str) -> Builder
Set MSH-5 and MSH-6, the receiving application and facility.
Sourcepub fn processing_id(self, id: &str) -> Builder
pub fn processing_id(self, id: &str) -> Builder
Set MSH-11, the processing ID: P production, T training, D
debugging. A builder starts at P.
Sourcepub fn segment(self, name: &str) -> Builder
pub fn segment(self, name: &str) -> Builder
Append an empty segment. Subsequent Builder::set calls that name
this segment address this occurrence, because paths without an
explicit [n] mean the first — so add a segment, fill it, then add
the next.
Sourcepub fn set(self, path: &str, value: &str) -> Builder
pub fn set(self, path: &str, value: &str) -> Builder
Set a value, escaping delimiters in it; see Message::set.
Sourcepub fn set_er7(self, path: &str, er7_text: &str) -> Builder
pub fn set_er7(self, path: &str, er7_text: &str) -> Builder
Set a value from text that is already ER7-encoded; see
Message::set_er7.
Sourcepub fn encode(self, value: &impl ToHl7) -> Builder
pub fn encode(self, value: &impl ToHl7) -> Builder
Write a crate::ToHl7 value’s fields into the message being
built — struct mode’s other direction.
Sourcepub fn build_valid(self) -> Result<Message, Error>
pub fn build_valid(self) -> Result<Message, Error>
Finish, and reject a message that does not pass validation. Use it for an outbound message, where sending something malformed costs more than noticing here.
§Errors
As Builder::build, and additionally when the built message does
not validate against its dictionary.