public static void SerializeSchedule(Hl7.Fhir.Model.Schedule 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 event
            if (value.Event != null && value.Event.Count > 0)
            {
                writer.WriteStartArrayElement("event");
                foreach (var item in value.Event)
                {
                    writer.WriteStartArrayMember("event");
                    PeriodSerializer.SerializePeriod(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element repeat
            if (value.Repeat != null)
            {
                writer.WriteStartElement("repeat");
                ScheduleSerializer.SerializeScheduleRepeatComponent(value.Repeat, writer, summary);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
        }
        /// <summary>
        /// Parse Schedule
        /// </summary>
        public static Hl7.Fhir.Model.Schedule ParseSchedule(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Schedule existingInstance = null)
        {
            Hl7.Fhir.Model.Schedule result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Schedule();
            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 event
                else if (atName == "event")
                {
                    result.Event = new List <Hl7.Fhir.Model.Period>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "event"))
                    {
                        result.Event.Add(PeriodParser.ParsePeriod(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element repeat
                else if (atName == "repeat")
                {
                    result.Repeat = ScheduleParser.ParseScheduleRepeatComponent(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);
        }