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
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `Specimen` 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 sample to be used for analysis.
///
/// FHIR path: `Specimen`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Specimen {
    /// `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 Identifier
    pub identifier: Vec<Identifier>,
    /// `accessionIdentifier` (0..1): Identifier assigned by the lab
    pub accession_identifier: Option<Identifier>,
    /// `status` (0..1): available | unavailable | unsatisfactory | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `type` (0..1): Kind of material that forms the specimen
    pub type_: Option<CodeableConcept>,
    /// `subject` (0..1): Where the specimen came from. This may be from patient(s), from a location (e.g., the source of an environmental sample), or a sampling of a substance or a device
    pub subject: Option<Reference>,
    /// `receivedTime` (0..1): The time when specimen was received for processing
    pub received_time: Option<Primitive<String>>,
    /// `parent` (0..*): Specimen from which this specimen originated
    pub parent: Vec<Reference>,
    /// `request` (0..*): Why the specimen was collected
    pub request: Vec<Reference>,
    /// `collection` (0..1): Collection details
    pub collection: Option<SpecimenCollection>,
    /// `processing` (0..*): Processing and processing step details
    pub processing: Vec<SpecimenProcessing>,
    /// `container` (0..*): Direct container of specimen (tube/slide, etc.)
    pub container: Vec<SpecimenContainer>,
    /// `condition` (0..*): State of the specimen
    pub condition: Vec<CodeableConcept>,
    /// `note` (0..*): Comments
    pub note: Vec<Annotation>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Specimen");
        let r = Specimen {
            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"),
            accession_identifier: o.one(d, "accessionIdentifier"),
            status: o.prim(d, "status", Kind::Code),
            type_: o.one(d, "type"),
            subject: o.one(d, "subject"),
            received_time: o.prim(d, "receivedTime", Kind::DateTime),
            parent: o.list(d, "parent"),
            request: o.list(d, "request"),
            collection: o.one(d, "collection"),
            processing: o.list(d, "processing"),
            container: o.list(d, "container"),
            condition: o.list(d, "condition"),
            note: o.list(d, "note"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Specimen".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("accessionIdentifier", &self.accession_identifier);
        w.prim("status", &self.status);
        w.one("type", &self.type_);
        w.one("subject", &self.subject);
        w.prim("receivedTime", &self.received_time);
        w.list("parent", &self.parent);
        w.list("request", &self.request);
        w.one("collection", &self.collection);
        w.list("processing", &self.processing);
        w.list("container", &self.container);
        w.list("condition", &self.condition);
        w.list("note", &self.note);
        w.finish()
    }
}

/// Collection details
///
/// FHIR path: `Specimen.collection`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SpecimenCollection {
    /// `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): Who collected the specimen
    pub collector: Option<Reference>,
    /// `collected[x]` (0..1): Collection time
    pub collected: Option<SpecimenCollectionCollected>,
    /// `duration` (0..1): How long it took to collect specimen
    pub duration: Option<Duration>,
    /// `quantity` (0..1): The quantity of specimen collected
    pub quantity: Option<Quantity>,
    /// `method` (0..1): Technique used to perform collection
    pub method: Option<CodeableConcept>,
    /// `bodySite` (0..1): Anatomical collection site
    pub body_site: Option<CodeableConcept>,
    /// `fastingStatus[x]` (0..1): Whether or how long patient abstained from food and/or drink
    pub fasting_status: Option<SpecimenCollectionFastingStatus>,
}

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

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

/// Processing and processing step details
///
/// FHIR path: `Specimen.processing`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SpecimenProcessing {
    /// `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): Textual description of procedure
    pub description: Option<Primitive<String>>,
    /// `procedure` (0..1): Indicates the treatment step applied to the specimen
    pub procedure: Option<CodeableConcept>,
    /// `additive` (0..*): Material used in the processing step
    pub additive: Vec<Reference>,
    /// `time[x]` (0..1): Date and time of specimen processing
    pub time: Option<SpecimenProcessingTime>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = SpecimenProcessing {
            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.list(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.list("additive", &self.additive);
        w.choice("time", &self.time);
        w.finish()
    }
}

/// Direct container of specimen (tube/slide, etc.)
///
/// FHIR path: `Specimen.container`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct SpecimenContainer {
    /// `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..*): Id for the container
    pub identifier: Vec<Identifier>,
    /// `description` (0..1): Textual description of the container
    pub description: Option<Primitive<String>>,
    /// `type` (0..1): Kind of container directly associated with specimen
    pub type_: Option<CodeableConcept>,
    /// `capacity` (0..1): Container volume or size
    pub capacity: Option<Quantity>,
    /// `specimenQuantity` (0..1): Quantity of specimen within container
    pub specimen_quantity: Option<Quantity>,
    /// `additive[x]` (0..1): Additive associated with container
    pub additive: Option<SpecimenContainerAdditive>,
}

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

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

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

#[cfg(feature = "clinical")]
impl Choice for SpecimenCollectionCollected {
    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 `Specimen.collection.fastingStatus[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum SpecimenCollectionFastingStatus {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Duration`
    Duration(Duration),
}

#[cfg(feature = "clinical")]
impl Choice for SpecimenCollectionFastingStatus {
    const TYPES: &'static [&'static str] = &["CodeableConcept", "Duration"];

    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),
            "Duration" => o.one(d, key).map(Self::Duration),
            _ => None,
        }
    }

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

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

#[cfg(feature = "clinical")]
impl Choice for SpecimenProcessingTime {
    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 `Specimen.container.additive[x]` allows.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq)]
pub enum SpecimenContainerAdditive {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "clinical")]
impl Choice for SpecimenContainerAdditive {
    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),
        }
    }
}