1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use super::Result;
use regex::Regex;
use std::path::Path;
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct DataHandling {
#[serde(default)]
pub stores: Vec<DataStore>,
#[serde(default)]
pub processes: Vec<DataProcess>,
#[serde(default)]
pub informationClassification: Option<InformationClassificationData>,
}
impl DataHandling {
pub fn implicits(&mut self) {
for s in &mut self.stores {
s.implicits();
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct InformationClassificationData {
pub highestProcessed: InformationClassification,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub enum InformationClassification {
StrictlyConfidential,
ConfidentialPatientData,
CommercialConfidential,
ProtectedInternal,
Public,
}
impl Default for InformationClassification {
fn default() -> Self {
InformationClassification::ConfidentialPatientData
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct DataStore {
pub backend: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub fields: Vec<DataField>,
#[serde(default)]
pub encrypted: Option<bool>,
pub cipher: Option<String>,
pub keyRotator: Option<String>,
pub retentionPeriod: Option<String>,
pub informationClassification: Option<InformationClassification>,
}
impl DataStore {
pub fn implicits(&mut self) {
for f in &mut self.fields {
if f.encrypted.is_none() {
if let Some(e) = self.encrypted {
f.encrypted = Some(e);
} else {
f.encrypted = Some(false);
}
}
if f.cipher.is_none() && self.cipher.is_some() {
f.cipher = self.cipher.clone();
}
if f.keyRotator.is_none() && self.keyRotator.is_some() {
f.keyRotator = self.keyRotator.clone();
}
if f.retentionPeriod.is_none() && self.retentionPeriod.is_some() {
f.retentionPeriod = self.retentionPeriod.clone();
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct DataField {
pub name: String,
pub encrypted: Option<bool>,
pub cipher: Option<String>,
pub keyRotator: Option<String>,
pub retentionPeriod: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct DataProcess {
pub field: String,
pub source: String,
}
impl DataHandling {
pub fn verify(&self) -> Result<()> {
let re = Regex::new(r"^[A-Z][[:alpha:]\d]+$").unwrap();
for s in &self.stores {
for f in &s.fields {
if !re.is_match(&f.name) {
bail!(
"The field {} is not valid PascalCase, or starts with a number",
f.name
);
}
}
}
for p in &self.processes {
let sourcepth = Path::new(".").join("services").join(&p.source);
if !sourcepth.is_dir() {
bail!("Service {} does not exist in services/", p.source);
}
}
Ok(())
}
}