use fhir_types::r4::codeable_concept::CodeableConcept;
use super::form::Slot;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum EmptyReason {
NilKnown,
Unavailable,
}
impl EmptyReason {
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::NilKnown => "nilknown",
Self::Unavailable => "unavailable",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) enum Emptied {
Coded(EmptyReason),
Mapped(CodeableConcept),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Section {
pub(super) slot: &'static Slot,
pub(super) paragraphs: Vec<String>,
pub(super) entries: Vec<String>,
pub(super) authors: Vec<String>,
pub(super) empty: Option<Emptied>,
}
impl Section {
#[must_use]
pub fn new(slot: &'static Slot, paragraphs: Vec<String>) -> Self {
Self {
slot,
paragraphs,
entries: Vec::new(),
authors: Vec::new(),
empty: None,
}
}
#[must_use]
pub const fn slot(&self) -> &'static Slot {
self.slot
}
#[must_use]
pub fn with_entry(mut self, full_url: String) -> Self {
self.entries.push(full_url);
self
}
#[must_use]
pub fn with_author(mut self, full_url: String) -> Self {
self.authors.push(full_url);
self
}
#[must_use]
pub fn empty_because(mut self, reason: EmptyReason) -> Self {
self.empty = Some(Emptied::Coded(reason));
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MappedSection {
pub slot: &'static Slot,
pub entries: Vec<String>,
pub empty_reason: Option<CodeableConcept>,
}
impl MappedSection {
#[must_use]
pub fn into_section(self, paragraphs: Vec<String>) -> Section {
Section {
entries: self.entries,
empty: self.empty_reason.map(Emptied::Mapped),
..Section::new(self.slot, paragraphs)
}
}
}