use crate::v1_1::common::generic::party_proxy::PartyProxy;
use crate::v1_1::composition::content::entry::entry::Entry;
impl Entry {
#[must_use]
pub fn subject_is_self(&self) -> bool {
matches!(self.subject(), PartyProxy::PartySelf(_))
}
#[must_use]
pub fn subject(&self) -> &PartyProxy {
match self {
Self::Action(entry) => &entry.subject,
Self::AdminEntry(entry) => &entry.subject,
Self::Evaluation(entry) => &entry.subject,
Self::Instruction(entry) => &entry.subject,
Self::Observation(entry) => &entry.subject,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::v1_1::common::generic::party_identified::{PartyIdentified, PartyIdentifiedData};
use crate::v1_1::common::generic::party_self::PartySelf;
use crate::v1_1::composition::content::entry::admin_entry::AdminEntry;
use crate::v1_1::data_structures::item_structure::item_structure::ItemStructure;
use crate::v1_1::data_structures::item_structure::item_tree::ItemTree;
use crate::v1_1::data_types::text::code_phrase::CodePhrase;
use crate::v1_1::data_types::text::dv_text::{DvText, DvTextData};
use openehr_base::v1_2::base_types::identification::terminology_id::TerminologyId;
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 code(terminology: &str, code: &str) -> CodePhrase {
CodePhrase {
terminology_id: TerminologyId {
value: terminology.to_owned(),
},
code_string: code.to_owned(),
preferred_term: None,
}
}
fn entry(subject: PartyProxy) -> Entry {
Entry::AdminEntry(AdminEntry {
name: text("admin"),
archetype_node_id: "openEHR-EHR-ADMIN_ENTRY.admin.v1".to_owned(),
uid: None,
links: None,
archetype_details: None,
feeder_audit: None,
language: code("ISO_639-1", "en"),
encoding: code("IANA_character-sets", "UTF-8"),
other_participations: None,
workflow_id: None,
subject,
provider: None,
data: 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,
})),
})
}
#[test]
fn a_party_self_subject_is_the_record_subject() {
assert!(entry(PartyProxy::PartySelf(PartySelf { external_ref: None })).subject_is_self());
}
#[test]
fn an_identified_subject_is_not_the_record_subject() {
let other = entry(PartyProxy::PartyIdentified(
PartyIdentified::PartyIdentified(PartyIdentifiedData {
external_ref: None,
name: Some("Relative of the subject".to_owned()),
identifiers: None,
}),
));
assert!(!other.subject_is_self());
}
}