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

/// This resource provides eligibility and plan details from the processing of an CoverageEligibilityRequest resource.
///
/// FHIR path: `CoverageEligibilityResponse`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageEligibilityResponse {
    /// `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..*): Business Identifier for coverage eligiblity request
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): active | cancelled | draft | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `purpose` (1..*): auth-requirements | benefits | discovery | validation
    pub purpose: Vec<Primitive<String>>,
    /// `patient` (1..1): Intended recipient of products and services
    pub patient: Option<Reference>,
    /// `serviced[x]` (0..1): Estimated date or dates of service
    pub serviced: Option<CoverageEligibilityResponseServiced>,
    /// `created` (1..1): Response creation date
    pub created: Option<Primitive<String>>,
    /// `requestor` (0..1): Party responsible for the request
    pub requestor: Option<Reference>,
    /// `request` (1..1): Eligibility request reference
    pub request: Option<Reference>,
    /// `outcome` (1..1): queued | complete | error | partial
    pub outcome: Option<Primitive<String>>,
    /// `disposition` (0..1): Disposition Message
    pub disposition: Option<Primitive<String>>,
    /// `insurer` (1..1): Coverage issuer
    pub insurer: Option<Reference>,
    /// `insurance` (0..*): Patient insurance information
    pub insurance: Vec<CoverageEligibilityResponseInsurance>,
    /// `preAuthRef` (0..1): Preauthorization reference
    pub pre_auth_ref: Option<Primitive<String>>,
    /// `form` (0..1): Printed form identifier
    pub form: Option<CodeableConcept>,
    /// `error` (0..*): Processing errors
    pub error: Vec<CoverageEligibilityResponseError>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "CoverageEligibilityResponse");
        let r = CoverageEligibilityResponse {
            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"),
            status: o.prim(d, "status", Kind::Code),
            purpose: o.prim_list(d, "purpose", Kind::Code),
            patient: o.one(d, "patient"),
            serviced: o.choice(d, "serviced"),
            created: o.prim(d, "created", Kind::DateTime),
            requestor: o.one(d, "requestor"),
            request: o.one(d, "request"),
            outcome: o.prim(d, "outcome", Kind::Code),
            disposition: o.prim(d, "disposition", Kind::String),
            insurer: o.one(d, "insurer"),
            insurance: o.list(d, "insurance"),
            pre_auth_ref: o.prim(d, "preAuthRef", Kind::String),
            form: o.one(d, "form"),
            error: o.list(d, "error"),
        };
        required(d, "status", &r.status);
        required_list(d, "purpose", &r.purpose, 1);
        required(d, "patient", &r.patient);
        required(d, "created", &r.created);
        required(d, "request", &r.request);
        required(d, "outcome", &r.outcome);
        required(d, "insurer", &r.insurer);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw(
            "resourceType",
            Json::String("CoverageEligibilityResponse".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("status", &self.status);
        w.prim_list("purpose", &self.purpose);
        w.one("patient", &self.patient);
        w.choice("serviced", &self.serviced);
        w.prim("created", &self.created);
        w.one("requestor", &self.requestor);
        w.one("request", &self.request);
        w.prim("outcome", &self.outcome);
        w.prim("disposition", &self.disposition);
        w.one("insurer", &self.insurer);
        w.list("insurance", &self.insurance);
        w.prim("preAuthRef", &self.pre_auth_ref);
        w.one("form", &self.form);
        w.list("error", &self.error);
        w.finish()
    }
}

/// Patient insurance information
///
/// FHIR path: `CoverageEligibilityResponse.insurance`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageEligibilityResponseInsurance {
    /// `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>,
    /// `coverage` (1..1): Insurance information
    pub coverage: Option<Reference>,
    /// `inforce` (0..1): Coverage inforce indicator
    pub inforce: Option<Primitive<bool>>,
    /// `benefitPeriod` (0..1): When the benefits are applicable
    pub benefit_period: Option<Period>,
    /// `item` (0..*): Benefits and authorization details
    pub item: Vec<CoverageEligibilityResponseInsuranceItem>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = CoverageEligibilityResponseInsurance {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            coverage: o.one(d, "coverage"),
            inforce: o.prim(d, "inforce", Kind::Boolean),
            benefit_period: o.one(d, "benefitPeriod"),
            item: o.list(d, "item"),
        };
        required(d, "coverage", &r.coverage);
        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("coverage", &self.coverage);
        w.prim("inforce", &self.inforce);
        w.one("benefitPeriod", &self.benefit_period);
        w.list("item", &self.item);
        w.finish()
    }
}

/// Benefits and authorization details
///
/// FHIR path: `CoverageEligibilityResponse.insurance.item`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageEligibilityResponseInsuranceItem {
    /// `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>,
    /// `category` (0..1): Benefit classification
    pub category: Option<CodeableConcept>,
    /// `productOrService` (0..1): Billing, service, product, or drug code
    pub product_or_service: Option<CodeableConcept>,
    /// `modifier` (0..*): Product or service billing modifiers
    pub modifier: Vec<CodeableConcept>,
    /// `provider` (0..1): Performing practitioner
    pub provider: Option<Reference>,
    /// `excluded` (0..1): Excluded from the plan
    pub excluded: Option<Primitive<bool>>,
    /// `name` (0..1): Short name for the benefit
    pub name: Option<Primitive<String>>,
    /// `description` (0..1): Description of the benefit or services covered
    pub description: Option<Primitive<String>>,
    /// `network` (0..1): In or out of network
    pub network: Option<CodeableConcept>,
    /// `unit` (0..1): Individual or family
    pub unit: Option<CodeableConcept>,
    /// `term` (0..1): Annual or lifetime
    pub term: Option<CodeableConcept>,
    /// `benefit` (0..*): Benefit Summary
    pub benefit: Vec<CoverageEligibilityResponseInsuranceItemBenefit>,
    /// `authorizationRequired` (0..1): Authorization required flag
    pub authorization_required: Option<Primitive<bool>>,
    /// `authorizationSupporting` (0..*): Type of required supporting materials
    pub authorization_supporting: Vec<CodeableConcept>,
    /// `authorizationUrl` (0..1): Preauthorization requirements endpoint
    pub authorization_url: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = CoverageEligibilityResponseInsuranceItem {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            category: o.one(d, "category"),
            product_or_service: o.one(d, "productOrService"),
            modifier: o.list(d, "modifier"),
            provider: o.one(d, "provider"),
            excluded: o.prim(d, "excluded", Kind::Boolean),
            name: o.prim(d, "name", Kind::String),
            description: o.prim(d, "description", Kind::String),
            network: o.one(d, "network"),
            unit: o.one(d, "unit"),
            term: o.one(d, "term"),
            benefit: o.list(d, "benefit"),
            authorization_required: o.prim(d, "authorizationRequired", Kind::Boolean),
            authorization_supporting: o.list(d, "authorizationSupporting"),
            authorization_url: o.prim(d, "authorizationUrl", Kind::Uri),
        };
        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("category", &self.category);
        w.one("productOrService", &self.product_or_service);
        w.list("modifier", &self.modifier);
        w.one("provider", &self.provider);
        w.prim("excluded", &self.excluded);
        w.prim("name", &self.name);
        w.prim("description", &self.description);
        w.one("network", &self.network);
        w.one("unit", &self.unit);
        w.one("term", &self.term);
        w.list("benefit", &self.benefit);
        w.prim("authorizationRequired", &self.authorization_required);
        w.list("authorizationSupporting", &self.authorization_supporting);
        w.prim("authorizationUrl", &self.authorization_url);
        w.finish()
    }
}

/// Benefit Summary
///
/// FHIR path: `CoverageEligibilityResponse.insurance.item.benefit`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageEligibilityResponseInsuranceItemBenefit {
    /// `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>,
    /// `type` (1..1): Benefit classification
    pub type_: Option<CodeableConcept>,
    /// `allowed[x]` (0..1): Benefits allowed
    pub allowed: Option<CoverageEligibilityResponseInsuranceItemBenefitAllowed>,
    /// `used[x]` (0..1): Benefits used
    pub used: Option<CoverageEligibilityResponseInsuranceItemBenefitUsed>,
}

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

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

/// Processing errors
///
/// FHIR path: `CoverageEligibilityResponse.error`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageEligibilityResponseError {
    /// `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` (1..1): Error code detailing processing issues
    pub code: Option<CodeableConcept>,
}

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

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

/// The types `CoverageEligibilityResponse.serviced[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum CoverageEligibilityResponseServiced {
    /// `date`
    Date(Primitive<String>),
    /// `Period`
    Period(Period),
}

#[cfg(feature = "financial")]
impl Choice for CoverageEligibilityResponseServiced {
    const TYPES: &'static [&'static str] = &["date", "Period"];

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

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

/// The types `CoverageEligibilityResponse.insurance.item.benefit.allowed[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum CoverageEligibilityResponseInsuranceItemBenefitAllowed {
    /// `unsignedInt`
    UnsignedInt(Primitive<i32>),
    /// `string`
    String(Primitive<String>),
    /// `Money`
    Money(Money),
}

#[cfg(feature = "financial")]
impl Choice for CoverageEligibilityResponseInsuranceItemBenefitAllowed {
    const TYPES: &'static [&'static str] = &["unsignedInt", "string", "Money"];

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::UnsignedInt(v) => w.prim_value(&choice_key(base, "unsignedInt"), v),
            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
            Self::Money(v) => w.value(&choice_key(base, "Money"), v),
        }
    }
}

/// The types `CoverageEligibilityResponse.insurance.item.benefit.used[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum CoverageEligibilityResponseInsuranceItemBenefitUsed {
    /// `unsignedInt`
    UnsignedInt(Primitive<i32>),
    /// `string`
    String(Primitive<String>),
    /// `Money`
    Money(Money),
}

#[cfg(feature = "financial")]
impl Choice for CoverageEligibilityResponseInsuranceItemBenefitUsed {
    const TYPES: &'static [&'static str] = &["unsignedInt", "string", "Money"];

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::UnsignedInt(v) => w.prim_value(&choice_key(base, "unsignedInt"), v),
            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
            Self::Money(v) => w.value(&choice_key(base, "Money"), v),
        }
    }
}