/// <summary>
 /// Creates a new instance of the <see cref="Contact"/> class with the 
 /// specified contact information.
 /// </summary>
 /// 
 /// <param name="contactInfo">
 /// The information about the contact.
 /// </param>
 /// 
 /// <exception cref="ArgumentNullException">
 /// The <paramref name="contactInfo"/> parameter is <b>null</b>.
 /// </exception>
 /// 
 public Contact(ContactInfo contactInfo)
     : base(TypeId)
 {
     this.ContactInformation = contactInfo;
 }
        /// <summary>
        /// Populates this <see cref="Contact"/> instance from the data in the XML.
        /// </summary>
        /// 
        /// <param name="typeSpecificXml">
        /// The XML to get the contact data from.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// The first node in <paramref name="typeSpecificXml"/> is not
        /// a contact node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator contactNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("contact");

            Validator.ThrowInvalidIfNull(contactNav, "ContactInformationUnexpectedNode");

            _contactInfo = new ContactInfo();
            _contactInfo.ParseXml(contactNav.SelectSingleNode("contact"));
        }
        /// <summary>
        /// Populates this <see cref="Payer"/> instance from the data in the XML.
        /// </summary>
        /// 
        /// <param name="typeSpecificXml">
        /// The XML to get the payer data from.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// The first node in <paramref name="typeSpecificXml"/> parameter is not
        /// a payer node.
        /// </exception>
        /// 
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator payerNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("payer");

            Validator.ThrowInvalidIfNull(payerNav, "PayerUnexpectedNode");

            _planName = payerNav.SelectSingleNode("plan-name").Value;

            _coverageType =
                XPathHelper.GetOptNavValue<CodableValue>(payerNav, "coverage-type");

            XPathNavigator carrierIdNav =
                payerNav.SelectSingleNode("carrier-id");
            if (carrierIdNav != null)
            {
                _carrierId = carrierIdNav.Value;
            }

            XPathNavigator groupNumNav =
                payerNav.SelectSingleNode("group-num");
            if (groupNumNav != null)
            {
                _groupNumber = groupNumNav.Value;
            }

            XPathNavigator planCodeNav =
                payerNav.SelectSingleNode("plan-code");
            if (planCodeNav != null)
            {
                _planCode = planCodeNav.Value;
            }

            XPathNavigator subscriberIdNav =
                payerNav.SelectSingleNode("subscriber-id");
            if (subscriberIdNav != null)
            {
                _subscriberId = subscriberIdNav.Value;
            }

            XPathNavigator personCodeNav =
                payerNav.SelectSingleNode("person-code");
            if (personCodeNav != null)
            {
                _personCode = personCodeNav.Value;
            }

            XPathNavigator subscriberNameNav =
                payerNav.SelectSingleNode("subscriber-name");
            if (subscriberNameNav != null)
            {
                _subscriberName = subscriberNameNav.Value;
            }

            XPathNavigator subscriberDobNav =
                payerNav.SelectSingleNode("subscriber-dob");
            if (subscriberDobNav != null)
            {
                _subscriberDateOfBirth = new HealthServiceDateTime();
                _subscriberDateOfBirth.ParseXml(subscriberDobNav);
            }

            XPathNavigator isPrimaryNav =
                payerNav.SelectSingleNode("is-primary");
            if (isPrimaryNav != null)
            {
                _isPrimary = isPrimaryNav.ValueAsBoolean;
            }

            XPathNavigator expirationDateNav =
                payerNav.SelectSingleNode("expiration-date");
            if (expirationDateNav != null)
            {
                _expirationDate = new HealthServiceDateTime();
                _expirationDate.ParseXml(expirationDateNav);
            }

            XPathNavigator contactNav =
                payerNav.SelectSingleNode("contact");
            if (contactNav != null)
            {
                _contact = new ContactInfo();
                _contact.ParseXml(contactNav);
            }
        }
        /// <summary>
        /// Populates this Person instance from the data in the XML.
        /// </summary>
        /// 
        /// <param name="navigator">
        /// The XML containing the goal information.
        /// </param>
        /// 
        /// <exception cref="InvalidOperationException">
        /// The first node in <paramref name="navigator"/> is not
        /// a person node.
        /// </exception>
        /// 
        public override void ParseXml(XPathNavigator navigator)
        {
            Validator.ThrowIfNavigatorNull(navigator);

            // <name>
            _name = new Name();
            _name.ParseXml(navigator.SelectSingleNode("name"));

            // <organization>
            XPathNavigator orgNav =
                navigator.SelectSingleNode("organization");

            if (orgNav != null)
            {
                _organization = orgNav.Value;
            }

            // <professional-training>
            XPathNavigator professionalTrainingNav =
                navigator.SelectSingleNode("professional-training");

            if (professionalTrainingNav != null)
            {
                _professionalTraining = professionalTrainingNav.Value;
            }

            // <id>
            XPathNavigator idNav =
                navigator.SelectSingleNode("id");

            if (idNav != null)
            {
                _id = idNav.Value;
            }

            // <contact>
            XPathNavigator contactNav =
                navigator.SelectSingleNode("contact");

            if (contactNav != null)
            {
                _contactInfo = new ContactInfo();
                _contactInfo.ParseXml(contactNav);
            }

            // <type>
            XPathNavigator typeNav =
                navigator.SelectSingleNode("type");

            if (typeNav != null)
            {
                _personType = new CodableValue();
                _personType.ParseXml(navigator.SelectSingleNode("type"));
            }
        }
        /// <summary>
        /// Populates the organization information from the 
        /// specified XML.
        /// </summary>
        /// 
        /// <param name="navigator">
        /// The XML containing the organization information.
        /// </param>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="navigator"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="UriFormatException">
        /// If <paramref name="Website"/> is empty. 
        /// -or-
        /// The scheme specified in <paramref name="Website"/> is invalid.
        /// -or-
        /// <paramref name="Website"/> contains too many slashes.
        /// -or-
        /// The host name specified in <paramref name="Website"/> is invalid.
        /// -or-
        /// The file name specified in <paramref name="Website"/> is invalid.
        /// </exception>
        /// 
        public override void ParseXml(XPathNavigator navigator)
        {
            Validator.ThrowIfNavigatorNull(navigator);

            _name = navigator.SelectSingleNode("name").Value;

            _contact = XPathHelper.GetOptNavValue<ContactInfo>(
                navigator,
                "contact");

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

            XPathNavigator websiteNav =
                navigator.SelectSingleNode("website");

            if (websiteNav != null)
            {
                _website = new Uri(websiteNav.Value, UriKind.RelativeOrAbsolute);
            }
        }