private void ExtractData(PatientDashboardDataEventArgs data)
 {
     _listInsPlans = data.ListInsPlans;
     _listInsSubs  = data.ListInsSubs;
     _listPatPlans = data.ListPatPlans;
     _listBenefits = data.ListBenefits;
     _histList     = data.HistList ?? ClaimProcs.GetHistList(_pat.PatNum, _listBenefits, _listPatPlans, _listInsPlans, DateTime.Today, _listInsSubs);
     _pat          = data.Pat;
 }
 public void RefreshData(Patient pat, SheetField sheetField)
 {
     _listInsPlans = new List <InsPlan>();
     _listInsSubs  = new List <InsSub>();
     _listPatPlans = new List <PatPlan>();
     _listBenefits = new List <Benefit>();
     _histList     = new List <ClaimProcHist>();
     _pat          = pat;
     if (_pat == null)
     {
         return;
     }
     _listPatPlans = PatPlans.Refresh(_pat.PatNum);
     _listInsSubs  = InsSubs.RefreshForFam(Patients.GetFamily(_pat.PatNum));
     _listInsPlans = InsPlans.RefreshForSubList(_listInsSubs);
     _listBenefits = Benefits.Refresh(_listPatPlans, _listInsSubs);
     _histList     = ClaimProcs.GetHistList(_pat.PatNum, _listBenefits, _listPatPlans, _listInsPlans, DateTime.Today, _listInsSubs);
 }
Example #3
0
        ///<summary>Runs Procedures.ComputeEstimates for given proc and listClaimProcs.
        ///Does not update existing ClaimProcs or insert new ClaimProcs in the database.
        ///Outs new ClaimProcs added by Procedures.ComputeEstimates, listClaimProcs will contain any added claimProcs.</summary>
        private void RecomputeEstimates(Procedure proc, List <ClaimProc> listClaimProcs, out List <ClaimProc> listNewClaimProcs,
                                        OrthoProcLink orthoProcLink, OrthoCase orthoCase, OrthoSchedule orthoSchedule, List <OrthoProcLink> listOrthoProcLinksForOrthoCase)
        {
            List <ClaimProc> listOrigClaimProcs = new List <ClaimProc>(listClaimProcs);
            Patient          pat          = Patients.GetPat(proc.PatNum);
            List <PatPlan>   listPatPlans = PatPlans.GetPatPlansForPat(pat.PatNum);
            List <InsSub>    listInsSubs  = InsSubs.GetMany(listPatPlans.Select(x => x.InsSubNum).ToList());
            List <InsPlan>   listInsPlans = InsPlans.GetByInsSubs(listInsSubs.Select(x => x.InsSubNum).ToList());
            List <Benefit>   listBenefits = Benefits.Refresh(listPatPlans, listInsSubs);      //Same method used in FormProcEdit.Load()->GetLoadData()
            //FormProcEdit uses GetHistList(....,procDate:DateTimeOD.Today,...)
            List <ClaimProcHist> listHist = ClaimProcs.GetHistList(pat.PatNum, listBenefits, listPatPlans, listInsPlans, DateTimeOD.Today, listInsSubs);
            bool isSaveToDb = false;

            //When isSaveToDb is true any estimates that are missing will be inserted into DB and it refreshes listClaimProcs from the Db.
            //Refreshing the list results in losing the changes to ProvNum and ProcDate.
            Procedures.ComputeEstimates(proc, pat.PatNum, ref listClaimProcs, false, listInsPlans, listPatPlans, listBenefits, listHist,
                                        new List <ClaimProcHist> {
            }, isSaveToDb, pat.Age, listInsSubs
                                        , useProcDateOnProc: true,
                                        orthoProcLink: orthoProcLink, orthoCase: orthoCase, orthoSchedule: orthoSchedule, listOrthoProcLinksForOrthoCase: listOrthoProcLinksForOrthoCase);
            listNewClaimProcs = listClaimProcs.Except(listOrigClaimProcs).ToList();
        }
Example #4
0
        ///<summary>Updates all claimproc estimates and also updates claim totals to db. Must supply procList which includes all procedures that this claim is linked to.  Will also need to refresh afterwards to see the results</summary>
        public static void CalculateAndUpdate(List <Procedure> procList, List <InsPlan> planList, Claim claimCur, List <PatPlan> patPlans, List <Benefit> benefitList, int patientAge, List <InsSub> subList)
        {
            //we need more than just the claimprocs for this claim.
            //in order to run Procedures.ComputeEstimates, we need all claimprocs for all procedures attached to this claim
            List <ClaimProc> ClaimProcsAll      = ClaimProcs.Refresh(claimCur.PatNum);
            List <ClaimProc> ClaimProcsForClaim = ClaimProcs.RefreshForClaim(claimCur.ClaimNum);         //will be ordered by line number.
            double           claimFee           = 0;
            double           dedApplied         = 0;
            double           insPayEst          = 0;
            double           insPayAmt          = 0;
            double           writeoff           = 0;
            InsPlan          plan = InsPlans.GetPlan(claimCur.PlanNum, planList);

            if (plan == null)
            {
                return;
            }
            long patPlanNum = PatPlans.GetPatPlanNum(claimCur.InsSubNum, patPlans);

            //first loop handles totals for received items.
            for (int i = 0; i < ClaimProcsForClaim.Count; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.Received)
                {
                    continue;                    //disregard any status except Receieved.
                }
                claimFee   += ClaimProcsForClaim[i].FeeBilled;
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                insPayAmt  += ClaimProcsForClaim[i].InsPayAmt;
                writeoff   += ClaimProcsForClaim[i].WriteOff;
            }
            //loop again only for procs not received.
            //And for preauth.
            Procedure ProcCur;
            //InsPlan plan=InsPlans.GetPlan(claimCur.PlanNum,planList);
            List <ClaimProcHist> histList         = ClaimProcs.GetHistList(claimCur.PatNum, benefitList, patPlans, planList, claimCur.ClaimNum, claimCur.DateService, subList);
            List <ClaimProc>     claimProcListOld = new List <ClaimProc>();    //make a copy

            for (int i = 0; i < ClaimProcsAll.Count; i++)
            {
                claimProcListOld.Add(ClaimProcsAll[i].Copy());
            }
            List <ClaimProcHist> loopList = new List <ClaimProcHist>();

            for (int i = 0; i < ClaimProcsForClaim.Count; i++)       //loop through each proc
            {
                ProcCur = Procedures.GetProcFromList(procList, ClaimProcsForClaim[i].ProcNum);
                //in order for ComputeEstimates to give accurate Writeoff when creating a claim, InsPayEst must be filled for the claimproc with status of NotReceived.
                //So, we must set it here.  We need to set it in the claimProcsAll list.  Find the matching one.
                for (int j = 0; j < ClaimProcsAll.Count; j++)
                {
                    if (ClaimProcsAll[j].ClaimProcNum == ClaimProcsForClaim[i].ClaimProcNum)                  //same claimproc in a different list
                    {
                        if (ClaimProcsForClaim[i].Status == ClaimProcStatus.NotReceived &&
                            ProcCur != null)                             //ignores payments, etc
                        {
                            ClaimProcsAll[j].InsPayEst = ClaimProcs.GetInsEstTotal(ClaimProcsAll[j]);
                        }
                    }
                }
                //When this is the secondary claim, HistList includes the primary estimates, which is something we don't want because the primary calculations gets confused.
                //So, we must remove those bad entries from histList.
                for (int h = histList.Count - 1; h >= 0; h--)         //loop through the histList backwards
                {
                    if (histList[h].ProcNum != ProcCur.ProcNum)
                    {
                        continue;                        //Makes sure we will only be excluding histList entries for procs on this claim.
                    }
                    //we already excluded this claimNum when getting the histList.
                    if (histList[h].Status != ClaimProcStatus.NotReceived)
                    {
                        continue;                        //The only ones that are a problem are the ones on the primary claim not received yet.
                    }
                    histList.RemoveAt(h);
                }
                Procedures.ComputeEstimates(ProcCur, claimCur.PatNum, ref ClaimProcsAll, false, planList, patPlans, benefitList, histList, loopList, false, patientAge, subList);
                //then, add this information to loopList so that the next procedure is aware of it.
                loopList.AddRange(ClaimProcs.GetHistForProc(ClaimProcsAll, ProcCur.ProcNum, ProcCur.CodeNum));
            }
            //save changes in the list to the database
            ClaimProcs.Synch(ref ClaimProcsAll, claimProcListOld);
            ClaimProcsForClaim = ClaimProcs.RefreshForClaim(claimCur.ClaimNum);
            //But ClaimProcsAll has not been refreshed.
            for (int i = 0; i < ClaimProcsForClaim.Count; i++)
            {
                if (ClaimProcsForClaim[i].Status != ClaimProcStatus.NotReceived &&
                    ClaimProcsForClaim[i].Status != ClaimProcStatus.Preauth &&
                    ClaimProcsForClaim[i].Status != ClaimProcStatus.CapClaim)
                {
                    continue;
                }
                ProcCur = Procedures.GetProcFromList(procList, ClaimProcsForClaim[i].ProcNum);
                if (ProcCur.ProcNum == 0)
                {
                    continue;                    //ignores payments, etc
                }
                //fee:
                int qty = ProcCur.UnitQty + ProcCur.BaseUnits;
                if (qty == 0)
                {
                    qty = 1;
                }
                if (plan.ClaimsUseUCR)                 //use UCR for the provider of the procedure
                {
                    long provNum = ProcCur.ProvNum;
                    if (provNum == 0)                   //if no prov set, then use practice default.
                    {
                        provNum = PrefC.GetLong(PrefName.PracticeDefaultProv);
                    }
                    //get the fee based on code and prov fee sched
                    double feebilled = Fees.GetAmount0(ProcCur.CodeNum, ProviderC.ListLong[Providers.GetIndexLong(provNum)].FeeSched);
                    if (feebilled > ProcCur.ProcFee)
                    {
                        ClaimProcsForClaim[i].FeeBilled = qty * feebilled;
                    }
                    else
                    {
                        ClaimProcsForClaim[i].FeeBilled = qty * ProcCur.ProcFee;
                    }
                }
                //else if(claimCur.ClaimType=="Cap") {//Even for capitation, use the proc fee.
                //	ClaimProcsForClaim[i].FeeBilled=0;
                //}
                else                  //don't use ucr.  Use the procedure fee instead.
                {
                    ClaimProcsForClaim[i].FeeBilled = qty * ProcCur.ProcFee;
                }
                claimFee += ClaimProcsForClaim[i].FeeBilled;
                if (claimCur.ClaimType == "PreAuth" || claimCur.ClaimType == "Other" || claimCur.ClaimType == "Cap")
                {
                    //only the fee gets calculated, the rest does not
                    ClaimProcs.Update(ClaimProcsForClaim[i]);
                    continue;
                }
                //ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i],ProcCur.ProcFee,ProcCur.ToothNum,ProcCur.CodeNum,plan,patPlanNum,benefitList,histList,loopList);
                ClaimProcsForClaim[i].InsPayEst  = ClaimProcs.GetInsEstTotal(ClaimProcsForClaim[i]); //Yes, this is duplicated from further up.
                ClaimProcsForClaim[i].DedApplied = ClaimProcs.GetDedEst(ClaimProcsForClaim[i]);
                if (ClaimProcsForClaim[i].Status == ClaimProcStatus.NotReceived)                     //(vs preauth)
                {
                    ClaimProcsForClaim[i].WriteOff = ClaimProcs.GetWriteOffEstimate(ClaimProcsForClaim[i]);
                    writeoff += ClaimProcsForClaim[i].WriteOff;

                    /*
                     * ClaimProcsForClaim[i].WriteOff=0;
                     * if(claimCur.ClaimType=="P" && plan.PlanType=="p") {//Primary && PPO
                     *      double insplanAllowed=Fees.GetAmount(ProcCur.CodeNum,plan.FeeSched);
                     *      if(insplanAllowed!=-1) {
                     *              ClaimProcsForClaim[i].WriteOff=ProcCur.ProcFee-insplanAllowed;
                     *      }
                     *      //else, if -1 fee not found, then do not show a writeoff. User can change writeoff if they disagree.
                     * }
                     * writeoff+=ClaimProcsForClaim[i].WriteOff;*/
                }
                dedApplied += ClaimProcsForClaim[i].DedApplied;
                insPayEst  += ClaimProcsForClaim[i].InsPayEst;
                ClaimProcsForClaim[i].ProcDate = ProcCur.ProcDate.Date;              //this solves a rare bug. Keeps dates synched.
                //It's rare enough that I'm not goint to add it to the db maint tool.
                ClaimProcs.Update(ClaimProcsForClaim[i]);
                //but notice that the ClaimProcs lists are not refreshed until the loop is finished.
            }            //for claimprocs.forclaim
            claimCur.ClaimFee   = claimFee;
            claimCur.DedApplied = dedApplied;
            claimCur.InsPayEst  = insPayEst;
            claimCur.InsPayAmt  = insPayAmt;
            claimCur.WriteOff   = writeoff;
            //Cur=ClaimCur;
            Claims.Update(claimCur);
        }
Example #5
0
        ///<summary>All of the code from this method is copied directly from the account module, ContrAccount.FillSummary().</summary>
        private void FillSummary()
        {
            textFamPriMax.Text = "";
            textFamPriDed.Text = "";
            textFamSecMax.Text = "";
            textFamSecDed.Text = "";
            textPriMax.Text    = "";
            textPriDed.Text    = "";
            textPriDedRem.Text = "";
            textPriUsed.Text   = "";
            textPriPend.Text   = "";
            textPriRem.Text    = "";
            textSecMax.Text    = "";
            textSecDed.Text    = "";
            textSecDedRem.Text = "";
            textSecUsed.Text   = "";
            textSecPend.Text   = "";
            textSecRem.Text    = "";
            if (_patCur == null)
            {
                return;
            }
            double         maxFam = 0;
            double         maxInd = 0;
            double         ded    = 0;
            double         dedFam = 0;
            double         dedRem = 0;
            double         remain = 0;
            double         pend   = 0;
            double         used   = 0;
            InsPlan        PlanCur;
            InsSub         SubCur;
            List <PatPlan> PatPlanList = PatPlans.Refresh(_patCur.PatNum);

            if (!PatPlans.IsPatPlanListValid(PatPlanList))
            {
                //PatPlans had invalid references and need to be refreshed.
                PatPlanList = PatPlans.Refresh(_patCur.PatNum);
            }
            List <InsSub>        subList     = InsSubs.RefreshForFam(_famCur);
            List <InsPlan>       InsPlanList = InsPlans.RefreshForSubList(subList);
            List <Benefit>       BenefitList = Benefits.Refresh(PatPlanList, subList);
            List <Claim>         ClaimList   = Claims.Refresh(_patCur.PatNum);
            List <ClaimProcHist> HistList    = ClaimProcs.GetHistList(_patCur.PatNum, BenefitList, PatPlanList, InsPlanList, DateTimeOD.Today, subList);

            if (PatPlanList.Count > 0)
            {
                SubCur  = InsSubs.GetSub(PatPlanList[0].InsSubNum, subList);
                PlanCur = InsPlans.GetPlan(SubCur.PlanNum, InsPlanList);
                pend    = InsPlans.GetPendingDisplay(HistList, DateTimeOD.Today, PlanCur, PatPlanList[0].PatPlanNum,
                                                     -1, _patCur.PatNum, PatPlanList[0].InsSubNum, BenefitList);
                used = InsPlans.GetInsUsedDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[0].PatPlanNum,
                                                  -1, InsPlanList, BenefitList, _patCur.PatNum, PatPlanList[0].InsSubNum);
                textPriPend.Text = pend.ToString("F");
                textPriUsed.Text = used.ToString("F");
                maxFam           = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, true);
                maxInd           = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, false);
                if (maxFam == -1)
                {
                    textFamPriMax.Text = "";
                }
                else
                {
                    textFamPriMax.Text = maxFam.ToString("F");
                }
                if (maxInd == -1)               //if annual max is blank
                {
                    textPriMax.Text = "";
                    textPriRem.Text = "";
                }
                else
                {
                    remain = maxInd - used - pend;
                    if (remain < 0)
                    {
                        remain = 0;
                    }
                    //textFamPriMax.Text=max.ToString("F");
                    textPriMax.Text = maxInd.ToString("F");
                    textPriRem.Text = remain.ToString("F");
                }
                //deductible:
                ded    = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, BenefitCoverageLevel.Individual);
                dedFam = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[0].PatPlanNum, BenefitCoverageLevel.Family);
                if (ded != -1)
                {
                    textPriDed.Text = ded.ToString("F");
                    dedRem          = InsPlans.GetDedRemainDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[0].PatPlanNum,
                                                                   -1, InsPlanList, _patCur.PatNum, ded, dedFam);
                    textPriDedRem.Text = dedRem.ToString("F");
                }
                if (dedFam != -1)
                {
                    textFamPriDed.Text = dedFam.ToString("F");
                }
            }
            if (PatPlanList.Count > 1)
            {
                SubCur  = InsSubs.GetSub(PatPlanList[1].InsSubNum, subList);
                PlanCur = InsPlans.GetPlan(SubCur.PlanNum, InsPlanList);
                pend    = InsPlans.GetPendingDisplay(HistList, DateTimeOD.Today, PlanCur, PatPlanList[1].PatPlanNum,
                                                     -1, _patCur.PatNum, PatPlanList[1].InsSubNum, BenefitList);
                textSecPend.Text = pend.ToString("F");
                used             = InsPlans.GetInsUsedDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[1].PatPlanNum,
                                                              -1, InsPlanList, BenefitList, _patCur.PatNum, PatPlanList[1].InsSubNum);
                textSecUsed.Text = used.ToString("F");
                //max=Benefits.GetAnnualMaxDisplay(BenefitList,PlanCur.PlanNum,PatPlanList[1].PatPlanNum);
                maxFam = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, true);
                maxInd = Benefits.GetAnnualMaxDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, false);
                if (maxFam == -1)
                {
                    textFamSecMax.Text = "";
                }
                else
                {
                    textFamSecMax.Text = maxFam.ToString("F");
                }
                if (maxInd == -1)               //if annual max is blank
                {
                    textSecMax.Text = "";
                    textSecRem.Text = "";
                }
                else
                {
                    remain = maxInd - used - pend;
                    if (remain < 0)
                    {
                        remain = 0;
                    }
                    //textFamSecMax.Text=max.ToString("F");
                    textSecMax.Text = maxInd.ToString("F");
                    textSecRem.Text = remain.ToString("F");
                }
                //deductible:
                ded    = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, BenefitCoverageLevel.Individual);
                dedFam = Benefits.GetDeductGeneralDisplay(BenefitList, PlanCur.PlanNum, PatPlanList[1].PatPlanNum, BenefitCoverageLevel.Family);
                if (ded != -1)
                {
                    textSecDed.Text = ded.ToString("F");
                    dedRem          = InsPlans.GetDedRemainDisplay(HistList, DateTimeOD.Today, PlanCur.PlanNum, PatPlanList[1].PatPlanNum,
                                                                   -1, InsPlanList, _patCur.PatNum, ded, dedFam);
                    textSecDedRem.Text = dedRem.ToString("F");
                }
                if (dedFam != -1)
                {
                    textFamSecDed.Text = dedFam.ToString("F");
                }
            }
        }