pub mod attachment;
pub mod employee;
pub mod models;
use crate::core::config::Config;
use attachment::AttachmentService;
use employee::EmployeeService;
pub struct EhrService {
pub employee: EmployeeService,
pub attachment: AttachmentService,
}
impl EhrService {
pub fn new(config: Config) -> Self {
Self {
employee: EmployeeService::new(config.clone()),
attachment: AttachmentService::new(config),
}
}
pub fn new_from_shared(shared: std::sync::Arc<Config>) -> Self {
Self {
employee: EmployeeService::new(shared.as_ref().clone()),
attachment: AttachmentService::new(shared.as_ref().clone()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::time::Duration;
#[test]
fn test_ehr_service_creation() {
let config = Config::default();
let service = EhrService::new(config.clone());
assert_eq!(service.employee.config.app_id, config.app_id);
assert_eq!(service.employee.config.app_secret, config.app_secret);
assert_eq!(service.attachment.config.app_id, config.app_id);
assert_eq!(service.attachment.config.app_secret, config.app_secret);
}
#[test]
fn test_ehr_service_with_custom_config() {
let config = Config::builder()
.app_id("ehr_test_app")
.app_secret("ehr_test_secret")
.req_timeout(Duration::from_secs(120))
.build();
let service = EhrService::new(config.clone());
assert_eq!(service.employee.config.app_id, "ehr_test_app");
assert_eq!(service.employee.config.app_secret, "ehr_test_secret");
assert_eq!(
service.employee.config.req_timeout,
Some(Duration::from_secs(120))
);
assert_eq!(service.attachment.config.app_id, "ehr_test_app");
assert_eq!(service.attachment.config.app_secret, "ehr_test_secret");
assert_eq!(
service.attachment.config.req_timeout,
Some(Duration::from_secs(120))
);
}
#[test]
fn test_ehr_service_config_independence() {
let config1 = Config::builder().app_id("ehr_app_1").build();
let config2 = Config::builder().app_id("ehr_app_2").build();
let service1 = EhrService::new(config1);
let service2 = EhrService::new(config2);
assert_eq!(service1.employee.config.app_id, "ehr_app_1");
assert_eq!(service2.employee.config.app_id, "ehr_app_2");
assert_ne!(
service1.employee.config.app_id,
service2.employee.config.app_id
);
assert_ne!(
service1.attachment.config.app_id,
service2.attachment.config.app_id
);
}
#[test]
fn test_ehr_service_sub_services_accessible() {
let config = Config::default();
let service = EhrService::new(config.clone());
assert_eq!(service.employee.config.app_id, config.app_id);
assert_eq!(service.attachment.config.app_id, config.app_id);
}
#[test]
fn test_ehr_service_config_cloning() {
let config = Config::builder()
.app_id("clone_test_app")
.app_secret("clone_test_secret")
.build();
let service = EhrService::new(config.clone());
assert_eq!(service.employee.config.app_id, "clone_test_app");
assert_eq!(service.employee.config.app_secret, "clone_test_secret");
assert_eq!(service.attachment.config.app_id, "clone_test_app");
assert_eq!(service.attachment.config.app_secret, "clone_test_secret");
}
#[test]
fn test_ehr_service_timeout_propagation() {
let config = Config::builder()
.req_timeout(Duration::from_secs(180))
.build();
let service = EhrService::new(config);
assert_eq!(
service.employee.config.req_timeout,
Some(Duration::from_secs(180))
);
assert_eq!(
service.attachment.config.req_timeout,
Some(Duration::from_secs(180))
);
}
#[test]
fn test_ehr_service_multiple_instances() {
let config = Config::default();
let service1 = EhrService::new(config.clone());
let service2 = EhrService::new(config.clone());
assert_eq!(
service1.employee.config.app_id,
service2.employee.config.app_id
);
assert_eq!(
service1.employee.config.app_secret,
service2.employee.config.app_secret
);
assert_eq!(
service1.attachment.config.app_id,
service2.attachment.config.app_id
);
assert_eq!(
service1.attachment.config.app_secret,
service2.attachment.config.app_secret
);
}
#[test]
fn test_ehr_service_config_consistency() {
let config = Config::builder()
.app_id("consistency_test")
.app_secret("consistency_secret")
.req_timeout(Duration::from_secs(150))
.build();
let service = EhrService::new(config);
assert_eq!(service.employee.config.app_id, "consistency_test");
assert_eq!(service.employee.config.app_secret, "consistency_secret");
assert_eq!(
service.employee.config.req_timeout,
Some(Duration::from_secs(150))
);
assert_eq!(service.attachment.config.app_id, "consistency_test");
assert_eq!(service.attachment.config.app_secret, "consistency_secret");
assert_eq!(
service.attachment.config.req_timeout,
Some(Duration::from_secs(150))
);
}
}