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
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `Claim` 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 provider issued list of professional services and products which have been provided, or are to be provided, to a patient which is sent to an insurer for reimbursement.
///
/// FHIR path: `Claim`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Claim {
    /// `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 claim
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): active | cancelled | draft | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `type` (1..1): Category or discipline
    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>,
    /// `billablePeriod` (0..1): Relevant time frame for the claim
    pub billable_period: Option<Period>,
    /// `created` (1..1): Resource creation date
    pub created: Option<Primitive<String>>,
    /// `enterer` (0..1): Author of the claim
    pub enterer: Option<Reference>,
    /// `insurer` (0..1): Target
    pub insurer: Option<Reference>,
    /// `provider` (1..1): Party responsible for the claim
    pub provider: Option<Reference>,
    /// `priority` (1..1): Desired processing ugency
    pub priority: Option<CodeableConcept>,
    /// `fundsReserve` (0..1): For whom to reserve funds
    pub funds_reserve: Option<CodeableConcept>,
    /// `related` (0..*): Prior or corollary claims
    pub related: Vec<ClaimRelated>,
    /// `prescription` (0..1): Prescription authorizing services and products
    pub prescription: Option<Reference>,
    /// `originalPrescription` (0..1): Original prescription if superseded by fulfiller
    pub original_prescription: Option<Reference>,
    /// `payee` (0..1): Recipient of benefits payable
    pub payee: Option<ClaimPayee>,
    /// `referral` (0..1): Treatment referral
    pub referral: Option<Reference>,
    /// `facility` (0..1): Servicing facility
    pub facility: Option<Reference>,
    /// `careTeam` (0..*): Members of the care team
    pub care_team: Vec<ClaimCareTeam>,
    /// `supportingInfo` (0..*): Supporting information
    pub supporting_info: Vec<ClaimSupportingInfo>,
    /// `diagnosis` (0..*): Pertinent diagnosis information
    pub diagnosis: Vec<ClaimDiagnosis>,
    /// `procedure` (0..*): Clinical procedures performed
    pub procedure: Vec<ClaimProcedure>,
    /// `insurance` (1..*): Patient insurance information
    pub insurance: Vec<ClaimInsurance>,
    /// `accident` (0..1): Details of the event
    pub accident: Option<ClaimAccident>,
    /// `item` (0..*): Product or service provided
    pub item: Vec<ClaimItem>,
    /// `total` (0..1): Total claim cost
    pub total: Option<Money>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Claim");
        let r = Claim {
            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"),
            billable_period: o.one(d, "billablePeriod"),
            created: o.prim(d, "created", Kind::DateTime),
            enterer: o.one(d, "enterer"),
            insurer: o.one(d, "insurer"),
            provider: o.one(d, "provider"),
            priority: o.one(d, "priority"),
            funds_reserve: o.one(d, "fundsReserve"),
            related: o.list(d, "related"),
            prescription: o.one(d, "prescription"),
            original_prescription: o.one(d, "originalPrescription"),
            payee: o.one(d, "payee"),
            referral: o.one(d, "referral"),
            facility: o.one(d, "facility"),
            care_team: o.list(d, "careTeam"),
            supporting_info: o.list(d, "supportingInfo"),
            diagnosis: o.list(d, "diagnosis"),
            procedure: o.list(d, "procedure"),
            insurance: o.list(d, "insurance"),
            accident: o.one(d, "accident"),
            item: o.list(d, "item"),
            total: o.one(d, "total"),
        };
        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, "provider", &r.provider);
        required(d, "priority", &r.priority);
        required_list(d, "insurance", &r.insurance, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Claim".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.one("billablePeriod", &self.billable_period);
        w.prim("created", &self.created);
        w.one("enterer", &self.enterer);
        w.one("insurer", &self.insurer);
        w.one("provider", &self.provider);
        w.one("priority", &self.priority);
        w.one("fundsReserve", &self.funds_reserve);
        w.list("related", &self.related);
        w.one("prescription", &self.prescription);
        w.one("originalPrescription", &self.original_prescription);
        w.one("payee", &self.payee);
        w.one("referral", &self.referral);
        w.one("facility", &self.facility);
        w.list("careTeam", &self.care_team);
        w.list("supportingInfo", &self.supporting_info);
        w.list("diagnosis", &self.diagnosis);
        w.list("procedure", &self.procedure);
        w.list("insurance", &self.insurance);
        w.one("accident", &self.accident);
        w.list("item", &self.item);
        w.one("total", &self.total);
        w.finish()
    }
}

/// Prior or corollary claims
///
/// FHIR path: `Claim.related`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimRelated {
    /// `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>,
    /// `claim` (0..1): Reference to the related claim
    pub claim: Option<Reference>,
    /// `relationship` (0..1): How the reference claim is related
    pub relationship: Option<CodeableConcept>,
    /// `reference` (0..1): File or case reference
    pub reference: Option<Identifier>,
}

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

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

/// Recipient of benefits payable
///
/// FHIR path: `Claim.payee`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimPayee {
    /// `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): Category of recipient
    pub type_: Option<CodeableConcept>,
    /// `party` (0..1): Recipient reference
    pub party: Option<Reference>,
}

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

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

/// Members of the care team
///
/// FHIR path: `Claim.careTeam`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimCareTeam {
    /// `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): Order of care team
    pub sequence: Option<Primitive<i32>>,
    /// `provider` (1..1): Practitioner or organization
    pub provider: Option<Reference>,
    /// `responsible` (0..1): Indicator of the lead practitioner
    pub responsible: Option<Primitive<bool>>,
    /// `role` (0..1): Function within the team
    pub role: Option<CodeableConcept>,
    /// `qualification` (0..1): Practitioner credential or specialization
    pub qualification: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimCareTeam {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            sequence: o.prim(d, "sequence", Kind::PositiveInt),
            provider: o.one(d, "provider"),
            responsible: o.prim(d, "responsible", Kind::Boolean),
            role: o.one(d, "role"),
            qualification: o.one(d, "qualification"),
        };
        required(d, "sequence", &r.sequence);
        required(d, "provider", &r.provider);
        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.one("provider", &self.provider);
        w.prim("responsible", &self.responsible);
        w.one("role", &self.role);
        w.one("qualification", &self.qualification);
        w.finish()
    }
}

/// Supporting information
///
/// FHIR path: `Claim.supportingInfo`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimSupportingInfo {
    /// `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): Information instance identifier
    pub sequence: Option<Primitive<i32>>,
    /// `category` (1..1): Classification of the supplied information
    pub category: Option<CodeableConcept>,
    /// `code` (0..1): Type of information
    pub code: Option<CodeableConcept>,
    /// `timing[x]` (0..1): When it occurred
    pub timing: Option<ClaimSupportingInfoTiming>,
    /// `value[x]` (0..1): Data to be provided
    pub value: Option<ClaimSupportingInfoValue>,
    /// `reason` (0..1): Explanation for the information
    pub reason: Option<CodeableConcept>,
}

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

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

/// Pertinent diagnosis information
///
/// FHIR path: `Claim.diagnosis`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimDiagnosis {
    /// `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): Diagnosis instance identifier
    pub sequence: Option<Primitive<i32>>,
    /// `diagnosis[x]` (1..1): Nature of illness or problem
    pub diagnosis: Option<ClaimDiagnosisDiagnosis>,
    /// `type` (0..*): Timing or nature of the diagnosis
    pub type_: Vec<CodeableConcept>,
    /// `onAdmission` (0..1): Present on admission
    pub on_admission: Option<CodeableConcept>,
    /// `packageCode` (0..1): Package billing code
    pub package_code: Option<CodeableConcept>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimDiagnosis {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            sequence: o.prim(d, "sequence", Kind::PositiveInt),
            diagnosis: o.choice(d, "diagnosis"),
            type_: o.list(d, "type"),
            on_admission: o.one(d, "onAdmission"),
            package_code: o.one(d, "packageCode"),
        };
        required(d, "sequence", &r.sequence);
        required(d, "diagnosis[x]", &r.diagnosis);
        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.choice("diagnosis", &self.diagnosis);
        w.list("type", &self.type_);
        w.one("onAdmission", &self.on_admission);
        w.one("packageCode", &self.package_code);
        w.finish()
    }
}

/// Clinical procedures performed
///
/// FHIR path: `Claim.procedure`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimProcedure {
    /// `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): Procedure instance identifier
    pub sequence: Option<Primitive<i32>>,
    /// `type` (0..*): Category of Procedure
    pub type_: Vec<CodeableConcept>,
    /// `date` (0..1): When the procedure was performed
    pub date: Option<Primitive<String>>,
    /// `procedure[x]` (1..1): Specific clinical procedure
    pub procedure: Option<ClaimProcedureProcedure>,
    /// `udi` (0..*): Unique device identifier
    pub udi: Vec<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimProcedure {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            sequence: o.prim(d, "sequence", Kind::PositiveInt),
            type_: o.list(d, "type"),
            date: o.prim(d, "date", Kind::DateTime),
            procedure: o.choice(d, "procedure"),
            udi: o.list(d, "udi"),
        };
        required(d, "sequence", &r.sequence);
        required(d, "procedure[x]", &r.procedure);
        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.list("type", &self.type_);
        w.prim("date", &self.date);
        w.choice("procedure", &self.procedure);
        w.list("udi", &self.udi);
        w.finish()
    }
}

/// Patient insurance information
///
/// FHIR path: `Claim.insurance`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimInsurance {
    /// `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>>,
    /// `identifier` (0..1): Pre-assigned Claim number
    pub identifier: Option<Identifier>,
    /// `coverage` (1..1): Insurance information
    pub coverage: Option<Reference>,
    /// `businessArrangement` (0..1): Additional provider contract number
    pub business_arrangement: Option<Primitive<String>>,
    /// `preAuthRef` (0..*): Prior authorization reference number
    pub pre_auth_ref: Vec<Primitive<String>>,
    /// `claimResponse` (0..1): Adjudication results
    pub claim_response: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimInsurance {
            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),
            identifier: o.one(d, "identifier"),
            coverage: o.one(d, "coverage"),
            business_arrangement: o.prim(d, "businessArrangement", Kind::String),
            pre_auth_ref: o.prim_list(d, "preAuthRef", 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("identifier", &self.identifier);
        w.one("coverage", &self.coverage);
        w.prim("businessArrangement", &self.business_arrangement);
        w.prim_list("preAuthRef", &self.pre_auth_ref);
        w.one("claimResponse", &self.claim_response);
        w.finish()
    }
}

/// Details of the event
///
/// FHIR path: `Claim.accident`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimAccident {
    /// `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>,
    /// `date` (1..1): When the incident occurred
    pub date: Option<Primitive<String>>,
    /// `type` (0..1): The nature of the accident
    pub type_: Option<CodeableConcept>,
    /// `location[x]` (0..1): Where the event occurred
    pub location: Option<ClaimAccidentLocation>,
}

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

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

/// Product or service provided
///
/// FHIR path: `Claim.item`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimItem {
    /// `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): Item instance identifier
    pub sequence: Option<Primitive<i32>>,
    /// `careTeamSequence` (0..*): Applicable careTeam members
    pub care_team_sequence: Vec<Primitive<i32>>,
    /// `diagnosisSequence` (0..*): Applicable diagnoses
    pub diagnosis_sequence: Vec<Primitive<i32>>,
    /// `procedureSequence` (0..*): Applicable procedures
    pub procedure_sequence: Vec<Primitive<i32>>,
    /// `informationSequence` (0..*): Applicable exception and supporting information
    pub information_sequence: Vec<Primitive<i32>>,
    /// `revenue` (0..1): Revenue or cost center code
    pub revenue: Option<CodeableConcept>,
    /// `category` (0..1): Benefit classification
    pub category: Option<CodeableConcept>,
    /// `productOrService` (1..1): Billing, service, product, or drug code
    pub product_or_service: Option<CodeableConcept>,
    /// `modifier` (0..*): Product or service 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<ClaimItemServiced>,
    /// `location[x]` (0..1): Place of service or where product was supplied
    pub location: Option<ClaimItemLocation>,
    /// `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>,
    /// `udi` (0..*): Unique device identifier
    pub udi: Vec<Reference>,
    /// `bodySite` (0..1): Anatomical location
    pub body_site: Option<CodeableConcept>,
    /// `subSite` (0..*): Anatomical sub-location
    pub sub_site: Vec<CodeableConcept>,
    /// `encounter` (0..*): Encounters related to this billed item
    pub encounter: Vec<Reference>,
    /// `detail` (0..*): Product or service provided
    pub detail: Vec<ClaimItemDetail>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = ClaimItem {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            sequence: o.prim(d, "sequence", Kind::PositiveInt),
            care_team_sequence: o.prim_list(d, "careTeamSequence", Kind::PositiveInt),
            diagnosis_sequence: o.prim_list(d, "diagnosisSequence", Kind::PositiveInt),
            procedure_sequence: o.prim_list(d, "procedureSequence", Kind::PositiveInt),
            information_sequence: o.prim_list(d, "informationSequence", Kind::PositiveInt),
            revenue: o.one(d, "revenue"),
            category: o.one(d, "category"),
            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"),
            udi: o.list(d, "udi"),
            body_site: o.one(d, "bodySite"),
            sub_site: o.list(d, "subSite"),
            encounter: o.list(d, "encounter"),
            detail: o.list(d, "detail"),
        };
        required(d, "sequence", &r.sequence);
        required(d, "productOrService", &r.product_or_service);
        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_list("careTeamSequence", &self.care_team_sequence);
        w.prim_list("diagnosisSequence", &self.diagnosis_sequence);
        w.prim_list("procedureSequence", &self.procedure_sequence);
        w.prim_list("informationSequence", &self.information_sequence);
        w.one("revenue", &self.revenue);
        w.one("category", &self.category);
        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.list("udi", &self.udi);
        w.one("bodySite", &self.body_site);
        w.list("subSite", &self.sub_site);
        w.list("encounter", &self.encounter);
        w.list("detail", &self.detail);
        w.finish()
    }
}

/// Product or service provided
///
/// FHIR path: `Claim.item.detail`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimItemDetail {
    /// `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): Item instance identifier
    pub sequence: Option<Primitive<i32>>,
    /// `revenue` (0..1): Revenue or cost center code
    pub revenue: Option<CodeableConcept>,
    /// `category` (0..1): Benefit classification
    pub category: Option<CodeableConcept>,
    /// `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>,
    /// `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>,
    /// `udi` (0..*): Unique device identifier
    pub udi: Vec<Reference>,
    /// `subDetail` (0..*): Product or service provided
    pub sub_detail: Vec<ClaimItemDetailSubDetail>,
}

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

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

/// Product or service provided
///
/// FHIR path: `Claim.item.detail.subDetail`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ClaimItemDetailSubDetail {
    /// `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): Item instance identifier
    pub sequence: Option<Primitive<i32>>,
    /// `revenue` (0..1): Revenue or cost center code
    pub revenue: Option<CodeableConcept>,
    /// `category` (0..1): Benefit classification
    pub category: Option<CodeableConcept>,
    /// `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>,
    /// `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>,
    /// `udi` (0..*): Unique device identifier
    pub udi: Vec<Reference>,
}

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

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

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

#[cfg(feature = "financial")]
impl Choice for ClaimSupportingInfoTiming {
    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 `Claim.supportingInfo.value[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum ClaimSupportingInfoValue {
    /// `boolean`
    Boolean(Primitive<bool>),
    /// `string`
    String(Primitive<String>),
    /// `Quantity`
    Quantity(Quantity),
    /// `Attachment`
    Attachment(Attachment),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "financial")]
impl Choice for ClaimSupportingInfoValue {
    const TYPES: &'static [&'static str] =
        &["boolean", "string", "Quantity", "Attachment", "Reference"];

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Boolean(v) => w.prim_value(&choice_key(base, "boolean"), v),
            Self::String(v) => w.prim_value(&choice_key(base, "string"), v),
            Self::Quantity(v) => w.value(&choice_key(base, "Quantity"), v),
            Self::Attachment(v) => w.value(&choice_key(base, "Attachment"), v),
            Self::Reference(v) => w.value(&choice_key(base, "Reference"), v),
        }
    }
}

/// The types `Claim.diagnosis.diagnosis[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum ClaimDiagnosisDiagnosis {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

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

/// The types `Claim.procedure.procedure[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum ClaimProcedureProcedure {
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
    /// `Reference`
    Reference(Reference),
}

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

/// The types `Claim.accident.location[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum ClaimAccidentLocation {
    /// `Address`
    Address(Address),
    /// `Reference`
    Reference(Reference),
}

#[cfg(feature = "financial")]
impl Choice for ClaimAccidentLocation {
    const TYPES: &'static [&'static str] = &["Address", "Reference"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "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::Address(v) => w.value(&choice_key(base, "Address"), v),
            Self::Reference(v) => w.value(&choice_key(base, "Reference"), v),
        }
    }
}

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

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

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