public static void SerializeMedicationPrescriptionDispenseComponent(Hl7.Fhir.Model.MedicationPrescription.MedicationPrescriptionDispenseComponent 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 medication
            if (value.Medication != null)
            {
                writer.WriteStartElement("medication");
                ResourceReferenceSerializer.SerializeResourceReference(value.Medication, writer, summary);
                writer.WriteEndElement();
            }

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

            // Serialize element numberOfRepeatsAllowed
            if (value.NumberOfRepeatsAllowedElement != null)
            {
                writer.WriteStartElement("numberOfRepeatsAllowed");
                IntegerSerializer.SerializeInteger(value.NumberOfRepeatsAllowedElement, writer, summary);
                writer.WriteEndElement();
            }

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

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


            writer.WriteEndComplexContent();
        }
        /// <summary>
        /// Parse MedicationPrescriptionDispenseComponent
        /// </summary>
        public static Hl7.Fhir.Model.MedicationPrescription.MedicationPrescriptionDispenseComponent ParseMedicationPrescriptionDispenseComponent(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.MedicationPrescription.MedicationPrescriptionDispenseComponent existingInstance = null)
        {
            Hl7.Fhir.Model.MedicationPrescription.MedicationPrescriptionDispenseComponent result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.MedicationPrescription.MedicationPrescriptionDispenseComponent();
            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 medication
                else if (atName == "medication")
                {
                    result.Medication = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

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

                // Parse element numberOfRepeatsAllowed
                else if (atName == "numberOfRepeatsAllowed")
                {
                    result.NumberOfRepeatsAllowedElement = IntegerParser.ParseInteger(reader, errors);
                }

                // Parse element quantity
                else if (atName == "quantity")
                {
                    result.Quantity = QuantityParser.ParseQuantity(reader, errors);
                }

                // Parse element expectedSupplyDuration
                else if (atName == "expectedSupplyDuration")
                {
                    result.ExpectedSupplyDuration = DurationParser.ParseDuration(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);
        }