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
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `DeviceDefinition` 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::*;

/// The characteristics, operational status and capabilities of a medical-related component of a medical device.
///
/// FHIR path: `DeviceDefinition`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDefinition {
    /// `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>,
    /// `udiDeviceIdentifier` (0..*): Unique Device Identifier (UDI) Barcode string
    pub udi_device_identifier: Vec<DeviceDefinitionUdiDeviceIdentifier>,
    /// `manufacturer[x]` (0..1): Name of device manufacturer
    pub manufacturer: Option<DeviceDefinitionManufacturer>,
    /// `deviceName` (0..*): A name given to the device to identify it
    pub device_name: Vec<DeviceDefinitionDeviceName>,
    /// `modelNumber` (0..1): The model number for the device
    pub model_number: Option<Primitive<String>>,
    /// `type` (0..1): What kind of device or device system this is
    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<DeviceDefinitionSpecialization>,
    /// `version` (0..*): Available versions
    pub version: Vec<Primitive<String>>,
    /// `safety` (0..*): Safety characteristics of the device
    pub safety: Vec<CodeableConcept>,
    /// `shelfLifeStorage` (0..*): Shelf Life and storage information
    pub shelf_life_storage: Vec<ProductShelfLife>,
    /// `physicalCharacteristics` (0..1): Dimensions, color etc.
    pub physical_characteristics: Option<ProdCharacteristic>,
    /// `languageCode` (0..*): Language code for the human-readable text strings produced by the device (all supported)
    pub language_code: Vec<CodeableConcept>,
    /// `capability` (0..*): Device capabilities
    pub capability: Vec<DeviceDefinitionCapability>,
    /// `property` (0..*): The actual configuration settings of a device as it actually operates, e.g., regulation status, time properties
    pub property: Vec<DeviceDefinitionProperty>,
    /// `owner` (0..1): Organization responsible for device
    pub owner: Option<Reference>,
    /// `contact` (0..*): Details for human/organization for support
    pub contact: Vec<ContactPoint>,
    /// `url` (0..1): Network address to contact device
    pub url: Option<Primitive<String>>,
    /// `onlineInformation` (0..1): Access to on-line information
    pub online_information: Option<Primitive<String>>,
    /// `note` (0..*): Device notes and comments
    pub note: Vec<Annotation>,
    /// `quantity` (0..1): The quantity of the device present in the packaging (e.g. the number of devices present in a pack, or the number of devices in the same package of the medicinal product)
    pub quantity: Option<Quantity>,
    /// `parentDevice` (0..1): The parent device it can be part of
    pub parent_device: Option<Reference>,
    /// `material` (0..*): A substance used to create the material(s) of which the device is made
    pub material: Vec<DeviceDefinitionMaterial>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "DeviceDefinition");
        let r = DeviceDefinition {
            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"),
            udi_device_identifier: o.list(d, "udiDeviceIdentifier"),
            manufacturer: o.choice(d, "manufacturer"),
            device_name: o.list(d, "deviceName"),
            model_number: o.prim(d, "modelNumber", Kind::String),
            type_: o.one(d, "type"),
            specialization: o.list(d, "specialization"),
            version: o.prim_list(d, "version", Kind::String),
            safety: o.list(d, "safety"),
            shelf_life_storage: o.list(d, "shelfLifeStorage"),
            physical_characteristics: o.one(d, "physicalCharacteristics"),
            language_code: o.list(d, "languageCode"),
            capability: o.list(d, "capability"),
            property: o.list(d, "property"),
            owner: o.one(d, "owner"),
            contact: o.list(d, "contact"),
            url: o.prim(d, "url", Kind::Uri),
            online_information: o.prim(d, "onlineInformation", Kind::Uri),
            note: o.list(d, "note"),
            quantity: o.one(d, "quantity"),
            parent_device: o.one(d, "parentDevice"),
            material: o.list(d, "material"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("DeviceDefinition".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.list("udiDeviceIdentifier", &self.udi_device_identifier);
        w.choice("manufacturer", &self.manufacturer);
        w.list("deviceName", &self.device_name);
        w.prim("modelNumber", &self.model_number);
        w.one("type", &self.type_);
        w.list("specialization", &self.specialization);
        w.prim_list("version", &self.version);
        w.list("safety", &self.safety);
        w.list("shelfLifeStorage", &self.shelf_life_storage);
        w.one("physicalCharacteristics", &self.physical_characteristics);
        w.list("languageCode", &self.language_code);
        w.list("capability", &self.capability);
        w.list("property", &self.property);
        w.one("owner", &self.owner);
        w.list("contact", &self.contact);
        w.prim("url", &self.url);
        w.prim("onlineInformation", &self.online_information);
        w.list("note", &self.note);
        w.one("quantity", &self.quantity);
        w.one("parentDevice", &self.parent_device);
        w.list("material", &self.material);
        w.finish()
    }
}

/// Unique Device Identifier (UDI) Barcode string
///
/// FHIR path: `DeviceDefinition.udiDeviceIdentifier`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDefinitionUdiDeviceIdentifier {
    /// `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` (1..1): The identifier that is to be associated with every Device that references this DeviceDefintiion for the issuer and jurisdication porvided in the DeviceDefinition.udiDeviceIdentifier
    pub device_identifier: Option<Primitive<String>>,
    /// `issuer` (1..1): The organization that assigns the identifier algorithm
    pub issuer: Option<Primitive<String>>,
    /// `jurisdiction` (1..1): The jurisdiction to which the deviceIdentifier applies
    pub jurisdiction: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = DeviceDefinitionUdiDeviceIdentifier {
            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),
        };
        required(d, "deviceIdentifier", &r.device_identifier);
        required(d, "issuer", &r.issuer);
        required(d, "jurisdiction", &r.jurisdiction);
        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.finish()
    }
}

/// A name given to the device to identify it
///
/// FHIR path: `DeviceDefinition.deviceName`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDefinitionDeviceName {
    /// `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 = "specialized")]
impl FhirJson for DeviceDefinitionDeviceName {
    const TYPE_NAME: &'static str = "DeviceDefinitionDeviceName";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = DeviceDefinitionDeviceName {
            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: `DeviceDefinition.specialization`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDefinitionSpecialization {
    /// `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<Primitive<String>>,
    /// `version` (0..1): The version of the standard that is used to operate and communicate
    pub version: Option<Primitive<String>>,
}

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

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

/// Device capabilities
///
/// FHIR path: `DeviceDefinition.capability`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDefinitionCapability {
    /// `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): Type of capability
    pub type_: Option<CodeableConcept>,
    /// `description` (0..*): Description of capability
    pub description: Vec<CodeableConcept>,
}

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

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

/// The actual configuration settings of a device as it actually operates, e.g., regulation status, time properties
///
/// FHIR path: `DeviceDefinition.property`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDefinitionProperty {
    /// `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 = "specialized")]
impl FhirJson for DeviceDefinitionProperty {
    const TYPE_NAME: &'static str = "DeviceDefinitionProperty";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = DeviceDefinitionProperty {
            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()
    }
}

/// A substance used to create the material(s) of which the device is made
///
/// FHIR path: `DeviceDefinition.material`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceDefinitionMaterial {
    /// `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>,
    /// `substance` (1..1): The substance
    pub substance: Option<CodeableConcept>,
    /// `alternate` (0..1): Indicates an alternative material of the device
    pub alternate: Option<Primitive<bool>>,
    /// `allergenicIndicator` (0..1): Whether the substance is a known or suspected allergen
    pub allergenic_indicator: Option<Primitive<bool>>,
}

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

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

/// The types `DeviceDefinition.manufacturer[x]` allows.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq)]
pub enum DeviceDefinitionManufacturer {
    /// `string`
    String(Primitive<String>),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "specialized")]
impl Choice for DeviceDefinitionManufacturer {
    const TYPES: &'static [&'static str] = &["string", "Reference"];

    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),
            "Reference" => o.one(d, key).map(Self::Reference),
            _ => None,
        }
    }

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