use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use super::{Address, ContactPoint};
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct EmergencyContact {
pub name: String,
pub relationship: String,
pub telecom: Vec<ContactPoint>,
pub address: Option<Address>,
pub is_primary: bool,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::models::ContactPointSystem;
#[test]
fn test_emergency_contact_creation() {
let contact = EmergencyContact {
name: "Jane Doe".into(),
relationship: "spouse".into(),
telecom: vec![ContactPoint {
system: ContactPointSystem::Phone,
value: "+15551234567".into(),
use_type: None,
}],
address: None,
is_primary: true,
};
assert_eq!(contact.name, "Jane Doe");
assert_eq!(contact.relationship, "spouse");
assert!(contact.is_primary);
assert_eq!(contact.telecom.len(), 1);
assert!(contact.address.is_none());
}
#[test]
fn test_emergency_contact_serialization() {
let contact = EmergencyContact {
name: "Bob Smith".into(),
relationship: "parent".into(),
telecom: vec![],
address: Some(Address {
use_type: None,
line1: Some("456 Elm St".into()),
line2: None,
city: Some("Anytown".into()),
state: Some("CA".into()),
postal_code: Some("90210".into()),
country: Some("US".into()),
}),
is_primary: false,
};
let json = serde_json::to_string(&contact).expect("Serialization should succeed");
let deser: EmergencyContact = serde_json::from_str(&json).expect("Deserialization should succeed");
assert_eq!(deser.name, "Bob Smith");
assert_eq!(deser.relationship, "parent");
assert!(!deser.is_primary);
assert!(deser.address.is_some());
assert_eq!(deser.address.as_ref().unwrap().city.as_deref(), Some("Anytown"));
}
}