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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
//! `Individual` — a natural person, from TMF632 v5.
use serde::{Deserialize, Serialize};
use crate::core::macros::{tmf_entity, tmf_patch_body, tmf_struct};
use crate::core::{
Characteristic, ExternalIdentifier, RelatedParty, TaxExemptionCertificate, Timestamp,
};
use super::common::{
Disability, LanguageAbility, OtherNameIndividual, PartyCreditProfile, PartyIdentification,
Skill,
};
use super::contact::ContactMedium;
/// The lifecycle state of an [`Individual`].
///
/// The v5 OAS defines a closed enum; [`IndividualState::Other`] keeps an
/// unrecognised value intact rather than failing the parse.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum IndividualState {
/// Created but not yet verified.
#[serde(rename = "initialized")]
Initialized,
/// Identity has been verified.
#[serde(rename = "validated")]
Validated,
/// The person has died.
#[serde(rename = "deceased")]
Deceased,
/// A value outside the v5 enumeration, preserved verbatim.
#[serde(untagged)]
Other(String),
}
tmf_struct! {
@name = "Individual", @ref = "PartyRef";
/// A natural person known to the service provider.
///
/// This is the **read model**. Use [`IndividualCreate`] for `POST` and
/// [`IndividualUpdate`] for `PATCH`.
///
/// ```
/// use rutmf::party::{ContactMedium, IndividualCreate};
///
/// // TMF632 requires both name parts on create.
/// let body = IndividualCreate::builder()
/// .given_name("Ada")
/// .family_name("Lovelace")
/// .contact_medium(vec![ContactMedium::email("ada@example.com")])
/// .build();
/// assert_eq!(body.family_name, "Lovelace");
/// ```
pub struct Individual {
/// Server-assigned identifier.
id: String,
/// Canonical URI of this individual.
href: String,
/// Given (first) name.
given_name: String,
/// Family (last) name.
family_name: String,
/// Middle name.
middle_name: String,
/// Prefix to the family name, e.g. `van`.
family_name_prefix: String,
/// The full name as one string.
name: String,
/// The name as it should be displayed.
formatted_name: String,
/// The legally registered name.
legal_name: String,
/// Preferred given name.
preferred_given_name: String,
/// Title, e.g. `Dr`.
title: String,
/// Aristocratic title.
aristocratic_title: String,
/// Generational suffix, e.g. `Jr`.
generation: String,
/// Gender.
gender: String,
/// Marital status.
marital_status: String,
/// Nationality.
nationality: String,
/// Country of birth.
country_of_birth: String,
/// Place of birth.
place_of_birth: String,
/// Date of birth.
birth_date: Timestamp,
/// Date of death.
death_date: Timestamp,
/// Where the individual is located.
location: String,
/// Lifecycle state.
status: IndividualState,
/// Ways of contacting the individual.
contact_medium: Vec<ContactMedium>,
/// Alternative names.
other_name: Vec<OtherNameIndividual>,
/// Identification documents.
individual_identification: Vec<PartyIdentification>,
/// Languages the individual can use.
language_ability: Vec<LanguageAbility>,
/// Recorded skills.
skill: Vec<Skill>,
/// Recorded disabilities.
disability: Vec<Disability>,
/// Credit ratings held about the individual.
credit_rating: Vec<PartyCreditProfile>,
/// Tax exemption certificates.
tax_exemption_certificate: Vec<TaxExemptionCertificate>,
/// Free-form characteristics.
party_characteristic: Vec<Characteristic>,
/// Other parties related to this one.
related_party: Vec<RelatedParty>,
/// Identifiers in external systems.
external_reference: Vec<ExternalIdentifier>,
}
}
tmf_entity!(Individual);
tmf_struct! {
@name = "Individual";
/// Body of a `POST /individual` — the v5 `Individual_FVO`.
///
/// `givenName` and `familyName` are required on create; `href` is
/// server-owned and absent.
pub struct IndividualCreate {
@required {
/// Given (first) name. **Required on create.**
given_name: String,
/// Family (last) name. **Required on create.**
family_name: String,
}
/// Client-supplied identifier, where the server permits one.
id: String,
/// Middle name.
middle_name: String,
/// Prefix to the family name, e.g. `van`.
family_name_prefix: String,
/// The full name as one string.
name: String,
/// The name as it should be displayed.
formatted_name: String,
/// The legally registered name.
legal_name: String,
/// Preferred given name.
preferred_given_name: String,
/// Title, e.g. `Dr`.
title: String,
/// Aristocratic title.
aristocratic_title: String,
/// Generational suffix, e.g. `Jr`.
generation: String,
/// Gender.
gender: String,
/// Marital status.
marital_status: String,
/// Nationality.
nationality: String,
/// Country of birth.
country_of_birth: String,
/// Place of birth.
place_of_birth: String,
/// Date of birth.
birth_date: Timestamp,
/// Date of death.
death_date: Timestamp,
/// Where the individual is located.
location: String,
/// Lifecycle state.
status: IndividualState,
/// Ways of contacting the individual.
contact_medium: Vec<ContactMedium>,
/// Alternative names.
other_name: Vec<OtherNameIndividual>,
/// Identification documents.
individual_identification: Vec<PartyIdentification>,
/// Languages the individual can use.
language_ability: Vec<LanguageAbility>,
/// Recorded skills.
skill: Vec<Skill>,
/// Recorded disabilities.
disability: Vec<Disability>,
/// Credit ratings held about the individual.
credit_rating: Vec<PartyCreditProfile>,
/// Tax exemption certificates.
tax_exemption_certificate: Vec<TaxExemptionCertificate>,
/// Free-form characteristics.
party_characteristic: Vec<Characteristic>,
/// Other parties related to this one.
related_party: Vec<RelatedParty>,
/// Identifiers in external systems.
external_reference: Vec<ExternalIdentifier>,
}
}
tmf_struct! {
@name = "Individual";
/// Body of a `PATCH /individual/{id}` — the v5 `Individual_MVO`.
///
/// Every member is optional, and the server-owned `id` and `href` are
/// absent entirely.
pub struct IndividualUpdate {
/// New given name.
given_name: String,
/// New family name.
family_name: String,
/// New middle name.
middle_name: String,
/// New family-name prefix.
family_name_prefix: String,
/// New full name.
name: String,
/// New display name.
formatted_name: String,
/// New legal name.
legal_name: String,
/// New preferred given name.
preferred_given_name: String,
/// New title.
title: String,
/// New aristocratic title.
aristocratic_title: String,
/// New generational suffix.
generation: String,
/// New gender.
gender: String,
/// New marital status.
marital_status: String,
/// New nationality.
nationality: String,
/// New country of birth.
country_of_birth: String,
/// New place of birth.
place_of_birth: String,
/// New date of birth.
birth_date: Timestamp,
/// New date of death.
death_date: Timestamp,
/// New location.
location: String,
/// New lifecycle state.
status: IndividualState,
/// Replacement contact media.
contact_medium: Vec<ContactMedium>,
/// Replacement alternative names.
other_name: Vec<OtherNameIndividual>,
/// Replacement identification documents.
individual_identification: Vec<PartyIdentification>,
/// Replacement language abilities.
language_ability: Vec<LanguageAbility>,
/// Replacement skills.
skill: Vec<Skill>,
/// Replacement disabilities.
disability: Vec<Disability>,
/// Replacement credit ratings.
credit_rating: Vec<PartyCreditProfile>,
/// Replacement tax exemption certificates.
tax_exemption_certificate: Vec<TaxExemptionCertificate>,
/// Replacement characteristics.
party_characteristic: Vec<Characteristic>,
/// Replacement related parties.
related_party: Vec<RelatedParty>,
/// Replacement external references.
external_reference: Vec<ExternalIdentifier>,
}
}
tmf_patch_body!(IndividualUpdate);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn state_keeps_an_unknown_value() {
let parsed: Individual = serde_json::from_str(r#"{"status":"suspended"}"#).unwrap();
assert_eq!(
parsed.status,
Some(IndividualState::Other("suspended".into()))
);
assert_eq!(
serde_json::to_value(&parsed).unwrap()["status"],
serde_json::json!("suspended")
);
}
#[test]
fn known_states_use_the_spec_spelling() {
let parsed: Individual = serde_json::from_str(r#"{"status":"validated"}"#).unwrap();
assert_eq!(parsed.status, Some(IndividualState::Validated));
}
#[test]
fn a_patch_body_can_change_the_members_the_mvo_allows() {
let patch = IndividualUpdate::builder().place_of_birth("Genoa").build();
assert_eq!(
serde_json::to_string(&patch).unwrap(),
r#"{"placeOfBirth":"Genoa","@type":"Individual"}"#
);
}
#[test]
fn a_defaulted_patch_body_carries_a_valid_discriminator() {
// Deriving `Default` would leave `@type` empty, which is a payload no
// conformant server accepts.
assert_eq!(IndividualUpdate::default().at_type, "Individual");
}
}