use fhirconnect::engine::outcome::{Loss, SkipReason, Warning};
use crate::terminology::transcode::Relation;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Withheld {
relation: Relation,
terminology: String,
code: String,
element: Option<String>,
}
impl Withheld {
#[must_use]
pub fn of(warning: &Warning) -> Option<Self> {
let Loss::Skipped {
reason:
SkipReason::TermMappingMatch {
match_code,
terminology,
code,
},
..
} = warning.loss()
else {
return None;
};
Some(Self {
relation: Relation::of(*match_code)?,
terminology: terminology.clone(),
code: code.clone(),
element: warning.location().fhir().map(str::to_owned),
})
}
#[must_use]
pub const fn relation(&self) -> Relation {
self.relation
}
#[must_use]
pub fn terminology(&self) -> &str {
&self.terminology
}
#[must_use]
pub fn code(&self) -> &str {
&self.code
}
#[must_use]
pub fn element(&self) -> Option<&str> {
self.element.as_deref()
}
#[must_use]
pub fn narrative(&self) -> String {
let element = self.element.as_deref().unwrap_or("A coded value");
format!(
"{element}: {} {} {}",
self.relation.words(),
self.terminology,
self.code
)
}
}