pub mod boolean;
pub mod code_phrase;
pub mod coded_text;
pub mod count;
pub mod date;
pub mod date_time;
pub mod duration;
pub mod encapsulated;
pub mod interval;
pub mod null_flavour;
pub mod number;
pub mod ordinal;
pub mod party;
pub mod party_ref;
pub mod proportion;
pub mod quantity;
pub mod range;
pub mod scalar;
pub mod string;
pub mod term_mapping;
pub mod text;
pub mod time;
pub mod uri;
use core::fmt;
use crate::engine::lens::date_time::InstantShortfall;
use crate::engine::lens::term_mapping::Withheld;
use crate::model::ast::keyword::Direction;
pub trait Lens<O, F> {
fn cell(&self) -> &'static str;
fn get(&self, source: &O) -> Result<F, LensError>;
fn put(&self, view: &F, existing: Option<&O>) -> Result<O, LensError>;
fn fallbacks(&self, view: &F) -> Vec<Fallback>;
fn withheld(&self, _source: &O) -> Vec<Withheld> {
Vec::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Fallback {
cell: &'static str,
field: &'static str,
}
impl Fallback {
#[must_use]
pub const fn new(cell: &'static str, field: &'static str) -> Self {
Self { cell, field }
}
#[must_use]
pub const fn cell(&self) -> &'static str {
self.cell
}
#[must_use]
pub const fn field(&self) -> &'static str {
self.field
}
}
impl fmt::Display for Fallback {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} filled {}", self.cell, self.field)
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum LensError {
#[error("{cell} going {direction} needs {attribute}, which the source does not carry")]
Missing {
cell: &'static str,
attribute: &'static str,
direction: Direction,
},
#[error("{cell} going {direction} cannot carry {attribute} {found}: {reason}")]
Shape {
cell: &'static str,
attribute: &'static str,
found: String,
reason: &'static str,
direction: Direction,
},
#[error("{cell} is defined going {defined} only, and was run going {direction}")]
OneWay {
cell: &'static str,
defined: Direction,
direction: Direction,
},
#[error("{cell} going {direction} is not defined for {situation}: {reason}")]
Undefined {
cell: &'static str,
situation: &'static str,
reason: &'static str,
direction: Direction,
},
#[error("no data-type cell pairs {rm_type} with {kind} going {direction}")]
NoCell {
rm_type: String,
kind: &'static str,
direction: Direction,
},
#[error("DV_DATE_TIME against instant going openEHR->FHIR needs {shortfall}")]
NotAnInstant {
shortfall: InstantShortfall,
},
#[error(
"a DV_PROPORTION of kind {kind} has no faithful FHIR Quantity; \
name a carrier that holds a denominator"
)]
UnrepresentableProportion {
kind: i32,
},
}