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

            throw new JsonException($"CompartmentDefinition.ResourceComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Пример #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR CompartmentDefinition#Resource
        /// </summary>
        public static void DeserializeJsonProperty(this CompartmentDefinition.ResourceComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "code":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.CodeElement = new Code <Hl7.Fhir.Model.ResourceType>();
                    reader.Skip();
                }
                else
                {
                    current.CodeElement = new Code <Hl7.Fhir.Model.ResourceType>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.ResourceType>(reader.GetString()));
                }
                break;

            case "_code":
                if (current.CodeElement == null)
                {
                    current.CodeElement = new Code <Hl7.Fhir.Model.ResourceType>();
                }
                ((Hl7.Fhir.Model.Element)current.CodeElement).DeserializeJson(ref reader, options);
                break;

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

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

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

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

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

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

                int i_param = 0;

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

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

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

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

            // Complex: resource, Export: ResourceComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// Serialize a FHIR CompartmentDefinition#Resource into JSON
        /// </summary>
        public static void SerializeJson(this CompartmentDefinition.ResourceComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: CompartmentDefinition#Resource, Export: ResourceComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            writer.WriteString("code", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.CodeElement.Value));

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

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

                    writer.WriteEndArray();
                }

                if (extensionCount > 0)
                {
                    writer.WritePropertyName("_param");
                    writer.WriteStartArray();
                    foreach (FhirString val in current.ParamElement)
                    {
                        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.DocumentationElement != null)
            {
                if (!string.IsNullOrEmpty(current.DocumentationElement.Value))
                {
                    writer.WriteString("documentation", current.DocumentationElement.Value);
                }
                if (current.DocumentationElement.HasExtensions() || (!string.IsNullOrEmpty(current.DocumentationElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_documentation", false, current.DocumentationElement.Extension, current.DocumentationElement.ElementId);
                }
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }