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

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

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

            writer.WritePropertyName("role");
            current.Role.SerializeJson(writer, options);

            if (current.AllergenicIndicatorElement != null)
            {
                if (current.AllergenicIndicatorElement.Value != null)
                {
                    writer.WriteBoolean("allergenicIndicator", (bool)current.AllergenicIndicatorElement.Value);
                }
                if (current.AllergenicIndicatorElement.HasExtensions() || (!string.IsNullOrEmpty(current.AllergenicIndicatorElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_allergenicIndicator", false, current.AllergenicIndicatorElement.Extension, current.AllergenicIndicatorElement.ElementId);
                }
            }

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

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

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

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
예제 #3
0
        /// <summary>
        /// Deserialize JSON into a FHIR MedicinalProductIngredient
        /// </summary>
        public static void DeserializeJsonProperty(this MedicinalProductIngredient current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "identifier":
                current.Identifier = new Hl7.Fhir.Model.Identifier();
                ((Hl7.Fhir.Model.Identifier)current.Identifier).DeserializeJson(ref reader, options);
                break;

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

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

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

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

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

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

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

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

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

                current.SpecifiedSubstance = new List <MedicinalProductIngredient.SpecifiedSubstanceComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MedicinalProductIngredient.SpecifiedSubstanceComponent v_SpecifiedSubstance = new Hl7.Fhir.Model.MedicinalProductIngredient.SpecifiedSubstanceComponent();
                    v_SpecifiedSubstance.DeserializeJson(ref reader, options);
                    current.SpecifiedSubstance.Add(v_SpecifiedSubstance);

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

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

            case "substance":
                current.Substance = new Hl7.Fhir.Model.MedicinalProductIngredient.SubstanceComponent();
                ((Hl7.Fhir.Model.MedicinalProductIngredient.SubstanceComponent)current.Substance).DeserializeJson(ref reader, options);
                break;

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