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
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `Device` 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 type of a manufactured item that is used in the provision of healthcare without being substantially changed through that activity. The device may be a medical or non-medical device.
///
/// FHIR path: `Device`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Device {
    /// `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..*): Instance identifier
    pub identifier: Vec<Identifier>,
    /// `definition` (0..1): The reference to the definition for the device
    pub definition: Option<Reference>,
    /// `udiCarrier` (0..*): Unique Device Identifier (UDI) Barcode string
    pub udi_carrier: Vec<DeviceUdiCarrier>,
    /// `status` (0..1): active | inactive | entered-in-error | unknown
    pub status: Option<Primitive<String>>,
    /// `statusReason` (0..*): online | paused | standby | offline | not-ready | transduc-discon | hw-discon | off
    pub status_reason: Vec<CodeableConcept>,
    /// `distinctIdentifier` (0..1): The distinct identification string
    pub distinct_identifier: Option<Primitive<String>>,
    /// `manufacturer` (0..1): Name of device manufacturer
    pub manufacturer: Option<Primitive<String>>,
    /// `manufactureDate` (0..1): Date when the device was made
    pub manufacture_date: Option<Primitive<String>>,
    /// `expirationDate` (0..1): Date and time of expiry of this device (if applicable)
    pub expiration_date: Option<Primitive<String>>,
    /// `lotNumber` (0..1): Lot number of manufacture
    pub lot_number: Option<Primitive<String>>,
    /// `serialNumber` (0..1): Serial number assigned by the manufacturer
    pub serial_number: Option<Primitive<String>>,
    /// `deviceName` (0..*): The name of the device as given by the manufacturer
    pub device_name: Vec<DeviceDeviceName>,
    /// `modelNumber` (0..1): The model number for the device
    pub model_number: Option<Primitive<String>>,
    /// `partNumber` (0..1): The part number of the device
    pub part_number: Option<Primitive<String>>,
    /// `type` (0..1): The kind or type of device
    pub type_: Option<CodeableConcept>,
    /// `specialization` (0..*): The capabilities supported on a device, the standards to which the device conforms for a particular purpose, and used for the communication
    pub specialization: Vec<DeviceSpecialization>,
    /// `version` (0..*): The actual design of the device or software version running on the device
    pub version: Vec<DeviceVersion>,
    /// `property` (0..*): The actual configuration settings of a device as it actually operates, e.g., regulation status, time properties
    pub property: Vec<DeviceProperty>,
    /// `patient` (0..1): Patient to whom Device is affixed
    pub patient: Option<Reference>,
    /// `owner` (0..1): Organization responsible for device
    pub owner: Option<Reference>,
    /// `contact` (0..*): Details for human/organization for support
    pub contact: Vec<ContactPoint>,
    /// `location` (0..1): Where the device is found
    pub location: Option<Reference>,
    /// `url` (0..1): Network address to contact device
    pub url: Option<Primitive<String>>,
    /// `note` (0..*): Device notes and comments
    pub note: Vec<Annotation>,
    /// `safety` (0..*): Safety Characteristics of Device
    pub safety: Vec<CodeableConcept>,
    /// `parent` (0..1): The parent device
    pub parent: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Device");
        let r = Device {
            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"),
            definition: o.one(d, "definition"),
            udi_carrier: o.list(d, "udiCarrier"),
            status: o.prim(d, "status", Kind::Code),
            status_reason: o.list(d, "statusReason"),
            distinct_identifier: o.prim(d, "distinctIdentifier", Kind::String),
            manufacturer: o.prim(d, "manufacturer", Kind::String),
            manufacture_date: o.prim(d, "manufactureDate", Kind::DateTime),
            expiration_date: o.prim(d, "expirationDate", Kind::DateTime),
            lot_number: o.prim(d, "lotNumber", Kind::String),
            serial_number: o.prim(d, "serialNumber", Kind::String),
            device_name: o.list(d, "deviceName"),
            model_number: o.prim(d, "modelNumber", Kind::String),
            part_number: o.prim(d, "partNumber", Kind::String),
            type_: o.one(d, "type"),
            specialization: o.list(d, "specialization"),
            version: o.list(d, "version"),
            property: o.list(d, "property"),
            patient: o.one(d, "patient"),
            owner: o.one(d, "owner"),
            contact: o.list(d, "contact"),
            location: o.one(d, "location"),
            url: o.prim(d, "url", Kind::Uri),
            note: o.list(d, "note"),
            safety: o.list(d, "safety"),
            parent: o.one(d, "parent"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Device".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.one("definition", &self.definition);
        w.list("udiCarrier", &self.udi_carrier);
        w.prim("status", &self.status);
        w.list("statusReason", &self.status_reason);
        w.prim("distinctIdentifier", &self.distinct_identifier);
        w.prim("manufacturer", &self.manufacturer);
        w.prim("manufactureDate", &self.manufacture_date);
        w.prim("expirationDate", &self.expiration_date);
        w.prim("lotNumber", &self.lot_number);
        w.prim("serialNumber", &self.serial_number);
        w.list("deviceName", &self.device_name);
        w.prim("modelNumber", &self.model_number);
        w.prim("partNumber", &self.part_number);
        w.one("type", &self.type_);
        w.list("specialization", &self.specialization);
        w.list("version", &self.version);
        w.list("property", &self.property);
        w.one("patient", &self.patient);
        w.one("owner", &self.owner);
        w.list("contact", &self.contact);
        w.one("location", &self.location);
        w.prim("url", &self.url);
        w.list("note", &self.note);
        w.list("safety", &self.safety);
        w.one("parent", &self.parent);
        w.finish()
    }
}

/// Unique Device Identifier (UDI) Barcode string
///
/// FHIR path: `Device.udiCarrier`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceUdiCarrier {
    /// `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>,
    /// `deviceIdentifier` (0..1): Mandatory fixed portion of UDI
    pub device_identifier: Option<Primitive<String>>,
    /// `issuer` (0..1): UDI Issuing Organization
    pub issuer: Option<Primitive<String>>,
    /// `jurisdiction` (0..1): Regional UDI authority
    pub jurisdiction: Option<Primitive<String>>,
    /// `carrierAIDC` (0..1): UDI Machine Readable Barcode String
    pub carrier_aidc: Option<Primitive<String>>,
    /// `carrierHRF` (0..1): UDI Human Readable Barcode String
    pub carrier_hrf: Option<Primitive<String>>,
    /// `entryType` (0..1): barcode | rfid | manual +
    pub entry_type: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = DeviceUdiCarrier {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            device_identifier: o.prim(d, "deviceIdentifier", Kind::String),
            issuer: o.prim(d, "issuer", Kind::Uri),
            jurisdiction: o.prim(d, "jurisdiction", Kind::Uri),
            carrier_aidc: o.prim(d, "carrierAIDC", Kind::Base64Binary),
            carrier_hrf: o.prim(d, "carrierHRF", Kind::String),
            entry_type: o.prim(d, "entryType", 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("deviceIdentifier", &self.device_identifier);
        w.prim("issuer", &self.issuer);
        w.prim("jurisdiction", &self.jurisdiction);
        w.prim("carrierAIDC", &self.carrier_aidc);
        w.prim("carrierHRF", &self.carrier_hrf);
        w.prim("entryType", &self.entry_type);
        w.finish()
    }
}

/// The name of the device as given by the manufacturer
///
/// FHIR path: `Device.deviceName`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDeviceName {
    /// `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>,
    /// `name` (1..1): The name of the device
    pub name: Option<Primitive<String>>,
    /// `type` (1..1): udi-label-name | user-friendly-name | patient-reported-name | manufacturer-name | model-name | other
    pub type_: Option<Primitive<String>>,
}

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

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

/// The capabilities supported on a device, the standards to which the device conforms for a particular purpose, and used for the communication
///
/// FHIR path: `Device.specialization`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceSpecialization {
    /// `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>,
    /// `systemType` (1..1): The standard that is used to operate and communicate
    pub system_type: Option<CodeableConcept>,
    /// `version` (0..1): The version of the standard that is used to operate and communicate
    pub version: Option<Primitive<String>>,
}

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

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

/// The actual design of the device or software version running on the device
///
/// FHIR path: `Device.version`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceVersion {
    /// `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): The type of the device version
    pub type_: Option<CodeableConcept>,
    /// `component` (0..1): A single component of the device version
    pub component: Option<Identifier>,
    /// `value` (1..1): The version text
    pub value: Option<Primitive<String>>,
}

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

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

/// The actual configuration settings of a device as it actually operates, e.g., regulation status, time properties
///
/// FHIR path: `Device.property`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceProperty {
    /// `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): Code that specifies the property DeviceDefinitionPropetyCode (Extensible)
    pub type_: Option<CodeableConcept>,
    /// `valueQuantity` (0..*): Property value as a quantity
    pub value_quantity: Vec<Quantity>,
    /// `valueCode` (0..*): Property value as a code, e.g., NTP4 (synced to NTP)
    pub value_code: Vec<CodeableConcept>,
}

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

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