Exemple #1
0
        public bool CodingCompleted(MedicareCustomerResultCodedViewModel codingCompleted)
        {
            try
            {
                _logger.Info("Running CodingCompled API for Aces for Customer Id: " + codingCompleted.CustomerId + " EventId : " + codingCompleted.EventId);

                if (string.IsNullOrWhiteSpace(codingCompleted.EmployeeId))
                {
                    _logger.Info("EmployeeId is blank. CodingCompleted API for Customer Id: " + codingCompleted.CustomerId + " EventId : " + codingCompleted.EventId);
                    return(false);
                }

                var oru = _organizationRoleUserRepository.GetOrganizationRoleUserByEmployeeIdandRoleId(codingCompleted.EmployeeId, (long)Roles.Coder);
                if (oru == null)
                {
                    _logger.Info("EmployeeId or Coder role not exist. CodingCompleted API for Customer Id: " + codingCompleted.CustomerId + " EventId : " + codingCompleted.EventId);
                    return(false);
                }

                var account = _corporateAccountRepository.GetbyEventId(codingCompleted.EventId);

                if (account != null && account.IsHealthPlan)
                {
                    var eventCustomer   = _eventCustomerRepository.Get(codingCompleted.EventId, codingCompleted.CustomerId);
                    var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventCustomer.Id, (long)TestType.eAWV);

                    var theEvent = _eventRepository.GetById(codingCompleted.EventId);

                    var questionnaireType = _accountHraChatQuestionnaireHistoryServices.QuestionnaireTypeByAccountIdandEventDate(account.Id, theEvent.EventDate);

                    if ((questionnaireType != QuestionnaireType.HraQuestionnaire) || !isTestPurchased)
                    {
                        _testResultService.SaveCustomerResultCoded(codingCompleted, oru);
                        _logger.Info("customer result state Updated for Customer Id: " + codingCompleted.CustomerId + " EventId : " + codingCompleted.EventId);
                    }

                    else
                    {
                        _logger.Info("Only HRA is allowed to update for customer Id: " + codingCompleted.CustomerId + "  EventId: " + codingCompleted.EventId);
                        return(false);
                    }
                }
                else
                {
                    _logger.Info("Coding Completed can be marked only for HealthPlan Events. Customer Id: " + codingCompleted.CustomerId + "  EventId: " + codingCompleted.EventId);
                    return(false);
                }

                _logger.Info("completed CodingCompleted API for Customer Id: " + codingCompleted.CustomerId + " EventId : " + codingCompleted.EventId + " Successfully");
                return(true);
            }
            catch (Exception ex)
            {
                _logger.Info("completed CodingCompleted API for Customer Id: " + codingCompleted.CustomerId + " EventId : " + codingCompleted.EventId + " With Error");
                _logger.Error("Message: " + ex.Message);
                _logger.Error("StackTrace: " + ex.StackTrace);

                return(false);
            }
        }
        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);
        }