public LabFormViewModel GetIfobtLabFormViewModel(long eventId, long customerId) { var eventData = _eventRepository.GetById(eventId); var customer = _customerRepository.GetCustomer(customerId); var host = _hostRepository.GetHostForEvent(eventData.Id); return(GetIfobtLabFormViewModel(eventData, customer, host)); }
// Belongs to Finance Domain public CustomerItemizedReceiptModel GetItemizedRecieptModel(long customerId, long eventId) { var customer = _customerRepository.GetCustomer(customerId); var host = _hostRepository.GetHostForEvent(eventId); var order = _orderRepository.GetOrder(customerId, eventId); var package = _eventPackageRepository.GetPackageForOrder(order.Id); var tests = _eventTestRepository.GetTestsForOrder(order.Id); IEnumerable <OrderedPair <long, long> > orderItemIdTestIdPair = null; //var orderitemIdsforTestitem = // order.OrderDetails.Where( // od => // od.DetailType == OrderItemType.EventTestItem && // od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess).Select(od => od.OrderItemId). // ToArray(); //if (orderitemIdsforTestitem.Count() > 0) // orderItemIdTestIdPair = _eventTestRepository.GetOrderItemIdandTestIdpair(orderitemIdsforTestitem); var products = _productRepository.GetProductNameForOrderItems(order.OrderDetails.Where(od => od.DetailType == OrderItemType.ProductItem && od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess).Select(od => od.OrderItemId).ToArray()); return(_itemizedRecieptModelFactory.Create(customer, host, order, package, tests, orderItemIdTestIdPair, products)); }
public EventCustomerPcpAppointmentEditModel GetEventCustomerEventModel(long eventcustomerId) { var eventCustomer = _eventCustomerRepository.GetById(eventcustomerId); var account = _corporateAccountRepository.GetbyEventId(eventCustomer.EventId); var customer = _customerRepository.GetCustomer(eventCustomer.CustomerId); var theEvent = _eventRepository.GetById(eventCustomer.EventId); var host = _hostRepository.GetHostForEvent(eventCustomer.EventId); var order = _orderRepository.GetOrder(eventCustomer.CustomerId, eventCustomer.EventId); var eventPackage = _eventPackageRepository.GetPackageForOrder(order.Id); var eventTest = _eventTestRepository.GetTestsForOrder(order.Id); var pcpDispositions = _pcpDispositionRepository.GetByCustomerIdEventId(eventCustomer.CustomerId, eventCustomer.EventId); var pcpAppointment = GetPcpAppointment(eventCustomer, pcpDispositions); PcpDisposition pcpDisposition = null; if (!pcpDispositions.IsNullOrEmpty()) { pcpDisposition = pcpDispositions.OrderByDescending(pd => pd.DataRecorderMetaData.DateCreated).First(); } var customerTest = new List<string>(); if (eventPackage != null) { customerTest.AddRange(eventPackage.Tests.Select(x => x.Test.Name)); } if (eventTest != null && eventTest.Any()) { customerTest.AddRange(eventTest.Select(x => x.Test.Name)); } var model = new EventCustomerPcpAppointmentEditModel { EventCustomerId = eventCustomer.Id, EventId = eventCustomer.EventId, CustomerId = customer.CustomerId, CustomerName = customer.Name, PhoneNumber = customer.HomePhoneNumber, CustomerEmail = customer.Email, ScreeningDate = theEvent.EventDate, HostName = host.OrganizationName, Location = host.Address, ScreenedForTest = customerTest, BookAfterNumberOfDays = account != null ? account.NumberOfDays : 0, NotAbleToSchedule = (pcpAppointment == null && pcpDisposition != null), DispositionId = (pcpAppointment == null && pcpDisposition != null) ? (long)pcpDisposition.Disposition : 0, Notes = (pcpAppointment == null && pcpDisposition != null) ? pcpDisposition.Notes : string.Empty, AppointmentDate = pcpAppointment != null ? pcpAppointment.AppointmentOn.Date : (DateTime?)null, AppointmentTime = pcpAppointment != null ? pcpAppointment.AppointmentOn.ToString("hh:mm: tt") : null, PreferredContactMethod = pcpAppointment != null ? pcpAppointment.PreferredContactMethod : -1, EventDate = theEvent.EventDate }; return model; }
public EventScreeningAuthorizationEditModel GetCustomersForAuthorization(long physicianId) { var eventData = _eventRepository.GetEventForAuthorization(physicianId); if (eventData == null) { return(null); } var host = _hostRepository.GetHostForEvent(eventData.Id); var eventTests = _eventTestRepository.GetTestsForEvent(eventData.Id); var eventPackages = _eventPackageRepository.GetPackagesForEvent(eventData.Id); var eventCustomers = _eventCustomerRepository.GetEventCustomersForAuthorization(eventData.Id); if (eventCustomers == null || eventCustomers.Count() < 1) { return(null); } var eventCustomerIds = eventCustomers.Select(ec => ec.Id).ToArray(); var assignments = _physicianAssignmentService.GetPhysicianAssignmentsByEventcustomerIds(eventCustomerIds); if (!assignments.Any(a => a.Primary.PhysicianId == physicianId)) { return(null); } eventCustomerIds = assignments.Where(a => a.Primary.PhysicianId == physicianId).Select(a => a.EventCustomerId).ToArray(); eventCustomers = eventCustomers.Where(ec => eventCustomerIds.Contains(ec.Id)).ToArray(); var orderIdEventCustomerIdPairs = _orderRepository.GetOrderEventCustomerIdPairforEventCustomerIds(eventCustomerIds); var orderIds = orderIdEventCustomerIdPairs.Select(p => p.FirstValue).ToArray(); var orderIdTestIdPairs = _eventTestRepository.GetEventTestIdForOrders(orderIds); var orderIdpackageIdPairs = _eventPackageRepository.GetEventPackageIdsForOrder(orderIds); var ecIdTestIdPairs = (from ec in orderIdEventCustomerIdPairs join ot in orderIdTestIdPairs on ec.FirstValue equals ot.FirstValue select new OrderedPair <long, long>(ec.SecondValue, ot.SecondValue)).ToArray(); var ecIdpackageIdPairs = (from ec in orderIdEventCustomerIdPairs join op in orderIdpackageIdPairs on ec.FirstValue equals op.FirstValue select new OrderedPair <long, long>(ec.SecondValue, op.SecondValue)).ToArray(); var customers = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).ToArray()); return(_eventScreeningAuthorizationEditModelFactory.Create(eventData, eventTests, eventCustomers, customers, eventPackages, ecIdpackageIdPairs, ecIdTestIdPairs, host)); }
public FluVaccinationConsentViewModel GetFluVaccinationConsentViewModel(long eventId, long customerId) { var eventData = _eventRepository.GetById(eventId); var host = _hostRepository.GetHostForEvent(eventId); var customer = _customerRepository.GetCustomer(customerId); var eventCustomer = _eventCustomerRepository.Get(eventId, customerId); var answers = _fluConsentAnswerRepository.GetByEventCustomerId(eventCustomer.Id); var questions = _fluConsentQuestionRepository.GetAllQuestions(); var signature = _fluConsentSignatureRepository.GetByEventCustomerId(eventCustomer.Id); var signatureFileIds = signature != null ? new[] { signature.SignatureFileId } : null; if (signature != null && signature.ClinicalProviderSignatureFileId.HasValue) { signatureFileIds = new[] { signature.SignatureFileId, signature.ClinicalProviderSignatureFileId.Value }; } var signatureFiles = !signatureFileIds.IsNullOrEmpty() ? _fileRepository.GetByIds(signatureFileIds) : null; return(GetFluVaccinationConsentViewModel(eventData, customer, host, questions, answers, signature, signatureFiles)); }
public void PollForPdfDownload() { try { if (_accountId <= 0) { return; } var corporateAccount = _corporateAccountRepository.GetById(_accountId); try { _logger.Info(string.Format("Genderating for accountId {0} and account tag {1}. ", corporateAccount.Id, corporateAccount.Tag)); var customSettingFilePath = string.Format(_customSettingFile, corporateAccount.Tag); var customSettings = _customSettingManager.Deserialize(customSettingFilePath); var exportToTime = DateTime.Now.AddHours(-1); var exportFromTime = customSettings.LastTransactionDate ?? _cutOfDate; DateTime?stopSendingPdftoHealthPlanDate = null; if (corporateAccount.IsHealthPlan) { stopSendingPdftoHealthPlanDate = _settings.StopSendingPdftoHealthPlanDate; } var eventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsToFax((int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false, exportToTime, exportFromTime, corporateAccount.Id, corporateAccount.Tag, true, stopSendingPdftoHealthPlanDate: stopSendingPdftoHealthPlanDate); var customerResults = eventCustomerResults as EventCustomerResult[] ?? eventCustomerResults.ToArray(); if (eventCustomerResults == null || !customerResults.Any()) { _logger.Info(string.Format("No event customer result list for {0} Result Pdf Download.", corporateAccount.Tag)); return; } _logger.Info(string.Format("Found {0} customers for {1} Result Pdf Download. ", eventCustomerResults.Count(), corporateAccount.Tag)); var pcpResultReport = _mediaRepository.GetPdfFileNameForPcpResultReport(); var healthPlanResultReport = _mediaRepository.GetPdfFileNameForHealthPlanResultReport(); var resultPostedToPlanFileName = Path.Combine(_resultPostedToPlanPath, string.Format("ResultPostedto_{0}.xml", corporateAccount.Tag)); var resultPosted = _resultPdfPostedSerializer.Deserialize(resultPostedToPlanFileName); resultPosted = resultPosted == null || resultPosted.Customer.IsNullOrEmpty() ? new ResultPdfPostedXml { Customer = new List <CustomerInfo>() } : resultPosted; var sftpFailedRecordsFileName = Path.Combine(_resultPostedToPlanPath, string.Format("CustomerResultsFailedOnSftp_{0}.xml", corporateAccount.Tag + "_ToWellmed")); var sftpFailedCustomers = _customerResultsFailedOnSftpSerializer.Deserialize(sftpFailedRecordsFileName); sftpFailedCustomers = sftpFailedCustomers == null || sftpFailedCustomers.EventCustomerIds.IsNullOrEmpty() ? new CustomerResultsFailedOnSftp { EventCustomerIds = new List <long>() } : sftpFailedCustomers; var newSftpFailedCustomers = new CustomerResultsFailedOnSftp { EventCustomerIds = new List <long>() }; if (!sftpFailedCustomers.EventCustomerIds.IsNullOrEmpty()) { var failedEventCustomerIds = sftpFailedCustomers.EventCustomerIds.Where(x => !customerResults.Select(ecr => ecr.Id).Contains(x)); if (!failedEventCustomerIds.IsNullOrEmpty()) { int totalRecords = failedEventCustomerIds.Count(); int pageNumber = 0; int pagesize = 100; while (true) { if (totalRecords < 1) { break; } var totalItems = pageNumber * pagesize; var customerIds = failedEventCustomerIds.Skip(totalItems).Take(pagesize); var failedEventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultsByIdsAndResultState(customerIds, (int)TestResultStateNumber.ResultDelivered, (int)NewTestResultStateNumber.ResultDelivered, false); if (!failedEventCustomerResults.IsNullOrEmpty()) { customerResults.Concat(failedEventCustomerResults); } pageNumber++; if (totalItems >= totalRecords) { break; } } } } foreach (var ecr in customerResults) { var sourcePath = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath + healthPlanResultReport; if (!File.Exists(sourcePath)) { sourcePath = _mediaRepository.GetPremiumVersionResultPdfLocation(ecr.EventId, ecr.CustomerId).PhysicalPath + pcpResultReport; } if (File.Exists(sourcePath)) { try { var customer = _customerRepository.GetCustomer(ecr.CustomerId); var eventData = _eventRepository.GetById(ecr.EventId); var host = _hostRepository.GetHostForEvent(ecr.EventId); if (!string.IsNullOrEmpty(customer.InsuranceId)) { var destinationFolderPdfPath = string.Empty; var destinationCatalystFolderPdfPath = string.Empty; //if (!string.IsNullOrEmpty(customer.GroupName) && _wellmedCustomerGroupName.Contains(customer.GroupName)) // destinationFolderPdfPath = _destinationCatalystFolderPdfPath + "\\" + host.Address.State + "\\" + eventData.EventDate.Year + "\\" + ecr.EventId; //else destinationFolderPdfPath = _destinationFolderPdfPath + "\\" + host.Address.State + "\\" + eventData.EventDate.Year + "\\" + ecr.EventId; var eventDirectoryPdf = GetDestinationFolderPath(destinationFolderPdfPath, customer, eventData.EventDate); var destinationFilename = ""; if (!string.IsNullOrEmpty(customer.GroupName)) { destinationFilename = RemoveIllegalFileChar(customer.GroupName) + "_" + RemoveIllegalFileChar(customer.InsuranceId); } else { destinationFilename = "NoGroup_" + RemoveIllegalFileChar(customer.InsuranceId); } if (corporateAccount.MarkPennedBack && ecr.IsPennedBack) { destinationFilename += "_" + corporateAccount.PennedBackText; } if (corporateAccount.ResultFormatTypeId == (long)ResultFormatType.PDF || corporateAccount.ResultFormatTypeId == (long)ResultFormatType.Both) { var fileName = "UHC_" + _resultPdfFileHelper.GetFileName(resultPosted.Customer, ecr, destinationFilename, (long)ResultFormatType.PDF); var resultPdfFile = eventDirectoryPdf + "/" + fileName + ".pdf"; _resultPdfDownloadHelper.ExportResultInPdfFormat(fileName + ".pdf", sourcePath, eventDirectoryPdf); if (File.Exists(resultPdfFile)) { var pgpFilePath = _pgpFileEncryptionHelper.EncryptFile(corporateAccount, resultPdfFile); } else { _logger.Info("File Not Found : " + resultPdfFile); } if (!string.IsNullOrEmpty(customer.GroupName) && _wellmedCustomerGroupName.Contains(customer.GroupName.ToLower())) { destinationCatalystFolderPdfPath = _destinationCatalystFolderPdfPath + "\\" + host.Address.State + "\\" + eventData.EventDate.Year + "\\" + ecr.EventId; var resultCatalystPdfFile = destinationCatalystFolderPdfPath + "/" + fileName + ".pdf"; _resultPdfDownloadHelper.ExportResultInPdfFormat(fileName + ".pdf", sourcePath, destinationCatalystFolderPdfPath); if (File.Exists(resultCatalystPdfFile)) { var pgpCatalystFilePath = _pgpFileEncryptionHelper.EncryptFile(corporateAccount, resultCatalystPdfFile); } else { _logger.Info("File Not Found : " + resultCatalystPdfFile); } } if (_sendReportToSftp) { var destinationSftpfolderPath = _destinationSftpFolderPdfPath + "\\" + host.Address.State + "\\" + eventData.EventDate.Year + "\\" + ecr.EventId; var resultPostedToSftp = false; if (ExportResultInSftp(fileName + ".pdf", sourcePath, destinationSftpfolderPath)) //GetDestinationFolderPath(destinationSftpfolderPath, customer, eventData.EventDate) { _logger.Info(string.Format("File Moved to Wellmed Sftp location for customer Id {0} and eventId {1}", ecr.CustomerId, ecr.EventId)); resultPostedToSftp = true; } if (resultPostedToSftp && !string.IsNullOrEmpty(customer.GroupName) && _wellmedCustomerGroupName.Contains(customer.GroupName.ToLower())) { var destinationSftpCatalystfolderPath = _destinationSftpCatalystFolderPdfPath + "\\" + host.Address.State + "\\" + eventData.EventDate.Year + "\\" + ecr.EventId; if (ExportResultInSftp(fileName + ".pdf", sourcePath, destinationSftpCatalystfolderPath)) { _logger.Info(string.Format("File Moved to Wellmed Catalyst Sftp location for customer Id {0} and eventId {1}", ecr.CustomerId, ecr.EventId)); } else { resultPostedToSftp = false; } } if (resultPostedToSftp) { resultPosted.Customer.Add(_resultPdfFileHelper.GetCustomerInfo(eventData, fileName + ".pdf", (long)ResultFormatType.PDF, customer, ecr.Id)); } else { newSftpFailedCustomers.EventCustomerIds.Add(ecr.Id); } } } if (corporateAccount.ResultFormatTypeId == (long)ResultFormatType.TIF || corporateAccount.ResultFormatTypeId == (long)ResultFormatType.Both) { var fileName = "UHC_" + _resultPdfFileHelper.GetFileName(resultPosted.Customer, ecr, destinationFilename, (long)ResultFormatType.TIF); var resultTifFile = eventDirectoryPdf + "/" + fileName + ".tif"; _resultPdfDownloadHelper.ExportResultInTiffFormat(fileName + ".tif", sourcePath, eventDirectoryPdf); if (File.Exists(resultTifFile)) { var pgpFilePath = _pgpFileEncryptionHelper.EncryptFile(corporateAccount, resultTifFile); resultPosted.Customer.Add(_resultPdfFileHelper.GetCustomerInfo(eventData, Path.GetFileName(pgpFilePath), (long)ResultFormatType.TIF, customer, ecr.Id)); } else { _logger.Info(string.Format("File {0} not Exit for pgp Encryption ", resultTifFile)); } } } else { _logger.Info(string.Format("member id is not found for customer {0} and eventId {1}", ecr.CustomerId, ecr.EventId)); } } catch (Exception exception) { _logger.Error(string.Format("some error occured for the customerId {0}, {1},\n Messagen {2} \n Stack Trace {3}", ecr.CustomerId, ecr.EventId, exception.Message, exception.StackTrace)); } } else { _logger.Info(string.Format("File not generated or removed for the customerId {0}, {1}", ecr.CustomerId, ecr.EventId)); } } customSettings.LastTransactionDate = exportToTime; _customSettingManager.SerializeandSave(customSettingFilePath, customSettings); if (resultPosted != null && !resultPosted.Customer.IsNullOrEmpty()) { _logger.Info("Result posted Log for " + corporateAccount.Tag); resultPosted = _resultPdfFileHelper.CorrectMissingRecords(resultPosted); var pdfLogfile = string.Format(_settings.PdfLogFilePath, corporateAccount.FolderName); pdfLogfile = Path.Combine(pdfLogfile, "Download"); try { _resultPdfFileHelper.CreateCsvForFileShared(resultPosted.Customer, pdfLogfile, corporateAccount.Tag + "_PdfLogFile"); } catch (Exception ex) { _logger.Error("some error occurred"); _logger.Error("exception: " + ex.Message); _logger.Error("stack trace: " + ex.StackTrace); } _logger.Info("Result posted Log Completed for " + corporateAccount.Tag); } _resultPdfPostedSerializer.SerializeandSave(resultPostedToPlanFileName, resultPosted); _customerResultsFailedOnSftpSerializer.SerializeandSave(sftpFailedRecordsFileName, newSftpFailedCustomers); } catch (Exception ex) { _logger.Error(string.Format("some error occured for AccountId: {0} and account tag: {1} Exception Message: \n{2}, \n stack Trace: \n\t {3} ", corporateAccount.Id, corporateAccount.Tag, ex.Message, ex.StackTrace)); } } catch (Exception exception) { _logger.Error(string.Format("some error occured Exception Message: \n{0}, \n stack Trace: \n\t {1} ", exception.Message, exception.StackTrace)); } }
public EventCustomerOrderSummaryModel GetEventCustomerOrderSummaryModel(TempCart tempCart, SourceCodeApplyEditModel sourceCodeModel = null) { if (tempCart == null) { return(new EventCustomerOrderSummaryModel()); } Event theEvent = null; Host eventHost = null; if (tempCart.EventId.HasValue) { theEvent = _eventRepository.GetById(tempCart.EventId.Value); eventHost = _hostRepository.GetHostForEvent(tempCart.EventId.Value); } EventSchedulingSlot appointment = null; if (tempCart.AppointmentId.HasValue) { appointment = _slotRepository.GetbyId(tempCart.AppointmentId.Value); } EventPackage eventPackage = null; if (tempCart.EventPackageId.HasValue) { eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value); } IEnumerable <EventTest> eventTests = null; var testIds = new List <long>(); if (!string.IsNullOrEmpty(tempCart.TestId)) { string[] testIdStrings = tempCart.TestId.Split(new[] { ',' }); foreach (var testIdString in testIdStrings) { int i = 0; if (int.TryParse(testIdString, out i)) { testIds.Add(i); } } } if (testIds.Count > 0) { eventTests = _eventTestRepository.GetbyIds(testIds); } IEnumerable <ElectronicProduct> products = null; var productIds = new List <long>(); if (!string.IsNullOrEmpty(tempCart.ProductId)) { string[] productIdStrings = tempCart.ProductId.Split(new[] { ',' }); foreach (var productIdIdString in productIdStrings) { int i = 0; if (int.TryParse(productIdIdString, out i)) { productIds.Add(i); } } } if (productIds.Count > 0) { products = _productRepository.GetByIds(productIds); } ShippingOption shippingOption = null; if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0) { shippingOption = _shippingOptionRepository.GetById(tempCart.ShippingId.Value); } SourceCodeApplyEditModel applySourceCodemodel = sourceCodeModel ?? GetSourceCodeApplied(tempCart); Order order = null; if (tempCart.IsCompleted) { order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value); } return(_eventCustomerSummaryModelFactory.Create(theEvent, eventHost, appointment, eventPackage, eventTests, products, shippingOption, applySourceCodemodel, order, tempCart.ShippingId)); }
public void Create(IEnumerable <EventCustomersEntity> eventCustomerEntities, IEnumerable <OrderedPair <long, long> > orgRoleUserIdUserIdPairs, IEnumerable <UserEntity> userEntities, IEnumerable <Address> addresses, IEnumerable <CustomerProfileEntity> customerProfileEntities, IEnumerable <EventsEntity> eventsEntities, IEnumerable <CustomerHealthInfoEntity> customerHealthInfoEntities, IEnumerable <OrderedPair <long, string> > careCoordinatorIdNamePair, IEnumerable <CustomerPrimaryCarePhysicianEntity> primaryCarePhysicianEntities, IEnumerable <Address> pcpAddresses, IEnumerable <EventAppointmentEntity> eventAppointmentEntities, string destinationDirectory) { long totalRecords = eventCustomerEntities.Count(); long counter = 1; _logger.Info("Total Records : " + totalRecords); var fileName = destinationDirectory + string.Format(@"\HRA-QA_{0}.csv", DateTime.Now.Date.ToString("yyyyMMdd")); if (!DirectoryOperationsHelper.IsDirectoryExist(destinationDirectory)) { DirectoryOperationsHelper.CreateDirectory(destinationDirectory); } WriteCsvHeader(fileName); foreach (var eventCustomerEntity in eventCustomerEntities) { try { _logger.Info(string.Format("Creating Model for event {0} and customer {1}", eventCustomerEntity.EventId, eventCustomerEntity.CustomerId)); var userId = orgRoleUserIdUserIdPairs.Where(oru => oru.FirstValue == eventCustomerEntity.CustomerId).Select(oru => oru.SecondValue).Single(); var user = userEntities.Where(u => u.UserId == userId).Select(u => u).Single(); var address = addresses.Where(a => a.Id == user.HomeAddressId).Select(a => a).Single(); var customer = customerProfileEntities.Where(cp => cp.CustomerId == eventCustomerEntity.CustomerId).Select(cp => cp).Single(); var eventData = eventsEntities.Where(e => e.EventId == eventCustomerEntity.EventId).Select(e => e).Single(); var primaryCarePhysician = primaryCarePhysicianEntities.Where(pcp => pcp.CustomerId == eventCustomerEntity.CustomerId).Select(pcp => pcp).FirstOrDefault(); var eventAppointment = eventAppointmentEntities.Where(ea => ea.AppointmentId == eventCustomerEntity.AppointmentId).Select(ea => ea).Single(); var hafAnswers = customerHealthInfoEntities.Where(chi => chi.EventCustomerId == eventCustomerEntity.EventCustomerId).Select(chi => chi).ToArray(); var answers = new List <OrderedPair <long, string> >(); foreach (var question in HouseCallHafResultExportHelper.Questions) { var hafAnswer = hafAnswers.Where(ha => ha.CustomerHealthQuestionId == question.FirstValue).Select(ha => ha).FirstOrDefault(); if (hafAnswer != null && question.FirstValue != 1233 && question.FirstValue != 1244) { if (receivedDateUnkownQuestionIds.Contains(question.FirstValue) || checkboxQuestionIds.Contains(question.FirstValue)) { if (!string.IsNullOrEmpty(hafAnswer.HealthQuestionAnswer)) { answers.Add(new OrderedPair <long, string>(question.FirstValue, "Yes")); } else { answers.Add(new OrderedPair <long, string>(question.FirstValue, "")); } } else if (hafAnswer.HealthQuestionAnswer == "RefusedDeclined") { answers.Add(new OrderedPair <long, string>(question.FirstValue, "Refused/Declined")); } else if (hafAnswer.HealthQuestionAnswer == "Retired disabled") { answers.Add(new OrderedPair <long, string>(question.FirstValue, "Retired/disabled")); } else if (hafAnswer.HealthQuestionAnswer == "Is it chronic pain") { answers.Add(new OrderedPair <long, string>(question.FirstValue, "It is chronic pain")); } else if (hafAnswer.HealthQuestionAnswer == "Is it acute pain") { answers.Add(new OrderedPair <long, string>(question.FirstValue, "It is acute pain")); } else { answers.Add(new OrderedPair <long, string>(question.FirstValue, hafAnswer.HealthQuestionAnswer)); } } else { if (question.FirstValue == 1177) { var healthQuestionAnswers = hafAnswers.Where(ha => assistiveDevicesUsedQuestionIds.Contains(ha.CustomerHealthQuestionId)).OrderBy(ha => ha.CustomerHealthQuestionId).Select(ha => ha.HealthQuestionAnswer); answers.Add(new OrderedPair <long, string>(question.FirstValue, string.Join(",", healthQuestionAnswers))); } else if (question.FirstValue == 1248) { var healthQuestionAnswers = hafAnswers.Where(ha => assistanceServicesUsedQuestionIds.Contains(ha.CustomerHealthQuestionId)).OrderBy(ha => ha.CustomerHealthQuestionId).Select(ha => ha.HealthQuestionAnswer); answers.Add(new OrderedPair <long, string>(question.FirstValue, string.Join(",", healthQuestionAnswers))); } else if (question.FirstValue == 1233) { var healthQuestionAnswers = hafAnswers.Where(ha => itemsNeededByFamilyMembersQuestionIds.Contains(ha.CustomerHealthQuestionId)).OrderBy(ha => ha.CustomerHealthQuestionId).Select(ha => ha.HealthQuestionAnswer); answers.Add(new OrderedPair <long, string>(question.FirstValue, string.Join(",", healthQuestionAnswers))); } else if (question.FirstValue == 1244) { var healthQuestionAnswers = hafAnswers.Where(ha => lackOfTransportationQuestionIds.Contains(ha.CustomerHealthQuestionId)).OrderBy(ha => ha.CustomerHealthQuestionId).Select(ha => ha.HealthQuestionAnswer); answers.Add(new OrderedPair <long, string>(question.FirstValue, string.Join(",", healthQuestionAnswers))); } else { answers.Add(new OrderedPair <long, string>(question.FirstValue, "")); } } } var model = new HouseCallHafResultExportModel { CustomerId = customer.CustomerId, MemberId = string.IsNullOrEmpty(customer.InsuranceId) ? "" : customer.InsuranceId, FirstName = user.FirstName, LastName = user.LastName, Dob = user.Dob, Gender = customer.Gender, Phone = user.PhoneHome, Address1 = address.StreetAddressLine1, City = address.City, State = address.State, Zip = address.ZipCode.Zip, EventId = eventData.EventId, HealthAssesmentAnswer = answers, RegistrationDate = eventCustomerEntity.DateCreated, }; if (model.EventId > 0) { var theEvent = _eventRepository.GetById(model.EventId); if (theEvent.HostId > 0) { var host = _hostRepository.GetHostForEvent(theEvent.Id); model.EventLocation = host.OrganizationName; model.EventAddress = host.Address.ToShortAddressString(); } } if (primaryCarePhysician != null) { model.PCPName = new Name(primaryCarePhysician.FirstName, primaryCarePhysician.MiddleName, primaryCarePhysician.LastName).FullName; var pcpAddress = pcpAddresses != null?pcpAddresses.Where(x => x.Id == primaryCarePhysician.Pcpaddress).FirstOrDefault() : null; if (pcpAddress != null) { model.PCPAddress = pcpAddress.StreetAddressLine1; model.PCPCity = pcpAddress.City; model.PCPState = pcpAddress.State; model.PCPZip = pcpAddress.ZipCode.Zip; } } if (eventAppointment != null) { model.AppointmentDate = eventAppointment.StartTime; model.AppointmentTime = eventAppointment.StartTime; } WriteCsv(model, fileName); _logger.Info(counter + " completed out of " + totalRecords); counter++; } catch (Exception ex) { _logger.Error(string.Format("\n\nFor Event {0} and Customer {1} \n Error:{2}", eventCustomerEntity.EventId, eventCustomerEntity.CustomerId, ex.Message)); } } }
public EventCustomerAggregate CreateEventCustomerAggregate(EventCustomer eventCustomer) { // Collect all the required data from different repositories. var eventData = _eventRepository.GetById(eventCustomer.EventId); var eventHost = _hostRepository.GetHostForEvent(eventCustomer.EventId); var appointment = _appointmentRepository.GetById(eventCustomer.AppointmentId.Value); var customer = _customerRepository.GetCustomer(eventCustomer.CustomerId); var order = _orderRepository.GetOrder(customer.CustomerId, eventData.Id); var activeOrderDetail = _orderController.GetActiveOrderDetail(order); if (eventHost == null || appointment == null || order == null || activeOrderDetail == null) { return(null); } var package = _packageRepository.GetById(activeOrderDetail.OrderItem.ItemId); string packageName = ""; if (package != null) { packageName = package.Package.Name; } var sourceCode = activeOrderDetail.SourceCodeOrderDetail != null?_sourceCodeRepository.GetSourceCodeById(activeOrderDetail.SourceCodeOrderDetail.SourceCodeId) : null; var paymentTypes = string.Join(",", order.PaymentsApplied.Select(pa => pa.PaymentType.Name).ToArray()); CustomerEventSignUpMode signUpMode = GetEventSignUpMode(eventCustomer); return(new EventCustomerAggregate { AppointmentId = eventCustomer.AppointmentId.Value, AppointmentTime = appointment.StartTime, CustomerAddress = customer.Address, CustomerId = customer.CustomerId, CustomerSignupDate = customer.DateCreated, EventAddress = eventHost.Address, EventCustomerId = eventCustomer.Id, EventDate = eventData.EventDate, EventId = eventData.Id, EventName = eventData.Name, EventSignupDate = eventCustomer.DataRecorderMetaData != null ? eventCustomer.DataRecorderMetaData.DateCreated : default(DateTime), EventStatus = eventData.Status, FirstName = customer.Name != null ? customer.Name.FirstName : string.Empty, IsPaid = order.TotalAmountPaid >= order.DiscountedTotal, LastName = customer.Name != null ? customer.Name.LastName : string.Empty, MarketingSource = eventCustomer.MarketingSource, MiddleName = customer.Name != null ? customer.Name.MiddleName : string.Empty, PackageName = packageName, PackageCost = activeOrderDetail.Price, PaidAmount = order.TotalAmountPaid, PaymentAmount = order.UndiscountedTotal, PaymentNet = order.DiscountedTotal, PaymentType = paymentTypes, SignUpMarketingSource = eventCustomer.MarketingSource, SignUpMode = signUpMode, SourceCode = sourceCode != null ? sourceCode.CouponCode : string.Empty, UnpaidAmount = order.TotalAmountPaid - order.DiscountedTotal }); }
public CustomerScreeningViewData GetCustomerScreeningViewData(long customerId, long eventId) { var eventCustomer = _eventCustomerRepository.Get(eventId, customerId); var customer = _customerRepository.GetCustomer(customerId); var theEvent = _eventRepository.GetById(eventId); var isNewResultFlow = theEvent.EventDate >= _settings.ResultFlowChangeDate; var testResults = GetTestResults(customerId, eventId, isNewResultFlow); var appointment = _appointmentRepository.GetEventCustomerAppointment(eventId, customerId); var order = _orderRepository.GetOrder(customerId, eventId); var package = _packageRepository.GetPackageForOrder(order.Id); var tests = _testRepository.GetTestsForOrder(order.Id); var evaluatingPhysicians = _physicianEvaluationRepsoitory.GetPhysicianEvaluation(eventCustomer.Id); var primaryEvalRecord = evaluatingPhysicians != null?evaluatingPhysicians.Where(p => p.IsPrimaryEvaluator).OrderByDescending(p => p.EvaluationEndTime ?? p.EvaluationStartTime).FirstOrDefault() : null; var primaryPhysicianId = primaryEvalRecord != null ? primaryEvalRecord.PhysicianId : 0; var overreadPhysicianId = primaryEvalRecord != null?evaluatingPhysicians.Where(p => !p.IsPrimaryEvaluator && p.EvaluationStartTime > primaryEvalRecord.EvaluationStartTime).OrderByDescending( p => p.EvaluationEndTime ?? p.EvaluationStartTime).Select(p => p.PhysicianId).FirstOrDefault() : 0; if (primaryPhysicianId < 1) { var assignment = _physicianAssignmentService.GetPhysicianIdsAssignedtoaCustomer(eventId, customerId); if (assignment != null) { primaryPhysicianId = assignment.First(); overreadPhysicianId = assignment.ElementAtOrDefault(1); } else // Should be Skip Evaluation Case { var physicians = testResults.Where(tr => tr.EvaluatedbyOrgRoleUserId > 0).Select(tr => tr.EvaluatedbyOrgRoleUserId).Distinct().ToArray(); if (physicians.Any()) { primaryPhysicianId = physicians.First(); } if (physicians.Count() > 1) { overreadPhysicianId = physicians.Last(); } } } if (primaryPhysicianId < 1) { //todo:default for the state primaryPhysicianId = _physicianRepository.GetDefaultPhysicianforEvent(eventId); } var primaryPhysician = _physicianRepository.GetPhysician(primaryPhysicianId); var overreadPhysician = overreadPhysicianId > 0 ? _physicianRepository.GetPhysician(overreadPhysicianId) : null; var host = _hostRepository.GetHostForEvent(eventId); var basicBiometric = _basicBiometricRepository.Get(eventId, customerId); CustomerScreeningViewData viewData = _factory.Create(testResults, customer, appointment, theEvent, package != null ? package.Package : null, tests != null ? tests.Select(t => t.Test).ToArray() : null, host, primaryPhysician, overreadPhysician, order, basicBiometric); if (order.PaymentsApplied != null) { var chargeCardPayments = order.PaymentsApplied.Where(pa => pa.PaymentType == PaymentType.CreditCard).Select( pa => (ChargeCardPayment)pa).ToArray(); if (chargeCardPayments.Count() > 0) { viewData.ChargeCards = _chargeCardRepository.GetByIds(chargeCardPayments.Select(cp => cp.ChargeCardId).ToArray()); } var checkPayments = order.PaymentsApplied.Where(pa => pa.PaymentType == PaymentType.Check).Select( pa => (CheckPayment)pa).ToArray(); if (checkPayments.Count() > 0) { viewData.Checks = _checkRepository.GetByIds(checkPayments.Select(c => c.CheckId).ToArray()); } } var eventHospitalPartner = _hospitalPartnerRepository.GetEventHospitalPartnersByEventId(eventId); if (eventHospitalPartner != null && eventHospitalPartner.RestrictEvaluation) { var eventPhysicianTests = _eventPhysicianTestRepository.GetByEventId(eventId); if (eventPhysicianTests != null && eventPhysicianTests.Any()) { viewData.EventPhysicianTests = eventPhysicianTests; } } return(viewData); }
public void Create(IEnumerable <EventCustomerResultEntity> eventCustomerResultEntities, IEnumerable <OrderedPair <long, long> > orgRoleUserIdUserIdPairs, IEnumerable <UserEntity> userEntities, IEnumerable <Address> addresses, IEnumerable <CustomerProfileEntity> customerProfileEntities, IEnumerable <EventsEntity> eventsEntities, IEnumerable <CustomerHealthInfoEntity> customerHealthInfoEntities, IEnumerable <OrderedPair <long, long> > eventIdPodIdPairs, IEnumerable <PodDetailsEntity> podDetailsEntities, IEnumerable <OrderedPair <long, long> > eventIdHospitalPartnerIdPairs, IEnumerable <OrderedPair <long, string> > hospitalPartnerIdNamePairs, IEnumerable <EventCustomerBasicBioMetricEntity> basicBioMetricEntities, IEnumerable <EventCustomersEntity> eventCustomersEntities, IEnumerable <EventAppointmentEntity> eventAppointmentEntities, IEnumerable <HospitalPartnerCustomerEntity> hospitalPartnerCustomerEntities, IEnumerable <OrderedPair <long, string> > careCoordinatorIdNamePair, IEnumerable <CustomerPrimaryCarePhysicianEntity> primaryCarePhysicianEntities, string destinationPath, IEnumerable <long> hafQuestionIds) { long totalRecords = eventCustomerResultEntities.Count(); long counter = 1; PcpResultExportHelper.Questions = PcpResultExportHelper.AllQuestions.Where(aq => hafQuestionIds.Contains(aq.FirstValue)).Select(aq => aq).ToArray(); _logger.Info("Total Records : " + totalRecords); WriteCsvHeader(destinationPath); foreach (var eventCustomerResultEntity in eventCustomerResultEntities) { try { _logger.Info(string.Format("Creating Model for event {0} and customer {1}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId)); var userId = orgRoleUserIdUserIdPairs.Where(oru => oru.FirstValue == eventCustomerResultEntity.CustomerId).Select(oru => oru.SecondValue).Single(); var user = userEntities.Where(u => u.UserId == userId).Select(u => u).Single(); var address = addresses.Where(a => a.Id == user.HomeAddressId).Select(a => a).Single(); var customer = customerProfileEntities.Where(cp => cp.CustomerId == eventCustomerResultEntity.CustomerId).Select(cp => cp).Single(); var eventData = eventsEntities.Where(e => e.EventId == eventCustomerResultEntity.EventId).Select(e => e).Single(); var podIds = eventIdPodIdPairs.Where(ep => ep.FirstValue == eventData.EventId).Select(ep => ep.SecondValue).ToArray(); var podName = string.Join(",", podDetailsEntities.Where(pd => podIds.Contains(pd.PodId)).Select(pd => pd.Name).ToArray()); var hospitalPartnerId = eventIdHospitalPartnerIdPairs.Where(ehp => ehp.FirstValue == eventData.EventId).Select(ehp => ehp.SecondValue).SingleOrDefault(); var hopitalPartnerName = hospitalPartnerIdNamePairs.Where(hp => hp.FirstValue == hospitalPartnerId).Select(hp => hp.SecondValue).SingleOrDefault(); var eventCustomer = eventCustomersEntities.Where(ec => ec.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(ec => ec).Single(); var eventAppointment = eventAppointmentEntities.Where(ea => ea.AppointmentId == eventCustomer.AppointmentId).Select(ea => ea).Single(); var primaryCarePhysician = primaryCarePhysicianEntities.Where(pcp => pcp.CustomerId == eventCustomerResultEntity.CustomerId).Select(pcp => pcp).FirstOrDefault(); var basicBimetric = basicBioMetricEntities.Where(bb => bb.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(bb => bb).FirstOrDefault(); var hafAnswers = customerHealthInfoEntities.Where(chi => chi.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(chi => chi).ToArray(); var answers = new List <OrderedPair <long, string> >(); foreach (var question in PcpResultExportHelper.Questions) { var hafAnswer = hafAnswers.Where(ha => ha.CustomerHealthQuestionId == question.FirstValue).Select(ha => ha).FirstOrDefault(); if (hafAnswer != null) { answers.Add(new OrderedPair <long, string>(question.FirstValue, hafAnswer.HealthQuestionAnswer)); } else { answers.Add(new OrderedPair <long, string>(question.FirstValue, "")); } } var age = string.Empty; if (user.Dob.HasValue) { var now = DateTime.Now; var checkCurrentLeapYear = new DateTime(now.Year, 3, 1); var birth = user.Dob.Value; var checkBirthLeapYear = new DateTime(birth.Year, 3, 1); var currentDayOfYear = now.DayOfYear; if (checkCurrentLeapYear.DayOfYear == 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear != 61) { currentDayOfYear = now.DayOfYear - 1; } else if (checkCurrentLeapYear.DayOfYear != 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear == 61) { currentDayOfYear = now.DayOfYear + 1; } var years = now.Year - birth.Year - ((currentDayOfYear < birth.DayOfYear) ? 1 : 0); var months = (12 + now.Month - birth.Month - ((now.Day < birth.Day) ? 1 : 0)) % 12; var days = now.Day - birth.Day; if (days < 0) { days = new DateTime(now.Year, now.Month, 1).AddDays(-1).AddDays(days).Day; } age = years.ToString(); } var ssn = "N/A"; if (!string.IsNullOrEmpty(user.Ssn)) { ssn = _cryptographyService.Decrypt(user.Ssn); if (ssn.Length >= 9) { ssn = ssn.Substring(0, 3) + "-" + ssn.Substring(3, 2) + "-" + ssn.Substring(ssn.Length - 4); } } var model = new PcpResultExportModel { CustomerId = customer.CustomerId, FirstName = user.FirstName, LastName = user.LastName, Address1 = address.StreetAddressLine1, City = address.City, State = address.State, Zip = address.ZipCode.Zip, Dob = user.Dob, Age = age, Height = customer.Height, Weight = customer.Weight > 0 ? customer.Weight.ToString() : "", Gender = customer.Gender, Race = customer.Race != "-1" ? customer.Race : "", Email = user.Email1, Phone = user.PhoneHome, Ssn = ssn, MemberId = string.IsNullOrEmpty(customer.InsuranceId) ? "" : customer.InsuranceId, Hicn = string.IsNullOrEmpty(customer.Hicn) ? "" : customer.Hicn, EventId = eventData.EventId, EventDate = eventData.EventDate, Pod = podName, HospitalPartner = hopitalPartnerName, Hipaa = ((RegulatoryState)eventCustomer.Hipaastatus).GetDescription(), CheckinTime = eventAppointment.CheckinTime.HasValue ? eventAppointment.CheckinTime.Value.ToShortTimeString() : "", CheckoutTime = eventAppointment.CheckoutTime.HasValue ? eventAppointment.CheckoutTime.Value.ToShortTimeString() : "", HealthAssesmentAnswer = answers, ResultSummary = eventCustomerResultEntity.ResultSummary.HasValue ? ((ResultInterpretation)eventCustomerResultEntity.ResultSummary).GetDescription() : "" }; if (primaryCarePhysician != null) { model.PrimaryPhysicianName = new Name(primaryCarePhysician.FirstName, primaryCarePhysician.MiddleName, primaryCarePhysician.LastName).FullName; } if (hospitalPartnerId > 0) { model.PartnerRelease = eventCustomer.PartnerRelease > 0 ? ((RegulatoryState)eventCustomer.PartnerRelease).GetDescription() : ""; var hospitalPartnerCustomer = hospitalPartnerCustomerEntities.LastOrDefault(hpc => hpc.EventId == eventCustomerResultEntity.EventId && hpc.CustomerId == eventCustomerResultEntity.CustomerId); model.CareCoordinatorStatus = hospitalPartnerCustomer != null ? ((HospitalPartnerCustomerStatus)hospitalPartnerCustomer.Status).GetDescription() : HospitalPartnerCustomerStatus.NotCalled.GetDescription(); model.CareCoordinatorOutcome = hospitalPartnerCustomer != null ? ((HospitalPartnerCustomerOutcome)hospitalPartnerCustomer.Outcome).GetDescription() : HospitalPartnerCustomerOutcome.NotScheduledNotInterested.GetDescription(); model.CareCoordinator = hospitalPartnerCustomer != null ? careCoordinatorIdNamePair.First(cc => cc.FirstValue == hospitalPartnerCustomer.CareCoordinatorOrgRoleUserId).SecondValue : "N/A"; model.CareCoordinatorNotes = hospitalPartnerCustomer != null ? hospitalPartnerCustomer.Notes : ""; } else { model.PartnerRelease = "N/A"; model.CareCoordinatorStatus = "N/A"; model.CareCoordinatorOutcome = "N/A"; model.CareCoordinator = "N/A"; model.CareCoordinatorNotes = "N/A"; } if (model.EventId > 0) { var theEvent = _eventRepository.GetById(model.EventId); if (theEvent.AccountId.HasValue && theEvent.AccountId > 0) { var organization = _organizationRepository.GetOrganizationbyId(theEvent.AccountId.Value); model.CorporateAccount = organization.Name; } if (theEvent.HostId > 0) { var host = _hostRepository.GetHostForEvent(theEvent.Id); model.EventLocation = host.OrganizationName + " @ " + host.Address; } } if (basicBimetric != null) { model.BloodPressure = (basicBimetric.SystolicPressure.HasValue ? basicBimetric.SystolicPressure.Value.ToString() : "0") + "/" + (basicBimetric.DiastolicPressure.HasValue ? basicBimetric.DiastolicPressure.Value.ToString() : "0"); model.PulseRate = basicBimetric.PulseRate.HasValue ? basicBimetric.PulseRate.Value.ToString() : ""; model.IsAbnormalBloodPressure = basicBimetric.IsBloodPressureElevated.HasValue && basicBimetric.IsBloodPressureElevated.Value ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString; } ITestResultRepository testResultRepository; var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvAAA); if (isTestPurchased) { _logger.Info("Setting Awv Aaa data."); testResultRepository = new AwvAaaTestRepository(); var awvAaaTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvAaaTestResult != null) { model = _awvAaaFactory.SetAwvAaaData(model, awvAaaTestResult as AwvAaaTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvEcho); if (isTestPurchased) { _logger.Info("Setting Awv Echo data."); testResultRepository = new AwvEchocardiogramTestRepository(); var awvEchoTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvEchoTestResult != null) { model = _awvEchoFactory.SetAwvEchoData(model, awvEchoTestResult as AwvEchocardiogramTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvCarotid); if (isTestPurchased) { _logger.Info("Setting Awv Carotid data."); testResultRepository = new AwvCarotidTestRepository(); var awvCarotidTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvCarotidTestResult != null) { model = _awvCarotidFactory.SetAwvCarotidData(model, awvCarotidTestResult as AwvCarotidTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvSpiro); if (isTestPurchased) { _logger.Info("Setting AWV Spiro data."); testResultRepository = new AwvSpiroTestRepository(); var awvSpiroTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvSpiroTestResult != null) { model = _awvSpiroFactory.SetAwvSpiroData(model, awvSpiroTestResult as AwvSpiroTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvABI); if (isTestPurchased) { _logger.Info("Setting Awv ABI data."); testResultRepository = new AwvAbiTestRepository(); var awvAbiTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvAbiTestResult != null) { model = _awvAbiFactory.SetAwvAbiData(model, awvAbiTestResult as AwvAbiTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvEkg); if (isTestPurchased) { _logger.Info("Setting Awv EKG data."); testResultRepository = new AwvEkgTestRepository(); var awvEkgTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvEkgTestResult != null) { model = _awvEkgFactory.SetAwvEkgData(model, awvEkgTestResult as AwvEkgTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.Vision); if (isTestPurchased) { _logger.Info("Setting Vision data."); testResultRepository = new VisionTestRepository(); var visionTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (visionTestResult != null) { model = _visionFactory.SetVisionData(model, visionTestResult as VisionTestResult); } } WriteCsv(model, destinationPath); _logger.Info(counter + " completed out of " + totalRecords); //if (counter > 10) // break; counter++; } catch (Exception ex) { _logger.Error(string.Format("\n\nFor Event {0} and Customer {1} \n Error:{2}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId, ex.Message)); } } }