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
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
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `ConceptMap` 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 statement of relationships from one set of concepts to one or more other concepts - either concepts in code systems, or data element/data element concepts, or classes in class models.
///
/// FHIR path: `ConceptMap`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConceptMap {
    /// `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>,
    /// `url` (0..1): Canonical identifier for this concept map, represented as a URI (globally unique)
    pub url: Option<Primitive<String>>,
    /// `identifier` (0..1): Additional identifier for the concept map
    pub identifier: Option<Identifier>,
    /// `version` (0..1): Business version of the concept map
    pub version: Option<Primitive<String>>,
    /// `name` (0..1): Name for this concept map (computer friendly)
    pub name: Option<Primitive<String>>,
    /// `title` (0..1): Name for this concept map (human friendly)
    pub title: Option<Primitive<String>>,
    /// `status` (1..1): draft | active | retired | unknown
    pub status: Option<Primitive<String>>,
    /// `experimental` (0..1): For testing purposes, not real usage
    pub experimental: Option<Primitive<bool>>,
    /// `date` (0..1): Date last changed
    pub date: Option<Primitive<String>>,
    /// `publisher` (0..1): Name of the publisher (organization or individual)
    pub publisher: Option<Primitive<String>>,
    /// `contact` (0..*): Contact details for the publisher
    pub contact: Vec<ContactDetail>,
    /// `description` (0..1): Natural language description of the concept map
    pub description: Option<Primitive<String>>,
    /// `useContext` (0..*): The context that the content is intended to support
    pub use_context: Vec<UsageContext>,
    /// `jurisdiction` (0..*): Intended jurisdiction for concept map (if applicable)
    pub jurisdiction: Vec<CodeableConcept>,
    /// `purpose` (0..1): Why this concept map is defined
    pub purpose: Option<Primitive<String>>,
    /// `copyright` (0..1): Use and/or publishing restrictions
    pub copyright: Option<Primitive<String>>,
    /// `source[x]` (0..1): The source value set that contains the concepts that are being mapped
    pub source: Option<ConceptMapSource>,
    /// `target[x]` (0..1): The target value set which provides context for the mappings
    pub target: Option<ConceptMapTarget>,
    /// `group` (0..*): Same source and target systems
    pub group: Vec<ConceptMapGroup>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "ConceptMap");
        let r = ConceptMap {
            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"),
            url: o.prim(d, "url", Kind::Uri),
            identifier: o.one(d, "identifier"),
            version: o.prim(d, "version", Kind::String),
            name: o.prim(d, "name", Kind::String),
            title: o.prim(d, "title", Kind::String),
            status: o.prim(d, "status", Kind::Code),
            experimental: o.prim(d, "experimental", Kind::Boolean),
            date: o.prim(d, "date", Kind::DateTime),
            publisher: o.prim(d, "publisher", Kind::String),
            contact: o.list(d, "contact"),
            description: o.prim(d, "description", Kind::Markdown),
            use_context: o.list(d, "useContext"),
            jurisdiction: o.list(d, "jurisdiction"),
            purpose: o.prim(d, "purpose", Kind::Markdown),
            copyright: o.prim(d, "copyright", Kind::Markdown),
            source: o.choice(d, "source"),
            target: o.choice(d, "target"),
            group: o.list(d, "group"),
        };
        required(d, "status", &r.status);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("ConceptMap".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.prim("url", &self.url);
        w.one("identifier", &self.identifier);
        w.prim("version", &self.version);
        w.prim("name", &self.name);
        w.prim("title", &self.title);
        w.prim("status", &self.status);
        w.prim("experimental", &self.experimental);
        w.prim("date", &self.date);
        w.prim("publisher", &self.publisher);
        w.list("contact", &self.contact);
        w.prim("description", &self.description);
        w.list("useContext", &self.use_context);
        w.list("jurisdiction", &self.jurisdiction);
        w.prim("purpose", &self.purpose);
        w.prim("copyright", &self.copyright);
        w.choice("source", &self.source);
        w.choice("target", &self.target);
        w.list("group", &self.group);
        w.finish()
    }
}

/// Same source and target systems
///
/// FHIR path: `ConceptMap.group`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConceptMapGroup {
    /// `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>,
    /// `source` (0..1): Source system where concepts to be mapped are defined
    pub source: Option<Primitive<String>>,
    /// `sourceVersion` (0..1): Specific version of the code system
    pub source_version: Option<Primitive<String>>,
    /// `target` (0..1): Target system that the concepts are to be mapped to
    pub target: Option<Primitive<String>>,
    /// `targetVersion` (0..1): Specific version of the code system
    pub target_version: Option<Primitive<String>>,
    /// `element` (1..*): Mappings for a concept from the source set
    pub element: Vec<ConceptMapGroupElement>,
    /// `unmapped` (0..1): What to do when there is no mapping for the source concept
    pub unmapped: Option<ConceptMapGroupUnmapped>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConceptMapGroup {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            source: o.prim(d, "source", Kind::Uri),
            source_version: o.prim(d, "sourceVersion", Kind::String),
            target: o.prim(d, "target", Kind::Uri),
            target_version: o.prim(d, "targetVersion", Kind::String),
            element: o.list(d, "element"),
            unmapped: o.one(d, "unmapped"),
        };
        required_list(d, "element", &r.element, 1);
        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("source", &self.source);
        w.prim("sourceVersion", &self.source_version);
        w.prim("target", &self.target);
        w.prim("targetVersion", &self.target_version);
        w.list("element", &self.element);
        w.one("unmapped", &self.unmapped);
        w.finish()
    }
}

/// Mappings for a concept from the source set
///
/// FHIR path: `ConceptMap.group.element`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConceptMapGroupElement {
    /// `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>,
    /// `code` (0..1): Identifies element being mapped
    pub code: Option<Primitive<String>>,
    /// `display` (0..1): Display for the code
    pub display: Option<Primitive<String>>,
    /// `target` (0..*): Concept in target system for element
    pub target: Vec<ConceptMapGroupElementTarget>,
}

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

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

/// Concept in target system for element
///
/// FHIR path: `ConceptMap.group.element.target`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConceptMapGroupElementTarget {
    /// `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>,
    /// `code` (0..1): Code that identifies the target element
    pub code: Option<Primitive<String>>,
    /// `display` (0..1): Display for the code
    pub display: Option<Primitive<String>>,
    /// `equivalence` (1..1): relatedto | equivalent | equal | wider | subsumes | narrower | specializes | inexact | unmatched | disjoint
    pub equivalence: Option<Primitive<String>>,
    /// `comment` (0..1): Description of status/issues in mapping
    pub comment: Option<Primitive<String>>,
    /// `dependsOn` (0..*): Other elements required for this mapping (from context)
    pub depends_on: Vec<ConceptMapGroupElementTargetDependsOn>,
    /// `product` (0..*): Other concepts that this mapping also produces
    pub product: Vec<ConceptMapGroupElementTargetDependsOn>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConceptMapGroupElementTarget {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            code: o.prim(d, "code", Kind::Code),
            display: o.prim(d, "display", Kind::String),
            equivalence: o.prim(d, "equivalence", Kind::Code),
            comment: o.prim(d, "comment", Kind::String),
            depends_on: o.list(d, "dependsOn"),
            product: o.list(d, "product"),
        };
        required(d, "equivalence", &r.equivalence);
        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("code", &self.code);
        w.prim("display", &self.display);
        w.prim("equivalence", &self.equivalence);
        w.prim("comment", &self.comment);
        w.list("dependsOn", &self.depends_on);
        w.list("product", &self.product);
        w.finish()
    }
}

/// Other elements required for this mapping (from context)
///
/// FHIR path: `ConceptMap.group.element.target.dependsOn`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConceptMapGroupElementTargetDependsOn {
    /// `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>,
    /// `property` (1..1): Reference to property mapping depends on
    pub property: Option<Primitive<String>>,
    /// `system` (0..1): Code System (if necessary)
    pub system: Option<Primitive<String>>,
    /// `value` (1..1): Value of the referenced element
    pub value: Option<Primitive<String>>,
    /// `display` (0..1): Display for the code (if value is a code)
    pub display: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConceptMapGroupElementTargetDependsOn {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            property: o.prim(d, "property", Kind::Uri),
            system: o.prim(d, "system", Kind::Canonical),
            value: o.prim(d, "value", Kind::String),
            display: o.prim(d, "display", Kind::String),
        };
        required(d, "property", &r.property);
        required(d, "value", &r.value);
        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("property", &self.property);
        w.prim("system", &self.system);
        w.prim("value", &self.value);
        w.prim("display", &self.display);
        w.finish()
    }
}

/// What to do when there is no mapping for the source concept
///
/// FHIR path: `ConceptMap.group.unmapped`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ConceptMapGroupUnmapped {
    /// `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>,
    /// `mode` (1..1): provided | fixed | other-map
    pub mode: Option<Primitive<String>>,
    /// `code` (0..1): Fixed code when mode = fixed
    pub code: Option<Primitive<String>>,
    /// `display` (0..1): Display for the code
    pub display: Option<Primitive<String>>,
    /// `url` (0..1): canonical reference to an additional ConceptMap to use for mapping if the source concept is unmapped
    pub url: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ConceptMapGroupUnmapped {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            mode: o.prim(d, "mode", Kind::Code),
            code: o.prim(d, "code", Kind::Code),
            display: o.prim(d, "display", Kind::String),
            url: o.prim(d, "url", Kind::Canonical),
        };
        required(d, "mode", &r.mode);
        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("mode", &self.mode);
        w.prim("code", &self.code);
        w.prim("display", &self.display);
        w.prim("url", &self.url);
        w.finish()
    }
}

/// The types `ConceptMap.source[x]` allows.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq)]
pub enum ConceptMapSource {
    /// `uri`
    Uri(Primitive<String>),
    /// `canonical`
    Canonical(Primitive<String>),
}

#[cfg(feature = "foundation")]
impl Choice for ConceptMapSource {
    const TYPES: &'static [&'static str] = &["uri", "canonical"];

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Uri(v) => w.prim_value(&choice_key(base, "uri"), v),
            Self::Canonical(v) => w.prim_value(&choice_key(base, "canonical"), v),
        }
    }
}

/// The types `ConceptMap.target[x]` allows.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq)]
pub enum ConceptMapTarget {
    /// `uri`
    Uri(Primitive<String>),
    /// `canonical`
    Canonical(Primitive<String>),
}

#[cfg(feature = "foundation")]
impl Choice for ConceptMapTarget {
    const TYPES: &'static [&'static str] = &["uri", "canonical"];

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Uri(v) => w.prim_value(&choice_key(base, "uri"), v),
            Self::Canonical(v) => w.prim_value(&choice_key(base, "canonical"), v),
        }
    }
}