use core::fmt;
use core::str::FromStr;
use openehr_mapping_core::header::metadata::MappingName;
use crate::resolve::program::condition::Condition;
use crate::resolve::program::target::FhirTarget;
use crate::resolve::program::target::OpenehrTarget;
use crate::resolve::program::target::Target;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Create {
Resource,
Event,
Archetype,
}
impl Create {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Resource => "resource",
Self::Event => "event",
Self::Archetype => "archetype",
}
}
#[must_use]
pub const fn admitted() -> &'static [&'static str] {
&["resource", "event", "archetype"]
}
}
impl fmt::Display for Create {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl FromStr for Create {
type Err = ();
fn from_str(text: &str) -> Result<Self, Self::Err> {
match text {
"resource" => Ok(Self::Resource),
"event" => Ok(Self::Event),
"archetype" => Ok(Self::Archetype),
_ => Err(()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Split {
create: Option<Create>,
path: Option<Target>,
unique: Vec<Target>,
}
impl Split {
#[must_use]
pub const fn new(create: Option<Create>, path: Option<Target>, unique: Vec<Target>) -> Self {
Self {
create,
path,
unique,
}
}
#[must_use]
pub const fn create(&self) -> Option<Create> {
self.create
}
#[must_use]
pub const fn path(&self) -> Option<&Target> {
self.path.as_ref()
}
#[must_use]
pub fn unique(&self) -> &[Target] {
&self.unique
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Preprocessor {
model: MappingName,
fhir_condition: Option<Condition>,
openehr_condition: Option<Condition>,
hierarchy: Option<Hierarchy>,
}
impl Preprocessor {
#[must_use]
pub const fn new(
model: MappingName,
fhir_condition: Option<Condition>,
openehr_condition: Option<Condition>,
hierarchy: Option<Hierarchy>,
) -> Self {
Self {
model,
fhir_condition,
openehr_condition,
hierarchy,
}
}
#[must_use]
pub const fn model(&self) -> &MappingName {
&self.model
}
#[must_use]
pub const fn fhir_condition(&self) -> Option<&Condition> {
self.fhir_condition.as_ref()
}
#[must_use]
pub const fn openehr_condition(&self) -> Option<&Condition> {
self.openehr_condition.as_ref()
}
#[must_use]
pub const fn hierarchy(&self) -> Option<&Hierarchy> {
self.hierarchy.as_ref()
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.fhir_condition.is_none()
&& self.openehr_condition.is_none()
&& self.hierarchy.is_none()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Hierarchy {
fhir: Option<FhirTarget>,
openehr: Option<OpenehrTarget>,
split_fhir: Option<Split>,
split_openehr: Option<Split>,
}
impl Hierarchy {
#[must_use]
pub const fn new(
fhir: Option<FhirTarget>,
openehr: Option<OpenehrTarget>,
split_fhir: Option<Split>,
split_openehr: Option<Split>,
) -> Self {
Self {
fhir,
openehr,
split_fhir,
split_openehr,
}
}
#[must_use]
pub const fn fhir(&self) -> Option<&FhirTarget> {
self.fhir.as_ref()
}
#[must_use]
pub const fn openehr(&self) -> Option<&OpenehrTarget> {
self.openehr.as_ref()
}
#[must_use]
pub const fn split_fhir(&self) -> Option<&Split> {
self.split_fhir.as_ref()
}
#[must_use]
pub const fn split_openehr(&self) -> Option<&Split> {
self.split_openehr.as_ref()
}
}