fhir-types 0.1.102

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
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
// @generated by fhir-codegen from hl7.fhir.r4b.core 4.3.0. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
// SPDX-FileCopyrightText: Ruben Talstra
// SPDX-License-Identifier: Apache-2.0
//! Definition of an observation

/// Definition of an observation
///
/// Set of definitional characteristics for a kind of observation or measurement
/// produced or consumed by an orderable health care service.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ObservationDefinition {
    /// Logical id of this artifact
    ///
    /// The logical id of the resource, as used in the URL for the resource. Once
    /// assigned, this value never changes.
    pub id: Option<std::string::String>,
    /// Metadata about the resource
    ///
    /// The metadata about the resource. This is content that is maintained by the
    /// infrastructure. Changes to the content might not always be associated with
    /// version changes to the resource.
    pub meta: Option<super::meta::Meta>,
    /// A set of rules under which this content was created
    ///
    /// A reference to a set of rules that were followed when the resource was
    /// constructed, and which must be understood when processing the content.
    /// Often, this is a reference to an implementation guide that defines the
    /// special rules along with other profiles etc.
    pub implicit_rules: Option<super::primitives::Uri>,
    /// Language of the resource content
    ///
    /// The base language in which the resource is written.
    pub language: Option<super::primitives::Code>,
    /// Text summary of the resource, for human interpretation
    ///
    /// A human-readable narrative that contains a summary of the resource and can
    /// be used to represent the content of the resource to a human. The narrative
    /// need not encode all the structured data, but is required to contain
    /// sufficient detail to make it "clinically safe" for a human to just read the
    /// narrative. Resource definitions may define what content should be
    /// represented in the narrative to ensure clinical safety.
    pub text: Option<super::narrative::Narrative>,
    /// Contained, inline Resources
    ///
    /// These resources do not have an independent existence apart from the resource
    /// that contains them - they cannot be identified independently, and nor can
    /// they have their own independent transaction scope.
    pub contained: Vec<super::resource::Resource>,
    /// Additional content defined by implementations
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the resource. 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>,
    /// Extensions that cannot be ignored
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the resource and that modifies the understanding of the
    /// element that contains it and/or the understanding of the containing
    /// element's descendants. Usually modifier elements provide negation or
    /// qualification. 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 is allowed to define an extension, there is a set of
    /// requirements that SHALL be met as part of the definition of the extension.
    /// Applications processing a resource are required to check for modifier
    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
    /// on Resource or DomainResource (including cannot change the meaning of
    /// modifierExtension itself).
    pub modifier_extension: Vec<super::extension::Extension>,
    /// Category of observation
    ///
    /// A code that classifies the general type of observation.
    pub category: Vec<super::codeable_concept::CodeableConcept>,
    /// Type of observation (code / type)
    ///
    /// Describes what will be observed. Sometimes this is called the observation
    /// "name".
    pub code: super::codeable_concept::CodeableConcept,
    /// Business identifier for this ObservationDefinition instance
    ///
    /// A unique identifier assigned to this ObservationDefinition artifact.
    pub identifier: Vec<super::identifier::Identifier>,
    /// Quantity | CodeableConcept | string | boolean | integer | Range | Ratio |
    /// SampledData | time | dateTime | Period
    ///
    /// The data types allowed for the value element of the instance observations
    /// conforming to this ObservationDefinition.
    pub permitted_data_type: Vec<super::primitives::Code>,
    /// Multiple results allowed
    ///
    /// Multiple results allowed for observations conforming to this
    /// ObservationDefinition.
    pub multiple_results_allowed: Option<super::primitives::Boolean>,
    /// Method used to produce the observation
    ///
    /// The method or technique used to perform the observation.
    pub method: Option<super::codeable_concept::CodeableConcept>,
    /// Preferred report name
    ///
    /// The preferred name to be used when reporting the results of observations
    /// conforming to this ObservationDefinition.
    pub preferred_report_name: Option<super::primitives::String>,
    /// Characteristics of quantitative results
    ///
    /// Characteristics for quantitative results of this observation.
    pub quantitative_details: Option<ObservationDefinitionQuantitativeDetails>,
    /// Qualified range for continuous and ordinal observation results
    ///
    /// Multiple ranges of results qualified by different contexts for ordinal or
    /// continuous observations conforming to this ObservationDefinition.
    pub qualified_interval: Vec<ObservationDefinitionQualifiedInterval>,
    /// Value set of valid coded values for the observations conforming to this
    /// ObservationDefinition
    ///
    /// The set of valid coded results for the observations conforming to this
    /// ObservationDefinition.
    pub valid_coded_value_set: Option<super::reference::Reference>,
    /// Value set of normal coded values for the observations conforming to this
    /// ObservationDefinition
    ///
    /// The set of normal coded results for the observations conforming to this
    /// ObservationDefinition.
    pub normal_coded_value_set: Option<super::reference::Reference>,
    /// Value set of abnormal coded values for the observations conforming to this
    /// ObservationDefinition
    ///
    /// The set of abnormal coded results for the observation conforming to this
    /// ObservationDefinition.
    pub abnormal_coded_value_set: Option<super::reference::Reference>,
    /// Value set of critical coded values for the observations conforming to this
    /// ObservationDefinition
    ///
    /// The set of critical coded results for the observation conforming to this
    /// ObservationDefinition.
    pub critical_coded_value_set: Option<super::reference::Reference>,
}

impl super::super::codec::Json for ObservationDefinition {
    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
        let mut object = super::super::codec::Object::new();
        object.insert(
            std::string::String::from("resourceType"),
            super::super::codec::Value::String(std::string::String::from("ObservationDefinition")),
        );
        if let Some(v) = &self.id {
            object.insert(
                std::string::String::from("id"),
                super::super::codec::Value::String(v.clone()),
            );
        }
        if let Some(item) = &self.meta {
            object.insert(
                std::string::String::from("meta"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.implicit_rules {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("implicitRules"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_implicitRules"), e);
            }
        }
        if let Some(item) = &self.language {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("language"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_language"), e);
            }
        }
        if let Some(item) = &self.text {
            object.insert(
                std::string::String::from("text"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if !self.contained.is_empty() {
            let mut items = Vec::with_capacity(self.contained.len());
            for item in &self.contained {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("contained"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.extension.is_empty() {
            let mut items = Vec::with_capacity(self.extension.len());
            for item in &self.extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.modifier_extension.is_empty() {
            let mut items = Vec::with_capacity(self.modifier_extension.len());
            for item in &self.modifier_extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("modifierExtension"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.category.is_empty() {
            let mut items = Vec::with_capacity(self.category.len());
            for item in &self.category {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("category"),
                super::super::codec::Value::Array(items),
            );
        }
        object.insert(
            std::string::String::from("code"),
            super::super::codec::Value::Object(super::super::codec::Json::to_json(&self.code)?),
        );
        if !self.identifier.is_empty() {
            let mut items = Vec::with_capacity(self.identifier.len());
            for item in &self.identifier {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("identifier"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.permitted_data_type.is_empty() {
            let (values, elements) =
                super::super::codec::primitive_arrays(&self.permitted_data_type)?;
            object.insert(std::string::String::from("permittedDataType"), values);
            if let Some(elements) = elements {
                object.insert(std::string::String::from("_permittedDataType"), elements);
            }
        }
        if let Some(item) = &self.multiple_results_allowed {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("multipleResultsAllowed"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_multipleResultsAllowed"), e);
            }
        }
        if let Some(item) = &self.method {
            object.insert(
                std::string::String::from("method"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.preferred_report_name {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("preferredReportName"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_preferredReportName"), e);
            }
        }
        if let Some(item) = &self.quantitative_details {
            object.insert(
                std::string::String::from("quantitativeDetails"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if !self.qualified_interval.is_empty() {
            let mut items = Vec::with_capacity(self.qualified_interval.len());
            for item in &self.qualified_interval {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("qualifiedInterval"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.valid_coded_value_set {
            object.insert(
                std::string::String::from("validCodedValueSet"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.normal_coded_value_set {
            object.insert(
                std::string::String::from("normalCodedValueSet"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.abnormal_coded_value_set {
            object.insert(
                std::string::String::from("abnormalCodedValueSet"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.critical_coded_value_set {
            object.insert(
                std::string::String::from("criticalCodedValueSet"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        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<&super::super::codec::Value> = None;
        let mut raw_meta: Option<&super::super::codec::Value> = None;
        let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
        let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
        let mut raw_language: Option<&super::super::codec::Value> = None;
        let mut raw_language_element: Option<&super::super::codec::Value> = None;
        let mut raw_text: Option<&super::super::codec::Value> = None;
        let mut raw_contained: Option<&super::super::codec::Value> = None;
        let mut raw_extension: Option<&super::super::codec::Value> = None;
        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
        let mut raw_category: Option<&super::super::codec::Value> = None;
        let mut raw_code: Option<&super::super::codec::Value> = None;
        let mut raw_identifier: Option<&super::super::codec::Value> = None;
        let mut raw_permitted_data_type: Option<&super::super::codec::Value> = None;
        let mut raw_permitted_data_type_element: Option<&super::super::codec::Value> = None;
        let mut raw_multiple_results_allowed: Option<&super::super::codec::Value> = None;
        let mut raw_multiple_results_allowed_element: Option<&super::super::codec::Value> = None;
        let mut raw_method: Option<&super::super::codec::Value> = None;
        let mut raw_preferred_report_name: Option<&super::super::codec::Value> = None;
        let mut raw_preferred_report_name_element: Option<&super::super::codec::Value> = None;
        let mut raw_quantitative_details: Option<&super::super::codec::Value> = None;
        let mut raw_qualified_interval: Option<&super::super::codec::Value> = None;
        let mut raw_valid_coded_value_set: Option<&super::super::codec::Value> = None;
        let mut raw_normal_coded_value_set: Option<&super::super::codec::Value> = None;
        let mut raw_abnormal_coded_value_set: Option<&super::super::codec::Value> = None;
        let mut raw_critical_coded_value_set: Option<&super::super::codec::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "resourceType" => {
                    if value.as_str() != Some("ObservationDefinition") {
                        return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
                    }
                }
                "id" => {
                    raw_id = Some(value);
                }
                "meta" => {
                    raw_meta = Some(value);
                }
                "implicitRules" => {
                    raw_implicit_rules = Some(value);
                }
                "_implicitRules" => {
                    raw_implicit_rules_element = Some(value);
                }
                "language" => {
                    raw_language = Some(value);
                }
                "_language" => {
                    raw_language_element = Some(value);
                }
                "text" => {
                    raw_text = Some(value);
                }
                "contained" => {
                    raw_contained = Some(value);
                }
                "extension" => {
                    raw_extension = Some(value);
                }
                "modifierExtension" => {
                    raw_modifier_extension = Some(value);
                }
                "category" => {
                    raw_category = Some(value);
                }
                "code" => {
                    raw_code = Some(value);
                }
                "identifier" => {
                    raw_identifier = Some(value);
                }
                "permittedDataType" => {
                    raw_permitted_data_type = Some(value);
                }
                "_permittedDataType" => {
                    raw_permitted_data_type_element = Some(value);
                }
                "multipleResultsAllowed" => {
                    raw_multiple_results_allowed = Some(value);
                }
                "_multipleResultsAllowed" => {
                    raw_multiple_results_allowed_element = Some(value);
                }
                "method" => {
                    raw_method = Some(value);
                }
                "preferredReportName" => {
                    raw_preferred_report_name = Some(value);
                }
                "_preferredReportName" => {
                    raw_preferred_report_name_element = Some(value);
                }
                "quantitativeDetails" => {
                    raw_quantitative_details = Some(value);
                }
                "qualifiedInterval" => {
                    raw_qualified_interval = Some(value);
                }
                "validCodedValueSet" => {
                    raw_valid_coded_value_set = Some(value);
                }
                "normalCodedValueSet" => {
                    raw_normal_coded_value_set = Some(value);
                }
                "abnormalCodedValueSet" => {
                    raw_abnormal_coded_value_set = Some(value);
                }
                "criticalCodedValueSet" => {
                    raw_critical_coded_value_set = 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 field_meta = raw_meta
            .map(|value| {
                path.with("meta", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
            (None, None) => None,
            (value, element) => Some(path.with("implicitRules", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_language = match (raw_language, raw_language_element) {
            (None, None) => None,
            (value, element) => Some(path.with("language", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_text = raw_text
            .map(|value| {
                path.with("text", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let mut field_contained = Vec::new();
        if let Some(raw) = raw_contained {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_contained.push(path.with_index("contained", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        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 mut field_modifier_extension = Vec::new();
        if let Some(raw) = raw_modifier_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_modifier_extension.push(path.with_index(
                    "modifierExtension",
                    index,
                    |path| {
                        super::super::codec::Json::from_json(
                            super::super::codec::expect_object(value, path)?,
                            path,
                        )
                    },
                )?);
            }
        }
        let mut field_category = Vec::new();
        if let Some(raw) = raw_category {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_category.push(path.with_index("category", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_code = path.with("code", |path| {
            let value = raw_code
                .ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
            super::super::codec::Json::from_json(
                super::super::codec::expect_object(
                    super::super::codec::expect_single(value, path)?,
                    path,
                )?,
                path,
            )
        })?;
        let mut field_identifier = Vec::new();
        if let Some(raw) = raw_identifier {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_identifier.push(path.with_index("identifier", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let mut field_permitted_data_type = Vec::new();
        for (index, (value, element)) in super::super::codec::pair_arrays(
            raw_permitted_data_type,
            raw_permitted_data_type_element,
            path,
        )?
        .into_iter()
        .enumerate()
        {
            field_permitted_data_type.push(path.with_index(
                "permittedDataType",
                index,
                |path| super::super::codec::Primitive::from_json_parts(value, element, path),
            )?);
        }
        let field_multiple_results_allowed = match (
            raw_multiple_results_allowed,
            raw_multiple_results_allowed_element,
        ) {
            (None, None) => None,
            (value, element) => Some(path.with("multipleResultsAllowed", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_method = raw_method
            .map(|value| {
                path.with("method", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_preferred_report_name =
            match (raw_preferred_report_name, raw_preferred_report_name_element) {
                (None, None) => None,
                (value, element) => Some(path.with("preferredReportName", |path| {
                    super::super::codec::Primitive::from_json_parts(value, element, path)
                })?),
            };
        let field_quantitative_details = raw_quantitative_details
            .map(|value| {
                path.with("quantitativeDetails", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let mut field_qualified_interval = Vec::new();
        if let Some(raw) = raw_qualified_interval {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_qualified_interval.push(path.with_index(
                    "qualifiedInterval",
                    index,
                    |path| {
                        super::super::codec::Json::from_json(
                            super::super::codec::expect_object(value, path)?,
                            path,
                        )
                    },
                )?);
            }
        }
        let field_valid_coded_value_set = raw_valid_coded_value_set
            .map(|value| {
                path.with("validCodedValueSet", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_normal_coded_value_set = raw_normal_coded_value_set
            .map(|value| {
                path.with("normalCodedValueSet", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_abnormal_coded_value_set = raw_abnormal_coded_value_set
            .map(|value| {
                path.with("abnormalCodedValueSet", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_critical_coded_value_set = raw_critical_coded_value_set
            .map(|value| {
                path.with("criticalCodedValueSet", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        Ok(Self {
            id: field_id,
            meta: field_meta,
            implicit_rules: field_implicit_rules,
            language: field_language,
            text: field_text,
            contained: field_contained,
            extension: field_extension,
            modifier_extension: field_modifier_extension,
            category: field_category,
            code: field_code,
            identifier: field_identifier,
            permitted_data_type: field_permitted_data_type,
            multiple_results_allowed: field_multiple_results_allowed,
            method: field_method,
            preferred_report_name: field_preferred_report_name,
            quantitative_details: field_quantitative_details,
            qualified_interval: field_qualified_interval,
            valid_coded_value_set: field_valid_coded_value_set,
            normal_coded_value_set: field_normal_coded_value_set,
            abnormal_coded_value_set: field_abnormal_coded_value_set,
            critical_coded_value_set: field_critical_coded_value_set,
        })
    }
}

impl serde::Serialize for ObservationDefinition {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        if let Some(item) = &self.implicit_rules {
            super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
        }
        if let Some(item) = &self.language {
            super::super::codec::element_entry(&mut map, "_language", item)?;
        }
        if let Some(item) = &self.multiple_results_allowed {
            super::super::codec::element_entry(&mut map, "_multipleResultsAllowed", item)?;
        }
        super::super::codec::element_list_entry(
            &mut map,
            "_permittedDataType",
            &self.permitted_data_type,
        )?;
        if let Some(item) = &self.preferred_report_name {
            super::super::codec::element_entry(&mut map, "_preferredReportName", item)?;
        }
        if let Some(item) = &self.abnormal_coded_value_set {
            serde::ser::SerializeMap::serialize_entry(&mut map, "abnormalCodedValueSet", item)?;
        }
        if !self.category.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "category", &self.category)?;
        }
        serde::ser::SerializeMap::serialize_entry(&mut map, "code", &self.code)?;
        if !self.contained.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
        }
        if let Some(item) = &self.critical_coded_value_set {
            serde::ser::SerializeMap::serialize_entry(&mut map, "criticalCodedValueSet", item)?;
        }
        if !self.extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
        }
        if let Some(v) = &self.id {
            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
        }
        if !self.identifier.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
        }
        if let Some(item) = &self.implicit_rules {
            super::super::codec::value_entry(&mut map, "implicitRules", item)?;
        }
        if let Some(item) = &self.language {
            super::super::codec::value_entry(&mut map, "language", item)?;
        }
        if let Some(item) = &self.meta {
            serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
        }
        if let Some(item) = &self.method {
            serde::ser::SerializeMap::serialize_entry(&mut map, "method", item)?;
        }
        if !self.modifier_extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "modifierExtension",
                &self.modifier_extension,
            )?;
        }
        if let Some(item) = &self.multiple_results_allowed {
            super::super::codec::value_entry(&mut map, "multipleResultsAllowed", item)?;
        }
        if let Some(item) = &self.normal_coded_value_set {
            serde::ser::SerializeMap::serialize_entry(&mut map, "normalCodedValueSet", item)?;
        }
        super::super::codec::value_list_entry(
            &mut map,
            "permittedDataType",
            &self.permitted_data_type,
        )?;
        if let Some(item) = &self.preferred_report_name {
            super::super::codec::value_entry(&mut map, "preferredReportName", item)?;
        }
        if !self.qualified_interval.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "qualifiedInterval",
                &self.qualified_interval,
            )?;
        }
        if let Some(item) = &self.quantitative_details {
            serde::ser::SerializeMap::serialize_entry(&mut map, "quantitativeDetails", item)?;
        }
        serde::ser::SerializeMap::serialize_entry(
            &mut map,
            "resourceType",
            "ObservationDefinition",
        )?;
        if let Some(item) = &self.text {
            serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
        }
        if let Some(item) = &self.valid_coded_value_set {
            serde::ser::SerializeMap::serialize_entry(&mut map, "validCodedValueSet", item)?;
        }
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for ObservationDefinition {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("ObservationDefinition");
        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)
    }
}

/// Qualified range for continuous and ordinal observation results
///
/// Multiple ranges of results qualified by different contexts for ordinal or
/// continuous observations conforming to this ObservationDefinition.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ObservationDefinitionQualifiedInterval {
    /// 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>,
    /// Extensions that cannot be ignored even if unrecognized
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element and that modifies the understanding of the
    /// element in which it is contained and/or the understanding of the containing
    /// element's descendants. Usually modifier elements provide negation or
    /// qualification. 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.
    /// Applications processing a resource are required to check for modifier
    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
    /// on Resource or DomainResource (including cannot change the meaning of
    /// modifierExtension itself).
    pub modifier_extension: Vec<super::extension::Extension>,
    /// reference | critical | absolute
    ///
    /// The category of interval of values for continuous or ordinal observations
    /// conforming to this ObservationDefinition.
    pub category: Option<super::primitives::Code>,
    /// The interval itself, for continuous or ordinal observations
    ///
    /// The low and high values determining the interval. There may be only one of
    /// the two.
    pub range: Option<super::range::Range>,
    /// Range context qualifier
    ///
    /// Codes to indicate the health context the range applies to. For example, the
    /// normal or therapeutic range.
    pub context: Option<super::codeable_concept::CodeableConcept>,
    /// Targetted population of the range
    ///
    /// Codes to indicate the target population this reference range applies to.
    pub applies_to: Vec<super::codeable_concept::CodeableConcept>,
    /// male | female | other | unknown
    ///
    /// Sex of the population the range applies to.
    pub gender: Option<super::primitives::Code>,
    /// Applicable age range, if relevant
    ///
    /// The age at which this reference range is applicable. This is a neonatal age
    /// (e.g. number of weeks at term) if the meaning says so.
    pub age: Option<super::range::Range>,
    /// Applicable gestational age range, if relevant
    ///
    /// The gestational age to which this reference range is applicable, in the
    /// context of pregnancy.
    pub gestational_age: Option<super::range::Range>,
    /// Condition associated with the reference range
    ///
    /// Text based condition for which the reference range is valid.
    pub condition: Option<super::primitives::String>,
}

impl super::super::codec::Json for ObservationDefinitionQualifiedInterval {
    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"),
                super::super::codec::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(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.modifier_extension.is_empty() {
            let mut items = Vec::with_capacity(self.modifier_extension.len());
            for item in &self.modifier_extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("modifierExtension"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.category {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("category"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_category"), e);
            }
        }
        if let Some(item) = &self.range {
            object.insert(
                std::string::String::from("range"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.context {
            object.insert(
                std::string::String::from("context"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if !self.applies_to.is_empty() {
            let mut items = Vec::with_capacity(self.applies_to.len());
            for item in &self.applies_to {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("appliesTo"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.gender {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("gender"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_gender"), e);
            }
        }
        if let Some(item) = &self.age {
            object.insert(
                std::string::String::from("age"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.gestational_age {
            object.insert(
                std::string::String::from("gestationalAge"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.condition {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("condition"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_condition"), 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<&super::super::codec::Value> = None;
        let mut raw_extension: Option<&super::super::codec::Value> = None;
        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
        let mut raw_category: Option<&super::super::codec::Value> = None;
        let mut raw_category_element: Option<&super::super::codec::Value> = None;
        let mut raw_range: Option<&super::super::codec::Value> = None;
        let mut raw_context: Option<&super::super::codec::Value> = None;
        let mut raw_applies_to: Option<&super::super::codec::Value> = None;
        let mut raw_gender: Option<&super::super::codec::Value> = None;
        let mut raw_gender_element: Option<&super::super::codec::Value> = None;
        let mut raw_age: Option<&super::super::codec::Value> = None;
        let mut raw_gestational_age: Option<&super::super::codec::Value> = None;
        let mut raw_condition: Option<&super::super::codec::Value> = None;
        let mut raw_condition_element: Option<&super::super::codec::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => {
                    raw_id = Some(value);
                }
                "extension" => {
                    raw_extension = Some(value);
                }
                "modifierExtension" => {
                    raw_modifier_extension = Some(value);
                }
                "category" => {
                    raw_category = Some(value);
                }
                "_category" => {
                    raw_category_element = Some(value);
                }
                "range" => {
                    raw_range = Some(value);
                }
                "context" => {
                    raw_context = Some(value);
                }
                "appliesTo" => {
                    raw_applies_to = Some(value);
                }
                "gender" => {
                    raw_gender = Some(value);
                }
                "_gender" => {
                    raw_gender_element = Some(value);
                }
                "age" => {
                    raw_age = Some(value);
                }
                "gestationalAge" => {
                    raw_gestational_age = Some(value);
                }
                "condition" => {
                    raw_condition = Some(value);
                }
                "_condition" => {
                    raw_condition_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 mut field_modifier_extension = Vec::new();
        if let Some(raw) = raw_modifier_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_modifier_extension.push(path.with_index(
                    "modifierExtension",
                    index,
                    |path| {
                        super::super::codec::Json::from_json(
                            super::super::codec::expect_object(value, path)?,
                            path,
                        )
                    },
                )?);
            }
        }
        let field_category = match (raw_category, raw_category_element) {
            (None, None) => None,
            (value, element) => Some(path.with("category", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_range = raw_range
            .map(|value| {
                path.with("range", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_context = raw_context
            .map(|value| {
                path.with("context", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let mut field_applies_to = Vec::new();
        if let Some(raw) = raw_applies_to {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_applies_to.push(path.with_index("appliesTo", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_gender = match (raw_gender, raw_gender_element) {
            (None, None) => None,
            (value, element) => Some(path.with("gender", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_age = raw_age
            .map(|value| {
                path.with("age", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_gestational_age = raw_gestational_age
            .map(|value| {
                path.with("gestationalAge", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_condition = match (raw_condition, raw_condition_element) {
            (None, None) => None,
            (value, element) => Some(path.with("condition", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        Ok(Self {
            id: field_id,
            extension: field_extension,
            modifier_extension: field_modifier_extension,
            category: field_category,
            range: field_range,
            context: field_context,
            applies_to: field_applies_to,
            gender: field_gender,
            age: field_age,
            gestational_age: field_gestational_age,
            condition: field_condition,
        })
    }
}

impl serde::Serialize for ObservationDefinitionQualifiedInterval {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        if let Some(item) = &self.category {
            super::super::codec::element_entry(&mut map, "_category", item)?;
        }
        if let Some(item) = &self.condition {
            super::super::codec::element_entry(&mut map, "_condition", item)?;
        }
        if let Some(item) = &self.gender {
            super::super::codec::element_entry(&mut map, "_gender", item)?;
        }
        if let Some(item) = &self.age {
            serde::ser::SerializeMap::serialize_entry(&mut map, "age", item)?;
        }
        if !self.applies_to.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "appliesTo", &self.applies_to)?;
        }
        if let Some(item) = &self.category {
            super::super::codec::value_entry(&mut map, "category", item)?;
        }
        if let Some(item) = &self.condition {
            super::super::codec::value_entry(&mut map, "condition", item)?;
        }
        if let Some(item) = &self.context {
            serde::ser::SerializeMap::serialize_entry(&mut map, "context", item)?;
        }
        if !self.extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
        }
        if let Some(item) = &self.gender {
            super::super::codec::value_entry(&mut map, "gender", item)?;
        }
        if let Some(item) = &self.gestational_age {
            serde::ser::SerializeMap::serialize_entry(&mut map, "gestationalAge", item)?;
        }
        if let Some(v) = &self.id {
            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
        }
        if !self.modifier_extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "modifierExtension",
                &self.modifier_extension,
            )?;
        }
        if let Some(item) = &self.range {
            serde::ser::SerializeMap::serialize_entry(&mut map, "range", item)?;
        }
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for ObservationDefinitionQualifiedInterval {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("ObservationDefinitionQualifiedInterval");
        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)
    }
}

/// Characteristics of quantitative results
///
/// Characteristics for quantitative results of this observation.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ObservationDefinitionQuantitativeDetails {
    /// 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>,
    /// Extensions that cannot be ignored even if unrecognized
    ///
    /// May be used to represent additional information that is not part of the
    /// basic definition of the element and that modifies the understanding of the
    /// element in which it is contained and/or the understanding of the containing
    /// element's descendants. Usually modifier elements provide negation or
    /// qualification. 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.
    /// Applications processing a resource are required to check for modifier
    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
    /// on Resource or DomainResource (including cannot change the meaning of
    /// modifierExtension itself).
    pub modifier_extension: Vec<super::extension::Extension>,
    /// Customary unit for quantitative results
    ///
    /// Customary unit used to report quantitative results of observations
    /// conforming to this ObservationDefinition.
    pub customary_unit: Option<super::codeable_concept::CodeableConcept>,
    /// SI unit for quantitative results
    ///
    /// SI unit used to report quantitative results of observations conforming to
    /// this ObservationDefinition.
    pub unit: Option<super::codeable_concept::CodeableConcept>,
    /// SI to Customary unit conversion factor
    ///
    /// Factor for converting value expressed with SI unit to value expressed with
    /// customary unit.
    pub conversion_factor: Option<super::primitives::Decimal>,
    /// Decimal precision of observation quantitative results
    ///
    /// Number of digits after decimal separator when the results of such
    /// observations are of type Quantity.
    pub decimal_precision: Option<super::primitives::Integer>,
}

impl super::super::codec::Json for ObservationDefinitionQuantitativeDetails {
    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"),
                super::super::codec::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(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("extension"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.modifier_extension.is_empty() {
            let mut items = Vec::with_capacity(self.modifier_extension.len());
            for item in &self.modifier_extension {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("modifierExtension"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.customary_unit {
            object.insert(
                std::string::String::from("customaryUnit"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.unit {
            object.insert(
                std::string::String::from("unit"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.conversion_factor {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("conversionFactor"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_conversionFactor"), e);
            }
        }
        if let Some(item) = &self.decimal_precision {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("decimalPrecision"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_decimalPrecision"), 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<&super::super::codec::Value> = None;
        let mut raw_extension: Option<&super::super::codec::Value> = None;
        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
        let mut raw_customary_unit: Option<&super::super::codec::Value> = None;
        let mut raw_unit: Option<&super::super::codec::Value> = None;
        let mut raw_conversion_factor: Option<&super::super::codec::Value> = None;
        let mut raw_conversion_factor_element: Option<&super::super::codec::Value> = None;
        let mut raw_decimal_precision: Option<&super::super::codec::Value> = None;
        let mut raw_decimal_precision_element: Option<&super::super::codec::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "id" => {
                    raw_id = Some(value);
                }
                "extension" => {
                    raw_extension = Some(value);
                }
                "modifierExtension" => {
                    raw_modifier_extension = Some(value);
                }
                "customaryUnit" => {
                    raw_customary_unit = Some(value);
                }
                "unit" => {
                    raw_unit = Some(value);
                }
                "conversionFactor" => {
                    raw_conversion_factor = Some(value);
                }
                "_conversionFactor" => {
                    raw_conversion_factor_element = Some(value);
                }
                "decimalPrecision" => {
                    raw_decimal_precision = Some(value);
                }
                "_decimalPrecision" => {
                    raw_decimal_precision_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 mut field_modifier_extension = Vec::new();
        if let Some(raw) = raw_modifier_extension {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_modifier_extension.push(path.with_index(
                    "modifierExtension",
                    index,
                    |path| {
                        super::super::codec::Json::from_json(
                            super::super::codec::expect_object(value, path)?,
                            path,
                        )
                    },
                )?);
            }
        }
        let field_customary_unit = raw_customary_unit
            .map(|value| {
                path.with("customaryUnit", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_unit = raw_unit
            .map(|value| {
                path.with("unit", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_conversion_factor = match (raw_conversion_factor, raw_conversion_factor_element) {
            (None, None) => None,
            (value, element) => Some(path.with("conversionFactor", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_decimal_precision = match (raw_decimal_precision, raw_decimal_precision_element) {
            (None, None) => None,
            (value, element) => Some(path.with("decimalPrecision", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        Ok(Self {
            id: field_id,
            extension: field_extension,
            modifier_extension: field_modifier_extension,
            customary_unit: field_customary_unit,
            unit: field_unit,
            conversion_factor: field_conversion_factor,
            decimal_precision: field_decimal_precision,
        })
    }
}

impl serde::Serialize for ObservationDefinitionQuantitativeDetails {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        if let Some(item) = &self.conversion_factor {
            super::super::codec::element_entry(&mut map, "_conversionFactor", item)?;
        }
        if let Some(item) = &self.decimal_precision {
            super::super::codec::element_entry(&mut map, "_decimalPrecision", item)?;
        }
        if let Some(item) = &self.conversion_factor {
            super::super::codec::value_entry(&mut map, "conversionFactor", item)?;
        }
        if let Some(item) = &self.customary_unit {
            serde::ser::SerializeMap::serialize_entry(&mut map, "customaryUnit", item)?;
        }
        if let Some(item) = &self.decimal_precision {
            super::super::codec::value_entry(&mut map, "decimalPrecision", item)?;
        }
        if !self.extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
        }
        if let Some(v) = &self.id {
            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
        }
        if !self.modifier_extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "modifierExtension",
                &self.modifier_extension,
            )?;
        }
        if let Some(item) = &self.unit {
            serde::ser::SerializeMap::serialize_entry(&mut map, "unit", item)?;
        }
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for ObservationDefinitionQuantitativeDetails {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
        let mut path = super::super::codec::Path::root("ObservationDefinitionQuantitativeDetails");
        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)
    }
}