public async Task Run(IJobCancellationToken token) { Log.Information($"Starting data quality alerts job"); await CreateDraftAlertsInBulkAsync(); await CreateBirthCountryAlertsInBulkAsync(); await CreateClinicalDatesAlertsInBulkAsync(); await CreateClusterAlertsInBulkAsync(); await CreateDotVotAlertsInBulkAsync(); await CreateTreatmentOutcome12MonthAlertsInBulkAsync(); await CreateTreatmentOutcome24MonthAlertsInBulkAsync(); await CreateTreatmentOutcome36MonthAlertsInBulkAsync(); var possibleDuplicateNotificationIds = await _dataQualityRepository.GetNotificationIdsEligibleForDqPotentialDuplicateAlertsAsync(); foreach (var notification in possibleDuplicateNotificationIds) { var alert = new DataQualityPotentialDuplicateAlert { NotificationId = notification.NotificationId, DuplicateId = notification.DuplicateId }; await _alertService.AddUniquePotentialDuplicateAlertAsync(alert); } Log.Information($"Finished data quality alerts job"); }
public async Task DismissAllOpenAlerts_DismissesDuplicateNotificationAlert() { // Arrange const int notificationId = 1; var alert1 = new DataQualityPotentialDuplicateAlert { AlertId = 101, AlertStatus = AlertStatus.Open, }; _mockAlertRepository .Setup(s => s.GetAllOpenAlertsByNotificationId(notificationId)) .Returns(Task.FromResult(new List <Alert> { alert1 })); // Act await _alertService.DismissAllOpenAlertsForNotification(notificationId); // Assert AssertAlertClosedRecently(alert1); _mockAlertRepository.Verify(r => r.SaveAlertChangesAsync(NotificationAuditType.Edited), Times.Once); }
public async Task AddUniquePotentialDuplicateAlertAsync(DataQualityPotentialDuplicateAlert alert) { if (alert.NotificationId.HasValue) { var matchingAlert = await _alertRepository.GetDuplicateAlertByNotificationIdAndDuplicateId(alert.NotificationId.Value, alert.DuplicateId); if (matchingAlert != null) { return; } } await PopulateAndAddAlertAsync(alert); }
public async Task AddUniquePotentialDuplicateAlertAsync_CreatesAlertWithCurrentTimestamp() { // Arrange _mockAlertRepository.Setup(x => x.GetDuplicateAlertByNotificationIdAndDuplicateId(It.IsAny <int>(), It.IsAny <int>())) .Returns(Task.FromResult((DataQualityPotentialDuplicateAlert)null)); var testAlert = new DataQualityPotentialDuplicateAlert { NotificationId = 2, AlertType = AlertType.DataQualityPotientialDuplicate }; // Act await _alertService.AddUniquePotentialDuplicateAlertAsync(testAlert); // Assert Assert.Equal(DateTime.Now, testAlert.CreationDate, TimeSpan.FromSeconds(1)); }
public async Task DismissingDuplicateNotificationAlert_AlsoRemovesAlertOnDuplicateRecord() { // Arrange var alert = new DataQualityPotentialDuplicateAlert { AlertId = 101, AlertStatus = AlertStatus.Open, NotificationId = 1, DuplicateId = 2, }; var duplicateAlert = new DataQualityPotentialDuplicateAlert { AlertId = 102, AlertStatus = AlertStatus.Open, NotificationId = 2, DuplicateId = 1 }; _mockAlertRepository .Setup(s => s.GetAllOpenAlertsByNotificationId(1)) .Returns(Task.FromResult(new List <Alert> { alert })); _mockAlertRepository .Setup(s => s.GetAllOpenAlertsByNotificationId(2)) .Returns(Task.FromResult(new List <Alert> { duplicateAlert })); // Act await _alertService.DismissAllOpenAlertsForNotification(1); // Assert AssertAlertClosedRecently(alert); AssertAlertClosedRecently(duplicateAlert); }
public async Task Run(IJobCancellationToken token) { Log.Information($"Starting data quality alerts job"); await CreateDraftAlertsInBulkAsync(); await CreateBirthCountryAlertsInBulkAsync(); await CreateClinicalDatesAlertsInBulkAsync(); await CreateDotVotAlertsInBulkAsync(); await CreateTreatmentOutcome12MonthAlertsInBulkAsync(); await CreateTreatmentOutcome24MonthAlertsInBulkAsync(); await CreateTreatmentOutcome36MonthAlertsInBulkAsync(); await CreateChildECMLevelAlertsInBulkAsync(); // When we check for treatment outcome alerts above, quite a lot of notifications are being brought // into the context. (This is because the eligibility check cannot be entirely translated into SQL so // we are fetching more notifications that we really need from the database and processing them in // memory). Because Notifications have quite a lot of "owns" relationships, this is bringing quite a // large number of objects into the context. This in turn can make save operations slow. We have seen // that each duplicate alert save below was taking more than a second. Here we clear the change tracker // meaning that the context is able to handle saves much more quickly. _context.ChangeTracker.Clear(); var possibleDuplicateNotificationIds = await _dataQualityRepository.GetNotificationIdsEligibleForDqPotentialDuplicateAlertsAsync(); foreach (var notification in possibleDuplicateNotificationIds) { var alert = new DataQualityPotentialDuplicateAlert { NotificationId = notification.NotificationId, DuplicateId = notification.DuplicateId, NhsNumberMismatch = notification.NhsNumber != notification.DuplicateNhsNumber && notification.NhsNumber != null && notification.DuplicateNhsNumber != null }; await _alertService.AddUniquePotentialDuplicateAlertAsync(alert); } Log.Information($"Finished data quality alerts job"); }