Example #1
0
        private async Task CreateAlertsInBulkAsync <T>(
            GetNotificationsEligibleForDqAlertsCount getCount,
            GetMultipleNotificationsEligibleForDataQualityDraftAlerts getNotifications) where T : Alert
        {
            var notificationsForAlertsCount = await getCount();

            var offset = 0;

            while (offset < notificationsForAlertsCount)
            {
                var notificationsForAlerts = await getNotifications(CountPerBatch, offset);

                var          now      = DateTime.Now;
                List <Alert> dqAlerts = notificationsForAlerts
                                        .Select(n => {
                    T alert = (T)Activator.CreateInstance(typeof(T));
                    alert.NotificationId = n.NotificationId;
                    alert.CreationDate   = now;
                    alert.TbServiceCode  = n.HospitalDetails?.TBServiceCode;
                    if (alert.AlertType != AlertType.TransferRequest)
                    {
                        alert.CaseManagerUsername = n.HospitalDetails?.CaseManagerUsername;
                    }

                    return((Alert)alert);
                })
                                        .ToList();

                // When sourcing the alerts, we made sure to only take ones where no duplicate alerts will be created.
                // This means we are safe to just add them all and not have to ask _alertService to repeat that check
                await _alertService.AddAlertsRangeAsync(dqAlerts);

                offset += CountPerBatch;
            }
        }
        private async Task CreateAlertsInBulkAsync <T>(
            GetNotificationsEligibleForDqAlertsCount getCount,
            GetMultipleNotificationsEligibleForDataQualityAlerts getNotifications) where T : Alert
        {
            var notificationsForAlertsCount = await getCount();

            var offset = 0;

            while (offset < notificationsForAlertsCount)
            {
                var notificationsForAlerts = await getNotifications(CountPerBatch, offset);

                var now      = DateTime.Now;
                var dqAlerts = notificationsForAlerts
                               .Select(n =>
                {
                    var alert            = (T)Activator.CreateInstance(typeof(T));
                    alert.NotificationId = n.NotificationId;
                    alert.CreationDate   = now;

                    return((Alert)alert);
                })
                               .ToList();

                // When sourcing the alerts, we made sure to only take ones where no duplicate alerts will be created.
                // This means we are safe to just add them all and not have to ask _alertService to repeat that check
                await _alertService.AddAlertsRangeAsync(dqAlerts);

                offset += CountPerBatch;
            }
        }