Ejemplo n.º 1
0
        public void PollForPriorityInQueueNotification()
        {
            try
            {
                var eventCustomerResultIds = _customerEventPriorityInQueueDataRepository.GetEventCustomerResultIdsForPriorityInQueueNotification(_settings.DaysToCheckPriorityInQueue);
                if (eventCustomerResultIds == null || !eventCustomerResultIds.Any())
                {
                    _logger.Info("No records found for priority in queue");
                }

                foreach (var eventCustomerResultId in eventCustomerResultIds)
                {
                    try
                    {
                        var eventCustomerResult = _eventCustomerResultRepository.GetById(eventCustomerResultId);

                        _logger.Info(string.Format("Checking Priority In Queue mail for EventId {0}, CustomerId {1}", eventCustomerResult.EventId, eventCustomerResult.CustomerId));

                        var messageAlreadySent = _eventCustomerNotificationRepository.GetByEventCustomerId(eventCustomerResultId, NotificationTypeAlias.PriorityInQueueCustomer);
                        if (messageAlreadySent != null)
                        {
                            _logger.Info(string.Format("Priority In Queue mail has been already sent for EventId {0}, CustomerId {1}", eventCustomerResult.EventId, eventCustomerResult.CustomerId));
                            continue;
                        }

                        var priorityInQueueNotificationModel = _emailNotificationModelsFactory.GetPriorityInQueueNotificationModel(eventCustomerResult.EventId, eventCustomerResult.CustomerId, "", eventCustomerResultId);

                        var notifications = _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.PriorityInQueueCustomer, EmailTemplateAlias.PriorityInQueueCustomer, priorityInQueueNotificationModel, 0, 1, "Priority in queue Customer");
                        if (notifications != null && notifications.Any())
                        {
                            _logger.Info(string.Format("Priority In Queue mail has been queued for EventId {0}, CustomerId {1}", eventCustomerResult.EventId, eventCustomerResult.CustomerId));

                            var notification = notifications.First();
                            var eventCustomerNotification = new EventCustomerNotification {
                                EventCustomerId = eventCustomerResultId, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id
                            };
                            _eventCustomerNotificationRepository.Save(eventCustomerNotification);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("Error for priority in queue for EventCustomerResultId {0}. \n Message : {1}, \n Stack Trace : {2}", eventCustomerResultId, ex.Message, ex.StackTrace));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error while polling data for priority in queue. \n Message : {0}, \n Stack Trace : {1}", ex.Message, ex.StackTrace));
            }
        }
        private string SendCustomNotification(Customer customer, EventCustomer eventCustomer, CorporateAccount account, CustomEventNotification customEventNotification)
        {
            try
            {
                var message = string.Empty;
                _logger.Info("Running Custom SMS for  Customer: " + customer.CustomerId);
                if (!eventCustomer.EnableTexting)
                {
                    message = "Customer has not opted for SMS";
                    _logger.Info(message);
                    return(message);
                }
                if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false)
                {
                    message = "Customer has not subscribed for SMS";
                    _logger.Info(message);
                    return(message);
                }
                var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.EventId, NotificationTypeAlias.CustomEventSmsNotification);

                var messageCount = (!messageAlreadySentList.IsNullOrEmpty()) ? EnumerableExtensions.Count(messageAlreadySentList) : 0;

                if (account != null)
                {
                    var accountMaxSmscount = (account.MaximumSms.HasValue) ? account.MaximumSms.Value : 0;

                    if (messageCount >= accountMaxSmscount)
                    {
                        _logger.Info("Maximum SMS has Been Sent ");
                        _logger.Info(string.Format("Allowed SMS {0}, SMS Already Sent {0} " + accountMaxSmscount, messageCount));
                        message = "Maximum SMS limit has been reached.";

                        return(message);
                    }
                }
                if (messageAlreadySentList.Any() && (account == null || !account.MaximumSms.HasValue))
                {
                    message = "Maximum SMS limit has been reached.";
                    return(message);
                }
                var smsNotificaionModel = _phoneNotificationModelsFactory.GetCustomEventSmsNotificatonModel(customEventNotification.Body);

                var notification = _notifier.NotifyViaSms(NotificationTypeAlias.CustomEventSmsNotification, EmailTemplateAlias.CustomEventSms, smsNotificaionModel, customer.Id, customEventNotification.CreatedBy, "Event Detail ");

                if (notification != null)
                {
                    var eventCustomerNotification = new EventCustomerNotification
                    {
                        EventCustomerId    = eventCustomer.Id,
                        NotificationId     = notification.Id,
                        NotificationTypeId = notification.NotificationType.Id
                    };
                    _eventCustomerNotificationRepository.Save(eventCustomerNotification);
                }

                message = "Message has been successfully Queued";

                return(message);
            }
            catch (Exception exception)
            {
                _logger.Error("Some Error occurred while Queuing message");
                _logger.Info("Message: " + exception.Message);
                _logger.Info("Stack Trace: " + exception.StackTrace);

                return("Some Error occurred while Queuing message");
            }
        }
Ejemplo n.º 3
0
        public void PollforFaxResultNotification()
        {
            try
            {
                var value = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.EnablePhysicianPartnerCustomerResultFaxNotification);

                if (value.ToLower() != bool.TrueString.ToLower())
                {
                    return;
                }

                var account = _corporateAccountRepository.GetById(_settings.PhysicianPartnerAccountId);

                DateTime?stopSendingPdftoHealthPlanDate = null;
                if (account != null && account.IsHealthPlan)
                {
                    stopSendingPdftoHealthPlanDate = _settings.StopSendingPdftoHealthPlanDate;
                }

                var eventCustomerResults =
                    _eventCustomerResultRepository.GetEventCustomerResultsToFax(
                        (int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false, DateTime.Now, DateTime.Now.AddHours(-_faxInterval), _settings.PhysicianPartnerAccountId, "", stopSendingPdftoHealthPlanDate: stopSendingPdftoHealthPlanDate);

                var customerResults = eventCustomerResults as EventCustomerResult[] ?? eventCustomerResults.ToArray();

                if (eventCustomerResults == null || !customerResults.Any())
                {
                    _logger.Info("No event customer result list found for Fax queue.");
                    return;
                }
                _logger.Info("Get the event customer result list for Fax queue.");

                var fileName = _mediaRepository.GetPdfFileNameForPcpResultReport();

                var customerIds = customerResults.Select(x => x.CustomerId).ToArray();

                var pcpList = _pcpRepository.GetByCustomerIds(customerIds).Where(x => x.Fax != null && !string.IsNullOrEmpty(x.Fax.ToString()));

                foreach (var ecr in customerResults)
                {
                    var messageAlreadySent = _eventCustomerNotificationRepository.GetByEventCustomerId(ecr.Id, NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification);
                    if (messageAlreadySent != null)
                    {
                        _logger.Info(string.Format("Fax already queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId));
                        continue;
                    }
                    var path   = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath;
                    var pdfUrl = path + fileName;
                    if (path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
                    {
                        throw new InvalidDirectoryPathException();
                    }

                    if (File.Exists(pdfUrl))
                    {
                        var pcp = pcpList.FirstOrDefault(x => x.CustomerId == ecr.CustomerId);

                        if (pcp == null)
                        {
                            _logger.Error(string.Format("PCP not found/or pcp Fax not found where customerId {0}", ecr.CustomerId));
                        }
                        else
                        {
                            try
                            {
                                PhoneNotificationModel model = null;
                                var notification             = _notifier.NotifyViaFax(NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification, model, pcp.Fax, DirectoryOperationsHelper.ReadAllBytes(pdfUrl), 1, "Faxing Notification");

                                if (notification != null)
                                {
                                    var eventCustomerNotification = new EventCustomerNotification {
                                        EventCustomerId = ecr.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id
                                    };
                                    _eventCustomerNotificationRepository.Save(eventCustomerNotification);
                                }
                                _logger.Info(string.Format("Fax queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId));
                            }
                            catch (Exception ex)
                            {
                                _logger.Error(string.Format("Fax not queued for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId));
                                _logger.Error("\n");
                                _logger.Error(ex.Message + "Stack Trace:" + ex.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        _logger.Error(string.Format("Fax queue: File Not found for EventId {0}, CustomerId {1}", ecr.EventId, ecr.CustomerId));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message + "Fax queue: Stack Trace:" + ex.StackTrace);
            }
        }
Ejemplo n.º 4
0
        //[HttpPost]
        public JsonResult SendConfirmationSms(long eventId, long customerId)
        {
            var currentSession = _sessionContext.UserSession;
            var eventCustomer  = _eventCustomerRepository.Get(eventId, customerId);
            var customer       = _customerRepository.GetCustomer(customerId);
            var message        = string.Empty;

            if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false)
            {
                _logger.Info("customer has not Subscribed for SMS customerId " + customer.CustomerId);

                message = "customer has not Subscribed for SMS";
                _logger.Info(message);

                return(Json(new { message }, JsonRequestBehavior.AllowGet));
            }

            if (eventCustomer.EnableTexting)
            {
                var account = _corporateAccountRepository.GetbyEventId(eventId);
                if (account != null && !account.EnableSms)
                {
                    message = "SMS has been disabled for Corporate Account Tag: " + account.Tag;
                    _logger.Info(message);

                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }

                var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.Id, NotificationTypeAlias.AppointmentConfirmation);
                var messageCount           = (messageAlreadySentList != null && messageAlreadySentList.Any()) ? messageAlreadySentList.Count() : 0;

                if (account != null && messageCount >= account.MaximumSms)
                {
                    _logger.Info("Maximum SMS has Been Sent ");
                    _logger.Info(string.Format("Allowed SMS {0}, SMS Already Sent {0} " + account.MaximumSms, messageCount));
                    message = "Maximum SMS limit has been reached.";
                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }

                if (account == null && messageCount > 0)
                {
                    message = "Appointment confirmation SMS has already been sent.";
                    _logger.Info(message);
                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }

                var eventData           = _eventRepository.GetById(eventId);
                var smsNotificaionModel = _phoneNotificationModelsFactory.GetScreeningReminderSmsNotificationModel(customer, eventData);

                var smsTemplateAlias = EmailTemplateAlias.AppointmentConfirmation;
                if (account != null && account.ConfirmationSmsTemplateId.HasValue && account.ConfirmationSmsTemplateId.Value > 0)
                {
                    var smsTemplate = _emailTemplateRepository.GetById(account.ConfirmationSmsTemplateId.Value);
                    smsTemplateAlias = smsTemplate.Alias;
                }
                var notification = _notifier.NotifyViaSms(NotificationTypeAlias.AppointmentConfirmation, smsTemplateAlias, smsNotificaionModel, customer.Id, currentSession.CurrentOrganizationRole.OrganizationRoleUserId, Request.Url.AbsolutePath);

                if (notification != null)
                {
                    var eventCustomerNotification = new EventCustomerNotification {
                        EventCustomerId = eventCustomer.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id
                    };
                    _eventCustomerNotificationRepository.Save(eventCustomerNotification);
                }
                else
                {
                    message = "Queuing is disabled for Appointment Confirmation SMS.";
                    _logger.Info(message);
                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                message = "Customer has not opted for SMS";
                _logger.Info(message);
                return(Json(new { message }, JsonRequestBehavior.AllowGet));
            }

            message = "Message Sent Successfully";
            return(Json(new { message }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public void SendAppointmentConfirmationMail(Customer customer, Event eventData, long createdByOrgRoleUserId, string source, CorporateAccount account)
        {
            var sendNotification = false;

            if (eventData.EventType == EventType.Retail)
            {
                sendNotification = true;
            }
            else if (eventData.AccountId.HasValue && eventData.AccountId.Value > 0 && account != null)
            {
                // account = ((IUniqueItemRepository<CorporateAccount>)_corporateAccountRepository).GetById(eventData.AccountId.Value);
                sendNotification = account.SendAppointmentMail && account.AppointmentConfirmationMailTemplateId > 0;
            }

            if (sendNotification)
            {
                var appointmentConfirmationViewModel = _emailNotificationModelsFactory.GetAppointmentConfirmationModel(eventData.Id, customer.CustomerId);

                string emailTemplateAlias = EmailTemplateAlias.AppointmentConfirmationWithEventDetails;
                if (account != null && account.AppointmentConfirmationMailTemplateId > 0)
                {
                    var emailTemplate = _emailTemplateRepository.GetById(account.AppointmentConfirmationMailTemplateId);
                    emailTemplateAlias = emailTemplate.Alias;
                }

                _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.AppointmentConfirmationWithEventDetails, emailTemplateAlias, appointmentConfirmationViewModel, customer.Id, createdByOrgRoleUserId, source, useAlternateEmail: true);
            }

            var eventCustomer = _eventCustomerRepository.Get(eventData.Id, customer.CustomerId);

            if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false)
            {
                _logger.Info("Customer has not subscribed for SMS " + customer.CustomerId);
                return;
            }

            if (account != null && !account.EnableSms)
            {
                _logger.Info("SMS feature has been disabled by corporate account: " + account.Tag + " EventId: " + eventData.Id);
                return;
            }

            var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.Id, NotificationTypeAlias.AppointmentConfirmation);

            var messageCount = (messageAlreadySentList != null && messageAlreadySentList.Any()) ? messageAlreadySentList.Count() : 0;

            if (account != null && messageCount >= account.MaximumSms)
            {
                _logger.Info(string.Format("Maximum Number of reminder message sms has been sent for this event. eventId {0} Customer Id: {1}", eventCustomer.EventId, eventCustomer.Id));
                return;
            }

            var smsTemplateAlias = EmailTemplateAlias.AppointmentConfirmation;

            if (account != null && account.ConfirmationSmsTemplateId.HasValue && account.ConfirmationSmsTemplateId.Value > 0)
            {
                var smsTemplate = _emailTemplateRepository.GetById(account.ConfirmationSmsTemplateId.Value);
                smsTemplateAlias = smsTemplate.Alias;
            }

            if (eventCustomer.EnableTexting)
            {
                var smsAppointmentConfirmation = _smsNotificationModelsFactory.GetScreeningReminderSmsNotificationModel(customer, eventData);
                var notification = _notifier.NotifyViaSms(NotificationTypeAlias.AppointmentConfirmation, smsTemplateAlias, smsAppointmentConfirmation, customer.Id, createdByOrgRoleUserId, source);

                if (notification != null)
                {
                    var eventCustomerNotification = new EventCustomerNotification {
                        EventCustomerId = eventCustomer.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id
                    };
                    _eventCustomerNotificationRepository.Save(eventCustomerNotification);
                }
            }
        }