///<summary>Updates all claimproc estimates and also updates claim totals to db. Must supply all claimprocs for this patient (or for this plan if fam max or ded). 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(ClaimProc[] ClaimProcList, Procedure[] procList, InsPlan[] PlanList, Claim ClaimCur, PatPlan[] patPlans, Benefit[] benefitList) { ClaimProc[] ClaimProcsForClaim = ClaimProcs.GetForClaim(ClaimProcList, ClaimCur.ClaimNum); double claimFee = 0; double dedApplied = 0; double insPayEst = 0; double insPayAmt = 0; double writeoff = 0; InsPlan PlanCur = InsPlans.GetPlan(ClaimCur.PlanNum, PlanList); if (PlanCur == null) { return; } int provNum; double dedRem; int patPlanNum = PatPlans.GetPatPlanNum(patPlans, ClaimCur.PlanNum); //this next line has to be done outside the loop. Takes annual max into consideration double insRem; //no changes get made to insRem in the loop. if (patPlanNum == 0) //patient does not have current coverage { insRem = 0; } else { insRem = InsPlans.GetInsRem(ClaimProcList, ClaimProcsForClaim[0].ProcDate, ClaimCur.PlanNum, patPlanNum, ClaimCur.ClaimNum, PlanList, benefitList); } //first loop handles totals for received items. for (int i = 0; i < ClaimProcsForClaim.Length; 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; } //loop again only for procs not received. //And for preauth. Procedure ProcCur; for (int i = 0; i < ClaimProcsForClaim.Length; i++) { if (ClaimProcsForClaim[i].Status != ClaimProcStatus.NotReceived && ClaimProcsForClaim[i].Status != ClaimProcStatus.Preauth) { continue; } ProcCur = Procedures.GetProc(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 (PlanCur.ClaimsUseUCR) //use UCR for the provider of the procedure { provNum = ProcCur.ProvNum; if (provNum == 0) //if no prov set, then use practice default. { provNum = PrefB.GetInt("PracticeDefaultProv"); } ClaimProcsForClaim[i].FeeBilled = qty * (Fees.GetAmount0( //get the fee based on code and prov fee sched ProcCur.CodeNum, Providers.ListLong[Providers.GetIndexLong(provNum)].FeeSched)); } 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") { //only the fee gets calculated, the rest does not ClaimProcs.Update(ClaimProcsForClaim[i]); continue; } //deduct: if (patPlanNum == 0) //patient does not have current coverage { dedRem = 0; } else { dedRem = InsPlans.GetDedRem(ClaimProcList, ClaimProcsForClaim[i].ProcDate, ClaimCur.PlanNum, patPlanNum, ClaimCur.ClaimNum, PlanList, benefitList, ProcedureCodes.GetStringProcCode(ProcCur.CodeNum)) - dedApplied; //subtracts deductible amounts already applied on this claim if (dedRem < 0) { dedRem = 0; } } if (dedRem > ClaimProcsForClaim[i].FeeBilled) //if deductible is more than cost of procedure { ClaimProcsForClaim[i].DedApplied = ClaimProcsForClaim[i].FeeBilled; } else { ClaimProcsForClaim[i].DedApplied = dedRem; } if (ClaimCur.ClaimType == "P") //primary { ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Pri, PlanList, patPlans, benefitList); //handles dedBeforePerc ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Pri, patPlans, true); } else if (ClaimCur.ClaimType == "S") //secondary { ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Sec, PlanList, patPlans, benefitList); ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Sec, patPlans, true); } if (ClaimCur.ClaimType == "P" || ClaimCur.ClaimType == "S") { if (ClaimProcsForClaim[i].DedBeforePerc) { int percent = 100; if (ClaimProcsForClaim[i].Percentage != -1) { percent = ClaimProcsForClaim[i].Percentage; } if (ClaimProcsForClaim[i].PercentOverride != -1) { percent = ClaimProcsForClaim[i].PercentOverride; } ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied * (double)percent / 100d; } else { ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied; } } //claimtypes other than P and S only changed manually if (ClaimProcsForClaim[i].InsPayEst < 0) { //example: if inspayest = 19 - 50(ded) for total of -31. ClaimProcsForClaim[i].DedApplied += ClaimProcsForClaim[i].InsPayEst; //eg. 50+(-31)=19 ClaimProcsForClaim[i].InsPayEst = 0; //so only 19 of deductible gets applied, and inspayest is 0 } if (insRem - insPayEst < 0) //total remaining ins-Estimated so far on this claim { ClaimProcsForClaim[i].InsPayEst = 0; } else if (ClaimProcsForClaim[i].InsPayEst > insRem - insPayEst) { ClaimProcsForClaim[i].InsPayEst = insRem - insPayEst; } if (ClaimProcsForClaim[i].Status == ClaimProcStatus.NotReceived) { ClaimProcsForClaim[i].WriteOff = 0; if (ClaimCur.ClaimType == "P" && PlanCur.PlanType == "p") //Primary && PPO { double insplanAllowed = Fees.GetAmount(ProcCur.CodeNum, PlanCur.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; 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; Update(ClaimCur); }
///<summary>Updates all claimproc estimates and also updates claim totals to db. Must supply all claimprocs for this patient. 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(ClaimProc[] ClaimProcList, Procedure[] procList, InsPlan[] PlanList, Claim ClaimCur, PatPlan[] patPlans, Benefit[] benefitList) { //Remember that this can be called externally also //ClaimProcList=claimProcList; ClaimProc[] ClaimProcsForClaim = ClaimProcs.GetForClaim(ClaimProcList, ClaimCur.ClaimNum); double claimFee = 0; double dedApplied = 0; double insPayEst = 0; double insPayAmt = 0; InsPlan PlanCur = InsPlans.GetPlan(ClaimCur.PlanNum, PlanList); if (PlanCur == null) { return; } //InsPlans.Cur=(InsPlan)InsPlans.HList[ClaimCur.PlanNum]; int provNum; double dedRem; int patPlanNum = PatPlans.GetPatPlanNum(patPlans, ClaimCur.PlanNum); //this next line has to be done outside the loop. Takes annual max into consideration double insRem; //no changes get made to insRem in the loop. if (patPlanNum == 0) //patient does not have current coverage { insRem = 0; } else { insRem = InsPlans.GetInsRem(ClaimProcList, ClaimProcsForClaim[0].ProcDate, ClaimCur.PlanNum, patPlanNum, ClaimCur.ClaimNum, PlanList, benefitList); } //first loop handles totals for received items. for (int i = 0; i < ClaimProcsForClaim.Length; 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; } //loop again only for procs not received. //And for preauth. Procedure ProcCur; for (int i = 0; i < ClaimProcsForClaim.Length; i++) { if (ClaimProcsForClaim[i].Status != ClaimProcStatus.NotReceived && ClaimProcsForClaim[i].Status != ClaimProcStatus.Preauth) { continue; } ProcCur = Procedures.GetProc(procList, ClaimProcsForClaim[i].ProcNum); if (ProcCur.ProcNum == 0) { continue; //ignores payments, etc } //fee: if (PlanCur.ClaimsUseUCR) //use UCR for the provider of the procedure { provNum = ProcCur.ProvNum; if (provNum == 0) //if no prov set, then use practice default. { provNum = PrefB.GetInt("PracticeDefaultProv"); } ClaimProcsForClaim[i].FeeBilled = Fees.GetAmount0( //get the fee based on ada and prov fee sched ProcCur.ADACode , Providers.ListLong[Providers.GetIndexLong(provNum)].FeeSched); } else //don't use ucr. Use the procedure fee instead. { ClaimProcsForClaim[i].FeeBilled = ProcCur.ProcFee; } claimFee += ClaimProcsForClaim[i].FeeBilled; if (ClaimCur.ClaimType == "PreAuth" || ClaimCur.ClaimType == "Other") { //only the fee gets calculated, the rest does not ClaimProcs.Update(ClaimProcsForClaim[i]); continue; } //deduct: if (patPlanNum == 0) //patient does not have current coverage { dedRem = 0; } else { dedRem = InsPlans.GetDedRem(ClaimProcList, ClaimProcsForClaim[i].ProcDate, ClaimCur.PlanNum, patPlanNum, ClaimCur.ClaimNum, PlanList, benefitList, ProcCur.ADACode) - dedApplied; //subtracts deductible amounts already applied on this claim if (dedRem < 0) { dedRem = 0; } } if (dedRem > ClaimProcsForClaim[i].FeeBilled) //if deductible is more than cost of procedure { ClaimProcsForClaim[i].DedApplied = ClaimProcsForClaim[i].FeeBilled; } else { ClaimProcsForClaim[i].DedApplied = dedRem; } //??obsolete: if dedApplied is too big, it might be adjusted in the next few lines.?? //insest: //Unlike deductible, we do not need to take into account any of the received claimprocs when calculating insest. So insRem takes care of annual max rather than received+est. //if(patPlanNum==0){//patient does not have current coverage // insRem=0; //} //else{ //insRem-=insPayEst;//subtracts insest amounts already applied on this claim //insRem=InsPlans.GetInsRem(ClaimProcList,ClaimProcsForClaim[i].ProcDate,ClaimCur.PlanNum, // patPlanNum,ClaimCur.ClaimNum,PlanList,benefitList) // -insPayEst;//subtracts insest amounts already applied on this claim // if(insRem<0) { // insRem=0; // } //} if (ClaimCur.ClaimType == "P") //primary { ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Pri, PlanList, patPlans, benefitList); //handles dedBeforePerc ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Pri, patPlans, true); //ClaimProcsForClaim[i].BaseEst; if (!ClaimProcsForClaim[i].DedBeforePerc) { ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied; } } else if (ClaimCur.ClaimType == "S") //secondary { ClaimProcs.ComputeBaseEst(ClaimProcsForClaim[i], ProcCur, PriSecTot.Sec, PlanList, patPlans, benefitList); ClaimProcsForClaim[i].InsPayEst = Procedures.GetEst(ProcCur, ClaimProcList, PriSecTot.Sec, patPlans, true); //ClaimProcsForClaim[i].BaseEst; if (!ClaimProcsForClaim[i].DedBeforePerc) { ClaimProcsForClaim[i].InsPayEst -= ClaimProcsForClaim[i].DedApplied; } } //other claimtypes only changed manually if (ClaimProcsForClaim[i].InsPayEst < 0) { //example: if inspayest = 19 - 50(ded) for total of -31. ClaimProcsForClaim[i].DedApplied += ClaimProcsForClaim[i].InsPayEst; //eg. 50+(-31)=19 ClaimProcsForClaim[i].InsPayEst = 0; //so only 19 of deductible gets applied, and inspayest is 0 } if (insRem - insPayEst < 0) //total remaining ins-Estimated so far on this claim { ClaimProcsForClaim[i].InsPayEst = 0; } else if (ClaimProcsForClaim[i].InsPayEst > insRem - insPayEst) { ClaimProcsForClaim[i].InsPayEst = insRem - insPayEst; } dedApplied += ClaimProcsForClaim[i].DedApplied; insPayEst += ClaimProcsForClaim[i].InsPayEst; 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; //Cur=ClaimCur; Update(ClaimCur); }