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

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

            writer.WritePropertyName("code");
            current.Code.SerializeJson(writer, options);

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

            if (current.ContributedToDeathElement != null)
            {
                if (current.ContributedToDeathElement.Value != null)
                {
                    writer.WriteBoolean("contributedToDeath", (bool)current.ContributedToDeathElement.Value);
                }
                if (current.ContributedToDeathElement.HasExtensions() || (!string.IsNullOrEmpty(current.ContributedToDeathElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_contributedToDeath", false, current.ContributedToDeathElement.Extension, current.ContributedToDeathElement.ElementId);
                }
            }

            if (current.Onset != null)
            {
                switch (current.Onset)
                {
                case Age v_Age:
                    writer.WritePropertyName("onsetAge");
                    v_Age.SerializeJson(writer, options);
                    break;

                case Range v_Range:
                    writer.WritePropertyName("onsetRange");
                    v_Range.SerializeJson(writer, options);
                    break;

                case Period v_Period:
                    writer.WritePropertyName("onsetPeriod");
                    v_Period.SerializeJson(writer, options);
                    break;

                case FhirString v_FhirString:
                    if (v_FhirString != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirString.Value))
                        {
                            writer.WriteString("onsetString", v_FhirString.Value);
                        }
                        if (v_FhirString.HasExtensions() || (!string.IsNullOrEmpty(v_FhirString.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_onsetString", false, v_FhirString.Extension, v_FhirString.ElementId);
                        }
                    }
                    break;
                }
            }
            if ((current.Note != null) && (current.Note.Count != 0))
            {
                writer.WritePropertyName("note");
                writer.WriteStartArray();
                foreach (Annotation val in current.Note)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deserialize JSON into a FHIR FamilyMemberHistory#Condition
        /// </summary>
        public static void DeserializeJsonProperty(this FamilyMemberHistory.ConditionComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "code":
                current.Code = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Code).DeserializeJson(ref reader, options);
                break;

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

            case "contributedToDeath":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.ContributedToDeathElement = new FhirBoolean();
                    reader.Skip();
                }
                else
                {
                    current.ContributedToDeathElement = new FhirBoolean(reader.GetBoolean());
                }
                break;

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

            case "onsetAge":
                current.Onset = new Hl7.Fhir.Model.Age();
                ((Hl7.Fhir.Model.Age)current.Onset).DeserializeJson(ref reader, options);
                break;

            case "onsetRange":
                current.Onset = new Hl7.Fhir.Model.Range();
                ((Hl7.Fhir.Model.Range)current.Onset).DeserializeJson(ref reader, options);
                break;

            case "onsetPeriod":
                current.Onset = new Hl7.Fhir.Model.Period();
                ((Hl7.Fhir.Model.Period)current.Onset).DeserializeJson(ref reader, options);
                break;

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

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

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

                current.Note = new List <Annotation>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Annotation v_Note = new Hl7.Fhir.Model.Annotation();
                    v_Note.DeserializeJson(ref reader, options);
                    current.Note.Add(v_Note);

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

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

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