use dicom_core::Tag;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MwlError {
MissingPatientId,
MissingModality {
found: Option<String>,
},
MissingStationAe,
MissingRequestedProcedureId,
MissingStartDateTime,
NoStudyUid,
TooLong {
tag: Tag,
max: usize,
actual: usize,
},
Write(String),
}
impl fmt::Display for MwlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MwlError::MissingPatientId => write!(f, "PID-3.1 (Patient ID) is absent; it is Type 1 in the worklist"),
MwlError::MissingModality { found: Some(v) } => write!(
f,
"no modality: IPC-5 absent and OBR-24 {v:?} is not a DICOM modality or a translatable HL7 table 0074 code"
),
MwlError::MissingModality { found: None } => {
write!(f, "no modality: neither IPC-5 nor OBR-24 is present")
}
MwlError::MissingStationAe => write!(
f,
"no Scheduled Station AE Title: IPC-9 absent and no default supplied"
),
MwlError::MissingRequestedProcedureId => write!(
f,
"no Requested Procedure ID: OBR-19, IPC-2 and the placer order number (ORC-2, OBR-2) are all absent"
),
MwlError::MissingStartDateTime => write!(
f,
"no scheduled start: neither OBR-27.4 nor TQ1-7 carries a date and time"
),
MwlError::NoStudyUid => write!(
f,
"the order carries no Study Instance UID (IPC-3, ZDS-1 or OBX) and none was generated: either the policy refuses, or there is no Requested Procedure ID and no Accession Number to derive one from"
),
MwlError::TooLong { tag, max, actual } => write!(
f,
"{tag} is {actual} characters, the VR allows {max}; not truncated because the result would be a different identifier"
),
MwlError::Write(e) => write!(f, "cannot encode the worklist item: {e}"),
}
}
}
impl std::error::Error for MwlError {}