/// <summary>
        /// Deserialize JSON into a FHIR MedicinalProductContraindication
        /// </summary>
        public static void DeserializeJson(this MedicinalProductContraindication current, ref Utf8JsonReader reader, JsonSerializerOptions options)
        {
            string propertyName;

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return;
                }

                if (reader.TokenType == JsonTokenType.PropertyName)
                {
                    propertyName = reader.GetString();
                    if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug)
                    {
                        Console.WriteLine($"MedicinalProductContraindication >>> MedicinalProductContraindication.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"MedicinalProductContraindication: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
        /// <summary>
        /// Serialize a FHIR MedicinalProductContraindication into JSON
        /// </summary>
        public static void SerializeJson(this MedicinalProductContraindication current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            writer.WriteString("resourceType", "MedicinalProductContraindication");
            // Complex: MedicinalProductContraindication, Export: MedicinalProductContraindication, Base: DomainResource (DomainResource)
            ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false);

            if ((current.Subject != null) && (current.Subject.Count != 0))
            {
                writer.WritePropertyName("subject");
                writer.WriteStartArray();
                foreach (ResourceReference val in current.Subject)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (current.Disease != null)
            {
                writer.WritePropertyName("disease");
                current.Disease.SerializeJson(writer, options);
            }

            if (current.DiseaseStatus != null)
            {
                writer.WritePropertyName("diseaseStatus");
                current.DiseaseStatus.SerializeJson(writer, options);
            }

            if ((current.Comorbidity != null) && (current.Comorbidity.Count != 0))
            {
                writer.WritePropertyName("comorbidity");
                writer.WriteStartArray();
                foreach (CodeableConcept val in current.Comorbidity)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if ((current.TherapeuticIndication != null) && (current.TherapeuticIndication.Count != 0))
            {
                writer.WritePropertyName("therapeuticIndication");
                writer.WriteStartArray();
                foreach (ResourceReference val in current.TherapeuticIndication)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if ((current.OtherTherapy != null) && (current.OtherTherapy.Count != 0))
            {
                writer.WritePropertyName("otherTherapy");
                writer.WriteStartArray();
                foreach (MedicinalProductContraindication.OtherTherapyComponent val in current.OtherTherapy)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if ((current.Population != null) && (current.Population.Count != 0))
            {
                writer.WritePropertyName("population");
                writer.WriteStartArray();
                foreach (Population val in current.Population)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
        /// <summary>
        /// Deserialize JSON into a FHIR MedicinalProductContraindication
        /// </summary>
        public static void DeserializeJsonProperty(this MedicinalProductContraindication current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "subject":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductContraindication error reading 'subject' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Subject = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_Subject = new Hl7.Fhir.Model.ResourceReference();
                    v_Subject.DeserializeJson(ref reader, options);
                    current.Subject.Add(v_Subject);

                    if (!reader.Read())
                    {
                        throw new JsonException($"MedicinalProductContraindication error reading 'subject' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Subject.Count == 0)
                {
                    current.Subject = null;
                }
                break;

            case "disease":
                current.Disease = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Disease).DeserializeJson(ref reader, options);
                break;

            case "diseaseStatus":
                current.DiseaseStatus = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.DiseaseStatus).DeserializeJson(ref reader, options);
                break;

            case "comorbidity":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductContraindication error reading 'comorbidity' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Comorbidity = new List <CodeableConcept>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.CodeableConcept v_Comorbidity = new Hl7.Fhir.Model.CodeableConcept();
                    v_Comorbidity.DeserializeJson(ref reader, options);
                    current.Comorbidity.Add(v_Comorbidity);

                    if (!reader.Read())
                    {
                        throw new JsonException($"MedicinalProductContraindication error reading 'comorbidity' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Comorbidity.Count == 0)
                {
                    current.Comorbidity = null;
                }
                break;

            case "therapeuticIndication":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductContraindication error reading 'therapeuticIndication' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.TherapeuticIndication = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_TherapeuticIndication = new Hl7.Fhir.Model.ResourceReference();
                    v_TherapeuticIndication.DeserializeJson(ref reader, options);
                    current.TherapeuticIndication.Add(v_TherapeuticIndication);

                    if (!reader.Read())
                    {
                        throw new JsonException($"MedicinalProductContraindication error reading 'therapeuticIndication' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.TherapeuticIndication.Count == 0)
                {
                    current.TherapeuticIndication = null;
                }
                break;

            case "otherTherapy":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductContraindication error reading 'otherTherapy' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.OtherTherapy = new List <MedicinalProductContraindication.OtherTherapyComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MedicinalProductContraindication.OtherTherapyComponent v_OtherTherapy = new Hl7.Fhir.Model.MedicinalProductContraindication.OtherTherapyComponent();
                    v_OtherTherapy.DeserializeJson(ref reader, options);
                    current.OtherTherapy.Add(v_OtherTherapy);

                    if (!reader.Read())
                    {
                        throw new JsonException($"MedicinalProductContraindication error reading 'otherTherapy' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.OtherTherapy.Count == 0)
                {
                    current.OtherTherapy = null;
                }
                break;

            case "population":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductContraindication error reading 'population' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Population = new List <Population>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Population v_Population = new Hl7.Fhir.Model.Population();
                    v_Population.DeserializeJson(ref reader, options);
                    current.Population.Add(v_Population);

                    if (!reader.Read())
                    {
                        throw new JsonException($"MedicinalProductContraindication error reading 'population' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Population.Count == 0)
                {
                    current.Population = null;
                }
                break;

            // Complex: MedicinalProductContraindication, Export: MedicinalProductContraindication, Base: DomainResource
            default:
                ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }