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

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

            if (current.Item != null)
            {
                switch (current.Item)
                {
                case CodeableConcept v_CodeableConcept:
                    writer.WritePropertyName("itemCodeableConcept");
                    v_CodeableConcept.SerializeJson(writer, options);
                    break;

                case ResourceReference v_ResourceReference:
                    writer.WritePropertyName("itemReference");
                    v_ResourceReference.SerializeJson(writer, options);
                    break;
                }
            }
            if (current.IsActiveElement != null)
            {
                if (current.IsActiveElement.Value != null)
                {
                    writer.WriteBoolean("isActive", (bool)current.IsActiveElement.Value);
                }
                if (current.IsActiveElement.HasExtensions() || (!string.IsNullOrEmpty(current.IsActiveElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_isActive", false, current.IsActiveElement.Extension, current.IsActiveElement.ElementId);
                }
            }

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

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
示例#3
0
        /// <summary>
        /// Deserialize JSON into a FHIR Medication#Ingredient
        /// </summary>
        public static void DeserializeJsonProperty(this Medication.IngredientComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "itemCodeableConcept":
                current.Item = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Item).DeserializeJson(ref reader, options);
                break;

            case "itemReference":
                current.Item = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Item).DeserializeJson(ref reader, options);
                break;

            case "isActive":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.IsActiveElement = new FhirBoolean();
                    reader.Skip();
                }
                else
                {
                    current.IsActiveElement = new FhirBoolean(reader.GetBoolean());
                }
                break;

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

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

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