public void Save(EventCustomerNotification eventCustomerNotification) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var entity = Mapper.Map <EventCustomerNotification, EventCustomerNotificationEntity>(eventCustomerNotification); if (!adapter.SaveEntity(entity)) { throw new PersistenceFailureException(); } } }
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"); } }
public CorporateAccountCustomerListModel Create(IEnumerable <EventCustomer> eventCustomers, IEnumerable <Customer> customers, IEnumerable <Order> orders, IEnumerable <OrderedPair <long, string> > packages, IEnumerable <OrderedPair <long, string> > tests, IEnumerable <ShippingDetail> shippingDetails, ShippingOption cdShippingOption, IEnumerable <EventCustomerResult> eventCustomerResults, IEnumerable <Event> events, IEnumerable <Pod> pods, IEnumerable <OrderedPair <long, string> > eventIdCorporateAccountNamePairs, IEnumerable <CustomerResultStatusViewModel> resultStatuses, IEnumerable <PrimaryCarePhysician> primaryCarePhysicians, IEnumerable <HealthAssessmentAnswer> healthAssessmentAnswers, IEnumerable <HealthAssessmentQuestion> healthAssessmentQuestions, IEnumerable <Language> languages, IEnumerable <EventCustomerNotification> eventCustomerNotifications, IEnumerable <EventHospitalPartner> eventHospitalPartners) { var collection = new List <CorporateAccountCustomerViewModel>(); foreach (var eventCustomer in eventCustomers) { var customer = customers.FirstOrDefault(c => c.CustomerId == eventCustomer.CustomerId); var order = orders.FirstOrDefault( o => o.EventId == eventCustomer.EventId && o.CustomerId == eventCustomer.CustomerId); var package = order == null ? null : packages.FirstOrDefault(p => p.FirstValue == order.Id); var test = order == null ? null : tests.Where(t => t.FirstValue == order.Id).ToList(); var productPurchased = string.Empty; if (package != null && !test.IsNullOrEmpty()) { productPurchased = package.SecondValue + " + " + string.Join(" + ", test.Select(t => t.SecondValue).ToArray()); } else if (!test.IsNullOrEmpty()) { productPurchased = string.Join(" + ", test.Select(t => t.SecondValue).ToArray()); } else if (package != null) { productPurchased = package.SecondValue; } ShippingDetail shippingDetail = null; string cdPurchased = "N/A"; if (order != null) { var shippingDetailIds = order.OrderDetails.SelectMany( od => od.ShippingDetailOrderDetails.Select(sdod => sdod.ShippingDetailId)).ToArray(); shippingDetail = shippingDetails.FirstOrDefault( sd => shippingDetailIds.Contains(sd.Id) && sd.ShippingOption.Id != (cdShippingOption != null ? cdShippingOption.Id : 0)); var cdShippingDetail = shippingDetails.FirstOrDefault( sd => shippingDetailIds.Contains(sd.Id) && sd.ShippingOption.Id == (cdShippingOption != null ? cdShippingOption.Id : 0)); var cdOrderDetail = order.OrderDetails.Where(od => od.IsCompleted && od.DetailType == OrderItemType.ProductItem) .ToArray(); if (cdOrderDetail != null && cdOrderDetail.Any() && cdShippingDetail != null) { cdPurchased = "CD"; } else if (cdOrderDetail != null && cdOrderDetail.Any() && cdShippingDetail == null) { cdPurchased = "Online"; } } var isEvaluated = false; var isPdfGenerated = false; var eventCustomerResult = eventCustomerResults.FirstOrDefault(ecr => ecr.Id == eventCustomer.Id); var result = "Not Processed"; var recommendation = "Not Processed"; if (eventCustomerResult != null) { isEvaluated = true; isPdfGenerated = eventCustomerResult.IsClinicalFormGenerated && eventCustomerResult.IsResultPdfGenerated; result = eventCustomerResult.ResultSummary.HasValue ? ((ResultInterpretation)eventCustomerResult.ResultSummary.Value).GetDescription() : "Not Available"; recommendation = eventCustomerResult.PathwayRecommendation.HasValue ? ((PathwayRecommendation)eventCustomerResult.PathwayRecommendation.Value).GetDescription() : "Not Available"; } var eventData = events.FirstOrDefault(e => e.Id == eventCustomer.EventId); var eventPods = pods.Where(p => eventData.PodIds.Contains(p.Id)).ToArray(); var corporateAccountName = eventIdCorporateAccountNamePairs.Where(ecan => ecan.FirstValue == eventData.Id).Select(ecan => ecan.SecondValue).SingleOrDefault(); var resultStatus = resultStatuses != null?resultStatuses.SingleOrDefault(rs => rs.EventCustomerId == eventCustomer.Id) : null; IEnumerable <OrderedPair <long, string> > pairTestSummary = null; if (resultStatus != null && resultStatus.TestResults != null) { pairTestSummary = resultStatus.TestResults.Select(tr => new OrderedPair <long, string>(tr.TestId, tr.TestInterpretation.HasValue ? ((ResultInterpretation)tr.TestInterpretation.Value).ToString() : "")); } var primaryCarePhysician = primaryCarePhysicians.SingleOrDefault(pcp => pcp.CustomerId == eventCustomer.CustomerId); var customerHealthAnswers = healthAssessmentAnswers.Where(haa => haa.EventCustomerId == eventCustomer.Id).ToArray(); var primaryCareAnswer = "No"; var mammogramProstateScreeningAnswer = "No"; var colonoscopyAnswer = "No"; var cancerAnswer = "No"; var weightBariatricAnswer = "No"; if (customerHealthAnswers.Any()) { var primaryCareQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.PrimaryCare.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (primaryCareQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.FirstOrDefault(cha => cha.QuestionId == primaryCareQuestionId); if (healthassessmentAnswer != null) { primaryCareAnswer = healthassessmentAnswer.Answer; } } var mammogramProstateScreeningQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.MammogramProstateScreening.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (mammogramProstateScreeningQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.SingleOrDefault(cha => cha.QuestionId == mammogramProstateScreeningQuestionId); if (healthassessmentAnswer != null) { mammogramProstateScreeningAnswer = healthassessmentAnswer.Answer; } } var colonoscopyQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.Colonoscopy.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (colonoscopyQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.SingleOrDefault(cha => cha.QuestionId == colonoscopyQuestionId); if (healthassessmentAnswer != null) { colonoscopyAnswer = healthassessmentAnswer.Answer; } } var cancerQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.Cancer.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (cancerQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.SingleOrDefault(cha => cha.QuestionId == cancerQuestionId); if (healthassessmentAnswer != null) { cancerAnswer = healthassessmentAnswer.Answer; } } var weightBariatricQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.WeightBariatric.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (weightBariatricQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.SingleOrDefault(cha => cha.QuestionId == weightBariatricQuestionId); if (healthassessmentAnswer != null) { weightBariatricAnswer = healthassessmentAnswer.Answer; } } } var preferredLanguage = "N/A"; if (customer.LanguageId.HasValue) { var language = languages.FirstOrDefault(x => x.Id == customer.LanguageId); if (language != null) { preferredLanguage = language.Name; } } EventCustomerNotification eventCustomerNotification = null; if (eventCustomerNotifications != null && eventCustomerNotifications.Any()) { eventCustomerNotification = eventCustomerNotifications.FirstOrDefault(ecn => ecn.EventCustomerId == eventCustomer.Id); } var eventHospitalPartner = eventHospitalPartners.FirstOrDefault(ehp => ehp.EventId == eventCustomer.EventId); var scannedDocumentUrl = string.Empty; var mediaLocScannedDocs = _mediaRepository.GetScannedDocumentStorageFileLocation(eventCustomer.EventId); if (Directory.Exists(mediaLocScannedDocs.PhysicalPath)) { var filesScannedDocs = Directory.GetFiles(mediaLocScannedDocs.PhysicalPath); if (filesScannedDocs.Any()) { var filename = filesScannedDocs.Where(fsd => !string.IsNullOrEmpty(fsd) && Path.GetFileName(fsd).StartsWith(customer.CustomerId.ToString())).Select(Path.GetFileName).FirstOrDefault(); if (!string.IsNullOrEmpty(filename)) { scannedDocumentUrl = mediaLocScannedDocs.Url + filename; } } } collection.Add(new CorporateAccountCustomerViewModel { CustomerName = customer.Name, Phone = customer.HomePhoneNumber != null ? customer.HomePhoneNumber.FormatPhoneNumber : string.Empty, PhoneCell = customer.MobilePhoneNumber != null ? customer.MobilePhoneNumber.FormatPhoneNumber : string.Empty, PhoneOffice = customer.OfficePhoneNumber != null ? customer.OfficePhoneNumber.FormatPhoneNumber : string.Empty, PhoneOfficeExtn = customer.PhoneOfficeExtension, DateofBirth = customer.DateOfBirth, Package = productPurchased, CdPurchased = cdPurchased, EventDate = eventData.EventDate, CustomerId = customer.CustomerId, EventId = eventCustomer.EventId, Gender = customer.Gender.ToString(), Height = customer.Height != null && customer.Height.TotalInches > 0 ? customer.Height.TotalInches.ToString() : "N/A", Weight = customer.Weight != null && customer.Weight.Pounds > 0 ? customer.Weight.Pounds.ToString() : "N/A", Pod = string.Join(", ", eventPods.Select(ep => ep.Name)), IsEvaluated = isEvaluated, IsPdfGenerated = isPdfGenerated, Result = result, Recommendation = recommendation, Email = customer.Email != null ? customer.Email.ToString() : string.Empty, Address = Mapper.Map <Address, AddressViewModel>(customer.Address), ShippingMode = shippingDetail != null ? "Paper" : "Online", MailedStatus = shippingDetail != null ? shippingDetail.Status.ToString() : "Online", MailedOn = shippingDetail != null ? shippingDetail.ShipmentDate : null, CorporateSponsor = corporateAccountName ?? "N/A", TestSummary = pairTestSummary, PrimaryCarePhysicianName = primaryCarePhysician != null ? primaryCarePhysician.Name.FullName : "N/A", PrimaryCare = primaryCareAnswer, MammogramProstateScreening = mammogramProstateScreeningAnswer, Colonoscopy = colonoscopyAnswer, Cancer = cancerAnswer, WeightBariatric = weightBariatricAnswer, PreferredLanguage = preferredLanguage, BestTimeToCall = customer.BestTimeToCall.HasValue && customer.BestTimeToCall.Value > 0 ? ((BestTimeToCall)customer.BestTimeToCall).GetDescription() : "N/A", EventCustomerId = eventCustomer.Id, IsCannedMessageSent = eventCustomerNotification != null, Ssn = (eventHospitalPartner != null && eventHospitalPartner.CaptureSsn && !string.IsNullOrEmpty(customer.Ssn) && customer.Ssn.Length >= 9) ? customer.Ssn.Substring(0, 3) + "-" + customer.Ssn.Substring(3, 2) + "-" + customer.Ssn.Substring(customer.Ssn.Length - 4)//"XXX-XX-" + customer.Ssn.Substring(customer.Ssn.Length - 4) : string.Empty, MemberId = string.IsNullOrEmpty(customer.InsuranceId) ? "N/A" : customer.InsuranceId, ScannedDocumentUrl = scannedDocumentUrl, HicnNumber = customer.Hicn }); } return(new CorporateAccountCustomerListModel { Collection = collection }); }
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); } }
public HospitalPartnerCustomerListModel Create(IEnumerable <EventCustomer> eventCustomers, IEnumerable <Order> orders, IEnumerable <Customer> customers, IEnumerable <OrderedPair <long, string> > packages, IEnumerable <OrderedPair <long, string> > tests, IEnumerable <HospitalPartnerCustomer> hospitalPartnerCustomers, IEnumerable <OrderedPair <long, string> > idNamePairs, IEnumerable <Event> events, IEnumerable <ShippingDetail> shippingDetails, IEnumerable <CustomerResultStatusViewModel> resultStatuses, ShippingOption cdShippingOption, IEnumerable <Pod> pods, IEnumerable <OrderedPair <long, string> > eventHospitalPartnerNamePairs, IEnumerable <OrderedPair <long, string> > eventIdCorporateAccounrNamePairs, IEnumerable <PrimaryCarePhysician> primaryCarePhysicians, IEnumerable <HealthAssessmentQuestion> healthAssessmentQuestions, IEnumerable <HealthAssessmentAnswer> healthAssessmentAnswers, IEnumerable <EventCustomerResult> eventCustomerResults, HospitalPartner hospitalPartner, IEnumerable <CustomerCallNotes> notes, IEnumerable <EventCustomerNotification> eventCustomerNotifications, IEnumerable <EventHospitalPartner> eventHospitalPartners, IEnumerable <OrderedPair <long, string> > eventCustomerIdHospitalFacilityNamePairs, IEnumerable <HospitalFacility> hospitalFacilities, IEnumerable <long> showScannedDocumentHospitalPartnerIds, IEnumerable <Language> languages) { var model = new HospitalPartnerCustomerListModel(); var customerModels = new List <HospitalPartnerCustomerViewModel>(); eventCustomers.ToList().ForEach(ec => { var order = orders.Where(o => o.EventId == ec.EventId && o.CustomerId == ec.CustomerId).FirstOrDefault(); var customer = customers.Where(c => c.CustomerId == ec.CustomerId).FirstOrDefault(); var package = order == null ? null : packages.Where(p => p.FirstValue == order.Id).FirstOrDefault(); var test = order == null ? null : tests.Where(p => p.FirstValue == order.Id).ToList(); var productPurchased = string.Empty; if (package != null && !test.IsNullOrEmpty()) { productPurchased = package.SecondValue + " + " + string.Join(" + ", test.Select(t => t.SecondValue).ToArray()); } else if (!test.IsNullOrEmpty()) { productPurchased = string.Join(" + ", test.Select(t => t.SecondValue).ToArray()); } else if (package != null) { productPurchased = package.SecondValue; } ShippingDetail shippingDetail = null; string cdPurhased = "N/A"; if (order != null) { var shippingDetailIds = order.OrderDetails.SelectMany(od => od.ShippingDetailOrderDetails.Select(sdod => sdod.ShippingDetailId)).ToArray(); shippingDetail = shippingDetails.Where(sd => shippingDetailIds.Contains(sd.Id) && sd.ShippingOption.Id != (cdShippingOption != null ? cdShippingOption.Id : 0)).FirstOrDefault(); var cdShippingDetail = shippingDetails.Where(sd => shippingDetailIds.Contains(sd.Id) && sd.ShippingOption.Id == (cdShippingOption != null ? cdShippingOption.Id : 0)).FirstOrDefault(); var cdOrderDetail = order.OrderDetails.Where(od => od.IsCompleted && od.DetailType == OrderItemType.ProductItem).ToArray(); if (cdOrderDetail != null && cdOrderDetail.Count() > 0 && cdShippingDetail != null) { cdPurhased = "CD"; } else if (cdOrderDetail != null && cdOrderDetail.Count() > 0 && cdShippingDetail == null) { cdPurhased = "Online"; } } var isEvaluated = false; var isPdfGenerated = false; var evenCustomerResult = eventCustomerResults.Where(ecr => ecr.Id == ec.Id).FirstOrDefault(); var result = "Not Processed"; var recommendation = "Not Processed"; if (evenCustomerResult != null) { isEvaluated = true; isPdfGenerated = evenCustomerResult.IsClinicalFormGenerated && evenCustomerResult.IsResultPdfGenerated; result = evenCustomerResult.ResultSummary.HasValue ? ((ResultInterpretation)evenCustomerResult.ResultSummary.Value).GetDescription() : "Not Available"; recommendation = evenCustomerResult.PathwayRecommendation.HasValue ? ((PathwayRecommendation)evenCustomerResult.PathwayRecommendation.Value).GetDescription() : "Not Available"; } HospitalPartnerCustomer hospitalPartnerCustomer = null; var customerActivities = hospitalPartnerCustomers.Where(hpc => hpc.EventId == ec.EventId && hpc.CustomerId == ec.CustomerId).ToArray(); if (customerActivities.Count() > 0) { customerActivities = customerActivities.OrderBy(hpc => hpc.Id).ToArray(); hospitalPartnerCustomer = customerActivities.Last(); } var care = "N/A"; if (hospitalPartnerCustomer != null) { care = idNamePairs.Where( cc => cc.FirstValue == hospitalPartnerCustomer.CareCoordinatorOrgRoleUserId). First().SecondValue; } var resultStatus = resultStatuses != null ? resultStatuses.Where(rs => rs.EventCustomerId == ec.Id).SingleOrDefault() : null; IEnumerable <OrderedPair <long, string> > pairTestSummary = null; if (resultStatus != null && resultStatus.TestResults != null) { pairTestSummary = resultStatus.TestResults.Select(tr => new OrderedPair <long, string>(tr.TestId, tr.TestInterpretation.HasValue ? ((ResultInterpretation)tr.TestInterpretation.Value).ToString() : "")); } var eventData = events.Where(e => e.Id == ec.EventId).FirstOrDefault(); var eventPods = pods.Where(p => eventData.PodIds.Contains(p.Id)).ToArray(); DateTime?initialCallDate = null; if (evenCustomerResult != null && evenCustomerResult.ResultState == (int)TestResultStateNumber.ResultDelivered && (hospitalPartnerCustomer == null || ((HospitalPartnerCustomerStatus)hospitalPartnerCustomer.Status) == HospitalPartnerCustomerStatus.NotCalled)) { if (shippingDetail != null && shippingDetail.Status == ShipmentStatus.Shipped) { initialCallDate = (shippingDetail.ShipmentDate ?? DateTime.Now).AddDays(1).AddDays(hospitalPartner != null && hospitalPartner.MailTransitDays != null ? hospitalPartner.MailTransitDays.Value : 0); } else if (shippingDetail == null) { initialCallDate = (evenCustomerResult.DataRecorderMetaData.DateModified ?? evenCustomerResult.DataRecorderMetaData.DateCreated).AddDays(1); } } var hospitalPartnername = eventHospitalPartnerNamePairs.Where(ehp => ehp.FirstValue == eventData.Id).Select(ehp => ehp.SecondValue).SingleOrDefault(); var corporateAccountName = eventIdCorporateAccounrNamePairs.Where(ecan => ecan.FirstValue == eventData.Id).Select(ecan => ecan.SecondValue).SingleOrDefault(); var primaryCarePhysician = primaryCarePhysicians.Where(pcp => pcp.CustomerId == ec.CustomerId).SingleOrDefault(); var customerHealthAnswers = healthAssessmentAnswers.Where(haa => haa.EventCustomerId == ec.Id).ToArray(); var primaryCareAnswer = "No"; var mammogramProstateScreeningAnswer = "No"; var colonoscopyAnswer = "No"; var cancerAnswer = "No"; var weightBariatricAnswer = "No"; if (customerHealthAnswers.Count() > 0) { var primaryCareQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.PrimaryCare.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (primaryCareQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.Where(cha => cha.QuestionId == primaryCareQuestionId).FirstOrDefault(); if (healthassessmentAnswer != null) { primaryCareAnswer = healthassessmentAnswer.Answer; } } var mammogramProstateScreeningQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.MammogramProstateScreening.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (mammogramProstateScreeningQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.Where(cha => cha.QuestionId == mammogramProstateScreeningQuestionId).SingleOrDefault(); if (healthassessmentAnswer != null) { mammogramProstateScreeningAnswer = healthassessmentAnswer.Answer; } } var colonoscopyQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.Colonoscopy.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (colonoscopyQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.Where(cha => cha.QuestionId == colonoscopyQuestionId).SingleOrDefault(); if (healthassessmentAnswer != null) { colonoscopyAnswer = healthassessmentAnswer.Answer; } } var cancerQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.Cancer.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (cancerQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.Where(cha => cha.QuestionId == cancerQuestionId).SingleOrDefault(); if (healthassessmentAnswer != null) { cancerAnswer = healthassessmentAnswer.Answer; } } var weightBariatricQuestionId = healthAssessmentQuestions.Where(haq => haq.Label == HealthAssessmentQuestionLabel.WeightBariatric.GetDescription()).Select(haq => haq.Id).SingleOrDefault(); if (weightBariatricQuestionId > 0) { var healthassessmentAnswer = customerHealthAnswers.Where(cha => cha.QuestionId == weightBariatricQuestionId).SingleOrDefault(); if (healthassessmentAnswer != null) { weightBariatricAnswer = healthassessmentAnswer.Answer; } } } //var notes = _customerCallNotesRepository.GetCustomerNotes(eventData.Id, new[] { customer.CustomerId }); var customerNotes = notes.Where(n => n.CustomerId == customer.CustomerId && n.EventId == eventData.Id).Select(n => n).ToArray(); string postScreeningNotes = string.Empty; if (!customerNotes.IsNullOrEmpty()) { //postScreeningNotes = string.Join("\\n\\n", notes.Where(n => n.NotesType == CustomerRegistrationNotesType.PostScreeningFollowUpNotes).Select(n => n.Notes).ToArray()); postScreeningNotes = string.Join("\\n\\n", customerNotes.Select(n => n.Notes).ToArray()); } EventCustomerNotification eventCustomerNotification = null; if (eventCustomerNotifications != null && eventCustomerNotifications.Count() > 0) { eventCustomerNotification = eventCustomerNotifications.FirstOrDefault(ecn => ecn.EventCustomerId == ec.Id); } var eventHospitalPartner = eventHospitalPartners.SingleOrDefault(ehp => ehp.EventId == eventData.Id); var showScannedDocumentUrl = false; var scannedDocumentUrl = string.Empty; if (eventHospitalPartner != null && showScannedDocumentHospitalPartnerIds != null) { showScannedDocumentUrl = showScannedDocumentHospitalPartnerIds.Contains(eventHospitalPartner.HospitalPartnerId); if (showScannedDocumentUrl) { var mediaLocScannedDocs = _mediaRepository.GetScannedDocumentStorageFileLocation(eventHospitalPartner.EventId); var filesScannedDocs = Directory.GetFiles(mediaLocScannedDocs.PhysicalPath); if (filesScannedDocs.Any()) { var filename = filesScannedDocs.Where(fsd => !string.IsNullOrEmpty(fsd) && Path.GetFileName(fsd).StartsWith(customer.CustomerId.ToString())).Select(Path.GetFileName).FirstOrDefault(); if (!string.IsNullOrEmpty(filename)) { scannedDocumentUrl = mediaLocScannedDocs.Url + filename; } } } } HospitalFacility hospitalFacility = null; var hospitalFacilityName = string.Empty; if (ec.HospitalFacilityId.HasValue) { if (hospitalFacilities != null && hospitalFacilities.Any()) { hospitalFacility = hospitalFacilities.FirstOrDefault(hf => hf.Id == ec.HospitalFacilityId); } if (eventCustomerIdHospitalFacilityNamePairs != null && eventCustomerIdHospitalFacilityNamePairs.Any()) { hospitalFacilityName = eventCustomerIdHospitalFacilityNamePairs.Where(ehp => ehp.FirstValue == ec.Id).Select(ehp => ehp.SecondValue).FirstOrDefault(); } } var preferredLanguage = "N/A"; if (customer.LanguageId.HasValue) { var language = languages.FirstOrDefault(x => x.Id == customer.LanguageId); if (language != null) { preferredLanguage = language.Name; } } customerModels.Add(new HospitalPartnerCustomerViewModel { CustomerName = customer.Name, Phone = customer.HomePhoneNumber != null ? customer.HomePhoneNumber.FormatPhoneNumber : string.Empty, PhoneCell = customer.MobilePhoneNumber != null ? customer.MobilePhoneNumber.FormatPhoneNumber : string.Empty, PhoneOffice = customer.OfficePhoneNumber != null ? customer.OfficePhoneNumber.FormatPhoneNumber : string.Empty, PhoneOfficeExtn = customer.PhoneOfficeExtension, DateofBirth = customer.DateOfBirth, Package = productPurchased, CdPurchased = cdPurhased, EventDate = eventData.EventDate, CustomerId = customer.CustomerId, EventId = ec.EventId, Gender = customer.Gender.ToString(), Height = customer.Height != null && customer.Height.TotalInches > 0 ? customer.Height.TotalInches.ToString() : "N/A", Weight = customer.Weight != null && customer.Weight.Pounds > 0 ? customer.Weight.Pounds.ToString() : "N/A", Pod = string.Join(", ", eventPods.Select(ep => ep.Name)), IsEvaluated = isEvaluated, IsPdfGenerated = isPdfGenerated, Status = hospitalPartnerCustomer != null ? ((HospitalPartnerCustomerStatus)hospitalPartnerCustomer.Status).GetDescription() : HospitalPartnerCustomerStatus.NotCalled.GetDescription(), Outcome = hospitalPartnerCustomer != null ? ((HospitalPartnerCustomerOutcome)hospitalPartnerCustomer.Outcome).GetDescription() : HospitalPartnerCustomerOutcome.NotCalled.GetDescription(), Care = care, LastModified = hospitalPartnerCustomer != null ? hospitalPartnerCustomer.DataRecorderMetaData.DateModified : null, Result = result, Recommendation = recommendation, Email = customer.Email != null ? customer.Email.ToString() : string.Empty, Address = Mapper.Map <Address, AddressViewModel>(customer.Address), ShippingMode = shippingDetail != null ? "Paper" : "Online", MailedStatus = shippingDetail != null ? shippingDetail.Status.ToString() : "Online", MailedOn = shippingDetail != null ? shippingDetail.ShipmentDate : null, HospitalPartnerName = hospitalPartnername ?? "N/A", CorporateSponsor = corporateAccountName ?? "N/A", TestSummary = pairTestSummary, PrimaryCarePhysicianName = primaryCarePhysician != null ? primaryCarePhysician.Name.FullName : "N/A", Activities = GetHospitalPartnerCustomerActivities(customerActivities, idNamePairs), PrimaryCare = primaryCareAnswer, MammogramProstateScreening = mammogramProstateScreeningAnswer, Colonoscopy = colonoscopyAnswer, Cancer = cancerAnswer, InitialCallDate = initialCallDate, WeightBariatric = weightBariatricAnswer, PostScreeningFollowUpNotes = postScreeningNotes, // PreferredLanguage = string.IsNullOrEmpty(customer.PreferredLanguage) ? "N/A" : customer.PreferredLanguage, PreferredLanguage = preferredLanguage, BestTimeToCall = customer.BestTimeToCall.HasValue && customer.BestTimeToCall.Value > 0 ? ((BestTimeToCall)customer.BestTimeToCall).GetDescription() : "N/A", EventCustomerId = ec.Id, HasCannedMessage = (hospitalPartner != null && !string.IsNullOrEmpty(hospitalPartner.CannedMessage) || hospitalFacility != null && !string.IsNullOrEmpty(hospitalFacility.CannedMessage)), IsCannedMessageSent = eventCustomerNotification != null, Ssn = (eventHospitalPartner != null && eventHospitalPartner.CaptureSsn && !string.IsNullOrEmpty(customer.Ssn) && customer.Ssn.Length >= 9) ? customer.Ssn.Substring(0, 3) + "-" + customer.Ssn.Substring(3, 2) + "-" + customer.Ssn.Substring(customer.Ssn.Length - 4) //"XXX-XX-" + customer.Ssn.Substring(customer.Ssn.Length - 4) : string.Empty, //"N/A" HospitalFacility = string.IsNullOrEmpty(hospitalFacilityName) ? "N/A" : hospitalFacilityName, ShowScannedDocumentUrl = showScannedDocumentUrl, ScannedDocumentUrl = scannedDocumentUrl, MemberId = string.IsNullOrEmpty(customer.InsuranceId) ? "N/A" : customer.InsuranceId }); }); model.Collection = customerModels; return(model); }
private void Mail() { var eventId = Session["EventID"] != null && !string.IsNullOrEmpty(Session["EventID"].ToString()) ? Convert.ToInt64(Session["EventID"]) : 0; var customerId = Session["CustomerId"] != null && !string.IsNullOrEmpty(Session["CustomerId"].ToString()) ? Convert.ToInt64(Session["CustomerId"]) : 0; var customerRepository = IoC.Resolve <ICustomerRepository>(); var customer = customerRepository.GetCustomer(customerId); var notifier = IoC.Resolve <INotifier>(); var emailNotificationModelsFactory = IoC.Resolve <IEmailNotificationModelsFactory>(); var currentSession = IoC.Resolve <ISessionContext>().UserSession; var appointmentConfirmationViewModel = emailNotificationModelsFactory.GetAppointmentConfirmationModel(eventId, customerId); var corporateAccountRepository = IoC.Resolve <ICorporateAccountRepository>(); var account = corporateAccountRepository.GetbyEventId(eventId); var eventCustomerNotificationRepository = IoC.Resolve <IEventCustomerNotificationRepository>(); var eventCustomerRepository = IoC.Resolve <IEventCustomerRepository>(); var emailTemplateRepository = IoC.Resolve <IEmailTemplateRepository>(); var logger = IoC.Resolve <ILogManager>().GetLogger <Global>(); var eventCustomer = eventCustomerRepository.Get(eventId, 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, currentSession.CurrentOrganizationRole.OrganizationRoleUserId, Request.Url.AbsolutePath, useAlternateEmail: true); if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false) { logger.Info("customer has not Subscribed for SMS customerId " + customer.CustomerId); return; } if (!eventCustomer.EnableTexting) { return; } if (account != null && !account.EnableSms) { logger.Info("account has disabled SMS, Account Tag: " + account.Tag); return; } var smsNotificaionModelFactory = IoC.Resolve <IPhoneNotificationModelsFactory>(); var eventRepository = IoC.Resolve <IEventRepository>(); var eventData = eventRepository.GetById(eventId); 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)); 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; } var smsNotificaionModel = smsNotificaionModelFactory.GetScreeningReminderSmsNotificationModel(customer, eventData); 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); } }
public bool SendCannedMessage(long eventCustomerId, long customerId) { var customerRepository = IoC.Resolve <ICustomerRepository>(); var customer = customerRepository.GetCustomer(customerId); if (customer.Email == null || string.IsNullOrEmpty(customer.Email.ToString())) { return(true); } var eventCustomerNotificationrepository = IoC.Resolve <IEventCustomerNotificationRepository>(); var messageAlreadySent = eventCustomerNotificationrepository.GetByEventCustomerId(eventCustomerId, NotificationTypeAlias.CannedMessageNotification); if (messageAlreadySent != null) { return(true); } var currentSession = _sessionContext.UserSession.CurrentOrganizationRole; var bodyText = string.Empty; var userService = IoC.Resolve <IUserService>(); var careCoordinatorUser = userService.GetUser(currentSession.OrganizationRoleUserId); if (currentSession.GetSystemRoleId == (long)Roles.HospitalPartnerCoordinator) { var eventCustomer = _eventCustomerRepository.GetById(eventCustomerId); if (eventCustomer.HospitalFacilityId.HasValue && eventCustomer.HospitalFacilityId.Value > 0) { var hospitalFacility = _hospitalFacilityRepository.GetHospitalFacility(eventCustomer.HospitalFacilityId.Value); if (!string.IsNullOrEmpty(hospitalFacility.CannedMessage)) { bodyText = hospitalFacility.CannedMessage; } } if (string.IsNullOrEmpty(bodyText)) { var hospitalPartnerId = currentSession.OrganizationId; var hospitalPartner = _hospitalPartnerRepository.GetHospitalPartnerforaVendor(hospitalPartnerId); bodyText = hospitalPartner.CannedMessage; } } else if (currentSession.CheckRole((long)Roles.HospitalFacilityCoordinator)) { var hospitalFacilityId = currentSession.OrganizationId; var hospitalFacility = _hospitalFacilityRepository.GetHospitalFacility(hospitalFacilityId); if (!string.IsNullOrEmpty(hospitalFacility.CannedMessage)) { bodyText = hospitalFacility.CannedMessage; } else { var hospitalPartnerId = _hospitalFacilityRepository.GetHospitalPartnerId(hospitalFacilityId); if (hospitalPartnerId > 0) { var hospitalPartner = _hospitalPartnerRepository.GetHospitalPartnerforaVendor(hospitalPartnerId); bodyText = hospitalPartner.CannedMessage; } } } var subjectText = "Mail from Care coordinator"; var notifier = IoC.Resolve <INotifier>(); var notification = notifier.NotifyCannedEmail(NotificationTypeAlias.CannedMessageNotification, careCoordinatorUser.Email, customer.Email.ToString(), subjectText, bodyText, customer.Id, currentSession.OrganizationRoleUserId, "Canned Message"); if (notification != null) { var eventCustomerNotification = new EventCustomerNotification { EventCustomerId = eventCustomerId, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id }; eventCustomerNotificationrepository.Save(eventCustomerNotification); } return(true); }
//[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)); }
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); } } }