use super::Extension;
pub mod healthcare {
use super::Extension;
use serde_json::json;
pub const FHIR_NAMESPACE: &str = "io.health.fhir";
pub const FHIR_VERSION: &str = "1.0.0";
#[derive(Debug, Clone)]
pub struct FhirExtensionBuilder {
fhir_version: String,
resources: Vec<String>,
smart_on_fhir: bool,
audit_logging: bool,
}
impl Default for FhirExtensionBuilder {
fn default() -> Self {
Self {
fhir_version: "R4".to_string(),
resources: Vec::new(),
smart_on_fhir: false,
audit_logging: true,
}
}
}
impl FhirExtensionBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_fhir_version(mut self, version: impl Into<String>) -> Self {
self.fhir_version = version.into();
self
}
#[must_use]
pub fn with_resources(mut self, resources: Vec<impl Into<String>>) -> Self {
self.resources = resources.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn with_smart_on_fhir(mut self, enabled: bool) -> Self {
self.smart_on_fhir = enabled;
self
}
#[must_use]
pub fn with_audit_logging(mut self, enabled: bool) -> Self {
self.audit_logging = enabled;
self
}
#[must_use]
pub fn build(self) -> Extension {
Extension::new(FHIR_NAMESPACE)
.with_version(FHIR_VERSION)
.with_description("HL7 FHIR healthcare data extension")
.with_config(json!({
"fhir_version": self.fhir_version,
"resources": self.resources,
"smart_on_fhir": self.smart_on_fhir,
"audit_logging": self.audit_logging
}))
}
}
#[must_use]
pub fn fhir_extension() -> FhirExtensionBuilder {
FhirExtensionBuilder::new()
}
pub mod resources {
pub const PATIENT: &str = "Patient";
pub const OBSERVATION: &str = "Observation";
pub const CONDITION: &str = "Condition";
pub const MEDICATION_REQUEST: &str = "MedicationRequest";
pub const DIAGNOSTIC_REPORT: &str = "DiagnosticReport";
pub const ENCOUNTER: &str = "Encounter";
pub const ALLERGY_INTOLERANCE: &str = "AllergyIntolerance";
pub const IMMUNIZATION: &str = "Immunization";
pub const PROCEDURE: &str = "Procedure";
pub const CARE_PLAN: &str = "CarePlan";
}
}
pub mod finance {
use super::Extension;
use serde_json::json;
pub const FINANCE_NAMESPACE: &str = "io.finance.data";
pub const FINANCE_VERSION: &str = "1.0.0";
#[derive(Debug, Clone)]
pub struct FinanceExtensionBuilder {
data_types: Vec<String>,
real_time: bool,
regulatory_compliance: Vec<String>,
encryption_required: bool,
}
impl Default for FinanceExtensionBuilder {
fn default() -> Self {
Self {
data_types: Vec::new(),
real_time: false,
regulatory_compliance: Vec::new(),
encryption_required: true,
}
}
}
impl FinanceExtensionBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_data_types(mut self, types: Vec<impl Into<String>>) -> Self {
self.data_types = types.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn with_real_time(mut self, enabled: bool) -> Self {
self.real_time = enabled;
self
}
#[must_use]
pub fn with_regulatory_compliance(mut self, frameworks: Vec<impl Into<String>>) -> Self {
self.regulatory_compliance = frameworks.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn with_encryption_required(mut self, required: bool) -> Self {
self.encryption_required = required;
self
}
#[must_use]
pub fn build(self) -> Extension {
Extension::new(FINANCE_NAMESPACE)
.with_version(FINANCE_VERSION)
.with_description("Financial services data extension")
.with_config(json!({
"data_types": self.data_types,
"real_time": self.real_time,
"regulatory_compliance": self.regulatory_compliance,
"encryption_required": self.encryption_required
}))
}
}
#[must_use]
pub fn finance_extension() -> FinanceExtensionBuilder {
FinanceExtensionBuilder::new()
}
pub mod data_types {
pub const EQUITY: &str = "equity";
pub const FIXED_INCOME: &str = "fixed_income";
pub const FX: &str = "fx";
pub const DERIVATIVES: &str = "derivatives";
pub const CRYPTO: &str = "crypto";
pub const ECONOMIC: &str = "economic";
pub const CORPORATE_ACTIONS: &str = "corporate_actions";
}
pub mod compliance {
pub const MIFID_II: &str = "MiFID II";
pub const SEC: &str = "SEC";
pub const GDPR: &str = "GDPR";
pub const CCPA: &str = "CCPA";
pub const PCI_DSS: &str = "PCI-DSS";
pub const SOX: &str = "SOX";
}
}
pub mod iot {
use super::Extension;
use serde_json::json;
pub const IOT_NAMESPACE: &str = "io.iot.devices";
pub const IOT_VERSION: &str = "1.0.0";
#[derive(Debug, Clone)]
pub struct IoTExtensionBuilder {
device_types: Vec<String>,
protocols: Vec<String>,
telemetry_interval_ms: u32,
buffered_messages: bool,
}
impl Default for IoTExtensionBuilder {
fn default() -> Self {
Self {
device_types: Vec::new(),
protocols: vec!["mqtt".to_string()],
telemetry_interval_ms: 1000,
buffered_messages: true,
}
}
}
impl IoTExtensionBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_device_types(mut self, types: Vec<impl Into<String>>) -> Self {
self.device_types = types.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn with_protocols(mut self, protocols: Vec<impl Into<String>>) -> Self {
self.protocols = protocols.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn with_telemetry_interval(mut self, interval_ms: u32) -> Self {
self.telemetry_interval_ms = interval_ms;
self
}
#[must_use]
pub fn with_buffered_messages(mut self, enabled: bool) -> Self {
self.buffered_messages = enabled;
self
}
#[must_use]
pub fn build(self) -> Extension {
Extension::new(IOT_NAMESPACE)
.with_version(IOT_VERSION)
.with_description("IoT device management extension")
.with_config(json!({
"device_types": self.device_types,
"protocols": self.protocols,
"telemetry_interval_ms": self.telemetry_interval_ms,
"buffered_messages": self.buffered_messages
}))
}
}
#[must_use]
pub fn iot_extension() -> IoTExtensionBuilder {
IoTExtensionBuilder::new()
}
pub mod device_types {
pub const SENSOR: &str = "sensor";
pub const ACTUATOR: &str = "actuator";
pub const GATEWAY: &str = "gateway";
pub const CAMERA: &str = "camera";
pub const METER: &str = "meter";
pub const WEARABLE: &str = "wearable";
}
pub mod protocols {
pub const MQTT: &str = "mqtt";
pub const COAP: &str = "coap";
pub const HTTP: &str = "http";
pub const WEBSOCKET: &str = "websocket";
pub const MODBUS: &str = "modbus";
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::extension::ExtensionRegistry;
#[test]
fn test_healthcare_fhir() {
let fhir = healthcare::fhir_extension()
.with_fhir_version("R4")
.with_resources(vec![
healthcare::resources::PATIENT,
healthcare::resources::OBSERVATION,
])
.with_smart_on_fhir(true)
.build();
assert_eq!(fhir.name, healthcare::FHIR_NAMESPACE);
assert!(fhir.config.is_some());
let config = fhir.config.unwrap();
assert_eq!(config["fhir_version"], "R4");
assert!(config["smart_on_fhir"].as_bool().unwrap());
}
#[test]
fn test_finance_extension() {
let finance = finance::finance_extension()
.with_data_types(vec![finance::data_types::EQUITY, finance::data_types::FX])
.with_real_time(true)
.with_regulatory_compliance(vec![finance::compliance::MIFID_II])
.build();
assert_eq!(finance.name, finance::FINANCE_NAMESPACE);
let config = finance.config.unwrap();
assert!(config["real_time"].as_bool().unwrap());
assert!(config["encryption_required"].as_bool().unwrap());
}
#[test]
fn test_iot_extension() {
let iot = iot::iot_extension()
.with_device_types(vec![iot::device_types::SENSOR, iot::device_types::GATEWAY])
.with_protocols(vec![iot::protocols::MQTT, iot::protocols::COAP])
.with_telemetry_interval(5000)
.build();
assert_eq!(iot.name, iot::IOT_NAMESPACE);
let config = iot.config.unwrap();
assert_eq!(config["telemetry_interval_ms"], 5000);
}
#[test]
fn test_registry_with_templates() {
let registry = ExtensionRegistry::new()
.register(healthcare::fhir_extension().build())
.register(finance::finance_extension().build());
assert!(registry.has(healthcare::FHIR_NAMESPACE));
assert!(registry.has(finance::FINANCE_NAMESPACE));
assert_eq!(registry.len(), 2);
}
}