public void PollForEvaluationReminderNotification() { _logger.Info("Starting the Polling Agent for Evaluation Reminder Notification."); var value = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.SendEmptyQueueEvaluationReminder); var physicians = _organizationRoleUserRepository.GetIdNamePairofUsersByRole(Roles.MedicalVendorUser); foreach (var orderedPair in physicians) { var overReadEvaluationPair = _physicianRepository.GetEventCustomerIdForOverReadPhysicianEvaluation(orderedPair.FirstValue); var evaluationPair = _physicianRepository.GetEventCustomerIdForPhysicianEvaluation(orderedPair.FirstValue); if ((value.ToLower() == bool.TrueString.ToLower()) || (evaluationPair.ItemsAvailable > 0 || overReadEvaluationPair.ItemsAvailable > 0)) { try { var createdByOrgRoleUserId = _organizationRoleUserRepository.GetOrganizationRoleUserIdsForRole((long)Roles.FranchisorAdmin).First(); var orgRoleUser = _organizationRoleUserRepository.GetOrganizationRoleUser(orderedPair.FirstValue); var evaluationReminderNotificationModel = _emailNotificationModelsFactory.GetEvaluationReminderNotificationModel(orderedPair.FirstValue); _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EvaluationReminder, EmailTemplateAlias.EvaluationReminder, evaluationReminderNotificationModel, orgRoleUser.UserId, createdByOrgRoleUserId, "Evaluation Reminder Notification"); } catch (Exception ex) { _logger.Info( String.Format("\n System failure: For Physician:{0} \n Message{1}", orderedPair.SecondValue, ex.Message)); } } else { _logger.Info(String.Format("\n No Evaluation Pending For Physician:{0}", orderedPair.SecondValue)); } } }
public void PollForLockCorporateEvent() { try { var corporateAccounts = _corporateAccountRepository.GetCorporateAccountForLockEvent(); if (corporateAccounts.IsNullOrEmpty()) { _logger.Info("No corporate account has been set for lock event."); return; } var createdByOrgRoleUserId = _organizationRoleUserRepository.GetOrganizationRoleUserIdsForRole((long)Roles.FranchisorAdmin).First(); foreach (var corporateAccount in corporateAccounts) { try { if (!corporateAccount.EventLockDaysCount.HasValue) { continue; } var eventDate = DateTime.Now.AddDays(corporateAccount.EventLockDaysCount.Value).Date; var eventIds = _eventRepository.LockCorporateEvents(corporateAccount.Id, eventDate); if (eventIds != null && eventIds.Any()) { foreach (var eventId in eventIds) { _logger.Info(string.Format("Events locked for Corporate: {0} and EventId : {1}", corporateAccount.Tag, eventId)); } var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationIdAndRoleId(corporateAccount.Id, (long)Roles.CorporateAccountCoordinator); if (orgRoleUsers != null && orgRoleUsers.Any()) { var userIds = orgRoleUsers.Select(oru => oru.UserId).ToList(); var users = _userRepository.GetUsers(userIds); foreach (var eventId in eventIds) { var eventHostViewData = _eventService.GetById(eventId); foreach (var user in users) { if (user.Email == null || string.IsNullOrEmpty(user.Email.ToString())) { continue; } var model = _emailNotificationModelsFactory.GetEventLockedNotificationViewModel(user, eventHostViewData); _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EventLocked, EmailTemplateAlias.EventLocked, model, new string[] { user.Email.ToString() }, user.Id, createdByOrgRoleUserId, "Event Lock Notification"); } } } else { _logger.Info("No Nurse Practitioner Pr for Corporate: " + corporateAccount.Tag); } } else { _logger.Info("No Events locked for Corporate: " + corporateAccount.Tag); } } catch (Exception ex) { _logger.Error(string.Format("Error while locking events for corporate {0}. Messsage: {1} \n StackTrace {2}", corporateAccount.Tag, ex.Message, ex.StackTrace)); } } } catch (Exception ex) { _logger.Error(string.Format("Error while polling events for corporate. Messsage: {0} \n StackTrace {1}", ex.Message, ex.StackTrace)); } }
public bool?IsKynHafPrefilled(long eventId, long customerId, DateTime appointmentTime, bool checkKynOnly = true) { var model = _healthAssessmentService.GetHealthAssessmentEditModel(customerId, eventId); if (model == null || !model.QuestionEditModels.Any()) { return(false); } if (!model.IsKynPurchased && checkKynOnly) { return(null); } var customer = _customerRepository.GetCustomer(customerId); var isFilled = checkKynOnly ? CheckKynHaf(customer, model) : CheckHafPrefilled(customer, eventId); if (isFilled) { var answers = _healthAssessmentRepository.Get(customerId, eventId); if (answers.Any()) { var answer = answers.First(); if (answer.DataRecorderMetaData == null || answer.DataRecorderMetaData.DataRecorderCreator == null) { return(false); } var technicianIds = _organizationRoleUserRepository.GetOrganizationRoleUserIdsForRole((long)Roles.Technician); technicianIds.AddRange(_organizationRoleUserRepository.GetOrganizationRoleUserIdsByParentRole((long)Roles.Technician)); var dataRecorderMetaData = answer.DataRecorderMetaData; var updatedByCustomerOrOtherThanTechnician = dataRecorderMetaData.DataRecorderCreator.Id == customerId || !technicianIds.Contains(dataRecorderMetaData.DataRecorderCreator.Id); if (updatedByCustomerOrOtherThanTechnician) { return(dataRecorderMetaData.DateCreated.AddHours(2) <= appointmentTime); } var latestVersion = _healthAssessmentRepository.GetLastVersionNumberUpdatedByCustomerOrOtherThanTechnician(answer.EventCustomerId, customerId); if (latestVersion > 0) { var archiveAnswers = _healthAssessmentRepository.GetArchive(customerId, eventId, latestVersion); model = _healthAssessmentService.GetHealthAssessmentEditModel(customerId, eventId, latestVersion); isFilled = checkKynOnly ? CheckKynHaf(customer, model) : CheckHafPrefilled(customer, eventId, latestVersion); if (isFilled) { if (archiveAnswers != null && archiveAnswers.Any()) { answer = archiveAnswers.First().HealthAssessmentAnswer; dataRecorderMetaData = answer.DataRecorderMetaData; return(dataRecorderMetaData.DateCreated.AddHours(2) <= appointmentTime); } } } } } return(false); }
public void PollforEventResultReadyNotification() { var notificationTypes = _notificationTypeRepository.GetAll(); var notificationIsActive = notificationTypes.Any(nt => (nt.NotificationTypeAlias == NotificationTypeAlias.EventResultReadyNotification) && nt.IsActive); if (!notificationIsActive) { return; } var eventIds = _eventCustomerResultRepository.GetEventIdsForEventResultReadyNotiFication().ToArray(); if (eventIds.Count() == 0) { return; } var createdByOrgRoleUserId = _organizationRoleUserRepository.GetOrganizationRoleUserIdsForRole((long)Roles.FranchisorAdmin).First(); foreach (var eventId in eventIds) { try { var notificationSent = _eventNotificationRepository.GetByEventId(eventId, NotificationTypeAlias.EventResultReadyNotification); if (notificationSent != null) { continue; } var hospitalPartnerId = _hospitalPartnerRepository.GetHospitalPartnerIdForEvent(eventId); if (hospitalPartnerId >= 1) { var partnerReleaseSinged = _eventCustomerResultRepository.CheckAnyCustomerResultsReadyAndSignedPartnerRelease(eventId); if (partnerReleaseSinged) { var allResultsReady = _eventCustomerResultRepository.CheckAllCustomerResultsReadyForEvent(eventId); if (!allResultsReady) { _logger.Info(string.Format("All Results are not ready For Event Id {0}", eventId)); } var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationId(hospitalPartnerId); var hospitalFacilityIds = _hospitalFacilityRepository.GetSelectedHospitalFacilityIdForEvent(eventId); if (hospitalFacilityIds != null && hospitalFacilityIds.Any()) { foreach (var hospitalFacilityId in hospitalFacilityIds) { var hospitalFacilityOrgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationId(hospitalFacilityId); if (hospitalFacilityOrgRoleUsers != null && hospitalFacilityOrgRoleUsers.Any()) { orgRoleUsers = orgRoleUsers.Concat(hospitalFacilityOrgRoleUsers); } } } var userIds = orgRoleUsers.Select(oru => oru.UserId).ToList(); var users = _userRepository.GetUsers(userIds); var eventHostViewData = _eventService.GetById(eventId); foreach (var user in users) { if (user.Email == null || string.IsNullOrEmpty(user.Email.ToString())) { continue; } var model = _emailNotificationModelsFactory.GetEventResultReadyNotificationViewModel(user, eventHostViewData); var notifications = _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EventResultReadyNotification, EmailTemplateAlias.EventResultReadyNotification, model, new string[] { user.Email.ToString() }, user.Id, createdByOrgRoleUserId, "Event Result Ready Notification"); if (notifications != null && notifications.Any()) { var eventNotification = new EventNotification { EventId = eventId, NotificationId = notifications.First().Id }; _eventNotificationRepository.Save(eventNotification); } } } } //var account = _corporateAccountRepository.GetbyEventId(eventId); //if (account != null && account.Id > 0 && account.SendEventResultReadyNotification) //{ // var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationIdAndRoleId(account.Id, (long)Roles.CorporateAccountCoordinator); // var userIds = orgRoleUsers.Select(oru => oru.UserId).ToList(); // var users = _userRepository.GetUsers(userIds); // var eventHostViewData = _eventService.GetById(eventId); // foreach (var user in users) // { // if (user.Email == null || string.IsNullOrEmpty(user.Email.ToString())) // continue; // var model = _emailNotificationModelsFactory.GetEventResultReadyNotificationViewModel(user, eventHostViewData); // var notifications = _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EventResultReadyNotification, EmailTemplateAlias.EventResultReadyNotification, model, new string[] { user.Email.ToString() }, user.Id, createdByOrgRoleUserId, "Event Result Ready Notification"); // if (notifications != null && notifications.Any()) // { // var eventNotification = new EventNotification { EventId = eventId, NotificationId = notifications.First().Id }; // _eventNotificationRepository.Save(eventNotification); // } // } //} } catch (Exception ex) { _logger.Error(string.Format("Event Result Ready Notification Error For Event Id {0} \nMessage:{1} \nStackTrace: {2}", eventId, ex.Message, ex.StackTrace)); } } }
public void PollforEventResultReadyNotification() { var notificationTypes = _notificationTypeRepository.GetAll(); var notificationIsActive = notificationTypes.Any(nt => (nt.NotificationTypeAlias == NotificationTypeAlias.EventResultReadyNotification) && nt.IsActive); if (!notificationIsActive) { return; } if (!_cutofDate.HasValue) { _logger.Info("Please provide cut of date to sent Corporate Event Result Ready Notification"); return; } var eventIds = _eventCustomerResultRepository.GetEventIdsForCorporateAccountEventResultReadyNotiFication(_cutofDate.Value).ToArray(); if (eventIds.Count() == 0) { _logger.Info("No Corporate Event found for sending Result Ready notification"); return; } var createdByOrgRoleUserId = _organizationRoleUserRepository.GetOrganizationRoleUserIdsForRole((long)Roles.FranchisorAdmin).First(); foreach (var eventId in eventIds) { try { var notificationSent = _eventNotificationRepository.GetByEventId(eventId, NotificationTypeAlias.EventResultReadyNotification); if (notificationSent != null && notificationSent.IsForCorporateAccount) { continue; } var account = _corporateAccountRepository.GetbyEventId(eventId); if (account != null && account.SendEventResultReadyNotification) { var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationIdAndRoleId(account.Id, (long)Roles.CorporateAccountCoordinator); if (!orgRoleUsers.IsNullOrEmpty()) { var userIds = orgRoleUsers.Select(oru => oru.UserId).ToList(); var users = _userRepository.GetUsers(userIds); var eventHostViewData = _eventService.GetById(eventId); foreach (var user in users) { if (user.Email == null || string.IsNullOrEmpty(user.Email.ToString())) { continue; } var model = _emailNotificationModelsFactory.GetEventResultReadyNotificationViewModel(user, eventHostViewData); var notifications = _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EventResultReadyNotification, EmailTemplateAlias.EventResultReadyNotification, model, new string[] { user.Email.ToString() }, user.Id, createdByOrgRoleUserId, "Event Result Ready Notification"); if (notifications != null && notifications.Any()) { var eventNotification = new EventNotification { EventId = eventId, NotificationId = notifications.First().Id, IsForCorporateAccount = true }; _eventNotificationRepository.SaveForCorporateAccount(eventNotification); } } } else { _logger.Info(string.Format("No coordinator Attached to Event For Account {0} is Off", account.Id)); } } else { _logger.Info(string.Format("Send Event Result Ready Notification For Account {0} is Off", account.Id)); } } catch (Exception ex) { _logger.Error(string.Format("Corporat Event Result Ready Notification Error For Event Id {0} \nMessage:{1} \nStackTrace: {2}", eventId, ex.Message, ex.StackTrace)); } } }