/// <summary>
        /// Populates this <see cref="LabTestResults"/> instance from the data in the XML. 
        /// </summary>
        /// 
        /// <param name="typeSpecificXml">
        /// The XML to get the lab test results data from.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the first node in <paramref name="typeSpecificXml"/> is not
        /// a lab test results node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator itemNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("lab-test-results");

            Validator.ThrowInvalidIfNull(itemNav, "LabTestResultsUnexpectedNode");

            // when
            _when =
                XPathHelper.GetOptNavValue<ApproximateDateTime>(itemNav, "when");

            // lab-group
            XPathNodeIterator labGroupIterator =
                itemNav.Select("lab-group");
            _labGroup = new Collection<LabTestResultGroup>();
            foreach (XPathNavigator labGroupNav in labGroupIterator)
            {
                LabTestResultGroup labTestResultGroup = new LabTestResultGroup();
                labTestResultGroup.ParseXml(labGroupNav);
                _labGroup.Add(labTestResultGroup);
            }

            // ordered-by
            _orderedBy =
                XPathHelper.GetOptNavValue<Organization>(itemNav, "ordered-by");
        }
        /// <summary>
        /// Populates this <see cref="GeneticSnpResults"/> instance from the data
        /// in the XML.
        /// </summary>
        /// 
        /// <param name="typeSpecificXml">
        /// The XML to get the genetic snp result data from.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the first node in <paramref name="typeSpecificXml"/> is not
        /// an "genetic-snp-results" node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator itemNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("genetic-snp-results");

            Validator.ThrowInvalidIfNull(itemNav, "GeneticSnpResultsUnexpectedNode");

            // <when> mandatory
            _when = new ApproximateDateTime();
            _when.ParseXml(itemNav.SelectSingleNode("when"));

            // <genome-build> mandatory
            _genomeBuild = itemNav.SelectSingleNode("genome-build").Value;

            // <chromosome> mandatory
            _chromosome = itemNav.SelectSingleNode("chromosome").Value;

            // <numbering-scheme> mandatory
            int numberingScheme = itemNav.SelectSingleNode("numbering-scheme").ValueAsInt;
            if ((numberingScheme == 0) || (numberingScheme == 1))
            {
                _numberingScheme = (GenomeNumberingScheme)numberingScheme;
            }
            else
            {
                _numberingScheme = GenomeNumberingScheme.Unknown;
            }

            // ordered-by
            _orderedBy =
                XPathHelper.GetOptNavValue<Organization>(itemNav, "ordered-by");

            // test-provider
            _testProvider =
                XPathHelper.GetOptNavValue<Organization>(itemNav, "test-provider");

            // laboratory-name
            _laboratoryName =
                XPathHelper.GetOptNavValue<Organization>(itemNav, "laboratory-name");

            // annotation-version
            _annotationVersion =
                XPathHelper.GetOptNavValue(itemNav, "annotation-version");

            // dbSNP-build
            _dbSnpBuild =
                XPathHelper.GetOptNavValue(itemNav, "dbSNP-build");

            // platform
            _platform =
                XPathHelper.GetOptNavValue(itemNav, "platform");
        }
        /// <summary>
        /// Populates this <see cref="LabTestResultGroup"/> instance from the data in the XML. 
        /// </summary>
        /// 
        /// <param name="navigator">
        /// The XML to get the lab test results group type data from.
        /// </param> 
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="navigator"/> is <b>null</b>.
        /// </exception>
        /// 
        public override void ParseXml(XPathNavigator navigator)
        {
            Validator.ThrowIfNavigatorNull(navigator);

               // group-name
               _groupName = new CodableValue();
               _groupName.ParseXml(navigator.SelectSingleNode("group-name"));

               // laboratory-name
               _laboratoryName =
               XPathHelper.GetOptNavValue<Organization>(navigator,"laboratory-name");

               // status
               _status =
               XPathHelper.GetOptNavValue<CodableValue>(navigator,"status");

               // sub-groups
               XPathNodeIterator subGroupsIterator = navigator.Select("sub-groups");

               _subGroups = new Collection<LabTestResultGroup>();
               foreach (XPathNavigator subGroupNav in subGroupsIterator)
               {
               LabTestResultGroup _subGroup = new LabTestResultGroup();
               _subGroup.ParseXml(subGroupNav);
               _subGroups.Add(_subGroup);
               }

               // results
               XPathNodeIterator resultsIterator = navigator.Select("results");

               _results = new Collection<LabTestResultDetails>();
               foreach (XPathNavigator resultNav in resultsIterator)
               {
               LabTestResultDetails result = new LabTestResultDetails();
               result.ParseXml(resultNav);
               _results.Add(result);
               }
        }
        /// <summary>
        /// Populates the data from the specified XML.
        /// </summary>
        /// 
        /// <param name="navigator">
        /// The XML containing the medical image study series.
        /// </param>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="navigator"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        public override void ParseXml(XPathNavigator navigator)
        {
            Validator.ThrowIfNavigatorNull(navigator);

            _acquisitionDateTime = XPathHelper.GetOptNavValue<HealthServiceDateTime>(navigator, "acquisition-datetime");
            _description = XPathHelper.GetOptNavValue(navigator, "description");

            _images.Clear();
            XPathNodeIterator imageIterator = navigator.Select("images");
            foreach (XPathNavigator imageNav in imageIterator)
            {
                MedicalImageStudySeriesImage image = new MedicalImageStudySeriesImage();
                image.ParseXml(imageNav);
                _images.Add(image);
            }

            _institutionName = XPathHelper.GetOptNavValue<Organization>(navigator, "institution-name");
            _modality = XPathHelper.GetOptNavValue<CodableValue>(navigator, "modality");
            _bodyPart = XPathHelper.GetOptNavValue<CodableValue>(navigator, "body-part");
            _previewBlobName = XPathHelper.GetOptNavValue(navigator, "preview-blob-name");
            _seriesInstanceUID = XPathHelper.GetOptNavValue(navigator, "series-instance-uid");
        }
        /// <summary>
        /// Populates this <see cref="ExplanationOfBenefits"/> instance from the data in the specified XML.
        /// </summary>
        ///
        /// <param name="typeSpecificXml">
        /// The XML to get the ExplanationOfBenefits data from.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="typeSpecificXml"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the first node in <paramref name="typeSpecificXml"/> is not
        /// a ExplanationOfBenefits node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            Validator.ThrowIfArgumentNull(typeSpecificXml, "typeSpecificXml", "ParseXmlNavNull");

            XPathNavigator itemNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("explanation-of-benefits");

            Validator.ThrowInvalidIfNull(itemNav, "ExplanationOfBenefitsUnexpectedNode");

            _dateSubmitted = XPathHelper.GetOptNavValue<HealthServiceDateTime>(itemNav, "date-submitted");
            _patient = XPathHelper.GetOptNavValue<PersonItem>(itemNav, "patient");
            _relationshipToMember = XPathHelper.GetOptNavValue<CodableValue>(itemNav, "relationship-to-member");
            _plan = XPathHelper.GetOptNavValue<Organization>(itemNav, "plan");
            _groupId = XPathHelper.GetOptNavValue(itemNav, "group-id");
            _memberId = itemNav.SelectSingleNode("member-id").Value;
            _claimType = XPathHelper.GetOptNavValue<CodableValue>(itemNav, "claim-type");
            _claimId = itemNav.SelectSingleNode("claim-id").Value;
            _submittedBy = XPathHelper.GetOptNavValue<Organization>(itemNav, "submitted-by");
            _provider = XPathHelper.GetOptNavValue<Organization>(itemNav, "provider");
            _currency = XPathHelper.GetOptNavValue<CodableValue>(itemNav, "currency");
            _claimTotals = XPathHelper.GetOptNavValue<ClaimAmounts>(itemNav, "claim-totals");

            _services.Clear();
            foreach(XPathNavigator servicesNav in itemNav.Select("services"))
            {
                Service service = new Service();
                service.ParseXml(servicesNav);
                _services.Add(service);
            }
        }
        /// <summary>
        /// Creates a new instance of the <see cref="ExplanationOfBenefits"/> class specifying mandatory values.
        /// </summary>
        ///
        /// <remarks>
        /// This item is not added to the health record until the
        /// <see cref="Microsoft.Health.HealthRecordAccessor.NewItem(HealthRecordItem)"/> method
        /// is called.
        /// </remarks>
        ///
        /// <param name="dateSubmitted">
        /// The date when the claim was submitted.
        /// </param>
        /// <param name="patient">
        /// The name of the patient.
        /// </param>
        /// <param name="plan">
        /// The plan covering this claim.
        /// </param>
        /// <param name="memberId">
        /// The member id of the plan member.
        /// </param>
        /// <param name="claimType">
        /// The type of the claim (medical, dental, etc.)
        /// </param>
        /// <param name="claimId">
        /// The claim id.
        /// </param>
        /// <param name="submittedBy">
        /// The organization that submitted this claim.
        /// </param>
        /// <param name="provider">
        /// The provider that performed the services.
        /// </param>
        /// <param name="currency">
        /// The currency used.
        /// </param>
        /// <param name="claimTotals">
        /// A summary of the financial information about this claim.
        /// </param>
        /// <param name="services">
        /// The service included in this claim.
        /// </param>
        ///
        /// <exception cref="ArgumentException">
        /// If <paramref name="memberId"/> is empty or contains only whitespace.
        /// If <paramref name="claimId"/> is empty or contains only whitespace.
        /// If <paramref name="services"/> is <b>null</b> or doesn't contain any values.            
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="memberId"/> is <b>null</b>.
        /// If <paramref name="claimId"/> is <b>null</b>.
        /// If <paramref name="dateSubmitted"/> is <b>null</b>.            
        /// If <paramref name="patient"/> is <b>null</b>.            
        /// If <paramref name="plan"/> is <b>null</b>.            
        /// If <paramref name="claimType"/> is <b>null</b>.            
        /// If <paramref name="submittedBy"/> is <b>null</b>.            
        /// If <paramref name="provider"/> is <b>null</b>.            
        /// If <paramref name="currency"/> is <b>null</b>.            
        /// If <paramref name="claimTotals"/> is <b>null</b>.            
        /// </exception>
        ///
        public ExplanationOfBenefits(
            HealthServiceDateTime dateSubmitted,
            PersonItem patient,    
            Organization plan,    
            string memberId,    
            CodableValue claimType,    
            string claimId,    
            Organization submittedBy,    
            Organization provider,    
            CodableValue currency,    
            ClaimAmounts claimTotals,    
            IEnumerable<Service> services)
            : base(TypeId)
        {
            DateSubmitted = dateSubmitted;
            Patient = patient;
            Plan = plan;
            MemberId = memberId;
            ClaimType = claimType;
            ClaimId = claimId;
            SubmittedBy = submittedBy;
            Provider = provider;
            Currency = currency;
            ClaimTotals = claimTotals;

            Validator.ThrowIfArgumentNull(services, "services", "ServicesMandatory");

            foreach (Service val in services)
            {
                Services.Add(val);
            }

            if (Services.Count == 0)
            {
                throw Validator.ArgumentException("services", "ServicesMandatory");
            }
        }
        /// <summary>
        /// Populates the data from the specified XML.
        /// </summary>
        /// 
        /// <param name="navigator">
        /// The XML containing the delivery.
        /// </param>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="navigator"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        public override void ParseXml(XPathNavigator navigator)
        {
            Validator.ThrowIfNavigatorNull(navigator);

            _location = XPathHelper.GetOptNavValue<Organization>(navigator, "location");
            _timeOfDelivery = XPathHelper.GetOptNavValue<ApproximateDateTime>(navigator, "time-of-delivery");
            _laborDuration = XPathHelper.GetOptNavValueAsDouble(navigator, "labor-duration");

            _complications.Clear();
            foreach (XPathNavigator complicationNav in navigator.Select("complications"))
            {
                CodableValue complication = new CodableValue();
                complication.ParseXml(complicationNav);
                _complications.Add(complication);
            }

            _anesthesia.Clear();
            foreach (XPathNavigator anesthesiaNav in navigator.Select("anesthesia"))
            {
                CodableValue anesthesia = new CodableValue();
                anesthesia.ParseXml(anesthesiaNav);
                _anesthesia.Add(anesthesia);
            }

            _deliveryMethod = XPathHelper.GetOptNavValue<CodableValue>(navigator, "delivery-method");
            _outcome = XPathHelper.GetOptNavValue<CodableValue>(navigator, "outcome");
            _baby = XPathHelper.GetOptNavValue<Baby>(navigator, "baby");
            _note = XPathHelper.GetOptNavValue(navigator, "note");
        }
        /// <summary>
        /// Information related to a medical encounter.
        /// </summary>
        /// 
        /// <param name="typeSpecificXml">
        /// The XML to get the medical encounter data from.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the first node in <paramref name="typeSpecificXml"/> is not
        /// a encounter node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator itemNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("encounter");

            Validator.ThrowInvalidIfNull(itemNav, "EncounterUnexpectedNode");

            // when
            _when =
                XPathHelper.GetOptNavValue<HealthServiceDateTime>(itemNav,"when");

            // type
            _type =
                XPathHelper.GetOptNavValue<CodableValue>(itemNav, "type");

            // reason
            _reason =
                XPathHelper.GetOptNavValue(itemNav, "reason");

            // duration
            _duration =
                XPathHelper.GetOptNavValue<DurationValue>(itemNav,"duration");

            // consent-granted
            _consentGranted =
                XPathHelper.GetOptNavValueAsBool(itemNav,"consent-granted");

            // facility
            _facility =
                XPathHelper.GetOptNavValue<Organization>(itemNav, "facility");
        }
        /// <summary>
        /// Populates this medication fill instance from the data in the XML.
        /// </summary>
        /// 
        /// <param name="typeSpecificXml">
        /// The XML to get the medication fill data from.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the first node in <paramref name="typeSpecificXml"/> is not
        /// a medication-fill node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator itemNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("medication-fill");

            Validator.ThrowInvalidIfNull(itemNav, "MedicationFillUnexpectedNode");

            _name = new CodableValue();
            _name.ParseXml(itemNav.SelectSingleNode("name"));

            _dateFilled =
                XPathHelper.GetOptNavValue<ApproximateDateTime>(itemNav, "date-filled");

            _daysSupply =
                XPathHelper.GetOptNavValueAsInt(itemNav, "days-supply");

            _nextRefillDate =
                XPathHelper.GetOptNavValue<HealthServiceDate>(itemNav, "next-refill-date");

            _refillsLeft =
                XPathHelper.GetOptNavValueAsInt(itemNav, "refills-left");

            _pharmacy =
                XPathHelper.GetOptNavValue<Organization>(itemNav, "pharmacy");

            _prescriptionNumber =
                XPathHelper.GetOptNavValue(itemNav, "prescription-number");

            _lotNumber =
                XPathHelper.GetOptNavValue(itemNav, "lot-number");
        }