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

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

            writer.WriteString("type", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.TypeElement.Value));

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

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

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

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

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

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

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Deserialize JSON into a FHIR RelatedArtifact
        /// </summary>
        public static void DeserializeJsonProperty(this RelatedArtifact current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "type":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.RelatedArtifact.RelatedArtifactType>();
                    reader.Skip();
                }
                else
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.RelatedArtifact.RelatedArtifactType>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.RelatedArtifact.RelatedArtifactType>(reader.GetString()));
                }
                break;

            case "_type":
                if (current.TypeElement == null)
                {
                    current.TypeElement = new Code <Hl7.Fhir.Model.RelatedArtifact.RelatedArtifactType>();
                }
                ((Hl7.Fhir.Model.Element)current.TypeElement).DeserializeJson(ref reader, options);
                break;

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

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

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

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

            case "citation":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.Citation = new Markdown();
                    reader.Skip();
                }
                else
                {
                    current.Citation = new Markdown(reader.GetString());
                }
                break;

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

            case "url":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.UrlElement = new FhirUrl();
                    reader.Skip();
                }
                else
                {
                    current.UrlElement = new FhirUrl(reader.GetString());
                }
                break;

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

            case "document":
                current.Document = new Hl7.Fhir.Model.Attachment();
                ((Hl7.Fhir.Model.Attachment)current.Document).DeserializeJson(ref reader, options);
                break;

            case "resource":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.ResourceElement = new Canonical();
                    reader.Skip();
                }
                else
                {
                    current.ResourceElement = new Canonical(reader.GetString());
                }
                break;

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

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