///<summary>Returns true if Update(OrthoPlanLink,OrthoPlanLink) 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(OrthoPlanLink orthoPlanLink, OrthoPlanLink oldOrthoPlanLink)
 {
     if (orthoPlanLink.OrthoCaseNum != oldOrthoPlanLink.OrthoCaseNum)
     {
         return(true);
     }
     if (orthoPlanLink.LinkType != oldOrthoPlanLink.LinkType)
     {
         return(true);
     }
     if (orthoPlanLink.FKey != oldOrthoPlanLink.FKey)
     {
         return(true);
     }
     if (orthoPlanLink.IsActive != oldOrthoPlanLink.IsActive)
     {
         return(true);
     }
     //SecDateTEntry not allowed to change
     if (orthoPlanLink.SecUserNumEntry != oldOrthoPlanLink.SecUserNumEntry)
     {
         return(true);
     }
     return(false);
 }
Example #2
0
        public void OrthoCases_Delete_DeleteOrthoCaseAndAssociatedObjects()
        {
            Prefs.UpdateString(PrefName.OrthoBandingCodes, "D8080");
            Prefs.UpdateString(PrefName.OrthoDebondCodes, "D8070");
            Prefs.UpdateString(PrefName.OrthoVisitCodes, "D8060");
            Userod user = UserodT.CreateUser();

            Security.CurUser = user;
            Patient   pat          = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name);
            Procedure bandingProc  = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.C, "", 0);
            Procedure visitProc    = ProcedureT.CreateProcedure(pat, "D8060", ProcStat.C, "", 0);
            Procedure debondProc   = ProcedureT.CreateProcedure(pat, "D8070", ProcStat.C, "", 0);
            long      orthoCaseNum = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc);

            OrthoProcLinks.LinkProcForActiveOrthoCase(visitProc);
            OrthoProcLinks.LinkProcForActiveOrthoCase(debondProc);
            OrthoCase            orthoCase        = OrthoCases.GetOne(orthoCaseNum);
            OrthoPlanLink        schedulePlanLink = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum, OrthoPlanLinkType.OrthoSchedule);
            long                 orthoscheduleNum = schedulePlanLink.FKey;
            OrthoSchedule        orthoSchedule    = OrthoSchedules.GetOne(schedulePlanLink.FKey);
            List <OrthoProcLink> listAllProcLinks = OrthoProcLinks.GetManyByOrthoCase(orthoCaseNum);

            OrthoCases.Delete(orthoCase.OrthoCaseNum, orthoSchedule, schedulePlanLink, listAllProcLinks);
            orthoCase        = OrthoCases.GetOne(orthoCaseNum);
            schedulePlanLink = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum, OrthoPlanLinkType.OrthoSchedule);
            orthoSchedule    = OrthoSchedules.GetOne(orthoscheduleNum);
            listAllProcLinks = OrthoProcLinks.GetManyByOrthoCase(orthoCaseNum);
            Assert.AreEqual(orthoCase, null);
            Assert.AreEqual(schedulePlanLink, null);
            Assert.AreEqual(orthoSchedule, null);
            Assert.AreEqual(listAllProcLinks.Count, 0);
        }
        ///<summary>Inserts one OrthoPlanLink into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(OrthoPlanLink orthoPlanLink, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO orthoplanlink (";

            if (!useExistingPK && isRandomKeys)
            {
                orthoPlanLink.OrthoPlanLinkNum = ReplicationServers.GetKeyNoCache("orthoplanlink", "OrthoPlanLinkNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "OrthoPlanLinkNum,";
            }
            command += "OrthoCaseNum,LinkType,FKey,IsActive,SecDateTEntry,SecUserNumEntry) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(orthoPlanLink.OrthoPlanLinkNum) + ",";
            }
            command +=
                POut.Long(orthoPlanLink.OrthoCaseNum) + ","
                + POut.Int((int)orthoPlanLink.LinkType) + ","
                + POut.Long(orthoPlanLink.FKey) + ","
                + POut.Bool(orthoPlanLink.IsActive) + ","
                + DbHelper.Now() + ","
                + POut.Long(orthoPlanLink.SecUserNumEntry) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                orthoPlanLink.OrthoPlanLinkNum = Db.NonQ(command, true, "OrthoPlanLinkNum", "orthoPlanLink");
            }
            return(orthoPlanLink.OrthoPlanLinkNum);
        }
        ///<summary>Updates one OrthoPlanLink 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(OrthoPlanLink orthoPlanLink, OrthoPlanLink oldOrthoPlanLink)
        {
            string command = "";

            if (orthoPlanLink.OrthoCaseNum != oldOrthoPlanLink.OrthoCaseNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OrthoCaseNum = " + POut.Long(orthoPlanLink.OrthoCaseNum) + "";
            }
            if (orthoPlanLink.LinkType != oldOrthoPlanLink.LinkType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "LinkType = " + POut.Int((int)orthoPlanLink.LinkType) + "";
            }
            if (orthoPlanLink.FKey != oldOrthoPlanLink.FKey)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FKey = " + POut.Long(orthoPlanLink.FKey) + "";
            }
            if (orthoPlanLink.IsActive != oldOrthoPlanLink.IsActive)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IsActive = " + POut.Bool(orthoPlanLink.IsActive) + "";
            }
            //SecDateTEntry not allowed to change
            if (orthoPlanLink.SecUserNumEntry != oldOrthoPlanLink.SecUserNumEntry)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SecUserNumEntry = " + POut.Long(orthoPlanLink.SecUserNumEntry) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE orthoplanlink SET " + command
                      + " WHERE OrthoPlanLinkNum = " + POut.Long(orthoPlanLink.OrthoPlanLinkNum);
            Db.NonQ(command);
            return(true);
        }
        ///<summary>Updates one OrthoPlanLink in the database.</summary>
        public static void Update(OrthoPlanLink orthoPlanLink)
        {
            string command = "UPDATE orthoplanlink SET "
                             + "OrthoCaseNum    =  " + POut.Long(orthoPlanLink.OrthoCaseNum) + ", "
                             + "LinkType        =  " + POut.Int((int)orthoPlanLink.LinkType) + ", "
                             + "FKey            =  " + POut.Long(orthoPlanLink.FKey) + ", "
                             + "IsActive        =  " + POut.Bool(orthoPlanLink.IsActive) + ", "
                             //SecDateTEntry not allowed to change
                             + "SecUserNumEntry =  " + POut.Long(orthoPlanLink.SecUserNumEntry) + " "
                             + "WHERE OrthoPlanLinkNum = " + POut.Long(orthoPlanLink.OrthoPlanLinkNum);

            Db.NonQ(command);
        }
Example #6
0
        ///<summary>Inserts the OrthoCase, OrthoSchedule, Schedule OrthoPlanLink, and banding OrthoProcLink for an Ortho Case.</summary>
        public static long InsertForFormOrthoCase(long patNum, double fee, double feeInsPrimary, double feeInsSecondary, double feePat, DateTime bandingDate
                                                  , bool isTransfer, DateTime debondDateExpected, double bandingAmount, double debondAmount, double visitAmount, Procedure bandingProc)
        {
            //No remoting role check; no call to db
            //Ortho Case
            OrthoCase newOrthoCase = new OrthoCase();

            newOrthoCase.PatNum             = patNum;
            newOrthoCase.Fee                = fee;
            newOrthoCase.FeeInsPrimary      = feeInsPrimary;
            newOrthoCase.FeeInsSecondary    = feeInsSecondary;
            newOrthoCase.FeePat             = feePat;
            newOrthoCase.BandingDate        = bandingDate;
            newOrthoCase.DebondDateExpected = debondDateExpected;
            newOrthoCase.IsTransfer         = isTransfer;
            newOrthoCase.SecUserNumEntry    = Security.CurUser.UserNum;
            newOrthoCase.IsActive           = true; //New Ortho Cases can only be added if there are no other active ones. So we automatically set a new ortho case as active.
            if (bandingProc.AptNum != 0)            //If banding is scheduled save the appointment date instead.
            {
                newOrthoCase.BandingDate = bandingProc.ProcDate;
            }
            long orthoCaseNum = OrthoCases.Insert(newOrthoCase);
            //Ortho Schedule
            OrthoSchedule newOrthoSchedule = new OrthoSchedule();

            newOrthoSchedule.BandingAmount = bandingAmount;
            newOrthoSchedule.DebondAmount  = debondAmount;
            newOrthoSchedule.VisitAmount   = visitAmount;
            newOrthoSchedule.IsActive      = true;
            long orthoScheduleNum = OrthoSchedules.Insert(newOrthoSchedule);
            //Ortho Plan Link
            OrthoPlanLink newOrthoPlanLink = new OrthoPlanLink();

            newOrthoPlanLink.OrthoCaseNum    = orthoCaseNum;
            newOrthoPlanLink.LinkType        = OrthoPlanLinkType.OrthoSchedule;
            newOrthoPlanLink.FKey            = orthoScheduleNum;
            newOrthoPlanLink.IsActive        = true;
            newOrthoPlanLink.SecUserNumEntry = Security.CurUser.UserNum;
            OrthoPlanLinks.Insert(newOrthoPlanLink);
            //Banding Proc Link
            if (!newOrthoCase.IsTransfer)
            {
                OrthoProcLinks.Insert(OrthoProcLinks.CreateHelper(orthoCaseNum, bandingProc.ProcNum, OrthoProcType.Banding));
            }
            return(orthoCaseNum);
        }
Example #7
0
        public void OrthoCases_Activate_ActivateAnOrthoCaseAndDeactivateOthersForPat()
        {
            Userod user = UserodT.CreateUser();

            Security.CurUser = user;
            Patient       pat               = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name);
            Procedure     bandingProc1      = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.TP, "", 0);
            Procedure     bandingProc2      = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.TP, "", 0);
            long          orthoCaseNum1     = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc1);
            long          orthoCaseNum2     = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc2);
            OrthoCase     orthoCase2        = OrthoCases.GetOne(orthoCaseNum2);
            OrthoPlanLink schedulePlanLink2 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum2, OrthoPlanLinkType.OrthoSchedule);
            OrthoSchedule orthoSchedule2    = OrthoSchedules.GetOne(schedulePlanLink2.FKey);

            //Set one OrthoCase inactive. Now orthoCase1 is active and orthoCase2 is inactive.
            OrthoCases.SetActiveState(orthoCase2, schedulePlanLink2, orthoSchedule2, false);
            OrthoCase     orthoCase1        = OrthoCases.GetOne(orthoCaseNum1);
            OrthoPlanLink schedulePlanLink1 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum1, OrthoPlanLinkType.OrthoSchedule);
            OrthoSchedule orthoSchedule1    = OrthoSchedules.GetOne(schedulePlanLink1.FKey);

            orthoCase2        = OrthoCases.GetOne(orthoCaseNum2);
            schedulePlanLink2 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum2, OrthoPlanLinkType.OrthoSchedule);
            orthoSchedule2    = OrthoSchedules.GetOne(schedulePlanLink2.FKey);
            Assert.AreEqual(orthoCase1.IsActive, true);
            Assert.AreEqual(schedulePlanLink1.IsActive, true);
            Assert.AreEqual(orthoSchedule1.IsActive, true);
            Assert.AreEqual(orthoCase2.IsActive, false);
            Assert.AreEqual(schedulePlanLink2.IsActive, false);
            Assert.AreEqual(orthoSchedule2.IsActive, false);
            //Active orthoCase2 which should inactivate orthoCase1
            OrthoCases.Activate(orthoCase2, pat.PatNum);
            orthoCase1        = OrthoCases.GetOne(orthoCaseNum1);
            schedulePlanLink1 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum1, OrthoPlanLinkType.OrthoSchedule);
            orthoSchedule1    = OrthoSchedules.GetOne(schedulePlanLink1.FKey);
            orthoCase2        = OrthoCases.GetOne(orthoCaseNum2);
            schedulePlanLink2 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum2, OrthoPlanLinkType.OrthoSchedule);
            orthoSchedule2    = OrthoSchedules.GetOne(schedulePlanLink2.FKey);
            Assert.AreEqual(orthoCase1.IsActive, false);
            Assert.AreEqual(schedulePlanLink1.IsActive, false);
            Assert.AreEqual(orthoSchedule1.IsActive, false);
            Assert.AreEqual(orthoCase2.IsActive, true);
            Assert.AreEqual(schedulePlanLink2.IsActive, true);
            Assert.AreEqual(orthoSchedule2.IsActive, true);
        }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <OrthoPlanLink> TableToList(DataTable table)
        {
            List <OrthoPlanLink> retVal = new List <OrthoPlanLink>();
            OrthoPlanLink        orthoPlanLink;

            foreach (DataRow row in table.Rows)
            {
                orthoPlanLink = new OrthoPlanLink();
                orthoPlanLink.OrthoPlanLinkNum = PIn.Long(row["OrthoPlanLinkNum"].ToString());
                orthoPlanLink.OrthoCaseNum     = PIn.Long(row["OrthoCaseNum"].ToString());
                orthoPlanLink.LinkType         = (OpenDentBusiness.OrthoPlanLinkType)PIn.Int(row["LinkType"].ToString());
                orthoPlanLink.FKey             = PIn.Long(row["FKey"].ToString());
                orthoPlanLink.IsActive         = PIn.Bool(row["IsActive"].ToString());
                orthoPlanLink.SecDateTEntry    = PIn.DateT(row["SecDateTEntry"].ToString());
                orthoPlanLink.SecUserNumEntry  = PIn.Long(row["SecUserNumEntry"].ToString());
                retVal.Add(orthoPlanLink);
            }
            return(retVal);
        }
Example #9
0
        public void OrthoProcLinks_SetProcFeeForLinkedProc_SetFeeForEachProcType()
        {
            Patient              pat                = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name);
            Procedure            bandingProc        = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.C, "", 0);
            Procedure            visitProc          = ProcedureT.CreateProcedure(pat, "D8060", ProcStat.C, "", 0);
            Procedure            debondProc         = ProcedureT.CreateProcedure(pat, "D8070", ProcStat.C, "", 0);
            long                 orthoCaseNum       = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, new Procedure());
            OrthoCase            orthoCase          = OrthoCases.GetOne(orthoCaseNum);
            OrthoPlanLink        schedulePlanLink   = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum, OrthoPlanLinkType.OrthoSchedule);
            OrthoSchedule        orthoSchedule      = OrthoSchedules.GetOne(schedulePlanLink.FKey);
            List <OrthoProcLink> listVisitProcLinks = OrthoProcLinks.GetVisitLinksForOrthoCase(orthoCaseNum);

            OrthoProcLinks.SetProcFeeForLinkedProc(orthoCase, bandingProc, OrthoProcType.Banding, listVisitProcLinks, schedulePlanLink, orthoSchedule);
            OrthoProcLinks.SetProcFeeForLinkedProc(orthoCase, visitProc, OrthoProcType.Visit, listVisitProcLinks, schedulePlanLink, orthoSchedule);
            OrthoProcLinks.SetProcFeeForLinkedProc(orthoCase, debondProc, OrthoProcType.Debond, listVisitProcLinks, schedulePlanLink, orthoSchedule);
            Assert.AreEqual(bandingProc.ProcFee, 1000);
            Assert.AreEqual(debondProc.ProcFee, 400);
            Assert.AreEqual(visitProc.ProcFee, 60);
        }
 ///<summary>Inserts one OrthoPlanLink into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(OrthoPlanLink orthoPlanLink)
 {
     return(InsertNoCache(orthoPlanLink, false));
 }
Example #11
0
        public void ClaimProcs_ComputeEstimatesByOrthoCase_SetClaimProcForEachProcType()
        {
            Prefs.UpdateString(PrefName.OrthoBandingCodes, "D8080");
            Prefs.UpdateString(PrefName.OrthoDebondCodes, "D8070");
            Prefs.UpdateString(PrefName.OrthoVisitCodes, "D8060");
            Patient       pat              = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name);
            Procedure     bandingProc      = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.C, "", 0);
            PatPlan       patPlan          = PatPlanT.CreatePatPlan(1, pat.PatNum, 0);
            ClaimProc     bandingClaimProc = ClaimProcT.CreateClaimProc(pat.PatNum, bandingProc.ProcNum, 0, 0, bandingProc.ProcDate, 1, 1, 1);
            Procedure     visitProc        = ProcedureT.CreateProcedure(pat, "D8060", ProcStat.C, "", 0);
            ClaimProc     visitClaimProc   = ClaimProcT.CreateClaimProc(pat.PatNum, visitProc.ProcNum, 0, 0, visitProc.ProcDate, 1, 1, 1);
            Procedure     debondProc       = ProcedureT.CreateProcedure(pat, "D8070", ProcStat.C, "", 0);
            ClaimProc     debondClaimProc  = ClaimProcT.CreateClaimProc(pat.PatNum, debondProc.ProcNum, 0, 0, debondProc.ProcDate, 1, 1, 1);
            long          orthoCaseNum     = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc);
            OrthoCase     orthoCase        = OrthoCases.GetOne(orthoCaseNum);
            OrthoPlanLink schedulePlanLink = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum, OrthoPlanLinkType.OrthoSchedule);
            OrthoSchedule orthoSchedule    = OrthoSchedules.GetOne(schedulePlanLink.FKey);

            OrthoProcLinks.LinkProcForActiveOrthoCase(bandingProc);
            OrthoProcLinks.LinkProcForActiveOrthoCase(visitProc);
            OrthoProcLinks.LinkProcForActiveOrthoCase(debondProc);
            List <OrthoProcLink> allProcLinks      = OrthoProcLinks.GetManyByOrthoCase(orthoCaseNum);
            OrthoProcLink        bandingLink       = allProcLinks.FirstOrDefault(x => x.ProcLinkType == OrthoProcType.Banding);
            OrthoProcLink        debondLink        = allProcLinks.FirstOrDefault(x => x.ProcLinkType == OrthoProcType.Debond);
            OrthoProcLink        visitLink         = allProcLinks.FirstOrDefault(x => x.ProcLinkType == OrthoProcType.Visit);
            List <ClaimProc>     listAllClaimProcs = new List <ClaimProc>()
            {
                bandingClaimProc, visitClaimProc, debondClaimProc
            };
            List <OrthoProcLink> listAllOrthoProcLinks = new List <OrthoProcLink>()
            {
                bandingLink, visitLink, debondLink
            };
            List <PatPlan> listPatPlans = new List <PatPlan>()
            {
                patPlan
            };

            ClaimProcs.ComputeEstimatesByOrthoCase(bandingProc, bandingLink, orthoCase, orthoSchedule, true, listAllClaimProcs,
                                                   new List <ClaimProc>()
            {
                bandingClaimProc
            }, listPatPlans, listAllOrthoProcLinks);
            ClaimProcs.ComputeEstimatesByOrthoCase(debondProc, debondLink, orthoCase, orthoSchedule, true, listAllClaimProcs,
                                                   new List <ClaimProc>()
            {
                debondClaimProc
            }, listPatPlans, listAllOrthoProcLinks);
            ClaimProcs.ComputeEstimatesByOrthoCase(visitProc, visitLink, orthoCase, orthoSchedule, true, listAllClaimProcs,
                                                   new List <ClaimProc>()
            {
                visitClaimProc
            }, listPatPlans, listAllOrthoProcLinks);
            Assert.AreEqual(bandingClaimProc.AllowedOverride, 0);
            Assert.AreEqual(bandingClaimProc.CopayOverride, 0);
            Assert.AreEqual(bandingClaimProc.PercentOverride, 0);
            Assert.AreEqual(bandingClaimProc.PaidOtherInsOverride, 0);
            Assert.AreEqual(bandingClaimProc.WriteOffEstOverride, 0);
            Assert.AreEqual(bandingClaimProc.InsEstTotalOverride, 600);
            Assert.AreEqual(debondClaimProc.AllowedOverride, 0);
            Assert.AreEqual(debondClaimProc.CopayOverride, 0);
            Assert.AreEqual(debondClaimProc.PercentOverride, 0);
            Assert.AreEqual(debondClaimProc.PaidOtherInsOverride, 0);
            Assert.AreEqual(debondClaimProc.WriteOffEstOverride, 0);
            Assert.AreEqual(debondClaimProc.InsEstTotalOverride, 240);
            Assert.AreEqual(visitClaimProc.AllowedOverride, 0);
            Assert.AreEqual(visitClaimProc.CopayOverride, 0);
            Assert.AreEqual(visitClaimProc.PercentOverride, 0);
            Assert.AreEqual(visitClaimProc.PaidOtherInsOverride, 0);
            Assert.AreEqual(visitClaimProc.WriteOffEstOverride, 0);
            Assert.AreEqual(visitClaimProc.InsEstTotalOverride, 36);
        }