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

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

            if (current.SequenceElement != null)
            {
                if (current.SequenceElement.Value != null)
                {
                    writer.WriteNumber("sequence", (int)current.SequenceElement.Value);
                }
                if (current.SequenceElement.HasExtensions() || (!string.IsNullOrEmpty(current.SequenceElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_sequence", false, current.SequenceElement.Extension, current.SequenceElement.ElementId);
                }
            }

            if (current.ChargeItem != null)
            {
                switch (current.ChargeItem)
                {
                case ResourceReference v_ResourceReference:
                    writer.WritePropertyName("chargeItemReference");
                    v_ResourceReference.SerializeJson(writer, options);
                    break;

                case CodeableConcept v_CodeableConcept:
                    writer.WritePropertyName("chargeItemCodeableConcept");
                    v_CodeableConcept.SerializeJson(writer, options);
                    break;
                }
            }
            if ((current.PriceComponent != null) && (current.PriceComponent.Count != 0))
            {
                writer.WritePropertyName("priceComponent");
                writer.WriteStartArray();
                foreach (Invoice.PriceComponentComponent val in current.PriceComponent)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserialize JSON into a FHIR Invoice#LineItem
        /// </summary>
        public static void DeserializeJsonProperty(this Invoice.LineItemComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "sequence":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.SequenceElement = new PositiveInt();
                    reader.Skip();
                }
                else
                {
                    current.SequenceElement = new PositiveInt(reader.GetInt32());
                }
                break;

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

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

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

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

                current.PriceComponent = new List <Invoice.PriceComponentComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Invoice.PriceComponentComponent v_PriceComponent = new Hl7.Fhir.Model.Invoice.PriceComponentComponent();
                    v_PriceComponent.DeserializeJson(ref reader, options);
                    current.PriceComponent.Add(v_PriceComponent);

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

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

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