use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Hl7Error {
pub message: String,
pub code: Option<String>,
}
impl Hl7Error {
pub const REQUIRED_FIELD_MISSING: &'static str =
"Validation Error - Required field missing in message";
pub const UNSUPPORTED_MESSAGE_TYPE: &'static str =
"Validation Error - Message Type not supported by this implementation";
pub const BAD_MESSAGE: &'static str = "Validation Error - Bad Message";
pub const PARSING_ERROR: &'static str = "Parsing Error";
pub const SERIALIZATION_ERROR: &'static str = "Serialization Error";
pub fn new(message: impl Into<String>) -> Self {
Self { message: message.into(), code: None }
}
pub fn with_code(message: impl Into<String>, code: impl Into<String>) -> Self {
Self { message: message.into(), code: Some(code.into()) }
}
}
impl fmt::Display for Hl7Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.code {
Some(code) => write!(f, "{code} : {}", self.message),
None => write!(f, "{}", self.message),
}
}
}
impl std::error::Error for Hl7Error {}