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

            throw new JsonException($"AllergyIntolerance.ReactionComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
        private void TheAllergyIntoleranceReactionShouldBeValid()
        {
            AllAllergyIntolerances.ForEach(allergy => {
                if (allergy.Reaction != null)
                {
                    allergy.Reaction.Count.ShouldBeLessThanOrEqualTo(1);
                    // git hub ref 173
                    // RMB 4/2/19 - debug for testing code should have been removed
                    //                  if (allergy.Reaction.Count == 0)
                    //                   {
                    //                        allergy.Reaction.Count.ShouldBe(1);
                    //                   }
                    // git hub ref 173
                    // RMB 23/1/19
                    if (allergy.Reaction.Any())
                    {
                        AllergyIntolerance.ReactionComponent reaction = allergy.Reaction[0];
                        if (reaction.Manifestation != null)
                        {
                            reaction.Manifestation.Count.ShouldBeLessThanOrEqualTo(1);

                            if (reaction.Manifestation.Count == 1)
                            {
                                if (reaction.Severity != null)
                                {
                                    reaction.Severity.ShouldBeOfType <AllergyIntolerance.AllergyIntoleranceSeverity>($"AllergyIntolerance Severity is not a valid value within the value set {FhirConst.ValueSetSystems.kVsAllergyIntoleranceSeverity}");

                                    var codableConcept = reaction.Manifestation.First();

                                    var codingDisplay = codableConcept.Coding.First().Display;

                                    // codingDisplay.ShouldBe("nullFlavor NI", "AllergyIntolerance.reaction.manifestation SHOULD be coded as the nullFlavor NI");
                                }
                            }
                        }

                        if (reaction.ExposureRoute != null)
                        {
                            reaction.ExposureRoute.Coding.First().System.Equals(FhirConst.CodeSystems.kCCSnomed);
                        }

                        reaction.Note.ShouldBeEmpty();
                        reaction.Onset.ShouldBeNull("Allergy Reaction Onset should be Null");
                        reaction.Substance.ShouldBeNull("Allergy Reaction Substance should be Null");
                    }
                }
            });
        }
        private void AddSeverityObservation(XElement element, AllergyIntolerance.ReactionComponent reaction)
        {
            if (element == null || reaction == null)
            {
                return;
            }

            foreach (var child in element.Elements())
            {
                switch (child.Name.LocalName)
                {
                case "value":
                    reaction.Severity = new AllergyIntoleranceSeverityParser().FromCda(child.Attribute("code")?.Value);
                    break;
                }
            }
        }
        private void AddReactionObservation(XElement element)
        {
            if (AllergyIntolerance == null || element == null)
            {
                return;
            }

            var reaction = new AllergyIntolerance.ReactionComponent();

            foreach (var child in element.Elements())
            {
                switch (child.Name.LocalName)
                {
                case "id":
                    reaction.ElementId = FromXml(new IdentifierParser(), child)?.Value;
                    break;

                case "effectiveTime":
                    reaction.OnsetElement = FromXml(new FhirDateTimeParser(), child.CdaElement("low"));
                    break;

                case "value":
                    var manifestation = FromXml(new CodeableConceptParser(), child);
                    if (manifestation != null)
                    {
                        reaction.Manifestation.Add(manifestation);
                    }
                    break;

                case "entryRelationship":
                    var obs        = child.CdaElement("observation");
                    var templateId = obs.CdaElement("templateId")?.Attribute("root")?.Value;
                    if (templateId == "2.16.840.1.113883.10.20.22.4.8")
                    {
                        AddSeverityObservation(obs, reaction);
                    }
                    break;
                }
            }

            if (reaction.Manifestation.Any())
            {
                AllergyIntolerance.Reaction.Add(reaction);
            }
        }
        private void TheAllergyIntoleranceReactionShouldBeValid()
        {
            AllAllergyIntolerances.ForEach(allergy =>
            {
                if (allergy.Reaction != null)
                {
                    allergy.Reaction.Count.ShouldBeLessThanOrEqualTo(1);
                    AllergyIntolerance.ReactionComponent reaction = allergy.Reaction[0];
                    if (reaction.Manifestation != null)
                    {
                        reaction.Manifestation.Count.ShouldBeLessThanOrEqualTo(1);

                        if (reaction.Manifestation.Count == 1)
                        {
                            if (reaction.Severity != null)
                            {
                                reaction.Severity.ShouldBeOfType <AllergyIntolerance.AllergyIntoleranceSeverity>($"AllergyIntolerance Severity is not a valid value within the value set {FhirConst.ValueSetSystems.kVsAllergyIntoleranceSeverity}");

                                var codableConcept = reaction.Manifestation.First();

                                var codingDisplay = codableConcept.Coding.First().Display;

                                codingDisplay.ShouldBe("nullFlavor NI", "AllergyIntolerance.reaction.manifestation SHOULD be coded as the nullFlavor NI");
                            }
                        }
                    }

                    if (reaction.ExposureRoute != null)
                    {
                        reaction.ExposureRoute.Coding.First().System.Equals(FhirConst.CodeSystems.kCCSnomed);
                    }

                    reaction.Note.ShouldBeEmpty();
                    reaction.Onset.ShouldBeNull();
                    reaction.Substance.ShouldBeNull();
                }
            });
        }
예제 #6
0
        /// <summary>
        /// Deserialize JSON into a FHIR AllergyIntolerance#Reaction
        /// </summary>
        public static void DeserializeJsonProperty(this AllergyIntolerance.ReactionComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "substance":
                current.Substance = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Substance).DeserializeJson(ref reader, options);
                break;

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

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

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

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

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

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

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

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

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

            case "severity":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.SeverityElement = new Code <Hl7.Fhir.Model.AllergyIntolerance.AllergyIntoleranceSeverity>();
                    reader.Skip();
                }
                else
                {
                    current.SeverityElement = new Code <Hl7.Fhir.Model.AllergyIntolerance.AllergyIntoleranceSeverity>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.AllergyIntolerance.AllergyIntoleranceSeverity>(reader.GetString()));
                }
                break;

            case "_severity":
                if (current.SeverityElement == null)
                {
                    current.SeverityElement = new Code <Hl7.Fhir.Model.AllergyIntolerance.AllergyIntoleranceSeverity>();
                }
                ((Hl7.Fhir.Model.Element)current.SeverityElement).DeserializeJson(ref reader, options);
                break;

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

            case "note":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"ReactionComponent 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($"ReactionComponent 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: reaction, Export: ReactionComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
예제 #7
0
        /// <summary>
        /// Serialize a FHIR AllergyIntolerance#Reaction into JSON
        /// </summary>
        public static void SerializeJson(this AllergyIntolerance.ReactionComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: AllergyIntolerance#Reaction, Export: ReactionComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

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

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

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

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

            if (current.SeverityElement != null)
            {
                if (current.SeverityElement.Value != null)
                {
                    writer.WriteString("severity", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.SeverityElement.Value));
                }
                if (current.SeverityElement.HasExtensions() || (!string.IsNullOrEmpty(current.SeverityElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_severity", false, current.SeverityElement.Extension, current.SeverityElement.ElementId);
                }
            }

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

            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();
            }
        }