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

/// A material substance originating from a biological entity intended to be transplanted or infused into another (possibly the same) biological entity.
///
/// FHIR path: `BiologicallyDerivedProduct`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct BiologicallyDerivedProduct {
    /// `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..*): External ids for this item
    pub identifier: Vec<Identifier>,
    /// `productCategory` (0..1): organ | tissue | fluid | cells | biologicalAgent
    pub product_category: Option<Primitive<String>>,
    /// `productCode` (0..1): What this biologically derived product is
    pub product_code: Option<CodeableConcept>,
    /// `status` (0..1): available | unavailable
    pub status: Option<Primitive<String>>,
    /// `request` (0..*): Procedure request
    pub request: Vec<Reference>,
    /// `quantity` (0..1): The amount of this biologically derived product
    pub quantity: Option<Primitive<i32>>,
    /// `parent` (0..*): BiologicallyDerivedProduct parent
    pub parent: Vec<Reference>,
    /// `collection` (0..1): How this product was collected
    pub collection: Option<BiologicallyDerivedProductCollection>,
    /// `processing` (0..*): Any processing of the product during collection
    pub processing: Vec<BiologicallyDerivedProductProcessing>,
    /// `manipulation` (0..1): Any manipulation of product post-collection
    pub manipulation: Option<BiologicallyDerivedProductManipulation>,
    /// `storage` (0..*): Product storage
    pub storage: Vec<BiologicallyDerivedProductStorage>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "BiologicallyDerivedProduct");
        let r = BiologicallyDerivedProduct {
            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"),
            product_category: o.prim(d, "productCategory", Kind::Code),
            product_code: o.one(d, "productCode"),
            status: o.prim(d, "status", Kind::Code),
            request: o.list(d, "request"),
            quantity: o.prim(d, "quantity", Kind::Integer),
            parent: o.list(d, "parent"),
            collection: o.one(d, "collection"),
            processing: o.list(d, "processing"),
            manipulation: o.one(d, "manipulation"),
            storage: o.list(d, "storage"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw(
            "resourceType",
            Json::String("BiologicallyDerivedProduct".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.prim("productCategory", &self.product_category);
        w.one("productCode", &self.product_code);
        w.prim("status", &self.status);
        w.list("request", &self.request);
        w.prim("quantity", &self.quantity);
        w.list("parent", &self.parent);
        w.one("collection", &self.collection);
        w.list("processing", &self.processing);
        w.one("manipulation", &self.manipulation);
        w.list("storage", &self.storage);
        w.finish()
    }
}

/// How this product was collected
///
/// FHIR path: `BiologicallyDerivedProduct.collection`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct BiologicallyDerivedProductCollection {
    /// `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>,
    /// `collector` (0..1): Individual performing collection
    pub collector: Option<Reference>,
    /// `source` (0..1): Who is product from
    pub source: Option<Reference>,
    /// `collected[x]` (0..1): Time of product collection
    pub collected: Option<BiologicallyDerivedProductCollectionCollected>,
}

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

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

/// Any processing of the product during collection
///
/// FHIR path: `BiologicallyDerivedProduct.processing`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct BiologicallyDerivedProductProcessing {
    /// `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>,
    /// `description` (0..1): Description of of processing
    pub description: Option<Primitive<String>>,
    /// `procedure` (0..1): Procesing code
    pub procedure: Option<CodeableConcept>,
    /// `additive` (0..1): Substance added during processing
    pub additive: Option<Reference>,
    /// `time[x]` (0..1): Time of processing
    pub time: Option<BiologicallyDerivedProductProcessingTime>,
}

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

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

/// Any manipulation of product post-collection
///
/// FHIR path: `BiologicallyDerivedProduct.manipulation`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct BiologicallyDerivedProductManipulation {
    /// `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>,
    /// `description` (0..1): Description of manipulation
    pub description: Option<Primitive<String>>,
    /// `time[x]` (0..1): Time of manipulation
    pub time: Option<BiologicallyDerivedProductManipulationTime>,
}

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

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

/// Product storage
///
/// FHIR path: `BiologicallyDerivedProduct.storage`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct BiologicallyDerivedProductStorage {
    /// `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>,
    /// `description` (0..1): Description of storage
    pub description: Option<Primitive<String>>,
    /// `temperature` (0..1): Storage temperature
    pub temperature: Option<Primitive<Decimal>>,
    /// `scale` (0..1): farenheit | celsius | kelvin
    pub scale: Option<Primitive<String>>,
    /// `duration` (0..1): Storage timeperiod
    pub duration: Option<Period>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = BiologicallyDerivedProductStorage {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            description: o.prim(d, "description", Kind::String),
            temperature: o.prim(d, "temperature", Kind::Decimal),
            scale: o.prim(d, "scale", Kind::Code),
            duration: o.one(d, "duration"),
        };
        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("description", &self.description);
        w.prim("temperature", &self.temperature);
        w.prim("scale", &self.scale);
        w.one("duration", &self.duration);
        w.finish()
    }
}

/// The types `BiologicallyDerivedProduct.collection.collected[x]` allows.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq)]
pub enum BiologicallyDerivedProductCollectionCollected {
    /// `dateTime`
    DateTime(Primitive<String>),
    /// `Period`
    Period(Period),
}

#[cfg(feature = "base")]
impl Choice for BiologicallyDerivedProductCollectionCollected {
    const TYPES: &'static [&'static str] = &["dateTime", "Period"];

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

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

/// The types `BiologicallyDerivedProduct.processing.time[x]` allows.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq)]
pub enum BiologicallyDerivedProductProcessingTime {
    /// `dateTime`
    DateTime(Primitive<String>),
    /// `Period`
    Period(Period),
}

#[cfg(feature = "base")]
impl Choice for BiologicallyDerivedProductProcessingTime {
    const TYPES: &'static [&'static str] = &["dateTime", "Period"];

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

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

/// The types `BiologicallyDerivedProduct.manipulation.time[x]` allows.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq)]
pub enum BiologicallyDerivedProductManipulationTime {
    /// `dateTime`
    DateTime(Primitive<String>),
    /// `Period`
    Period(Period),
}

#[cfg(feature = "base")]
impl Choice for BiologicallyDerivedProductManipulationTime {
    const TYPES: &'static [&'static str] = &["dateTime", "Period"];

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

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