コード例 #1
0
        public static void SerializeProvenance(Hl7.Fhir.Model.Provenance value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartRootObject("Provenance");
            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 target
            if (value.Target != null && !summary && value.Target.Count > 0)
            {
                writer.WriteStartArrayElement("target");
                foreach (var item in value.Target)
                {
                    writer.WriteStartArrayMember("target");
                    ResourceReferenceSerializer.SerializeResourceReference(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

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

            // Serialize element recorded
            if (value.RecordedElement != null && !summary)
            {
                writer.WriteStartElement("recorded");
                InstantSerializer.SerializeInstant(value.RecordedElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element reason
            if (value.Reason != null && !summary)
            {
                writer.WriteStartElement("reason");
                CodeableConceptSerializer.SerializeCodeableConcept(value.Reason, writer, summary);
                writer.WriteEndElement();
            }

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

            // Serialize element policy
            if (value.PolicyElement != null && !summary && value.PolicyElement.Count > 0)
            {
                writer.WriteStartArrayElement("policy");
                foreach (var item in value.PolicyElement)
                {
                    writer.WriteStartArrayMember("policy");
                    FhirUriSerializer.SerializeFhirUri(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element agent
            if (value.Agent != null && !summary && value.Agent.Count > 0)
            {
                writer.WriteStartArrayElement("agent");
                foreach (var item in value.Agent)
                {
                    writer.WriteStartArrayMember("agent");
                    ProvenanceSerializer.SerializeProvenanceAgentComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element entity
            if (value.Entity != null && !summary && value.Entity.Count > 0)
            {
                writer.WriteStartArrayElement("entity");
                foreach (var item in value.Entity)
                {
                    writer.WriteStartArrayMember("entity");
                    ProvenanceSerializer.SerializeProvenanceEntityComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

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


            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }
コード例 #2
0
        /// <summary>
        /// Parse Provenance
        /// </summary>
        public static Hl7.Fhir.Model.Provenance ParseProvenance(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Provenance existingInstance = null)
        {
            Hl7.Fhir.Model.Provenance result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Provenance();
            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 target
                else if (atName == "target")
                {
                    result.Target = new List <Hl7.Fhir.Model.ResourceReference>();
                    reader.EnterArray();

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

                    reader.LeaveArray();
                }

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

                // Parse element recorded
                else if (atName == "recorded")
                {
                    result.RecordedElement = InstantParser.ParseInstant(reader, errors);
                }

                // Parse element reason
                else if (atName == "reason")
                {
                    result.Reason = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

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

                // Parse element policy
                else if (atName == "policy")
                {
                    result.PolicyElement = new List <Hl7.Fhir.Model.FhirUri>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "policy"))
                    {
                        result.PolicyElement.Add(FhirUriParser.ParseFhirUri(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element agent
                else if (atName == "agent")
                {
                    result.Agent = new List <Hl7.Fhir.Model.Provenance.ProvenanceAgentComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "agent"))
                    {
                        result.Agent.Add(ProvenanceParser.ParseProvenanceAgentComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element entity
                else if (atName == "entity")
                {
                    result.Entity = new List <Hl7.Fhir.Model.Provenance.ProvenanceEntityComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "entity"))
                    {
                        result.Entity.Add(ProvenanceParser.ParseProvenanceEntityComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element signature
                else if (atName == "signature")
                {
                    result.SignatureElement = 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);
        }
コード例 #3
0
        public override ErrorList Validate()
        {
            var result = new ErrorList();

            result.AddRange(base.Validate());

            if (Identifier != null)
            {
                result.AddRange(Identifier.Validate());
            }
            if (VersionIdentifier != null)
            {
                result.AddRange(VersionIdentifier.Validate());
            }
            if (CreatedElement != null)
            {
                result.AddRange(CreatedElement.Validate());
            }
            if (Type != null)
            {
                result.AddRange(Type.Validate());
            }
            if (Subtype != null)
            {
                result.AddRange(Subtype.Validate());
            }
            if (TitleElement != null)
            {
                result.AddRange(TitleElement.Validate());
            }
            if (StatusElement != null)
            {
                result.AddRange(StatusElement.Validate());
            }
            if (Confidentiality != null)
            {
                result.AddRange(Confidentiality.Validate());
            }
            if (Subject != null)
            {
                result.AddRange(Subject.Validate());
            }
            if (Author != null)
            {
                Author.ForEach(elem => result.AddRange(elem.Validate()));
            }
            if (Attester != null)
            {
                Attester.ForEach(elem => result.AddRange(elem.Validate()));
            }
            if (Custodian != null)
            {
                result.AddRange(Custodian.Validate());
            }
            if (Event != null)
            {
                result.AddRange(Event.Validate());
            }
            if (Encounter != null)
            {
                result.AddRange(Encounter.Validate());
            }
            if (ReplacesElement != null)
            {
                result.AddRange(ReplacesElement.Validate());
            }
            if (Provenance != null)
            {
                Provenance.ForEach(elem => result.AddRange(elem.Validate()));
            }
            if (Stylesheet != null)
            {
                result.AddRange(Stylesheet.Validate());
            }
            if (Representation != null)
            {
                result.AddRange(Representation.Validate());
            }
            if (Section != null)
            {
                Section.ForEach(elem => result.AddRange(elem.Validate()));
            }

            return(result);
        }