Ejemplo n.º 1
0
 ///<summary>Inserts one RepeatCharge into the database.  Returns the new priKey.</summary>
 internal static long Insert(RepeatCharge repeatCharge)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         repeatCharge.RepeatChargeNum=DbHelper.GetNextOracleKey("repeatcharge","RepeatChargeNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(repeatCharge,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     repeatCharge.RepeatChargeNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(repeatCharge,false);
     }
 }
Ejemplo n.º 2
0
 ///<summary>Inserts one RepeatCharge into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(RepeatCharge repeatCharge,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         repeatCharge.RepeatChargeNum=ReplicationServers.GetKey("repeatcharge","RepeatChargeNum");
     }
     string command="INSERT INTO repeatcharge (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="RepeatChargeNum,";
     }
     command+="PatNum,ProcCode,ChargeAmt,DateStart,DateStop,Note) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(repeatCharge.RepeatChargeNum)+",";
     }
     command+=
              POut.Long  (repeatCharge.PatNum)+","
         +"'"+POut.String(repeatCharge.ProcCode)+"',"
         +"'"+POut.Double(repeatCharge.ChargeAmt)+"',"
         +    POut.Date  (repeatCharge.DateStart)+","
         +    POut.Date  (repeatCharge.DateStop)+","
         +"'"+POut.String(repeatCharge.Note)+"')";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         repeatCharge.RepeatChargeNum=Db.NonQ(command,true);
     }
     return repeatCharge.RepeatChargeNum;
 }
Ejemplo n.º 3
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<RepeatCharge> TableToList(DataTable table){
			List<RepeatCharge> retVal=new List<RepeatCharge>();
			RepeatCharge repeatCharge;
			for(int i=0;i<table.Rows.Count;i++) {
				repeatCharge=new RepeatCharge();
				repeatCharge.RepeatChargeNum= PIn.Long  (table.Rows[i]["RepeatChargeNum"].ToString());
				repeatCharge.PatNum         = PIn.Long  (table.Rows[i]["PatNum"].ToString());
				repeatCharge.ProcCode       = PIn.String(table.Rows[i]["ProcCode"].ToString());
				repeatCharge.ChargeAmt      = PIn.Double(table.Rows[i]["ChargeAmt"].ToString());
				repeatCharge.DateStart      = PIn.Date  (table.Rows[i]["DateStart"].ToString());
				repeatCharge.DateStop       = PIn.Date  (table.Rows[i]["DateStop"].ToString());
				repeatCharge.Note           = PIn.String(table.Rows[i]["Note"].ToString());
				repeatCharge.CopyNoteToProc = PIn.Bool  (table.Rows[i]["CopyNoteToProc"].ToString());
				repeatCharge.CreatesClaim   = PIn.Bool  (table.Rows[i]["CreatesClaim"].ToString());
				repeatCharge.IsEnabled      = PIn.Bool  (table.Rows[i]["IsEnabled"].ToString());
				retVal.Add(repeatCharge);
			}
			return retVal;
		}
Ejemplo n.º 4
0
 ///<summary>Updates one RepeatCharge in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
 internal static void Update(RepeatCharge repeatCharge,RepeatCharge oldRepeatCharge)
 {
     string command="";
     if(repeatCharge.PatNum != oldRepeatCharge.PatNum) {
         if(command!=""){ command+=",";}
         command+="PatNum = "+POut.Long(repeatCharge.PatNum)+"";
     }
     if(repeatCharge.ProcCode != oldRepeatCharge.ProcCode) {
         if(command!=""){ command+=",";}
         command+="ProcCode = '"+POut.String(repeatCharge.ProcCode)+"'";
     }
     if(repeatCharge.ChargeAmt != oldRepeatCharge.ChargeAmt) {
         if(command!=""){ command+=",";}
         command+="ChargeAmt = '"+POut.Double(repeatCharge.ChargeAmt)+"'";
     }
     if(repeatCharge.DateStart != oldRepeatCharge.DateStart) {
         if(command!=""){ command+=",";}
         command+="DateStart = "+POut.Date(repeatCharge.DateStart)+"";
     }
     if(repeatCharge.DateStop != oldRepeatCharge.DateStop) {
         if(command!=""){ command+=",";}
         command+="DateStop = "+POut.Date(repeatCharge.DateStop)+"";
     }
     if(repeatCharge.Note != oldRepeatCharge.Note) {
         if(command!=""){ command+=",";}
         command+="Note = '"+POut.String(repeatCharge.Note)+"'";
     }
     if(command==""){
         return;
     }
     command="UPDATE repeatcharge SET "+command
         +" WHERE RepeatChargeNum = "+POut.Long(repeatCharge.RepeatChargeNum);
     Db.NonQ(command);
 }
Ejemplo n.º 5
0
 ///<summary>Updates one RepeatCharge in the database.</summary>
 internal static void Update(RepeatCharge repeatCharge)
 {
     string command="UPDATE repeatcharge SET "
         +"PatNum         =  "+POut.Long  (repeatCharge.PatNum)+", "
         +"ProcCode       = '"+POut.String(repeatCharge.ProcCode)+"', "
         +"ChargeAmt      = '"+POut.Double(repeatCharge.ChargeAmt)+"', "
         +"DateStart      =  "+POut.Date  (repeatCharge.DateStart)+", "
         +"DateStop       =  "+POut.Date  (repeatCharge.DateStop)+", "
         +"Note           = '"+POut.String(repeatCharge.Note)+"' "
         +"WHERE RepeatChargeNum = "+POut.Long(repeatCharge.RepeatChargeNum);
     Db.NonQ(command);
 }
Ejemplo n.º 6
0
        public void Legacy_TestFiftyFive()
        {
            //Changing the amount or start date on a repeat charge should not cause the repeat charge to be added again.
            string  suffix = "55";
            Patient pat    = PatientT.CreatePatient(suffix);
            Patient patOld = pat.Copy();

            pat.BillingCycleDay = 11;
            Patients.Update(pat, patOld);
            Prefs.UpdateBool(PrefName.BillingUseBillingCycleDay, true);
            UpdateHistoryT.CreateUpdateHistory("16.1.1.0");
            Prefs.RefreshCache();
            List <RepeatCharge> listRepeatingCharges = RepeatCharges.Refresh(0).ToList();

            listRepeatingCharges.ForEach(x => RepeatCharges.Delete(x));
            DateTime   dateRun         = new DateTime(2015, 12, 15);
            List <int> listFailedTests = new List <int>();
            //Subtest 1 ===============================================================
            //Run the repeat charge tool. Change the charge amount on the repeat charge. Run the repeat charge tool again. Make sure that no
            //extra procedures are added.
            RepeatCharge rc = new RepeatCharge();

            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 11, 1);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            rc.ChargeAmt = 80;
            RepeatCharges.Update(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            List <Procedure> procs = Procedures.Refresh(pat.PatNum);

            if (procs.Count != 2 ||
                procs.FindAll(x => x.ProcDate.ToShortDateString() == "11/11/2015" && x.ProcFee == 99).Count != 1 ||
                procs.FindAll(x => x.ProcDate.ToShortDateString() == "12/11/2015" && x.ProcFee == 99).Count != 1)
            {
                listFailedTests.Add(1);
            }
            //Subtest 2 ===============================================================
            //Run the repeat charge tool. Change the start date on the repeat charge. Run the repeat charge tool again. Make sure that no
            //extra procedures are added.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 11, 1);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            rc.DateStart = new DateTime(2015, 11, 2);
            RepeatCharges.Update(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            if (procs.Count != 2 ||
                procs.FindAll(x => x.ProcDate.ToShortDateString() == "11/11/2015" && x.ProcFee == 99).Count != 1 ||
                procs.FindAll(x => x.ProcDate.ToShortDateString() == "12/11/2015" && x.ProcFee == 99).Count != 1)
            {
                listFailedTests.Add(2);
            }
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            Assert.AreEqual(0, listFailedTests.Count);
        }
Ejemplo n.º 7
0
        public void Legacy_TestFiftyFour()
        {
            //When there are multiple repeat charges on one account and the repeat charge tool is run, and then a procedure from the account is deleted,
            //and then the repeat charges tool is run again, the same number of procedures that were deleted should be added.
            string  suffix = "54";
            Patient pat    = PatientT.CreatePatient(suffix);
            Patient patOld = pat.Copy();

            pat.BillingCycleDay = 11;
            Patients.Update(pat, patOld);
            PrefT.UpdateBool(PrefName.BillingUseBillingCycleDay, true);
            PrefT.UpdateBool(PrefName.FutureTransDatesAllowed, true);
            UpdateHistoryT.CreateUpdateHistory("16.1.1.0");            //Sets a timestamp that determines which logic we use to calculate repeate charge procedures
            Prefs.RefreshCache();
            List <RepeatCharge> listRepeatingCharges = RepeatCharges.Refresh(0).ToList();

            listRepeatingCharges.ForEach(x => RepeatCharges.Delete(x));
            DateTime     dateRun         = new DateTime(DateTime.Today.AddMonths(2).Year, DateTime.Today.AddMonths(2).Month, 15);//The 15th of two months from now
            List <int>   listFailedTests = new List <int>();
            RepeatCharge rc = new RepeatCharge();

            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 15);  //The 15th of this month
            rc.Note            = "Charge #1";
            rc.CopyNoteToProc  = true;
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 15);
            rc.Note            = "Charge #2";
            rc.CopyNoteToProc  = true;
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 15);
            rc.Note            = "Charge #3";
            rc.CopyNoteToProc  = true;
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            //Subtest 1 ===============================================================
            //There are three procedures with the same amount, proc code, and start date. Run the repeat charge tool. Delete all procedures from
            //last month. Run the repeat charge tool again. Make sure that the correct repeat charges were added back.
            RepeatCharges.RunRepeatingCharges(dateRun);
            List <Procedure> procs = Procedures.Refresh(pat.PatNum);
            int lastMonth          = dateRun.AddMonths(-1).Month;
            int thisMonth          = dateRun.Month;

            //Delete all procedures from last month
            procs.FindAll(x => x.ProcDate.Month == lastMonth)
            .ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            //Make sure that the correct number of procedures were added using the correct repeating charges
            if (procs.Count != 6 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #3").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #3").Count != 1)
            {
                listFailedTests.Add(1);
            }
            //Subtest 2 ===============================================================
            //Run the repeat charge tool. Delete all procedures from this month. Run the repeat charge tool again. Make sure that the correct
            //repeat charges were added back.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            //Delete all procedures from this month
            procs.FindAll(x => x.ProcDate.Month == thisMonth)
            .ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            //Make sure that the correct number of procedures were added using the correct repeating charges
            if (procs.Count != 6 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #3").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #3").Count != 1)
            {
                listFailedTests.Add(2);
            }
            //Subtest 3 ===============================================================
            //Run the repeat charge tool. Delete one procedure from this month. Run the repeat charge tool again. Make sure that the correct
            //repeat charges were added back.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            //Delete one procedure from this month
            procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #1")
            .ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            //Make sure that the correct number of procedures were added using the correct repeating charges
            if (procs.Count != 6 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #3").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #3").Count != 1)
            {
                listFailedTests.Add(3);
            }
            //Subtest 4 ===============================================================
            //Run the repeat charge tool. Delete one procedure from last month. Run the repeat charge tool again. Make sure that the correct
            //repeat charges were added back.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            //Delete one procedure from last month
            procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #1")
            .ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            //Make sure that the correct number of procedures were added using the correct repeating charges
            if (procs.Count != 6 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == lastMonth && x.BillingNote == "Charge #3").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #1").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #2").Count != 1 ||
                procs.FindAll(x => x.ProcDate.Month == thisMonth && x.BillingNote == "Charge #3").Count != 1)
            {
                listFailedTests.Add(4);
            }
            Assert.AreEqual(0, listFailedTests.Count);
        }
Ejemplo n.º 8
0
        public void Legacy_TestFiftySix()
        {
            //Repeat charges should not be posted before the start date.
            string  suffix = "56";
            Patient pat    = PatientT.CreatePatient(suffix);
            Patient patOld = pat.Copy();

            pat.BillingCycleDay = 15;
            Patients.Update(pat, patOld);
            Prefs.UpdateBool(PrefName.BillingUseBillingCycleDay, true);
            UpdateHistoryT.CreateUpdateHistory("16.1.1.0");
            Prefs.RefreshCache();
            List <RepeatCharge> listRepeatingCharges = RepeatCharges.Refresh(0).ToList();

            listRepeatingCharges.ForEach(x => RepeatCharges.Delete(x));
            DateTime   dateRun         = new DateTime(2015, 12, 15);
            List <int> listFailedTests = new List <int>();
            //Subtest 1 ===============================================================
            //The date start is the same as the date ran and the same as the billing day. Add a procedure that day.
            RepeatCharge rc = new RepeatCharge();

            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 12, 15);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            List <Procedure> procs = Procedures.Refresh(pat.PatNum);

            if (procs.Count != 1 || procs.FindAll(x => x.ProcDate.ToShortDateString() == "12/15/2015" && x.ProcFee == 99).Count != 1)
            {
                listFailedTests.Add(1);
            }
            //Subtest 2 ===============================================================
            //The start date is the same as the date ran but the billing day is three days earlier. Don't add a procedure that day.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            patOld = pat.Copy();
            pat.BillingCycleDay = 12;
            Patients.Update(pat, patOld);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 12, 15);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            if (procs.Count != 0)
            {
                listFailedTests.Add(2);
            }
            //Subtest 3 ===============================================================
            //The start date is the same as the billing day but is three days after the date ran. Don't add a procedure that day.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            patOld = pat.Copy();
            pat.BillingCycleDay = 15;
            Patients.Update(pat, patOld);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 12, 18);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            if (procs.Count != 0)
            {
                listFailedTests.Add(3);
            }
            Assert.AreEqual(0, listFailedTests.Count);
        }
Ejemplo n.º 9
0
        public void Legacy_TestFiftyThree()
        {
            //Repeat charges should be added after the stop date if the duration of the repeating charge if the number of charges added to the account is
            //less than the number of months the repeat charge was active (a partial month is counted as a full month).
            string  suffix = "53";
            Patient pat    = PatientT.CreatePatient(suffix);
            Patient patOld = pat.Copy();

            pat.BillingCycleDay = 11;
            Patients.Update(pat, patOld);
            Prefs.UpdateBool(PrefName.BillingUseBillingCycleDay, true);
            UpdateHistoryT.CreateUpdateHistory("16.1.1.0");
            Prefs.RefreshCache();
            //delete all existing repeating charges
            List <RepeatCharge> listRepeatingCharges = RepeatCharges.Refresh(0).ToList();

            listRepeatingCharges.ForEach(x => RepeatCharges.Delete(x));
            DateTime dateRun = new DateTime(2015, 12, 15);
            //Subtest 1 =====================================================
            //The start day is before the stop day which is before the billing day. Add a charge after the stop date.
            RepeatCharge rc = new RepeatCharge();

            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";   //arbitrary code
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 11, 8);
            rc.DateStop        = new DateTime(2015, 12, 9);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            List <Procedure> procs = Procedures.Refresh(pat.PatNum);

            Assert.AreEqual(2, procs.Count);
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 11, 11)));
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 12, 11)));
            //Subtest 2 =====================================================
            //The start day is after the billing day which is after the stop day. Add a charge after the stop date.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 10, 25);
            rc.DateStop        = new DateTime(2015, 12, 1);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            Assert.AreEqual(2, procs.Count);
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 11, 11)));
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 12, 11)));
            //Subtest 3 =====================================================
            //The start day is the same as the stop day but before the billing day. Add a charge after the stop date.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            rc           = new RepeatCharge();
            rc.ChargeAmt = 99;
            rc.PatNum    = pat.PatNum;
            rc.ProcCode  = "D2750";
            rc.IsEnabled = true;
            rc.DateStart = new DateTime(2015, 11, 10);
            rc.DateStop  = new DateTime(2015, 12, 10);
            RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            Assert.AreEqual(2, procs.Count);
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 11, 11)));
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 12, 11)));
            //Subtest 4 =====================================================
            //The start day is the same as the stop day and the billing day. Don't add a charge after the stop date.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            dateRun            = new DateTime(2015, 11, 15);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 10, 11);
            rc.DateStop        = new DateTime(2015, 11, 11);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            Assert.AreEqual(2, procs.Count);
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 10, 11)));
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 11, 11)));
            //Subtest 5 =====================================================
            //The start day is after the stop day which is after the billing day. Don't add a charge after the stop date.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 10, 15);
            rc.DateStop        = new DateTime(2015, 11, 13);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            Procedure p = new Procedure();

            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            Assert.AreEqual(1, procs.Count);
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 11, 11)));
            //Subtest 6 =====================================================
            //The start day is before billing day which is before the stop day. Don't add a charge after the stop date.
            procs.ForEach(x => Procedures.Delete(x.ProcNum));
            RepeatCharges.Delete(rc);
            rc                 = new RepeatCharge();
            rc.ChargeAmt       = 99;
            rc.PatNum          = pat.PatNum;
            rc.ProcCode        = "D2750";
            rc.IsEnabled       = true;
            rc.DateStart       = new DateTime(2015, 11, 05);
            rc.DateStop        = new DateTime(2015, 11, 20);
            rc.RepeatChargeNum = RepeatCharges.Insert(rc);
            RepeatCharges.RunRepeatingCharges(dateRun);
            procs = Procedures.Refresh(pat.PatNum);
            Assert.AreEqual(1, procs.Count);
            Assert.AreEqual(1, procs.Count(x => x.ProcDate == new DateTime(2015, 11, 11)));
        }
Ejemplo n.º 10
0
        ///<summary>Called from FormRepeatCharge.</summary>
        public static void Delete(RepeatCharge charge)
        {
            string command = "DELETE FROM repeatcharge WHERE RepeatChargeNum =" + POut.PInt(charge.RepeatChargeNum);

            General.NonQ(command);
        }
Ejemplo n.º 11
0
        ///<summary>Updates one RepeatCharge in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(RepeatCharge repeatCharge, RepeatCharge oldRepeatCharge)
        {
            string command = "";

            if (repeatCharge.PatNum != oldRepeatCharge.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(repeatCharge.PatNum) + "";
            }
            if (repeatCharge.ProcCode != oldRepeatCharge.ProcCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProcCode = '" + POut.String(repeatCharge.ProcCode) + "'";
            }
            if (repeatCharge.ChargeAmt != oldRepeatCharge.ChargeAmt)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ChargeAmt = '" + POut.Double(repeatCharge.ChargeAmt) + "'";
            }
            if (repeatCharge.DateStart.Date != oldRepeatCharge.DateStart.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateStart = " + POut.Date(repeatCharge.DateStart) + "";
            }
            if (repeatCharge.DateStop.Date != oldRepeatCharge.DateStop.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateStop = " + POut.Date(repeatCharge.DateStop) + "";
            }
            if (repeatCharge.Note != oldRepeatCharge.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = " + DbHelper.ParamChar + "paramNote";
            }
            if (repeatCharge.CopyNoteToProc != oldRepeatCharge.CopyNoteToProc)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "CopyNoteToProc = " + POut.Bool(repeatCharge.CopyNoteToProc) + "";
            }
            if (repeatCharge.CreatesClaim != oldRepeatCharge.CreatesClaim)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "CreatesClaim = " + POut.Bool(repeatCharge.CreatesClaim) + "";
            }
            if (repeatCharge.IsEnabled != oldRepeatCharge.IsEnabled)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IsEnabled = " + POut.Bool(repeatCharge.IsEnabled) + "";
            }
            if (repeatCharge.UsePrepay != oldRepeatCharge.UsePrepay)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UsePrepay = " + POut.Bool(repeatCharge.UsePrepay) + "";
            }
            if (repeatCharge.Npi != oldRepeatCharge.Npi)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Npi = " + DbHelper.ParamChar + "paramNpi";
            }
            if (repeatCharge.ErxAccountId != oldRepeatCharge.ErxAccountId)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ErxAccountId = " + DbHelper.ParamChar + "paramErxAccountId";
            }
            if (repeatCharge.ProviderName != oldRepeatCharge.ProviderName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProviderName = " + DbHelper.ParamChar + "paramProviderName";
            }
            if (repeatCharge.ChargeAmtAlt != oldRepeatCharge.ChargeAmtAlt)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ChargeAmtAlt = '" + POut.Double(repeatCharge.ChargeAmtAlt) + "'";
            }
            if (repeatCharge.UnearnedTypes != oldRepeatCharge.UnearnedTypes)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UnearnedTypes = '" + POut.String(repeatCharge.UnearnedTypes) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            if (repeatCharge.Note == null)
            {
                repeatCharge.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(repeatCharge.Note));

            if (repeatCharge.Npi == null)
            {
                repeatCharge.Npi = "";
            }
            OdSqlParameter paramNpi = new OdSqlParameter("paramNpi", OdDbType.Text, POut.StringParam(repeatCharge.Npi));

            if (repeatCharge.ErxAccountId == null)
            {
                repeatCharge.ErxAccountId = "";
            }
            OdSqlParameter paramErxAccountId = new OdSqlParameter("paramErxAccountId", OdDbType.Text, POut.StringParam(repeatCharge.ErxAccountId));

            if (repeatCharge.ProviderName == null)
            {
                repeatCharge.ProviderName = "";
            }
            OdSqlParameter paramProviderName = new OdSqlParameter("paramProviderName", OdDbType.Text, POut.StringParam(repeatCharge.ProviderName));

            command = "UPDATE repeatcharge SET " + command
                      + " WHERE RepeatChargeNum = " + POut.Long(repeatCharge.RepeatChargeNum);
            Db.NonQ(command, paramNote, paramNpi, paramErxAccountId, paramProviderName);
            return(true);
        }
Ejemplo n.º 12
0
        ///<summary>Inserts one RepeatCharge into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(RepeatCharge repeatCharge, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO repeatcharge (";

            if (!useExistingPK && isRandomKeys)
            {
                repeatCharge.RepeatChargeNum = ReplicationServers.GetKeyNoCache("repeatcharge", "RepeatChargeNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "RepeatChargeNum,";
            }
            command += "PatNum,ProcCode,ChargeAmt,DateStart,DateStop,Note,CopyNoteToProc,CreatesClaim,IsEnabled,UsePrepay,Npi,ErxAccountId,ProviderName,ChargeAmtAlt,UnearnedTypes) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(repeatCharge.RepeatChargeNum) + ",";
            }
            command +=
                POut.Long(repeatCharge.PatNum) + ","
                + "'" + POut.String(repeatCharge.ProcCode) + "',"
                + "'" + POut.Double(repeatCharge.ChargeAmt) + "',"
                + POut.Date(repeatCharge.DateStart) + ","
                + POut.Date(repeatCharge.DateStop) + ","
                + DbHelper.ParamChar + "paramNote,"
                + POut.Bool(repeatCharge.CopyNoteToProc) + ","
                + POut.Bool(repeatCharge.CreatesClaim) + ","
                + POut.Bool(repeatCharge.IsEnabled) + ","
                + POut.Bool(repeatCharge.UsePrepay) + ","
                + DbHelper.ParamChar + "paramNpi,"
                + DbHelper.ParamChar + "paramErxAccountId,"
                + DbHelper.ParamChar + "paramProviderName,"
                + "'" + POut.Double(repeatCharge.ChargeAmtAlt) + "',"
                + "'" + POut.String(repeatCharge.UnearnedTypes) + "')";
            if (repeatCharge.Note == null)
            {
                repeatCharge.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(repeatCharge.Note));

            if (repeatCharge.Npi == null)
            {
                repeatCharge.Npi = "";
            }
            OdSqlParameter paramNpi = new OdSqlParameter("paramNpi", OdDbType.Text, POut.StringParam(repeatCharge.Npi));

            if (repeatCharge.ErxAccountId == null)
            {
                repeatCharge.ErxAccountId = "";
            }
            OdSqlParameter paramErxAccountId = new OdSqlParameter("paramErxAccountId", OdDbType.Text, POut.StringParam(repeatCharge.ErxAccountId));

            if (repeatCharge.ProviderName == null)
            {
                repeatCharge.ProviderName = "";
            }
            OdSqlParameter paramProviderName = new OdSqlParameter("paramProviderName", OdDbType.Text, POut.StringParam(repeatCharge.ProviderName));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramNote, paramNpi, paramErxAccountId, paramProviderName);
            }
            else
            {
                repeatCharge.RepeatChargeNum = Db.NonQ(command, true, "RepeatChargeNum", "repeatCharge", paramNote, paramNpi, paramErxAccountId, paramProviderName);
            }
            return(repeatCharge.RepeatChargeNum);
        }
Ejemplo n.º 13
0
 ///<summary>Inserts one RepeatCharge into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(RepeatCharge repeatCharge)
 {
     return(InsertNoCache(repeatCharge, false));
 }
Ejemplo n.º 14
0
		///<summary>Updates one RepeatCharge in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
		public static void Update(RepeatCharge repeatCharge,RepeatCharge oldRepeatCharge){
			string command="";
			if(repeatCharge.PatNum != oldRepeatCharge.PatNum) {
				if(command!=""){ command+=",";}
				command+="PatNum = "+POut.Long(repeatCharge.PatNum)+"";
			}
			if(repeatCharge.ProcCode != oldRepeatCharge.ProcCode) {
				if(command!=""){ command+=",";}
				command+="ProcCode = '"+POut.String(repeatCharge.ProcCode)+"'";
			}
			if(repeatCharge.ChargeAmt != oldRepeatCharge.ChargeAmt) {
				if(command!=""){ command+=",";}
				command+="ChargeAmt = '"+POut.Double(repeatCharge.ChargeAmt)+"'";
			}
			if(repeatCharge.DateStart != oldRepeatCharge.DateStart) {
				if(command!=""){ command+=",";}
				command+="DateStart = "+POut.Date(repeatCharge.DateStart)+"";
			}
			if(repeatCharge.DateStop != oldRepeatCharge.DateStop) {
				if(command!=""){ command+=",";}
				command+="DateStop = "+POut.Date(repeatCharge.DateStop)+"";
			}
			if(repeatCharge.Note != oldRepeatCharge.Note) {
				if(command!=""){ command+=",";}
				command+="Note = '"+POut.String(repeatCharge.Note)+"'";
			}
			if(repeatCharge.CopyNoteToProc != oldRepeatCharge.CopyNoteToProc) {
				if(command!=""){ command+=",";}
				command+="CopyNoteToProc = "+POut.Bool(repeatCharge.CopyNoteToProc)+"";
			}
			if(repeatCharge.CreatesClaim != oldRepeatCharge.CreatesClaim) {
				if(command!=""){ command+=",";}
				command+="CreatesClaim = "+POut.Bool(repeatCharge.CreatesClaim)+"";
			}
			if(repeatCharge.IsEnabled != oldRepeatCharge.IsEnabled) {
				if(command!=""){ command+=",";}
				command+="IsEnabled = "+POut.Bool(repeatCharge.IsEnabled)+"";
			}
			if(command==""){
				return;
			}
			command="UPDATE repeatcharge SET "+command
				+" WHERE RepeatChargeNum = "+POut.Long(repeatCharge.RepeatChargeNum);
			Db.NonQ(command);
		}
Ejemplo n.º 15
0
		///<summary>Updates one RepeatCharge in the database.</summary>
		public static void Update(RepeatCharge repeatCharge){
			string command="UPDATE repeatcharge SET "
				+"PatNum         =  "+POut.Long  (repeatCharge.PatNum)+", "
				+"ProcCode       = '"+POut.String(repeatCharge.ProcCode)+"', "
				+"ChargeAmt      = '"+POut.Double(repeatCharge.ChargeAmt)+"', "
				+"DateStart      =  "+POut.Date  (repeatCharge.DateStart)+", "
				+"DateStop       =  "+POut.Date  (repeatCharge.DateStop)+", "
				+"Note           = '"+POut.String(repeatCharge.Note)+"', "
				+"CopyNoteToProc =  "+POut.Bool  (repeatCharge.CopyNoteToProc)+", "
				+"CreatesClaim   =  "+POut.Bool  (repeatCharge.CreatesClaim)+", "
				+"IsEnabled      =  "+POut.Bool  (repeatCharge.IsEnabled)+" "
				+"WHERE RepeatChargeNum = "+POut.Long(repeatCharge.RepeatChargeNum);
			Db.NonQ(command);
		}
Ejemplo n.º 16
0
 ///<summary>Returns true if Update(RepeatCharge,RepeatCharge) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(RepeatCharge repeatCharge, RepeatCharge oldRepeatCharge)
 {
     if (repeatCharge.PatNum != oldRepeatCharge.PatNum)
     {
         return(true);
     }
     if (repeatCharge.ProcCode != oldRepeatCharge.ProcCode)
     {
         return(true);
     }
     if (repeatCharge.ChargeAmt != oldRepeatCharge.ChargeAmt)
     {
         return(true);
     }
     if (repeatCharge.DateStart.Date != oldRepeatCharge.DateStart.Date)
     {
         return(true);
     }
     if (repeatCharge.DateStop.Date != oldRepeatCharge.DateStop.Date)
     {
         return(true);
     }
     if (repeatCharge.Note != oldRepeatCharge.Note)
     {
         return(true);
     }
     if (repeatCharge.CopyNoteToProc != oldRepeatCharge.CopyNoteToProc)
     {
         return(true);
     }
     if (repeatCharge.CreatesClaim != oldRepeatCharge.CreatesClaim)
     {
         return(true);
     }
     if (repeatCharge.IsEnabled != oldRepeatCharge.IsEnabled)
     {
         return(true);
     }
     if (repeatCharge.UsePrepay != oldRepeatCharge.UsePrepay)
     {
         return(true);
     }
     if (repeatCharge.Npi != oldRepeatCharge.Npi)
     {
         return(true);
     }
     if (repeatCharge.ErxAccountId != oldRepeatCharge.ErxAccountId)
     {
         return(true);
     }
     if (repeatCharge.ProviderName != oldRepeatCharge.ProviderName)
     {
         return(true);
     }
     if (repeatCharge.ChargeAmtAlt != oldRepeatCharge.ChargeAmtAlt)
     {
         return(true);
     }
     if (repeatCharge.UnearnedTypes != oldRepeatCharge.UnearnedTypes)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 17
0
        ///<summary>Go through the transaction dictionary created in CreateProcedureLogs() to edit repeat charges as needed.
        ///Returns the note for the newly generated repeat charge.</summary>
        private void ZeroOutRepeatingCharge(ProcedureCode procCur, List <AvaTax.TransQtyAmt> listCurTrans)
        {
            Commlog prepaymentCommlog = new Commlog();

            prepaymentCommlog.PatNum         = _patCur.PatNum;
            prepaymentCommlog.SentOrReceived = CommSentOrReceived.Received;
            prepaymentCommlog.CommDateTime   = DateTime.Now;
            prepaymentCommlog.CommType       = Commlogs.GetTypeAuto(CommItemTypeAuto.FIN);
            prepaymentCommlog.Mode_          = CommItemMode.None;
            prepaymentCommlog.Note           = "";//Appended to below.
            prepaymentCommlog.UserNum        = Security.CurUser.UserNum;
            string note = "From PrepaymentTool: \r\n";
            bool   hasBeenBilledThisMonth = (DateTimeOD.Today.Day >= _patCur.BillingCycleDay);
            //Get all applicable repeat charges.
            List <RepeatCharge> listRcForProc = _listRcForPat.FindAll(x => x.ProcCode == procCur.ProcCode && x.IsEnabled);
            //Get number of months new repeat charge will be for.
            int numMonths = listCurTrans.Sum(x => x.qty);
            //Create repeat charge, taken from ContrAccount.cs
            RepeatCharge rcNew = new RepeatCharge();

            rcNew.PatNum         = _patCur.PatNum;
            rcNew.ProcCode       = procCur.ProcCode;
            rcNew.ChargeAmt      = 0;
            rcNew.IsEnabled      = true;
            rcNew.CopyNoteToProc = true;
            //Build dates using billing day so the patient doesn't have gaps in their repeat charges.
            DateTime dateBillThisMonth = DateTimeOD.GetMostRecentValidDate(DateTime.Today.Year, DateTime.Today.Month, _patCur.BillingCycleDay);

            if (hasBeenBilledThisMonth)
            {
                //Current month has been billed, push new repeat charge out a month.
                rcNew.DateStart = dateBillThisMonth.AddMonths(1);
                rcNew.DateStop  = dateBillThisMonth.AddMonths(numMonths);
            }
            else
            {
                //Current month has not been billed yet, include on this repeat charge.
                rcNew.DateStart = dateBillThisMonth;
                rcNew.DateStop  = dateBillThisMonth.AddMonths(numMonths - 1);
            }
            //Use the stop date to update the Note as requested by Accounting.
            DatePrepaidThrough = rcNew.DateStop.AddMonths(1).AddDays(-1);
            rcNew.Note         = _prepaidThroughNote;
            //Edit exisiting repeat charge start/stop dates.
            foreach (RepeatCharge rcExisting in listRcForProc)
            {
                if (rcExisting.DateStop.Year > 1880 && rcExisting.DateStop < DateTimeOD.Today)
                {
                    continue;                    //The charge has a stop date in the past (has been disabled).
                }
                if (rcExisting.DateStop.Year > 1880 && rcExisting.DateStop <= DateTimeOD.Today.AddMonths(numMonths))
                {
                    rcExisting.DateStop  = DateTimeOD.Today;
                    rcExisting.IsEnabled = false;
                    //This repeat charge will never be used again due to the prepayment we are creating right now.  Disable and add note to commlog for history.
                    note += "Disabled repeat charge with Rate: " + POut.Double(rcExisting.ChargeAmt) + " for Code: " + POut.String(rcExisting.ProcCode)
                            + " Start Date: " + POut.Date(rcExisting.DateStart) + " Stop Date: " + POut.Date(rcExisting.DateStop) + "\r\n";
                    RepeatCharges.Update(rcExisting);
                    continue;
                }
                //Need to push start date of existing repeat charge forward one month past the new repeat charge (if charge months overlap).
                DateTime dateNext = rcNew.DateStop.AddMonths(1);
                if (dateNext > rcExisting.DateStart)                 //Only change if needed.
                {
                    note += "Edited Start Date for repeat charge from: " + POut.Date(rcExisting.DateStart) + " to: " + POut.Date(dateNext) +
                            " Code: " + POut.String(rcExisting.ProcCode) + " Rate: " + POut.Double(rcExisting.ChargeAmt) + "\r\n";
                    //Change to billing day to make sure it matches other repeat charges.
                    rcExisting.DateStart = dateNext;
                    RepeatCharges.Update(rcExisting);
                }
            }
            //Insert the new repeat charge.
            prepaymentCommlog.Note = note;
            Commlogs.Insert(prepaymentCommlog);
            RepeatCharges.Insert(rcNew);
        }