fhir-types 0.1.106

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
// @generated by fhir-codegen from hl7.fhir.r4.core 4.0.1. DO NOT EDIT.
// Change the emitter (tools/fhir-codegen) and regenerate.
// SPDX-FileCopyrightText: Vernum Projecten B.V.
// SPDX-License-Identifier: Apache-2.0
//! System of unique identification

/// System of unique identification
///
/// A curated namespace that issues unique symbols within that namespace for the
/// identification of concepts, people, devices, etc. Represents a "System" used
/// within the Identifier and Coding data types.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct NamingSystem {
    /// 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>,
    /// Name for this naming system (computer friendly)
    ///
    /// A natural language name identifying the naming system. This name should be
    /// usable as an identifier for the module by machine processing applications
    /// such as code generation.
    pub name: super::primitives::String,
    /// draft | active | retired | unknown
    ///
    /// The status of this naming system. Enables tracking the life-cycle of the
    /// content.
    pub status: super::primitives::Code,
    /// codesystem | identifier | root
    ///
    /// Indicates the purpose for the naming system - what kinds of things does it
    /// make unique?
    pub kind: super::primitives::Code,
    /// Date last changed
    ///
    /// The date (and optionally time) when the naming system was published. The
    /// date must change when the business version changes and it must change if the
    /// status code changes. In addition, it should change when the substantive
    /// content of the naming system changes.
    pub date: super::primitives::DateTime,
    /// Name of the publisher (organization or individual)
    ///
    /// The name of the organization or individual that published the naming system.
    pub publisher: Option<super::primitives::String>,
    /// Contact details for the publisher
    ///
    /// Contact details to assist a user in finding and communicating with the
    /// publisher.
    pub contact: Vec<super::contact_detail::ContactDetail>,
    /// Who maintains system namespace?
    ///
    /// The name of the organization that is responsible for issuing identifiers or
    /// codes for this namespace and ensuring their non-collision.
    pub responsible: Option<super::primitives::String>,
    /// e.g. driver, provider, patient, bank etc.
    ///
    /// Categorizes a naming system for easier search by grouping related naming
    /// systems.
    pub r#type: Option<super::codeable_concept::CodeableConcept>,
    /// Natural language description of the naming system
    ///
    /// A free text natural language description of the naming system from a
    /// consumer's perspective. Details about what the namespace identifies
    /// including scope, granularity, version labeling, etc.
    pub description: Option<super::primitives::Markdown>,
    /// The context that the content is intended to support
    ///
    /// The content was developed with a focus and intent of supporting the contexts
    /// that are listed. These contexts may be general categories (gender, age, ...)
    /// or may be references to specific programs (insurance plans, studies, ...)
    /// and may be used to assist with indexing and searching for appropriate naming
    /// system instances.
    pub use_context: Vec<super::usage_context::UsageContext>,
    /// Intended jurisdiction for naming system (if applicable)
    ///
    /// A legal or geographic region in which the naming system is intended to be
    /// used.
    pub jurisdiction: Vec<super::codeable_concept::CodeableConcept>,
    /// How/where is it used
    ///
    /// Provides guidance on the use of the namespace, including the handling of
    /// formatting characters, use of upper vs. lower case, etc.
    pub usage: Option<super::primitives::String>,
    /// Unique identifiers used for system
    ///
    /// Indicates how the system may be identified when referenced in electronic
    /// exchange.
    pub unique_id: Vec<NamingSystemUniqueId>,
}

impl super::super::codec::Json for NamingSystem {
    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("NamingSystem")),
        );
        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 let Some(v) = super::super::codec::Primitive::value_json(&self.name)? {
            object.insert(std::string::String::from("name"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.name)? {
            object.insert(std::string::String::from("_name"), e);
        }
        if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
            object.insert(std::string::String::from("status"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
            object.insert(std::string::String::from("_status"), e);
        }
        if let Some(v) = super::super::codec::Primitive::value_json(&self.kind)? {
            object.insert(std::string::String::from("kind"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.kind)? {
            object.insert(std::string::String::from("_kind"), e);
        }
        if let Some(v) = super::super::codec::Primitive::value_json(&self.date)? {
            object.insert(std::string::String::from("date"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.date)? {
            object.insert(std::string::String::from("_date"), e);
        }
        if let Some(item) = &self.publisher {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("publisher"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_publisher"), e);
            }
        }
        if !self.contact.is_empty() {
            let mut items = Vec::with_capacity(self.contact.len());
            for item in &self.contact {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("contact"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.responsible {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("responsible"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_responsible"), e);
            }
        }
        if let Some(item) = &self.r#type {
            object.insert(
                std::string::String::from("type"),
                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
            );
        }
        if let Some(item) = &self.description {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("description"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_description"), e);
            }
        }
        if !self.use_context.is_empty() {
            let mut items = Vec::with_capacity(self.use_context.len());
            for item in &self.use_context {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("useContext"),
                super::super::codec::Value::Array(items),
            );
        }
        if !self.jurisdiction.is_empty() {
            let mut items = Vec::with_capacity(self.jurisdiction.len());
            for item in &self.jurisdiction {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("jurisdiction"),
                super::super::codec::Value::Array(items),
            );
        }
        if let Some(item) = &self.usage {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("usage"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_usage"), e);
            }
        }
        if !self.unique_id.is_empty() {
            let mut items = Vec::with_capacity(self.unique_id.len());
            for item in &self.unique_id {
                items.push(super::super::codec::Value::Object(
                    super::super::codec::Json::to_json(item)?,
                ));
            }
            object.insert(
                std::string::String::from("uniqueId"),
                super::super::codec::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<&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_name: Option<&super::super::codec::Value> = None;
        let mut raw_name_element: Option<&super::super::codec::Value> = None;
        let mut raw_status: Option<&super::super::codec::Value> = None;
        let mut raw_status_element: Option<&super::super::codec::Value> = None;
        let mut raw_kind: Option<&super::super::codec::Value> = None;
        let mut raw_kind_element: Option<&super::super::codec::Value> = None;
        let mut raw_date: Option<&super::super::codec::Value> = None;
        let mut raw_date_element: Option<&super::super::codec::Value> = None;
        let mut raw_publisher: Option<&super::super::codec::Value> = None;
        let mut raw_publisher_element: Option<&super::super::codec::Value> = None;
        let mut raw_contact: Option<&super::super::codec::Value> = None;
        let mut raw_responsible: Option<&super::super::codec::Value> = None;
        let mut raw_responsible_element: Option<&super::super::codec::Value> = None;
        let mut raw_type: Option<&super::super::codec::Value> = None;
        let mut raw_description: Option<&super::super::codec::Value> = None;
        let mut raw_description_element: Option<&super::super::codec::Value> = None;
        let mut raw_use_context: Option<&super::super::codec::Value> = None;
        let mut raw_jurisdiction: Option<&super::super::codec::Value> = None;
        let mut raw_usage: Option<&super::super::codec::Value> = None;
        let mut raw_usage_element: Option<&super::super::codec::Value> = None;
        let mut raw_unique_id: Option<&super::super::codec::Value> = None;
        for (key, value) in object {
            match key.as_str() {
                "resourceType" => {
                    if value.as_str() != Some("NamingSystem") {
                        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);
                }
                "name" => {
                    raw_name = Some(value);
                }
                "_name" => {
                    raw_name_element = Some(value);
                }
                "status" => {
                    raw_status = Some(value);
                }
                "_status" => {
                    raw_status_element = Some(value);
                }
                "kind" => {
                    raw_kind = Some(value);
                }
                "_kind" => {
                    raw_kind_element = Some(value);
                }
                "date" => {
                    raw_date = Some(value);
                }
                "_date" => {
                    raw_date_element = Some(value);
                }
                "publisher" => {
                    raw_publisher = Some(value);
                }
                "_publisher" => {
                    raw_publisher_element = Some(value);
                }
                "contact" => {
                    raw_contact = Some(value);
                }
                "responsible" => {
                    raw_responsible = Some(value);
                }
                "_responsible" => {
                    raw_responsible_element = Some(value);
                }
                "type" => {
                    raw_type = Some(value);
                }
                "description" => {
                    raw_description = Some(value);
                }
                "_description" => {
                    raw_description_element = Some(value);
                }
                "useContext" => {
                    raw_use_context = Some(value);
                }
                "jurisdiction" => {
                    raw_jurisdiction = Some(value);
                }
                "usage" => {
                    raw_usage = Some(value);
                }
                "_usage" => {
                    raw_usage_element = Some(value);
                }
                "uniqueId" => {
                    raw_unique_id = 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::primitives::checked_string(
                        super::super::codec::expect_string(value, path)?,
                        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 field_name = path.with("name", |path| {
            super::super::codec::Primitive::from_json_parts(raw_name, raw_name_element, path)
        })?;
        let field_status = path.with("status", |path| {
            super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
        })?;
        let field_kind = path.with("kind", |path| {
            super::super::codec::Primitive::from_json_parts(raw_kind, raw_kind_element, path)
        })?;
        let field_date = path.with("date", |path| {
            super::super::codec::Primitive::from_json_parts(raw_date, raw_date_element, path)
        })?;
        let field_publisher = match (raw_publisher, raw_publisher_element) {
            (None, None) => None,
            (value, element) => Some(path.with("publisher", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let mut field_contact = Vec::new();
        if let Some(raw) = raw_contact {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_contact.push(path.with_index("contact", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_responsible = match (raw_responsible, raw_responsible_element) {
            (None, None) => None,
            (value, element) => Some(path.with("responsible", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_type = raw_type
            .map(|value| {
                path.with("type", |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(
                            super::super::codec::expect_single(value, path)?,
                            path,
                        )?,
                        path,
                    )
                })
            })
            .transpose()?;
        let field_description = match (raw_description, raw_description_element) {
            (None, None) => None,
            (value, element) => Some(path.with("description", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let mut field_use_context = Vec::new();
        if let Some(raw) = raw_use_context {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_use_context.push(path.with_index("useContext", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let mut field_jurisdiction = Vec::new();
        if let Some(raw) = raw_jurisdiction {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_jurisdiction.push(path.with_index("jurisdiction", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        let field_usage = match (raw_usage, raw_usage_element) {
            (None, None) => None,
            (value, element) => Some(path.with("usage", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let mut field_unique_id = Vec::new();
        if let Some(raw) = raw_unique_id {
            for (index, value) in super::super::codec::expect_array(raw, path)?
                .iter()
                .enumerate()
            {
                field_unique_id.push(path.with_index("uniqueId", index, |path| {
                    super::super::codec::Json::from_json(
                        super::super::codec::expect_object(value, path)?,
                        path,
                    )
                })?);
            }
        }
        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,
            name: field_name,
            status: field_status,
            kind: field_kind,
            date: field_date,
            publisher: field_publisher,
            contact: field_contact,
            responsible: field_responsible,
            r#type: field_type,
            description: field_description,
            use_context: field_use_context,
            jurisdiction: field_jurisdiction,
            usage: field_usage,
            unique_id: field_unique_id,
        })
    }
}

impl serde::Serialize for NamingSystem {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut map = serde::Serializer::serialize_map(serializer, None)?;
        super::super::codec::element_entry(&mut map, "_date", &self.date)?;
        if let Some(item) = &self.description {
            super::super::codec::element_entry(&mut map, "_description", item)?;
        }
        if let Some(item) = &self.implicit_rules {
            super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
        }
        super::super::codec::element_entry(&mut map, "_kind", &self.kind)?;
        if let Some(item) = &self.language {
            super::super::codec::element_entry(&mut map, "_language", item)?;
        }
        super::super::codec::element_entry(&mut map, "_name", &self.name)?;
        if let Some(item) = &self.publisher {
            super::super::codec::element_entry(&mut map, "_publisher", item)?;
        }
        if let Some(item) = &self.responsible {
            super::super::codec::element_entry(&mut map, "_responsible", item)?;
        }
        super::super::codec::element_entry(&mut map, "_status", &self.status)?;
        if let Some(item) = &self.usage {
            super::super::codec::element_entry(&mut map, "_usage", item)?;
        }
        if !self.contact.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "contact", &self.contact)?;
        }
        if !self.contained.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
        }
        super::super::codec::value_entry(&mut map, "date", &self.date)?;
        if let Some(item) = &self.description {
            super::super::codec::value_entry(&mut map, "description", 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 let Some(item) = &self.implicit_rules {
            super::super::codec::value_entry(&mut map, "implicitRules", item)?;
        }
        if !self.jurisdiction.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "jurisdiction",
                &self.jurisdiction,
            )?;
        }
        super::super::codec::value_entry(&mut map, "kind", &self.kind)?;
        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 !self.modifier_extension.is_empty() {
            serde::ser::SerializeMap::serialize_entry(
                &mut map,
                "modifierExtension",
                &self.modifier_extension,
            )?;
        }
        super::super::codec::value_entry(&mut map, "name", &self.name)?;
        if let Some(item) = &self.publisher {
            super::super::codec::value_entry(&mut map, "publisher", item)?;
        }
        serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "NamingSystem")?;
        if let Some(item) = &self.responsible {
            super::super::codec::value_entry(&mut map, "responsible", item)?;
        }
        super::super::codec::value_entry(&mut map, "status", &self.status)?;
        if let Some(item) = &self.text {
            serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
        }
        if let Some(item) = &self.r#type {
            serde::ser::SerializeMap::serialize_entry(&mut map, "type", item)?;
        }
        if !self.unique_id.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "uniqueId", &self.unique_id)?;
        }
        if let Some(item) = &self.usage {
            super::super::codec::value_entry(&mut map, "usage", item)?;
        }
        if !self.use_context.is_empty() {
            serde::ser::SerializeMap::serialize_entry(&mut map, "useContext", &self.use_context)?;
        }
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for NamingSystem {
    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("NamingSystem");
        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)
    }
}

/// Unique identifiers used for system
///
/// Indicates how the system may be identified when referenced in electronic
/// exchange.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct NamingSystemUniqueId {
    /// 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>,
    /// oid | uuid | uri | other
    ///
    /// Identifies the unique identifier scheme used for this particular identifier.
    pub r#type: super::primitives::Code,
    /// The unique identifier
    ///
    /// The string that should be sent over the wire to identify the code system or
    /// identifier system.
    pub value: super::primitives::String,
    /// Is this the id that should be used for this type
    ///
    /// Indicates whether this identifier is the "preferred" identifier of this
    /// type.
    pub preferred: Option<super::primitives::Boolean>,
    /// Notes about identifier usage
    ///
    /// Notes about the past or intended usage of this identifier.
    pub comment: Option<super::primitives::String>,
    /// When is identifier valid?
    ///
    /// Identifies the period of time over which this identifier is considered
    /// appropriate to refer to the naming system. Outside of this window, the
    /// identifier might be non-deterministic.
    pub period: Option<super::period::Period>,
}

impl super::super::codec::Json for NamingSystemUniqueId {
    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(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 let Some(v) = super::super::codec::Primitive::value_json(&self.value)? {
            object.insert(std::string::String::from("value"), v);
        }
        if let Some(e) = super::super::codec::Primitive::element_json(&self.value)? {
            object.insert(std::string::String::from("_value"), e);
        }
        if let Some(item) = &self.preferred {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("preferred"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_preferred"), e);
            }
        }
        if let Some(item) = &self.comment {
            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
                object.insert(std::string::String::from("comment"), v);
            }
            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
                object.insert(std::string::String::from("_comment"), e);
            }
        }
        if let Some(item) = &self.period {
            object.insert(
                std::string::String::from("period"),
                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_extension: Option<&super::super::codec::Value> = None;
        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
        let mut raw_type: Option<&super::super::codec::Value> = None;
        let mut raw_type_element: Option<&super::super::codec::Value> = None;
        let mut raw_value: Option<&super::super::codec::Value> = None;
        let mut raw_value_element: Option<&super::super::codec::Value> = None;
        let mut raw_preferred: Option<&super::super::codec::Value> = None;
        let mut raw_preferred_element: Option<&super::super::codec::Value> = None;
        let mut raw_comment: Option<&super::super::codec::Value> = None;
        let mut raw_comment_element: Option<&super::super::codec::Value> = None;
        let mut raw_period: 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);
                }
                "type" => {
                    raw_type = Some(value);
                }
                "_type" => {
                    raw_type_element = Some(value);
                }
                "value" => {
                    raw_value = Some(value);
                }
                "_value" => {
                    raw_value_element = Some(value);
                }
                "preferred" => {
                    raw_preferred = Some(value);
                }
                "_preferred" => {
                    raw_preferred_element = Some(value);
                }
                "comment" => {
                    raw_comment = Some(value);
                }
                "_comment" => {
                    raw_comment_element = Some(value);
                }
                "period" => {
                    raw_period = 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::primitives::checked_string(
                        super::super::codec::expect_string(value, path)?,
                        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_type = path.with("type", |path| {
            super::super::codec::Primitive::from_json_parts(raw_type, raw_type_element, path)
        })?;
        let field_value = path.with("value", |path| {
            super::super::codec::Primitive::from_json_parts(raw_value, raw_value_element, path)
        })?;
        let field_preferred = match (raw_preferred, raw_preferred_element) {
            (None, None) => None,
            (value, element) => Some(path.with("preferred", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_comment = match (raw_comment, raw_comment_element) {
            (None, None) => None,
            (value, element) => Some(path.with("comment", |path| {
                super::super::codec::Primitive::from_json_parts(value, element, path)
            })?),
        };
        let field_period = raw_period
            .map(|value| {
                path.with("period", |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,
            extension: field_extension,
            modifier_extension: field_modifier_extension,
            r#type: field_type,
            value: field_value,
            preferred: field_preferred,
            comment: field_comment,
            period: field_period,
        })
    }
}

impl serde::Serialize for NamingSystemUniqueId {
    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.comment {
            super::super::codec::element_entry(&mut map, "_comment", item)?;
        }
        if let Some(item) = &self.preferred {
            super::super::codec::element_entry(&mut map, "_preferred", item)?;
        }
        super::super::codec::element_entry(&mut map, "_type", &self.r#type)?;
        super::super::codec::element_entry(&mut map, "_value", &self.value)?;
        if let Some(item) = &self.comment {
            super::super::codec::value_entry(&mut map, "comment", 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.period {
            serde::ser::SerializeMap::serialize_entry(&mut map, "period", item)?;
        }
        if let Some(item) = &self.preferred {
            super::super::codec::value_entry(&mut map, "preferred", item)?;
        }
        super::super::codec::value_entry(&mut map, "type", &self.r#type)?;
        super::super::codec::value_entry(&mut map, "value", &self.value)?;
        serde::ser::SerializeMap::end(map)
    }
}

impl<'de> serde::Deserialize<'de> for NamingSystemUniqueId {
    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("NamingSystemUniqueId");
        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)
    }
}