use crate::v1_2::data_types::text::dv_text::DvText;
use crate::v1_2::demographic::party::Party;
impl Party {
#[must_use]
pub fn r#type(&self) -> &DvText {
match self {
Self::Agent(party) => &party.name,
Self::Group(party) => &party.name,
Self::Organisation(party) => &party.name,
Self::Person(party) => &party.name,
Self::Role(party) => &party.name,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::v1_2::data_structures::item_structure::item_structure::ItemStructure;
use crate::v1_2::data_structures::item_structure::item_tree::ItemTree;
use crate::v1_2::data_types::text::dv_text::DvTextData;
use crate::v1_2::demographic::organisation::Organisation;
use crate::v1_2::demographic::party_identity::PartyIdentity;
use crate::v1_2::demographic::person::Person;
fn text(value: &str) -> DvText {
DvText::DvText(DvTextData {
value: value.to_owned(),
hyperlink: None,
formatting: None,
mappings: openehr_base::containers::present_nonempty(Vec::new()),
language: None,
encoding: None,
})
}
fn identities() -> openehr_base::containers::NonEmptyVec<PartyIdentity> {
openehr_base::containers::NonEmptyVec::of(PartyIdentity {
name: text("legal"),
archetype_node_id: "openEHR-DEMOGRAPHIC-PARTY_IDENTITY.person_name.v1".to_owned(),
uid: None,
links: None,
archetype_details: None,
feeder_audit: None,
details: ItemStructure::ItemTree(Box::new(ItemTree {
name: text("tree"),
archetype_node_id: "at0001".to_owned(),
uid: None,
links: None,
archetype_details: None,
feeder_audit: None,
items: None,
})),
})
}
fn person(name: &str) -> Party {
Party::Person(Person {
name: text(name),
archetype_node_id: "openEHR-DEMOGRAPHIC-PERSON.person.v1".to_owned(),
uid: None,
links: None,
archetype_details: None,
feeder_audit: None,
identities: identities(),
contacts: None,
details: None,
relationships: None,
languages: None,
roles: None,
})
}
fn organisation(name: &str) -> Party {
Party::Organisation(Organisation {
name: text(name),
archetype_node_id: "openEHR-DEMOGRAPHIC-ORGANISATION.organisation.v1".to_owned(),
uid: None,
links: None,
archetype_details: None,
feeder_audit: None,
identities: identities(),
contacts: None,
details: None,
relationships: None,
languages: None,
roles: None,
})
}
#[test]
fn the_type_is_the_name_of_whichever_party_this_is() {
let a_person = person("PERSON");
assert_eq!(a_person.r#type(), &text("PERSON"));
let an_organisation = organisation("ORGANISATION");
assert_eq!(an_organisation.r#type(), &text("ORGANISATION"));
let general_practitioner = person("general practitioner");
assert_eq!(general_practitioner.r#type(), &text("general practitioner"));
}
}