/// <summary>
        /// Writes the blood pressure data to the specified XmlWriter.
        /// </summary>
        ///
        /// <param name="writer">
        /// The XmlWriter to write the blood pressure data to.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="writer"/> is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="ThingSerializationException">
        /// The <see cref="Systolic"/> or <see cref="Diastolic"/> property has not been set.
        /// </exception>
        ///
        public override void WriteXml(XmlWriter writer)
        {
            Validator.ThrowIfWriterNull(writer);
            Validator.ThrowSerializationIfNull(_systolic, Resources.BPSystolicNotSet);
            Validator.ThrowSerializationIfNull(_diastolic, Resources.BPDiastolicNotSet);

            // <blood-pressure>
            writer.WriteStartElement("blood-pressure");

            // <when>
            _when.WriteXml("when", writer);

            writer.WriteElementString("systolic", _systolic.ToString());

            writer.WriteElementString("diastolic", _diastolic.ToString());

            if (_pulse != null)
            {
                writer.WriteElementString("pulse", _pulse.ToString());
            }

            if (_irregularHeartbeatDetected != null)
            {
                writer.WriteElementString(
                    "irregular-heartbeat",
                    SDKHelper.XmlFromBool((bool)_irregularHeartbeatDetected));
            }

            // </bp>
            writer.WriteEndElement();
        }
        /// <summary>
        /// Retrieves lists of vocabulary items for the specified
        /// vocabularies and culture.
        /// </summary>
        ///
        /// <param name="connection">
        /// The connection to use for this operation. The connection
        /// must have application capability.
        /// </param>
        ///
        /// <param name="vocabularyKeys">
        /// A list of keys identifying the requested vocabularies.
        /// </param>
        ///
        /// <param name="cultureIsFixed">
        /// HealthVault looks for the vocabulary items for the culture info
        /// specified using <see cref="HealthServiceConnection.Culture"/>.
        /// If <paramref name="cultureIsFixed"/> is set to <b>false</b> and if
        /// items are not found for the specified culture, items for the
        /// default fallback culture are returned. If
        /// <paramref name="cultureIsFixed"/> is set to <b>true</b>,
        /// fallback will not occur, and if items are not found for the
        /// specified culture, empty strings are returned.
        /// </param>
        ///
        /// <returns>
        /// The specified vocabularies and their items, or empty strings.
        /// </returns>
        ///
        /// <exception cref="ArgumentException">
        /// The <paramref name="vocabularyKeys"/> list is empty.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="vocabularyKeys"/> list is <b>null</b>
        /// or contains a <b>null</b> entry.
        /// </exception>
        ///
        /// <exception cref="HealthServiceException">
        /// There is an error in the server request.
        /// <br></br>
        /// -Or-
        /// <br></br>
        /// One of the requested vocabularies is not found on the server.
        /// <br></br>
        /// -Or-
        /// <br></br>
        /// One of the requested vocabularies does not contain representations
        /// for its items for the specified culture when
        /// <paramref name="cultureIsFixed"/> is <b>true</b>.
        /// <br></br>
        /// -Or-
        /// <br></br>
        /// There is an error loading the vocabulary.
        /// </exception>
        ///
        public virtual async Task <ReadOnlyCollection <Vocabulary> > GetVocabularyAsync(
            IHealthVaultConnection connection,
            IList <VocabularyKey> vocabularyKeys,
            bool cultureIsFixed)
        {
            Validator.ThrowIfArgumentNull(vocabularyKeys, nameof(vocabularyKeys), Resources.VocabularyKeysNullOrEmpty);

            if (vocabularyKeys.Count == 0)
            {
                throw new ArgumentException(Resources.VocabularyKeysNullOrEmpty, nameof(vocabularyKeys));
            }

            var method        = HealthVaultMethods.GetVocabulary;
            int methodVersion = 2;

            StringBuilder     requestParameters = new StringBuilder(256);
            XmlWriterSettings settings          = SDKHelper.XmlUnicodeWriterSettings;

            settings.OmitXmlDeclaration = true;
            settings.ConformanceLevel   = ConformanceLevel.Fragment;

            using (XmlWriter writer = XmlWriter.Create(requestParameters, settings))
            {
                writer.WriteStartElement("vocabulary-parameters");

                for (int i = 0; i < vocabularyKeys.Count; i++)
                {
                    Validator.ThrowIfArgumentNull(vocabularyKeys[i], "vocabularyKeys[i]", Resources.VocabularyKeysNullOrEmpty);

                    vocabularyKeys[i].WriteXml(writer);
                }

                writer.WriteElementString(
                    "fixed-culture",
                    SDKHelper.XmlFromBool(cultureIsFixed));

                writer.WriteEndElement();
                writer.Flush();
            }

            string parameters = requestParameters.ToString();

            HealthServiceResponseData responseData = await connection.ExecuteAsync(method, methodVersion, parameters).ConfigureAwait(false);

            ReadOnlyCollection <Vocabulary> vocabularies
                = CreateVocabulariesFromResponse(method.ToString(), responseData);

            return(vocabularies);
        }
        /// <summary>
        /// Writes the XML representation of the address into
        /// the specified XML writer.
        /// </summary>
        ///
        /// <param name="nodeName">
        /// The name of the outer node for the address.
        /// </param>
        ///
        /// <param name="writer">
        /// The XML writer into which the address should be
        /// written.
        /// </param>
        ///
        /// <exception cref="ArgumentException">
        /// The <paramref name="nodeName"/> parameter is <b>null</b> or empty.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="writer"/> parameter is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="ThingSerializationException">
        /// The <see cref="Street"/> property is empty or <see cref="City"/>,
        /// <see cref="Country"/>, or <see cref="PostalCode"/> property has not been set.
        /// </exception>
        ///
        public override void WriteXml(string nodeName, XmlWriter writer)
        {
            Validator.ThrowIfStringNullOrEmpty(nodeName, nameof(nodeName));
            Validator.ThrowIfArgumentNull(writer, nameof(writer), Resources.WriteXmlNullWriter);

            if (_street.Count == 0)
            {
                throw new ThingSerializationException(Resources.AddressStreetNotSet);
            }

            Validator.ThrowSerializationIfNull(_city, Resources.AddressCityNotSet);
            Validator.ThrowSerializationIfNull(_country, Resources.AddressCountryNotSet);
            Validator.ThrowSerializationIfNull(_postalCode, Resources.AddressPostalCodeNotSet);

            writer.WriteStartElement(nodeName);

            if (!string.IsNullOrEmpty(_description))
            {
                writer.WriteElementString("description", _description);
            }

            if (_isPrimary != null)
            {
                writer.WriteElementString(
                    "is-primary",
                    SDKHelper.XmlFromBool((bool)_isPrimary));
            }

            foreach (string street in _street)
            {
                writer.WriteElementString("street", street);
            }

            writer.WriteElementString("city", _city);
            if (!string.IsNullOrEmpty(_state))
            {
                writer.WriteElementString("state", _state);
            }

            writer.WriteElementString("postcode", _postalCode);
            writer.WriteElementString("country", _country);

            XmlWriterHelper.WriteOptString(writer, "county", _county);

            writer.WriteEndElement();
        }
        /// <summary>
        /// Writes the language to the specified XML writer.
        /// </summary>
        ///
        /// <param name="nodeName">
        /// The name of the outer element for the language.
        /// </param>
        ///
        /// <param name="writer">
        /// The XmlWriter to write the language to.
        /// </param>
        ///
        /// <exception cref="ArgumentException">
        /// The <paramref name="nodeName"/> parameter is <b>null</b> or empty.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="writer"/> parameter is <b>null</b>.
        /// </exception>
        ///
        public override void WriteXml(string nodeName, XmlWriter writer)
        {
            Validator.ThrowIfStringNullOrEmpty(nodeName, "nodeName");
            Validator.ThrowIfWriterNull(writer);

            // null indicates uninitialized
            if (_language.Text != null)
            {
                writer.WriteStartElement(nodeName);

                _language.WriteXml("language", writer);

                writer.WriteElementString(
                    "is-primary",
                    SDKHelper.XmlFromBool(_isPrimary));

                writer.WriteEndElement();
            }
        }
        /// <summary>
        /// Writes the XML representation of the MessageAttachment into
        /// the specified XML writer.
        /// </summary>
        ///
        /// <param name="nodeName">
        /// The name of the outer node for the medical image study series.
        /// </param>
        ///
        /// <param name="writer">
        /// The XML writer into which the MessageAttachment should be
        /// written.
        /// </param>
        ///
        /// <exception cref="ArgumentException">
        /// If <paramref name="nodeName"/> parameter is <b>null</b> or empty.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="writer"/> parameter is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="ThingSerializationException">
        /// If <see cref="Name"/> is <b>null</b> or empty or contains only whitespace.
        /// If <see cref="BlobName"/> is <b>null</b> or empty or contains only whitespace.
        /// </exception>
        ///
        public override void WriteXml(string nodeName, XmlWriter writer)
        {
            Validator.ThrowIfStringNullOrEmpty(nodeName, nameof(nodeName));
            Validator.ThrowIfWriterNull(writer);

            if (string.IsNullOrEmpty(_name) || string.IsNullOrEmpty(_name.Trim()))
            {
                throw new ThingSerializationException(Resources.MessageNameMandatory);
            }

            if (string.IsNullOrEmpty(_blobName) || string.IsNullOrEmpty(_blobName.Trim()))
            {
                throw new ThingSerializationException(Resources.BlobNameMandatory);
            }

            writer.WriteStartElement("attachments");

            writer.WriteElementString("name", _name);
            writer.WriteElementString("blob-name", _blobName);
            writer.WriteElementString("inline-display", SDKHelper.XmlFromBool(_inlineDisplay));
            XmlWriterHelper.WriteOptString(writer, "content-id", _contentId);
            writer.WriteEndElement();
        }
Esempio n. 6
0
        /// <summary>
        /// Writes the XML representation of the telephone number into
        /// the specified XML writer.
        /// </summary>
        ///
        /// <param name="nodeName">
        /// The name of the outer node for the phone.
        /// </param>
        ///
        /// <param name="writer">
        /// The XML writer into which the telephone number should be
        /// written.
        /// </param>
        ///
        /// <exception cref="ArgumentException">
        /// The <paramref name="nodeName"/> parameter is <b>null</b> or empty.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="writer"/> parameter is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="ThingSerializationException">
        /// The <see cref="Number"/> property has not been set.
        /// </exception>
        ///
        public override void WriteXml(string nodeName, XmlWriter writer)
        {
            Validator.ThrowIfStringNullOrEmpty(nodeName, "nodeName");
            Validator.ThrowIfWriterNull(writer);
            Validator.ThrowSerializationIfNull(_number, Resources.PhoneNumberNotSet);

            writer.WriteStartElement(nodeName);

            if (!string.IsNullOrEmpty(_description))
            {
                writer.WriteElementString("description", _description);
            }

            if (_isPrimary != null)
            {
                writer.WriteElementString(
                    "is-primary",
                    SDKHelper.XmlFromBool((bool)_isPrimary));
            }

            writer.WriteElementString("number", _number);

            writer.WriteEndElement();
        }
Esempio n. 7
0
        internal void WriteXml(string nodeName, XmlWriter writer)
        {
            writer.WriteStartElement(nodeName);

            writer.WriteAttributeString("id", Id.ToString());

            if (Location != null)
            {
                writer.WriteAttributeString("location-country", Location.Country);
                if (!string.IsNullOrEmpty(Location.StateProvince))
                {
                    writer.WriteAttributeString("location-state-province", Location.StateProvince);
                }
            }

            writer.WriteAttributeString(
                "record-custodian",
                XmlConvert.ToString(_custodian));

            writer.WriteAttributeString(
                "rel-type",
                XmlConvert.ToString((int)_relationshipType));

            if (!string.IsNullOrEmpty(_relationshipName))
            {
                writer.WriteAttributeString(
                    "rel-name",
                    _relationshipName);
            }

            writer.WriteAttributeString(
                "auth-expires",
                DateAuthorizationExpires == null ? "9999-12-31T23:59:59.999Z" : SDKHelper.XmlFromInstant(DateAuthorizationExpires.Value));

            writer.WriteAttributeString(
                "auth-expired",
                SDKHelper.XmlFromBool(_authExpired));

            if (!string.IsNullOrEmpty(_displayName))
            {
                writer.WriteAttributeString(
                    "display-name",
                    _displayName);
            }

            writer.WriteAttributeString(
                "state",
                State.ToString());

            writer.WriteAttributeString(
                "date-created",
                SDKHelper.XmlFromInstant(DateCreated));

            if (QuotaInBytes.HasValue)
            {
                writer.WriteAttributeString(
                    "max-size-bytes",
                    XmlConvert.ToString(QuotaInBytes.Value));
            }

            if (QuotaUsedInBytes.HasValue)
            {
                writer.WriteAttributeString(
                    "size-bytes",
                    XmlConvert.ToString(QuotaUsedInBytes.Value));
            }

            writer.WriteAttributeString(
                "app-record-auth-action",
                HealthRecordAuthorizationStatus.ToString());

            writer.WriteAttributeString(
                "app-specific-record-id",
                ApplicationSpecificRecordId);

            writer.WriteAttributeString(
                "date-updated",
                SDKHelper.XmlFromInstant(DateUpdated));

            writer.WriteValue(_name);

            writer.WriteEndElement();
        }
Esempio n. 8
0
        /// <summary>
        /// Constructs the XML for the filter group which is used in the
        /// "GetThings" request.
        /// </summary>
        ///
        /// <param name="writer">
        /// The Xml writer to write the filter group XML to.
        /// </param>
        ///
        internal void AddFilterXml(XmlWriter writer)
        {
            // Open with a group tag
            writer.WriteStartElement("group");

            if (!string.IsNullOrEmpty(Name))
            {
                // Add the name attribute to the group tag
                writer.WriteAttributeString("name", Name);
            }

            if (MaxItemsReturned > 0)
            {
                // Add the max attribute to the group tag
                writer.WriteAttributeString(
                    "max",
                    MaxItemsReturned.ToString(CultureInfo.InvariantCulture));
            }

            if (MaxFullItemsReturnedPerRequest >= 0)
            {
                // Add the max-full attribute to the group tag
                writer.WriteAttributeString(
                    "max-full",
                    MaxFullItemsReturnedPerRequest.ToString(CultureInfo.InvariantCulture));
            }

            foreach (Guid id in ItemIds)
            {
                // Add the <id> tag to the filter group
                writer.WriteElementString("id", id.ToString());
            }

            foreach (ThingKey key in ItemKeys)
            {
                // Add the <key> tag to the filter group
                writer.WriteStartElement("key");
                writer.WriteAttributeString(
                    "version-stamp", key.VersionStamp.ToString());
                writer.WriteValue(key.Id.ToString());
                writer.WriteEndElement();
            }

            foreach (string thingId in ClientItemIds)
            {
                // Add the <id> tag to the filter group
                writer.WriteElementString("client-thing-id", thingId);
            }

            AddFilterSection(writer);

            View.AddViewXml(writer);

            if (_currentVersionOnly.HasValue)
            {
                writer.WriteElementString(
                    "current-version-only",
                    SDKHelper.XmlFromBool(_currentVersionOnly.Value));
            }

            if (Intentions != ItemRetrievalIntentions.Unspecified)
            {
                writer.WriteStartElement("intents");

                // view
                if (Intentions.HasFlag(ItemRetrievalIntentions.View))
                {
                    writer.WriteElementString("intent", "view");
                }

                // download
                if (Intentions.HasFlag(ItemRetrievalIntentions.Download))
                {
                    writer.WriteElementString("intent", "download");
                }

                // transmit
                if (Intentions.HasFlag(ItemRetrievalIntentions.Transmit))
                {
                    writer.WriteElementString("intent", "transmit");
                }

                writer.WriteEndElement();
            }

            if (OrderByClauses.Count > 0)
            {
                writer.WriteStartElement("order-by");
                foreach (var orderByClause in OrderByClauses)
                {
                    writer.WriteStartElement("order-by-property");
                    writer.WriteAttributeString("type-id", orderByClause.ThingTypeId.ToString());
                    writer.WriteAttributeString("property-name", orderByClause.Name);
                    writer.WriteAttributeString("direction", orderByClause.Direction.ToString());
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }

            // Close the group tag
            writer.WriteEndElement();
        }
Esempio n. 9
0
        /// <summary>
        /// Writes the payer data to the specified XmlWriter.
        /// </summary>
        ///
        /// <param name="writer">
        /// The XmlWriter to write the payer data to.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="writer"/> is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="ThingSerializationException">
        /// The <see cref="PlanName"/> parameter has not been set.
        /// </exception>
        ///
        public override void WriteXml(XmlWriter writer)
        {
            Validator.ThrowIfWriterNull(writer);
            Validator.ThrowSerializationIfNull(_planName, Resources.PayerPlanNameNotSet);

            // <payer>
            writer.WriteStartElement("payer");

            writer.WriteElementString("plan-name", _planName);

            // <coverage-type>
            XmlWriterHelper.WriteOpt(
                writer,
                "coverage-type",
                _coverageType);

            if (!string.IsNullOrEmpty(_carrierId))
            {
                writer.WriteElementString("carrier-id", _carrierId);
            }

            if (!string.IsNullOrEmpty(_groupNumber))
            {
                writer.WriteElementString("group-num", _groupNumber);
            }

            if (!string.IsNullOrEmpty(_planCode))
            {
                writer.WriteElementString("plan-code", _planCode);
            }

            if (!string.IsNullOrEmpty(_subscriberId))
            {
                writer.WriteElementString("subscriber-id", _subscriberId);
            }

            if (!string.IsNullOrEmpty(_personCode))
            {
                writer.WriteElementString("person-code", _personCode);
            }

            if (!string.IsNullOrEmpty(_subscriberName))
            {
                writer.WriteElementString("subscriber-name", _subscriberName);
            }

            if (_subscriberDateOfBirth != null)
            {
                _subscriberDateOfBirth.WriteXml("subscriber-dob", writer);
            }

            if (_isPrimary != null)
            {
                writer.WriteElementString(
                    "is-primary",
                    SDKHelper.XmlFromBool((bool)_isPrimary));
            }

            if (_expirationDate != null)
            {
                _expirationDate.WriteXml("expiration-date", writer);
            }

            if (_contact != null)
            {
                _contact.WriteXml("contact", writer);
            }

            // </payer>
            writer.WriteEndElement();
        }
Esempio n. 10
0
        internal string GetRequestParameters(Guid appId)
        {
            StringBuilder     result   = new StringBuilder();
            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;

            using (XmlWriter writer = XmlWriter.Create(result, settings))
            {
                if (appId != Guid.Empty)
                {
                    writer.WriteElementString("id", appId.ToString());
                }

                CultureSpecificNames.AppendLocalizedElements(writer, "name");

                if (PublicKeys.Count > 0)
                {
                    writer.WriteStartElement("public-keys");

                    foreach (byte[] publicKey in PublicKeys)
                    {
                        string hexString = BitConverter.ToString(publicKey);
                        hexString = hexString.Replace("-", string.Empty);

                        writer.WriteElementString("public-key", hexString);
                    }

                    writer.WriteEndElement();
                }

                if (OnlineBaseAuthorizations.Count > 0)
                {
                    writer.WriteStartElement("person-online-base-auth");
                    writer.WriteRaw(AuthorizationRule.GetRulesXml(OnlineBaseAuthorizations));
                    writer.WriteEndElement();
                }

                if (OfflineBaseAuthorizations.Count > 0)
                {
                    writer.WriteStartElement("person-offline-base-auth");
                    writer.WriteRaw(AuthorizationRule.GetRulesXml(OfflineBaseAuthorizations));
                    writer.WriteEndElement();
                }

                if (CallableMethods.Count > 0)
                {
                    string methodString = string.Empty;
                    bool   methodAdded  = false;
                    foreach (HealthVaultMethods method in CallableMethods)
                    {
                        if (methodAdded)
                        {
                            methodString = methodString + "," + method;
                        }
                        else
                        {
                            methodString = method.ToString();
                            methodAdded  = true;
                        }
                    }

                    writer.WriteElementString("methods", methodString);
                }

                if (ActionUrl != null)
                {
                    writer.WriteElementString("action-url", ActionUrl.OriginalString);
                }

                CultureSpecificDescriptions.AppendLocalizedElements(
                    writer, "description");

                CultureSpecificAuthorizationReasons.AppendLocalizedElements(
                    writer, "auth-reason");

                if (!string.IsNullOrEmpty(DomainName))
                {
                    writer.WriteElementString("domain-name", DomainName);
                }

                LargeLogo?.AppendRequestParameters(writer, "large-logo", "logo");

                SmallLogo?.AppendRequestParameters(writer, "small-logo", "logo");

                if ((ConfigurationOptions & ApplicationOptions.PersistentTokensAllowed) ==
                    ApplicationOptions.PersistentTokensAllowed &&
                    PersistentTokenTtlInSeconds != null)
                {
                    writer.WriteStartElement("persistent-tokens");

                    writer.WriteElementString("enabled", "true");
                    writer.WriteElementString("token-ttl-seconds", PersistentTokenTtlInSeconds.Value.ToString());

                    writer.WriteEndElement();
                }

                PrivacyStatement?.AppendRequestParameters(writer, "privacy-statement", "statement");

                TermsOfUse?.AppendRequestParameters(writer, "terms-of-use", "statement");

                if ((ConfigurationOptions & ApplicationOptions.ApplicationAuthorizationRequired) ==
                    ApplicationOptions.ApplicationAuthorizationRequired)
                {
                    writer.WriteElementString("app-auth-required", "true");
                }

                if ((ConfigurationOptions & ApplicationOptions.RestrictApplicationUsers) == ApplicationOptions.RestrictApplicationUsers)
                {
                    writer.WriteElementString("restrict-app-users", "true");
                }

                if ((ConfigurationOptions & ApplicationOptions.PublishApplication) ==
                    ApplicationOptions.PublishApplication)
                {
                    writer.WriteElementString("is-published", "true");
                }

                DtcSuccessMessage?.AppendRequestParameters(
                    writer, "dtc-success-message", "statement");

                if (ApplicationAttributes.Count != 0)
                {
                    writer.WriteStartElement("app-attributes");
                    foreach (string attribute in ApplicationAttributes)
                    {
                        if (!string.IsNullOrEmpty(attribute))
                        {
                            writer.WriteElementString("app-attribute", attribute);
                        }
                    }

                    writer.WriteEndElement();
                }

                if (!string.IsNullOrEmpty(ValidIPPrefixes))
                {
                    writer.WriteElementString("valid-ip-prefixes", ValidIPPrefixes);
                }

                if (VocabularyAuthorizations.Count > 0)
                {
                    writer.WriteStartElement("vocabulary-authorizations");
                    foreach (VocabularyAuthorization auth in VocabularyAuthorizations)
                    {
                        auth.WriteXml(writer);
                    }

                    writer.WriteEndElement();
                }

                SupportedRecordLocations.WriteXml(writer, "supported-record-locations");

                if (SupportedHealthVaultInstances.Count > 0 || SupportAllHealthVaultInstances)
                {
                    writer.WriteStartElement("supported-instances");

                    if (SupportAllHealthVaultInstances)
                    {
                        writer.WriteAttributeString("support-all-instances", SDKHelper.XmlFromBool(SupportAllHealthVaultInstances));
                    }
                    else
                    {
                        foreach (string instanceId in SupportedHealthVaultInstances)
                        {
                            writer.WriteElementString("instance-id", instanceId);
                        }
                    }

                    writer.WriteEndElement();
                }

                if (MeaningfulUseSources.Count > 0)
                {
                    writer.WriteStartElement("meaningful-use-sources");
                    foreach (string source in MeaningfulUseSources)
                    {
                        writer.WriteElementString("source", source);
                    }

                    writer.WriteEndElement();
                }

                if (IsOnboardedToBdp.HasValue && IsBulkExtractionPermissionRequired.HasValue)
                {
                    writer.WriteStartElement("bulk-extraction-settings");

                    writer.WriteElementString("is-onboarded", SDKHelper.XmlFromBool(IsOnboardedToBdp.Value));
                    writer.WriteElementString("is-permission-required", SDKHelper.XmlFromBool(IsBulkExtractionPermissionRequired.Value));

                    writer.WriteEndElement();
                }
            }

            return(result.ToString());
        }
        /// <summary>
        /// Writes the asthma inhaler data to the specified XmlWriter.
        /// </summary>
        ///
        /// <param name="writer">
        /// The XmlWriter to write the asthma inhaler data to.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="writer"/> is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="ThingSerializationException">
        /// If <see cref="StartDate"/> is <b>null</b>, or
        /// <see cref="Drug"/> is <b>null</b> or empty.
        /// </exception>
        ///
        public override void WriteXml(XmlWriter writer)
        {
            Validator.ThrowIfWriterNull(writer);
            Validator.ThrowSerializationIfNull(_startDate, Resources.AsthmaInhalerStartDateNotSet);
            Validator.ThrowSerializationIfNull(_drug, Resources.AsthmaInhalerDrugNotSet);

            // <asthma-inhaler>
            writer.WriteStartElement("asthma-inhaler");

            // <drug>
            _drug.WriteXml("drug", writer);

            // <strength>
            _strength?.WriteXml("strength", writer);

            if (_purpose != InhalerPurpose.None)
            {
                // <purpose>
                writer.WriteElementString("purpose", _purpose.ToString());
            }
            else
            {
                if (!string.IsNullOrEmpty(_purposeString))
                {
                    // <purpose>
                    writer.WriteElementString("purpose", _purposeString);
                }
            }

            // <start-date>
            _startDate.WriteXml("start-date", writer);

            if (_stopDate != null)
            {
                // <stop-date>
                _stopDate.WriteXml("stop-date", writer);
            }

            if (_expirationDate != null)
            {
                // <expiration-date>
                _expirationDate.WriteXml("expiration-date", writer);
            }

            if (!string.IsNullOrEmpty(_deviceId))
            {
                // <device-id>
                writer.WriteElementString("device-id", _deviceId);
            }

            if (_initialDoses != null)
            {
                // <initial-doses>
                writer.WriteElementString(
                    "initial-doses",
                    ((int)_initialDoses).ToString(CultureInfo.InvariantCulture));
            }

            if (_minDailyDoses != null)
            {
                // <initial-doses>
                writer.WriteElementString(
                    "min-daily-doses",
                    ((int)_minDailyDoses).ToString(CultureInfo.InvariantCulture));
            }

            if (_maxDailyDoses != null)
            {
                // <max-daily-doses>
                writer.WriteElementString(
                    "max-daily-doses",
                    ((int)_maxDailyDoses).ToString(CultureInfo.InvariantCulture));
            }

            if (_canAlert != null)
            {
                writer.WriteElementString(
                    "can-alert",
                    SDKHelper.XmlFromBool((bool)_canAlert));
            }

            foreach (Alert alert in _alerts)
            {
                alert.WriteXml("alert", writer);
            }

            // </asthma-inhaler>
            writer.WriteEndElement();
        }