fhir-types 0.1.33

Generated per-version FHIR types and terminology operation contracts
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
// @generated by fhir-codegen from hl7.fhir.r4.core 4.0.1. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
//! Describes a required data item

/// Describes a required data item
///
/// Describes a required data item for evaluation in terms of the type of data,
/// and optional code or date-based filters of the data.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DataRequirement {
    /// Unique id for inter-element referencing
    ///
    /// Unique id for the element within a resource (for internal references). This
    /// may be any string value that does not contain spaces.
    pub id: Option<std::string::String>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element. To make the use of extensions safe and
    /// manageable, there is a strict set of governance applied to the definition
    /// and use of extensions. Though any implementer can define an extension, there
    /// is a set of requirements that SHALL be met as part of the definition of the
    /// extension.
    pub extension: Vec<super::extension::Extension>,
    /// The type of the required data
    ///
    /// The type of the required data, specified as the type name of a resource. For
    /// profiles, this value is set to the type of the base resource of the profile.
    pub r#type: super::primitives::Code,
    /// The profile of the required data
    ///
    /// The profile of the required data, specified as the uri of the profile
    /// definition.
    pub profile: Vec<super::primitives::Canonical>,
    /// E.g. Patient, Practitioner, RelatedPerson, Organization, Location, Device
    ///
    /// The intended subjects of the data requirement. If this element is not
    /// provided, a Patient subject is assumed.
    pub subject: Option<DataRequirementSubject>,
    /// Indicates specific structure elements that are referenced by the knowledge
    /// module
    ///
    /// Indicates that specific elements of the type are referenced by the knowledge
    /// module and must be supported by the consumer in order to obtain an effective
    /// evaluation. This does not mean that a value is required for this element,
    /// only that the consuming system must understand the element and be able to
    /// provide values for it if they are available. The value of mustSupport SHALL
    /// be a FHIRPath resolveable on the type of the DataRequirement. The path SHALL
    /// consist only of identifiers, constant indexers, and .resolve() (see the
    /// \[Simple FHIRPath Profile\](fhirpath.html\#simple) for full details).
    pub must_support: Vec<super::primitives::String>,
    /// What codes are expected
    ///
    /// Code filters specify additional constraints on the data, specifying the
    /// value set of interest for a particular element of the data. Each code filter
    /// defines an additional constraint on the data, i.e. code filters are AND'ed,
    /// not OR'ed.
    pub code_filter: Vec<DataRequirementCodeFilter>,
    /// What dates/date ranges are expected
    ///
    /// Date filters specify additional constraints on the data in terms of the
    /// applicable date range for specific elements. Each date filter specifies an
    /// additional constraint on the data, i.e. date filters are AND'ed, not OR'ed.
    pub date_filter: Vec<DataRequirementDateFilter>,
    /// Number of results
    ///
    /// Specifies a maximum number of results that are required (uses the \_count
    /// search parameter).
    pub limit: Option<super::primitives::PositiveInt>,
    /// Order of the results
    ///
    /// Specifies the order of the results to be returned.
    pub sort: Vec<DataRequirementSort>,
}

impl super::super::codec::Json for DataRequirement {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                serde_json::Value::String(v.clone()),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                serde_json::Value::Array(items),
            );
        }
        if let Some(v) = super::super::codec::Primitive::value_json(&self.r#type)? {
            object.insert(std::string::String::from("type"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.r#type)? {
            object.insert(std::string::String::from("_type"), e);
        }
        if !self.profile.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.profile)?;
            object.insert(std::string::String::from("profile"), values);
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_profile"), elements);
            }
        }
        if let Some(item) = &self.subject {
            let (suffix, value, element) = item.to_json_parts()?;
            if let Some(value) = value {
                object.insert(format!("subject{suffix}"), value);
            }
            if let Some(element) = element {
                object.insert(format!("_subject{suffix}"), element);
            }
        }
        if !self.must_support.is_empty() {
            let (values, elements) = super::super::codec::primitive_arrays(&self.must_support)?;
            object.insert(std::string::String::from("mustSupport"), values);
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_mustSupport"), elements);
            }
        }
        if !self.code_filter.is_empty() {
            let mut items = Vec::with_capacity(self.code_filter.len());
            for item in &self.code_filter {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("codeFilter"),
                serde_json::Value::Array(items),
            );
        }
        if !self.date_filter.is_empty() {
            let mut items = Vec::with_capacity(self.date_filter.len());
            for item in &self.date_filter {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("dateFilter"),
                serde_json::Value::Array(items),
            );
        }
        if let Some(item) = &self.limit {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("limit"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_limit"), e);
            }
        }
        if !self.sort.is_empty() {
            let mut items = Vec::with_capacity(self.sort.len());
            for item in &self.sort {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("sort"),
                serde_json::Value::Array(items),
            );
        }
        Ok(object)
    }

    fn from_json(
        object: &super::super::codec::Object,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        let mut raw_id: Option<&serde_json::Value> = None;
        let mut raw_extension: Option<&serde_json::Value> = None;
        let mut raw_type: Option<&serde_json::Value> = None;
        let mut raw_type_element: Option<&serde_json::Value> = None;
        let mut raw_profile: Option<&serde_json::Value> = None;
        let mut raw_profile_element: Option<&serde_json::Value> = None;
        let mut raw_subject = super::super::codec::ChoiceSlot::default();
        let mut raw_must_support: Option<&serde_json::Value> = None;
        let mut raw_must_support_element: Option<&serde_json::Value> = None;
        let mut raw_code_filter: Option<&serde_json::Value> = None;
        let mut raw_date_filter: Option<&serde_json::Value> = None;
        let mut raw_limit: Option<&serde_json::Value> = None;
        let mut raw_limit_element: Option<&serde_json::Value> = None;
        let mut raw_sort: Option<&serde_json::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => raw_id = Some(value),
                "extension" => raw_extension = Some(value),
                "type" => raw_type = Some(value),
                "_type" => raw_type_element = Some(value),
                "profile" => raw_profile = Some(value),
                "_profile" => raw_profile_element = Some(value),
                "subjectCodeableConcept" => {
                    raw_subject.value("CodeableConcept", value, path)?;
                }
                "_subjectCodeableConcept" => {
                    raw_subject.element("CodeableConcept", value, path)?;
                }
                "subjectReference" => {
                    raw_subject.value("Reference", value, path)?;
                }
                "_subjectReference" => {
                    raw_subject.element("Reference", value, path)?;
                }
                "mustSupport" => raw_must_support = Some(value),
                "_mustSupport" => raw_must_support_element = Some(value),
                "codeFilter" => raw_code_filter = Some(value),
                "dateFilter" => raw_date_filter = Some(value),
                "limit" => raw_limit = Some(value),
                "_limit" => raw_limit_element = Some(value),
                "sort" => raw_sort = Some(value),
                other => {
                    return path.with(other, |path| {
                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
                    });
                }
            }
        }
        let field_id = raw_id
            .map(|value| {
                path.with("id", |path| {
                    let value = super::super::codec::expect_single(value, path)?;
                    super::super::codec::expect_string(value, path)
                })
            })
            .transpose()?;
        let mut field_extension = Vec::new();
        if let Some(raw) = raw_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_extension.push(path.with_index("extension", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_type = path.with("type", |path| {
            super::super::codec::Primitive::from_json_parts(raw_type, raw_type_element, path)
        })?;
        let mut field_profile = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_profile, raw_profile_element, path)?
                .into_iter()
                .enumerate()
        {
            field_profile.push(path.with_index("profile", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let field_subject = match raw_subject.suffix {
            None => None,
            Some(suffix) => Some(path.with("subject", |path| {
                DataRequirementSubject::from_json_parts(
                    suffix,
                    raw_subject.value,
                    raw_subject.element,
                    path,
                )
            })?),
        };
        let mut field_must_support = Vec::new();
        for (index, (value, element)) in
            super::super::codec::pair_arrays(raw_must_support, raw_must_support_element, path)?
                .into_iter()
                .enumerate()
        {
            field_must_support.push(path.with_index("mustSupport", index, |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?);
        }
        let mut field_code_filter = Vec::new();
        if let Some(raw) = raw_code_filter {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_code_filter.push(path.with_index("codeFilter", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let mut field_date_filter = Vec::new();
        if let Some(raw) = raw_date_filter {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_date_filter.push(path.with_index("dateFilter", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_limit = match (raw_limit, raw_limit_element) {
            (None, None) => None,
            (value, element) => Some(path.with("limit", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let mut field_sort = Vec::new();
        if let Some(raw) = raw_sort {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_sort.push(path.with_index("sort", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        Ok(Self {
            id: field_id,
            extension: field_extension,
            r#type: field_type,
            profile: field_profile,
            subject: field_subject,
            must_support: field_must_support,
            code_filter: field_code_filter,
            date_filter: field_date_filter,
            limit: field_limit,
            sort: field_sort,
        })
    }
}

impl serde::Serialize for DataRequirement {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        super::super::codec::Json::to_json(self)
            .map_err(serde::ser::Error::custom)?
            .serialize(serializer)
    }
}

impl<'de> serde::Deserialize<'de> for DataRequirement {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = serde_json::Value::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("DataRequirement");
        let object =
            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
    }
}

/// What codes are expected
///
/// Code filters specify additional constraints on the data, specifying the
/// value set of interest for a particular element of the data. Each code filter
/// defines an additional constraint on the data, i.e. code filters are AND'ed,
/// not OR'ed.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DataRequirementCodeFilter {
    /// Unique id for inter-element referencing
    ///
    /// Unique id for the element within a resource (for internal references). This
    /// may be any string value that does not contain spaces.
    pub id: Option<std::string::String>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element. To make the use of extensions safe and
    /// manageable, there is a strict set of governance applied to the definition
    /// and use of extensions. Though any implementer can define an extension, there
    /// is a set of requirements that SHALL be met as part of the definition of the
    /// extension.
    pub extension: Vec<super::extension::Extension>,
    /// A code-valued attribute to filter on
    ///
    /// The code-valued attribute of the filter. The specified path SHALL be a
    /// FHIRPath resolveable on the specified type of the DataRequirement, and SHALL
    /// consist only of identifiers, constant indexers, and .resolve(). The path is
    /// allowed to contain qualifiers (.) to traverse sub-elements, as well as
    /// indexers (\[x\]) to traverse multiple-cardinality sub-elements (see the
    /// \[Simple FHIRPath Profile\](fhirpath.html\#simple) for full details). Note
    /// that the index must be an integer constant. The path must resolve to an
    /// element of type code, Coding, or CodeableConcept.
    pub path: Option<super::primitives::String>,
    /// A coded (token) parameter to search on
    ///
    /// A token parameter that refers to a search parameter defined on the specified
    /// type of the DataRequirement, and which searches on elements of type code,
    /// Coding, or CodeableConcept.
    pub search_param: Option<super::primitives::String>,
    /// Valueset for the filter
    ///
    /// The valueset for the code filter. The valueSet and code elements are
    /// additive. If valueSet is specified, the filter will return only those data
    /// items for which the value of the code-valued element specified in the path
    /// is a member of the specified valueset.
    pub value_set: Option<super::primitives::Canonical>,
    /// What code is expected
    ///
    /// The codes for the code filter. If values are given, the filter will return
    /// only those data items for which the code-valued attribute specified by the
    /// path has a value that is one of the specified codes. If codes are specified
    /// in addition to a value set, the filter returns items matching a code in the
    /// value set or one of the specified codes.
    pub code: Vec<super::coding::Coding>,
}

impl super::super::codec::Json for DataRequirementCodeFilter {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                serde_json::Value::String(v.clone()),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                serde_json::Value::Array(items),
            );
        }
        if let Some(item) = &self.path {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("path"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_path"), e);
            }
        }
        if let Some(item) = &self.search_param {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("searchParam"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_searchParam"), e);
            }
        }
        if let Some(item) = &self.value_set {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("valueSet"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_valueSet"), e);
            }
        }
        if !self.code.is_empty() {
            let mut items = Vec::with_capacity(self.code.len());
            for item in &self.code {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("code"),
                serde_json::Value::Array(items),
            );
        }
        Ok(object)
    }

    fn from_json(
        object: &super::super::codec::Object,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        let mut raw_id: Option<&serde_json::Value> = None;
        let mut raw_extension: Option<&serde_json::Value> = None;
        let mut raw_path: Option<&serde_json::Value> = None;
        let mut raw_path_element: Option<&serde_json::Value> = None;
        let mut raw_search_param: Option<&serde_json::Value> = None;
        let mut raw_search_param_element: Option<&serde_json::Value> = None;
        let mut raw_value_set: Option<&serde_json::Value> = None;
        let mut raw_value_set_element: Option<&serde_json::Value> = None;
        let mut raw_code: Option<&serde_json::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => raw_id = Some(value),
                "extension" => raw_extension = Some(value),
                "path" => raw_path = Some(value),
                "_path" => raw_path_element = Some(value),
                "searchParam" => raw_search_param = Some(value),
                "_searchParam" => raw_search_param_element = Some(value),
                "valueSet" => raw_value_set = Some(value),
                "_valueSet" => raw_value_set_element = Some(value),
                "code" => raw_code = Some(value),
                other => {
                    return path.with(other, |path| {
                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
                    });
                }
            }
        }
        let field_id = raw_id
            .map(|value| {
                path.with("id", |path| {
                    let value = super::super::codec::expect_single(value, path)?;
                    super::super::codec::expect_string(value, path)
                })
            })
            .transpose()?;
        let mut field_extension = Vec::new();
        if let Some(raw) = raw_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_extension.push(path.with_index("extension", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_path = match (raw_path, raw_path_element) {
            (None, None) => None,
            (value, element) => Some(path.with("path", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_search_param = match (raw_search_param, raw_search_param_element) {
            (None, None) => None,
            (value, element) => Some(path.with("searchParam", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_value_set = match (raw_value_set, raw_value_set_element) {
            (None, None) => None,
            (value, element) => Some(path.with("valueSet", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let mut field_code = Vec::new();
        if let Some(raw) = raw_code {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_code.push(path.with_index("code", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        Ok(Self {
            id: field_id,
            extension: field_extension,
            path: field_path,
            search_param: field_search_param,
            value_set: field_value_set,
            code: field_code,
        })
    }
}

impl serde::Serialize for DataRequirementCodeFilter {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        super::super::codec::Json::to_json(self)
            .map_err(serde::ser::Error::custom)?
            .serialize(serializer)
    }
}

impl<'de> serde::Deserialize<'de> for DataRequirementCodeFilter {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = serde_json::Value::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("DataRequirementCodeFilter");
        let object =
            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
    }
}

/// What dates/date ranges are expected
///
/// Date filters specify additional constraints on the data in terms of the
/// applicable date range for specific elements. Each date filter specifies an
/// additional constraint on the data, i.e. date filters are AND'ed, not OR'ed.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DataRequirementDateFilter {
    /// Unique id for inter-element referencing
    ///
    /// Unique id for the element within a resource (for internal references). This
    /// may be any string value that does not contain spaces.
    pub id: Option<std::string::String>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element. To make the use of extensions safe and
    /// manageable, there is a strict set of governance applied to the definition
    /// and use of extensions. Though any implementer can define an extension, there
    /// is a set of requirements that SHALL be met as part of the definition of the
    /// extension.
    pub extension: Vec<super::extension::Extension>,
    /// A date-valued attribute to filter on
    ///
    /// The date-valued attribute of the filter. The specified path SHALL be a
    /// FHIRPath resolveable on the specified type of the DataRequirement, and SHALL
    /// consist only of identifiers, constant indexers, and .resolve(). The path is
    /// allowed to contain qualifiers (.) to traverse sub-elements, as well as
    /// indexers (\[x\]) to traverse multiple-cardinality sub-elements (see the
    /// \[Simple FHIRPath Profile\](fhirpath.html\#simple) for full details). Note
    /// that the index must be an integer constant. The path must resolve to an
    /// element of type date, dateTime, Period, Schedule, or Timing.
    pub path: Option<super::primitives::String>,
    /// A date valued parameter to search on
    ///
    /// A date parameter that refers to a search parameter defined on the specified
    /// type of the DataRequirement, and which searches on elements of type date,
    /// dateTime, Period, Schedule, or Timing.
    pub search_param: Option<super::primitives::String>,
    /// The value of the filter, as a Period, DateTime, or Duration value
    ///
    /// The value of the filter. If period is specified, the filter will return only
    /// those data items that fall within the bounds determined by the Period,
    /// inclusive of the period boundaries. If dateTime is specified, the filter
    /// will return only those data items that are equal to the specified dateTime.
    /// If a Duration is specified, the filter will return only those data items
    /// that fall within Duration before now.
    pub value: Option<DataRequirementDateFilterValue>,
}

impl super::super::codec::Json for DataRequirementDateFilter {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                serde_json::Value::String(v.clone()),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                serde_json::Value::Array(items),
            );
        }
        if let Some(item) = &self.path {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("path"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_path"), e);
            }
        }
        if let Some(item) = &self.search_param {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("searchParam"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_searchParam"), e);
            }
        }
        if let Some(item) = &self.value {
            let (suffix, value, element) = item.to_json_parts()?;
            if let Some(value) = value {
                object.insert(format!("value{suffix}"), value);
            }
            if let Some(element) = element {
                object.insert(format!("_value{suffix}"), element);
            }
        }
        Ok(object)
    }

    fn from_json(
        object: &super::super::codec::Object,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        let mut raw_id: Option<&serde_json::Value> = None;
        let mut raw_extension: Option<&serde_json::Value> = None;
        let mut raw_path: Option<&serde_json::Value> = None;
        let mut raw_path_element: Option<&serde_json::Value> = None;
        let mut raw_search_param: Option<&serde_json::Value> = None;
        let mut raw_search_param_element: Option<&serde_json::Value> = None;
        let mut raw_value = super::super::codec::ChoiceSlot::default();
        for (key, value) in object {
            match key.as_str() {
                "id" => raw_id = Some(value),
                "extension" => raw_extension = Some(value),
                "path" => raw_path = Some(value),
                "_path" => raw_path_element = Some(value),
                "searchParam" => raw_search_param = Some(value),
                "_searchParam" => raw_search_param_element = Some(value),
                "valueDateTime" => {
                    raw_value.value("DateTime", value, path)?;
                }
                "_valueDateTime" => {
                    raw_value.element("DateTime", value, path)?;
                }
                "valuePeriod" => {
                    raw_value.value("Period", value, path)?;
                }
                "_valuePeriod" => {
                    raw_value.element("Period", value, path)?;
                }
                "valueDuration" => {
                    raw_value.value("Duration", value, path)?;
                }
                "_valueDuration" => {
                    raw_value.element("Duration", value, path)?;
                }
                other => {
                    return path.with(other, |path| {
                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
                    });
                }
            }
        }
        let field_id = raw_id
            .map(|value| {
                path.with("id", |path| {
                    let value = super::super::codec::expect_single(value, path)?;
                    super::super::codec::expect_string(value, path)
                })
            })
            .transpose()?;
        let mut field_extension = Vec::new();
        if let Some(raw) = raw_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_extension.push(path.with_index("extension", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_path = match (raw_path, raw_path_element) {
            (None, None) => None,
            (value, element) => Some(path.with("path", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_search_param = match (raw_search_param, raw_search_param_element) {
            (None, None) => None,
            (value, element) => Some(path.with("searchParam", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_value = match raw_value.suffix {
            None => None,
            Some(suffix) => Some(path.with("value", |path| {
                DataRequirementDateFilterValue::from_json_parts(
                    suffix,
                    raw_value.value,
                    raw_value.element,
                    path,
                )
            })?),
        };
        Ok(Self {
            id: field_id,
            extension: field_extension,
            path: field_path,
            search_param: field_search_param,
            value: field_value,
        })
    }
}

impl serde::Serialize for DataRequirementDateFilter {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        super::super::codec::Json::to_json(self)
            .map_err(serde::ser::Error::custom)?
            .serialize(serializer)
    }
}

impl<'de> serde::Deserialize<'de> for DataRequirementDateFilter {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = serde_json::Value::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("DataRequirementDateFilter");
        let object =
            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
    }
}

/// The \`value\[x\]\` choice of \`DataRequirementDateFilter\`.
///
/// The value of the filter. If period is specified, the filter will return only
/// those data items that fall within the bounds determined by the Period,
/// inclusive of the period boundaries. If dateTime is specified, the filter
/// will return only those data items that are equal to the specified dateTime.
/// If a Duration is specified, the filter will return only those data items
/// that fall within Duration before now.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DataRequirementDateFilterValue {
    /// The `dateTime` form.
    DateTime(super::primitives::DateTime),
    /// The `Period` form.
    Period(super::period::Period),
    /// The `Duration` form.
    Duration(super::duration::Duration),
}

impl DataRequirementDateFilterValue {
    /// The key suffix, the value part, and the `_name` part of this form.
    ///
    /// # Errors
    ///
    /// Returns [`super::super::codec::EncodeError`] when a held value has no JSON form.
    pub fn to_json_parts(
        &self,
    ) -> Result<
        (
            &'static str,
            Option<serde_json::Value>,
            Option<serde_json::Value>,
        ),
        super::super::codec::EncodeError,
    > {
        match self {
            Self::DateTime(inner) => Ok((
                "DateTime",
                super::super::codec::Primitive::value_json(inner)?,
                super::super::codec::Primitive::element_json(inner)?,
            )),
            Self::Period(inner) => Ok((
                "Period",
                Some(serde_json::Value::Object(
                    super::super::codec::Json::to_json(inner)?,
                )),
                None,
            )),
            Self::Duration(inner) => Ok((
                "Duration",
                Some(serde_json::Value::Object(
                    super::super::codec::Json::to_json(inner)?,
                )),
                None,
            )),
        }
    }

    /// Decodes the form named by `suffix` from its value and `_name` parts.
    ///
    /// # Errors
    ///
    /// Returns [`super::super::codec::DecodeError`] for an unknown suffix or a malformed part.
    pub fn from_json_parts(
        suffix: &str,
        value: Option<&serde_json::Value>,
        element: Option<&serde_json::Value>,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        match suffix {
            "DateTime" => Ok(Self::DateTime(
                super::super::codec::Primitive::from_json_parts(value, element, path)?,
            )),
            "Period" => {
                if element.is_some() {
                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
                        expected: "no underscore form for a complex type",
                    }));
                }
                let value = value.ok_or_else(|| {
                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
                })?;
                let inner = super::super::codec::Json::from_json(
                    super::super::codec::expect_object(
                        super::super::codec::expect_single(value, path)?,
                        path,
                    )?,
                    path,
                )?;
                Ok(Self::Period(inner))
            }
            "Duration" => {
                if element.is_some() {
                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
                        expected: "no underscore form for a complex type",
                    }));
                }
                let value = value.ok_or_else(|| {
                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
                })?;
                let inner = super::super::codec::Json::from_json(
                    super::super::codec::expect_object(
                        super::super::codec::expect_single(value, path)?,
                        path,
                    )?,
                    path,
                )?;
                Ok(Self::Duration(inner))
            }
            _ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
        }
    }
}

/// Order of the results
///
/// Specifies the order of the results to be returned.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DataRequirementSort {
    /// Unique id for inter-element referencing
    ///
    /// Unique id for the element within a resource (for internal references). This
    /// may be any string value that does not contain spaces.
    pub id: Option<std::string::String>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element. To make the use of extensions safe and
    /// manageable, there is a strict set of governance applied to the definition
    /// and use of extensions. Though any implementer can define an extension, there
    /// is a set of requirements that SHALL be met as part of the definition of the
    /// extension.
    pub extension: Vec<super::extension::Extension>,
    /// The name of the attribute to perform the sort
    ///
    /// The attribute of the sort. The specified path must be resolvable from the
    /// type of the required data. The path is allowed to contain qualifiers (.) to
    /// traverse sub-elements, as well as indexers (\[x\]) to traverse
    /// multiple-cardinality sub-elements. Note that the index must be an integer
    /// constant.
    pub path: super::primitives::String,
    /// ascending | descending
    ///
    /// The direction of the sort, ascending or descending.
    pub direction: super::primitives::Code,
}

impl super::super::codec::Json for DataRequirementSort {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                serde_json::Value::String(v.clone()),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(serde_json::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                serde_json::Value::Array(items),
            );
        }
        if let Some(v) = super::super::codec::Primitive::value_json(&self.path)? {
            object.insert(std::string::String::from("path"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.path)? {
            object.insert(std::string::String::from("_path"), e);
        }
        if let Some(v) = super::super::codec::Primitive::value_json(&self.direction)? {
            object.insert(std::string::String::from("direction"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.direction)? {
            object.insert(std::string::String::from("_direction"), e);
        }
        Ok(object)
    }

    fn from_json(
        object: &super::super::codec::Object,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        let mut raw_id: Option<&serde_json::Value> = None;
        let mut raw_extension: Option<&serde_json::Value> = None;
        let mut raw_path: Option<&serde_json::Value> = None;
        let mut raw_path_element: Option<&serde_json::Value> = None;
        let mut raw_direction: Option<&serde_json::Value> = None;
        let mut raw_direction_element: Option<&serde_json::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => raw_id = Some(value),
                "extension" => raw_extension = Some(value),
                "path" => raw_path = Some(value),
                "_path" => raw_path_element = Some(value),
                "direction" => raw_direction = Some(value),
                "_direction" => raw_direction_element = Some(value),
                other => {
                    return path.with(other, |path| {
                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
                    });
                }
            }
        }
        let field_id = raw_id
            .map(|value| {
                path.with("id", |path| {
                    let value = super::super::codec::expect_single(value, path)?;
                    super::super::codec::expect_string(value, path)
                })
            })
            .transpose()?;
        let mut field_extension = Vec::new();
        if let Some(raw) = raw_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_extension.push(path.with_index("extension", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_path = path.with("path", |path| {
            super::super::codec::Primitive::from_json_parts(raw_path, raw_path_element, path)
        })?;
        let field_direction = path.with("direction", |path| {
            super::super::codec::Primitive::from_json_parts(
                raw_direction,
                raw_direction_element,
                path,
            )
        })?;
        Ok(Self {
            id: field_id,
            extension: field_extension,
            path: field_path,
            direction: field_direction,
        })
    }
}

impl serde::Serialize for DataRequirementSort {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        super::super::codec::Json::to_json(self)
            .map_err(serde::ser::Error::custom)?
            .serialize(serializer)
    }
}

impl<'de> serde::Deserialize<'de> for DataRequirementSort {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = serde_json::Value::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("DataRequirementSort");
        let object =
            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
    }
}

/// The \`subject\[x\]\` choice of \`DataRequirement\`.
///
/// The intended subjects of the data requirement. If this element is not
/// provided, a Patient subject is assumed.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DataRequirementSubject {
    /// The `CodeableConcept` form.
    CodeableConcept(super::codeable_concept::CodeableConcept),
    /// The `Reference` form.
    Reference(super::reference::Reference),
}

impl DataRequirementSubject {
    /// The key suffix, the value part, and the `_name` part of this form.
    ///
    /// # Errors
    ///
    /// Returns [`super::super::codec::EncodeError`] when a held value has no JSON form.
    pub fn to_json_parts(
        &self,
    ) -> Result<
        (
            &'static str,
            Option<serde_json::Value>,
            Option<serde_json::Value>,
        ),
        super::super::codec::EncodeError,
    > {
        match self {
            Self::CodeableConcept(inner) => Ok((
                "CodeableConcept",
                Some(serde_json::Value::Object(
                    super::super::codec::Json::to_json(inner)?,
                )),
                None,
            )),
            Self::Reference(inner) => Ok((
                "Reference",
                Some(serde_json::Value::Object(
                    super::super::codec::Json::to_json(inner)?,
                )),
                None,
            )),
        }
    }

    /// Decodes the form named by `suffix` from its value and `_name` parts.
    ///
    /// # Errors
    ///
    /// Returns [`super::super::codec::DecodeError`] for an unknown suffix or a malformed part.
    pub fn from_json_parts(
        suffix: &str,
        value: Option<&serde_json::Value>,
        element: Option<&serde_json::Value>,
        path: &mut super::super::codec::Path,
    ) -> Result<Self, super::super::codec::DecodeError> {
        match suffix {
            "CodeableConcept" => {
                if element.is_some() {
                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
                        expected: "no underscore form for a complex type",
                    }));
                }
                let value = value.ok_or_else(|| {
                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
                })?;
                let inner = super::super::codec::Json::from_json(
                    super::super::codec::expect_object(
                        super::super::codec::expect_single(value, path)?,
                        path,
                    )?,
                    path,
                )?;
                Ok(Self::CodeableConcept(inner))
            }
            "Reference" => {
                if element.is_some() {
                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
                        expected: "no underscore form for a complex type",
                    }));
                }
                let value = value.ok_or_else(|| {
                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
                })?;
                let inner = super::super::codec::Json::from_json(
                    super::super::codec::expect_object(
                        super::super::codec::expect_single(value, path)?,
                        path,
                    )?,
                    path,
                )?;
                Ok(Self::Reference(inner))
            }
            _ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
        }
    }
}