1use serde::{Deserialize, Serialize};
2use std::env;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Config {
7 pub version: Option<String>,
8 pub sender: Entity,
9 pub requester: Entity,
10 pub receivers: Vec<Entity>,
11 pub patient: PatientConfig,
12 pub security: Option<SecurityConfig>,
13 pub encryption: Option<EncryptionConfig>,
14 pub custom_tags: Option<Vec<String>>,
15 pub report: Option<ReportConfig>,
16 pub files: Option<Vec<FileConfig>>,
17 pub consent: Option<ConsentConfig>,
18 pub deid_keys: Option<Vec<String>>,
19 pub jws_signing_key: Option<String>,
20 pub verify_assertions: Option<bool>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct Entity {
26 pub name: String,
27 pub id: String,
28 pub contact: ContactInfo,
29 pub assertion: Option<AssertionConfig>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ContactInfo {
36 Email(String),
37 Detailed {
38 system: String,
39 value: String,
40 },
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct AssertionConfig {
46 pub alg: String,
47 pub public_key: String,
48 pub fingerprint: Option<String>,
49 pub key_reference: Option<String>,
50 pub signature: Option<String>,
51 pub expires_at: Option<String>,
52 pub private_key: Option<String>, }
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct PatientConfig {
58 pub name: Option<String>,
59 pub id: Option<String>,
60 pub dob: Option<String>,
61 pub sex: Option<String>,
62 pub identifiers: Option<Vec<IdentifierConfig>>,
63 pub verification: Option<VerificationConfig>,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct IdentifierConfig {
69 pub system: String,
70 pub value: String,
71 pub use_field: Option<String>, }
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct VerificationConfig {
77 pub status: String,
78 pub method: String,
79 pub timestamp: Option<String>,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct SecurityConfig {
85 pub classification: Option<String>,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct EncryptionConfig {
91 pub recipient_public_key: String,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96pub struct ReportConfig {
97 pub file: Option<String>,
98 pub url: Option<String>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum FileConfig {
105 Path(String),
106 Detailed {
107 path: String,
108 name: Option<String>,
109 },
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct ConsentConfig {
115 pub status: String,
116 pub scope: Option<Vec<String>>,
117 pub method: Option<String>,
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct StudyConfig {
123 pub description: Option<String>,
124 pub uid: Option<String>,
125 pub modality: Option<String>,
126 pub body_part: Option<String>,
127}
128
129impl Default for Config {
130 fn default() -> Self {
131 Self {
132 version: Some("1.0".to_string()),
133 sender: Entity {
134 name: "".to_string(),
135 id: "".to_string(),
136 contact: ContactInfo::Email("".to_string()),
137 assertion: None,
138 },
139 requester: Entity {
140 name: "".to_string(),
141 id: "".to_string(),
142 contact: ContactInfo::Email("".to_string()),
143 assertion: None,
144 },
145 receivers: vec![],
146 patient: PatientConfig {
147 name: None,
148 id: None,
149 dob: None,
150 sex: None,
151 identifiers: None,
152 verification: None,
153 },
154 security: Some(SecurityConfig {
155 classification: Some("confidential".to_string()),
156 }),
157 encryption: None,
158 custom_tags: None,
159 report: None,
160 files: None,
161 consent: None,
162 deid_keys: None,
163 jws_signing_key: None,
164 verify_assertions: None,
165 }
166 }
167}
168
169#[derive(Debug, Clone)]
171pub struct ValidationConfig {
172 pub schema_path: String,
173}
174
175impl Default for ValidationConfig {
176 fn default() -> Self {
177 let schema_path = env::var("JMIX_SCHEMA_DIR").unwrap_or_else(|_| "../jmix/schemas".to_string());
178 Self { schema_path }
179 }
180}