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

/// Detailed definition of a medicinal product, typically for uses other than direct patient care (e.g. regulatory use).
///
/// FHIR path: `MedicinalProduct`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProduct {
    /// `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..*): Business identifier for this product. Could be an MPID
    pub identifier: Vec<Identifier>,
    /// `type` (0..1): Regulatory type, e.g. Investigational or Authorized
    pub type_: Option<CodeableConcept>,
    /// `domain` (0..1): If this medicine applies to human or veterinary uses
    pub domain: Option<Coding>,
    /// `combinedPharmaceuticalDoseForm` (0..1): The dose form for a single part product, or combined form of a multiple part product
    pub combined_pharmaceutical_dose_form: Option<CodeableConcept>,
    /// `legalStatusOfSupply` (0..1): The legal status of supply of the medicinal product as classified by the regulator
    pub legal_status_of_supply: Option<CodeableConcept>,
    /// `additionalMonitoringIndicator` (0..1): Whether the Medicinal Product is subject to additional monitoring for regulatory reasons
    pub additional_monitoring_indicator: Option<CodeableConcept>,
    /// `specialMeasures` (0..*): Whether the Medicinal Product is subject to special measures for regulatory reasons
    pub special_measures: Vec<Primitive<String>>,
    /// `paediatricUseIndicator` (0..1): If authorised for use in children
    pub paediatric_use_indicator: Option<CodeableConcept>,
    /// `productClassification` (0..*): Allows the product to be classified by various systems
    pub product_classification: Vec<CodeableConcept>,
    /// `marketingStatus` (0..*): Marketing status of the medicinal product, in contrast to marketing authorizaton
    pub marketing_status: Vec<MarketingStatus>,
    /// `pharmaceuticalProduct` (0..*): Pharmaceutical aspects of product
    pub pharmaceutical_product: Vec<Reference>,
    /// `packagedMedicinalProduct` (0..*): Package representation for the product
    pub packaged_medicinal_product: Vec<Reference>,
    /// `attachedDocument` (0..*): Supporting documentation, typically for regulatory submission
    pub attached_document: Vec<Reference>,
    /// `masterFile` (0..*): A master file for to the medicinal product (e.g. Pharmacovigilance System Master File)
    pub master_file: Vec<Reference>,
    /// `contact` (0..*): A product specific contact, person (in a role), or an organization
    pub contact: Vec<Reference>,
    /// `clinicalTrial` (0..*): Clinical trials or studies that this product is involved in
    pub clinical_trial: Vec<Reference>,
    /// `name` (1..*): The product's name, including full name and possibly coded parts
    pub name: Vec<MedicinalProductName>,
    /// `crossReference` (0..*): Reference to another product, e.g. for linking authorised to investigational product
    pub cross_reference: Vec<Identifier>,
    /// `manufacturingBusinessOperation` (0..*): An operation applied to the product, for manufacturing or adminsitrative purpose
    pub manufacturing_business_operation: Vec<MedicinalProductManufacturingBusinessOperation>,
    /// `specialDesignation` (0..*): Indicates if the medicinal product has an orphan designation for the treatment of a rare disease
    pub special_designation: Vec<MedicinalProductSpecialDesignation>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MedicinalProduct");
        let r = MedicinalProduct {
            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"),
            type_: o.one(d, "type"),
            domain: o.one(d, "domain"),
            combined_pharmaceutical_dose_form: o.one(d, "combinedPharmaceuticalDoseForm"),
            legal_status_of_supply: o.one(d, "legalStatusOfSupply"),
            additional_monitoring_indicator: o.one(d, "additionalMonitoringIndicator"),
            special_measures: o.prim_list(d, "specialMeasures", Kind::String),
            paediatric_use_indicator: o.one(d, "paediatricUseIndicator"),
            product_classification: o.list(d, "productClassification"),
            marketing_status: o.list(d, "marketingStatus"),
            pharmaceutical_product: o.list(d, "pharmaceuticalProduct"),
            packaged_medicinal_product: o.list(d, "packagedMedicinalProduct"),
            attached_document: o.list(d, "attachedDocument"),
            master_file: o.list(d, "masterFile"),
            contact: o.list(d, "contact"),
            clinical_trial: o.list(d, "clinicalTrial"),
            name: o.list(d, "name"),
            cross_reference: o.list(d, "crossReference"),
            manufacturing_business_operation: o.list(d, "manufacturingBusinessOperation"),
            special_designation: o.list(d, "specialDesignation"),
        };
        required_list(d, "name", &r.name, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("MedicinalProduct".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("type", &self.type_);
        w.one("domain", &self.domain);
        w.one(
            "combinedPharmaceuticalDoseForm",
            &self.combined_pharmaceutical_dose_form,
        );
        w.one("legalStatusOfSupply", &self.legal_status_of_supply);
        w.one(
            "additionalMonitoringIndicator",
            &self.additional_monitoring_indicator,
        );
        w.prim_list("specialMeasures", &self.special_measures);
        w.one("paediatricUseIndicator", &self.paediatric_use_indicator);
        w.list("productClassification", &self.product_classification);
        w.list("marketingStatus", &self.marketing_status);
        w.list("pharmaceuticalProduct", &self.pharmaceutical_product);
        w.list("packagedMedicinalProduct", &self.packaged_medicinal_product);
        w.list("attachedDocument", &self.attached_document);
        w.list("masterFile", &self.master_file);
        w.list("contact", &self.contact);
        w.list("clinicalTrial", &self.clinical_trial);
        w.list("name", &self.name);
        w.list("crossReference", &self.cross_reference);
        w.list(
            "manufacturingBusinessOperation",
            &self.manufacturing_business_operation,
        );
        w.list("specialDesignation", &self.special_designation);
        w.finish()
    }
}

/// The product's name, including full name and possibly coded parts
///
/// FHIR path: `MedicinalProduct.name`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductName {
    /// `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>,
    /// `productName` (1..1): The full product name
    pub product_name: Option<Primitive<String>>,
    /// `namePart` (0..*): Coding words or phrases of the name
    pub name_part: Vec<MedicinalProductNameNamePart>,
    /// `countryLanguage` (0..*): Country where the name applies
    pub country_language: Vec<MedicinalProductNameCountryLanguage>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicinalProductName {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            product_name: o.prim(d, "productName", Kind::String),
            name_part: o.list(d, "namePart"),
            country_language: o.list(d, "countryLanguage"),
        };
        required(d, "productName", &r.product_name);
        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("productName", &self.product_name);
        w.list("namePart", &self.name_part);
        w.list("countryLanguage", &self.country_language);
        w.finish()
    }
}

/// Coding words or phrases of the name
///
/// FHIR path: `MedicinalProduct.name.namePart`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductNameNamePart {
    /// `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>,
    /// `part` (1..1): A fragment of a product name
    pub part: Option<Primitive<String>>,
    /// `type` (1..1): Idenifying type for this part of the name (e.g. strength part)
    pub type_: Option<Coding>,
}

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

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

/// Country where the name applies
///
/// FHIR path: `MedicinalProduct.name.countryLanguage`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductNameCountryLanguage {
    /// `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>,
    /// `country` (1..1): Country code for where this name applies
    pub country: Option<CodeableConcept>,
    /// `jurisdiction` (0..1): Jurisdiction code for where this name applies
    pub jurisdiction: Option<CodeableConcept>,
    /// `language` (1..1): Language code for this name
    pub language: Option<CodeableConcept>,
}

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

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

/// An operation applied to the product, for manufacturing or adminsitrative purpose
///
/// FHIR path: `MedicinalProduct.manufacturingBusinessOperation`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductManufacturingBusinessOperation {
    /// `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>,
    /// `operationType` (0..1): The type of manufacturing operation
    pub operation_type: Option<CodeableConcept>,
    /// `authorisationReferenceNumber` (0..1): Regulatory authorization reference number
    pub authorisation_reference_number: Option<Identifier>,
    /// `effectiveDate` (0..1): Regulatory authorization date
    pub effective_date: Option<Primitive<String>>,
    /// `confidentialityIndicator` (0..1): To indicate if this proces is commercially confidential
    pub confidentiality_indicator: Option<CodeableConcept>,
    /// `manufacturer` (0..*): The manufacturer or establishment associated with the process
    pub manufacturer: Vec<Reference>,
    /// `regulator` (0..1): A regulator which oversees the operation
    pub regulator: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicinalProductManufacturingBusinessOperation {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            operation_type: o.one(d, "operationType"),
            authorisation_reference_number: o.one(d, "authorisationReferenceNumber"),
            effective_date: o.prim(d, "effectiveDate", Kind::DateTime),
            confidentiality_indicator: o.one(d, "confidentialityIndicator"),
            manufacturer: o.list(d, "manufacturer"),
            regulator: o.one(d, "regulator"),
        };
        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("operationType", &self.operation_type);
        w.one(
            "authorisationReferenceNumber",
            &self.authorisation_reference_number,
        );
        w.prim("effectiveDate", &self.effective_date);
        w.one("confidentialityIndicator", &self.confidentiality_indicator);
        w.list("manufacturer", &self.manufacturer);
        w.one("regulator", &self.regulator);
        w.finish()
    }
}

/// Indicates if the medicinal product has an orphan designation for the treatment of a rare disease
///
/// FHIR path: `MedicinalProduct.specialDesignation`.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MedicinalProductSpecialDesignation {
    /// `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>,
    /// `identifier` (0..*): Identifier for the designation, or procedure number
    pub identifier: Vec<Identifier>,
    /// `type` (0..1): The type of special designation, e.g. orphan drug, minor use
    pub type_: Option<CodeableConcept>,
    /// `intendedUse` (0..1): The intended use of the product, e.g. prevention, treatment
    pub intended_use: Option<CodeableConcept>,
    /// `indication[x]` (0..1): Condition for which the medicinal use applies
    pub indication: Option<MedicinalProductSpecialDesignationIndication>,
    /// `status` (0..1): For example granted, pending, expired or withdrawn
    pub status: Option<CodeableConcept>,
    /// `date` (0..1): Date when the designation was granted
    pub date: Option<Primitive<String>>,
    /// `species` (0..1): Animal species for which this applies
    pub species: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MedicinalProductSpecialDesignation {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            identifier: o.list(d, "identifier"),
            type_: o.one(d, "type"),
            intended_use: o.one(d, "intendedUse"),
            indication: o.choice(d, "indication"),
            status: o.one(d, "status"),
            date: o.prim(d, "date", Kind::DateTime),
            species: o.one(d, "species"),
        };
        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("identifier", &self.identifier);
        w.one("type", &self.type_);
        w.one("intendedUse", &self.intended_use);
        w.choice("indication", &self.indication);
        w.one("status", &self.status);
        w.prim("date", &self.date);
        w.one("species", &self.species);
        w.finish()
    }
}

/// The types `MedicinalProduct.specialDesignation.indication[x]` allows.
#[cfg(feature = "specialized")]
#[derive(Debug, Clone, PartialEq)]
pub enum MedicinalProductSpecialDesignationIndication {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

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

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

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