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

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

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

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

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

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

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

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

            if (current.ShapeElement != null)
            {
                if (!string.IsNullOrEmpty(current.ShapeElement.Value))
                {
                    writer.WriteString("shape", current.ShapeElement.Value);
                }
                if (current.ShapeElement.HasExtensions() || (!string.IsNullOrEmpty(current.ShapeElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_shape", false, current.ShapeElement.Extension, current.ShapeElement.ElementId);
                }
            }

            if ((current.ColorElement != null) && (current.ColorElement.Count != 0))
            {
                int valueCount     = 0;
                int extensionCount = 0;
                foreach (FhirString val in current.ColorElement)
                {
                    if (!string.IsNullOrEmpty(val.Value))
                    {
                        valueCount++;
                    }
                    if (val.HasExtensions())
                    {
                        extensionCount++;
                    }
                }

                if (valueCount > 0)
                {
                    writer.WritePropertyName("color");
                    writer.WriteStartArray();
                    foreach (FhirString val in current.ColorElement)
                    {
                        if (string.IsNullOrEmpty(val.Value))
                        {
                            writer.WriteNullValue();
                        }
                        else
                        {
                            writer.WriteStringValue(val.Value);
                        }
                    }

                    writer.WriteEndArray();
                }

                if (extensionCount > 0)
                {
                    writer.WritePropertyName("_color");
                    writer.WriteStartArray();
                    foreach (FhirString val in current.ColorElement)
                    {
                        if (val.HasExtensions() || (!string.IsNullOrEmpty(val.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, string.Empty, true, val.Extension, val.ElementId);
                        }
                        else
                        {
                            writer.WriteNullValue();
                        }
                    }

                    writer.WriteEndArray();
                }
            }

            if ((current.ImprintElement != null) && (current.ImprintElement.Count != 0))
            {
                int valueCount     = 0;
                int extensionCount = 0;
                foreach (FhirString val in current.ImprintElement)
                {
                    if (!string.IsNullOrEmpty(val.Value))
                    {
                        valueCount++;
                    }
                    if (val.HasExtensions())
                    {
                        extensionCount++;
                    }
                }

                if (valueCount > 0)
                {
                    writer.WritePropertyName("imprint");
                    writer.WriteStartArray();
                    foreach (FhirString val in current.ImprintElement)
                    {
                        if (string.IsNullOrEmpty(val.Value))
                        {
                            writer.WriteNullValue();
                        }
                        else
                        {
                            writer.WriteStringValue(val.Value);
                        }
                    }

                    writer.WriteEndArray();
                }

                if (extensionCount > 0)
                {
                    writer.WritePropertyName("_imprint");
                    writer.WriteStartArray();
                    foreach (FhirString val in current.ImprintElement)
                    {
                        if (val.HasExtensions() || (!string.IsNullOrEmpty(val.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, string.Empty, true, val.Extension, val.ElementId);
                        }
                        else
                        {
                            writer.WriteNullValue();
                        }
                    }

                    writer.WriteEndArray();
                }
            }

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

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

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
コード例 #3
0
        /// <summary>
        /// Deserialize JSON into a FHIR ProdCharacteristic
        /// </summary>
        public static void DeserializeJsonProperty(this ProdCharacteristic current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "height":
                current.Height = new Hl7.Fhir.Model.Quantity();
                ((Hl7.Fhir.Model.Quantity)current.Height).DeserializeJson(ref reader, options);
                break;

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

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

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

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

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

            case "shape":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.ShapeElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.ShapeElement = new FhirString(reader.GetString());
                }
                break;

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

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

                current.ColorElement = new List <FhirString>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    if (reader.TokenType == JsonTokenType.Null)
                    {
                        current.ColorElement.Add(new FhirString());
                        reader.Skip();
                    }
                    else
                    {
                        current.ColorElement.Add(new FhirString(reader.GetString()));
                    }

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

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

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

                int i_color = 0;

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    if (i_color >= current.ColorElement.Count)
                    {
                        current.ColorElement.Add(new FhirString());
                    }
                    if (reader.TokenType == JsonTokenType.Null)
                    {
                        reader.Skip();
                    }
                    else
                    {
                        ((Hl7.Fhir.Model.Element)current.ColorElement[i_color++]).DeserializeJson(ref reader, options);
                    }

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

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

                current.ImprintElement = new List <FhirString>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    if (reader.TokenType == JsonTokenType.Null)
                    {
                        current.ImprintElement.Add(new FhirString());
                        reader.Skip();
                    }
                    else
                    {
                        current.ImprintElement.Add(new FhirString(reader.GetString()));
                    }

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

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

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

                int i_imprint = 0;

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    if (i_imprint >= current.ImprintElement.Count)
                    {
                        current.ImprintElement.Add(new FhirString());
                    }
                    if (reader.TokenType == JsonTokenType.Null)
                    {
                        reader.Skip();
                    }
                    else
                    {
                        ((Hl7.Fhir.Model.Element)current.ImprintElement[i_imprint++]).DeserializeJson(ref reader, options);
                    }

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

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

                current.Image = new List <Attachment>();

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

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

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

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

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