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

            throw new JsonException($"MedicationAdministration.DosageComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Example #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR MedicationAdministration#Dosage
        /// </summary>
        public static void DeserializeJsonProperty(this MedicationAdministration.DosageComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "text":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.TextElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.TextElement = new FhirString(reader.GetString());
                }
                break;

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

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

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

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

            case "dose":
                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 "rateQuantity":
                current.Rate = new Hl7.Fhir.Model.Quantity();
                ((Hl7.Fhir.Model.Quantity)current.Rate).DeserializeJson(ref reader, options);
                break;

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

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

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

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

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

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

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

                case Quantity v_Quantity:
                    writer.WritePropertyName("rateQuantity");
                    v_Quantity.SerializeJson(writer, options);
                    break;
                }
            }
            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }