use std::collections::BTreeSet;
use super::identifier::{CommunityPatientId, HomeCommunityId};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Discovery {
Matched(Vec<Match>),
NoMatch,
MoreAttributesRequested(Vec<RequestedAttribute>),
}
impl Discovery {
#[must_use]
pub fn communities(&self) -> BTreeSet<&HomeCommunityId> {
match self {
Self::Matched(found) => found.iter().map(Match::community).collect(),
Self::NoMatch | Self::MoreAttributesRequested(_) => BTreeSet::new(),
}
}
}
#[derive(Debug, Clone)]
pub struct Match {
community: HomeCommunityId,
patient_ids: Vec<CommunityPatientId>,
}
impl Match {
pub(super) fn new(community: HomeCommunityId, patient_ids: Vec<CommunityPatientId>) -> Self {
Self {
community,
patient_ids,
}
}
#[must_use]
pub fn community(&self) -> &HomeCommunityId {
&self.community
}
#[must_use]
pub fn patient_ids(&self) -> &[CommunityPatientId] {
&self.patient_ids
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum RequestedAttribute {
AdministrativeGender,
PatientAddress,
PatientTelecom,
BirthPlaceName,
BirthPlaceAddress,
MothersMaidenName,
Other,
}
impl RequestedAttribute {
pub(super) fn of(code: &str) -> Self {
match code {
"LivingSubjectAdministrativeGenderRequested" => Self::AdministrativeGender,
"PatientAddressRequested" => Self::PatientAddress,
"PatientTelecomRequested" => Self::PatientTelecom,
"LivingSubjectBirthPlaceNameRequested" => Self::BirthPlaceName,
"LivingSubjectBirthPlaceAddressRequested" => Self::BirthPlaceAddress,
"MothersMaidenNameRequested" => Self::MothersMaidenName,
_ => Self::Other,
}
}
}