/// <summary>
        /// Deserialize JSON into a FHIR ObservationDefinition#QualifiedInterval
        /// </summary>
        public static void DeserializeJson(this ObservationDefinition.QualifiedIntervalComponent 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($"ObservationDefinition.QualifiedIntervalComponent >>> ObservationDefinition#QualifiedInterval.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"ObservationDefinition.QualifiedIntervalComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
        /// <summary>
        /// Deserialize JSON into a FHIR ObservationDefinition#QualifiedInterval
        /// </summary>
        public static void DeserializeJsonProperty(this ObservationDefinition.QualifiedIntervalComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "category":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.CategoryElement = new Code <Hl7.Fhir.Model.ObservationDefinition.ObservationRangeCategory>();
                    reader.Skip();
                }
                else
                {
                    current.CategoryElement = new Code <Hl7.Fhir.Model.ObservationDefinition.ObservationRangeCategory>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.ObservationDefinition.ObservationRangeCategory>(reader.GetString()));
                }
                break;

            case "_category":
                if (current.CategoryElement == null)
                {
                    current.CategoryElement = new Code <Hl7.Fhir.Model.ObservationDefinition.ObservationRangeCategory>();
                }
                ((Hl7.Fhir.Model.Element)current.CategoryElement).DeserializeJson(ref reader, options);
                break;

            case "range":
                current.Range = new Hl7.Fhir.Model.Range();
                ((Hl7.Fhir.Model.Range)current.Range).DeserializeJson(ref reader, options);
                break;

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

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

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

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

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

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

            case "gender":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.GenderElement = new Code <Hl7.Fhir.Model.AdministrativeGender>();
                    reader.Skip();
                }
                else
                {
                    current.GenderElement = new Code <Hl7.Fhir.Model.AdministrativeGender>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.AdministrativeGender>(reader.GetString()));
                }
                break;

            case "_gender":
                if (current.GenderElement == null)
                {
                    current.GenderElement = new Code <Hl7.Fhir.Model.AdministrativeGender>();
                }
                ((Hl7.Fhir.Model.Element)current.GenderElement).DeserializeJson(ref reader, options);
                break;

            case "age":
                current.Age = new Hl7.Fhir.Model.Range();
                ((Hl7.Fhir.Model.Range)current.Age).DeserializeJson(ref reader, options);
                break;

            case "gestationalAge":
                current.GestationalAge = new Hl7.Fhir.Model.Range();
                ((Hl7.Fhir.Model.Range)current.GestationalAge).DeserializeJson(ref reader, options);
                break;

            case "condition":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.ConditionElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.ConditionElement = new FhirString(reader.GetString());
                }
                break;

            case "_condition":
                if (current.ConditionElement == null)
                {
                    current.ConditionElement = new FhirString();
                }
                ((Hl7.Fhir.Model.Element)current.ConditionElement).DeserializeJson(ref reader, options);
                break;

            // Complex: qualifiedInterval, Export: QualifiedIntervalComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
        /// <summary>
        /// Serialize a FHIR ObservationDefinition#QualifiedInterval into JSON
        /// </summary>
        public static void SerializeJson(this ObservationDefinition.QualifiedIntervalComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: ObservationDefinition#QualifiedInterval, Export: QualifiedIntervalComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            if (current.CategoryElement != null)
            {
                if (current.CategoryElement.Value != null)
                {
                    writer.WriteString("category", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.CategoryElement.Value));
                }
                if (current.CategoryElement.HasExtensions() || (!string.IsNullOrEmpty(current.CategoryElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_category", false, current.CategoryElement.Extension, current.CategoryElement.ElementId);
                }
            }

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

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

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

            if (current.GenderElement != null)
            {
                if (current.GenderElement.Value != null)
                {
                    writer.WriteString("gender", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.GenderElement.Value));
                }
                if (current.GenderElement.HasExtensions() || (!string.IsNullOrEmpty(current.GenderElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_gender", false, current.GenderElement.Extension, current.GenderElement.ElementId);
                }
            }

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

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

            if (current.ConditionElement != null)
            {
                if (!string.IsNullOrEmpty(current.ConditionElement.Value))
                {
                    writer.WriteString("condition", current.ConditionElement.Value);
                }
                if (current.ConditionElement.HasExtensions() || (!string.IsNullOrEmpty(current.ConditionElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_condition", false, current.ConditionElement.Extension, current.ConditionElement.ElementId);
                }
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }