public static void SerializeCarePlan(Hl7.Fhir.Model.CarePlan value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartRootObject("CarePlan");
            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 identifier
            if (value.Identifier != null && !summary)
            {
                writer.WriteStartElement("identifier");
                IdentifierSerializer.SerializeIdentifier(value.Identifier, writer, summary);
                writer.WriteEndElement();
            }

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

            // Serialize element status
            if (value.StatusElement != null && !summary)
            {
                writer.WriteStartElement("status");
                CodeSerializer.SerializeCode <Hl7.Fhir.Model.CarePlan.CarePlanStatus>(value.StatusElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element period
            if (value.Period != null && !summary)
            {
                writer.WriteStartElement("period");
                PeriodSerializer.SerializePeriod(value.Period, writer, summary);
                writer.WriteEndElement();
            }

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

            // Serialize element concern
            if (value.Concern != null && !summary && value.Concern.Count > 0)
            {
                writer.WriteStartArrayElement("concern");
                foreach (var item in value.Concern)
                {
                    writer.WriteStartArrayMember("concern");
                    ResourceReferenceSerializer.SerializeResourceReference(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element participant
            if (value.Participant != null && !summary && value.Participant.Count > 0)
            {
                writer.WriteStartArrayElement("participant");
                foreach (var item in value.Participant)
                {
                    writer.WriteStartArrayMember("participant");
                    CarePlanSerializer.SerializeCarePlanParticipantComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element goal
            if (value.Goal != null && !summary && value.Goal.Count > 0)
            {
                writer.WriteStartArrayElement("goal");
                foreach (var item in value.Goal)
                {
                    writer.WriteStartArrayMember("goal");
                    CarePlanSerializer.SerializeCarePlanGoalComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element activity
            if (value.Activity != null && !summary && value.Activity.Count > 0)
            {
                writer.WriteStartArrayElement("activity");
                foreach (var item in value.Activity)
                {
                    writer.WriteStartArrayMember("activity");
                    CarePlanSerializer.SerializeCarePlanActivityComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element notes
            if (value.NotesElement != null && !summary)
            {
                writer.WriteStartElement("notes");
                FhirStringSerializer.SerializeFhirString(value.NotesElement, writer, summary);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse CarePlan
        /// </summary>
        public static Hl7.Fhir.Model.CarePlan ParseCarePlan(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.CarePlan existingInstance = null)
        {
            Hl7.Fhir.Model.CarePlan result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.CarePlan();
            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 identifier
                else if (atName == "identifier")
                {
                    result.Identifier = IdentifierParser.ParseIdentifier(reader, errors);
                }

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

                // Parse element status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.CarePlan.CarePlanStatus>(reader, errors);
                }

                // Parse element period
                else if (atName == "period")
                {
                    result.Period = PeriodParser.ParsePeriod(reader, errors);
                }

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

                // Parse element concern
                else if (atName == "concern")
                {
                    result.Concern = new List <Hl7.Fhir.Model.ResourceReference>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "concern"))
                    {
                        result.Concern.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element participant
                else if (atName == "participant")
                {
                    result.Participant = new List <Hl7.Fhir.Model.CarePlan.CarePlanParticipantComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "participant"))
                    {
                        result.Participant.Add(CarePlanParser.ParseCarePlanParticipantComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element goal
                else if (atName == "goal")
                {
                    result.Goal = new List <Hl7.Fhir.Model.CarePlan.CarePlanGoalComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "goal"))
                    {
                        result.Goal.Add(CarePlanParser.ParseCarePlanGoalComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element activity
                else if (atName == "activity")
                {
                    result.Activity = new List <Hl7.Fhir.Model.CarePlan.CarePlanActivityComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "activity"))
                    {
                        result.Activity.Add(CarePlanParser.ParseCarePlanActivityComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element notes
                else if (atName == "notes")
                {
                    result.NotesElement = FhirStringParser.ParseFhirString(reader, errors);
                }

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