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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `AuditEvent` 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 an event made for purposes of maintaining a security log. Typical uses include detection of intrusion attempts and monitoring for inappropriate usage.
///
/// FHIR path: `AuditEvent`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AuditEvent {
    /// `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>,
    /// `type` (1..1): Type/identifier of event
    pub type_: Option<Coding>,
    /// `subtype` (0..*): More specific type/id for the event
    pub subtype: Vec<Coding>,
    /// `action` (0..1): Type of action performed during the event
    pub action: Option<Primitive<String>>,
    /// `period` (0..1): When the activity occurred
    pub period: Option<Period>,
    /// `recorded` (1..1): Time when the event was recorded
    pub recorded: Option<Primitive<String>>,
    /// `outcome` (0..1): Whether the event succeeded or failed
    pub outcome: Option<Primitive<String>>,
    /// `outcomeDesc` (0..1): Description of the event outcome
    pub outcome_desc: Option<Primitive<String>>,
    /// `purposeOfEvent` (0..*): The purposeOfUse of the event
    pub purpose_of_event: Vec<CodeableConcept>,
    /// `agent` (1..*): Actor involved in the event
    pub agent: Vec<AuditEventAgent>,
    /// `source` (1..1): Audit Event Reporter
    pub source: Option<AuditEventSource>,
    /// `entity` (0..*): Data or objects used
    pub entity: Vec<AuditEventEntity>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "AuditEvent");
        let r = AuditEvent {
            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"),
            type_: o.one(d, "type"),
            subtype: o.list(d, "subtype"),
            action: o.prim(d, "action", Kind::Code),
            period: o.one(d, "period"),
            recorded: o.prim(d, "recorded", Kind::Instant),
            outcome: o.prim(d, "outcome", Kind::Code),
            outcome_desc: o.prim(d, "outcomeDesc", Kind::String),
            purpose_of_event: o.list(d, "purposeOfEvent"),
            agent: o.list(d, "agent"),
            source: o.one(d, "source"),
            entity: o.list(d, "entity"),
        };
        required(d, "type", &r.type_);
        required(d, "recorded", &r.recorded);
        required_list(d, "agent", &r.agent, 1);
        required(d, "source", &r.source);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("AuditEvent".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.one("type", &self.type_);
        w.list("subtype", &self.subtype);
        w.prim("action", &self.action);
        w.one("period", &self.period);
        w.prim("recorded", &self.recorded);
        w.prim("outcome", &self.outcome);
        w.prim("outcomeDesc", &self.outcome_desc);
        w.list("purposeOfEvent", &self.purpose_of_event);
        w.list("agent", &self.agent);
        w.one("source", &self.source);
        w.list("entity", &self.entity);
        w.finish()
    }
}

/// Actor involved in the event
///
/// FHIR path: `AuditEvent.agent`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AuditEventAgent {
    /// `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): How agent participated
    pub type_: Option<CodeableConcept>,
    /// `role` (0..*): Agent role in the event
    pub role: Vec<CodeableConcept>,
    /// `who` (0..1): Identifier of who
    pub who: Option<Reference>,
    /// `altId` (0..1): Alternative User identity
    pub alt_id: Option<Primitive<String>>,
    /// `name` (0..1): Human friendly name for the agent
    pub name: Option<Primitive<String>>,
    /// `requestor` (1..1): Whether user is initiator
    pub requestor: Option<Primitive<bool>>,
    /// `location` (0..1): Where
    pub location: Option<Reference>,
    /// `policy` (0..*): Policy that authorized event
    pub policy: Vec<Primitive<String>>,
    /// `media` (0..1): Type of media
    pub media: Option<Coding>,
    /// `network` (0..1): Logical network location for application activity
    pub network: Option<AuditEventAgentNetwork>,
    /// `purposeOfUse` (0..*): Reason given for this user
    pub purpose_of_use: Vec<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = AuditEventAgent {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            role: o.list(d, "role"),
            who: o.one(d, "who"),
            alt_id: o.prim(d, "altId", Kind::String),
            name: o.prim(d, "name", Kind::String),
            requestor: o.prim(d, "requestor", Kind::Boolean),
            location: o.one(d, "location"),
            policy: o.prim_list(d, "policy", Kind::Uri),
            media: o.one(d, "media"),
            network: o.one(d, "network"),
            purpose_of_use: o.list(d, "purposeOfUse"),
        };
        required(d, "requestor", &r.requestor);
        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("type", &self.type_);
        w.list("role", &self.role);
        w.one("who", &self.who);
        w.prim("altId", &self.alt_id);
        w.prim("name", &self.name);
        w.prim("requestor", &self.requestor);
        w.one("location", &self.location);
        w.prim_list("policy", &self.policy);
        w.one("media", &self.media);
        w.one("network", &self.network);
        w.list("purposeOfUse", &self.purpose_of_use);
        w.finish()
    }
}

/// Logical network location for application activity
///
/// FHIR path: `AuditEvent.agent.network`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AuditEventAgentNetwork {
    /// `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>,
    /// `address` (0..1): Identifier for the network access point of the user device
    pub address: Option<Primitive<String>>,
    /// `type` (0..1): The type of network access point
    pub type_: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = AuditEventAgentNetwork {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            address: o.prim(d, "address", Kind::String),
            type_: o.prim(d, "type", Kind::Code),
        };
        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("address", &self.address);
        w.prim("type", &self.type_);
        w.finish()
    }
}

/// Audit Event Reporter
///
/// FHIR path: `AuditEvent.source`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AuditEventSource {
    /// `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>,
    /// `site` (0..1): Logical source location within the enterprise
    pub site: Option<Primitive<String>>,
    /// `observer` (1..1): The identity of source detecting the event
    pub observer: Option<Reference>,
    /// `type` (0..*): The type of source where event originated
    pub type_: Vec<Coding>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = AuditEventSource {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            site: o.prim(d, "site", Kind::String),
            observer: o.one(d, "observer"),
            type_: o.list(d, "type"),
        };
        required(d, "observer", &r.observer);
        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("site", &self.site);
        w.one("observer", &self.observer);
        w.list("type", &self.type_);
        w.finish()
    }
}

/// Data or objects used
///
/// FHIR path: `AuditEvent.entity`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AuditEventEntity {
    /// `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>,
    /// `what` (0..1): Specific instance of resource
    pub what: Option<Reference>,
    /// `type` (0..1): Type of entity involved
    pub type_: Option<Coding>,
    /// `role` (0..1): What role the entity played
    pub role: Option<Coding>,
    /// `lifecycle` (0..1): Life-cycle stage for the entity
    pub lifecycle: Option<Coding>,
    /// `securityLabel` (0..*): Security labels on the entity
    pub security_label: Vec<Coding>,
    /// `name` (0..1): Descriptor for entity
    pub name: Option<Primitive<String>>,
    /// `description` (0..1): Descriptive text
    pub description: Option<Primitive<String>>,
    /// `query` (0..1): Query parameters
    pub query: Option<Primitive<String>>,
    /// `detail` (0..*): Additional Information about the entity
    pub detail: Vec<AuditEventEntityDetail>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = AuditEventEntity {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            what: o.one(d, "what"),
            type_: o.one(d, "type"),
            role: o.one(d, "role"),
            lifecycle: o.one(d, "lifecycle"),
            security_label: o.list(d, "securityLabel"),
            name: o.prim(d, "name", Kind::String),
            description: o.prim(d, "description", Kind::String),
            query: o.prim(d, "query", Kind::Base64Binary),
            detail: o.list(d, "detail"),
        };
        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("what", &self.what);
        w.one("type", &self.type_);
        w.one("role", &self.role);
        w.one("lifecycle", &self.lifecycle);
        w.list("securityLabel", &self.security_label);
        w.prim("name", &self.name);
        w.prim("description", &self.description);
        w.prim("query", &self.query);
        w.list("detail", &self.detail);
        w.finish()
    }
}

/// Additional Information about the entity
///
/// FHIR path: `AuditEvent.entity.detail`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AuditEventEntityDetail {
    /// `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` (1..1): Name of the property
    pub type_: Option<Primitive<String>>,
    /// `value[x]` (1..1): Property value
    pub value: Option<AuditEventEntityDetailValue>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = AuditEventEntityDetail {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.prim(d, "type", Kind::String),
            value: o.choice(d, "value"),
        };
        required(d, "type", &r.type_);
        required(d, "value[x]", &r.value);
        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.choice("value", &self.value);
        w.finish()
    }
}

/// The types `AuditEvent.entity.detail.value[x]` allows.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq)]
pub enum AuditEventEntityDetailValue {
    /// `string`
    String(Primitive<String>),
    /// `base64Binary`
    Base64Binary(Primitive<String>),
}

#[cfg(feature = "foundation")]
impl Choice for AuditEventEntityDetailValue {
    const TYPES: &'static [&'static str] = &["string", "base64Binary"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "string" => o.prim(d, key, Kind::String).map(Self::String),
            "base64Binary" => o.prim(d, key, Kind::Base64Binary).map(Self::Base64Binary),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
            Self::Base64Binary(v) => w.prim_value(&choice_key(base, "base64Binary"), v),
        }
    }
}