Esempio n. 1
0
        public static void SerializeAdverseReaction(Hl7.Fhir.Model.AdverseReaction value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartRootObject("AdverseReaction");
            writer.WriteStartComplexContent();

            // Serialize element _id
            if (value.LocalIdElement != null)
            {
                writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute);
            }

            // Serialize element extension
            if (value.Extension != null && !summary && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach (var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element language
            if (value.LanguageElement != null && !summary)
            {
                writer.WriteStartElement("language");
                CodeSerializer.SerializeCode(value.LanguageElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element text
            if (value.Text != null && !summary)
            {
                writer.WriteStartElement("text");
                NarrativeSerializer.SerializeNarrative(value.Text, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element contained
            if (value.Contained != null && !summary && value.Contained.Count > 0)
            {
                writer.WriteStartArrayElement("contained");
                foreach (var item in value.Contained)
                {
                    writer.WriteStartArrayMember("contained");
                    FhirSerializer.SerializeResource(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element reactionDate
            if (value.ReactionDateElement != null && !summary)
            {
                writer.WriteStartElement("reactionDate");
                FhirDateTimeSerializer.SerializeFhirDateTime(value.ReactionDateElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element subject
            if (value.Subject != null && !summary)
            {
                writer.WriteStartElement("subject");
                ResourceReferenceSerializer.SerializeResourceReference(value.Subject, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element didNotOccurFlag
            if (value.DidNotOccurFlagElement != null && !summary)
            {
                writer.WriteStartElement("didNotOccurFlag");
                FhirBooleanSerializer.SerializeFhirBoolean(value.DidNotOccurFlagElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element recorder
            if (value.Recorder != null && !summary)
            {
                writer.WriteStartElement("recorder");
                ResourceReferenceSerializer.SerializeResourceReference(value.Recorder, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element symptom
            if (value.Symptom != null && !summary && value.Symptom.Count > 0)
            {
                writer.WriteStartArrayElement("symptom");
                foreach (var item in value.Symptom)
                {
                    writer.WriteStartArrayMember("symptom");
                    AdverseReactionSerializer.SerializeAdverseReactionSymptomComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element exposure
            if (value.Exposure != null && !summary && value.Exposure.Count > 0)
            {
                writer.WriteStartArrayElement("exposure");
                foreach (var item in value.Exposure)
                {
                    writer.WriteStartArrayMember("exposure");
                    AdverseReactionSerializer.SerializeAdverseReactionExposureComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }


            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }
Esempio n. 2
0
        /// <summary>
        /// Parse AdverseReaction
        /// </summary>
        public static Hl7.Fhir.Model.AdverseReaction ParseAdverseReaction(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.AdverseReaction existingInstance = null)
        {
            Hl7.Fhir.Model.AdverseReaction result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.AdverseReaction();
            string currentElementName             = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element reactionDate
                else if (atName == "reactionDate")
                {
                    result.ReactionDateElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                }

                // Parse element subject
                else if (atName == "subject")
                {
                    result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element didNotOccurFlag
                else if (atName == "didNotOccurFlag")
                {
                    result.DidNotOccurFlagElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                // Parse element recorder
                else if (atName == "recorder")
                {
                    result.Recorder = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element symptom
                else if (atName == "symptom")
                {
                    result.Symptom = new List <Hl7.Fhir.Model.AdverseReaction.AdverseReactionSymptomComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "symptom"))
                    {
                        result.Symptom.Add(AdverseReactionParser.ParseAdverseReactionSymptomComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element exposure
                else if (atName == "exposure")
                {
                    result.Exposure = new List <Hl7.Fhir.Model.AdverseReaction.AdverseReactionExposureComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "exposure"))
                    {
                        result.Exposure.Add(AdverseReactionParser.ParseAdverseReactionExposureComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }