public static List <PayPlanProductionEntry> GetProductionForLinks(List <PayPlanLink> listCredits) { //No remoting role check; no call to db List <long> listProcNums = listCredits.FindAll(x => x.LinkType == PayPlanLinkType.Procedure).Select(x => x.FKey).ToList(); List <long> listAdjNumsForCredits = listCredits.FindAll(x => x.LinkType == PayPlanLinkType.Adjustment).Select(x => x.FKey).ToList(); List <PayPlanProductionEntry> listPayPlanProductionEntries = new List <PayPlanProductionEntry>(); //ortho cases to be implemented later. List <Procedure> listProcedures = Procedures.GetManyProc(listProcNums, false); List <Adjustment> listCreditAdjustments = Adjustments.GetMany(listAdjNumsForCredits); List <Adjustment> listProcAdjustments = Adjustments.GetForProcs(listProcNums); List <ClaimProc> listClaimProcs = ClaimProcs.GetForProcs(listProcNums); //used for calculating patient porition foreach (PayPlanLink credit in listCredits) { if (credit.LinkType == PayPlanLinkType.Procedure) { Procedure proc = listProcedures.FirstOrDefault(x => x.ProcNum == credit.FKey); if (proc != null) { listPayPlanProductionEntries.Add(new PayPlanProductionEntry(proc, credit, listClaimProcs, listProcAdjustments)); } } else if (credit.LinkType == PayPlanLinkType.Adjustment) { Adjustment adj = listCreditAdjustments.FirstOrDefault(x => x.AdjNum == credit.FKey); if (adj != null) { listPayPlanProductionEntries.Add(new PayPlanProductionEntry(adj, credit)); } } } return(listPayPlanProductionEntries); }
///<summary>Returns a list of overcharged payplans from the listPayPlanNums. Only necessary for Dynamic Payment Plans. ///Returns an empty list if none are overcharged.</summary> public static List <PayPlan> GetOverchargedPayPlans(List <long> listPayPlanNums) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <PayPlan> >(MethodBase.GetCurrentMethod(), listPayPlanNums)); } List <PayPlan> listDynamicPayPlansForPatient = new List <PayPlan>(); foreach (long payPlanNum in listPayPlanNums) { if (payPlanNum == 0) { continue; //do not include installment plans } PayPlan payPlanCur = PayPlans.GetOne(payPlanNum); if (payPlanCur.IsDynamic) //Only add Dynamic PayPlans to the list since they are all we care about { listDynamicPayPlansForPatient.Add(payPlanCur); } } #region Get Data List <PayPlanLink> listPayPlanLinksAll = PayPlanLinks.GetForPayPlans(listPayPlanNums); List <long> listProcedureLinkFKeys = listPayPlanLinksAll.Where(x => x.LinkType == PayPlanLinkType.Procedure).Select(x => x.FKey).ToList(); List <long> listAdjustmentLinkFKeys = listPayPlanLinksAll.Where(x => x.LinkType == PayPlanLinkType.Adjustment).Select(x => x.FKey).ToList(); List <PayPlanCharge> listPayPlanCharges = PayPlanCharges.GetForPayPlans(listPayPlanNums); List <Procedure> listProcsAttachedToPayPlan = Procedures.GetManyProc(listProcedureLinkFKeys, false); List <Adjustment> listAdjsAttachedToPayPlan = Adjustments.GetMany(listAdjustmentLinkFKeys); List <ClaimProc> listClaimProcsForProcs = ClaimProcs.GetForProcs(listProcedureLinkFKeys); List <Adjustment> listAdjForProcs = Adjustments.GetForProcs(listProcedureLinkFKeys); #endregion Get Data List <PayPlan> listPayPlansOvercharged = new List <PayPlan>(); foreach (PayPlan payPlanCur in listDynamicPayPlansForPatient) { List <PayPlanLink> listLinksForPayPlan = listPayPlanLinksAll.FindAll(x => x.PayPlanNum == payPlanCur.PayPlanNum); //Get total amount that has been debited for the current pay plan thus far. decimal amtDebitedTotal = listPayPlanCharges.FindAll(x => x.PayPlanNum == payPlanCur.PayPlanNum && x.ChargeType == PayPlanChargeType.Debit) .Sum(x => (decimal)x.Principal); #region Sum Linked Production decimal totalPrincipalForPayPlan = 0; foreach (PayPlanLink payPlanLink in listLinksForPayPlan) { PayPlanProductionEntry productionEntry = null; if (payPlanLink.LinkType == PayPlanLinkType.Procedure) { Procedure proc = listProcsAttachedToPayPlan.FirstOrDefault(x => x.ProcNum == payPlanLink.FKey); if (proc != null) { productionEntry = new PayPlanProductionEntry(proc, payPlanLink, listClaimProcsForProcs, listAdjForProcs); } } else if (payPlanLink.LinkType == PayPlanLinkType.Adjustment) { Adjustment adj = listAdjsAttachedToPayPlan.FirstOrDefault(x => x.AdjNum == payPlanLink.FKey); if (adj != null) { productionEntry = new PayPlanProductionEntry(adj, payPlanLink); } } if (productionEntry != null) { if (productionEntry.AmountOverride == 0) { totalPrincipalForPayPlan += productionEntry.AmountOriginal; } else { totalPrincipalForPayPlan += productionEntry.AmountOverride; } } } #endregion Sum Linked Production //If the total that has been debited thus far exceeds the total principal for the pay plan, it is overcharged. if (amtDebitedTotal.IsGreaterThan(totalPrincipalForPayPlan)) { listPayPlansOvercharged.Add(payPlanCur); } } return(listPayPlansOvercharged); }