/// <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); } } }