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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `ClaimResponse` 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 the adjudication details from the processing of a Claim resource.
///
/// FHIR path: `ClaimResponse`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponse {
    /// `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 a claim response
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): active | cancelled | draft | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `type` (1..1): More granular claim type
    pub type_: Option<CodeableConcept>,
    /// `subType` (0..1): More granular claim type
    pub sub_type: Option<CodeableConcept>,
    /// `use` (1..1): claim | preauthorization | predetermination
    pub use_: Option<Primitive<String>>,
    /// `patient` (1..1): The recipient of the products and services
    pub patient: Option<Reference>,
    /// `created` (1..1): Response creation date
    pub created: Option<Primitive<String>>,
    /// `insurer` (1..1): Party responsible for reimbursement
    pub insurer: Option<Reference>,
    /// `requestor` (0..1): Party responsible for the claim
    pub requestor: Option<Reference>,
    /// `request` (0..1): Id of resource triggering adjudication
    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>>,
    /// `preAuthRef` (0..1): Preauthorization reference
    pub pre_auth_ref: Option<Primitive<String>>,
    /// `preAuthPeriod` (0..1): Preauthorization reference effective period
    pub pre_auth_period: Option<Period>,
    /// `payeeType` (0..1): Party to be paid any benefits payable
    pub payee_type: Option<CodeableConcept>,
    /// `item` (0..*): Adjudication for claim line items
    pub item: Vec<ClaimResponseItem>,
    /// `addItem` (0..*): Insurer added line items
    pub add_item: Vec<ClaimResponseAddItem>,
    /// `adjudication` (0..*): Header-level adjudication
    pub adjudication: Vec<ClaimResponseItemAdjudication>,
    /// `total` (0..*): Adjudication totals
    pub total: Vec<ClaimResponseTotal>,
    /// `payment` (0..1): Payment Details
    pub payment: Option<ClaimResponsePayment>,
    /// `fundsReserve` (0..1): Funds reserved status
    pub funds_reserve: Option<CodeableConcept>,
    /// `formCode` (0..1): Printed form identifier
    pub form_code: Option<CodeableConcept>,
    /// `form` (0..1): Printed reference or actual form
    pub form: Option<Attachment>,
    /// `processNote` (0..*): Note concerning adjudication
    pub process_note: Vec<ClaimResponseProcessNote>,
    /// `communicationRequest` (0..*): Request for additional information
    pub communication_request: Vec<Reference>,
    /// `insurance` (0..*): Patient insurance information
    pub insurance: Vec<ClaimResponseInsurance>,
    /// `error` (0..*): Processing errors
    pub error: Vec<ClaimResponseError>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "ClaimResponse");
        let r = ClaimResponse {
            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),
            type_: o.one(d, "type"),
            sub_type: o.one(d, "subType"),
            use_: o.prim(d, "use", Kind::Code),
            patient: o.one(d, "patient"),
            created: o.prim(d, "created", Kind::DateTime),
            insurer: o.one(d, "insurer"),
            requestor: o.one(d, "requestor"),
            request: o.one(d, "request"),
            outcome: o.prim(d, "outcome", Kind::Code),
            disposition: o.prim(d, "disposition", Kind::String),
            pre_auth_ref: o.prim(d, "preAuthRef", Kind::String),
            pre_auth_period: o.one(d, "preAuthPeriod"),
            payee_type: o.one(d, "payeeType"),
            item: o.list(d, "item"),
            add_item: o.list(d, "addItem"),
            adjudication: o.list(d, "adjudication"),
            total: o.list(d, "total"),
            payment: o.one(d, "payment"),
            funds_reserve: o.one(d, "fundsReserve"),
            form_code: o.one(d, "formCode"),
            form: o.one(d, "form"),
            process_note: o.list(d, "processNote"),
            communication_request: o.list(d, "communicationRequest"),
            insurance: o.list(d, "insurance"),
            error: o.list(d, "error"),
        };
        required(d, "status", &r.status);
        required(d, "type", &r.type_);
        required(d, "use", &r.use_);
        required(d, "patient", &r.patient);
        required(d, "created", &r.created);
        required(d, "insurer", &r.insurer);
        required(d, "outcome", &r.outcome);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("ClaimResponse".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.one("type", &self.type_);
        w.one("subType", &self.sub_type);
        w.prim("use", &self.use_);
        w.one("patient", &self.patient);
        w.prim("created", &self.created);
        w.one("insurer", &self.insurer);
        w.one("requestor", &self.requestor);
        w.one("request", &self.request);
        w.prim("outcome", &self.outcome);
        w.prim("disposition", &self.disposition);
        w.prim("preAuthRef", &self.pre_auth_ref);
        w.one("preAuthPeriod", &self.pre_auth_period);
        w.one("payeeType", &self.payee_type);
        w.list("item", &self.item);
        w.list("addItem", &self.add_item);
        w.list("adjudication", &self.adjudication);
        w.list("total", &self.total);
        w.one("payment", &self.payment);
        w.one("fundsReserve", &self.funds_reserve);
        w.one("formCode", &self.form_code);
        w.one("form", &self.form);
        w.list("processNote", &self.process_note);
        w.list("communicationRequest", &self.communication_request);
        w.list("insurance", &self.insurance);
        w.list("error", &self.error);
        w.finish()
    }
}

/// Adjudication for claim line items
///
/// FHIR path: `ClaimResponse.item`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseItem {
    /// `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>,
    /// `itemSequence` (1..1): Claim item instance identifier
    pub item_sequence: Option<Primitive<i32>>,
    /// `noteNumber` (0..*): Applicable note numbers
    pub note_number: Vec<Primitive<i32>>,
    /// `adjudication` (1..*): Adjudication details
    pub adjudication: Vec<ClaimResponseItemAdjudication>,
    /// `detail` (0..*): Adjudication for claim details
    pub detail: Vec<ClaimResponseItemDetail>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseItem {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            item_sequence: o.prim(d, "itemSequence", Kind::PositiveInt),
            note_number: o.prim_list(d, "noteNumber", Kind::PositiveInt),
            adjudication: o.list(d, "adjudication"),
            detail: o.list(d, "detail"),
        };
        required(d, "itemSequence", &r.item_sequence);
        required_list(d, "adjudication", &r.adjudication, 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("itemSequence", &self.item_sequence);
        w.prim_list("noteNumber", &self.note_number);
        w.list("adjudication", &self.adjudication);
        w.list("detail", &self.detail);
        w.finish()
    }
}

/// Adjudication details
///
/// FHIR path: `ClaimResponse.item.adjudication`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseItemAdjudication {
    /// `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` (1..1): Type of adjudication information
    pub category: Option<CodeableConcept>,
    /// `reason` (0..1): Explanation of adjudication outcome
    pub reason: Option<CodeableConcept>,
    /// `amount` (0..1): Monetary amount
    pub amount: Option<Money>,
    /// `value` (0..1): Non-monetary value
    pub value: Option<Primitive<Decimal>>,
}

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

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

/// Adjudication for claim details
///
/// FHIR path: `ClaimResponse.item.detail`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseItemDetail {
    /// `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>,
    /// `detailSequence` (1..1): Claim detail instance identifier
    pub detail_sequence: Option<Primitive<i32>>,
    /// `noteNumber` (0..*): Applicable note numbers
    pub note_number: Vec<Primitive<i32>>,
    /// `adjudication` (1..*): Detail level adjudication details
    pub adjudication: Vec<ClaimResponseItemAdjudication>,
    /// `subDetail` (0..*): Adjudication for claim sub-details
    pub sub_detail: Vec<ClaimResponseItemDetailSubDetail>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseItemDetail {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            detail_sequence: o.prim(d, "detailSequence", Kind::PositiveInt),
            note_number: o.prim_list(d, "noteNumber", Kind::PositiveInt),
            adjudication: o.list(d, "adjudication"),
            sub_detail: o.list(d, "subDetail"),
        };
        required(d, "detailSequence", &r.detail_sequence);
        required_list(d, "adjudication", &r.adjudication, 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("detailSequence", &self.detail_sequence);
        w.prim_list("noteNumber", &self.note_number);
        w.list("adjudication", &self.adjudication);
        w.list("subDetail", &self.sub_detail);
        w.finish()
    }
}

/// Adjudication for claim sub-details
///
/// FHIR path: `ClaimResponse.item.detail.subDetail`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseItemDetailSubDetail {
    /// `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>,
    /// `subDetailSequence` (1..1): Claim sub-detail instance identifier
    pub sub_detail_sequence: Option<Primitive<i32>>,
    /// `noteNumber` (0..*): Applicable note numbers
    pub note_number: Vec<Primitive<i32>>,
    /// `adjudication` (0..*): Subdetail level adjudication details
    pub adjudication: Vec<ClaimResponseItemAdjudication>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseItemDetailSubDetail {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            sub_detail_sequence: o.prim(d, "subDetailSequence", Kind::PositiveInt),
            note_number: o.prim_list(d, "noteNumber", Kind::PositiveInt),
            adjudication: o.list(d, "adjudication"),
        };
        required(d, "subDetailSequence", &r.sub_detail_sequence);
        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("subDetailSequence", &self.sub_detail_sequence);
        w.prim_list("noteNumber", &self.note_number);
        w.list("adjudication", &self.adjudication);
        w.finish()
    }
}

/// Insurer added line items
///
/// FHIR path: `ClaimResponse.addItem`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseAddItem {
    /// `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>,
    /// `itemSequence` (0..*): Item sequence number
    pub item_sequence: Vec<Primitive<i32>>,
    /// `detailSequence` (0..*): Detail sequence number
    pub detail_sequence: Vec<Primitive<i32>>,
    /// `subdetailSequence` (0..*): Subdetail sequence number
    pub subdetail_sequence: Vec<Primitive<i32>>,
    /// `provider` (0..*): Authorized providers
    pub provider: Vec<Reference>,
    /// `productOrService` (1..1): Billing, service, product, or drug code
    pub product_or_service: Option<CodeableConcept>,
    /// `modifier` (0..*): Service/Product billing modifiers
    pub modifier: Vec<CodeableConcept>,
    /// `programCode` (0..*): Program the product or service is provided under
    pub program_code: Vec<CodeableConcept>,
    /// `serviced[x]` (0..1): Date or dates of service or product delivery
    pub serviced: Option<ClaimResponseAddItemServiced>,
    /// `location[x]` (0..1): Place of service or where product was supplied
    pub location: Option<ClaimResponseAddItemLocation>,
    /// `quantity` (0..1): Count of products or services
    pub quantity: Option<Quantity>,
    /// `unitPrice` (0..1): Fee, charge or cost per item
    pub unit_price: Option<Money>,
    /// `factor` (0..1): Price scaling factor
    pub factor: Option<Primitive<Decimal>>,
    /// `net` (0..1): Total item cost
    pub net: Option<Money>,
    /// `bodySite` (0..1): Anatomical location
    pub body_site: Option<CodeableConcept>,
    /// `subSite` (0..*): Anatomical sub-location
    pub sub_site: Vec<CodeableConcept>,
    /// `noteNumber` (0..*): Applicable note numbers
    pub note_number: Vec<Primitive<i32>>,
    /// `adjudication` (1..*): Added items adjudication
    pub adjudication: Vec<ClaimResponseItemAdjudication>,
    /// `detail` (0..*): Insurer added line details
    pub detail: Vec<ClaimResponseAddItemDetail>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseAddItem {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            item_sequence: o.prim_list(d, "itemSequence", Kind::PositiveInt),
            detail_sequence: o.prim_list(d, "detailSequence", Kind::PositiveInt),
            subdetail_sequence: o.prim_list(d, "subdetailSequence", Kind::PositiveInt),
            provider: o.list(d, "provider"),
            product_or_service: o.one(d, "productOrService"),
            modifier: o.list(d, "modifier"),
            program_code: o.list(d, "programCode"),
            serviced: o.choice(d, "serviced"),
            location: o.choice(d, "location"),
            quantity: o.one(d, "quantity"),
            unit_price: o.one(d, "unitPrice"),
            factor: o.prim(d, "factor", Kind::Decimal),
            net: o.one(d, "net"),
            body_site: o.one(d, "bodySite"),
            sub_site: o.list(d, "subSite"),
            note_number: o.prim_list(d, "noteNumber", Kind::PositiveInt),
            adjudication: o.list(d, "adjudication"),
            detail: o.list(d, "detail"),
        };
        required(d, "productOrService", &r.product_or_service);
        required_list(d, "adjudication", &r.adjudication, 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_list("itemSequence", &self.item_sequence);
        w.prim_list("detailSequence", &self.detail_sequence);
        w.prim_list("subdetailSequence", &self.subdetail_sequence);
        w.list("provider", &self.provider);
        w.one("productOrService", &self.product_or_service);
        w.list("modifier", &self.modifier);
        w.list("programCode", &self.program_code);
        w.choice("serviced", &self.serviced);
        w.choice("location", &self.location);
        w.one("quantity", &self.quantity);
        w.one("unitPrice", &self.unit_price);
        w.prim("factor", &self.factor);
        w.one("net", &self.net);
        w.one("bodySite", &self.body_site);
        w.list("subSite", &self.sub_site);
        w.prim_list("noteNumber", &self.note_number);
        w.list("adjudication", &self.adjudication);
        w.list("detail", &self.detail);
        w.finish()
    }
}

/// Insurer added line details
///
/// FHIR path: `ClaimResponse.addItem.detail`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseAddItemDetail {
    /// `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>,
    /// `productOrService` (1..1): Billing, service, product, or drug code
    pub product_or_service: Option<CodeableConcept>,
    /// `modifier` (0..*): Service/Product billing modifiers
    pub modifier: Vec<CodeableConcept>,
    /// `quantity` (0..1): Count of products or services
    pub quantity: Option<Quantity>,
    /// `unitPrice` (0..1): Fee, charge or cost per item
    pub unit_price: Option<Money>,
    /// `factor` (0..1): Price scaling factor
    pub factor: Option<Primitive<Decimal>>,
    /// `net` (0..1): Total item cost
    pub net: Option<Money>,
    /// `noteNumber` (0..*): Applicable note numbers
    pub note_number: Vec<Primitive<i32>>,
    /// `adjudication` (1..*): Added items detail adjudication
    pub adjudication: Vec<ClaimResponseItemAdjudication>,
    /// `subDetail` (0..*): Insurer added line items
    pub sub_detail: Vec<ClaimResponseAddItemDetailSubDetail>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseAddItemDetail {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            product_or_service: o.one(d, "productOrService"),
            modifier: o.list(d, "modifier"),
            quantity: o.one(d, "quantity"),
            unit_price: o.one(d, "unitPrice"),
            factor: o.prim(d, "factor", Kind::Decimal),
            net: o.one(d, "net"),
            note_number: o.prim_list(d, "noteNumber", Kind::PositiveInt),
            adjudication: o.list(d, "adjudication"),
            sub_detail: o.list(d, "subDetail"),
        };
        required(d, "productOrService", &r.product_or_service);
        required_list(d, "adjudication", &r.adjudication, 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.one("productOrService", &self.product_or_service);
        w.list("modifier", &self.modifier);
        w.one("quantity", &self.quantity);
        w.one("unitPrice", &self.unit_price);
        w.prim("factor", &self.factor);
        w.one("net", &self.net);
        w.prim_list("noteNumber", &self.note_number);
        w.list("adjudication", &self.adjudication);
        w.list("subDetail", &self.sub_detail);
        w.finish()
    }
}

/// Insurer added line items
///
/// FHIR path: `ClaimResponse.addItem.detail.subDetail`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseAddItemDetailSubDetail {
    /// `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>,
    /// `productOrService` (1..1): Billing, service, product, or drug code
    pub product_or_service: Option<CodeableConcept>,
    /// `modifier` (0..*): Service/Product billing modifiers
    pub modifier: Vec<CodeableConcept>,
    /// `quantity` (0..1): Count of products or services
    pub quantity: Option<Quantity>,
    /// `unitPrice` (0..1): Fee, charge or cost per item
    pub unit_price: Option<Money>,
    /// `factor` (0..1): Price scaling factor
    pub factor: Option<Primitive<Decimal>>,
    /// `net` (0..1): Total item cost
    pub net: Option<Money>,
    /// `noteNumber` (0..*): Applicable note numbers
    pub note_number: Vec<Primitive<i32>>,
    /// `adjudication` (1..*): Added items detail adjudication
    pub adjudication: Vec<ClaimResponseItemAdjudication>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseAddItemDetailSubDetail {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            product_or_service: o.one(d, "productOrService"),
            modifier: o.list(d, "modifier"),
            quantity: o.one(d, "quantity"),
            unit_price: o.one(d, "unitPrice"),
            factor: o.prim(d, "factor", Kind::Decimal),
            net: o.one(d, "net"),
            note_number: o.prim_list(d, "noteNumber", Kind::PositiveInt),
            adjudication: o.list(d, "adjudication"),
        };
        required(d, "productOrService", &r.product_or_service);
        required_list(d, "adjudication", &r.adjudication, 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.one("productOrService", &self.product_or_service);
        w.list("modifier", &self.modifier);
        w.one("quantity", &self.quantity);
        w.one("unitPrice", &self.unit_price);
        w.prim("factor", &self.factor);
        w.one("net", &self.net);
        w.prim_list("noteNumber", &self.note_number);
        w.list("adjudication", &self.adjudication);
        w.finish()
    }
}

/// Adjudication totals
///
/// FHIR path: `ClaimResponse.total`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseTotal {
    /// `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` (1..1): Type of adjudication information
    pub category: Option<CodeableConcept>,
    /// `amount` (1..1): Financial total for the category
    pub amount: Option<Money>,
}

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

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

/// Payment Details
///
/// FHIR path: `ClaimResponse.payment`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponsePayment {
    /// `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): Partial or complete payment
    pub type_: Option<CodeableConcept>,
    /// `adjustment` (0..1): Payment adjustment for non-claim issues
    pub adjustment: Option<Money>,
    /// `adjustmentReason` (0..1): Explanation for the adjustment
    pub adjustment_reason: Option<CodeableConcept>,
    /// `date` (0..1): Expected date of payment
    pub date: Option<Primitive<String>>,
    /// `amount` (1..1): Payable amount after adjustment
    pub amount: Option<Money>,
    /// `identifier` (0..1): Business identifier for the payment
    pub identifier: Option<Identifier>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponsePayment {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            adjustment: o.one(d, "adjustment"),
            adjustment_reason: o.one(d, "adjustmentReason"),
            date: o.prim(d, "date", Kind::Date),
            amount: o.one(d, "amount"),
            identifier: o.one(d, "identifier"),
        };
        required(d, "type", &r.type_);
        required(d, "amount", &r.amount);
        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.one("adjustment", &self.adjustment);
        w.one("adjustmentReason", &self.adjustment_reason);
        w.prim("date", &self.date);
        w.one("amount", &self.amount);
        w.one("identifier", &self.identifier);
        w.finish()
    }
}

/// Note concerning adjudication
///
/// FHIR path: `ClaimResponse.processNote`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseProcessNote {
    /// `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>,
    /// `number` (0..1): Note instance identifier
    pub number: Option<Primitive<i32>>,
    /// `type` (0..1): display | print | printoper
    pub type_: Option<Primitive<String>>,
    /// `text` (1..1): Note explanatory text
    pub text: Option<Primitive<String>>,
    /// `language` (0..1): Language of the text
    pub language: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseProcessNote {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            number: o.prim(d, "number", Kind::PositiveInt),
            type_: o.prim(d, "type", Kind::Code),
            text: o.prim(d, "text", Kind::String),
            language: o.one(d, "language"),
        };
        required(d, "text", &r.text);
        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("number", &self.number);
        w.prim("type", &self.type_);
        w.prim("text", &self.text);
        w.one("language", &self.language);
        w.finish()
    }
}

/// Patient insurance information
///
/// FHIR path: `ClaimResponse.insurance`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseInsurance {
    /// `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>,
    /// `sequence` (1..1): Insurance instance identifier
    pub sequence: Option<Primitive<i32>>,
    /// `focal` (1..1): Coverage to be used for adjudication
    pub focal: Option<Primitive<bool>>,
    /// `coverage` (1..1): Insurance information
    pub coverage: Option<Reference>,
    /// `businessArrangement` (0..1): Additional provider contract number
    pub business_arrangement: Option<Primitive<String>>,
    /// `claimResponse` (0..1): Adjudication results
    pub claim_response: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseInsurance {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            sequence: o.prim(d, "sequence", Kind::PositiveInt),
            focal: o.prim(d, "focal", Kind::Boolean),
            coverage: o.one(d, "coverage"),
            business_arrangement: o.prim(d, "businessArrangement", Kind::String),
            claim_response: o.one(d, "claimResponse"),
        };
        required(d, "sequence", &r.sequence);
        required(d, "focal", &r.focal);
        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.prim("sequence", &self.sequence);
        w.prim("focal", &self.focal);
        w.one("coverage", &self.coverage);
        w.prim("businessArrangement", &self.business_arrangement);
        w.one("claimResponse", &self.claim_response);
        w.finish()
    }
}

/// Processing errors
///
/// FHIR path: `ClaimResponse.error`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimResponseError {
    /// `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>,
    /// `itemSequence` (0..1): Item sequence number
    pub item_sequence: Option<Primitive<i32>>,
    /// `detailSequence` (0..1): Detail sequence number
    pub detail_sequence: Option<Primitive<i32>>,
    /// `subDetailSequence` (0..1): Subdetail sequence number
    pub sub_detail_sequence: Option<Primitive<i32>>,
    /// `code` (1..1): Error code detailing processing issues
    pub code: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimResponseError {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            item_sequence: o.prim(d, "itemSequence", Kind::PositiveInt),
            detail_sequence: o.prim(d, "detailSequence", Kind::PositiveInt),
            sub_detail_sequence: o.prim(d, "subDetailSequence", Kind::PositiveInt),
            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.prim("itemSequence", &self.item_sequence);
        w.prim("detailSequence", &self.detail_sequence);
        w.prim("subDetailSequence", &self.sub_detail_sequence);
        w.one("code", &self.code);
        w.finish()
    }
}

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

#[cfg(feature = "financial")]
impl Choice for ClaimResponseAddItemServiced {
    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 `ClaimResponse.addItem.location[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum ClaimResponseAddItemLocation {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Address`
    Address(Address),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "financial")]
impl Choice for ClaimResponseAddItemLocation {
    const TYPES: &'static [&'static str] = &["CodeableConcept", "Address", "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),
            "Address" => o.one(d, key).map(Self::Address),
            "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::Address(v) => w.value(&choice_key(base, "Address"), v),
            Self::Reference(v) => w.value(&choice_key(base, "Reference"), v),
        }
    }
}