/// <summary>
        /// Parse PrescriptionMedicineComponent
        /// </summary>
        public static Prescription.PrescriptionMedicineComponent ParsePrescriptionMedicineComponent(IFhirReader reader, ErrorList errors, Prescription.PrescriptionMedicineComponent existingInstance = null)
        {
            Prescription.PrescriptionMedicineComponent result = existingInstance != null ? existingInstance : new Prescription.PrescriptionMedicineComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if (reader.IsAtRefIdElement())
                    {
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());
                    }

                    // Parse element identification
                    else if (ParserUtils.IsAtFhirElement(reader, "identification"))
                    {
                        result.Identification = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                    }

                    // Parse element activeIngredient
                    else if (ParserUtils.IsAtFhirElement(reader, "activeIngredient"))
                    {
                        result.ActiveIngredient = new List <Prescription.PrescriptionMedicineActiveIngredientComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "activeIngredient"))
                        {
                            result.ActiveIngredient.Add(PrescriptionParser.ParsePrescriptionMedicineActiveIngredientComponent(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element inactiveIngredient
                    else if (ParserUtils.IsAtFhirElement(reader, "inactiveIngredient"))
                    {
                        result.InactiveIngredient = new List <Prescription.PrescriptionMedicineInactiveIngredientComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "inactiveIngredient"))
                        {
                            result.InactiveIngredient.Add(PrescriptionParser.ParsePrescriptionMedicineInactiveIngredientComponent(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);
        }
        /// <summary>
        /// Parse Prescription
        /// </summary>
        public static Prescription ParsePrescription(IFhirReader reader, ErrorList errors, Prescription existingInstance = null)
        {
            Prescription result = existingInstance != null ? existingInstance : new Prescription();

            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element language
                    else if (ParserUtils.IsAtFhirElement(reader, "language"))
                    {
                        result.Language = CodeParser.ParseCode(reader, errors);
                    }

                    // Parse element text
                    else if (ParserUtils.IsAtFhirElement(reader, "text"))
                    {
                        result.Text = NarrativeParser.ParseNarrative(reader, errors);
                    }

                    // Parse element contained
                    else if (ParserUtils.IsAtFhirElement(reader, "contained"))
                    {
                        result.Contained = new List <Resource>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "contained"))
                        {
                            result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if (reader.IsAtRefIdElement())
                    {
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());
                    }

                    // Parse element identifier
                    else if (ParserUtils.IsAtFhirElement(reader, "identifier"))
                    {
                        result.Identifier = new List <Identifier>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "identifier"))
                        {
                            result.Identifier.Add(IdentifierParser.ParseIdentifier(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element status
                    else if (ParserUtils.IsAtFhirElement(reader, "status"))
                    {
                        result.Status = CodeParser.ParseCode <Prescription.PrescriptionStatus>(reader, errors);
                    }

                    // Parse element patient
                    else if (ParserUtils.IsAtFhirElement(reader, "patient"))
                    {
                        result.Patient = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element prescriber
                    else if (ParserUtils.IsAtFhirElement(reader, "prescriber"))
                    {
                        result.Prescriber = ResourceReferenceParser.ParseResourceReference(reader, errors);
                    }

                    // Parse element prescribed
                    else if (ParserUtils.IsAtFhirElement(reader, "prescribed"))
                    {
                        result.Prescribed = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                    }

                    // Parse element dispense
                    else if (ParserUtils.IsAtFhirElement(reader, "dispense"))
                    {
                        result.Dispense = PrescriptionParser.ParsePrescriptionDispenseComponent(reader, errors);
                    }

                    // Parse element medicine
                    else if (ParserUtils.IsAtFhirElement(reader, "medicine"))
                    {
                        result.Medicine = PrescriptionParser.ParsePrescriptionMedicineComponent(reader, errors);
                    }

                    // Parse element administrationRequest
                    else if (ParserUtils.IsAtFhirElement(reader, "administrationRequest"))
                    {
                        result.AdministrationRequest = PrescriptionParser.ParsePrescriptionAdministrationRequestComponent(reader, errors);
                    }

                    // Parse element reason
                    else if (ParserUtils.IsAtFhirElement(reader, "reason"))
                    {
                        result.Reason = CodeableConceptParser.ParseCodeableConcept(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();
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message, reader);
            }
            return(result);
        }
        /// <summary>
        /// Parse PrescriptionAdministrationRequestComponent
        /// </summary>
        public static Prescription.PrescriptionAdministrationRequestComponent ParsePrescriptionAdministrationRequestComponent(IFhirReader reader, ErrorList errors, Prescription.PrescriptionAdministrationRequestComponent existingInstance = null)
        {
            Prescription.PrescriptionAdministrationRequestComponent result = existingInstance != null ? existingInstance : new Prescription.PrescriptionAdministrationRequestComponent();
            try
            {
                string currentElementName = reader.CurrentElementName;
                reader.EnterElement();

                while (reader.HasMoreElements())
                {
                    // Parse element extension
                    if (ParserUtils.IsAtFhirElement(reader, "extension"))
                    {
                        result.Extension = new List <Extension>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "extension"))
                        {
                            result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                        }

                        reader.LeaveArray();
                    }

                    // Parse element internalId
                    else if (reader.IsAtRefIdElement())
                    {
                        result.InternalId = Id.Parse(reader.ReadRefIdContents());
                    }

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

                    // Parse element totalPeriodicDose
                    else if (ParserUtils.IsAtFhirElement(reader, "totalPeriodicDose"))
                    {
                        result.TotalPeriodicDose = RatioParser.ParseRatio(reader, errors);
                    }

                    // Parse element start
                    else if (ParserUtils.IsAtFhirElement(reader, "start"))
                    {
                        result.Start = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                    }

                    // Parse element end
                    else if (ParserUtils.IsAtFhirElement(reader, "end"))
                    {
                        result.End = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                    }

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

                    // Parse element numberOfAdministrations
                    else if (ParserUtils.IsAtFhirElement(reader, "numberOfAdministrations"))
                    {
                        result.NumberOfAdministrations = IntegerParser.ParseInteger(reader, errors);
                    }

                    // Parse element dosageInstruction
                    else if (ParserUtils.IsAtFhirElement(reader, "dosageInstruction"))
                    {
                        result.DosageInstruction = new List <Prescription.PrescriptionAdministrationRequestDosageInstructionComponent>();
                        reader.EnterArray();

                        while (ParserUtils.IsAtArrayElement(reader, "dosageInstruction"))
                        {
                            result.DosageInstruction.Add(PrescriptionParser.ParsePrescriptionAdministrationRequestDosageInstructionComponent(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);
        }