Exemple #1
0
        /// <summary>
        /// Converts the specified string representation of an NHS identifier to its correctly-formatted equivalent.
        /// </summary>
        /// <remarks>
        /// Throws an exception if the string cannot be parsed.
        /// </remarks>
        /// <param name="value">A string containing an NHS identifier to be parsed. </param>
        /// <returns>An NHS identifier constructed from the value parameter. </returns>
        public static NhsNumber ParseNhsNumber(string value)
        {
            string parsedValue;

            NhsNumberParseResult result = NhsNumber.TryParseNhsNumber(value, out parsedValue);

            if (result == NhsNumberParseResult.Success)
            {
                return(new NhsNumber(parsedValue));
            }
            else
            {
                if (result == NhsNumberParseResult.FailedAlphaCharacterContent)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageAlphaChars, value));
                }
                else if (result == NhsNumberParseResult.FailedChecksum)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageChecksum, value));
                }
                else if (result == NhsNumberParseResult.FailedDigitCount)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitCount, value));
                }
                else if (result == NhsNumberParseResult.FailedAllSameDigits)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitsAllSame, value));
                }
                else
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageUnknownError, value));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Validates whether a given identifier is a valid NhsNumber.
        /// </summary>
        /// <remarks>ArgumentException will be raised if the IdentifierType is NhsNumber and Text is not a valid NhsNumber</remarks>
        private void Validate()
        {
            if (this.IdentifierType == IdentifierType.NhsNumber && string.Compare(this.Text, PatientBannerControl.PatientBannerResources.DefaultIdentifierValue, StringComparison.CurrentCultureIgnoreCase) != 0)
            {
                try
                {
                    NhsNumber.ParseNhsNumber(this.Text);
                }
                catch (ArgumentException)
                {
                    this.lastIdentifierValid = false;
                    throw;
                }
            }

            this.lastIdentifierValid = true;
        }
Exemple #3
0
        /// <summary>
        /// Parses/sets the NHS Number.
        /// </summary>
        /// <param name="nhsNumber">String to assign to the NHS Number.</param>
        private void SetNhsNumber(string nhsNumber)
        {
            // Parse the text passed in to see if meets the formatting criteria
            // If it is store the value and format it for display
            string parsedValue;

            NhsNumberParseResult result = NhsNumber.TryParseNhsNumber(nhsNumber, out parsedValue);

            if (result == NhsNumberParseResult.Success)
            {
                this.nhsNumber = parsedValue.Substring(0, 3) + " " + parsedValue.Substring(3, 3) + " " + parsedValue.Substring(6, 4);
            }
            else
            {
                if (result == NhsNumberParseResult.FailedAlphaCharacterContent)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageAlphaChars, nhsNumber));
                }
                else if (result == NhsNumberParseResult.FailedChecksum)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageChecksum, nhsNumber));
                }
                else if (result == NhsNumberParseResult.FailedDigitCount)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitCount, nhsNumber));
                }
                else if (result == NhsNumberParseResult.FailedAllSameDigits)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageDigitsAllSame, nhsNumber));
                }
                else
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, NhsNumberExceptionResources.InvalidNhsNumberMessageUnknownError, nhsNumber));
                }
            }
        }