#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum AuditChangeType {
Creation,
Amendment,
Modification,
Synthesis,
Deleted,
Attestation,
Restoration,
FormatConversion,
Unknown,
}
impl AuditChangeType {
pub const GROUP_ID: &str = "audit_change_type";
pub const ALL: [Self; 9] = [
Self::Creation,
Self::Amendment,
Self::Modification,
Self::Synthesis,
Self::Deleted,
Self::Attestation,
Self::Restoration,
Self::FormatConversion,
Self::Unknown,
];
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::Creation => "249",
Self::Amendment => "250",
Self::Modification => "251",
Self::Synthesis => "252",
Self::Deleted => "523",
Self::Attestation => "666",
Self::Restoration => "816",
Self::FormatConversion => "817",
Self::Unknown => "253",
}
}
#[must_use]
pub const fn rubric(self) -> &'static str {
match self {
Self::Creation => "creation",
Self::Amendment => "amendment",
Self::Modification => "modification",
Self::Synthesis => "synthesis",
Self::Deleted => "deleted",
Self::Attestation => "attestation",
Self::Restoration => "restoration",
Self::FormatConversion => "format conversion",
Self::Unknown => "unknown",
}
}
#[must_use]
pub fn from_code(code: &str) -> Option<Self> {
Self::ALL.into_iter().find(|c| c.code() == code)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum VersionLifecycleState {
Complete,
Incomplete,
Deleted,
Inactive,
Abandoned,
}
impl VersionLifecycleState {
pub const GROUP_ID: &str = "version_lifecycle_state";
pub const ALL: [Self; 5] = [
Self::Complete,
Self::Incomplete,
Self::Deleted,
Self::Inactive,
Self::Abandoned,
];
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::Complete => "532",
Self::Incomplete => "553",
Self::Deleted => "523",
Self::Inactive => "800",
Self::Abandoned => "801",
}
}
#[must_use]
pub const fn rubric(self) -> &'static str {
match self {
Self::Complete => "complete",
Self::Incomplete => "incomplete",
Self::Deleted => "deleted",
Self::Inactive => "inactive",
Self::Abandoned => "abandoned",
}
}
#[must_use]
pub fn from_code(code: &str) -> Option<Self> {
Self::ALL.into_iter().find(|c| c.code() == code)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::bundle::openehr;
fn bundle_group(group: &str) -> Vec<(String, String)> {
openehr()
.concepts_in_group(group)
.iter()
.map(|c| (c.id.clone(), c.rubric.clone()))
.collect()
}
#[test]
fn the_change_types_are_the_bundles() {
let named: Vec<(String, String)> = AuditChangeType::ALL
.iter()
.map(|c| (c.code().to_owned(), c.rubric().to_owned()))
.collect();
assert_eq!(named, bundle_group(AuditChangeType::GROUP_ID));
}
#[test]
fn the_lifecycle_states_are_the_bundles() {
let named: Vec<(String, String)> = VersionLifecycleState::ALL
.iter()
.map(|c| (c.code().to_owned(), c.rubric().to_owned()))
.collect();
assert_eq!(named, bundle_group(VersionLifecycleState::GROUP_ID));
}
#[test]
fn a_code_reads_back_to_its_concept() {
assert_eq!(
AuditChangeType::from_code("251"),
Some(AuditChangeType::Modification)
);
assert_eq!(
VersionLifecycleState::from_code("523"),
Some(VersionLifecycleState::Deleted)
);
assert_eq!(AuditChangeType::from_code("532"), None);
}
}