fhir-types 0.1.19

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
// @generated by fhir-codegen from hl7.fhir.r6.core 6.0.0-ballot5. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
//! Content in a format defined elsewhere

/// Content in a format defined elsewhere
///
/// For referring to data content defined in other formats.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Attachment {
    /// 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>,
    /// Mime type of the content, with charset etc.
    ///
    /// Identifies the type of the data in the attachment and allows a method to be
    /// chosen to interpret or render the data. Includes mime type parameters such
    /// as charset where appropriate.
    pub content_type: Option<super::primitives::Code>,
    /// Human language of the content (BCP-47)
    ///
    /// The human language of the content. The value can be any valid value
    /// according to BCP 47.
    pub language: Option<super::primitives::Code>,
    /// Data inline, base64ed
    ///
    /// The actual data of the attachment - a sequence of bytes, base64 encoded.
    pub data: Option<super::primitives::Base64Binary>,
    /// Uri where the data can be found
    ///
    /// A location where the data can be accessed.
    pub url: Option<super::primitives::Url>,
    /// Number of bytes of content (if url provided)
    ///
    /// The number of bytes of data that make up this attachment (before base64
    /// encoding, if that is done).
    pub size: Option<super::primitives::Integer64>,
    /// Hash of the data (sha-1, base64ed)
    ///
    /// The calculated hash of the data using SHA-1. Represented using base64.
    pub hash: Option<super::primitives::Base64Binary>,
    /// Label to display in place of the data
    ///
    /// A label or set of text to display in place of the data.
    pub title: Option<super::primitives::String>,
    /// Date attachment was first created
    ///
    /// The date that the attachment was first created.
    pub creation: Option<super::primitives::DateTime>,
    /// Height of the image in pixels (photo/video).
    pub height: Option<super::primitives::PositiveInt>,
    /// Width of the image in pixels (photo/video).
    pub width: Option<super::primitives::PositiveInt>,
    /// Number of frames if \> 1 (photo)
    ///
    /// The number of frames in a photo. This is used with a multi-page fax, or an
    /// imaging acquisition context that takes multiple slices in a single image, or
    /// an animated gif. If there is more than one frame, this SHALL have a value in
    /// order to alert interface software that a multi-frame capable rendering
    /// widget is required.
    pub frames: Option<super::primitives::PositiveInt>,
    /// Length in seconds (audio / video)
    ///
    /// The duration of the recording in seconds - for audio and video.
    pub duration: Option<super::primitives::Decimal>,
    /// Number of printed pages
    ///
    /// The number of pages when printed.
    pub pages: Option<super::primitives::PositiveInt>,
}

impl super::super::codec::Json for Attachment {
    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"),
                serde_json::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(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                serde_json::Value::Array(items),
            );
        }
        if let Some(item) = &self.content_type {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("contentType"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_contentType"), e);
            }
        }
        if let Some(item) = &self.language {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("language"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_language"), e);
            }
        }
        if let Some(item) = &self.data {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("data"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_data"), e);
            }
        }
        if let Some(item) = &self.url {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("url"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_url"), e);
            }
        }
        if let Some(item) = &self.size {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("size"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_size"), e);
            }
        }
        if let Some(item) = &self.hash {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("hash"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_hash"), e);
            }
        }
        if let Some(item) = &self.title {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("title"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_title"), e);
            }
        }
        if let Some(item) = &self.creation {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("creation"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_creation"), e);
            }
        }
        if let Some(item) = &self.height {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("height"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_height"), e);
            }
        }
        if let Some(item) = &self.width {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("width"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_width"), e);
            }
        }
        if let Some(item) = &self.frames {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("frames"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_frames"), e);
            }
        }
        if let Some(item) = &self.duration {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("duration"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_duration"), e);
            }
        }
        if let Some(item) = &self.pages {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("pages"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_pages"), 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<&serde_json::Value> = None;
        let mut raw_extension: Option<&serde_json::Value> = None;
        let mut raw_content_type: Option<&serde_json::Value> = None;
        let mut raw_content_type_element: Option<&serde_json::Value> = None;
        let mut raw_language: Option<&serde_json::Value> = None;
        let mut raw_language_element: Option<&serde_json::Value> = None;
        let mut raw_data: Option<&serde_json::Value> = None;
        let mut raw_data_element: Option<&serde_json::Value> = None;
        let mut raw_url: Option<&serde_json::Value> = None;
        let mut raw_url_element: Option<&serde_json::Value> = None;
        let mut raw_size: Option<&serde_json::Value> = None;
        let mut raw_size_element: Option<&serde_json::Value> = None;
        let mut raw_hash: Option<&serde_json::Value> = None;
        let mut raw_hash_element: Option<&serde_json::Value> = None;
        let mut raw_title: Option<&serde_json::Value> = None;
        let mut raw_title_element: Option<&serde_json::Value> = None;
        let mut raw_creation: Option<&serde_json::Value> = None;
        let mut raw_creation_element: Option<&serde_json::Value> = None;
        let mut raw_height: Option<&serde_json::Value> = None;
        let mut raw_height_element: Option<&serde_json::Value> = None;
        let mut raw_width: Option<&serde_json::Value> = None;
        let mut raw_width_element: Option<&serde_json::Value> = None;
        let mut raw_frames: Option<&serde_json::Value> = None;
        let mut raw_frames_element: Option<&serde_json::Value> = None;
        let mut raw_duration: Option<&serde_json::Value> = None;
        let mut raw_duration_element: Option<&serde_json::Value> = None;
        let mut raw_pages: Option<&serde_json::Value> = None;
        let mut raw_pages_element: Option<&serde_json::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => raw_id = Some(value),
                "extension" => raw_extension = Some(value),
                "contentType" => raw_content_type = Some(value),
                "_contentType" => raw_content_type_element = Some(value),
                "language" => raw_language = Some(value),
                "_language" => raw_language_element = Some(value),
                "data" => raw_data = Some(value),
                "_data" => raw_data_element = Some(value),
                "url" => raw_url = Some(value),
                "_url" => raw_url_element = Some(value),
                "size" => raw_size = Some(value),
                "_size" => raw_size_element = Some(value),
                "hash" => raw_hash = Some(value),
                "_hash" => raw_hash_element = Some(value),
                "title" => raw_title = Some(value),
                "_title" => raw_title_element = Some(value),
                "creation" => raw_creation = Some(value),
                "_creation" => raw_creation_element = Some(value),
                "height" => raw_height = Some(value),
                "_height" => raw_height_element = Some(value),
                "width" => raw_width = Some(value),
                "_width" => raw_width_element = Some(value),
                "frames" => raw_frames = Some(value),
                "_frames" => raw_frames_element = Some(value),
                "duration" => raw_duration = Some(value),
                "_duration" => raw_duration_element = Some(value),
                "pages" => raw_pages = Some(value),
                "_pages" => raw_pages_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_content_type = match (raw_content_type, raw_content_type_element) {
            (None, None) => None,
            (value, element) => Some(path.with("contentType", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_language = match (raw_language, raw_language_element) {
            (None, None) => None,
            (value, element) => Some(path.with("language", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_data = match (raw_data, raw_data_element) {
            (None, None) => None,
            (value, element) => Some(path.with("data", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_url = match (raw_url, raw_url_element) {
            (None, None) => None,
            (value, element) => Some(path.with("url", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_size = match (raw_size, raw_size_element) {
            (None, None) => None,
            (value, element) => Some(path.with("size", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_hash = match (raw_hash, raw_hash_element) {
            (None, None) => None,
            (value, element) => Some(path.with("hash", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_title = match (raw_title, raw_title_element) {
            (None, None) => None,
            (value, element) => Some(path.with("title", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_creation = match (raw_creation, raw_creation_element) {
            (None, None) => None,
            (value, element) => Some(path.with("creation", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_height = match (raw_height, raw_height_element) {
            (None, None) => None,
            (value, element) => Some(path.with("height", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_width = match (raw_width, raw_width_element) {
            (None, None) => None,
            (value, element) => Some(path.with("width", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_frames = match (raw_frames, raw_frames_element) {
            (None, None) => None,
            (value, element) => Some(path.with("frames", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_duration = match (raw_duration, raw_duration_element) {
            (None, None) => None,
            (value, element) => Some(path.with("duration", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_pages = match (raw_pages, raw_pages_element) {
            (None, None) => None,
            (value, element) => Some(path.with("pages", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        Ok(Self {
            id: field_id,
            extension: field_extension,
            content_type: field_content_type,
            language: field_language,
            data: field_data,
            url: field_url,
            size: field_size,
            hash: field_hash,
            title: field_title,
            creation: field_creation,
            height: field_height,
            width: field_width,
            frames: field_frames,
            duration: field_duration,
            pages: field_pages,
        })
    }
}

impl serde::Serialize for Attachment {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        super::super::codec::Json::to_json(self)
            .map_err(serde::ser::Error::custom)?
            .serialize(serializer)
    }
}

impl<'de> serde::Deserialize<'de> for Attachment {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = serde_json::Value::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("Attachment");
        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)
    }
}