Example #1
0
        public void LedgersTests_ComputeAgingProcLifo_PayPlan1()
        {
            Patient       pat                 = PatientT.CreatePatient(fName: "Schedule Based", lName: "UDP Ortho");
            Def           defNeg              = DefT.CreateDefinition(DefCat.AdjTypes, "Ortho Revenue", "-");
            Def           defPos              = DefT.CreateDefinition(DefCat.AdjTypes, "Ortho Revenue", "+");
            Def           defPay              = DefT.CreateDefinition(DefCat.PaymentTypes, "Check");
            Procedure     proc                = ProcedureT.CreateProcedure(pat, "D8090", ProcStat.C, "", 4000, DateTime.Today.AddMonths(-6).AddDays(-1));
            PayPlan       payPlan             = PayPlanT.CreatePayPlan(pat.PatNum, 4000, 166.67, DateTime.Today.AddMonths(-6).AddDays(-1), proc.ProvNum);
            Adjustment    adj6                = AdjustmentT.MakeAdjustment(pat.PatNum, -2800, DateTime.Today.AddMonths(-6).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defNeg.DefNum);
            Payment       pay6                = PaymentT.MakePayment(pat.PatNum, 166.67, DateTime.Today.AddMonths(-6).AddDays(-1), payPlanNum: payPlan.PayPlanNum, provNum: proc.ProvNum, procNum: proc.ProcNum, payType: defPay.DefNum);
            PayPlanCharge ppc6                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-6).AddDays(-1), 1200, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
            Adjustment    adj5                = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-5).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
            Payment       pay5                = PaymentT.MakePayment(pat.PatNum, 166.67, DateTime.Today.AddMonths(-5).AddDays(-1), payPlanNum: payPlan.PayPlanNum, provNum: proc.ProvNum, procNum: proc.ProcNum, payType: defPay.DefNum);
            PayPlanCharge ppc5                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-5).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
            Adjustment    adj4                = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-4).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
            PayPlanCharge ppc4                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-4).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
            Adjustment    adj3                = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-3).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
            PayPlanCharge ppc3                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-3).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
            Adjustment    adj2                = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-2).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
            PayPlanCharge ppc2                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-2).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
            Adjustment    adj1                = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-1).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
            PayPlanCharge ppc1                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-1).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
            int           payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                CheckAgingProcLifo(pat.PatNum, 166.67, 166.67, 166.67, 333.34, 833.35, YN.Yes);
                CheckAgingProcLifo(pat.PatNum, 166.67, 288.41, 288.41, 89.86, 833.35, YN.No);
                CheckAgingProcLifo(pat.PatNum, 166.67, 288.41, 288.41, 89.86, 833.35, YN.Unknown);          //Unset will behave the same as Off for now, until we change default behavior in future.
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
            }
        }
Example #2
0
        public void LedgersTests_ComputeAgingProcLifo_DateLastPay()
        {
            string     suffix            = MethodBase.GetCurrentMethod().Name;
            Patient    pat               = PatientT.CreatePatient(fName: "Aging_DateLastPay", suffix: suffix);
            Procedure  proc95            = ProcedureT.CreateProcedure(pat, "D0270", ProcStat.C, "", 1000, DateTime.Today.AddDays(-95));
            Procedure  proc85            = ProcedureT.CreateProcedure(pat, "D1110", ProcStat.C, "", 100, DateTime.Today.AddDays(-85));
            Payment    pay50             = PaymentT.MakePayment(pat.PatNum, 50, DateTime.Today.AddDays(-50));
            Adjustment adj40_1           = AdjustmentT.MakeAdjustment(pat.PatNum, 4, DateTime.Today.AddDays(-40), proc85.ProcDate, proc85.ProcNum);
            Adjustment adj40_2           = AdjustmentT.MakeAdjustment(pat.PatNum, 6, DateTime.Today.AddDays(-40), proc85.ProcDate, proc85.ProcNum);
            Payment    pay2              = PaymentT.MakePayment(pat.PatNum, 50, DateTime.Today.AddDays(-2));
            int        agingProcLifoPrev = PrefC.GetInt(PrefName.AgingProcLifo);

            try {
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.No);
                Dictionary <long, DataRow> dictAging = Ledgers.GetAgingGuarTransTable(DateTime.Today, new List <long> {
                    pat.Guarantor
                }, hasDateLastPay: true);
                Assert.AreEqual(PIn.Date(dictAging[pat.Guarantor]["DateLastPay"].ToString()), pay2.PayDate);
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.Yes);
                dictAging = Ledgers.GetAgingGuarTransTable(DateTime.Today, new List <long> {
                    pat.Guarantor
                }, hasDateLastPay: true);
                Assert.AreEqual(PIn.Date(dictAging[pat.Guarantor]["DateLastPay"].ToString()), pay2.PayDate);
            }
            finally {
                PrefT.UpdateInt(PrefName.AgingProcLifo, agingProcLifoPrev);
            }
        }
Example #3
0
        public void LedgersTests_ComputeAgingProcLifo_Case1()
        {
            string     suffix = MethodBase.GetCurrentMethod().Name;
            Patient    pat    = PatientT.CreatePatient(fName: "Aging_Case1", suffix: suffix);
            Procedure  proc85 = ProcedureT.CreateProcedure(pat, "D1110", ProcStat.C, "", 100, DateTime.Today.AddDays(-85));
            Adjustment adj55  = AdjustmentT.MakeAdjustment(pat.PatNum, 10, DateTime.Today.AddDays(-55), proc85.ProcDate, proc85.ProcNum);
            Adjustment adj2   = AdjustmentT.MakeAdjustment(pat.PatNum, -8, DateTime.Today.AddDays(-2), proc85.ProcDate, proc85.ProcNum);

            CheckAgingProcLifo(pat.PatNum, 0, 10, 92, 0, 0, YN.Yes);
            CheckAgingProcLifo(pat.PatNum, 0, 10, 92, 0, 0, YN.No);
            CheckAgingProcLifo(pat.PatNum, 0, 10, 92, 0, 0, YN.Unknown);      //Unset will behave the same as Off for now, until we change default behavior in future.
        }
Example #4
0
        public void LedgersTests_ComputeAging_PayPlanDynamic()
        {
            List <Procedure>  listProcs = new List <Procedure>();
            List <Adjustment> listAdjs  = new List <Adjustment>();
            long       provNum          = ProviderT.CreateProvider("Aging_PayPlanDynamic");
            string     suffix           = MethodBase.GetCurrentMethod().Name;
            Patient    pat      = PatientT.CreatePatient(fName: "Aging_PayPlanDynamic", suffix: suffix);
            Family     fam      = Patients.GetFamily(pat.PatNum);
            Procedure  proc1    = ProcedureT.CreateProcedure(pat, "D0210", ProcStat.C, "", 45, DateTime.Today.AddDays(-61), provNum: provNum);
            Procedure  proc2    = ProcedureT.CreateProcedure(pat, "D0220", ProcStat.C, "", 55, DateTime.Today.AddDays(-32), provNum: provNum);
            Procedure  proc3    = ProcedureT.CreateProcedure(pat, "D0270", ProcStat.C, "", 65, DateTime.Today.AddDays(-15), provNum: provNum);
            Adjustment adjProc2 = AdjustmentT.MakeAdjustment(pat.PatNum, 10, proc2.ProcDate, proc2.ProcDate, proc2.ProcNum, provNum);
            Adjustment adjProc3 = AdjustmentT.MakeAdjustment(pat.PatNum, 20, proc3.ProcDate, proc3.ProcDate, proc3.ProcNum, provNum);
            Adjustment adj      = AdjustmentT.MakeAdjustment(pat.PatNum, 30, DateTime.Today.AddDays(-5), provNum: provNum);

            listProcs.AddRange(new List <Procedure> {
                proc1, proc2, proc3
            });
            listAdjs.AddRange(new List <Adjustment> {
                adj
            });
            PayPlan payPlan = PayPlanT.CreateDynamicPaymentPlan(pat.PatNum, pat.PatNum, DateTime.Today.AddDays(-1), 0, 0, 40, listProcs, listAdjs);
            //PayPlan payplan=PayPlanT.CreatePayPlanWithCredits(pat.PatNum,40,DateTime.Today,provNum:provNum,listProcs,195,pat.PatNum);
            //make two non payplan productions to put on the account
            Procedure procUnattached = ProcedureT.CreateProcedure(pat, "D0210", ProcStat.C, "", 35, DateTime.Today.AddDays(-91), provNum: provNum);
            //Run pay plan logic to generate first set of charges
            List <PayPlanCharge> listChargesDb = PayPlanCharges.GetForPayPlan(payPlan.PayPlanNum);
            List <PayPlanLink>   listEntries   = PayPlanLinks.GetForPayPlans(new List <long> {
                payPlan.PayPlanNum
            });
            PayPlanTerms         terms = PayPlanT.GetTerms(payPlan, listEntries);
            List <PayPlanCharge> listChargesThisPeriod = PayPlanEdit.GetListExpectedCharges(listChargesDb, terms, fam, listEntries, payPlan, true);

            Assert.AreEqual(40, listChargesThisPeriod.Sum(x => x.Principal));
            foreach (PayPlanCharge charge in listChargesThisPeriod)
            {
                PayPlanCharges.Insert(charge);
            }
            int payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                CheckAgingProcLifo(pat.PatNum, 70, 0, 0, 5, 40, YN.Yes);         //new
                CheckAgingProcLifo(pat.PatNum, 75, 0, 0, 0, 40, YN.No);          //old
                CheckAgingProcLifo(pat.PatNum, 75, 0, 0, 0, 40, YN.Unknown);
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
            }
        }
Example #5
0
        public void PaymentEdit_Init_AttachedAdjustment()
        {
            Patient    pat        = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name);
            long       provNum    = ProviderT.CreateProvider("prov1");
            Procedure  proc       = ProcedureT.CreateProcedure(pat, "D0120", ProcStat.C, "", 135, DateTime.Today.AddMonths(-1).AddDays(1), provNum: provNum);
            Adjustment adjustment = AdjustmentT.MakeAdjustment(pat.PatNum, 20, DateTime.Today.AddDays(-15), provNum: provNum, procNum: proc.ProcNum);
            Payment    payCur     = PaymentT.MakePaymentNoSplits(pat.PatNum, 20);

            PaymentEdit.LoadData loadData = PaymentEdit.GetLoadData(pat, payCur, new List <long> {
                pat.PatNum
            }, true, false);
            PaymentEdit.InitData initData = PaymentEdit.Init(loadData.ListAssociatedPatients, Patients.GetFamily(pat.PatNum), new Family {
            }, payCur
                                                             , loadData.ListSplits, new List <Procedure>(), pat.PatNum, loadData: loadData);
            //Verify there is only one charge (the procedure's charge + the adjustment for the amount original)
            Assert.AreEqual(1, initData.AutoSplitData.ListAccountCharges.Count);
            Assert.AreEqual(typeof(Procedure), initData.AutoSplitData.ListAccountCharges[0].Tag.GetType());
            Assert.AreEqual(155, initData.AutoSplitData.ListAccountCharges[0].AmountOriginal);
        }
Example #6
0
        public void PaymentEdit_Init_AdjustmentPreferWithPosAdjustment()
        {
            PrefT.UpdateInt(PrefName.AutoSplitLogic, (int)AutoSplitPreference.Adjustments);
            Patient    pat        = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name);
            long       provNum    = ProviderT.CreateProvider("prov1");
            Procedure  proc1      = ProcedureT.CreateProcedure(pat, "D0220", ProcStat.C, "", 75, DateTime.Today.AddMonths(-1), provNum: provNum);
            Procedure  proc2      = ProcedureT.CreateProcedure(pat, "D0120", ProcStat.C, "", 135, DateTime.Today.AddMonths(-1).AddDays(1), provNum: provNum);
            Adjustment adjustment = AdjustmentT.MakeAdjustment(pat.PatNum, 20, DateTime.Today.AddDays(-15), provNum: provNum);
            Payment    payCur     = PaymentT.MakePaymentNoSplits(pat.PatNum, 20);

            PaymentEdit.LoadData loadData = PaymentEdit.GetLoadData(pat, payCur, new List <long> {
                pat.PatNum
            }, true, false);
            PaymentEdit.InitData initData = PaymentEdit.Init(loadData.ListAssociatedPatients, Patients.GetFamily(pat.PatNum), new Family {
            }, payCur
                                                             , loadData.ListSplits, new List <Procedure>(), pat.PatNum, loadData: loadData);
            //Verify the logic chooses to pay off the adjustment first
            Assert.AreEqual(1, initData.AutoSplitData.ListAccountCharges.Count(x => x.Tag.GetType() == typeof(Adjustment) && x.AmountEnd == 0));
        }
Example #7
0
        public void LedgersTests_ComputeAgingProcLifo_PayPlan3()
        {
            string        suffix              = MethodBase.GetCurrentMethod().Name;
            Patient       pat                 = PatientT.CreatePatient(fName: "Aging_PayPlan3", suffix: suffix);
            Procedure     proc95              = ProcedureT.CreateProcedure(pat, "D0270", ProcStat.C, "", 200, DateTime.Today.AddDays(-95));
            Procedure     proc35              = ProcedureT.CreateProcedure(pat, "D1110", ProcStat.C, "", 100, DateTime.Today.AddDays(-35));
            PayPlan       payPlan             = PayPlanT.CreatePayPlan(pat.PatNum, 100, 50, DateTime.Today.AddDays(-35), proc35.ProvNum);
            Adjustment    adj5                = AdjustmentT.MakeAdjustment(pat.PatNum, -5.50, DateTime.Today.AddDays(-5), proc35.ProcDate, proc35.ProcNum);
            PayPlanCharge ppc5                = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddDays(-5), 100, 0, chargeType: PayPlanChargeType.Credit, procNum: proc35.ProcNum);
            int           payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                CheckAgingProcLifo(pat.PatNum, 50, 44.50, 0, 200, 100, YN.Yes);
                CheckAgingProcLifo(pat.PatNum, 50, 150, 0, 94.50, 100, YN.No);
                CheckAgingProcLifo(pat.PatNum, 50, 150, 0, 94.50, 100, YN.Unknown);          //Unset will behave the same as Off for now, until we change default behavior in future.
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
            }
        }
Example #8
0
        public void PaymentEdit_Init_AutoSplitWithAdjustmentAndExistingPayment()          //Legacy_TestFortyFive
        {
            string         suffix        = "45";
            Patient        pat           = PatientT.CreatePatient(suffix);
            long           patNum        = pat.PatNum;
            Procedure      procedure1    = ProcedureT.CreateProcedure(pat, "D1110", ProcStat.C, "", 40, DateTime.Now.AddDays(-1));
            Procedure      procedure2    = ProcedureT.CreateProcedure(pat, "D0120", ProcStat.C, "", 60, DateTime.Now.AddDays(-2));
            Procedure      procedure3    = ProcedureT.CreateProcedure(pat, "D0220", ProcStat.C, "", 80, DateTime.Now.AddDays(-3));
            Adjustment     adjustment    = AdjustmentT.MakeAdjustment(patNum, -40, procDate: DateTime.Now.AddDays(-2));
            Payment        payment       = PaymentT.MakePayment(patNum, 100, DateTime.Now.AddDays(-2), procNum: procedure3.ProcNum);
            Payment        payment2      = PaymentT.MakePaymentNoSplits(patNum, 50, DateTime.Today);
            Family         famForPat     = Patients.GetFamily(patNum);
            List <Patient> listFamForPat = famForPat.ListPats.ToList();

            PaymentEdit.InitData init = PaymentEdit.Init(listFamForPat, famForPat, new Family {
            }, payment2, new List <PaySplit>(), new List <Procedure>(), patNum);
            //Auto Splits will be in opposite order from least recent to most recent.
            //ListSplitsCur should contain two paysplits, 40 attached to the D1110 and another for the remainder of 10, not attached to any procedure.
            Assert.AreEqual(2, init.AutoSplitData.ListSplitsCur.Count);
            Assert.IsFalse(init.AutoSplitData.ListSplitsCur[0].SplitAmt != 40 || init.AutoSplitData.ListSplitsCur[0].ProcNum != procedure1.ProcNum);
            Assert.IsFalse(init.AutoSplitData.ListSplitsCur[1].SplitAmt != 10 || init.AutoSplitData.ListSplitsCur[1].ProcNum != 0);
        }
Example #9
0
        public void LedgersTests_ComputeAging_PayPlanDynamicCredits()
        {
            //first need to create an unrelated pat that also has payment plan data to conflict with ours. This test is specifically to guard against a bug
            List <Procedure>  listProcs = new List <Procedure>();
            List <Adjustment> listAdjs  = new List <Adjustment>();
            long      provNum           = ProviderT.CreateProvider("Aging_PayPlanDynamicCredits");
            Patient   unrelatedPat      = PatientT.CreatePatient("unrelatedPatPayPlanDyn");
            Procedure procAttach        = ProcedureT.CreateProcedure(unrelatedPat, "D0220", ProcStat.C, "", 200, provNum: provNum);

            listProcs.Add(procAttach);
            listAdjs.Add(AdjustmentT.MakeAdjustment(unrelatedPat.PatNum, 15, DateTime.Today.AddDays(-2), provNum: provNum));
            listAdjs.Add(AdjustmentT.MakeAdjustment(unrelatedPat.PatNum, 5, DateTime.Today, DateTime.Today.AddDays(-2), procAttach.ProcNum, provNum));
            PayPlanT.CreateDynamicPaymentPlan(unrelatedPat.PatNum, unrelatedPat.PatNum, DateTime.Today.AddDays(-2), 0, 0, 20, listProcs, listAdjs);
            string  suffix = MethodBase.GetCurrentMethod().Name;
            Patient pat    = PatientT.CreatePatient(fName: "Aging_PayPlanDynamic", suffix: suffix);

            listProcs.Clear();
            listAdjs.Clear();
            Procedure  proc = ProcedureT.CreateProcedure(pat, "D0270", ProcStat.C, "", 65, DateTime.Today.AddDays(-1), provNum: provNum);
            Adjustment adj  = AdjustmentT.MakeAdjustment(pat.PatNum, 20, DateTime.Today.AddDays(-1), proc.ProcDate, proc.ProcNum, provNum);

            listProcs.Add(proc);
            listAdjs.Add(adj);
            PayPlan payPlan             = PayPlanT.CreateDynamicPaymentPlan(pat.PatNum, pat.PatNum, DateTime.Today.AddDays(-1), 0, 0, 30, listProcs, listAdjs);
            int     payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                CheckAgingProcLifo(pat.PatNum, 0, 0, 0, 0, 0, YN.Yes);
                CheckAgingProcLifo(pat.PatNum, 0, 0, 0, 0, 0, YN.No);
                Assert.AreEqual(pat.BalTotal, 0);               //everything on account should be credited
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
            }
        }
Example #10
0
        public void LedgersTests_ComputeAgingProcLifo_LargeDb()
        {
            Def            defNeg   = DefT.CreateDefinition(DefCat.AdjTypes, "Ortho Revenue", "-");
            Def            defPos   = DefT.CreateDefinition(DefCat.AdjTypes, "Ortho Revenue", "+");
            Def            defPay   = DefT.CreateDefinition(DefCat.PaymentTypes, "Check");
            List <Patient> listPats = new List <Patient>();

            for (int i = 0; i < 1000; i++)
            {
                Patient       pat     = PatientT.CreatePatient(fName: "Schedule Based", lName: "UDP Ortho LargeDb");
                Procedure     proc    = ProcedureT.CreateProcedure(pat, "D8090", ProcStat.C, "", 4000, DateTime.Today.AddMonths(-6).AddDays(-1));
                PayPlan       payPlan = PayPlanT.CreatePayPlan(pat.PatNum, 4000, 166.67, DateTime.Today.AddMonths(-6).AddDays(-1), proc.ProvNum);
                Adjustment    adj6    = AdjustmentT.MakeAdjustment(pat.PatNum, -2800, DateTime.Today.AddMonths(-6).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defNeg.DefNum);
                Payment       pay6    = PaymentT.MakePayment(pat.PatNum, 166.67, DateTime.Today.AddMonths(-6).AddDays(-1), payPlanNum: payPlan.PayPlanNum, provNum: proc.ProvNum, procNum: proc.ProcNum, payType: defPay.DefNum);
                PayPlanCharge ppc6    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-6).AddDays(-1), 1200, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj5    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-5).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                Payment       pay5    = PaymentT.MakePayment(pat.PatNum, 166.67, DateTime.Today.AddMonths(-5).AddDays(-1), payPlanNum: payPlan.PayPlanNum, provNum: proc.ProvNum, procNum: proc.ProcNum, payType: defPay.DefNum);
                PayPlanCharge ppc5    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-5).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj4    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-4).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc4    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-4).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj3    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-3).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc3    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-3).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj2    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-2).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc2    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-2).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                Adjustment    adj1    = AdjustmentT.MakeAdjustment(pat.PatNum, 121.74, DateTime.Today.AddMonths(-1).AddDays(-1), proc.ProcDate, proc.ProcNum, provNum: proc.ProvNum, adjType: defPos.DefNum);
                PayPlanCharge ppc1    = PayPlanChargeT.CreateOne(payPlan.PayPlanNum, pat.Guarantor, pat.PatNum, DateTime.Today.AddMonths(-1).AddDays(-1), 121.74, 0, "D8090:  CompOrthoAdlt", proc.ProvNum, 0, PayPlanChargeType.Credit, proc.ProcNum);
                listPats.Add(pat);
            }
            int       payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);
            int       agingProcLifoPrev   = PrefC.GetInt(PrefName.AgingProcLifo);
            Stopwatch swOn    = new Stopwatch();
            Stopwatch swOff   = new Stopwatch();
            Stopwatch swUnset = new Stopwatch();

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                swOn.Start();
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.Yes);
                Ledgers.ComputeAging(0, DateTime.Today);               //Compute aging for all patients.
                foreach (Patient pat in listPats)
                {
                    PatAssertBalances(pat.PatNum, 166.67, 166.67, 166.67, 333.34, 833.35);
                }
                swOn.Stop();
                swOff.Start();
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.No);
                Ledgers.ComputeAging(0, DateTime.Today);               //Compute aging for all patients.
                foreach (Patient pat in listPats)
                {
                    PatAssertBalances(pat.PatNum, 166.67, 288.41, 288.41, 89.86, 833.35);
                }
                swOff.Stop();
                swUnset.Start();
                PrefT.UpdateInt(PrefName.AgingProcLifo, (int)YN.Unknown);
                Ledgers.ComputeAging(0, DateTime.Today);               //Compute aging for all patients.
                foreach (Patient pat in listPats)
                {
                    PatAssertBalances(pat.PatNum, 166.67, 288.41, 288.41, 89.86, 833.35);
                }
                swUnset.Stop();
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
                PrefT.UpdateInt(PrefName.AgingProcLifo, agingProcLifoPrev);
            }
            //Fails if swOn run time is at least 10 times as large as the average of the runtimes for swUnset and swOff.
            Assert.IsTrue(swOn.Elapsed.TotalMilliseconds < (swUnset.Elapsed.TotalMilliseconds + swOff.Elapsed.TotalMilliseconds) * 5,
                          "Pref On: " + swOn.Elapsed + "\r\n"
                          + "Pref Off: " + swOff.Elapsed + "\r\n"
                          + "Pref Unset: " + swUnset.Elapsed);
        }