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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `Encounter` 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::*;

/// An interaction between a patient and healthcare provider(s) for the purpose of providing healthcare service(s) or assessing the health status of a patient.
///
/// FHIR path: `Encounter`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Encounter {
    /// `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(s) by which this encounter is known
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): planned | arrived | triaged | in-progress | onleave | finished | cancelled +
    pub status: Option<Primitive<String>>,
    /// `statusHistory` (0..*): List of past encounter statuses
    pub status_history: Vec<EncounterStatusHistory>,
    /// `class` (1..1): Classification of patient encounter
    pub class: Option<Coding>,
    /// `classHistory` (0..*): List of past encounter classes
    pub class_history: Vec<EncounterClassHistory>,
    /// `type` (0..*): Specific type of encounter
    pub type_: Vec<CodeableConcept>,
    /// `serviceType` (0..1): Specific type of service
    pub service_type: Option<CodeableConcept>,
    /// `priority` (0..1): Indicates the urgency of the encounter
    pub priority: Option<CodeableConcept>,
    /// `subject` (0..1): The patient or group present at the encounter
    pub subject: Option<Reference>,
    /// `episodeOfCare` (0..*): Episode(s) of care that this encounter should be recorded against
    pub episode_of_care: Vec<Reference>,
    /// `basedOn` (0..*): The ServiceRequest that initiated this encounter
    pub based_on: Vec<Reference>,
    /// `participant` (0..*): List of participants involved in the encounter
    pub participant: Vec<EncounterParticipant>,
    /// `appointment` (0..*): The appointment that scheduled this encounter
    pub appointment: Vec<Reference>,
    /// `period` (0..1): The start and end time of the encounter
    pub period: Option<Period>,
    /// `length` (0..1): Quantity of time the encounter lasted (less time absent)
    pub length: Option<Duration>,
    /// `reasonCode` (0..*): Coded reason the encounter takes place
    pub reason_code: Vec<CodeableConcept>,
    /// `reasonReference` (0..*): Reason the encounter takes place (reference)
    pub reason_reference: Vec<Reference>,
    /// `diagnosis` (0..*): The list of diagnosis relevant to this encounter
    pub diagnosis: Vec<EncounterDiagnosis>,
    /// `account` (0..*): The set of accounts that may be used for billing for this Encounter
    pub account: Vec<Reference>,
    /// `hospitalization` (0..1): Details about the admission to a healthcare service
    pub hospitalization: Option<EncounterHospitalization>,
    /// `location` (0..*): List of locations where the patient has been
    pub location: Vec<EncounterLocation>,
    /// `serviceProvider` (0..1): The organization (facility) responsible for this encounter
    pub service_provider: Option<Reference>,
    /// `partOf` (0..1): Another Encounter this encounter is part of
    pub part_of: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Encounter");
        let r = Encounter {
            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),
            status_history: o.list(d, "statusHistory"),
            class: o.one(d, "class"),
            class_history: o.list(d, "classHistory"),
            type_: o.list(d, "type"),
            service_type: o.one(d, "serviceType"),
            priority: o.one(d, "priority"),
            subject: o.one(d, "subject"),
            episode_of_care: o.list(d, "episodeOfCare"),
            based_on: o.list(d, "basedOn"),
            participant: o.list(d, "participant"),
            appointment: o.list(d, "appointment"),
            period: o.one(d, "period"),
            length: o.one(d, "length"),
            reason_code: o.list(d, "reasonCode"),
            reason_reference: o.list(d, "reasonReference"),
            diagnosis: o.list(d, "diagnosis"),
            account: o.list(d, "account"),
            hospitalization: o.one(d, "hospitalization"),
            location: o.list(d, "location"),
            service_provider: o.one(d, "serviceProvider"),
            part_of: o.one(d, "partOf"),
        };
        required(d, "status", &r.status);
        required(d, "class", &r.class);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Encounter".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.list("statusHistory", &self.status_history);
        w.one("class", &self.class);
        w.list("classHistory", &self.class_history);
        w.list("type", &self.type_);
        w.one("serviceType", &self.service_type);
        w.one("priority", &self.priority);
        w.one("subject", &self.subject);
        w.list("episodeOfCare", &self.episode_of_care);
        w.list("basedOn", &self.based_on);
        w.list("participant", &self.participant);
        w.list("appointment", &self.appointment);
        w.one("period", &self.period);
        w.one("length", &self.length);
        w.list("reasonCode", &self.reason_code);
        w.list("reasonReference", &self.reason_reference);
        w.list("diagnosis", &self.diagnosis);
        w.list("account", &self.account);
        w.one("hospitalization", &self.hospitalization);
        w.list("location", &self.location);
        w.one("serviceProvider", &self.service_provider);
        w.one("partOf", &self.part_of);
        w.finish()
    }
}

/// List of past encounter statuses
///
/// FHIR path: `Encounter.statusHistory`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EncounterStatusHistory {
    /// `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>,
    /// `status` (1..1): planned | arrived | triaged | in-progress | onleave | finished | cancelled +
    pub status: Option<Primitive<String>>,
    /// `period` (1..1): The time that the episode was in the specified status
    pub period: Option<Period>,
}

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

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

/// List of past encounter classes
///
/// FHIR path: `Encounter.classHistory`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EncounterClassHistory {
    /// `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>,
    /// `class` (1..1): inpatient | outpatient | ambulatory | emergency +
    pub class: Option<Coding>,
    /// `period` (1..1): The time that the episode was in the specified class
    pub period: Option<Period>,
}

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

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

/// List of participants involved in the encounter
///
/// FHIR path: `Encounter.participant`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EncounterParticipant {
    /// `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..*): Role of participant in encounter
    pub type_: Vec<CodeableConcept>,
    /// `period` (0..1): Period of time during the encounter that the participant participated
    pub period: Option<Period>,
    /// `individual` (0..1): Persons involved in the encounter other than the patient
    pub individual: Option<Reference>,
}

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

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

/// The list of diagnosis relevant to this encounter
///
/// FHIR path: `Encounter.diagnosis`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EncounterDiagnosis {
    /// `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>,
    /// `condition` (1..1): The diagnosis or procedure relevant to the encounter
    pub condition: Option<Reference>,
    /// `use` (0..1): Role that this diagnosis has within the encounter (e.g. admission, billing, discharge …)
    pub use_: Option<CodeableConcept>,
    /// `rank` (0..1): Ranking of the diagnosis (for each role type)
    pub rank: Option<Primitive<i32>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = EncounterDiagnosis {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            condition: o.one(d, "condition"),
            use_: o.one(d, "use"),
            rank: o.prim(d, "rank", Kind::PositiveInt),
        };
        required(d, "condition", &r.condition);
        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("condition", &self.condition);
        w.one("use", &self.use_);
        w.prim("rank", &self.rank);
        w.finish()
    }
}

/// Details about the admission to a healthcare service
///
/// FHIR path: `Encounter.hospitalization`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EncounterHospitalization {
    /// `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>,
    /// `preAdmissionIdentifier` (0..1): Pre-admission identifier
    pub pre_admission_identifier: Option<Identifier>,
    /// `origin` (0..1): The location/organization from which the patient came before admission
    pub origin: Option<Reference>,
    /// `admitSource` (0..1): From where patient was admitted (physician referral, transfer)
    pub admit_source: Option<CodeableConcept>,
    /// `reAdmission` (0..1): The type of hospital re-admission that has occurred (if any). If the value is absent, then this is not identified as a readmission
    pub re_admission: Option<CodeableConcept>,
    /// `dietPreference` (0..*): Diet preferences reported by the patient
    pub diet_preference: Vec<CodeableConcept>,
    /// `specialCourtesy` (0..*): Special courtesies (VIP, board member)
    pub special_courtesy: Vec<CodeableConcept>,
    /// `specialArrangement` (0..*): Wheelchair, translator, stretcher, etc.
    pub special_arrangement: Vec<CodeableConcept>,
    /// `destination` (0..1): Location/organization to which the patient is discharged
    pub destination: Option<Reference>,
    /// `dischargeDisposition` (0..1): Category or kind of location after discharge
    pub discharge_disposition: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = EncounterHospitalization {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            pre_admission_identifier: o.one(d, "preAdmissionIdentifier"),
            origin: o.one(d, "origin"),
            admit_source: o.one(d, "admitSource"),
            re_admission: o.one(d, "reAdmission"),
            diet_preference: o.list(d, "dietPreference"),
            special_courtesy: o.list(d, "specialCourtesy"),
            special_arrangement: o.list(d, "specialArrangement"),
            destination: o.one(d, "destination"),
            discharge_disposition: o.one(d, "dischargeDisposition"),
        };
        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("preAdmissionIdentifier", &self.pre_admission_identifier);
        w.one("origin", &self.origin);
        w.one("admitSource", &self.admit_source);
        w.one("reAdmission", &self.re_admission);
        w.list("dietPreference", &self.diet_preference);
        w.list("specialCourtesy", &self.special_courtesy);
        w.list("specialArrangement", &self.special_arrangement);
        w.one("destination", &self.destination);
        w.one("dischargeDisposition", &self.discharge_disposition);
        w.finish()
    }
}

/// List of locations where the patient has been
///
/// FHIR path: `Encounter.location`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EncounterLocation {
    /// `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>,
    /// `location` (1..1): Location the encounter takes place
    pub location: Option<Reference>,
    /// `status` (0..1): planned | active | reserved | completed
    pub status: Option<Primitive<String>>,
    /// `physicalType` (0..1): The physical type of the location (usually the level in the location hierachy - bed room ward etc.)
    pub physical_type: Option<CodeableConcept>,
    /// `period` (0..1): Time period during which the patient was present at the location
    pub period: Option<Period>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = EncounterLocation {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            location: o.one(d, "location"),
            status: o.prim(d, "status", Kind::Code),
            physical_type: o.one(d, "physicalType"),
            period: o.one(d, "period"),
        };
        required(d, "location", &r.location);
        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("location", &self.location);
        w.prim("status", &self.status);
        w.one("physicalType", &self.physical_type);
        w.one("period", &self.period);
        w.finish()
    }
}