/// <summary>
        /// Parse ProtocolStepComponent
        /// </summary>
        public static Hl7.Fhir.Model.Protocol.ProtocolStepComponent ParseProtocolStepComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Protocol.ProtocolStepComponent existingInstance = null)
        {
            Hl7.Fhir.Model.Protocol.ProtocolStepComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Protocol.ProtocolStepComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "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 (ParserUtils.IsAtFhirElement(reader, "_id"))
                    {
                        result.LocalId = Id.Parse(reader.ReadPrimitiveContents("id"));
                    }

                    // Parse element name
                    else if (ParserUtils.IsAtFhirElement(reader, "name"))
                    {
                        result.Name = FhirStringParser.ParseFhirString(reader, errors);
                    }

                    // Parse element description
                    else if (ParserUtils.IsAtFhirElement(reader, "description"))
                    {
                        result.Description = FhirStringParser.ParseFhirString(reader, errors);
                    }

                    // Parse element duration
                    else if (ParserUtils.IsAtFhirElement(reader, "duration"))
                    {
                        result.Duration = DurationParser.ParseDuration(reader, errors);
                    }

                    // Parse element precondition
                    else if (ParserUtils.IsAtFhirElement(reader, "precondition"))
                    {
                        result.Precondition = ProtocolParser.ParseProtocolStepPreconditionComponent(reader, errors);
                    }

                    // Parse element exit
                    else if (ParserUtils.IsAtFhirElement(reader, "exit"))
                    {
                        result.Exit = ProtocolParser.ParseProtocolStepPreconditionComponent(reader, errors);
                    }

                    // Parse element firstActivity
                    else if (ParserUtils.IsAtFhirElement(reader, "firstActivity"))
                    {
                        result.FirstActivity = IdRefParser.ParseIdRef(reader, errors);
                    }

                    // Parse element activity
                    else if (ParserUtils.IsAtFhirElement(reader, "activity"))
                    {
                        result.Activity = new List <Hl7.Fhir.Model.Protocol.ProtocolStepActivityComponent>();
                        reader.EnterArray();

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

                        reader.LeaveArray();
                    }

                    // Parse element next
                    else if (ParserUtils.IsAtFhirElement(reader, "next"))
                    {
                        result.Next = new List <Hl7.Fhir.Model.Protocol.ProtocolStepNextComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "next"))
                        {
                            result.Next.Add(ProtocolParser.ParseProtocolStepNextComponent(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();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
Exemplo n.º 2
0
        public static void SerializeProtocolStepComponent(Hl7.Fhir.Model.Protocol.ProtocolStepComponent value, IFhirWriter writer)
        {
            writer.WriteStartComplexContent();

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

            // Serialize element _id
            if (value.LocalId != null)
            {
                writer.WriteStartElement("_id");
                IdSerializer.SerializeId(value.LocalId, writer);
                writer.WriteEndElement();
            }

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

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

            // Serialize element duration
            if (value.Duration != null)
            {
                writer.WriteStartElement("duration");
                QuantitySerializer.SerializeQuantity(value.Duration, writer);
                writer.WriteEndElement();
            }

            // Serialize element precondition
            if (value.Precondition != null)
            {
                writer.WriteStartElement("precondition");
                ProtocolSerializer.SerializeProtocolStepPreconditionComponent(value.Precondition, writer);
                writer.WriteEndElement();
            }

            // Serialize element exit
            if (value.Exit != null)
            {
                writer.WriteStartElement("exit");
                ProtocolSerializer.SerializeProtocolStepPreconditionComponent(value.Exit, writer);
                writer.WriteEndElement();
            }

            // Serialize element firstActivity
            if (value.FirstActivity != null)
            {
                writer.WriteStartElement("firstActivity");
                IdRefSerializer.SerializeIdRef(value.FirstActivity, writer);
                writer.WriteEndElement();
            }

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

            // Serialize element next
            if (value.Next != null && value.Next.Count > 0)
            {
                writer.WriteStartArrayElement("next");
                foreach (var item in value.Next)
                {
                    writer.WriteStartArrayMember("next");
                    ProtocolSerializer.SerializeProtocolStepNextComponent(item, writer);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }


            writer.WriteEndComplexContent();
        }