public PartialViewResult GetEventRegisteredOn(long eventId, DateTime eventDate, string hostName, string hostAddress, DateTime?appointmentTime, string timeZone,
                                                      string pods, long eventCustomerId, bool isCancelled, bool isRescheduled)
        {
            var eventRegData = new RegisteredEventViewModel
            {
                EventId         = eventId,
                EventDate       = eventDate,
                HostName        = hostName,
                HostAddress     = hostAddress,
                AppointmentTime = appointmentTime,
                TimeZone        = timeZone,
                Pods            = pods,
                EventCustomerId = eventCustomerId,
                IsCanceled      = isCancelled,
                IsRescheduled   = isRescheduled,
            };

            return(PartialView(eventRegData));
        }
        public PreAssessmentCustomerContactViewModel GetByCustomerId(long customerId, long callId, long orgRoleUserId)
        {
            if (customerId <= 0)
            {
                return(null);
            }
            var       call          = _callCenterCallRepository.GetById(callId);
            var       eventCustomer = _eventCustomerRepository.Get(call.EventId, customerId);
            CallQueue callQueue     = null;

            if (call != null)
            {
                callQueue = _callQueueRepository.GetById((long)call.CallQueueId);
            }
            var customer = _customerRepository.GetCustomer(customerId);

            var memberIdLabel = string.Empty;
            CorporateAccount    corporateAccount    = null;
            CustomerEligibility customerEligibility = null;

            if (customer != null)
            {
                customerEligibility = _customerEligibilityRepository.GetByCustomerIdAndYear(customer.CustomerId, DateTime.Today.Year);
                if (!string.IsNullOrEmpty(customer.Tag))
                {
                    corporateAccount = _corporateAccountRepository.GetByTag(customer.Tag);
                    memberIdLabel    = corporateAccount != null ? corporateAccount.MemberIdLabel : string.Empty;
                }
            }

            var prospectCustomer = _prospectCustomerRepository.GetProspectCustomerByCustomerId(customerId);
            CallQueuePatientInfomationViewModel patientInfo = null;

            if (customer != null)
            {
                Falcon.App.Core.Medical.Domain.ActivityType activityType = null;
                if (customer.ActivityId.HasValue)
                {
                    activityType = _activityTypeRepository.GetById(customer.ActivityId.Value);
                }

                patientInfo = _preAssessmentCallQueuePatientInfomationFactory.SetCustomerInfo(customer, customerEligibility, activityType);
            }
            else
            {
                patientInfo = _preAssessmentCallQueuePatientInfomationFactory.SetProspectCustomerInfo(prospectCustomer);
            }


            if (patientInfo.HealthPlanPhoneNumber == null)
            {
                patientInfo.HealthPlanPhoneNumber = corporateAccount != null ? corporateAccount.CheckoutPhoneNumber : null;
            }
            var additionalFileds = new List <OrderedPair <string, string> >();

            if (corporateAccount != null)
            {
                var accountAdditionalFields = _accountAdditionalFieldRepository.GetByAccountId(corporateAccount.Id);
                if (accountAdditionalFields.Any())
                {
                    additionalFileds.AddRange(accountAdditionalFields.Select(additionalField => new OrderedPair <string, string>(additionalField.DisplayName,
                                                                                                                                 GetCustomerAdditionalField(customer, additionalField.AdditionalFieldId))));
                }
                if (corporateAccount.ShowCallCenterScript && corporateAccount.CallCenterScriptFileId > 0)
                {
                    var callCenterScriptPdf = _fileRepository.GetById(corporateAccount.CallCenterScriptFileId);
                    var mediaLocation       = _mediaRepository.GetCallCenterScriptPdfFolderLocation();
                    patientInfo.CallCenterScriptUrl = mediaLocation.Url + callCenterScriptPdf.Path;
                }
                if (callQueue != null && callQueue.Category == HealthPlanCallQueueCategory.PreAssessmentCallQueue)
                {
                    if (corporateAccount.ShowCallCenterScript && corporateAccount.ConfirmationScriptFileId > 0)
                    {
                        var confirmationScriptPdf = _fileRepository.GetById(corporateAccount.ConfirmationScriptFileId);
                        var mediaLocation         = _mediaRepository.GetCallCenterScriptPdfFolderLocation();
                        patientInfo.CallCenterScriptUrl = mediaLocation.Url + confirmationScriptPdf.Path;
                    }
                }
            }
            var hasMammo = customer != null && _preApprovedTestRepository.CheckPreApprovedTestForCustomer(customer.CustomerId, TestGroup.BreastCancer);

            patientInfo.HasMammo = hasMammo;

            patientInfo.MammoTestAsPreApproved = hasMammo;

            patientInfo.CustomerId         = customerId;
            patientInfo.ProspectCustomerId = prospectCustomer != null ? prospectCustomer.Id : 0;

            patientInfo = _preAssessmentCallQueuePatientInfomationFactory.SetCustomerTagInfo(prospectCustomer, patientInfo);

            if (patientInfo != null && callQueue != null && callQueue.IsHealthPlan)
            {
                patientInfo.PrimaryCarePhysician = _primaryCarePhysicianHelper.GetPrimaryCarePhysicianViewModel(customerId);
            }

            if (customer != null)
            {
                var customerCustomTags = _corporateCustomerCustomTagRepository.GetByCustomerId(customer.CustomerId);
                if (!customerCustomTags.IsNullOrEmpty())
                {
                    var customTags = customerCustomTags.OrderByDescending(x => x.DataRecorderMetaData.DateCreated).Select(x => x.Tag).ToArray();
                    patientInfo.CustomCorporateTags = customTags.IsNullOrEmpty() ? string.Empty : string.Join(",", customTags);
                }
            }

            IEnumerable <string> preApprovedTests = null;
            var preApprovedTestsList = _preApprovedTestRepository.GetPreApprovedTests(customerId);

            if (preApprovedTestsList.Count() > 0)
            {
                preApprovedTests = preApprovedTestsList;
            }

            IEnumerable <Package> preApprovedPackages = null;
            var preApprovedPackageList = _preApprovedPackageRepository.GetByCustomerId(customerId);
            var packageIds             = preApprovedPackageList != null?preApprovedPackageList.Select(x => x.PackageId) : null;

            if (packageIds != null)
            {
                preApprovedPackages = _packageRepository.GetByIds(packageIds.ToList());
            }

            if (customer != null && customer.Address != null && customer.Address.StateId > 0 && corporateAccount != null)
            {
                patientInfo.HealthPlanPhoneNumber = _customerAccountGlocomNumberService.GetGlocomNumber(corporateAccount.Id, customer.Address.StateId, customer.CustomerId, callId);
            }

            if (patientInfo.HealthPlanPhoneNumber == null)
            {
                patientInfo.HealthPlanPhoneNumber = corporateAccount != null ? corporateAccount.CheckoutPhoneNumber : null;
            }

            if (patientInfo.HealthPlanPhoneNumber != null)
            {
                string dialerUrl;
                var    callCenterRepProfile = _callCenterRepProfileRepository.Get(orgRoleUserId);
                if (callCenterRepProfile != null && !string.IsNullOrEmpty(callCenterRepProfile.DialerUrl))
                {
                    dialerUrl = callCenterRepProfile.DialerUrl.ToLower().Replace(CallCenterAgentUrlKeywords.CallerId.ToLower(), (patientInfo.HealthPlanPhoneNumber.AreaCode + patientInfo.HealthPlanPhoneNumber.Number))
                                .Replace(CallCenterAgentUrlKeywords.PatientId.ToLower(), patientInfo.CustomerId.ToString());
                }
                else
                {
                    dialerUrl = "Glocom://*65*" + patientInfo.HealthPlanPhoneNumber.AreaCode + patientInfo.HealthPlanPhoneNumber.Number + "*1" + CallCenterAgentUrlKeywords.PatientContact.ToLower();
                }

                if (patientInfo.CallBackPhoneNumber != null)
                {
                    patientInfo.CallBackPhoneNumberUrl = dialerUrl.Replace(CallCenterAgentUrlKeywords.PatientContact.ToLower(), (patientInfo.CallBackPhoneNumber.AreaCode + patientInfo.CallBackPhoneNumber.Number));
                }

                if (patientInfo.OfficePhoneNumber != null)
                {
                    patientInfo.OfficePhoneNumberUrl = dialerUrl.Replace(CallCenterAgentUrlKeywords.PatientContact.ToLower(), (patientInfo.OfficePhoneNumber.AreaCode + patientInfo.OfficePhoneNumber.Number));
                }

                if (patientInfo.MobilePhoneNumber != null && !string.IsNullOrEmpty(patientInfo.MobilePhoneNumber.Number))
                {
                    patientInfo.MobilePhoneNumberUrl = dialerUrl.Replace(CallCenterAgentUrlKeywords.PatientContact.ToLower(), (patientInfo.MobilePhoneNumber.AreaCode + patientInfo.MobilePhoneNumber.Number));
                }
            }

            var preAssessmentCustomerCallQueueCallAttempt = _preAssessmentCustomerCallQueueCallAttemptRepository.GetByCallId(callId);

            RegisteredEventViewModel registeredEventModel = null;
            var isCancelled = false;

            if (callQueue != null && callQueue.Category == HealthPlanCallQueueCategory.PreAssessmentCallQueue && call.EventId > 0)
            {
                var         isEawvPurchased = _testResultService.IsTestPurchasedByCustomer(eventCustomer.Id, (long)TestType.eAWV);
                Appointment appointment     = null;
                if (eventCustomer.AppointmentId.HasValue)
                {
                    appointment = _appointmentRepository.GetById(eventCustomer.AppointmentId.Value);
                }
                else
                {
                    isCancelled = true;
                }

                var theEvent = _eventService.GetById(eventCustomer.EventId);

                var hostAddress = new AddressViewModel
                {
                    StreetAddressLine1 = theEvent.StreetAddressLine1,
                    StreetAddressLine2 = theEvent.StreetAddressLine2,
                    City    = theEvent.City,
                    State   = theEvent.State,
                    ZipCode = theEvent.Zip
                };

                QuestionnaireType questionnaireType = QuestionnaireType.None;
                if (corporateAccount != null && corporateAccount.IsHealthPlan && theEvent != null)
                {
                    questionnaireType = _accountHraChatQuestionnaireHistoryServices.QuestionnaireTypeByAccountIdandEventDate(corporateAccount.Id, theEvent.EventDate);
                }

                registeredEventModel = new RegisteredEventViewModel
                {
                    EventId             = theEvent.EventId,
                    EventDate           = theEvent.EventDate,
                    AppointmentTime     = appointment != null ? appointment.StartTime : (DateTime?)null,
                    HostName            = theEvent.OrganizationName,
                    HostAddress         = hostAddress.ToString(),
                    EventNotes          = "",
                    EventCustomerId     = eventCustomer.Id,
                    TimeZone            = theEvent.EventTimeZone,
                    IsCanceled          = isCancelled,
                    HraQuestionerAppUrl = _settings.HraQuestionerAppUrl,
                    OrganizationNameForHraQuestioner = _settings.OrganizationNameForHraQuestioner,
                    CorporateAccountTag = corporateAccount.Tag,
                    MedicareVisitId     = eventCustomer.AwvVisitId.HasValue ? eventCustomer.AwvVisitId.Value : 0,
                    Pods = theEvent.Pods.IsNullOrEmpty() ? "" : theEvent.PodNames(),
                    ShowHraQuestionnaire = questionnaireType == QuestionnaireType.HraQuestionnaire ? true : false,
                    IsEawvPurchased      = isEawvPurchased,

                    ShowChatQuestionnaire = questionnaireType == QuestionnaireType.ChatQuestionnaire ? true : false,
                    ChatQuestionerAppUrl  = _settings.ChatQuestionerAppUrl,
                    AllowNonMammoPatients = theEvent.AllowNonMammoPatients,
                    CaptureHaf            = corporateAccount != null && corporateAccount.CaptureHaf,
                };

                preAssessmentCustomerCallQueueCallAttempt.IsNotesReadAndUnderstood = true;
            }
            if (corporateAccount != null)
            {
                var organization = _organizationRepository.GetOrganizationbyId(corporateAccount.Id);
                patientInfo.HealthPlan = organization.Name;
            }

            var warmTransfer = false;

            if (customer != null && corporateAccount != null && corporateAccount.WarmTransfer)
            {
                var customerWarmTransfer = _customerWarmTransferRepository.GetByCustomerIdAndYear(customer.CustomerId, DateTime.Today.Year);
                warmTransfer = customerWarmTransfer != null && customerWarmTransfer.IsWarmTransfer.HasValue && customerWarmTransfer.IsWarmTransfer.Value;
            }

            var model = new PreAssessmentCustomerContactViewModel
            {
                PatientInfomation = patientInfo,
                // CallHistory = callHistoryModel,
                PreApprovedTests = preApprovedTests,
                //    ReadAndUnderstood = currentCall != null && currentCall.ReadAndUnderstood.HasValue && currentCall.ReadAndUnderstood.Value,
                AdditionalFields = additionalFileds,
                MemberIdLabel    = memberIdLabel,
                //  IsCallEnded = currentCall != null && currentCall.Status == (long)CallStatus.CallSkipped && currentCall.EndTime.HasValue,
                PreApprovedPackages = !preApprovedPackages.IsNullOrEmpty() ? preApprovedPackages.Select(x => x.Name).ToList() : null,
                CallId                   = callId,
                HealthPlanId             = corporateAccount != null ? corporateAccount.Id : 0,
                CallQueueCustomerAttempt = preAssessmentCustomerCallQueueCallAttempt ?? new PreAssessmentCustomerCallQueueCallAttempt {
                    IsNotesReadAndUnderstood = true
                },
                EventInformation = registeredEventModel,
                WarmTransfer     = warmTransfer,
                // RequiredTests = requiredTests,
            };
            var isHealthPlanCallQueue = call != null;
            var patientInfoEditModel  = _preAssessmentCallQueuePatientInfomationFactory.GetCallQueueCustomerEditModel(model, isHealthPlanCallQueue);

            model.PatientInfoEditModel     = patientInfoEditModel;
            model.PatientInfoEditViewModel = patientInfoEditModel;
            return(model);
        }