コード例 #1
0
        private async Task <Dictionary <string, string> > GenerateDuplicateNhsNumberNotificationUrlsAsync(string nhsNumber, NotificationGroup group)
        {
            // If NhsNumber is empty or does not pass validation - return null
            // Potential duplication of validation here so that both Server and Dynamic/JS routes to warnings
            // can use the same method.
            if (string.IsNullOrEmpty(nhsNumber) || !string.IsNullOrEmpty(
                    ValidationService.GetPropertyValidationResult <PatientDetails>("NhsNumber", nhsNumber, false).Content))
            {
                return(null);
            }

            var ntbsNhsNumberMatchesTask   = NotificationRepository.GetNotificationIdsByNhsNumberAsync(nhsNumber);
            var legacyNhsNumberMatchesTask = _migrationRepository.GetLegacyNotificationNhsNumberMatches(nhsNumber);
            var ntbsNhsNumberMatches       = await ntbsNhsNumberMatchesTask;
            var legacyNhsNumberMatches     = await legacyNhsNumberMatchesTask;
            var idsInGroup = group?.Notifications?.Select(n => n.NotificationId) ?? new List <int>();
            var filteredNtbsIdDictionary = ntbsNhsNumberMatches
                                           .Except(idsInGroup)
                                           .Where(n => n != NotificationId)
                                           .ToDictionary(
                id => id.ToString(),
                id => RouteHelper.GetNotificationPath(id, NotificationSubPaths.Overview));

            var legacyIdDictionary = legacyNhsNumberMatches.ToDictionary(
                match => $"{match.Source}: {match.OldNotificationId}",
                match => RouteHelper.GetLegacyNotificationPath(match.OldNotificationId));

            return(filteredNtbsIdDictionary.Concat(legacyIdDictionary).ToDictionary(x => x.Key, x => x.Value));
        }