Skip to main content

fhir_types/r6/
code_system.rs

1// @generated by fhir-codegen from hl7.fhir.r6.core 6.0.0-ballot5. DO NOT EDIT.
2// Change the emitter (tools/fhir-codegen) and regenerate.
3// SPDX-FileCopyrightText: Cadasto B.V.
4// SPDX-License-Identifier: Apache-2.0
5//! Declares the existence of and describes a code system or code system supplement
6
7/// Declares the existence of and describes a code system or code system
8/// supplement
9///
10/// The CodeSystem resource is used to declare the existence of and describe a
11/// code system or code system supplement and its key properties, and optionally
12/// define a part or all of its content.
13#[derive(Debug, Clone, Default, PartialEq, Eq)]
14pub struct CodeSystem {
15    /// Logical id of this artifact
16    ///
17    /// The logical id of the resource, as used in the URL for the resource. Once
18    /// assigned, this value never changes.
19    pub id: Option<std::string::String>,
20    /// Metadata about the resource
21    ///
22    /// The metadata about the resource. This is content that is maintained by the
23    /// infrastructure. Changes to the content might not always be associated with
24    /// version changes to the resource.
25    pub meta: Option<super::meta::Meta>,
26    /// A set of rules under which this content was created
27    ///
28    /// A reference to a set of rules that were followed when the resource was
29    /// constructed, and which must be understood when processing the content.
30    /// Often, this is a reference to an implementation guide that defines the
31    /// special rules along with other profiles etc. For DomainResources, if more
32    /// than one implicitRules policy applies, additional policies may be conveyed
33    /// using the
34    /// \[additionalImplicitRules\](<https://build.fhir.org/ig/HL7/fhir-extensions/StructureDefinition-additionalImplicitRules.html>)
35    /// extension.
36    pub implicit_rules: Option<super::primitives::Uri>,
37    /// Language of the resource content
38    ///
39    /// The base language in which the resource is written.
40    pub language: Option<super::primitives::Code>,
41    /// Text summary of the resource, for human interpretation
42    ///
43    /// A human-readable narrative that contains a summary of the resource and can
44    /// be used to represent the content of the resource to a human. The narrative
45    /// need not encode all the structured data, but is required to contain
46    /// sufficient detail to make it "clinically safe" for a human to just read the
47    /// narrative. Resource definitions may define what content should be
48    /// represented in the narrative to ensure clinical safety.
49    pub text: Option<super::narrative::Narrative>,
50    /// Contained, inline Resources
51    ///
52    /// These resources do not have an independent existence apart from the resource
53    /// that contains them - they cannot be identified independently, nor can they
54    /// have their own independent transaction scope. This is allowed to be a
55    /// Parameters resource if and only if it is referenced by a resource that
56    /// provides context/meaning.
57    pub contained: Vec<super::resource::Resource>,
58    /// Additional content defined by implementations
59    ///
60    /// May be used to represent additional information that is not part of the
61    /// basic definition of the resource. To make the use of extensions safe and
62    /// managable, there is a strict set of governance applied to the definition and
63    /// use of extensions. Though any implementer can define an extension, there is
64    /// a set of requirements that SHALL be met as part of the definition of the
65    /// extension.
66    pub extension: Vec<super::extension::Extension>,
67    /// Extensions that cannot be ignored
68    ///
69    /// May be used to represent additional information that is not part of the
70    /// basic definition of the resource and that modifies the understanding of the
71    /// element that contains it and/or the understanding of the containing
72    /// element's descendants. Usually modifier elements provide negation or
73    /// qualification. To make the use of extensions safe and managable, there is a
74    /// strict set of governance applied to the definition and use of extensions.
75    /// Though any implementer is allowed to define an extension, there is a set of
76    /// requirements that SHALL be met as part of the definition of the extension.
77    /// Applications processing a resource are required to check for modifier
78    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
79    /// on Resource or DomainResource (including cannot change the meaning of
80    /// modifierExtension itself).
81    pub modifier_extension: Vec<super::extension::Extension>,
82    /// Canonical identifier for this code system, represented as a URI (globally
83    /// unique) (Coding.system)
84    ///
85    /// An absolute URI that is used to identify this code system when it is
86    /// referenced in a specification, model, design or an instance; also called its
87    /// canonical identifier. This SHOULD be globally unique and SHOULD be a literal
88    /// address at which an authoritative instance of this code system is (or will
89    /// be) published. This URL can be the target of a canonical reference. It SHALL
90    /// remain the same when the code system is stored on different servers. This is
91    /// used in \[Coding\](datatypes.html\#Coding).system.
92    pub url: Option<super::primitives::Uri>,
93    /// Additional identifier for the code system (business identifier)
94    ///
95    /// A formal identifier that is used to identify this code system when it is
96    /// represented in other formats, or referenced in a specification, model,
97    /// design or an instance.
98    pub identifier: Vec<super::identifier::Identifier>,
99    /// Business version of the code system (Coding.version)
100    ///
101    /// The identifier that is used to identify this version of the code system when
102    /// it is referenced in a specification, model, design or instance. This is an
103    /// arbitrary value managed by the code system author and is not expected to be
104    /// globally unique. For example, it might be a timestamp (e.g. yyyymmdd) if a
105    /// managed version is not available. There is also no expectation that versions
106    /// can be placed in a lexicographical sequence. This is used in
107    /// \[Coding\](datatypes.html\#Coding).version.
108    pub version: Option<super::primitives::String>,
109    /// How to compare versions
110    ///
111    /// Indicates the mechanism used to compare versions to determine which
112    /// CodeSystem is more current.
113    pub version_algorithm: Option<CodeSystemVersionAlgorithm>,
114    /// Name for this code system (computer friendly)
115    ///
116    /// A natural language name identifying the code system. This name should be
117    /// usable as an identifier for the module by machine processing applications
118    /// such as code generation.
119    pub name: Option<super::primitives::String>,
120    /// Name for this code system (human friendly)
121    ///
122    /// A short, descriptive, user-friendly title for the code system.
123    pub title: Option<super::primitives::String>,
124    /// draft | active | retired | unknown
125    ///
126    /// The status of this code system. Enables tracking the life-cycle of the
127    /// content.
128    pub status: super::primitives::Code,
129    /// For testing only - never for real usage
130    ///
131    /// A Boolean value to indicate that this code system is authored for testing
132    /// purposes (or education/evaluation/marketing) and no version of this resource
133    /// will ever be intended for genuine usage.
134    pub experimental: Option<super::primitives::Boolean>,
135    /// Date last changed
136    ///
137    /// The date (and optionally time) when the code system was last significantly
138    /// changed. The date must change when the business version changes and it must
139    /// change if the status code changes. In addition, it should change when the
140    /// substantive content of the code system changes.
141    pub date: Option<super::primitives::DateTime>,
142    /// Name of the publisher/steward (organization or individual)
143    ///
144    /// The name of the organization or individual responsible for the release and
145    /// ongoing maintenance of the code system.
146    pub publisher: Option<super::primitives::String>,
147    /// Contact details for the publisher
148    ///
149    /// Contact details to assist a user in finding and communicating with the
150    /// publisher.
151    pub contact: Vec<super::contact_detail::ContactDetail>,
152    /// Natural language description of the code system
153    ///
154    /// A free text natural language description of the code system from a
155    /// consumer's perspective.
156    pub description: Option<super::primitives::Markdown>,
157    /// The context that the content is intended to support
158    ///
159    /// The content was developed with a focus and intent of supporting the contexts
160    /// that are listed. These contexts may be general categories (gender, age, ...)
161    /// or may be references to specific programs (insurance plans, studies, ...)
162    /// and may be used to assist with indexing and searching for appropriate code
163    /// system instances.
164    pub use_context: Vec<super::usage_context::UsageContext>,
165    /// Jurisdiction of the authority that maintains the code system (if applicable)
166    ///
167    /// A legal or geographic region in which the authority that maintains the
168    /// resource is operating. In general, the jurisdiction is also found in the
169    /// useContext. The useContext may reference additional jurisdictions because
170    /// the defining jurisdiction does not necessarily limit the jurisdictions of
171    /// use.
172    pub jurisdiction: Vec<super::codeable_concept::CodeableConcept>,
173    /// Why this code system is defined
174    ///
175    /// Explanation of why this code system is needed and why it has been designed
176    /// as it has.
177    pub purpose: Option<super::primitives::Markdown>,
178    /// Notice about intellectual property ownership, can include restrictions on
179    /// use
180    ///
181    /// A copyright statement relating to the code system and/or its contents.
182    /// Copyright statements are notices of intellectual property ownership and can
183    /// include restrictions on the use and publishing of the code system.
184    pub copyright: Option<super::primitives::Markdown>,
185    /// Copyright holder and year(s)
186    ///
187    /// A short string (\<50 characters), suitable for inclusion in a page footer
188    /// that identifies the copyright holder, effective period, and optionally
189    /// whether rights are restricted. (e.g. 'All rights reserved', 'Some rights
190    /// reserved').
191    pub copyright_label: Option<super::primitives::String>,
192    /// When the CodeSystem was approved by publisher
193    ///
194    /// The date on which the resource content was approved by the publisher.
195    /// Approval happens once when the content is officially approved for usage.
196    pub approval_date: Option<super::primitives::Date>,
197    /// When the CodeSystem was last reviewed by the publisher
198    ///
199    /// The date on which the resource content was last reviewed. Review happens
200    /// periodically after approval but does not change the original approval date.
201    pub last_review_date: Option<super::primitives::Date>,
202    /// When the CodeSystem is expected to be used
203    ///
204    /// The period during which the CodeSystem content was or is planned to be in
205    /// active use.
206    pub effective_period: Option<super::period::Period>,
207    /// E.g. Education, Treatment, Assessment, etc
208    ///
209    /// Descriptions related to the content of the CodeSystem. Topics provide a
210    /// high-level categorization as well as keywords for the CodeSystem that can be
211    /// useful for filtering and searching.
212    pub topic: Vec<super::codeable_concept::CodeableConcept>,
213    /// Who authored the CodeSystem
214    ///
215    /// An individual or organization primarily involved in the creation and
216    /// maintenance of the CodeSystem.
217    pub author: Vec<super::contact_detail::ContactDetail>,
218    /// Who edited the CodeSystem
219    ///
220    /// An individual or organization primarily responsible for internal coherence
221    /// of the CodeSystem.
222    pub editor: Vec<super::contact_detail::ContactDetail>,
223    /// Who reviewed the CodeSystem
224    ///
225    /// An individual or organization asserted by the publisher to be primarily
226    /// responsible for review of some aspect of the CodeSystem.
227    pub reviewer: Vec<super::contact_detail::ContactDetail>,
228    /// Who endorsed the CodeSystem
229    ///
230    /// An individual or organization asserted by the publisher to be responsible
231    /// for officially endorsing the CodeSystem for use in some setting.
232    pub endorser: Vec<super::contact_detail::ContactDetail>,
233    /// Additional documentation, citations, etc
234    ///
235    /// Related artifacts such as additional documentation, justification,
236    /// dependencies, bibliographic references, and predecessor and successor
237    /// artifacts. If the type is \`successor\` or \`predecessor\`, the related
238    /// resource must be a CodeSystem.
239    pub related_artifact: Vec<super::related_artifact::RelatedArtifact>,
240    /// If code comparison is case sensitive
241    ///
242    /// If code comparison is case sensitive when codes within this system are
243    /// compared to each other.
244    pub case_sensitive: Option<super::primitives::Boolean>,
245    /// Canonical reference to the value set with entire code system
246    ///
247    /// Canonical reference to the value set that contains all codes in the code
248    /// system independent of code status.
249    pub value_set: Option<super::primitives::Canonical>,
250    /// grouped-by | is-a | part-of | classified-with
251    ///
252    /// The meaning of the hierarchy of concepts as represented in this resource.
253    pub hierarchy_meaning: Option<super::primitives::Code>,
254    /// If code system defines a compositional grammar
255    ///
256    /// The code system defines a compositional (post-coordination) grammar.
257    pub compositional: Option<super::primitives::Boolean>,
258    /// If definitions are not stable
259    ///
260    /// This flag is used to signify that the code system does not commit to concept
261    /// permanence across versions. If true, a version must be specified when
262    /// referencing this code system.
263    pub version_needed: Option<super::primitives::Boolean>,
264    /// not-present | example | fragment | complete | supplement
265    ///
266    /// The extent of the content of the code system (the concepts and codes it
267    /// defines) are represented in this resource instance.
268    pub content: super::primitives::Code,
269    /// Canonical URL of Code System this adds designations and properties to
270    ///
271    /// The canonical URL of the code system that this code system supplement is
272    /// adding designations and properties to.
273    pub supplements: Option<super::primitives::Canonical>,
274    /// Total concepts in the code system
275    ///
276    /// The total number of concepts defined by the code system. Where the code
277    /// system has a compositional grammar, the basis of this count is defined by
278    /// the system steward.
279    pub count: Option<super::primitives::UnsignedInt>,
280    /// Filter that can be used in a value set
281    ///
282    /// A filter that can be used in a value set compose statement when selecting
283    /// concepts using a filter.
284    pub filter: Vec<CodeSystemFilter>,
285    /// Additional information supplied about each concept
286    ///
287    /// A property defines an additional slot through which additional information
288    /// can be provided about a concept.
289    pub property: Vec<CodeSystemProperty>,
290    /// Concepts in the code system
291    ///
292    /// Concepts that are in the code system. The concept definitions are inherently
293    /// hierarchical, but the definitions must be consulted to determine what the
294    /// meanings of the hierarchical relationships are.
295    pub concept: Vec<CodeSystemConcept>,
296}
297
298impl super::super::codec::Json for CodeSystem {
299    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
300        let mut object = super::super::codec::Object::new();
301        object.insert(
302            std::string::String::from("resourceType"),
303            super::super::codec::Value::String(std::string::String::from("CodeSystem")),
304        );
305        if let Some(v) = &self.id {
306            object.insert(
307                std::string::String::from("id"),
308                super::super::codec::Value::String(v.clone()),
309            );
310        }
311        if let Some(item) = &self.meta {
312            object.insert(
313                std::string::String::from("meta"),
314                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
315            );
316        }
317        if let Some(item) = &self.implicit_rules {
318            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
319                object.insert(std::string::String::from("implicitRules"), v);
320            }
321            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
322                object.insert(std::string::String::from("_implicitRules"), e);
323            }
324        }
325        if let Some(item) = &self.language {
326            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
327                object.insert(std::string::String::from("language"), v);
328            }
329            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
330                object.insert(std::string::String::from("_language"), e);
331            }
332        }
333        if let Some(item) = &self.text {
334            object.insert(
335                std::string::String::from("text"),
336                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
337            );
338        }
339        if !self.contained.is_empty() {
340            let mut items = Vec::with_capacity(self.contained.len());
341            for item in &self.contained {
342                items.push(super::super::codec::Value::Object(
343                    super::super::codec::Json::to_json(item)?,
344                ));
345            }
346            object.insert(
347                std::string::String::from("contained"),
348                super::super::codec::Value::Array(items),
349            );
350        }
351        if !self.extension.is_empty() {
352            let mut items = Vec::with_capacity(self.extension.len());
353            for item in &self.extension {
354                items.push(super::super::codec::Value::Object(
355                    super::super::codec::Json::to_json(item)?,
356                ));
357            }
358            object.insert(
359                std::string::String::from("extension"),
360                super::super::codec::Value::Array(items),
361            );
362        }
363        if !self.modifier_extension.is_empty() {
364            let mut items = Vec::with_capacity(self.modifier_extension.len());
365            for item in &self.modifier_extension {
366                items.push(super::super::codec::Value::Object(
367                    super::super::codec::Json::to_json(item)?,
368                ));
369            }
370            object.insert(
371                std::string::String::from("modifierExtension"),
372                super::super::codec::Value::Array(items),
373            );
374        }
375        if let Some(item) = &self.url {
376            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
377                object.insert(std::string::String::from("url"), v);
378            }
379            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
380                object.insert(std::string::String::from("_url"), e);
381            }
382        }
383        if !self.identifier.is_empty() {
384            let mut items = Vec::with_capacity(self.identifier.len());
385            for item in &self.identifier {
386                items.push(super::super::codec::Value::Object(
387                    super::super::codec::Json::to_json(item)?,
388                ));
389            }
390            object.insert(
391                std::string::String::from("identifier"),
392                super::super::codec::Value::Array(items),
393            );
394        }
395        if let Some(item) = &self.version {
396            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
397                object.insert(std::string::String::from("version"), v);
398            }
399            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
400                object.insert(std::string::String::from("_version"), e);
401            }
402        }
403        if let Some(item) = &self.version_algorithm {
404            let (suffix, value, element) = item.to_json_parts()?;
405            if let Some(value) = value {
406                object.insert(format!("versionAlgorithm{suffix}"), value);
407            }
408            if let Some(element) = element {
409                object.insert(format!("_versionAlgorithm{suffix}"), element);
410            }
411        }
412        if let Some(item) = &self.name {
413            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
414                object.insert(std::string::String::from("name"), v);
415            }
416            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
417                object.insert(std::string::String::from("_name"), e);
418            }
419        }
420        if let Some(item) = &self.title {
421            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
422                object.insert(std::string::String::from("title"), v);
423            }
424            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
425                object.insert(std::string::String::from("_title"), e);
426            }
427        }
428        if let Some(v) = super::super::codec::Primitive::value_json(&self.status)? {
429            object.insert(std::string::String::from("status"), v);
430        }
431        if let Some(e) = super::super::codec::Primitive::element_json(&self.status)? {
432            object.insert(std::string::String::from("_status"), e);
433        }
434        if let Some(item) = &self.experimental {
435            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
436                object.insert(std::string::String::from("experimental"), v);
437            }
438            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
439                object.insert(std::string::String::from("_experimental"), e);
440            }
441        }
442        if let Some(item) = &self.date {
443            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
444                object.insert(std::string::String::from("date"), v);
445            }
446            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
447                object.insert(std::string::String::from("_date"), e);
448            }
449        }
450        if let Some(item) = &self.publisher {
451            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
452                object.insert(std::string::String::from("publisher"), v);
453            }
454            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
455                object.insert(std::string::String::from("_publisher"), e);
456            }
457        }
458        if !self.contact.is_empty() {
459            let mut items = Vec::with_capacity(self.contact.len());
460            for item in &self.contact {
461                items.push(super::super::codec::Value::Object(
462                    super::super::codec::Json::to_json(item)?,
463                ));
464            }
465            object.insert(
466                std::string::String::from("contact"),
467                super::super::codec::Value::Array(items),
468            );
469        }
470        if let Some(item) = &self.description {
471            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
472                object.insert(std::string::String::from("description"), v);
473            }
474            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
475                object.insert(std::string::String::from("_description"), e);
476            }
477        }
478        if !self.use_context.is_empty() {
479            let mut items = Vec::with_capacity(self.use_context.len());
480            for item in &self.use_context {
481                items.push(super::super::codec::Value::Object(
482                    super::super::codec::Json::to_json(item)?,
483                ));
484            }
485            object.insert(
486                std::string::String::from("useContext"),
487                super::super::codec::Value::Array(items),
488            );
489        }
490        if !self.jurisdiction.is_empty() {
491            let mut items = Vec::with_capacity(self.jurisdiction.len());
492            for item in &self.jurisdiction {
493                items.push(super::super::codec::Value::Object(
494                    super::super::codec::Json::to_json(item)?,
495                ));
496            }
497            object.insert(
498                std::string::String::from("jurisdiction"),
499                super::super::codec::Value::Array(items),
500            );
501        }
502        if let Some(item) = &self.purpose {
503            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
504                object.insert(std::string::String::from("purpose"), v);
505            }
506            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
507                object.insert(std::string::String::from("_purpose"), e);
508            }
509        }
510        if let Some(item) = &self.copyright {
511            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
512                object.insert(std::string::String::from("copyright"), v);
513            }
514            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
515                object.insert(std::string::String::from("_copyright"), e);
516            }
517        }
518        if let Some(item) = &self.copyright_label {
519            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
520                object.insert(std::string::String::from("copyrightLabel"), v);
521            }
522            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
523                object.insert(std::string::String::from("_copyrightLabel"), e);
524            }
525        }
526        if let Some(item) = &self.approval_date {
527            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
528                object.insert(std::string::String::from("approvalDate"), v);
529            }
530            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
531                object.insert(std::string::String::from("_approvalDate"), e);
532            }
533        }
534        if let Some(item) = &self.last_review_date {
535            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
536                object.insert(std::string::String::from("lastReviewDate"), v);
537            }
538            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
539                object.insert(std::string::String::from("_lastReviewDate"), e);
540            }
541        }
542        if let Some(item) = &self.effective_period {
543            object.insert(
544                std::string::String::from("effectivePeriod"),
545                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
546            );
547        }
548        if !self.topic.is_empty() {
549            let mut items = Vec::with_capacity(self.topic.len());
550            for item in &self.topic {
551                items.push(super::super::codec::Value::Object(
552                    super::super::codec::Json::to_json(item)?,
553                ));
554            }
555            object.insert(
556                std::string::String::from("topic"),
557                super::super::codec::Value::Array(items),
558            );
559        }
560        if !self.author.is_empty() {
561            let mut items = Vec::with_capacity(self.author.len());
562            for item in &self.author {
563                items.push(super::super::codec::Value::Object(
564                    super::super::codec::Json::to_json(item)?,
565                ));
566            }
567            object.insert(
568                std::string::String::from("author"),
569                super::super::codec::Value::Array(items),
570            );
571        }
572        if !self.editor.is_empty() {
573            let mut items = Vec::with_capacity(self.editor.len());
574            for item in &self.editor {
575                items.push(super::super::codec::Value::Object(
576                    super::super::codec::Json::to_json(item)?,
577                ));
578            }
579            object.insert(
580                std::string::String::from("editor"),
581                super::super::codec::Value::Array(items),
582            );
583        }
584        if !self.reviewer.is_empty() {
585            let mut items = Vec::with_capacity(self.reviewer.len());
586            for item in &self.reviewer {
587                items.push(super::super::codec::Value::Object(
588                    super::super::codec::Json::to_json(item)?,
589                ));
590            }
591            object.insert(
592                std::string::String::from("reviewer"),
593                super::super::codec::Value::Array(items),
594            );
595        }
596        if !self.endorser.is_empty() {
597            let mut items = Vec::with_capacity(self.endorser.len());
598            for item in &self.endorser {
599                items.push(super::super::codec::Value::Object(
600                    super::super::codec::Json::to_json(item)?,
601                ));
602            }
603            object.insert(
604                std::string::String::from("endorser"),
605                super::super::codec::Value::Array(items),
606            );
607        }
608        if !self.related_artifact.is_empty() {
609            let mut items = Vec::with_capacity(self.related_artifact.len());
610            for item in &self.related_artifact {
611                items.push(super::super::codec::Value::Object(
612                    super::super::codec::Json::to_json(item)?,
613                ));
614            }
615            object.insert(
616                std::string::String::from("relatedArtifact"),
617                super::super::codec::Value::Array(items),
618            );
619        }
620        if let Some(item) = &self.case_sensitive {
621            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
622                object.insert(std::string::String::from("caseSensitive"), v);
623            }
624            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
625                object.insert(std::string::String::from("_caseSensitive"), e);
626            }
627        }
628        if let Some(item) = &self.value_set {
629            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
630                object.insert(std::string::String::from("valueSet"), v);
631            }
632            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
633                object.insert(std::string::String::from("_valueSet"), e);
634            }
635        }
636        if let Some(item) = &self.hierarchy_meaning {
637            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
638                object.insert(std::string::String::from("hierarchyMeaning"), v);
639            }
640            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
641                object.insert(std::string::String::from("_hierarchyMeaning"), e);
642            }
643        }
644        if let Some(item) = &self.compositional {
645            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
646                object.insert(std::string::String::from("compositional"), v);
647            }
648            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
649                object.insert(std::string::String::from("_compositional"), e);
650            }
651        }
652        if let Some(item) = &self.version_needed {
653            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
654                object.insert(std::string::String::from("versionNeeded"), v);
655            }
656            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
657                object.insert(std::string::String::from("_versionNeeded"), e);
658            }
659        }
660        if let Some(v) = super::super::codec::Primitive::value_json(&self.content)? {
661            object.insert(std::string::String::from("content"), v);
662        }
663        if let Some(e) = super::super::codec::Primitive::element_json(&self.content)? {
664            object.insert(std::string::String::from("_content"), e);
665        }
666        if let Some(item) = &self.supplements {
667            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
668                object.insert(std::string::String::from("supplements"), v);
669            }
670            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
671                object.insert(std::string::String::from("_supplements"), e);
672            }
673        }
674        if let Some(item) = &self.count {
675            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
676                object.insert(std::string::String::from("count"), v);
677            }
678            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
679                object.insert(std::string::String::from("_count"), e);
680            }
681        }
682        if !self.filter.is_empty() {
683            let mut items = Vec::with_capacity(self.filter.len());
684            for item in &self.filter {
685                items.push(super::super::codec::Value::Object(
686                    super::super::codec::Json::to_json(item)?,
687                ));
688            }
689            object.insert(
690                std::string::String::from("filter"),
691                super::super::codec::Value::Array(items),
692            );
693        }
694        if !self.property.is_empty() {
695            let mut items = Vec::with_capacity(self.property.len());
696            for item in &self.property {
697                items.push(super::super::codec::Value::Object(
698                    super::super::codec::Json::to_json(item)?,
699                ));
700            }
701            object.insert(
702                std::string::String::from("property"),
703                super::super::codec::Value::Array(items),
704            );
705        }
706        if !self.concept.is_empty() {
707            let mut items = Vec::with_capacity(self.concept.len());
708            for item in &self.concept {
709                items.push(super::super::codec::Value::Object(
710                    super::super::codec::Json::to_json(item)?,
711                ));
712            }
713            object.insert(
714                std::string::String::from("concept"),
715                super::super::codec::Value::Array(items),
716            );
717        }
718        Ok(object)
719    }
720
721    fn from_json(
722        object: &super::super::codec::Object,
723        path: &mut super::super::codec::Path,
724    ) -> Result<Self, super::super::codec::DecodeError> {
725        let mut raw_id: Option<&super::super::codec::Value> = None;
726        let mut raw_meta: Option<&super::super::codec::Value> = None;
727        let mut raw_implicit_rules: Option<&super::super::codec::Value> = None;
728        let mut raw_implicit_rules_element: Option<&super::super::codec::Value> = None;
729        let mut raw_language: Option<&super::super::codec::Value> = None;
730        let mut raw_language_element: Option<&super::super::codec::Value> = None;
731        let mut raw_text: Option<&super::super::codec::Value> = None;
732        let mut raw_contained: Option<&super::super::codec::Value> = None;
733        let mut raw_extension: Option<&super::super::codec::Value> = None;
734        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
735        let mut raw_url: Option<&super::super::codec::Value> = None;
736        let mut raw_url_element: Option<&super::super::codec::Value> = None;
737        let mut raw_identifier: Option<&super::super::codec::Value> = None;
738        let mut raw_version: Option<&super::super::codec::Value> = None;
739        let mut raw_version_element: Option<&super::super::codec::Value> = None;
740        let mut raw_version_algorithm = super::super::codec::ChoiceSlot::default();
741        let mut raw_name: Option<&super::super::codec::Value> = None;
742        let mut raw_name_element: Option<&super::super::codec::Value> = None;
743        let mut raw_title: Option<&super::super::codec::Value> = None;
744        let mut raw_title_element: Option<&super::super::codec::Value> = None;
745        let mut raw_status: Option<&super::super::codec::Value> = None;
746        let mut raw_status_element: Option<&super::super::codec::Value> = None;
747        let mut raw_experimental: Option<&super::super::codec::Value> = None;
748        let mut raw_experimental_element: Option<&super::super::codec::Value> = None;
749        let mut raw_date: Option<&super::super::codec::Value> = None;
750        let mut raw_date_element: Option<&super::super::codec::Value> = None;
751        let mut raw_publisher: Option<&super::super::codec::Value> = None;
752        let mut raw_publisher_element: Option<&super::super::codec::Value> = None;
753        let mut raw_contact: Option<&super::super::codec::Value> = None;
754        let mut raw_description: Option<&super::super::codec::Value> = None;
755        let mut raw_description_element: Option<&super::super::codec::Value> = None;
756        let mut raw_use_context: Option<&super::super::codec::Value> = None;
757        let mut raw_jurisdiction: Option<&super::super::codec::Value> = None;
758        let mut raw_purpose: Option<&super::super::codec::Value> = None;
759        let mut raw_purpose_element: Option<&super::super::codec::Value> = None;
760        let mut raw_copyright: Option<&super::super::codec::Value> = None;
761        let mut raw_copyright_element: Option<&super::super::codec::Value> = None;
762        let mut raw_copyright_label: Option<&super::super::codec::Value> = None;
763        let mut raw_copyright_label_element: Option<&super::super::codec::Value> = None;
764        let mut raw_approval_date: Option<&super::super::codec::Value> = None;
765        let mut raw_approval_date_element: Option<&super::super::codec::Value> = None;
766        let mut raw_last_review_date: Option<&super::super::codec::Value> = None;
767        let mut raw_last_review_date_element: Option<&super::super::codec::Value> = None;
768        let mut raw_effective_period: Option<&super::super::codec::Value> = None;
769        let mut raw_topic: Option<&super::super::codec::Value> = None;
770        let mut raw_author: Option<&super::super::codec::Value> = None;
771        let mut raw_editor: Option<&super::super::codec::Value> = None;
772        let mut raw_reviewer: Option<&super::super::codec::Value> = None;
773        let mut raw_endorser: Option<&super::super::codec::Value> = None;
774        let mut raw_related_artifact: Option<&super::super::codec::Value> = None;
775        let mut raw_case_sensitive: Option<&super::super::codec::Value> = None;
776        let mut raw_case_sensitive_element: Option<&super::super::codec::Value> = None;
777        let mut raw_value_set: Option<&super::super::codec::Value> = None;
778        let mut raw_value_set_element: Option<&super::super::codec::Value> = None;
779        let mut raw_hierarchy_meaning: Option<&super::super::codec::Value> = None;
780        let mut raw_hierarchy_meaning_element: Option<&super::super::codec::Value> = None;
781        let mut raw_compositional: Option<&super::super::codec::Value> = None;
782        let mut raw_compositional_element: Option<&super::super::codec::Value> = None;
783        let mut raw_version_needed: Option<&super::super::codec::Value> = None;
784        let mut raw_version_needed_element: Option<&super::super::codec::Value> = None;
785        let mut raw_content: Option<&super::super::codec::Value> = None;
786        let mut raw_content_element: Option<&super::super::codec::Value> = None;
787        let mut raw_supplements: Option<&super::super::codec::Value> = None;
788        let mut raw_supplements_element: Option<&super::super::codec::Value> = None;
789        let mut raw_count: Option<&super::super::codec::Value> = None;
790        let mut raw_count_element: Option<&super::super::codec::Value> = None;
791        let mut raw_filter: Option<&super::super::codec::Value> = None;
792        let mut raw_property: Option<&super::super::codec::Value> = None;
793        let mut raw_concept: Option<&super::super::codec::Value> = None;
794        for (key, value) in object {
795            match key.as_str() {
796                "resourceType" => {
797                    if value.as_str() != Some("CodeSystem") {
798                        return Err(path.error(super::super::codec::DecodeErrorKind::ResourceType));
799                    }
800                }
801                "id" => {
802                    raw_id = Some(value);
803                }
804                "meta" => {
805                    raw_meta = Some(value);
806                }
807                "implicitRules" => {
808                    raw_implicit_rules = Some(value);
809                }
810                "_implicitRules" => {
811                    raw_implicit_rules_element = Some(value);
812                }
813                "language" => {
814                    raw_language = Some(value);
815                }
816                "_language" => {
817                    raw_language_element = Some(value);
818                }
819                "text" => {
820                    raw_text = Some(value);
821                }
822                "contained" => {
823                    raw_contained = Some(value);
824                }
825                "extension" => {
826                    raw_extension = Some(value);
827                }
828                "modifierExtension" => {
829                    raw_modifier_extension = Some(value);
830                }
831                "url" => {
832                    raw_url = Some(value);
833                }
834                "_url" => {
835                    raw_url_element = Some(value);
836                }
837                "identifier" => {
838                    raw_identifier = Some(value);
839                }
840                "version" => {
841                    raw_version = Some(value);
842                }
843                "_version" => {
844                    raw_version_element = Some(value);
845                }
846                "versionAlgorithmString" => {
847                    raw_version_algorithm.value("String", value, path)?;
848                }
849                "_versionAlgorithmString" => {
850                    raw_version_algorithm.element("String", value, path)?;
851                }
852                "versionAlgorithmCoding" => {
853                    raw_version_algorithm.value("Coding", value, path)?;
854                }
855                "_versionAlgorithmCoding" => {
856                    raw_version_algorithm.element("Coding", value, path)?;
857                }
858                "name" => {
859                    raw_name = Some(value);
860                }
861                "_name" => {
862                    raw_name_element = Some(value);
863                }
864                "title" => {
865                    raw_title = Some(value);
866                }
867                "_title" => {
868                    raw_title_element = Some(value);
869                }
870                "status" => {
871                    raw_status = Some(value);
872                }
873                "_status" => {
874                    raw_status_element = Some(value);
875                }
876                "experimental" => {
877                    raw_experimental = Some(value);
878                }
879                "_experimental" => {
880                    raw_experimental_element = Some(value);
881                }
882                "date" => {
883                    raw_date = Some(value);
884                }
885                "_date" => {
886                    raw_date_element = Some(value);
887                }
888                "publisher" => {
889                    raw_publisher = Some(value);
890                }
891                "_publisher" => {
892                    raw_publisher_element = Some(value);
893                }
894                "contact" => {
895                    raw_contact = Some(value);
896                }
897                "description" => {
898                    raw_description = Some(value);
899                }
900                "_description" => {
901                    raw_description_element = Some(value);
902                }
903                "useContext" => {
904                    raw_use_context = Some(value);
905                }
906                "jurisdiction" => {
907                    raw_jurisdiction = Some(value);
908                }
909                "purpose" => {
910                    raw_purpose = Some(value);
911                }
912                "_purpose" => {
913                    raw_purpose_element = Some(value);
914                }
915                "copyright" => {
916                    raw_copyright = Some(value);
917                }
918                "_copyright" => {
919                    raw_copyright_element = Some(value);
920                }
921                "copyrightLabel" => {
922                    raw_copyright_label = Some(value);
923                }
924                "_copyrightLabel" => {
925                    raw_copyright_label_element = Some(value);
926                }
927                "approvalDate" => {
928                    raw_approval_date = Some(value);
929                }
930                "_approvalDate" => {
931                    raw_approval_date_element = Some(value);
932                }
933                "lastReviewDate" => {
934                    raw_last_review_date = Some(value);
935                }
936                "_lastReviewDate" => {
937                    raw_last_review_date_element = Some(value);
938                }
939                "effectivePeriod" => {
940                    raw_effective_period = Some(value);
941                }
942                "topic" => {
943                    raw_topic = Some(value);
944                }
945                "author" => {
946                    raw_author = Some(value);
947                }
948                "editor" => {
949                    raw_editor = Some(value);
950                }
951                "reviewer" => {
952                    raw_reviewer = Some(value);
953                }
954                "endorser" => {
955                    raw_endorser = Some(value);
956                }
957                "relatedArtifact" => {
958                    raw_related_artifact = Some(value);
959                }
960                "caseSensitive" => {
961                    raw_case_sensitive = Some(value);
962                }
963                "_caseSensitive" => {
964                    raw_case_sensitive_element = Some(value);
965                }
966                "valueSet" => {
967                    raw_value_set = Some(value);
968                }
969                "_valueSet" => {
970                    raw_value_set_element = Some(value);
971                }
972                "hierarchyMeaning" => {
973                    raw_hierarchy_meaning = Some(value);
974                }
975                "_hierarchyMeaning" => {
976                    raw_hierarchy_meaning_element = Some(value);
977                }
978                "compositional" => {
979                    raw_compositional = Some(value);
980                }
981                "_compositional" => {
982                    raw_compositional_element = Some(value);
983                }
984                "versionNeeded" => {
985                    raw_version_needed = Some(value);
986                }
987                "_versionNeeded" => {
988                    raw_version_needed_element = Some(value);
989                }
990                "content" => {
991                    raw_content = Some(value);
992                }
993                "_content" => {
994                    raw_content_element = Some(value);
995                }
996                "supplements" => {
997                    raw_supplements = Some(value);
998                }
999                "_supplements" => {
1000                    raw_supplements_element = Some(value);
1001                }
1002                "count" => {
1003                    raw_count = Some(value);
1004                }
1005                "_count" => {
1006                    raw_count_element = Some(value);
1007                }
1008                "filter" => {
1009                    raw_filter = Some(value);
1010                }
1011                "property" => {
1012                    raw_property = Some(value);
1013                }
1014                "concept" => {
1015                    raw_concept = Some(value);
1016                }
1017                other => {
1018                    return path.with(other, |path| {
1019                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
1020                    });
1021                }
1022            }
1023        }
1024        let field_id = raw_id
1025            .map(|value| {
1026                path.with("id", |path| {
1027                    let value = super::super::codec::expect_single(value, path)?;
1028                    super::primitives::checked_id(
1029                        super::super::codec::expect_string(value, path)?,
1030                        path,
1031                    )
1032                })
1033            })
1034            .transpose()?;
1035        let field_meta = raw_meta
1036            .map(|value| {
1037                path.with("meta", |path| {
1038                    super::super::codec::Json::from_json(
1039                        super::super::codec::expect_object(
1040                            super::super::codec::expect_single(value, path)?,
1041                            path,
1042                        )?,
1043                        path,
1044                    )
1045                })
1046            })
1047            .transpose()?;
1048        let field_implicit_rules = match (raw_implicit_rules, raw_implicit_rules_element) {
1049            (None, None) => None,
1050            (value, element) => Some(path.with("implicitRules", |path| {
1051                super::super::codec::Primitive::from_json_parts(value, element, path)
1052            })?),
1053        };
1054        let field_language = match (raw_language, raw_language_element) {
1055            (None, None) => None,
1056            (value, element) => Some(path.with("language", |path| {
1057                super::super::codec::Primitive::from_json_parts(value, element, path)
1058            })?),
1059        };
1060        let field_text = raw_text
1061            .map(|value| {
1062                path.with("text", |path| {
1063                    super::super::codec::Json::from_json(
1064                        super::super::codec::expect_object(
1065                            super::super::codec::expect_single(value, path)?,
1066                            path,
1067                        )?,
1068                        path,
1069                    )
1070                })
1071            })
1072            .transpose()?;
1073        let mut field_contained = Vec::new();
1074        if let Some(raw) = raw_contained {
1075            for (index, value) in path
1076                .with("contained", |path| {
1077                    super::super::codec::expect_array(raw, path)
1078                })?
1079                .iter()
1080                .enumerate()
1081            {
1082                field_contained.push(path.with_index("contained", index, |path| {
1083                    super::super::codec::Json::from_json(
1084                        super::super::codec::expect_object(value, path)?,
1085                        path,
1086                    )
1087                })?);
1088            }
1089        }
1090        let mut field_extension = Vec::new();
1091        if let Some(raw) = raw_extension {
1092            for (index, value) in path
1093                .with("extension", |path| {
1094                    super::super::codec::expect_array(raw, path)
1095                })?
1096                .iter()
1097                .enumerate()
1098            {
1099                field_extension.push(path.with_index("extension", index, |path| {
1100                    super::super::codec::Json::from_json(
1101                        super::super::codec::expect_object(value, path)?,
1102                        path,
1103                    )
1104                })?);
1105            }
1106        }
1107        let mut field_modifier_extension = Vec::new();
1108        if let Some(raw) = raw_modifier_extension {
1109            for (index, value) in path
1110                .with("modifierExtension", |path| {
1111                    super::super::codec::expect_array(raw, path)
1112                })?
1113                .iter()
1114                .enumerate()
1115            {
1116                field_modifier_extension.push(path.with_index(
1117                    "modifierExtension",
1118                    index,
1119                    |path| {
1120                        super::super::codec::Json::from_json(
1121                            super::super::codec::expect_object(value, path)?,
1122                            path,
1123                        )
1124                    },
1125                )?);
1126            }
1127        }
1128        let field_url = match (raw_url, raw_url_element) {
1129            (None, None) => None,
1130            (value, element) => Some(path.with("url", |path| {
1131                super::super::codec::Primitive::from_json_parts(value, element, path)
1132            })?),
1133        };
1134        let mut field_identifier = Vec::new();
1135        if let Some(raw) = raw_identifier {
1136            for (index, value) in path
1137                .with("identifier", |path| {
1138                    super::super::codec::expect_array(raw, path)
1139                })?
1140                .iter()
1141                .enumerate()
1142            {
1143                field_identifier.push(path.with_index("identifier", index, |path| {
1144                    super::super::codec::Json::from_json(
1145                        super::super::codec::expect_object(value, path)?,
1146                        path,
1147                    )
1148                })?);
1149            }
1150        }
1151        let field_version = match (raw_version, raw_version_element) {
1152            (None, None) => None,
1153            (value, element) => Some(path.with("version", |path| {
1154                super::super::codec::Primitive::from_json_parts(value, element, path)
1155            })?),
1156        };
1157        let field_version_algorithm = match raw_version_algorithm.suffix {
1158            None => None,
1159            Some(suffix) => Some(path.with("versionAlgorithm", |path| {
1160                CodeSystemVersionAlgorithm::from_json_parts(
1161                    suffix,
1162                    raw_version_algorithm.value,
1163                    raw_version_algorithm.element,
1164                    path,
1165                )
1166            })?),
1167        };
1168        let field_name = match (raw_name, raw_name_element) {
1169            (None, None) => None,
1170            (value, element) => Some(path.with("name", |path| {
1171                super::super::codec::Primitive::from_json_parts(value, element, path)
1172            })?),
1173        };
1174        let field_title = match (raw_title, raw_title_element) {
1175            (None, None) => None,
1176            (value, element) => Some(path.with("title", |path| {
1177                super::super::codec::Primitive::from_json_parts(value, element, path)
1178            })?),
1179        };
1180        let field_status = path.with("status", |path| {
1181            super::super::codec::Primitive::from_json_parts(raw_status, raw_status_element, path)
1182        })?;
1183        let field_experimental = match (raw_experimental, raw_experimental_element) {
1184            (None, None) => None,
1185            (value, element) => Some(path.with("experimental", |path| {
1186                super::super::codec::Primitive::from_json_parts(value, element, path)
1187            })?),
1188        };
1189        let field_date = match (raw_date, raw_date_element) {
1190            (None, None) => None,
1191            (value, element) => Some(path.with("date", |path| {
1192                super::super::codec::Primitive::from_json_parts(value, element, path)
1193            })?),
1194        };
1195        let field_publisher = match (raw_publisher, raw_publisher_element) {
1196            (None, None) => None,
1197            (value, element) => Some(path.with("publisher", |path| {
1198                super::super::codec::Primitive::from_json_parts(value, element, path)
1199            })?),
1200        };
1201        let mut field_contact = Vec::new();
1202        if let Some(raw) = raw_contact {
1203            for (index, value) in path
1204                .with("contact", |path| {
1205                    super::super::codec::expect_array(raw, path)
1206                })?
1207                .iter()
1208                .enumerate()
1209            {
1210                field_contact.push(path.with_index("contact", index, |path| {
1211                    super::super::codec::Json::from_json(
1212                        super::super::codec::expect_object(value, path)?,
1213                        path,
1214                    )
1215                })?);
1216            }
1217        }
1218        let field_description = match (raw_description, raw_description_element) {
1219            (None, None) => None,
1220            (value, element) => Some(path.with("description", |path| {
1221                super::super::codec::Primitive::from_json_parts(value, element, path)
1222            })?),
1223        };
1224        let mut field_use_context = Vec::new();
1225        if let Some(raw) = raw_use_context {
1226            for (index, value) in path
1227                .with("useContext", |path| {
1228                    super::super::codec::expect_array(raw, path)
1229                })?
1230                .iter()
1231                .enumerate()
1232            {
1233                field_use_context.push(path.with_index("useContext", index, |path| {
1234                    super::super::codec::Json::from_json(
1235                        super::super::codec::expect_object(value, path)?,
1236                        path,
1237                    )
1238                })?);
1239            }
1240        }
1241        let mut field_jurisdiction = Vec::new();
1242        if let Some(raw) = raw_jurisdiction {
1243            for (index, value) in path
1244                .with("jurisdiction", |path| {
1245                    super::super::codec::expect_array(raw, path)
1246                })?
1247                .iter()
1248                .enumerate()
1249            {
1250                field_jurisdiction.push(path.with_index("jurisdiction", index, |path| {
1251                    super::super::codec::Json::from_json(
1252                        super::super::codec::expect_object(value, path)?,
1253                        path,
1254                    )
1255                })?);
1256            }
1257        }
1258        let field_purpose = match (raw_purpose, raw_purpose_element) {
1259            (None, None) => None,
1260            (value, element) => Some(path.with("purpose", |path| {
1261                super::super::codec::Primitive::from_json_parts(value, element, path)
1262            })?),
1263        };
1264        let field_copyright = match (raw_copyright, raw_copyright_element) {
1265            (None, None) => None,
1266            (value, element) => Some(path.with("copyright", |path| {
1267                super::super::codec::Primitive::from_json_parts(value, element, path)
1268            })?),
1269        };
1270        let field_copyright_label = match (raw_copyright_label, raw_copyright_label_element) {
1271            (None, None) => None,
1272            (value, element) => Some(path.with("copyrightLabel", |path| {
1273                super::super::codec::Primitive::from_json_parts(value, element, path)
1274            })?),
1275        };
1276        let field_approval_date = match (raw_approval_date, raw_approval_date_element) {
1277            (None, None) => None,
1278            (value, element) => Some(path.with("approvalDate", |path| {
1279                super::super::codec::Primitive::from_json_parts(value, element, path)
1280            })?),
1281        };
1282        let field_last_review_date = match (raw_last_review_date, raw_last_review_date_element) {
1283            (None, None) => None,
1284            (value, element) => Some(path.with("lastReviewDate", |path| {
1285                super::super::codec::Primitive::from_json_parts(value, element, path)
1286            })?),
1287        };
1288        let field_effective_period = raw_effective_period
1289            .map(|value| {
1290                path.with("effectivePeriod", |path| {
1291                    super::super::codec::Json::from_json(
1292                        super::super::codec::expect_object(
1293                            super::super::codec::expect_single(value, path)?,
1294                            path,
1295                        )?,
1296                        path,
1297                    )
1298                })
1299            })
1300            .transpose()?;
1301        let mut field_topic = Vec::new();
1302        if let Some(raw) = raw_topic {
1303            for (index, value) in path
1304                .with("topic", |path| super::super::codec::expect_array(raw, path))?
1305                .iter()
1306                .enumerate()
1307            {
1308                field_topic.push(path.with_index("topic", index, |path| {
1309                    super::super::codec::Json::from_json(
1310                        super::super::codec::expect_object(value, path)?,
1311                        path,
1312                    )
1313                })?);
1314            }
1315        }
1316        let mut field_author = Vec::new();
1317        if let Some(raw) = raw_author {
1318            for (index, value) in path
1319                .with("author", |path| {
1320                    super::super::codec::expect_array(raw, path)
1321                })?
1322                .iter()
1323                .enumerate()
1324            {
1325                field_author.push(path.with_index("author", index, |path| {
1326                    super::super::codec::Json::from_json(
1327                        super::super::codec::expect_object(value, path)?,
1328                        path,
1329                    )
1330                })?);
1331            }
1332        }
1333        let mut field_editor = Vec::new();
1334        if let Some(raw) = raw_editor {
1335            for (index, value) in path
1336                .with("editor", |path| {
1337                    super::super::codec::expect_array(raw, path)
1338                })?
1339                .iter()
1340                .enumerate()
1341            {
1342                field_editor.push(path.with_index("editor", index, |path| {
1343                    super::super::codec::Json::from_json(
1344                        super::super::codec::expect_object(value, path)?,
1345                        path,
1346                    )
1347                })?);
1348            }
1349        }
1350        let mut field_reviewer = Vec::new();
1351        if let Some(raw) = raw_reviewer {
1352            for (index, value) in path
1353                .with("reviewer", |path| {
1354                    super::super::codec::expect_array(raw, path)
1355                })?
1356                .iter()
1357                .enumerate()
1358            {
1359                field_reviewer.push(path.with_index("reviewer", index, |path| {
1360                    super::super::codec::Json::from_json(
1361                        super::super::codec::expect_object(value, path)?,
1362                        path,
1363                    )
1364                })?);
1365            }
1366        }
1367        let mut field_endorser = Vec::new();
1368        if let Some(raw) = raw_endorser {
1369            for (index, value) in path
1370                .with("endorser", |path| {
1371                    super::super::codec::expect_array(raw, path)
1372                })?
1373                .iter()
1374                .enumerate()
1375            {
1376                field_endorser.push(path.with_index("endorser", index, |path| {
1377                    super::super::codec::Json::from_json(
1378                        super::super::codec::expect_object(value, path)?,
1379                        path,
1380                    )
1381                })?);
1382            }
1383        }
1384        let mut field_related_artifact = Vec::new();
1385        if let Some(raw) = raw_related_artifact {
1386            for (index, value) in path
1387                .with("relatedArtifact", |path| {
1388                    super::super::codec::expect_array(raw, path)
1389                })?
1390                .iter()
1391                .enumerate()
1392            {
1393                field_related_artifact.push(path.with_index("relatedArtifact", index, |path| {
1394                    super::super::codec::Json::from_json(
1395                        super::super::codec::expect_object(value, path)?,
1396                        path,
1397                    )
1398                })?);
1399            }
1400        }
1401        let field_case_sensitive = match (raw_case_sensitive, raw_case_sensitive_element) {
1402            (None, None) => None,
1403            (value, element) => Some(path.with("caseSensitive", |path| {
1404                super::super::codec::Primitive::from_json_parts(value, element, path)
1405            })?),
1406        };
1407        let field_value_set = match (raw_value_set, raw_value_set_element) {
1408            (None, None) => None,
1409            (value, element) => Some(path.with("valueSet", |path| {
1410                super::super::codec::Primitive::from_json_parts(value, element, path)
1411            })?),
1412        };
1413        let field_hierarchy_meaning = match (raw_hierarchy_meaning, raw_hierarchy_meaning_element) {
1414            (None, None) => None,
1415            (value, element) => Some(path.with("hierarchyMeaning", |path| {
1416                super::super::codec::Primitive::from_json_parts(value, element, path)
1417            })?),
1418        };
1419        let field_compositional = match (raw_compositional, raw_compositional_element) {
1420            (None, None) => None,
1421            (value, element) => Some(path.with("compositional", |path| {
1422                super::super::codec::Primitive::from_json_parts(value, element, path)
1423            })?),
1424        };
1425        let field_version_needed = match (raw_version_needed, raw_version_needed_element) {
1426            (None, None) => None,
1427            (value, element) => Some(path.with("versionNeeded", |path| {
1428                super::super::codec::Primitive::from_json_parts(value, element, path)
1429            })?),
1430        };
1431        let field_content = path.with("content", |path| {
1432            super::super::codec::Primitive::from_json_parts(raw_content, raw_content_element, path)
1433        })?;
1434        let field_supplements = match (raw_supplements, raw_supplements_element) {
1435            (None, None) => None,
1436            (value, element) => Some(path.with("supplements", |path| {
1437                super::super::codec::Primitive::from_json_parts(value, element, path)
1438            })?),
1439        };
1440        let field_count = match (raw_count, raw_count_element) {
1441            (None, None) => None,
1442            (value, element) => Some(path.with("count", |path| {
1443                super::super::codec::Primitive::from_json_parts(value, element, path)
1444            })?),
1445        };
1446        let mut field_filter = Vec::new();
1447        if let Some(raw) = raw_filter {
1448            for (index, value) in path
1449                .with("filter", |path| {
1450                    super::super::codec::expect_array(raw, path)
1451                })?
1452                .iter()
1453                .enumerate()
1454            {
1455                field_filter.push(path.with_index("filter", index, |path| {
1456                    super::super::codec::Json::from_json(
1457                        super::super::codec::expect_object(value, path)?,
1458                        path,
1459                    )
1460                })?);
1461            }
1462        }
1463        let mut field_property = Vec::new();
1464        if let Some(raw) = raw_property {
1465            for (index, value) in path
1466                .with("property", |path| {
1467                    super::super::codec::expect_array(raw, path)
1468                })?
1469                .iter()
1470                .enumerate()
1471            {
1472                field_property.push(path.with_index("property", index, |path| {
1473                    super::super::codec::Json::from_json(
1474                        super::super::codec::expect_object(value, path)?,
1475                        path,
1476                    )
1477                })?);
1478            }
1479        }
1480        let mut field_concept = Vec::new();
1481        if let Some(raw) = raw_concept {
1482            for (index, value) in path
1483                .with("concept", |path| {
1484                    super::super::codec::expect_array(raw, path)
1485                })?
1486                .iter()
1487                .enumerate()
1488            {
1489                field_concept.push(path.with_index("concept", index, |path| {
1490                    super::super::codec::Json::from_json(
1491                        super::super::codec::expect_object(value, path)?,
1492                        path,
1493                    )
1494                })?);
1495            }
1496        }
1497        Ok(Self {
1498            id: field_id,
1499            meta: field_meta,
1500            implicit_rules: field_implicit_rules,
1501            language: field_language,
1502            text: field_text,
1503            contained: field_contained,
1504            extension: field_extension,
1505            modifier_extension: field_modifier_extension,
1506            url: field_url,
1507            identifier: field_identifier,
1508            version: field_version,
1509            version_algorithm: field_version_algorithm,
1510            name: field_name,
1511            title: field_title,
1512            status: field_status,
1513            experimental: field_experimental,
1514            date: field_date,
1515            publisher: field_publisher,
1516            contact: field_contact,
1517            description: field_description,
1518            use_context: field_use_context,
1519            jurisdiction: field_jurisdiction,
1520            purpose: field_purpose,
1521            copyright: field_copyright,
1522            copyright_label: field_copyright_label,
1523            approval_date: field_approval_date,
1524            last_review_date: field_last_review_date,
1525            effective_period: field_effective_period,
1526            topic: field_topic,
1527            author: field_author,
1528            editor: field_editor,
1529            reviewer: field_reviewer,
1530            endorser: field_endorser,
1531            related_artifact: field_related_artifact,
1532            case_sensitive: field_case_sensitive,
1533            value_set: field_value_set,
1534            hierarchy_meaning: field_hierarchy_meaning,
1535            compositional: field_compositional,
1536            version_needed: field_version_needed,
1537            content: field_content,
1538            supplements: field_supplements,
1539            count: field_count,
1540            filter: field_filter,
1541            property: field_property,
1542            concept: field_concept,
1543        })
1544    }
1545}
1546
1547impl serde::Serialize for CodeSystem {
1548    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
1549        let mut map = serde::Serializer::serialize_map(serializer, None)?;
1550        if let Some(item) = &self.approval_date {
1551            super::super::codec::element_entry(&mut map, "_approvalDate", item)?;
1552        }
1553        if let Some(item) = &self.case_sensitive {
1554            super::super::codec::element_entry(&mut map, "_caseSensitive", item)?;
1555        }
1556        if let Some(item) = &self.compositional {
1557            super::super::codec::element_entry(&mut map, "_compositional", item)?;
1558        }
1559        super::super::codec::element_entry(&mut map, "_content", &self.content)?;
1560        if let Some(item) = &self.copyright {
1561            super::super::codec::element_entry(&mut map, "_copyright", item)?;
1562        }
1563        if let Some(item) = &self.copyright_label {
1564            super::super::codec::element_entry(&mut map, "_copyrightLabel", item)?;
1565        }
1566        if let Some(item) = &self.count {
1567            super::super::codec::element_entry(&mut map, "_count", item)?;
1568        }
1569        if let Some(item) = &self.date {
1570            super::super::codec::element_entry(&mut map, "_date", item)?;
1571        }
1572        if let Some(item) = &self.description {
1573            super::super::codec::element_entry(&mut map, "_description", item)?;
1574        }
1575        if let Some(item) = &self.experimental {
1576            super::super::codec::element_entry(&mut map, "_experimental", item)?;
1577        }
1578        if let Some(item) = &self.hierarchy_meaning {
1579            super::super::codec::element_entry(&mut map, "_hierarchyMeaning", item)?;
1580        }
1581        if let Some(item) = &self.implicit_rules {
1582            super::super::codec::element_entry(&mut map, "_implicitRules", item)?;
1583        }
1584        if let Some(item) = &self.language {
1585            super::super::codec::element_entry(&mut map, "_language", item)?;
1586        }
1587        if let Some(item) = &self.last_review_date {
1588            super::super::codec::element_entry(&mut map, "_lastReviewDate", item)?;
1589        }
1590        if let Some(item) = &self.name {
1591            super::super::codec::element_entry(&mut map, "_name", item)?;
1592        }
1593        if let Some(item) = &self.publisher {
1594            super::super::codec::element_entry(&mut map, "_publisher", item)?;
1595        }
1596        if let Some(item) = &self.purpose {
1597            super::super::codec::element_entry(&mut map, "_purpose", item)?;
1598        }
1599        super::super::codec::element_entry(&mut map, "_status", &self.status)?;
1600        if let Some(item) = &self.supplements {
1601            super::super::codec::element_entry(&mut map, "_supplements", item)?;
1602        }
1603        if let Some(item) = &self.title {
1604            super::super::codec::element_entry(&mut map, "_title", item)?;
1605        }
1606        if let Some(item) = &self.url {
1607            super::super::codec::element_entry(&mut map, "_url", item)?;
1608        }
1609        if let Some(item) = &self.value_set {
1610            super::super::codec::element_entry(&mut map, "_valueSet", item)?;
1611        }
1612        if let Some(item) = &self.version {
1613            super::super::codec::element_entry(&mut map, "_version", item)?;
1614        }
1615        if let Some(CodeSystemVersionAlgorithm::String(inner)) = &self.version_algorithm {
1616            super::super::codec::element_entry(&mut map, "_versionAlgorithmString", inner)?;
1617        }
1618        if let Some(item) = &self.version_needed {
1619            super::super::codec::element_entry(&mut map, "_versionNeeded", item)?;
1620        }
1621        if let Some(item) = &self.approval_date {
1622            super::super::codec::value_entry(&mut map, "approvalDate", item)?;
1623        }
1624        if !self.author.is_empty() {
1625            serde::ser::SerializeMap::serialize_entry(&mut map, "author", &self.author)?;
1626        }
1627        if let Some(item) = &self.case_sensitive {
1628            super::super::codec::value_entry(&mut map, "caseSensitive", item)?;
1629        }
1630        if let Some(item) = &self.compositional {
1631            super::super::codec::value_entry(&mut map, "compositional", item)?;
1632        }
1633        if !self.concept.is_empty() {
1634            serde::ser::SerializeMap::serialize_entry(&mut map, "concept", &self.concept)?;
1635        }
1636        if !self.contact.is_empty() {
1637            serde::ser::SerializeMap::serialize_entry(&mut map, "contact", &self.contact)?;
1638        }
1639        if !self.contained.is_empty() {
1640            serde::ser::SerializeMap::serialize_entry(&mut map, "contained", &self.contained)?;
1641        }
1642        super::super::codec::value_entry(&mut map, "content", &self.content)?;
1643        if let Some(item) = &self.copyright {
1644            super::super::codec::value_entry(&mut map, "copyright", item)?;
1645        }
1646        if let Some(item) = &self.copyright_label {
1647            super::super::codec::value_entry(&mut map, "copyrightLabel", item)?;
1648        }
1649        if let Some(item) = &self.count {
1650            super::super::codec::value_entry(&mut map, "count", item)?;
1651        }
1652        if let Some(item) = &self.date {
1653            super::super::codec::value_entry(&mut map, "date", item)?;
1654        }
1655        if let Some(item) = &self.description {
1656            super::super::codec::value_entry(&mut map, "description", item)?;
1657        }
1658        if !self.editor.is_empty() {
1659            serde::ser::SerializeMap::serialize_entry(&mut map, "editor", &self.editor)?;
1660        }
1661        if let Some(item) = &self.effective_period {
1662            serde::ser::SerializeMap::serialize_entry(&mut map, "effectivePeriod", item)?;
1663        }
1664        if !self.endorser.is_empty() {
1665            serde::ser::SerializeMap::serialize_entry(&mut map, "endorser", &self.endorser)?;
1666        }
1667        if let Some(item) = &self.experimental {
1668            super::super::codec::value_entry(&mut map, "experimental", item)?;
1669        }
1670        if !self.extension.is_empty() {
1671            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
1672        }
1673        if !self.filter.is_empty() {
1674            serde::ser::SerializeMap::serialize_entry(&mut map, "filter", &self.filter)?;
1675        }
1676        if let Some(item) = &self.hierarchy_meaning {
1677            super::super::codec::value_entry(&mut map, "hierarchyMeaning", item)?;
1678        }
1679        if let Some(v) = &self.id {
1680            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
1681        }
1682        if !self.identifier.is_empty() {
1683            serde::ser::SerializeMap::serialize_entry(&mut map, "identifier", &self.identifier)?;
1684        }
1685        if let Some(item) = &self.implicit_rules {
1686            super::super::codec::value_entry(&mut map, "implicitRules", item)?;
1687        }
1688        if !self.jurisdiction.is_empty() {
1689            serde::ser::SerializeMap::serialize_entry(
1690                &mut map,
1691                "jurisdiction",
1692                &self.jurisdiction,
1693            )?;
1694        }
1695        if let Some(item) = &self.language {
1696            super::super::codec::value_entry(&mut map, "language", item)?;
1697        }
1698        if let Some(item) = &self.last_review_date {
1699            super::super::codec::value_entry(&mut map, "lastReviewDate", item)?;
1700        }
1701        if let Some(item) = &self.meta {
1702            serde::ser::SerializeMap::serialize_entry(&mut map, "meta", item)?;
1703        }
1704        if !self.modifier_extension.is_empty() {
1705            serde::ser::SerializeMap::serialize_entry(
1706                &mut map,
1707                "modifierExtension",
1708                &self.modifier_extension,
1709            )?;
1710        }
1711        if let Some(item) = &self.name {
1712            super::super::codec::value_entry(&mut map, "name", item)?;
1713        }
1714        if !self.property.is_empty() {
1715            serde::ser::SerializeMap::serialize_entry(&mut map, "property", &self.property)?;
1716        }
1717        if let Some(item) = &self.publisher {
1718            super::super::codec::value_entry(&mut map, "publisher", item)?;
1719        }
1720        if let Some(item) = &self.purpose {
1721            super::super::codec::value_entry(&mut map, "purpose", item)?;
1722        }
1723        if !self.related_artifact.is_empty() {
1724            serde::ser::SerializeMap::serialize_entry(
1725                &mut map,
1726                "relatedArtifact",
1727                &self.related_artifact,
1728            )?;
1729        }
1730        serde::ser::SerializeMap::serialize_entry(&mut map, "resourceType", "CodeSystem")?;
1731        if !self.reviewer.is_empty() {
1732            serde::ser::SerializeMap::serialize_entry(&mut map, "reviewer", &self.reviewer)?;
1733        }
1734        super::super::codec::value_entry(&mut map, "status", &self.status)?;
1735        if let Some(item) = &self.supplements {
1736            super::super::codec::value_entry(&mut map, "supplements", item)?;
1737        }
1738        if let Some(item) = &self.text {
1739            serde::ser::SerializeMap::serialize_entry(&mut map, "text", item)?;
1740        }
1741        if let Some(item) = &self.title {
1742            super::super::codec::value_entry(&mut map, "title", item)?;
1743        }
1744        if !self.topic.is_empty() {
1745            serde::ser::SerializeMap::serialize_entry(&mut map, "topic", &self.topic)?;
1746        }
1747        if let Some(item) = &self.url {
1748            super::super::codec::value_entry(&mut map, "url", item)?;
1749        }
1750        if !self.use_context.is_empty() {
1751            serde::ser::SerializeMap::serialize_entry(&mut map, "useContext", &self.use_context)?;
1752        }
1753        if let Some(item) = &self.value_set {
1754            super::super::codec::value_entry(&mut map, "valueSet", item)?;
1755        }
1756        if let Some(item) = &self.version {
1757            super::super::codec::value_entry(&mut map, "version", item)?;
1758        }
1759        match &self.version_algorithm {
1760            Some(CodeSystemVersionAlgorithm::Coding(inner)) => {
1761                serde::ser::SerializeMap::serialize_entry(
1762                    &mut map,
1763                    "versionAlgorithmCoding",
1764                    inner.as_ref(),
1765                )?;
1766            }
1767            Some(CodeSystemVersionAlgorithm::String(inner)) => {
1768                super::super::codec::value_entry(&mut map, "versionAlgorithmString", inner)?;
1769            }
1770            None => {}
1771        }
1772        if let Some(item) = &self.version_needed {
1773            super::super::codec::value_entry(&mut map, "versionNeeded", item)?;
1774        }
1775        serde::ser::SerializeMap::end(map)
1776    }
1777}
1778
1779impl<'de> serde::Deserialize<'de> for CodeSystem {
1780    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1781        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
1782        let mut path = super::super::codec::Path::root("CodeSystem");
1783        let object =
1784            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
1785        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
1786    }
1787}
1788
1789/// Concepts in the code system
1790///
1791/// Concepts that are in the code system. The concept definitions are inherently
1792/// hierarchical, but the definitions must be consulted to determine what the
1793/// meanings of the hierarchical relationships are.
1794#[derive(Debug, Clone, Default, PartialEq, Eq)]
1795pub struct CodeSystemConcept {
1796    /// Unique id for inter-element referencing
1797    ///
1798    /// Unique id for the element within a resource (for internal references). This
1799    /// may be any string value that does not contain spaces.
1800    pub id: Option<std::string::String>,
1801    /// Additional content defined by implementations
1802    ///
1803    /// May be used to represent additional information that is not part of the
1804    /// basic definition of the element. To make the use of extensions safe and
1805    /// managable, there is a strict set of governance applied to the definition and
1806    /// use of extensions. Though any implementer can define an extension, there is
1807    /// a set of requirements that SHALL be met as part of the definition of the
1808    /// extension.
1809    pub extension: Vec<super::extension::Extension>,
1810    /// Extensions that cannot be ignored even if unrecognized
1811    ///
1812    /// May be used to represent additional information that is not part of the
1813    /// basic definition of the element and that modifies the understanding of the
1814    /// element in which it is contained and/or the understanding of the containing
1815    /// element's descendants. Usually modifier elements provide negation or
1816    /// qualification. To make the use of extensions safe and managable, there is a
1817    /// strict set of governance applied to the definition and use of extensions.
1818    /// Though any implementer can define an extension, there is a set of
1819    /// requirements that SHALL be met as part of the definition of the extension.
1820    /// Applications processing a resource are required to check for modifier
1821    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
1822    /// on Resource or DomainResource (including cannot change the meaning of
1823    /// modifierExtension itself).
1824    pub modifier_extension: Vec<super::extension::Extension>,
1825    /// Code that identifies concept
1826    ///
1827    /// A code - a text symbol - that uniquely identifies the concept within the
1828    /// code system.
1829    pub code: super::primitives::Code,
1830    /// Text to display to the user
1831    ///
1832    /// A human readable string that is the recommended default way to present this
1833    /// concept to a user.
1834    pub display: Option<super::primitives::String>,
1835    /// Formal definition
1836    ///
1837    /// The formal definition of the concept. The code system resource does not make
1838    /// formal definitions required, because of the prevalence of legacy systems.
1839    /// However, they are highly recommended, as without them there is no formal
1840    /// meaning associated with the concept.
1841    pub definition: Option<super::primitives::String>,
1842    /// Additional representations for the concept
1843    ///
1844    /// Additional representations for the concept - other languages, aliases,
1845    /// specialized purposes, used for particular purposes, etc.
1846    pub designation: Vec<CodeSystemConceptDesignation>,
1847    /// Property value for the concept
1848    ///
1849    /// A property value for this concept.
1850    pub property: Vec<CodeSystemConceptProperty>,
1851    /// Child Concepts (is-a/contains/categorizes)
1852    ///
1853    /// Defines children of a concept to produce a hierarchy of concepts. The nature
1854    /// of the relationships is variable (is-a/contains/categorizes) - see
1855    /// hierarchyMeaning.
1856    pub concept: Vec<CodeSystemConcept>,
1857}
1858
1859impl super::super::codec::Json for CodeSystemConcept {
1860    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
1861        let mut object = super::super::codec::Object::new();
1862        if let Some(v) = &self.id {
1863            object.insert(
1864                std::string::String::from("id"),
1865                super::super::codec::Value::String(v.clone()),
1866            );
1867        }
1868        if !self.extension.is_empty() {
1869            let mut items = Vec::with_capacity(self.extension.len());
1870            for item in &self.extension {
1871                items.push(super::super::codec::Value::Object(
1872                    super::super::codec::Json::to_json(item)?,
1873                ));
1874            }
1875            object.insert(
1876                std::string::String::from("extension"),
1877                super::super::codec::Value::Array(items),
1878            );
1879        }
1880        if !self.modifier_extension.is_empty() {
1881            let mut items = Vec::with_capacity(self.modifier_extension.len());
1882            for item in &self.modifier_extension {
1883                items.push(super::super::codec::Value::Object(
1884                    super::super::codec::Json::to_json(item)?,
1885                ));
1886            }
1887            object.insert(
1888                std::string::String::from("modifierExtension"),
1889                super::super::codec::Value::Array(items),
1890            );
1891        }
1892        if let Some(v) = super::super::codec::Primitive::value_json(&self.code)? {
1893            object.insert(std::string::String::from("code"), v);
1894        }
1895        if let Some(e) = super::super::codec::Primitive::element_json(&self.code)? {
1896            object.insert(std::string::String::from("_code"), e);
1897        }
1898        if let Some(item) = &self.display {
1899            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
1900                object.insert(std::string::String::from("display"), v);
1901            }
1902            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
1903                object.insert(std::string::String::from("_display"), e);
1904            }
1905        }
1906        if let Some(item) = &self.definition {
1907            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
1908                object.insert(std::string::String::from("definition"), v);
1909            }
1910            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
1911                object.insert(std::string::String::from("_definition"), e);
1912            }
1913        }
1914        if !self.designation.is_empty() {
1915            let mut items = Vec::with_capacity(self.designation.len());
1916            for item in &self.designation {
1917                items.push(super::super::codec::Value::Object(
1918                    super::super::codec::Json::to_json(item)?,
1919                ));
1920            }
1921            object.insert(
1922                std::string::String::from("designation"),
1923                super::super::codec::Value::Array(items),
1924            );
1925        }
1926        if !self.property.is_empty() {
1927            let mut items = Vec::with_capacity(self.property.len());
1928            for item in &self.property {
1929                items.push(super::super::codec::Value::Object(
1930                    super::super::codec::Json::to_json(item)?,
1931                ));
1932            }
1933            object.insert(
1934                std::string::String::from("property"),
1935                super::super::codec::Value::Array(items),
1936            );
1937        }
1938        if !self.concept.is_empty() {
1939            let mut items = Vec::with_capacity(self.concept.len());
1940            for item in &self.concept {
1941                items.push(super::super::codec::Value::Object(
1942                    super::super::codec::Json::to_json(item)?,
1943                ));
1944            }
1945            object.insert(
1946                std::string::String::from("concept"),
1947                super::super::codec::Value::Array(items),
1948            );
1949        }
1950        Ok(object)
1951    }
1952
1953    fn from_json(
1954        object: &super::super::codec::Object,
1955        path: &mut super::super::codec::Path,
1956    ) -> Result<Self, super::super::codec::DecodeError> {
1957        let mut raw_id: Option<&super::super::codec::Value> = None;
1958        let mut raw_extension: Option<&super::super::codec::Value> = None;
1959        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
1960        let mut raw_code: Option<&super::super::codec::Value> = None;
1961        let mut raw_code_element: Option<&super::super::codec::Value> = None;
1962        let mut raw_display: Option<&super::super::codec::Value> = None;
1963        let mut raw_display_element: Option<&super::super::codec::Value> = None;
1964        let mut raw_definition: Option<&super::super::codec::Value> = None;
1965        let mut raw_definition_element: Option<&super::super::codec::Value> = None;
1966        let mut raw_designation: Option<&super::super::codec::Value> = None;
1967        let mut raw_property: Option<&super::super::codec::Value> = None;
1968        let mut raw_concept: Option<&super::super::codec::Value> = None;
1969        for (key, value) in object {
1970            match key.as_str() {
1971                "id" => {
1972                    raw_id = Some(value);
1973                }
1974                "extension" => {
1975                    raw_extension = Some(value);
1976                }
1977                "modifierExtension" => {
1978                    raw_modifier_extension = Some(value);
1979                }
1980                "code" => {
1981                    raw_code = Some(value);
1982                }
1983                "_code" => {
1984                    raw_code_element = Some(value);
1985                }
1986                "display" => {
1987                    raw_display = Some(value);
1988                }
1989                "_display" => {
1990                    raw_display_element = Some(value);
1991                }
1992                "definition" => {
1993                    raw_definition = Some(value);
1994                }
1995                "_definition" => {
1996                    raw_definition_element = Some(value);
1997                }
1998                "designation" => {
1999                    raw_designation = Some(value);
2000                }
2001                "property" => {
2002                    raw_property = Some(value);
2003                }
2004                "concept" => {
2005                    raw_concept = Some(value);
2006                }
2007                other => {
2008                    return path.with(other, |path| {
2009                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
2010                    });
2011                }
2012            }
2013        }
2014        let field_id = raw_id
2015            .map(|value| {
2016                path.with("id", |path| {
2017                    let value = super::super::codec::expect_single(value, path)?;
2018                    super::primitives::checked_string(
2019                        super::super::codec::expect_string(value, path)?,
2020                        path,
2021                    )
2022                })
2023            })
2024            .transpose()?;
2025        let mut field_extension = Vec::new();
2026        if let Some(raw) = raw_extension {
2027            for (index, value) in path
2028                .with("extension", |path| {
2029                    super::super::codec::expect_array(raw, path)
2030                })?
2031                .iter()
2032                .enumerate()
2033            {
2034                field_extension.push(path.with_index("extension", index, |path| {
2035                    super::super::codec::Json::from_json(
2036                        super::super::codec::expect_object(value, path)?,
2037                        path,
2038                    )
2039                })?);
2040            }
2041        }
2042        let mut field_modifier_extension = Vec::new();
2043        if let Some(raw) = raw_modifier_extension {
2044            for (index, value) in path
2045                .with("modifierExtension", |path| {
2046                    super::super::codec::expect_array(raw, path)
2047                })?
2048                .iter()
2049                .enumerate()
2050            {
2051                field_modifier_extension.push(path.with_index(
2052                    "modifierExtension",
2053                    index,
2054                    |path| {
2055                        super::super::codec::Json::from_json(
2056                            super::super::codec::expect_object(value, path)?,
2057                            path,
2058                        )
2059                    },
2060                )?);
2061            }
2062        }
2063        let field_code = path.with("code", |path| {
2064            super::super::codec::Primitive::from_json_parts(raw_code, raw_code_element, path)
2065        })?;
2066        let field_display = match (raw_display, raw_display_element) {
2067            (None, None) => None,
2068            (value, element) => Some(path.with("display", |path| {
2069                super::super::codec::Primitive::from_json_parts(value, element, path)
2070            })?),
2071        };
2072        let field_definition = match (raw_definition, raw_definition_element) {
2073            (None, None) => None,
2074            (value, element) => Some(path.with("definition", |path| {
2075                super::super::codec::Primitive::from_json_parts(value, element, path)
2076            })?),
2077        };
2078        let mut field_designation = Vec::new();
2079        if let Some(raw) = raw_designation {
2080            for (index, value) in path
2081                .with("designation", |path| {
2082                    super::super::codec::expect_array(raw, path)
2083                })?
2084                .iter()
2085                .enumerate()
2086            {
2087                field_designation.push(path.with_index("designation", index, |path| {
2088                    super::super::codec::Json::from_json(
2089                        super::super::codec::expect_object(value, path)?,
2090                        path,
2091                    )
2092                })?);
2093            }
2094        }
2095        let mut field_property = Vec::new();
2096        if let Some(raw) = raw_property {
2097            for (index, value) in path
2098                .with("property", |path| {
2099                    super::super::codec::expect_array(raw, path)
2100                })?
2101                .iter()
2102                .enumerate()
2103            {
2104                field_property.push(path.with_index("property", index, |path| {
2105                    super::super::codec::Json::from_json(
2106                        super::super::codec::expect_object(value, path)?,
2107                        path,
2108                    )
2109                })?);
2110            }
2111        }
2112        let mut field_concept = Vec::new();
2113        if let Some(raw) = raw_concept {
2114            for (index, value) in path
2115                .with("concept", |path| {
2116                    super::super::codec::expect_array(raw, path)
2117                })?
2118                .iter()
2119                .enumerate()
2120            {
2121                field_concept.push(path.with_index("concept", index, |path| {
2122                    super::super::codec::Json::from_json(
2123                        super::super::codec::expect_object(value, path)?,
2124                        path,
2125                    )
2126                })?);
2127            }
2128        }
2129        Ok(Self {
2130            id: field_id,
2131            extension: field_extension,
2132            modifier_extension: field_modifier_extension,
2133            code: field_code,
2134            display: field_display,
2135            definition: field_definition,
2136            designation: field_designation,
2137            property: field_property,
2138            concept: field_concept,
2139        })
2140    }
2141}
2142
2143impl serde::Serialize for CodeSystemConcept {
2144    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2145        let mut map = serde::Serializer::serialize_map(serializer, None)?;
2146        super::super::codec::element_entry(&mut map, "_code", &self.code)?;
2147        if let Some(item) = &self.definition {
2148            super::super::codec::element_entry(&mut map, "_definition", item)?;
2149        }
2150        if let Some(item) = &self.display {
2151            super::super::codec::element_entry(&mut map, "_display", item)?;
2152        }
2153        super::super::codec::value_entry(&mut map, "code", &self.code)?;
2154        if !self.concept.is_empty() {
2155            serde::ser::SerializeMap::serialize_entry(&mut map, "concept", &self.concept)?;
2156        }
2157        if let Some(item) = &self.definition {
2158            super::super::codec::value_entry(&mut map, "definition", item)?;
2159        }
2160        if !self.designation.is_empty() {
2161            serde::ser::SerializeMap::serialize_entry(&mut map, "designation", &self.designation)?;
2162        }
2163        if let Some(item) = &self.display {
2164            super::super::codec::value_entry(&mut map, "display", item)?;
2165        }
2166        if !self.extension.is_empty() {
2167            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
2168        }
2169        if let Some(v) = &self.id {
2170            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
2171        }
2172        if !self.modifier_extension.is_empty() {
2173            serde::ser::SerializeMap::serialize_entry(
2174                &mut map,
2175                "modifierExtension",
2176                &self.modifier_extension,
2177            )?;
2178        }
2179        if !self.property.is_empty() {
2180            serde::ser::SerializeMap::serialize_entry(&mut map, "property", &self.property)?;
2181        }
2182        serde::ser::SerializeMap::end(map)
2183    }
2184}
2185
2186impl<'de> serde::Deserialize<'de> for CodeSystemConcept {
2187    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2188        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
2189        let mut path = super::super::codec::Path::root("CodeSystemConcept");
2190        let object =
2191            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
2192        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
2193    }
2194}
2195
2196/// Additional representations for the concept
2197///
2198/// Additional representations for the concept - other languages, aliases,
2199/// specialized purposes, used for particular purposes, etc.
2200#[derive(Debug, Clone, Default, PartialEq, Eq)]
2201pub struct CodeSystemConceptDesignation {
2202    /// Unique id for inter-element referencing
2203    ///
2204    /// Unique id for the element within a resource (for internal references). This
2205    /// may be any string value that does not contain spaces.
2206    pub id: Option<std::string::String>,
2207    /// Additional content defined by implementations
2208    ///
2209    /// May be used to represent additional information that is not part of the
2210    /// basic definition of the element. To make the use of extensions safe and
2211    /// managable, there is a strict set of governance applied to the definition and
2212    /// use of extensions. Though any implementer can define an extension, there is
2213    /// a set of requirements that SHALL be met as part of the definition of the
2214    /// extension.
2215    pub extension: Vec<super::extension::Extension>,
2216    /// Extensions that cannot be ignored even if unrecognized
2217    ///
2218    /// May be used to represent additional information that is not part of the
2219    /// basic definition of the element and that modifies the understanding of the
2220    /// element in which it is contained and/or the understanding of the containing
2221    /// element's descendants. Usually modifier elements provide negation or
2222    /// qualification. To make the use of extensions safe and managable, there is a
2223    /// strict set of governance applied to the definition and use of extensions.
2224    /// Though any implementer can define an extension, there is a set of
2225    /// requirements that SHALL be met as part of the definition of the extension.
2226    /// Applications processing a resource are required to check for modifier
2227    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
2228    /// on Resource or DomainResource (including cannot change the meaning of
2229    /// modifierExtension itself).
2230    pub modifier_extension: Vec<super::extension::Extension>,
2231    /// Human language of the designation
2232    ///
2233    /// The language this designation is defined for.
2234    pub language: Option<super::primitives::Code>,
2235    /// Details how this designation would be used
2236    ///
2237    /// A code that details how this designation would be used.
2238    pub r#use: Option<super::coding::Coding>,
2239    /// Additional ways how this designation would be used
2240    ///
2241    /// Additional codes that detail how this designation would be used, if there is
2242    /// more than one use.
2243    pub additional_use: Vec<super::coding::Coding>,
2244    /// The text value for this designation.
2245    pub value: super::primitives::String,
2246}
2247
2248impl super::super::codec::Json for CodeSystemConceptDesignation {
2249    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
2250        let mut object = super::super::codec::Object::new();
2251        if let Some(v) = &self.id {
2252            object.insert(
2253                std::string::String::from("id"),
2254                super::super::codec::Value::String(v.clone()),
2255            );
2256        }
2257        if !self.extension.is_empty() {
2258            let mut items = Vec::with_capacity(self.extension.len());
2259            for item in &self.extension {
2260                items.push(super::super::codec::Value::Object(
2261                    super::super::codec::Json::to_json(item)?,
2262                ));
2263            }
2264            object.insert(
2265                std::string::String::from("extension"),
2266                super::super::codec::Value::Array(items),
2267            );
2268        }
2269        if !self.modifier_extension.is_empty() {
2270            let mut items = Vec::with_capacity(self.modifier_extension.len());
2271            for item in &self.modifier_extension {
2272                items.push(super::super::codec::Value::Object(
2273                    super::super::codec::Json::to_json(item)?,
2274                ));
2275            }
2276            object.insert(
2277                std::string::String::from("modifierExtension"),
2278                super::super::codec::Value::Array(items),
2279            );
2280        }
2281        if let Some(item) = &self.language {
2282            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
2283                object.insert(std::string::String::from("language"), v);
2284            }
2285            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
2286                object.insert(std::string::String::from("_language"), e);
2287            }
2288        }
2289        if let Some(item) = &self.r#use {
2290            object.insert(
2291                std::string::String::from("use"),
2292                super::super::codec::Value::Object(super::super::codec::Json::to_json(item)?),
2293            );
2294        }
2295        if !self.additional_use.is_empty() {
2296            let mut items = Vec::with_capacity(self.additional_use.len());
2297            for item in &self.additional_use {
2298                items.push(super::super::codec::Value::Object(
2299                    super::super::codec::Json::to_json(item)?,
2300                ));
2301            }
2302            object.insert(
2303                std::string::String::from("additionalUse"),
2304                super::super::codec::Value::Array(items),
2305            );
2306        }
2307        if let Some(v) = super::super::codec::Primitive::value_json(&self.value)? {
2308            object.insert(std::string::String::from("value"), v);
2309        }
2310        if let Some(e) = super::super::codec::Primitive::element_json(&self.value)? {
2311            object.insert(std::string::String::from("_value"), e);
2312        }
2313        Ok(object)
2314    }
2315
2316    fn from_json(
2317        object: &super::super::codec::Object,
2318        path: &mut super::super::codec::Path,
2319    ) -> Result<Self, super::super::codec::DecodeError> {
2320        let mut raw_id: Option<&super::super::codec::Value> = None;
2321        let mut raw_extension: Option<&super::super::codec::Value> = None;
2322        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
2323        let mut raw_language: Option<&super::super::codec::Value> = None;
2324        let mut raw_language_element: Option<&super::super::codec::Value> = None;
2325        let mut raw_use: Option<&super::super::codec::Value> = None;
2326        let mut raw_additional_use: Option<&super::super::codec::Value> = None;
2327        let mut raw_value: Option<&super::super::codec::Value> = None;
2328        let mut raw_value_element: Option<&super::super::codec::Value> = None;
2329        for (key, value) in object {
2330            match key.as_str() {
2331                "id" => {
2332                    raw_id = Some(value);
2333                }
2334                "extension" => {
2335                    raw_extension = Some(value);
2336                }
2337                "modifierExtension" => {
2338                    raw_modifier_extension = Some(value);
2339                }
2340                "language" => {
2341                    raw_language = Some(value);
2342                }
2343                "_language" => {
2344                    raw_language_element = Some(value);
2345                }
2346                "use" => {
2347                    raw_use = Some(value);
2348                }
2349                "additionalUse" => {
2350                    raw_additional_use = Some(value);
2351                }
2352                "value" => {
2353                    raw_value = Some(value);
2354                }
2355                "_value" => {
2356                    raw_value_element = Some(value);
2357                }
2358                other => {
2359                    return path.with(other, |path| {
2360                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
2361                    });
2362                }
2363            }
2364        }
2365        let field_id = raw_id
2366            .map(|value| {
2367                path.with("id", |path| {
2368                    let value = super::super::codec::expect_single(value, path)?;
2369                    super::primitives::checked_string(
2370                        super::super::codec::expect_string(value, path)?,
2371                        path,
2372                    )
2373                })
2374            })
2375            .transpose()?;
2376        let mut field_extension = Vec::new();
2377        if let Some(raw) = raw_extension {
2378            for (index, value) in path
2379                .with("extension", |path| {
2380                    super::super::codec::expect_array(raw, path)
2381                })?
2382                .iter()
2383                .enumerate()
2384            {
2385                field_extension.push(path.with_index("extension", index, |path| {
2386                    super::super::codec::Json::from_json(
2387                        super::super::codec::expect_object(value, path)?,
2388                        path,
2389                    )
2390                })?);
2391            }
2392        }
2393        let mut field_modifier_extension = Vec::new();
2394        if let Some(raw) = raw_modifier_extension {
2395            for (index, value) in path
2396                .with("modifierExtension", |path| {
2397                    super::super::codec::expect_array(raw, path)
2398                })?
2399                .iter()
2400                .enumerate()
2401            {
2402                field_modifier_extension.push(path.with_index(
2403                    "modifierExtension",
2404                    index,
2405                    |path| {
2406                        super::super::codec::Json::from_json(
2407                            super::super::codec::expect_object(value, path)?,
2408                            path,
2409                        )
2410                    },
2411                )?);
2412            }
2413        }
2414        let field_language = match (raw_language, raw_language_element) {
2415            (None, None) => None,
2416            (value, element) => Some(path.with("language", |path| {
2417                super::super::codec::Primitive::from_json_parts(value, element, path)
2418            })?),
2419        };
2420        let field_use = raw_use
2421            .map(|value| {
2422                path.with("use", |path| {
2423                    super::super::codec::Json::from_json(
2424                        super::super::codec::expect_object(
2425                            super::super::codec::expect_single(value, path)?,
2426                            path,
2427                        )?,
2428                        path,
2429                    )
2430                })
2431            })
2432            .transpose()?;
2433        let mut field_additional_use = Vec::new();
2434        if let Some(raw) = raw_additional_use {
2435            for (index, value) in path
2436                .with("additionalUse", |path| {
2437                    super::super::codec::expect_array(raw, path)
2438                })?
2439                .iter()
2440                .enumerate()
2441            {
2442                field_additional_use.push(path.with_index("additionalUse", index, |path| {
2443                    super::super::codec::Json::from_json(
2444                        super::super::codec::expect_object(value, path)?,
2445                        path,
2446                    )
2447                })?);
2448            }
2449        }
2450        let field_value = path.with("value", |path| {
2451            super::super::codec::Primitive::from_json_parts(raw_value, raw_value_element, path)
2452        })?;
2453        Ok(Self {
2454            id: field_id,
2455            extension: field_extension,
2456            modifier_extension: field_modifier_extension,
2457            language: field_language,
2458            r#use: field_use,
2459            additional_use: field_additional_use,
2460            value: field_value,
2461        })
2462    }
2463}
2464
2465impl serde::Serialize for CodeSystemConceptDesignation {
2466    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2467        let mut map = serde::Serializer::serialize_map(serializer, None)?;
2468        if let Some(item) = &self.language {
2469            super::super::codec::element_entry(&mut map, "_language", item)?;
2470        }
2471        super::super::codec::element_entry(&mut map, "_value", &self.value)?;
2472        if !self.additional_use.is_empty() {
2473            serde::ser::SerializeMap::serialize_entry(
2474                &mut map,
2475                "additionalUse",
2476                &self.additional_use,
2477            )?;
2478        }
2479        if !self.extension.is_empty() {
2480            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
2481        }
2482        if let Some(v) = &self.id {
2483            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
2484        }
2485        if let Some(item) = &self.language {
2486            super::super::codec::value_entry(&mut map, "language", item)?;
2487        }
2488        if !self.modifier_extension.is_empty() {
2489            serde::ser::SerializeMap::serialize_entry(
2490                &mut map,
2491                "modifierExtension",
2492                &self.modifier_extension,
2493            )?;
2494        }
2495        if let Some(item) = &self.r#use {
2496            serde::ser::SerializeMap::serialize_entry(&mut map, "use", item)?;
2497        }
2498        super::super::codec::value_entry(&mut map, "value", &self.value)?;
2499        serde::ser::SerializeMap::end(map)
2500    }
2501}
2502
2503impl<'de> serde::Deserialize<'de> for CodeSystemConceptDesignation {
2504    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2505        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
2506        let mut path = super::super::codec::Path::root("CodeSystemConceptDesignation");
2507        let object =
2508            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
2509        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
2510    }
2511}
2512
2513/// Property value for the concept
2514///
2515/// A property value for this concept.
2516#[derive(Debug, Clone, PartialEq, Eq)]
2517pub struct CodeSystemConceptProperty {
2518    /// Unique id for inter-element referencing
2519    ///
2520    /// Unique id for the element within a resource (for internal references). This
2521    /// may be any string value that does not contain spaces.
2522    pub id: Option<std::string::String>,
2523    /// Additional content defined by implementations
2524    ///
2525    /// May be used to represent additional information that is not part of the
2526    /// basic definition of the element. To make the use of extensions safe and
2527    /// managable, there is a strict set of governance applied to the definition and
2528    /// use of extensions. Though any implementer can define an extension, there is
2529    /// a set of requirements that SHALL be met as part of the definition of the
2530    /// extension.
2531    pub extension: Vec<super::extension::Extension>,
2532    /// Extensions that cannot be ignored even if unrecognized
2533    ///
2534    /// May be used to represent additional information that is not part of the
2535    /// basic definition of the element and that modifies the understanding of the
2536    /// element in which it is contained and/or the understanding of the containing
2537    /// element's descendants. Usually modifier elements provide negation or
2538    /// qualification. To make the use of extensions safe and managable, there is a
2539    /// strict set of governance applied to the definition and use of extensions.
2540    /// Though any implementer can define an extension, there is a set of
2541    /// requirements that SHALL be met as part of the definition of the extension.
2542    /// Applications processing a resource are required to check for modifier
2543    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
2544    /// on Resource or DomainResource (including cannot change the meaning of
2545    /// modifierExtension itself).
2546    pub modifier_extension: Vec<super::extension::Extension>,
2547    /// Reference to CodeSystem.property.code or a FHIR defined concept-property
2548    ///
2549    /// Identifies a property that is either defined in this CodeSystem
2550    /// (\`CodeSystem.property.code\`) or is a code from
2551    /// \[<http://hl7.org/fhir/concept-properties>\](codesystem.html\#defined-props).
2552    pub code: super::primitives::Code,
2553    /// Value of the property for this concept
2554    ///
2555    /// The value of this property.
2556    pub value: CodeSystemConceptPropertyValue,
2557}
2558
2559impl super::super::codec::Json for CodeSystemConceptProperty {
2560    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
2561        let mut object = super::super::codec::Object::new();
2562        if let Some(v) = &self.id {
2563            object.insert(
2564                std::string::String::from("id"),
2565                super::super::codec::Value::String(v.clone()),
2566            );
2567        }
2568        if !self.extension.is_empty() {
2569            let mut items = Vec::with_capacity(self.extension.len());
2570            for item in &self.extension {
2571                items.push(super::super::codec::Value::Object(
2572                    super::super::codec::Json::to_json(item)?,
2573                ));
2574            }
2575            object.insert(
2576                std::string::String::from("extension"),
2577                super::super::codec::Value::Array(items),
2578            );
2579        }
2580        if !self.modifier_extension.is_empty() {
2581            let mut items = Vec::with_capacity(self.modifier_extension.len());
2582            for item in &self.modifier_extension {
2583                items.push(super::super::codec::Value::Object(
2584                    super::super::codec::Json::to_json(item)?,
2585                ));
2586            }
2587            object.insert(
2588                std::string::String::from("modifierExtension"),
2589                super::super::codec::Value::Array(items),
2590            );
2591        }
2592        if let Some(v) = super::super::codec::Primitive::value_json(&self.code)? {
2593            object.insert(std::string::String::from("code"), v);
2594        }
2595        if let Some(e) = super::super::codec::Primitive::element_json(&self.code)? {
2596            object.insert(std::string::String::from("_code"), e);
2597        }
2598        let (suffix, value, element) = self.value.to_json_parts()?;
2599        if let Some(value) = value {
2600            object.insert(format!("value{suffix}"), value);
2601        }
2602        if let Some(element) = element {
2603            object.insert(format!("_value{suffix}"), element);
2604        }
2605        Ok(object)
2606    }
2607
2608    fn from_json(
2609        object: &super::super::codec::Object,
2610        path: &mut super::super::codec::Path,
2611    ) -> Result<Self, super::super::codec::DecodeError> {
2612        let mut raw_id: Option<&super::super::codec::Value> = None;
2613        let mut raw_extension: Option<&super::super::codec::Value> = None;
2614        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
2615        let mut raw_code: Option<&super::super::codec::Value> = None;
2616        let mut raw_code_element: Option<&super::super::codec::Value> = None;
2617        let mut raw_value = super::super::codec::ChoiceSlot::default();
2618        for (key, value) in object {
2619            match key.as_str() {
2620                "id" => {
2621                    raw_id = Some(value);
2622                }
2623                "extension" => {
2624                    raw_extension = Some(value);
2625                }
2626                "modifierExtension" => {
2627                    raw_modifier_extension = Some(value);
2628                }
2629                "code" => {
2630                    raw_code = Some(value);
2631                }
2632                "_code" => {
2633                    raw_code_element = Some(value);
2634                }
2635                "valueCode" => {
2636                    raw_value.value("Code", value, path)?;
2637                }
2638                "_valueCode" => {
2639                    raw_value.element("Code", value, path)?;
2640                }
2641                "valueCoding" => {
2642                    raw_value.value("Coding", value, path)?;
2643                }
2644                "_valueCoding" => {
2645                    raw_value.element("Coding", value, path)?;
2646                }
2647                "valueString" => {
2648                    raw_value.value("String", value, path)?;
2649                }
2650                "_valueString" => {
2651                    raw_value.element("String", value, path)?;
2652                }
2653                "valueInteger" => {
2654                    raw_value.value("Integer", value, path)?;
2655                }
2656                "_valueInteger" => {
2657                    raw_value.element("Integer", value, path)?;
2658                }
2659                "valueBoolean" => {
2660                    raw_value.value("Boolean", value, path)?;
2661                }
2662                "_valueBoolean" => {
2663                    raw_value.element("Boolean", value, path)?;
2664                }
2665                "valueDateTime" => {
2666                    raw_value.value("DateTime", value, path)?;
2667                }
2668                "_valueDateTime" => {
2669                    raw_value.element("DateTime", value, path)?;
2670                }
2671                "valueDecimal" => {
2672                    raw_value.value("Decimal", value, path)?;
2673                }
2674                "_valueDecimal" => {
2675                    raw_value.element("Decimal", value, path)?;
2676                }
2677                other => {
2678                    return path.with(other, |path| {
2679                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
2680                    });
2681                }
2682            }
2683        }
2684        let field_id = raw_id
2685            .map(|value| {
2686                path.with("id", |path| {
2687                    let value = super::super::codec::expect_single(value, path)?;
2688                    super::primitives::checked_string(
2689                        super::super::codec::expect_string(value, path)?,
2690                        path,
2691                    )
2692                })
2693            })
2694            .transpose()?;
2695        let mut field_extension = Vec::new();
2696        if let Some(raw) = raw_extension {
2697            for (index, value) in path
2698                .with("extension", |path| {
2699                    super::super::codec::expect_array(raw, path)
2700                })?
2701                .iter()
2702                .enumerate()
2703            {
2704                field_extension.push(path.with_index("extension", index, |path| {
2705                    super::super::codec::Json::from_json(
2706                        super::super::codec::expect_object(value, path)?,
2707                        path,
2708                    )
2709                })?);
2710            }
2711        }
2712        let mut field_modifier_extension = Vec::new();
2713        if let Some(raw) = raw_modifier_extension {
2714            for (index, value) in path
2715                .with("modifierExtension", |path| {
2716                    super::super::codec::expect_array(raw, path)
2717                })?
2718                .iter()
2719                .enumerate()
2720            {
2721                field_modifier_extension.push(path.with_index(
2722                    "modifierExtension",
2723                    index,
2724                    |path| {
2725                        super::super::codec::Json::from_json(
2726                            super::super::codec::expect_object(value, path)?,
2727                            path,
2728                        )
2729                    },
2730                )?);
2731            }
2732        }
2733        let field_code = path.with("code", |path| {
2734            super::super::codec::Primitive::from_json_parts(raw_code, raw_code_element, path)
2735        })?;
2736        let field_value = path.with("value", |path| {
2737            let suffix = raw_value
2738                .suffix
2739                .ok_or_else(|| path.error(super::super::codec::DecodeErrorKind::MissingProperty))?;
2740            CodeSystemConceptPropertyValue::from_json_parts(
2741                suffix,
2742                raw_value.value,
2743                raw_value.element,
2744                path,
2745            )
2746        })?;
2747        Ok(Self {
2748            id: field_id,
2749            extension: field_extension,
2750            modifier_extension: field_modifier_extension,
2751            code: field_code,
2752            value: field_value,
2753        })
2754    }
2755}
2756
2757impl serde::Serialize for CodeSystemConceptProperty {
2758    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
2759        let mut map = serde::Serializer::serialize_map(serializer, None)?;
2760        super::super::codec::element_entry(&mut map, "_code", &self.code)?;
2761        match &self.value {
2762            CodeSystemConceptPropertyValue::Boolean(inner) => {
2763                super::super::codec::element_entry(&mut map, "_valueBoolean", inner)?;
2764            }
2765            CodeSystemConceptPropertyValue::Code(inner) => {
2766                super::super::codec::element_entry(&mut map, "_valueCode", inner)?;
2767            }
2768            CodeSystemConceptPropertyValue::DateTime(inner) => {
2769                super::super::codec::element_entry(&mut map, "_valueDateTime", inner)?;
2770            }
2771            CodeSystemConceptPropertyValue::Decimal(inner) => {
2772                super::super::codec::element_entry(&mut map, "_valueDecimal", inner)?;
2773            }
2774            CodeSystemConceptPropertyValue::Integer(inner) => {
2775                super::super::codec::element_entry(&mut map, "_valueInteger", inner)?;
2776            }
2777            CodeSystemConceptPropertyValue::String(inner) => {
2778                super::super::codec::element_entry(&mut map, "_valueString", inner)?;
2779            }
2780            CodeSystemConceptPropertyValue::Coding(_) => {}
2781        }
2782        super::super::codec::value_entry(&mut map, "code", &self.code)?;
2783        if !self.extension.is_empty() {
2784            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
2785        }
2786        if let Some(v) = &self.id {
2787            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
2788        }
2789        if !self.modifier_extension.is_empty() {
2790            serde::ser::SerializeMap::serialize_entry(
2791                &mut map,
2792                "modifierExtension",
2793                &self.modifier_extension,
2794            )?;
2795        }
2796        match &self.value {
2797            CodeSystemConceptPropertyValue::Boolean(inner) => {
2798                super::super::codec::value_entry(&mut map, "valueBoolean", inner)?;
2799            }
2800            CodeSystemConceptPropertyValue::Code(inner) => {
2801                super::super::codec::value_entry(&mut map, "valueCode", inner)?;
2802            }
2803            CodeSystemConceptPropertyValue::Coding(inner) => {
2804                serde::ser::SerializeMap::serialize_entry(&mut map, "valueCoding", inner.as_ref())?;
2805            }
2806            CodeSystemConceptPropertyValue::DateTime(inner) => {
2807                super::super::codec::value_entry(&mut map, "valueDateTime", inner)?;
2808            }
2809            CodeSystemConceptPropertyValue::Decimal(inner) => {
2810                super::super::codec::value_entry(&mut map, "valueDecimal", inner)?;
2811            }
2812            CodeSystemConceptPropertyValue::Integer(inner) => {
2813                super::super::codec::value_entry(&mut map, "valueInteger", inner)?;
2814            }
2815            CodeSystemConceptPropertyValue::String(inner) => {
2816                super::super::codec::value_entry(&mut map, "valueString", inner)?;
2817            }
2818        }
2819        serde::ser::SerializeMap::end(map)
2820    }
2821}
2822
2823impl<'de> serde::Deserialize<'de> for CodeSystemConceptProperty {
2824    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
2825        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
2826        let mut path = super::super::codec::Path::root("CodeSystemConceptProperty");
2827        let object =
2828            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
2829        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
2830    }
2831}
2832
2833/// The \`value\[x\]\` choice of \`CodeSystemConceptProperty\`.
2834///
2835/// The value of this property.
2836#[derive(Debug, Clone, PartialEq, Eq)]
2837pub enum CodeSystemConceptPropertyValue {
2838    /// The `code` form.
2839    Code(super::primitives::Code),
2840    /// The `Coding` form.
2841    Coding(Box<super::coding::Coding>),
2842    /// The `string` form.
2843    String(super::primitives::String),
2844    /// The `integer` form.
2845    Integer(super::primitives::Integer),
2846    /// The `boolean` form.
2847    Boolean(super::primitives::Boolean),
2848    /// The `dateTime` form.
2849    DateTime(super::primitives::DateTime),
2850    /// The `decimal` form.
2851    Decimal(super::primitives::Decimal),
2852}
2853
2854impl CodeSystemConceptPropertyValue {
2855    /// The key suffix, the value part, and the `_name` part of this form.
2856    ///
2857    /// # Errors
2858    ///
2859    /// Returns [`super::super::codec::EncodeError`] when a held value has no JSON form.
2860    pub fn to_json_parts(
2861        &self,
2862    ) -> Result<
2863        (
2864            &'static str,
2865            Option<super::super::codec::Value>,
2866            Option<super::super::codec::Value>,
2867        ),
2868        super::super::codec::EncodeError,
2869    > {
2870        match self {
2871            Self::Code(inner) => Ok((
2872                "Code",
2873                super::super::codec::Primitive::value_json(inner)?,
2874                super::super::codec::Primitive::element_json(inner)?,
2875            )),
2876            Self::Coding(inner) => Ok((
2877                "Coding",
2878                Some(super::super::codec::Value::Object(
2879                    super::super::codec::Json::to_json(inner.as_ref())?,
2880                )),
2881                None,
2882            )),
2883            Self::String(inner) => Ok((
2884                "String",
2885                super::super::codec::Primitive::value_json(inner)?,
2886                super::super::codec::Primitive::element_json(inner)?,
2887            )),
2888            Self::Integer(inner) => Ok((
2889                "Integer",
2890                super::super::codec::Primitive::value_json(inner)?,
2891                super::super::codec::Primitive::element_json(inner)?,
2892            )),
2893            Self::Boolean(inner) => Ok((
2894                "Boolean",
2895                super::super::codec::Primitive::value_json(inner)?,
2896                super::super::codec::Primitive::element_json(inner)?,
2897            )),
2898            Self::DateTime(inner) => Ok((
2899                "DateTime",
2900                super::super::codec::Primitive::value_json(inner)?,
2901                super::super::codec::Primitive::element_json(inner)?,
2902            )),
2903            Self::Decimal(inner) => Ok((
2904                "Decimal",
2905                super::super::codec::Primitive::value_json(inner)?,
2906                super::super::codec::Primitive::element_json(inner)?,
2907            )),
2908        }
2909    }
2910
2911    /// Decodes the form named by `suffix` from its value and `_name` parts.
2912    ///
2913    /// # Errors
2914    ///
2915    /// Returns [`super::super::codec::DecodeError`] for an unknown suffix or a malformed part.
2916    pub fn from_json_parts(
2917        suffix: &str,
2918        value: Option<&super::super::codec::Value>,
2919        element: Option<&super::super::codec::Value>,
2920        path: &mut super::super::codec::Path,
2921    ) -> Result<Self, super::super::codec::DecodeError> {
2922        match suffix {
2923            "Code" => Ok(Self::Code(super::super::codec::Primitive::from_json_parts(
2924                value, element, path,
2925            )?)),
2926            "Coding" => {
2927                if element.is_some() {
2928                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
2929                        expected: "no underscore form for a complex type",
2930                    }));
2931                }
2932                let value = value.ok_or_else(|| {
2933                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
2934                })?;
2935                let inner = super::super::codec::Json::from_json(
2936                    super::super::codec::expect_object(
2937                        super::super::codec::expect_single(value, path)?,
2938                        path,
2939                    )?,
2940                    path,
2941                )?;
2942                Ok(Self::Coding(Box::new(inner)))
2943            }
2944            "String" => Ok(Self::String(
2945                super::super::codec::Primitive::from_json_parts(value, element, path)?,
2946            )),
2947            "Integer" => Ok(Self::Integer(
2948                super::super::codec::Primitive::from_json_parts(value, element, path)?,
2949            )),
2950            "Boolean" => Ok(Self::Boolean(
2951                super::super::codec::Primitive::from_json_parts(value, element, path)?,
2952            )),
2953            "DateTime" => Ok(Self::DateTime(
2954                super::super::codec::Primitive::from_json_parts(value, element, path)?,
2955            )),
2956            "Decimal" => Ok(Self::Decimal(
2957                super::super::codec::Primitive::from_json_parts(value, element, path)?,
2958            )),
2959            _ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
2960        }
2961    }
2962}
2963
2964/// Filter that can be used in a value set
2965///
2966/// A filter that can be used in a value set compose statement when selecting
2967/// concepts using a filter.
2968#[derive(Debug, Clone, Default, PartialEq, Eq)]
2969pub struct CodeSystemFilter {
2970    /// Unique id for inter-element referencing
2971    ///
2972    /// Unique id for the element within a resource (for internal references). This
2973    /// may be any string value that does not contain spaces.
2974    pub id: Option<std::string::String>,
2975    /// Additional content defined by implementations
2976    ///
2977    /// May be used to represent additional information that is not part of the
2978    /// basic definition of the element. To make the use of extensions safe and
2979    /// managable, there is a strict set of governance applied to the definition and
2980    /// use of extensions. Though any implementer can define an extension, there is
2981    /// a set of requirements that SHALL be met as part of the definition of the
2982    /// extension.
2983    pub extension: Vec<super::extension::Extension>,
2984    /// Extensions that cannot be ignored even if unrecognized
2985    ///
2986    /// May be used to represent additional information that is not part of the
2987    /// basic definition of the element and that modifies the understanding of the
2988    /// element in which it is contained and/or the understanding of the containing
2989    /// element's descendants. Usually modifier elements provide negation or
2990    /// qualification. To make the use of extensions safe and managable, there is a
2991    /// strict set of governance applied to the definition and use of extensions.
2992    /// Though any implementer can define an extension, there is a set of
2993    /// requirements that SHALL be met as part of the definition of the extension.
2994    /// Applications processing a resource are required to check for modifier
2995    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
2996    /// on Resource or DomainResource (including cannot change the meaning of
2997    /// modifierExtension itself).
2998    pub modifier_extension: Vec<super::extension::Extension>,
2999    /// Code that identifies the filter
3000    ///
3001    /// The code that identifies this filter when it is used as a filter in
3002    /// \[ValueSet\](valueset.html\#).compose.include.filter.
3003    pub code: super::primitives::Code,
3004    /// How or why the filter is used
3005    ///
3006    /// A description of how or why the filter is used.
3007    pub description: Option<super::primitives::String>,
3008    /// = | is-a | descendent-of | is-not-a | regex | in | not-in | generalizes |
3009    /// child-of | descendent-leaf | exists | property-value-of
3010    ///
3011    /// A list of operators that can be used with the filter.
3012    pub operator: Vec<super::primitives::Code>,
3013    /// Code from the system, or regex criteria, or boolean value for exists
3014    ///
3015    /// CodeSystem.filter.value is represented as a string, and the string value
3016    /// must be as described in \[Using Filter
3017    /// Values\](valueset.html\#filter-values).
3018    pub value: super::primitives::String,
3019}
3020
3021impl super::super::codec::Json for CodeSystemFilter {
3022    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
3023        let mut object = super::super::codec::Object::new();
3024        if let Some(v) = &self.id {
3025            object.insert(
3026                std::string::String::from("id"),
3027                super::super::codec::Value::String(v.clone()),
3028            );
3029        }
3030        if !self.extension.is_empty() {
3031            let mut items = Vec::with_capacity(self.extension.len());
3032            for item in &self.extension {
3033                items.push(super::super::codec::Value::Object(
3034                    super::super::codec::Json::to_json(item)?,
3035                ));
3036            }
3037            object.insert(
3038                std::string::String::from("extension"),
3039                super::super::codec::Value::Array(items),
3040            );
3041        }
3042        if !self.modifier_extension.is_empty() {
3043            let mut items = Vec::with_capacity(self.modifier_extension.len());
3044            for item in &self.modifier_extension {
3045                items.push(super::super::codec::Value::Object(
3046                    super::super::codec::Json::to_json(item)?,
3047                ));
3048            }
3049            object.insert(
3050                std::string::String::from("modifierExtension"),
3051                super::super::codec::Value::Array(items),
3052            );
3053        }
3054        if let Some(v) = super::super::codec::Primitive::value_json(&self.code)? {
3055            object.insert(std::string::String::from("code"), v);
3056        }
3057        if let Some(e) = super::super::codec::Primitive::element_json(&self.code)? {
3058            object.insert(std::string::String::from("_code"), e);
3059        }
3060        if let Some(item) = &self.description {
3061            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
3062                object.insert(std::string::String::from("description"), v);
3063            }
3064            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
3065                object.insert(std::string::String::from("_description"), e);
3066            }
3067        }
3068        if !self.operator.is_empty() {
3069            let (values, elements) = super::super::codec::primitive_arrays(&self.operator)?;
3070            if let Some(values) = values {
3071                object.insert(std::string::String::from("operator"), values);
3072            }
3073            if let Some(elements) = elements {
3074                object.insert(std::string::String::from("_operator"), elements);
3075            }
3076        }
3077        if let Some(v) = super::super::codec::Primitive::value_json(&self.value)? {
3078            object.insert(std::string::String::from("value"), v);
3079        }
3080        if let Some(e) = super::super::codec::Primitive::element_json(&self.value)? {
3081            object.insert(std::string::String::from("_value"), e);
3082        }
3083        Ok(object)
3084    }
3085
3086    fn from_json(
3087        object: &super::super::codec::Object,
3088        path: &mut super::super::codec::Path,
3089    ) -> Result<Self, super::super::codec::DecodeError> {
3090        let mut raw_id: Option<&super::super::codec::Value> = None;
3091        let mut raw_extension: Option<&super::super::codec::Value> = None;
3092        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
3093        let mut raw_code: Option<&super::super::codec::Value> = None;
3094        let mut raw_code_element: Option<&super::super::codec::Value> = None;
3095        let mut raw_description: Option<&super::super::codec::Value> = None;
3096        let mut raw_description_element: Option<&super::super::codec::Value> = None;
3097        let mut raw_operator: Option<&super::super::codec::Value> = None;
3098        let mut raw_operator_element: Option<&super::super::codec::Value> = None;
3099        let mut raw_value: Option<&super::super::codec::Value> = None;
3100        let mut raw_value_element: Option<&super::super::codec::Value> = None;
3101        for (key, value) in object {
3102            match key.as_str() {
3103                "id" => {
3104                    raw_id = Some(value);
3105                }
3106                "extension" => {
3107                    raw_extension = Some(value);
3108                }
3109                "modifierExtension" => {
3110                    raw_modifier_extension = Some(value);
3111                }
3112                "code" => {
3113                    raw_code = Some(value);
3114                }
3115                "_code" => {
3116                    raw_code_element = Some(value);
3117                }
3118                "description" => {
3119                    raw_description = Some(value);
3120                }
3121                "_description" => {
3122                    raw_description_element = Some(value);
3123                }
3124                "operator" => {
3125                    raw_operator = Some(value);
3126                }
3127                "_operator" => {
3128                    raw_operator_element = Some(value);
3129                }
3130                "value" => {
3131                    raw_value = Some(value);
3132                }
3133                "_value" => {
3134                    raw_value_element = Some(value);
3135                }
3136                other => {
3137                    return path.with(other, |path| {
3138                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
3139                    });
3140                }
3141            }
3142        }
3143        let field_id = raw_id
3144            .map(|value| {
3145                path.with("id", |path| {
3146                    let value = super::super::codec::expect_single(value, path)?;
3147                    super::primitives::checked_string(
3148                        super::super::codec::expect_string(value, path)?,
3149                        path,
3150                    )
3151                })
3152            })
3153            .transpose()?;
3154        let mut field_extension = Vec::new();
3155        if let Some(raw) = raw_extension {
3156            for (index, value) in path
3157                .with("extension", |path| {
3158                    super::super::codec::expect_array(raw, path)
3159                })?
3160                .iter()
3161                .enumerate()
3162            {
3163                field_extension.push(path.with_index("extension", index, |path| {
3164                    super::super::codec::Json::from_json(
3165                        super::super::codec::expect_object(value, path)?,
3166                        path,
3167                    )
3168                })?);
3169            }
3170        }
3171        let mut field_modifier_extension = Vec::new();
3172        if let Some(raw) = raw_modifier_extension {
3173            for (index, value) in path
3174                .with("modifierExtension", |path| {
3175                    super::super::codec::expect_array(raw, path)
3176                })?
3177                .iter()
3178                .enumerate()
3179            {
3180                field_modifier_extension.push(path.with_index(
3181                    "modifierExtension",
3182                    index,
3183                    |path| {
3184                        super::super::codec::Json::from_json(
3185                            super::super::codec::expect_object(value, path)?,
3186                            path,
3187                        )
3188                    },
3189                )?);
3190            }
3191        }
3192        let field_code = path.with("code", |path| {
3193            super::super::codec::Primitive::from_json_parts(raw_code, raw_code_element, path)
3194        })?;
3195        let field_description = match (raw_description, raw_description_element) {
3196            (None, None) => None,
3197            (value, element) => Some(path.with("description", |path| {
3198                super::super::codec::Primitive::from_json_parts(value, element, path)
3199            })?),
3200        };
3201        let mut field_operator = Vec::new();
3202        for (index, (value, element)) in path
3203            .with("operator", |path| {
3204                super::super::codec::pair_arrays(raw_operator, raw_operator_element, path)
3205            })?
3206            .into_iter()
3207            .enumerate()
3208        {
3209            field_operator.push(path.with_index("operator", index, |path| {
3210                super::super::codec::Primitive::from_json_parts(value, element, path)
3211            })?);
3212        }
3213        if field_operator.is_empty() && !path.is_lenient() {
3214            return path.with("operator", |path| {
3215                Err(path.error(super::super::codec::DecodeErrorKind::MissingProperty))
3216            });
3217        }
3218        let field_value = path.with("value", |path| {
3219            super::super::codec::Primitive::from_json_parts(raw_value, raw_value_element, path)
3220        })?;
3221        Ok(Self {
3222            id: field_id,
3223            extension: field_extension,
3224            modifier_extension: field_modifier_extension,
3225            code: field_code,
3226            description: field_description,
3227            operator: field_operator,
3228            value: field_value,
3229        })
3230    }
3231}
3232
3233impl serde::Serialize for CodeSystemFilter {
3234    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
3235        let mut map = serde::Serializer::serialize_map(serializer, None)?;
3236        super::super::codec::element_entry(&mut map, "_code", &self.code)?;
3237        if let Some(item) = &self.description {
3238            super::super::codec::element_entry(&mut map, "_description", item)?;
3239        }
3240        super::super::codec::element_list_entry(&mut map, "_operator", &self.operator)?;
3241        super::super::codec::element_entry(&mut map, "_value", &self.value)?;
3242        super::super::codec::value_entry(&mut map, "code", &self.code)?;
3243        if let Some(item) = &self.description {
3244            super::super::codec::value_entry(&mut map, "description", item)?;
3245        }
3246        if !self.extension.is_empty() {
3247            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
3248        }
3249        if let Some(v) = &self.id {
3250            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
3251        }
3252        if !self.modifier_extension.is_empty() {
3253            serde::ser::SerializeMap::serialize_entry(
3254                &mut map,
3255                "modifierExtension",
3256                &self.modifier_extension,
3257            )?;
3258        }
3259        super::super::codec::value_list_entry(&mut map, "operator", &self.operator)?;
3260        super::super::codec::value_entry(&mut map, "value", &self.value)?;
3261        serde::ser::SerializeMap::end(map)
3262    }
3263}
3264
3265impl<'de> serde::Deserialize<'de> for CodeSystemFilter {
3266    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
3267        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
3268        let mut path = super::super::codec::Path::root("CodeSystemFilter");
3269        let object =
3270            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
3271        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
3272    }
3273}
3274
3275/// Additional information supplied about each concept
3276///
3277/// A property defines an additional slot through which additional information
3278/// can be provided about a concept.
3279#[derive(Debug, Clone, Default, PartialEq, Eq)]
3280pub struct CodeSystemProperty {
3281    /// Unique id for inter-element referencing
3282    ///
3283    /// Unique id for the element within a resource (for internal references). This
3284    /// may be any string value that does not contain spaces.
3285    pub id: Option<std::string::String>,
3286    /// Additional content defined by implementations
3287    ///
3288    /// May be used to represent additional information that is not part of the
3289    /// basic definition of the element. To make the use of extensions safe and
3290    /// managable, there is a strict set of governance applied to the definition and
3291    /// use of extensions. Though any implementer can define an extension, there is
3292    /// a set of requirements that SHALL be met as part of the definition of the
3293    /// extension.
3294    pub extension: Vec<super::extension::Extension>,
3295    /// Extensions that cannot be ignored even if unrecognized
3296    ///
3297    /// May be used to represent additional information that is not part of the
3298    /// basic definition of the element and that modifies the understanding of the
3299    /// element in which it is contained and/or the understanding of the containing
3300    /// element's descendants. Usually modifier elements provide negation or
3301    /// qualification. To make the use of extensions safe and managable, there is a
3302    /// strict set of governance applied to the definition and use of extensions.
3303    /// Though any implementer can define an extension, there is a set of
3304    /// requirements that SHALL be met as part of the definition of the extension.
3305    /// Applications processing a resource are required to check for modifier
3306    /// extensions. Modifier extensions SHALL NOT change the meaning of any elements
3307    /// on Resource or DomainResource (including cannot change the meaning of
3308    /// modifierExtension itself).
3309    pub modifier_extension: Vec<super::extension::Extension>,
3310    /// Identifies the property on the concepts, and when referred to in operations
3311    ///
3312    /// A code that is used to identify the property. The code is used internally
3313    /// (in CodeSystem.concept.property.code) and also externally, such as in
3314    /// property filters.
3315    pub code: super::primitives::Code,
3316    /// Formal identifier for the property
3317    ///
3318    /// Reference to the formal meaning of the property. One possible source of
3319    /// meaning is the \[Concept Properties\](codesystem-concept-properties.html)
3320    /// code system.
3321    pub uri: Option<super::primitives::Uri>,
3322    /// Why the property is defined, and/or what it conveys
3323    ///
3324    /// A description of the property- why it is defined, and how its value might be
3325    /// used.
3326    pub description: Option<super::primitives::String>,
3327    /// code | Coding | string | integer | boolean | dateTime | decimal
3328    ///
3329    /// The type of the property value. Properties of type "code" contain a code
3330    /// defined by the code system or another code system.
3331    pub r#type: super::primitives::Code,
3332}
3333
3334impl super::super::codec::Json for CodeSystemProperty {
3335    fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
3336        let mut object = super::super::codec::Object::new();
3337        if let Some(v) = &self.id {
3338            object.insert(
3339                std::string::String::from("id"),
3340                super::super::codec::Value::String(v.clone()),
3341            );
3342        }
3343        if !self.extension.is_empty() {
3344            let mut items = Vec::with_capacity(self.extension.len());
3345            for item in &self.extension {
3346                items.push(super::super::codec::Value::Object(
3347                    super::super::codec::Json::to_json(item)?,
3348                ));
3349            }
3350            object.insert(
3351                std::string::String::from("extension"),
3352                super::super::codec::Value::Array(items),
3353            );
3354        }
3355        if !self.modifier_extension.is_empty() {
3356            let mut items = Vec::with_capacity(self.modifier_extension.len());
3357            for item in &self.modifier_extension {
3358                items.push(super::super::codec::Value::Object(
3359                    super::super::codec::Json::to_json(item)?,
3360                ));
3361            }
3362            object.insert(
3363                std::string::String::from("modifierExtension"),
3364                super::super::codec::Value::Array(items),
3365            );
3366        }
3367        if let Some(v) = super::super::codec::Primitive::value_json(&self.code)? {
3368            object.insert(std::string::String::from("code"), v);
3369        }
3370        if let Some(e) = super::super::codec::Primitive::element_json(&self.code)? {
3371            object.insert(std::string::String::from("_code"), e);
3372        }
3373        if let Some(item) = &self.uri {
3374            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
3375                object.insert(std::string::String::from("uri"), v);
3376            }
3377            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
3378                object.insert(std::string::String::from("_uri"), e);
3379            }
3380        }
3381        if let Some(item) = &self.description {
3382            if let Some(v) = super::super::codec::Primitive::value_json(item)? {
3383                object.insert(std::string::String::from("description"), v);
3384            }
3385            if let Some(e) = super::super::codec::Primitive::element_json(item)? {
3386                object.insert(std::string::String::from("_description"), e);
3387            }
3388        }
3389        if let Some(v) = super::super::codec::Primitive::value_json(&self.r#type)? {
3390            object.insert(std::string::String::from("type"), v);
3391        }
3392        if let Some(e) = super::super::codec::Primitive::element_json(&self.r#type)? {
3393            object.insert(std::string::String::from("_type"), e);
3394        }
3395        Ok(object)
3396    }
3397
3398    fn from_json(
3399        object: &super::super::codec::Object,
3400        path: &mut super::super::codec::Path,
3401    ) -> Result<Self, super::super::codec::DecodeError> {
3402        let mut raw_id: Option<&super::super::codec::Value> = None;
3403        let mut raw_extension: Option<&super::super::codec::Value> = None;
3404        let mut raw_modifier_extension: Option<&super::super::codec::Value> = None;
3405        let mut raw_code: Option<&super::super::codec::Value> = None;
3406        let mut raw_code_element: Option<&super::super::codec::Value> = None;
3407        let mut raw_uri: Option<&super::super::codec::Value> = None;
3408        let mut raw_uri_element: Option<&super::super::codec::Value> = None;
3409        let mut raw_description: Option<&super::super::codec::Value> = None;
3410        let mut raw_description_element: Option<&super::super::codec::Value> = None;
3411        let mut raw_type: Option<&super::super::codec::Value> = None;
3412        let mut raw_type_element: Option<&super::super::codec::Value> = None;
3413        for (key, value) in object {
3414            match key.as_str() {
3415                "id" => {
3416                    raw_id = Some(value);
3417                }
3418                "extension" => {
3419                    raw_extension = Some(value);
3420                }
3421                "modifierExtension" => {
3422                    raw_modifier_extension = Some(value);
3423                }
3424                "code" => {
3425                    raw_code = Some(value);
3426                }
3427                "_code" => {
3428                    raw_code_element = Some(value);
3429                }
3430                "uri" => {
3431                    raw_uri = Some(value);
3432                }
3433                "_uri" => {
3434                    raw_uri_element = Some(value);
3435                }
3436                "description" => {
3437                    raw_description = Some(value);
3438                }
3439                "_description" => {
3440                    raw_description_element = Some(value);
3441                }
3442                "type" => {
3443                    raw_type = Some(value);
3444                }
3445                "_type" => {
3446                    raw_type_element = Some(value);
3447                }
3448                other => {
3449                    return path.with(other, |path| {
3450                        Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
3451                    });
3452                }
3453            }
3454        }
3455        let field_id = raw_id
3456            .map(|value| {
3457                path.with("id", |path| {
3458                    let value = super::super::codec::expect_single(value, path)?;
3459                    super::primitives::checked_string(
3460                        super::super::codec::expect_string(value, path)?,
3461                        path,
3462                    )
3463                })
3464            })
3465            .transpose()?;
3466        let mut field_extension = Vec::new();
3467        if let Some(raw) = raw_extension {
3468            for (index, value) in path
3469                .with("extension", |path| {
3470                    super::super::codec::expect_array(raw, path)
3471                })?
3472                .iter()
3473                .enumerate()
3474            {
3475                field_extension.push(path.with_index("extension", index, |path| {
3476                    super::super::codec::Json::from_json(
3477                        super::super::codec::expect_object(value, path)?,
3478                        path,
3479                    )
3480                })?);
3481            }
3482        }
3483        let mut field_modifier_extension = Vec::new();
3484        if let Some(raw) = raw_modifier_extension {
3485            for (index, value) in path
3486                .with("modifierExtension", |path| {
3487                    super::super::codec::expect_array(raw, path)
3488                })?
3489                .iter()
3490                .enumerate()
3491            {
3492                field_modifier_extension.push(path.with_index(
3493                    "modifierExtension",
3494                    index,
3495                    |path| {
3496                        super::super::codec::Json::from_json(
3497                            super::super::codec::expect_object(value, path)?,
3498                            path,
3499                        )
3500                    },
3501                )?);
3502            }
3503        }
3504        let field_code = path.with("code", |path| {
3505            super::super::codec::Primitive::from_json_parts(raw_code, raw_code_element, path)
3506        })?;
3507        let field_uri = match (raw_uri, raw_uri_element) {
3508            (None, None) => None,
3509            (value, element) => Some(path.with("uri", |path| {
3510                super::super::codec::Primitive::from_json_parts(value, element, path)
3511            })?),
3512        };
3513        let field_description = match (raw_description, raw_description_element) {
3514            (None, None) => None,
3515            (value, element) => Some(path.with("description", |path| {
3516                super::super::codec::Primitive::from_json_parts(value, element, path)
3517            })?),
3518        };
3519        let field_type = path.with("type", |path| {
3520            super::super::codec::Primitive::from_json_parts(raw_type, raw_type_element, path)
3521        })?;
3522        Ok(Self {
3523            id: field_id,
3524            extension: field_extension,
3525            modifier_extension: field_modifier_extension,
3526            code: field_code,
3527            uri: field_uri,
3528            description: field_description,
3529            r#type: field_type,
3530        })
3531    }
3532}
3533
3534impl serde::Serialize for CodeSystemProperty {
3535    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
3536        let mut map = serde::Serializer::serialize_map(serializer, None)?;
3537        super::super::codec::element_entry(&mut map, "_code", &self.code)?;
3538        if let Some(item) = &self.description {
3539            super::super::codec::element_entry(&mut map, "_description", item)?;
3540        }
3541        super::super::codec::element_entry(&mut map, "_type", &self.r#type)?;
3542        if let Some(item) = &self.uri {
3543            super::super::codec::element_entry(&mut map, "_uri", item)?;
3544        }
3545        super::super::codec::value_entry(&mut map, "code", &self.code)?;
3546        if let Some(item) = &self.description {
3547            super::super::codec::value_entry(&mut map, "description", item)?;
3548        }
3549        if !self.extension.is_empty() {
3550            serde::ser::SerializeMap::serialize_entry(&mut map, "extension", &self.extension)?;
3551        }
3552        if let Some(v) = &self.id {
3553            serde::ser::SerializeMap::serialize_entry(&mut map, "id", v)?;
3554        }
3555        if !self.modifier_extension.is_empty() {
3556            serde::ser::SerializeMap::serialize_entry(
3557                &mut map,
3558                "modifierExtension",
3559                &self.modifier_extension,
3560            )?;
3561        }
3562        super::super::codec::value_entry(&mut map, "type", &self.r#type)?;
3563        if let Some(item) = &self.uri {
3564            super::super::codec::value_entry(&mut map, "uri", item)?;
3565        }
3566        serde::ser::SerializeMap::end(map)
3567    }
3568}
3569
3570impl<'de> serde::Deserialize<'de> for CodeSystemProperty {
3571    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
3572        let value = <super::super::codec::Value as serde::Deserialize>::deserialize(deserializer)?;
3573        let mut path = super::super::codec::Path::root("CodeSystemProperty");
3574        let object =
3575            super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
3576        super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
3577    }
3578}
3579
3580/// The \`versionAlgorithm\[x\]\` choice of \`CodeSystem\`.
3581///
3582/// Indicates the mechanism used to compare versions to determine which
3583/// CodeSystem is more current.
3584#[derive(Debug, Clone, PartialEq, Eq)]
3585pub enum CodeSystemVersionAlgorithm {
3586    /// The `string` form.
3587    String(super::primitives::String),
3588    /// The `Coding` form.
3589    Coding(Box<super::coding::Coding>),
3590}
3591
3592impl CodeSystemVersionAlgorithm {
3593    /// The key suffix, the value part, and the `_name` part of this form.
3594    ///
3595    /// # Errors
3596    ///
3597    /// Returns [`super::super::codec::EncodeError`] when a held value has no JSON form.
3598    pub fn to_json_parts(
3599        &self,
3600    ) -> Result<
3601        (
3602            &'static str,
3603            Option<super::super::codec::Value>,
3604            Option<super::super::codec::Value>,
3605        ),
3606        super::super::codec::EncodeError,
3607    > {
3608        match self {
3609            Self::String(inner) => Ok((
3610                "String",
3611                super::super::codec::Primitive::value_json(inner)?,
3612                super::super::codec::Primitive::element_json(inner)?,
3613            )),
3614            Self::Coding(inner) => Ok((
3615                "Coding",
3616                Some(super::super::codec::Value::Object(
3617                    super::super::codec::Json::to_json(inner.as_ref())?,
3618                )),
3619                None,
3620            )),
3621        }
3622    }
3623
3624    /// Decodes the form named by `suffix` from its value and `_name` parts.
3625    ///
3626    /// # Errors
3627    ///
3628    /// Returns [`super::super::codec::DecodeError`] for an unknown suffix or a malformed part.
3629    pub fn from_json_parts(
3630        suffix: &str,
3631        value: Option<&super::super::codec::Value>,
3632        element: Option<&super::super::codec::Value>,
3633        path: &mut super::super::codec::Path,
3634    ) -> Result<Self, super::super::codec::DecodeError> {
3635        match suffix {
3636            "String" => Ok(Self::String(
3637                super::super::codec::Primitive::from_json_parts(value, element, path)?,
3638            )),
3639            "Coding" => {
3640                if element.is_some() {
3641                    return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
3642                        expected: "no underscore form for a complex type",
3643                    }));
3644                }
3645                let value = value.ok_or_else(|| {
3646                    path.error(super::super::codec::DecodeErrorKind::MissingProperty)
3647                })?;
3648                let inner = super::super::codec::Json::from_json(
3649                    super::super::codec::expect_object(
3650                        super::super::codec::expect_single(value, path)?,
3651                        path,
3652                    )?,
3653                    path,
3654                )?;
3655                Ok(Self::Coding(Box::new(inner)))
3656            }
3657            _ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
3658        }
3659    }
3660}