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

            throw new JsonException($"MedicinalProductPackaged.PackageItemComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Esempio n. 2
0
        /// <summary>
        /// Deserialize JSON into a FHIR MedicinalProductPackaged#PackageItem
        /// </summary>
        public static void DeserializeJsonProperty(this MedicinalProductPackaged.PackageItemComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "identifier":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"PackageItemComponent 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($"PackageItemComponent 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 "type":
                current.Type = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Type).DeserializeJson(ref reader, options);
                break;

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

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

                current.Material = new List <CodeableConcept>();

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

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

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

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

                current.AlternateMaterial = new List <CodeableConcept>();

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

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

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

            case "device":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"PackageItemComponent 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($"PackageItemComponent 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 "manufacturedItem":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"PackageItemComponent error reading 'manufacturedItem' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

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

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

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

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

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

                current.PackageItem = new List <MedicinalProductPackaged.PackageItemComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MedicinalProductPackaged.PackageItemComponent v_PackageItem = new Hl7.Fhir.Model.MedicinalProductPackaged.PackageItemComponent();
                    v_PackageItem.DeserializeJson(ref reader, options);
                    current.PackageItem.Add(v_PackageItem);

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

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

            case "physicalCharacteristics":
                current.PhysicalCharacteristics = new Hl7.Fhir.Model.ProdCharacteristic();
                ((Hl7.Fhir.Model.ProdCharacteristic)current.PhysicalCharacteristics).DeserializeJson(ref reader, options);
                break;

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

                current.OtherCharacteristics = new List <CodeableConcept>();

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

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

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

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

                current.ShelfLifeStorage = new List <ProductShelfLife>();

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

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

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

            case "manufacturer":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"PackageItemComponent 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($"PackageItemComponent 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;

            // Complex: packageItem, Export: PackageItemComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Serialize a FHIR MedicinalProductPackaged#PackageItem into JSON
        /// </summary>
        public static void SerializeJson(this MedicinalProductPackaged.PackageItemComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: MedicinalProductPackaged#PackageItem, Export: PackageItemComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)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("type");
            current.Type.SerializeJson(writer, options);

            writer.WritePropertyName("quantity");
            current.Quantity.SerializeJson(writer, options);

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

            if ((current.AlternateMaterial != null) && (current.AlternateMaterial.Count != 0))
            {
                writer.WritePropertyName("alternateMaterial");
                writer.WriteStartArray();
                foreach (CodeableConcept val in current.AlternateMaterial)
                {
                    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.ManufacturedItem != null) && (current.ManufacturedItem.Count != 0))
            {
                writer.WritePropertyName("manufacturedItem");
                writer.WriteStartArray();
                foreach (ResourceReference val in current.ManufacturedItem)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

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

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

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

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

            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 (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }