fhir-types 0.1.115

Generated per-version FHIR types and terminology operation contracts
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
// @generated by fhir-codegen from hl7.fhir.r4.core 4.0.1. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-License-Identifier: Apache-2.0
//! The marketing status describes the date when a medicinal product is actually put on the market or the date as of which it is no longer available

/// The marketing status describes the date when a medicinal product is actually
/// put on the market or the date as of which it is no longer available.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ProdCharacteristic {
    /// Unique id for inter-element referencing
    ///
    /// Unique id for the element within a resource (for internal references). This
    /// may be any string value that does not contain spaces.
    pub id: Option<std::string::String>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element. To make the use of extensions safe and
    /// manageable, there is a strict set of governance applied to the definition
    /// and use of extensions. Though any implementer can define an extension, there
    /// is a set of requirements that SHALL be met as part of the definition of the
    /// extension.
    pub extension: Vec<super::extension::Extension>,
    /// Extensions that cannot be ignored even if unrecognized
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element and that modifies the understanding of the
    /// element in which it is contained and/or the understanding of the containing
    /// element's descendants. Usually modifier elements provide negation or
    /// qualification. To make the use of extensions safe and manageable, there is a
    /// strict set of governance applied to the definition and use of extensions.
    /// Though any implementer can define an extension, there is a set of
    /// requirements that SHALL be met as part of the definition of the extension.
    /// Applications processing a resource are required to check for modifier
    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
    /// on Resource or DomainResource (including cannot change the meaning of
    /// modifierExtension itself).
    pub modifier_extension: Vec<super::extension::Extension>,
    /// Where applicable, the height can be specified using a numerical value and
    /// its unit of measurement The unit of measurement shall be specified in
    /// accordance with ISO 11240 and the resulting terminology The symbol and the
    /// symbol identifier shall be used.
    pub height: Option<super::quantity::Quantity>,
    /// Where applicable, the width can be specified using a numerical value and its
    /// unit of measurement The unit of measurement shall be specified in accordance
    /// with ISO 11240 and the resulting terminology The symbol and the symbol
    /// identifier shall be used.
    pub width: Option<super::quantity::Quantity>,
    /// Where applicable, the depth can be specified using a numerical value and its
    /// unit of measurement The unit of measurement shall be specified in accordance
    /// with ISO 11240 and the resulting terminology The symbol and the symbol
    /// identifier shall be used.
    pub depth: Option<super::quantity::Quantity>,
    /// Where applicable, the weight can be specified using a numerical value and
    /// its unit of measurement The unit of measurement shall be specified in
    /// accordance with ISO 11240 and the resulting terminology The symbol and the
    /// symbol identifier shall be used.
    pub weight: Option<super::quantity::Quantity>,
    /// Where applicable, the nominal volume can be specified using a numerical
    /// value and its unit of measurement The unit of measurement shall be specified
    /// in accordance with ISO 11240 and the resulting terminology The symbol and
    /// the symbol identifier shall be used.
    pub nominal_volume: Option<super::quantity::Quantity>,
    /// Where applicable, the external diameter can be specified using a numerical
    /// value and its unit of measurement The unit of measurement shall be specified
    /// in accordance with ISO 11240 and the resulting terminology The symbol and
    /// the symbol identifier shall be used.
    pub external_diameter: Option<super::quantity::Quantity>,
    /// Where applicable, the shape can be specified An appropriate controlled
    /// vocabulary shall be used The term and the term identifier shall be used.
    pub shape: Option<super::primitives::String>,
    /// Where applicable, the color can be specified An appropriate controlled
    /// vocabulary shall be used The term and the term identifier shall be used.
    pub color: Vec<super::primitives::String>,
    /// Where applicable, the imprint can be specified as text.
    pub imprint: Vec<super::primitives::String>,
    /// Where applicable, the image can be provided The format of the image
    /// attachment shall be specified by regional implementations.
    pub image: Vec<super::attachment::Attachment>,
    /// Where applicable, the scoring can be specified An appropriate controlled
    /// vocabulary shall be used The term and the term identifier shall be used.
    pub scoring: Option<super::codeable_concept::CodeableConcept>,
}

impl super::super::codec::Json for ProdCharacteristic {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                super::super::codec::Value::String(v.clone()),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.modifier_extension.is_empty() {
            let mut items = Vec::with_capacity(self.modifier_extension.len());
            for item in &self.modifier_extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("modifierExtension"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.height {
            object.insert(
                std::string::String::from("height"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.width {
            object.insert(
                std::string::String::from("width"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.depth {
            object.insert(
                std::string::String::from("depth"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.weight {
            object.insert(
                std::string::String::from("weight"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.nominal_volume {
            object.insert(
                std::string::String::from("nominalVolume"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.external_diameter {
            object.insert(
                std::string::String::from("externalDiameter"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.shape {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("shape"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_shape"), e);
            }
        }
        if !self.color.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.color)?;
            if let Some(values) = values {
                object.insert(std::string::String::from("color"), values);
            }
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_color"), elements);
            }
        }
        if !self.imprint.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.imprint)?;
            if let Some(values) = values {
                object.insert(std::string::String::from("imprint"), values);
            }
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_imprint"), elements);
            }
        }
        if !self.image.is_empty() {
            let mut items = Vec::with_capacity(self.image.len());
            for item in &self.image {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("image"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.scoring {
            object.insert(
                std::string::String::from("scoring"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        Ok(object)
    }

    fn from_json(
        object: &super::super::codec::Object,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        let mut raw_id: Option<&super::super::codec::Value> = None;
        let mut raw_extension: Option<&super::super::codec::Value> = None;
        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
        let mut raw_height: Option<&super::super::codec::Value> = None;
        let mut raw_width: Option<&super::super::codec::Value> = None;
        let mut raw_depth: Option<&super::super::codec::Value> = None;
        let mut raw_weight: Option<&super::super::codec::Value> = None;
        let mut raw_nominal_volume: Option<&super::super::codec::Value> = None;
        let mut raw_external_diameter: Option<&super::super::codec::Value> = None;
        let mut raw_shape: Option<&super::super::codec::Value> = None;
        let mut raw_shape_element: Option<&super::super::codec::Value> = None;
        let mut raw_color: Option<&super::super::codec::Value> = None;
        let mut raw_color_element: Option<&super::super::codec::Value> = None;
        let mut raw_imprint: Option<&super::super::codec::Value> = None;
        let mut raw_imprint_element: Option<&super::super::codec::Value> = None;
        let mut raw_image: Option<&super::super::codec::Value> = None;
        let mut raw_scoring: Option<&super::super::codec::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => {
                    raw_id = Some(value);
                }
                "extension" => {
                    raw_extension = Some(value);
                }
                "modifierExtension" => {
                    raw_modifier_extension = Some(value);
                }
                "height" => {
                    raw_height = Some(value);
                }
                "width" => {
                    raw_width = Some(value);
                }
                "depth" => {
                    raw_depth = Some(value);
                }
                "weight" => {
                    raw_weight = Some(value);
                }
                "nominalVolume" => {
                    raw_nominal_volume = Some(value);
                }
                "externalDiameter" => {
                    raw_external_diameter = Some(value);
                }
                "shape" => {
                    raw_shape = Some(value);
                }
                "_shape" => {
                    raw_shape_element = Some(value);
                }
                "color" => {
                    raw_color = Some(value);
                }
                "_color" => {
                    raw_color_element = Some(value);
                }
                "imprint" => {
                    raw_imprint = Some(value);
                }
                "_imprint" => {
                    raw_imprint_element = Some(value);
                }
                "image" => {
                    raw_image = Some(value);
                }
                "scoring" => {
                    raw_scoring = Some(value);
                }
                other => {
                    return path.with(other, |path| {
                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
                    });
                }
            }
        }
        let field_id = raw_id
            .map(|value| {
                path.with("id", |path| {
                    let value = super::super::codec::expect_single(value, path)?;
                    super::primitives::checked_string(
                        super::super::codec::expect_string(value, path)?,
                        path,
                    )
                })
            })
            .transpose()?;
        let mut field_extension = Vec::new();
        if let Some(raw) = raw_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_extension.push(path.with_index("extension", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let mut field_modifier_extension = Vec::new();
        if let Some(raw) = raw_modifier_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_modifier_extension.push(path.with_index(
                    "modifierExtension",
                    index,
                    |path| {
                        super::super::codec::Json::from_json(
                            super::super::codec::expect_object(value, path)?,
                            path,
                        )
                    },
                )?);
            }
        }
        let field_height = raw_height
            .map(|value| {
                path.with("height", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_width = raw_width
            .map(|value| {
                path.with("width", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_depth = raw_depth
            .map(|value| {
                path.with("depth", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_weight = raw_weight
            .map(|value| {
                path.with("weight", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_nominal_volume = raw_nominal_volume
            .map(|value| {
                path.with("nominalVolume", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_external_diameter = raw_external_diameter
            .map(|value| {
                path.with("externalDiameter", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_shape = match (raw_shape, raw_shape_element) {
            (None, None) => None,
            (value, element) => Some(path.with("shape", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let mut field_color = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_color, raw_color_element, path)?
                .into_iter()
                .enumerate()
        {
            field_color.push(path.with_index("color", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let mut field_imprint = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_imprint, raw_imprint_element, path)?
                .into_iter()
                .enumerate()
        {
            field_imprint.push(path.with_index("imprint", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let mut field_image = Vec::new();
        if let Some(raw) = raw_image {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_image.push(path.with_index("image", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_scoring = raw_scoring
            .map(|value| {
                path.with("scoring", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        Ok(Self {
            id: field_id,
            extension: field_extension,
            modifier_extension: field_modifier_extension,
            height: field_height,
            width: field_width,
            depth: field_depth,
            weight: field_weight,
            nominal_volume: field_nominal_volume,
            external_diameter: field_external_diameter,
            shape: field_shape,
            color: field_color,
            imprint: field_imprint,
            image: field_image,
            scoring: field_scoring,
        })
    }
}

impl serde::Serialize for ProdCharacteristic {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        super::super::codec::element_list_entry(&mut map, "_color", &self.color)?;
        super::super::codec::element_list_entry(&mut map, "_imprint", &self.imprint)?;
        if let Some(item) = &self.shape {
            super::super::codec::element_entry(&mut map, "_shape", item)?;
        }
        super::super::codec::value_list_entry(&mut map, "color", &self.color)?;
        if let Some(item) = &self.depth {
            serde::ser::SerializeMap::serialize_entry(&mut map, "depth", item)?;
        }
        if !self.extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
        }
        if let Some(item) = &self.external_diameter {
            serde::ser::SerializeMap::serialize_entry(&mut map, "externalDiameter", item)?;
        }
        if let Some(item) = &self.height {
            serde::ser::SerializeMap::serialize_entry(&mut map, "height", item)?;
        }
        if let Some(v) = &self.id {
            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
        }
        if !self.image.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "image", &self.image)?;
        }
        super::super::codec::value_list_entry(&mut map, "imprint", &self.imprint)?;
        if !self.modifier_extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "modifierExtension",
                &self.modifier_extension,
            )?;
        }
        if let Some(item) = &self.nominal_volume {
            serde::ser::SerializeMap::serialize_entry(&mut map, "nominalVolume", item)?;
        }
        if let Some(item) = &self.scoring {
            serde::ser::SerializeMap::serialize_entry(&mut map, "scoring", item)?;
        }
        if let Some(item) = &self.shape {
            super::super::codec::value_entry(&mut map, "shape", item)?;
        }
        if let Some(item) = &self.weight {
            serde::ser::SerializeMap::serialize_entry(&mut map, "weight", item)?;
        }
        if let Some(item) = &self.width {
            serde::ser::SerializeMap::serialize_entry(&mut map, "width", item)?;
        }
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for ProdCharacteristic {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("ProdCharacteristic");
        let object =
            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
    }
}