///<summary>Retrieves data and uses them to create new PayPlanExtended objects. ///Heavy lifting (db calls and double loops) done here once upon load. This also gets called if the user clicks "Refresh Data".</summary> private bool LoadData() { List <PayPlan> listPayPlans; List <PayPlanCharge> listPayPlanCharges; List <ClaimProc> listPayPlanClaimProcs; List <Patient> listPatients; List <InsPlan> listInsPlans; listPayPlans = PayPlans.GetAllOpenInsPayPlans(); if (listPayPlans.Count == 0) { MsgBox.Show(this, "There are no insurance payment plans past due."); return(false); } listPayPlanCharges = PayPlanCharges.GetForPayPlans(listPayPlans.Select(x => x.PayPlanNum).ToList()).Where(x => x.ChargeType == PayPlanChargeType.Debit).ToList(); listPayPlanClaimProcs = ClaimProcs.GetForPayPlans(listPayPlans.Select(x => x.PayPlanNum).ToList() , new List <ClaimProcStatus>() { ClaimProcStatus.Received, ClaimProcStatus.Supplemental }); listPatients = Patients.GetLimForPats(listPayPlans.Select(x => x.PatNum).ToList()); listInsPlans = InsPlans.GetPlans(listPayPlans.Select(x => x.PlanNum).ToList()); _listPayPlanExtended = new List <PayPlanExtended>(); foreach (PayPlan plan in listPayPlans) { //for each payplan, create a PayPlanExtended object which contains all of the payment plan's information and it's charges. //pass in the plan, the list of associated charges, and the list of associated claimprocs (payments). _listPayPlanExtended.Add(new PayPlanExtended(plan, listPatients.FirstOrDefault(x => x.PatNum == plan.PatNum), listPayPlanCharges.Where(x => x.PayPlanNum == plan.PayPlanNum).ToList(), listPayPlanClaimProcs.Where(x => x.PayPlanNum == plan.PayPlanNum).ToList(), listInsPlans.FirstOrDefault(x => x.PlanNum == plan.PlanNum))); } return(true); }