public async Task <ContentResult> OnPostValidatePostcode([FromBody] PostcodeValidationModel validationData)
        {
            var notification = await NotificationRepository.GetNotificationAsync(NotificationId);

            var foundPostcode = await _postcodeService.FindPostcodeAsync(validationData.Postcode);

            var propertyValueTuples = new List <(string, object)>
            {
                ("PostcodeToLookup", foundPostcode?.Postcode),
                ("Postcode", validationData.Postcode)
            };

            return(ValidationService.GetMultiplePropertiesValidationResult <PatientDetails>(
                       propertyValueTuples,
                       validationData.ShouldValidateFull,
                       notification.IsLegacy));
        }
        private async Task <PatientDetails> ExtractPatientDetails(MigrationDbNotification notification)
        {
            var addressRaw = string.Join(" \n",
                                         notification.Line1,
                                         notification.Line2,
                                         notification.City,
                                         notification.County);
            var address = RemoveCharactersNotIn(
                ValidationRegexes.CharacterValidationWithNumbersForwardSlashAndNewLine,
                addressRaw);
            var givenName      = RemoveCharactersNotIn(ValidationRegexes.CharacterValidation, notification.GivenName);
            var familyName     = RemoveCharactersNotIn(ValidationRegexes.CharacterValidation, notification.FamilyName);
            var localPatientId = RemoveCharactersNotIn(
                ValidationRegexes.CharacterValidationWithNumbersForwardSlashExtended,
                notification.LocalPatientId);

            var details = new PatientDetails();

            details.FamilyName        = familyName;
            details.GivenName         = givenName;
            details.NhsNumber         = notification.NhsNumber;
            details.NhsNumberNotKnown = notification.NhsNumberNotKnown == 1 || notification.NhsNumber == null;
            details.Dob            = notification.DateOfBirth;
            details.YearOfUkEntry  = notification.UkEntryYear;
            details.UkBorn         = notification.UkBorn;
            details.CountryId      = notification.BirthCountryId ?? Countries.UnknownId;
            details.LocalPatientId = localPatientId;
            details.Postcode       = notification.Postcode;
            details.PostcodeLookup = await _postcodeService.FindPostcodeAsync(notification.Postcode);

            details.PostcodeToLookup = details.PostcodeLookup?.Postcode;
            details.NoFixedAbode     = notification.NoFixedAbode == 1;
            details.Address          = address;
            details.EthnicityId      = notification.NtbsEthnicGroupId ?? Ethnicities.NotStatedId;
            details.SexId            = notification.NtbsSexId ?? Sexes.UnknownId;
            details.OccupationId     = notification.NtbsOccupationId;
            details.OccupationOther  = RemoveCharactersNotIn(
                ValidationRegexes.CharacterValidationWithNumbersForwardSlashExtended,
                notification.OccupationFreetext);

            ForceValidNhsNumber(details);

            return(details);
        }
Exemple #3
0
        protected async Task FindAndSetPostcodeAsync <T>(IPostcodeService postcodeService, T model) where T : IHasPostcode
        {
            var foundPostcode = await postcodeService.FindPostcodeAsync(model.Postcode);

            model.PostcodeToLookup = foundPostcode?.Postcode;
        }