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

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

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

            writer.WriteString("actuality", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.ActualityElement.Value));

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

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

            writer.WritePropertyName("subject");
            current.Subject.SerializeJson(writer, options);

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

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

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

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

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

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

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

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

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

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

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

            if ((current.SuspectEntity != null) && (current.SuspectEntity.Count != 0))
            {
                writer.WritePropertyName("suspectEntity");
                writer.WriteStartArray();
                foreach (AdverseEvent.SuspectEntityComponent val in current.SuspectEntity)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

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

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

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

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

            case "actuality":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.ActualityElement = new Code <Hl7.Fhir.Model.AdverseEvent.AdverseEventActuality>();
                    reader.Skip();
                }
                else
                {
                    current.ActualityElement = new Code <Hl7.Fhir.Model.AdverseEvent.AdverseEventActuality>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.AdverseEvent.AdverseEventActuality>(reader.GetString()));
                }
                break;

            case "_actuality":
                if (current.ActualityElement == null)
                {
                    current.ActualityElement = new Code <Hl7.Fhir.Model.AdverseEvent.AdverseEventActuality>();
                }
                ((Hl7.Fhir.Model.Element)current.ActualityElement).DeserializeJson(ref reader, options);
                break;

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

                current.Category = new List <CodeableConcept>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.CodeableConcept v_Category = new Hl7.Fhir.Model.CodeableConcept();
                    v_Category.DeserializeJson(ref reader, options);
                    current.Category.Add(v_Category);

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

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

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

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

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

            case "date":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.DateElement = new FhirDateTime();
                    reader.Skip();
                }
                else
                {
                    current.DateElement = new FhirDateTime(reader.GetString());
                }
                break;

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

            case "detected":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.DetectedElement = new FhirDateTime();
                    reader.Skip();
                }
                else
                {
                    current.DetectedElement = new FhirDateTime(reader.GetString());
                }
                break;

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

            case "recordedDate":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.RecordedDateElement = new FhirDateTime();
                    reader.Skip();
                }
                else
                {
                    current.RecordedDateElement = new FhirDateTime(reader.GetString());
                }
                break;

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

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

                current.ResultingCondition = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_ResultingCondition = new Hl7.Fhir.Model.ResourceReference();
                    v_ResultingCondition.DeserializeJson(ref reader, options);
                    current.ResultingCondition.Add(v_ResultingCondition);

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

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

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

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

            case "severity":
                current.Severity = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Severity).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 "recorder":
                current.Recorder = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Recorder).DeserializeJson(ref reader, options);
                break;

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

                current.Contributor = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_Contributor = new Hl7.Fhir.Model.ResourceReference();
                    v_Contributor.DeserializeJson(ref reader, options);
                    current.Contributor.Add(v_Contributor);

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

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

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

                current.SuspectEntity = new List <AdverseEvent.SuspectEntityComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.AdverseEvent.SuspectEntityComponent v_SuspectEntity = new Hl7.Fhir.Model.AdverseEvent.SuspectEntityComponent();
                    v_SuspectEntity.DeserializeJson(ref reader, options);
                    current.SuspectEntity.Add(v_SuspectEntity);

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

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

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

                current.SubjectMedicalHistory = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_SubjectMedicalHistory = new Hl7.Fhir.Model.ResourceReference();
                    v_SubjectMedicalHistory.DeserializeJson(ref reader, options);
                    current.SubjectMedicalHistory.Add(v_SubjectMedicalHistory);

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

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

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

                current.ReferenceDocument = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_ReferenceDocument = new Hl7.Fhir.Model.ResourceReference();
                    v_ReferenceDocument.DeserializeJson(ref reader, options);
                    current.ReferenceDocument.Add(v_ReferenceDocument);

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

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

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

                current.Study = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_Study = new Hl7.Fhir.Model.ResourceReference();
                    v_Study.DeserializeJson(ref reader, options);
                    current.Study.Add(v_Study);

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

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

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