/// <summary>
        /// We have to run the reference lab result matches after the notifications have been imported into the main db,
        /// since the matches are stored externally - we need to know what the generated NTBS ids are beforehand.
        /// </summary>
        private async Task ImportReferenceLabResultsAsync(PerformContext context,
                                                          string requestId,
                                                          IList <Notification> notifications,
                                                          ImportResult importResult)
        {
            var legacyIds = notifications.Select(n => n.ETSID);
            var matches   = await _migrationRepository.GetReferenceLaboratoryMatches(legacyIds);

            foreach (var(legacyId, referenceLaboratoryNumber) in matches)
            {
                var notificationId = notifications.Single(n => n.ETSID == legacyId).NotificationId;
                var success        = await _specimenService.MatchSpecimenAsync(notificationId,
                                                                               referenceLaboratoryNumber,
                                                                               AuditService.AuditUserSystem,
                                                                               isMigrating : true);

                if (!success)
                {
                    var error = $"Failed to set the specimen match for Notification: {notificationId}, reference lab number: {referenceLaboratoryNumber}. " +
                                $"The notification is already imported, manual intervention needed!";
                    _logger.LogError(context, requestId, error);
                    importResult.AddNotificationError(legacyId, error);
                }
            }
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                await PreparePageForGetAsync();

                return(Page());
            }

            var(laboratoryReferenceNumber, value) = PotentialMatchSelections.Single();
            int notificationId;

            if (value.NotificationIdIsManual)
            {
                notificationId = await ValidateManualMatch(value);
            }
            else
            {
                notificationId = await ValidateCandidateMatch(value);
            }

            if (!ModelState.IsValid)
            {
                await PreparePageForGetAsync();

                return(Page());
            }

            await FetchUnmatchedSpecimensAsync();

            if (UnmatchedSpecimens.All(specimen => specimen.ReferenceLaboratoryNumber != laboratoryReferenceNumber))
            {
                throw new DataException(
                          "When performing a specimen match via `/LabResults`, the chosen specimen reference " +
                          "number was either previously matched, or unavailable to the user.");
            }

            var userName = User.FindFirstValue(ClaimTypes.Upn);
            await _specimenService.MatchSpecimenAsync(notificationId, laboratoryReferenceNumber, userName);

            AddTempDataForSuccessfulMessage(notificationId, laboratoryReferenceNumber);

            // Explicit path to the current page to avoid persisting any 'scroll to id' path values
            return(RedirectToPage("/LabResults/Index"));
        }