fhirkit 0.1.0

FHIR R4 for Rust: typed models for every resource and datatype generated from the official specification, lossless JSON with path-precise validation, typed search queries, FHIRPath
Documentation
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `Consent` resource.

#![allow(
    unused_imports,
    clippy::large_enum_variant,
    clippy::too_many_lines,
    clippy::doc_markdown
)]

use crate::decode::{
    choice_key, required, required_list, resource_type, Choice, Decoder, FhirJson, Obj, ObjWriter,
};
use crate::json::Json;
use crate::primitive::{Decimal, Kind, Primitive};
use crate::r4::*;

/// A record of a healthcare consumer’s choices, which permits or denies identified recipient(s) or recipient role(s) to perform one or more actions within a given policy context, for specific purposes and periods of time.
///
/// FHIR path: `Consent`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Consent {
    /// `id` (0..1): Logical id of this artifact
    pub id: Option<String>,
    /// `meta` (0..1): Metadata about the resource
    pub meta: Option<Meta>,
    /// `implicitRules` (0..1): A set of rules under which this content was created
    pub implicit_rules: Option<Primitive<String>>,
    /// `language` (0..1): Language of the resource content
    pub language: Option<Primitive<String>>,
    /// `text` (0..1): Text summary of the resource, for human interpretation
    pub text: Option<Narrative>,
    /// `contained` (0..*): Contained, inline Resources
    pub contained: Vec<Resource>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored
    pub modifier_extension: Vec<Extension>,
    /// `identifier` (0..*): Identifier for this record (external references)
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): draft | proposed | active | rejected | inactive | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `scope` (1..1): Which of the four areas this resource covers (extensible)
    pub scope: Option<CodeableConcept>,
    /// `category` (1..*): Classification of the consent statement - for indexing/retrieval
    pub category: Vec<CodeableConcept>,
    /// `patient` (0..1): Who the consent applies to
    pub patient: Option<Reference>,
    /// `dateTime` (0..1): When this Consent was created or indexed
    pub date_time: Option<Primitive<String>>,
    /// `performer` (0..*): Who is agreeing to the policy and rules
    pub performer: Vec<Reference>,
    /// `organization` (0..*): Custodian of the consent
    pub organization: Vec<Reference>,
    /// `source[x]` (0..1): Source from which this consent is taken
    pub source: Option<ConsentSource>,
    /// `policy` (0..*): Policies covered by this consent
    pub policy: Vec<ConsentPolicy>,
    /// `policyRule` (0..1): Regulation that this consents to
    pub policy_rule: Option<CodeableConcept>,
    /// `verification` (0..*): Consent Verified by patient or family
    pub verification: Vec<ConsentVerification>,
    /// `provision` (0..1): Constraints to the base Consent.policyRule
    pub provision: Option<ConsentProvision>,
}

#[cfg(feature = "foundation")]
impl FhirJson for Consent {
    const TYPE_NAME: &'static str = "Consent";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Consent");
        let r = Consent {
            id: o.string(d, "id"),
            meta: o.one(d, "meta"),
            implicit_rules: o.prim(d, "implicitRules", Kind::Uri),
            language: o.prim(d, "language", Kind::Code),
            text: o.one(d, "text"),
            contained: o.list(d, "contained"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            identifier: o.list(d, "identifier"),
            status: o.prim(d, "status", Kind::Code),
            scope: o.one(d, "scope"),
            category: o.list(d, "category"),
            patient: o.one(d, "patient"),
            date_time: o.prim(d, "dateTime", Kind::DateTime),
            performer: o.list(d, "performer"),
            organization: o.list(d, "organization"),
            source: o.choice(d, "source"),
            policy: o.list(d, "policy"),
            policy_rule: o.one(d, "policyRule"),
            verification: o.list(d, "verification"),
            provision: o.one(d, "provision"),
        };
        required(d, "status", &r.status);
        required(d, "scope", &r.scope);
        required_list(d, "category", &r.category, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Consent".into()));
        w.string("id", &self.id);
        w.one("meta", &self.meta);
        w.prim("implicitRules", &self.implicit_rules);
        w.prim("language", &self.language);
        w.one("text", &self.text);
        w.list("contained", &self.contained);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.list("identifier", &self.identifier);
        w.prim("status", &self.status);
        w.one("scope", &self.scope);
        w.list("category", &self.category);
        w.one("patient", &self.patient);
        w.prim("dateTime", &self.date_time);
        w.list("performer", &self.performer);
        w.list("organization", &self.organization);
        w.choice("source", &self.source);
        w.list("policy", &self.policy);
        w.one("policyRule", &self.policy_rule);
        w.list("verification", &self.verification);
        w.one("provision", &self.provision);
        w.finish()
    }
}

/// Policies covered by this consent
///
/// FHIR path: `Consent.policy`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConsentPolicy {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `authority` (0..1): Enforcement source for policy
    pub authority: Option<Primitive<String>>,
    /// `uri` (0..1): Specific policy covered by this consent
    pub uri: Option<Primitive<String>>,
}

#[cfg(feature = "foundation")]
impl FhirJson for ConsentPolicy {
    const TYPE_NAME: &'static str = "ConsentPolicy";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConsentPolicy {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            authority: o.prim(d, "authority", Kind::Uri),
            uri: o.prim(d, "uri", Kind::Uri),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("authority", &self.authority);
        w.prim("uri", &self.uri);
        w.finish()
    }
}

/// Consent Verified by patient or family
///
/// FHIR path: `Consent.verification`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConsentVerification {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `verified` (1..1): Has been verified
    pub verified: Option<Primitive<bool>>,
    /// `verifiedWith` (0..1): Person who verified
    pub verified_with: Option<Reference>,
    /// `verificationDate` (0..1): When consent verified
    pub verification_date: Option<Primitive<String>>,
}

#[cfg(feature = "foundation")]
impl FhirJson for ConsentVerification {
    const TYPE_NAME: &'static str = "ConsentVerification";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConsentVerification {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            verified: o.prim(d, "verified", Kind::Boolean),
            verified_with: o.one(d, "verifiedWith"),
            verification_date: o.prim(d, "verificationDate", Kind::DateTime),
        };
        required(d, "verified", &r.verified);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("verified", &self.verified);
        w.one("verifiedWith", &self.verified_with);
        w.prim("verificationDate", &self.verification_date);
        w.finish()
    }
}

/// Constraints to the base Consent.policyRule
///
/// FHIR path: `Consent.provision`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConsentProvision {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `type` (0..1): deny | permit
    pub type_: Option<Primitive<String>>,
    /// `period` (0..1): Timeframe for this rule
    pub period: Option<Period>,
    /// `actor` (0..*): Who|what controlled by this rule (or group, by role)
    pub actor: Vec<ConsentProvisionActor>,
    /// `action` (0..*): Actions controlled by this rule
    pub action: Vec<CodeableConcept>,
    /// `securityLabel` (0..*): Security Labels that define affected resources
    pub security_label: Vec<Coding>,
    /// `purpose` (0..*): Context of activities covered by this rule
    pub purpose: Vec<Coding>,
    /// `class` (0..*): e.g. Resource Type, Profile, CDA, etc.
    pub class: Vec<Coding>,
    /// `code` (0..*): e.g. LOINC or SNOMED CT code, etc. in the content
    pub code: Vec<CodeableConcept>,
    /// `dataPeriod` (0..1): Timeframe for data controlled by this rule
    pub data_period: Option<Period>,
    /// `data` (0..*): Data controlled by this rule
    pub data: Vec<ConsentProvisionData>,
    /// `provision` (0..*): Nested Exception Rules
    pub provision: Vec<ConsentProvision>,
}

#[cfg(feature = "foundation")]
impl FhirJson for ConsentProvision {
    const TYPE_NAME: &'static str = "ConsentProvision";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConsentProvision {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.prim(d, "type", Kind::Code),
            period: o.one(d, "period"),
            actor: o.list(d, "actor"),
            action: o.list(d, "action"),
            security_label: o.list(d, "securityLabel"),
            purpose: o.list(d, "purpose"),
            class: o.list(d, "class"),
            code: o.list(d, "code"),
            data_period: o.one(d, "dataPeriod"),
            data: o.list(d, "data"),
            provision: o.list(d, "provision"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("type", &self.type_);
        w.one("period", &self.period);
        w.list("actor", &self.actor);
        w.list("action", &self.action);
        w.list("securityLabel", &self.security_label);
        w.list("purpose", &self.purpose);
        w.list("class", &self.class);
        w.list("code", &self.code);
        w.one("dataPeriod", &self.data_period);
        w.list("data", &self.data);
        w.list("provision", &self.provision);
        w.finish()
    }
}

/// Who|what controlled by this rule (or group, by role)
///
/// FHIR path: `Consent.provision.actor`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConsentProvisionActor {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `role` (1..1): How the actor is involved
    pub role: Option<CodeableConcept>,
    /// `reference` (1..1): Resource for the actor (or group, by role)
    pub reference: Option<Reference>,
}

#[cfg(feature = "foundation")]
impl FhirJson for ConsentProvisionActor {
    const TYPE_NAME: &'static str = "ConsentProvisionActor";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConsentProvisionActor {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            role: o.one(d, "role"),
            reference: o.one(d, "reference"),
        };
        required(d, "role", &r.role);
        required(d, "reference", &r.reference);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.one("role", &self.role);
        w.one("reference", &self.reference);
        w.finish()
    }
}

/// Data controlled by this rule
///
/// FHIR path: `Consent.provision.data`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConsentProvisionData {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `meaning` (1..1): instance | related | dependents | authoredby
    pub meaning: Option<Primitive<String>>,
    /// `reference` (1..1): The actual data reference
    pub reference: Option<Reference>,
}

#[cfg(feature = "foundation")]
impl FhirJson for ConsentProvisionData {
    const TYPE_NAME: &'static str = "ConsentProvisionData";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConsentProvisionData {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            meaning: o.prim(d, "meaning", Kind::Code),
            reference: o.one(d, "reference"),
        };
        required(d, "meaning", &r.meaning);
        required(d, "reference", &r.reference);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("meaning", &self.meaning);
        w.one("reference", &self.reference);
        w.finish()
    }
}

/// The types `Consent.source[x]` allows.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq)]
pub enum ConsentSource {
    /// `Attachment`
    Attachment(Attachment),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "foundation")]
impl Choice for ConsentSource {
    const TYPES: &'static [&'static str] = &["Attachment", "Reference"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "Attachment" => o.one(d, key).map(Self::Attachment),
            "Reference" => o.one(d, key).map(Self::Reference),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Attachment(v) => w.value(&choice_key(base, "Attachment"), v),
            Self::Reference(v) => w.value(&choice_key(base, "Reference"), v),
        }
    }
}