/// <summary>
        /// Parse ProvenanceEntityComponent
        /// </summary>
        public static Hl7.Fhir.Model.Provenance.ProvenanceEntityComponent ParseProvenanceEntityComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Provenance.ProvenanceEntityComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Provenance.ProvenanceEntityComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Provenance.ProvenanceEntityComponent();
            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 _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element role
                else if (atName == "role")
                {
                    result.RoleElement = CodeParser.ParseCode <Hl7.Fhir.Model.Provenance.ProvenanceEntityRole>(reader, errors);
                }

                // Parse element type
                else if (atName == "type")
                {
                    result.Type = CodingParser.ParseCoding(reader, errors);
                }

                // Parse element reference
                else if (atName == "reference")
                {
                    result.ReferenceElement = FhirUriParser.ParseFhirUri(reader, errors);
                }

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

                // Parse element agent
                else if (atName == "agent")
                {
                    result.Agent = ProvenanceParser.ParseProvenanceAgentComponent(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);
        }
Ejemplo n.º 2
0
        public static void SerializeProvenanceEntityComponent(Hl7.Fhir.Model.Provenance.ProvenanceEntityComponent value, IFhirWriter writer, bool summary)
        {
            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 role
            if (value.RoleElement != null)
            {
                writer.WriteStartElement("role");
                CodeSerializer.SerializeCode <Hl7.Fhir.Model.Provenance.ProvenanceEntityRole>(value.RoleElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element type
            if (value.Type != null)
            {
                writer.WriteStartElement("type");
                CodingSerializer.SerializeCoding(value.Type, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element reference
            if (value.ReferenceElement != null)
            {
                writer.WriteStartElement("reference");
                FhirUriSerializer.SerializeFhirUri(value.ReferenceElement, writer, summary);
                writer.WriteEndElement();
            }

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

            // Serialize element agent
            if (value.Agent != null)
            {
                writer.WriteStartElement("agent");
                ProvenanceSerializer.SerializeProvenanceAgentComponent(value.Agent, writer, summary);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
        }