public IActionResult Index()
        {
            var model = _insuranceCompanyRepository.GetAll()
                        .Select(i => new IndexViewModel
            {
                Id              = i.Id,
                Name            = i.Name,
                DiscountPercent = i.DiscountPercent
            }).ToList();

            return(View(model));
        }
Beispiel #2
0
        public IEnumerable <SelectListItem> GetComboInsurances()
        {
            var list = _insuranceRepository.GetAll().Select(s => new SelectListItem
            {
                Text  = s.Name,
                Value = s.Id.ToString()
            }).OrderBy(l => l.Text).ToList();

            list.Insert(0, new SelectListItem
            {
                Text  = "(Select an Insurance Company...)",
                Value = "0"
            });

            return(list);
        }
Beispiel #3
0
        public IEnumerable <InsuranceDetailViewModel> GetInsuranceDetailByEventCustomerIds(IEnumerable <long> eventCustomerIds)
        {
            var eligibilities = _eligibilityRepository.GetByEventCustomerIds(eventCustomerIds);

            if (eligibilities != null && eligibilities.Any())
            {
                var insurancedetailViewModels = new List <InsuranceDetailViewModel>();

                var eventCustomerEligibilities = _eligibilityRepository.GetEventCustomerEligibilityIdByEventCustomerIds(eventCustomerIds);

                var insuranceCompanies = _insuranceCompanyRepository.GetAll();

                eligibilities.ToList().ForEach(e =>
                {
                    var response = JsonConvert.DeserializeObject <EligibleResponse>(e.Response);
                    InsuranceCompany insuranceCompany = null;
                    if (response.PrimaryInsurance != null)
                    {
                        insuranceCompany = insuranceCompanies.FirstOrDefault(ic => ic.Code == response.PrimaryInsurance.Id);
                    }
                    else if (response.Insurance != null)
                    {
                        insuranceCompany = insuranceCompanies.FirstOrDefault(ic => ic.Code == response.Insurance.Id);
                    }

                    if (insuranceCompany == null)
                    {
                        insuranceCompany = insuranceCompanies.First(ic => ic.Id == e.InsuranceCompanyId);
                    }

                    var eventCustomerEligibility = eventCustomerEligibilities.First(ece => ece.EligibilityId == e.Id);

                    insurancedetailViewModels.Add(new InsuranceDetailViewModel
                    {
                        EventCustomerId  = eventCustomerEligibility.EventCustomerId,
                        MemberId         = response.Demographics.Subscriber.MemberId,
                        InsuranceCompany = insuranceCompany.Name,
                        PlanName         = response.Plan.PlanName,
                        PlanId           = string.IsNullOrEmpty(response.Plan.PlanNumber) ? "N/A" : response.Plan.PlanNumber,
                        GroupName        = string.IsNullOrEmpty(response.Demographics.Subscriber.GroupName) ? "N/A" : response.Demographics.Subscriber.GroupName,
                        GroupId          = string.IsNullOrEmpty(response.Demographics.Subscriber.GroupId) ? "N/A" : response.Demographics.Subscriber.GroupId,
                    });
                });
                return(insurancedetailViewModels);
            }
            return(null);
        }
Beispiel #4
0
 /// <summary>
 /// Method whose purpose is to return all
 /// insurance company records from the database.
 /// </summary>
 /// <returns>
 /// Returns all insurance company objects as a IList
 /// of InsuranceCompanyModel objects.
 /// </returns>
 public IList <InsuranceCompanyModel> GetAll()
 {
     return(_insuranceCompanyRepository.GetAll());
 }
        public void PollforInsuranceEncounter()
        {
            const int pageSize   = 50;
            int       pageNumber = 1;

            _logger.Info("\n");
            _logger.Info(string.Format("Creating Patients and Encounter. Date: {0:MM/dd/yyyy}", DateTime.Now));
            _logger.Info("\n");

            var filter = new InsurancePaymentListModelFilter
            {
                EventFrom = DateTime.Now.Date.AddDays(-1),
                EventTo   = DateTime.Now.Date.AddDays(-1)
            };

            while (true)
            {
                try
                {
                    int totalRecords;

                    var eventCustomers = _eventCustomerRepository.GetInsurancePayment(pageNumber, pageSize, filter, out totalRecords);

                    if (eventCustomers == null || !eventCustomers.Any())
                    {
                        _logger.Info("No Records Found!");
                        break;
                    }

                    var insuranceCompanies  = _insuranceCompanyRepository.GetAll();
                    var billingAccounts     = _billingAccountRepository.GetAll();
                    var billingAccountTests = _billingAccountRepository.GetAllBillingAccountTests();

                    if (billingAccounts == null || !billingAccounts.Any())
                    {
                        _logger.Info("No billing account has been setup");
                        break;
                    }

                    if (billingAccountTests == null || !billingAccountTests.Any())
                    {
                        _logger.Info("No billing account test has been setup");
                        break;
                    }
                    //var response = _kareoApi.GetPatient(4, billingAccounts.First());
                    foreach (var eventCustomer in eventCustomers)
                    {
                        if (eventCustomer.NoShow || !eventCustomer.AppointmentId.HasValue || !eventCustomer.LeftWithoutScreeningReasonId.HasValue)
                        {
                            continue;
                        }

                        var appointment = _appointmentRepository.GetById(eventCustomer.AppointmentId.Value);

                        if (!appointment.CheckInTime.HasValue)
                        {
                            continue;
                        }

                        _logger.Info(string.Format("Creating Patient and Encounter for Event (Id: {0}) and Customer (Id: {1})", eventCustomer.EventId, eventCustomer.CustomerId));
                        _logger.Info("\n");

                        var customer    = _customerRepository.GetCustomer(eventCustomer.CustomerId);
                        var eventData   = _eventRepository.GetById(eventCustomer.EventId);
                        var eligibility = _eligibilityRepository.GetByEventCustomerId(eventCustomer.Id);
                        var pcp         = _primaryCarePhysicianRepository.Get(eventCustomer.CustomerId);

                        var eventTests = new List <EventTest>();

                        var orderId       = _orderRepository.GetOrderIdByEventCustomerId(eventCustomer.Id);
                        var eventPackage  = _eventPackageRepository.GetPackageForOrder(orderId);
                        var alaCarteTests = _eventTestRepository.GetTestsForOrder(orderId);

                        if (eventPackage != null)
                        {
                            foreach (var test in eventPackage.Tests)
                            {
                                test.Price = test.Test.PackagePrice;
                            }
                            eventTests.AddRange(eventPackage.Tests);
                        }

                        if (alaCarteTests != null && alaCarteTests.Any())
                        {
                            eventTests.AddRange(alaCarteTests);
                        }

                        foreach (var billingAccount in billingAccounts)
                        {
                            var billingAccountTestIds = billingAccountTests.Where(bat => bat.BillingAccountId == billingAccount.Id).Select(bat => bat.TestId).ToArray();

                            var insuranceTests = eventTests.Where(et => billingAccountTestIds.Contains(et.TestId)).Select(et => et).ToArray();
                            if (insuranceTests == null || !insuranceTests.Any())
                            {
                                continue;
                            }

                            long patientId;
                            var  customerBillingAccount = _customerBillingAccountRepository.GetByCustomerIdBillingAccountId(eventCustomer.CustomerId, billingAccount.Id);
                            if (customerBillingAccount != null)
                            {
                                patientId = customerBillingAccount.BillingPatientId;
                            }
                            else
                            {
                                var patientResponse = _kareoApi.CreatePatient(customer, eligibility, insuranceCompanies, pcp, billingAccount);
                                if (!patientResponse.PatientID.HasValue)
                                {
                                    _logger.Info(string.Format("Patient not created for Event (Id: {0}) and Customer (Id: {1}) and Billing Account {2}", eventCustomer.EventId, eventCustomer.CustomerId, billingAccount.Name));
                                    _logger.Info("\n");
                                    continue;
                                }

                                customerBillingAccount = new CustomerBillingAccount()
                                {
                                    BillingAccountId = billingAccount.Id,
                                    BillingPatientId = patientResponse.PatientID.Value,
                                    CustomerId       = customer.CustomerId,
                                    DateCreated      = DateTime.Now
                                };
                                _customerBillingAccountRepository.Save(customerBillingAccount);

                                patientId = patientResponse.PatientID.Value;

                                _logger.Info(string.Format("Patient created for Event (Id: {0}) and Customer (Id: {1}) and Billing Account {2}", eventCustomer.EventId, eventCustomer.CustomerId, billingAccount.Name));
                            }

                            if (patientId > 0)
                            {
                                var encounterResponse = _kareoApi.CreateEncounter(patientId, eventData, insuranceTests, billingAccount);
                                if (encounterResponse.EncounterID > 0)
                                {
                                    var encounter = new Encounter
                                    {
                                        Id = encounterResponse.EncounterID,
                                        BillingAccountId = billingAccount.Id,
                                        DateCreated      = DateTime.Now
                                    };
                                    encounter = _encounterRepository.Save(encounter);
                                    _encounterRepository.SaveEventCustomerEncounter(eventCustomer.Id, encounter.Id);

                                    _logger.Info(string.Format("Encounter created for Event (Id: {0}) and Customer (Id: {1}) and Billing Account {2}", eventCustomer.EventId, eventCustomer.CustomerId, billingAccount.Name));
                                }
                                else
                                {
                                    _logger.Info(string.Format("Encounter not created for Event (Id: {0}) and Customer (Id: {1}) and Billing Account {2}", eventCustomer.EventId, eventCustomer.CustomerId, billingAccount.Name));
                                    _logger.Info("\n");
                                }
                            }
                        }
                    }

                    if ((pageNumber * pageSize) >= totalRecords)
                    {
                        break;
                    }

                    pageNumber++;
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Error while fetching event customers Message:{0} \nStackTrace: {1}", ex.Message, ex.StackTrace));
                    _logger.Info("\n");
                    break;
                }
            }
        }