fhir-types 0.1.92

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
// @generated by fhir-codegen from hl7.fhir.r5.core 5.0.0. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
//! Related artifacts for a knowledge resource

/// Related artifacts for a knowledge resource
///
/// Related artifacts such as additional documentation, justification, or
/// bibliographic references.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct RelatedArtifact {
    /// 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
    /// managable, 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>,
    /// documentation | justification | citation | predecessor | successor |
    /// derived-from | depends-on | composed-of | part-of | amends | amended-with |
    /// appends | appended-with | cites | cited-by | comments-on | comment-in |
    /// contains | contained-in | corrects | correction-in | replaces |
    /// replaced-with | retracts | retracted-by | signs | similar-to | supports |
    /// supported-with | transforms | transformed-into | transformed-with |
    /// documents | specification-of | created-with | cite-as
    ///
    /// The type of relationship to the related artifact.
    pub r#type: super::primitives::Code,
    /// Additional classifiers
    ///
    /// Provides additional classifiers of the related artifact.
    pub classifier: Vec<super::codeable_concept::CodeableConcept>,
    /// Short label
    ///
    /// A short label that can be used to reference the citation from elsewhere in
    /// the containing artifact, such as a footnote index.
    pub label: Option<super::primitives::String>,
    /// Brief description of the related artifact
    ///
    /// A brief description of the document or knowledge resource being referenced,
    /// suitable for display to a consumer.
    pub display: Option<super::primitives::String>,
    /// Bibliographic citation for the artifact
    ///
    /// A bibliographic citation for the related artifact. This text SHOULD be
    /// formatted according to an accepted citation format.
    pub citation: Option<super::primitives::Markdown>,
    /// What document is being referenced
    ///
    /// The document being referenced, represented as an attachment. This is
    /// exclusive with the resource element.
    pub document: Option<super::attachment::Attachment>,
    /// What artifact is being referenced
    ///
    /// The related artifact, such as a library, value set, profile, or other
    /// knowledge resource.
    pub resource: Option<super::primitives::Canonical>,
    /// What artifact, if not a conformance resource
    ///
    /// The related artifact, if the artifact is not a canonical resource, or a
    /// resource reference to a canonical resource.
    pub resource_reference: Option<super::reference::Reference>,
    /// draft | active | retired | unknown
    ///
    /// The publication status of the artifact being referred to.
    pub publication_status: Option<super::primitives::Code>,
    /// Date of publication of the artifact being referred to
    ///
    /// The date of publication of the artifact being referred to.
    pub publication_date: Option<super::primitives::Date>,
}

impl super::super::codec::Json for RelatedArtifact {
    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 let Some(v) = super::super::codec::Primitive::value_json(&self.r#type)? {
            object.insert(std::string::String::from("type"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.r#type)? {
            object.insert(std::string::String::from("_type"), e);
        }
        if !self.classifier.is_empty() {
            let mut items = Vec::with_capacity(self.classifier.len());
            for item in &self.classifier {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("classifier"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.label {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("label"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_label"), e);
            }
        }
        if let Some(item) = &self.display {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("display"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_display"), e);
            }
        }
        if let Some(item) = &self.citation {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("citation"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_citation"), e);
            }
        }
        if let Some(item) = &self.document {
            object.insert(
                std::string::String::from("document"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.resource {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("resource"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_resource"), e);
            }
        }
        if let Some(item) = &self.resource_reference {
            object.insert(
                std::string::String::from("resourceReference"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.publication_status {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("publicationStatus"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_publicationStatus"), e);
            }
        }
        if let Some(item) = &self.publication_date {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("publicationDate"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_publicationDate"), e);
            }
        }
        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_type: Option<&super::super::codec::Value> = None;
        let mut raw_type_element: Option<&super::super::codec::Value> = None;
        let mut raw_classifier: Option<&super::super::codec::Value> = None;
        let mut raw_label: Option<&super::super::codec::Value> = None;
        let mut raw_label_element: Option<&super::super::codec::Value> = None;
        let mut raw_display: Option<&super::super::codec::Value> = None;
        let mut raw_display_element: Option<&super::super::codec::Value> = None;
        let mut raw_citation: Option<&super::super::codec::Value> = None;
        let mut raw_citation_element: Option<&super::super::codec::Value> = None;
        let mut raw_document: Option<&super::super::codec::Value> = None;
        let mut raw_resource: Option<&super::super::codec::Value> = None;
        let mut raw_resource_element: Option<&super::super::codec::Value> = None;
        let mut raw_resource_reference: Option<&super::super::codec::Value> = None;
        let mut raw_publication_status: Option<&super::super::codec::Value> = None;
        let mut raw_publication_status_element: Option<&super::super::codec::Value> = None;
        let mut raw_publication_date: Option<&super::super::codec::Value> = None;
        let mut raw_publication_date_element: 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),
                "type" => raw_type = Some(value),
                "_type" => raw_type_element = Some(value),
                "classifier" => raw_classifier = Some(value),
                "label" => raw_label = Some(value),
                "_label" => raw_label_element = Some(value),
                "display" => raw_display = Some(value),
                "_display" => raw_display_element = Some(value),
                "citation" => raw_citation = Some(value),
                "_citation" => raw_citation_element = Some(value),
                "document" => raw_document = Some(value),
                "resource" => raw_resource = Some(value),
                "_resource" => raw_resource_element = Some(value),
                "resourceReference" => raw_resource_reference = Some(value),
                "publicationStatus" => raw_publication_status = Some(value),
                "_publicationStatus" => raw_publication_status_element = Some(value),
                "publicationDate" => raw_publication_date = Some(value),
                "_publicationDate" => raw_publication_date_element = 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::super::codec::expect_string(value, 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 field_type = path.with("type", |path| {
            super::super::codec::Primitive::from_json_parts(raw_type, raw_type_element, path)
        })?;
        let mut field_classifier = Vec::new();
        if let Some(raw) = raw_classifier {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_classifier.push(path.with_index("classifier", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_label = match (raw_label, raw_label_element) {
            (None, None) => None,
            (value, element) => Some(path.with("label", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_display = match (raw_display, raw_display_element) {
            (None, None) => None,
            (value, element) => Some(path.with("display", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_citation = match (raw_citation, raw_citation_element) {
            (None, None) => None,
            (value, element) => Some(path.with("citation", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_document = raw_document
            .map(|value| {
                path.with("document", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_resource = match (raw_resource, raw_resource_element) {
            (None, None) => None,
            (value, element) => Some(path.with("resource", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_resource_reference = raw_resource_reference
            .map(|value| {
                path.with("resourceReference", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_publication_status =
            match (raw_publication_status, raw_publication_status_element) {
                (None, None) => None,
                (value, element) => Some(path.with("publicationStatus", |path| {
                    super::super::codec::Primitive::from_json_parts(value, element, path)
                })?),
            };
        let field_publication_date = match (raw_publication_date, raw_publication_date_element) {
            (None, None) => None,
            (value, element) => Some(path.with("publicationDate", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        Ok(Self {
            id: field_id,
            extension: field_extension,
            r#type: field_type,
            classifier: field_classifier,
            label: field_label,
            display: field_display,
            citation: field_citation,
            document: field_document,
            resource: field_resource,
            resource_reference: field_resource_reference,
            publication_status: field_publication_status,
            publication_date: field_publication_date,
        })
    }
}

impl serde::Serialize for RelatedArtifact {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        if let Some(item) = &self.citation {
            super::super::codec::element_entry(&mut map, "_citation", item)?;
        }
        if let Some(item) = &self.display {
            super::super::codec::element_entry(&mut map, "_display", item)?;
        }
        if let Some(item) = &self.label {
            super::super::codec::element_entry(&mut map, "_label", item)?;
        }
        if let Some(item) = &self.publication_date {
            super::super::codec::element_entry(&mut map, "_publicationDate", item)?;
        }
        if let Some(item) = &self.publication_status {
            super::super::codec::element_entry(&mut map, "_publicationStatus", item)?;
        }
        if let Some(item) = &self.resource {
            super::super::codec::element_entry(&mut map, "_resource", item)?;
        }
        super::super::codec::element_entry(&mut map, "_type", &self.r#type)?;
        if let Some(item) = &self.citation {
            super::super::codec::value_entry(&mut map, "citation", item)?;
        }
        if !self.classifier.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "classifier", &self.classifier)?;
        }
        if let Some(item) = &self.display {
            super::super::codec::value_entry(&mut map, "display", item)?;
        }
        if let Some(item) = &self.document {
            serde::ser::SerializeMap::serialize_entry(&mut map, "document", item)?;
        }
        if !self.extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
        }
        if let Some(v) = &self.id {
            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
        }
        if let Some(item) = &self.label {
            super::super::codec::value_entry(&mut map, "label", item)?;
        }
        if let Some(item) = &self.publication_date {
            super::super::codec::value_entry(&mut map, "publicationDate", item)?;
        }
        if let Some(item) = &self.publication_status {
            super::super::codec::value_entry(&mut map, "publicationStatus", item)?;
        }
        if let Some(item) = &self.resource {
            super::super::codec::value_entry(&mut map, "resource", item)?;
        }
        if let Some(item) = &self.resource_reference {
            serde::ser::SerializeMap::serialize_entry(&mut map, "resourceReference", item)?;
        }
        super::super::codec::value_entry(&mut map, "type", &self.r#type)?;
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for RelatedArtifact {
    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("RelatedArtifact");
        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)
    }
}