Ejemplo n.º 1
0
        /// <summary>
        /// Deserialize JSON into a FHIR Dosage#DoseAndRate
        /// </summary>
        public static void DeserializeJson(this Dosage.DoseAndRateComponent 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($"Dosage.DoseAndRateComponent >>> Dosage#DoseAndRate.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"Dosage.DoseAndRateComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Serialize a FHIR Dosage#DoseAndRate into JSON
        /// </summary>
        public static void SerializeJson(this Dosage.DoseAndRateComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: Dosage#DoseAndRate, Export: DoseAndRateComponent, Base: Element (Element)
            ((Hl7.Fhir.Model.Element)current).SerializeJson(writer, options, false);

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

            if (current.Dose != null)
            {
                switch (current.Dose)
                {
                case Range v_Range:
                    writer.WritePropertyName("doseRange");
                    v_Range.SerializeJson(writer, options);
                    break;

                case Quantity v_Quantity:
                    writer.WritePropertyName("doseQuantity");
                    v_Quantity.SerializeJson(writer, options);
                    break;
                }
            }
            if (current.Rate != null)
            {
                switch (current.Rate)
                {
                case Ratio v_Ratio:
                    writer.WritePropertyName("rateRatio");
                    v_Ratio.SerializeJson(writer, options);
                    break;

                case Range v_Range:
                    writer.WritePropertyName("rateRange");
                    v_Range.SerializeJson(writer, options);
                    break;

                case Quantity v_Quantity:
                    writer.WritePropertyName("rateQuantity");
                    v_Quantity.SerializeJson(writer, options);
                    break;
                }
            }
            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deserialize JSON into a FHIR Dosage#DoseAndRate
        /// </summary>
        public static void DeserializeJsonProperty(this Dosage.DoseAndRateComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "type":
                current.Type = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Type).DeserializeJson(ref reader, options);
                break;

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

            case "doseQuantity":
                current.Dose = new Hl7.Fhir.Model.Quantity();
                ((Hl7.Fhir.Model.Quantity)current.Dose).DeserializeJson(ref reader, options);
                break;

            case "rateRatio":
                current.Rate = new Hl7.Fhir.Model.Ratio();
                ((Hl7.Fhir.Model.Ratio)current.Rate).DeserializeJson(ref reader, options);
                break;

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

            case "rateQuantity":
                current.Rate = new Hl7.Fhir.Model.Quantity();
                ((Hl7.Fhir.Model.Quantity)current.Rate).DeserializeJson(ref reader, options);
                break;

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