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

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

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

            writer.WritePropertyName("administrableDoseForm");
            current.AdministrableDoseForm.SerializeJson(writer, options);

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

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

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

            if ((current.Characteristics != null) && (current.Characteristics.Count != 0))
            {
                writer.WritePropertyName("characteristics");
                writer.WriteStartArray();
                foreach (MedicinalProductPharmaceutical.CharacteristicsComponent val in current.Characteristics)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if ((current.RouteOfAdministration != null) && (current.RouteOfAdministration.Count != 0))
            {
                writer.WritePropertyName("routeOfAdministration");
                writer.WriteStartArray();
                foreach (MedicinalProductPharmaceutical.RouteOfAdministrationComponent val in current.RouteOfAdministration)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deserialize JSON into a FHIR MedicinalProductPharmaceutical
        /// </summary>
        public static void DeserializeJsonProperty(this MedicinalProductPharmaceutical current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "identifier":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductPharmaceutical error reading 'identifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Identifier = new List <Identifier>();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                current.Characteristics = new List <MedicinalProductPharmaceutical.CharacteristicsComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MedicinalProductPharmaceutical.CharacteristicsComponent v_Characteristics = new Hl7.Fhir.Model.MedicinalProductPharmaceutical.CharacteristicsComponent();
                    v_Characteristics.DeserializeJson(ref reader, options);
                    current.Characteristics.Add(v_Characteristics);

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

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

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

                current.RouteOfAdministration = new List <MedicinalProductPharmaceutical.RouteOfAdministrationComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MedicinalProductPharmaceutical.RouteOfAdministrationComponent v_RouteOfAdministration = new Hl7.Fhir.Model.MedicinalProductPharmaceutical.RouteOfAdministrationComponent();
                    v_RouteOfAdministration.DeserializeJson(ref reader, options);
                    current.RouteOfAdministration.Add(v_RouteOfAdministration);

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

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

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