Beispiel #1
0
 ///<summary>Compares two procedures and returns the order they should appear based on status, priority, toothrange, toothnum, then proccode.
 ///Uses the same logic as the other CompareProcedures but takes Procedure objects instead of DataRows.
 ///Only used for the Appointment Edit window currently.</summary>
 public static int CompareProcedures(Procedure x, Procedure y)
 {
     //first by status
     if (x.ProcStatus != y.ProcStatus)
     {
         //Cn,TP,R,EO,C,EC,D
         //EC procs will draw on top of C procs of same date in the 3D tooth chart,
         //but this is not a problem since C procs should always have a later date than EC procs.
         //EC must come after C so that group notes will come after their procedures in Progress Notes.
         int             xIdx, yIdx;
         List <ProcStat> sortOrder = new List <ProcStat>
         {                //The order of statuses in this list is very important and determines the sort order for procedures.
             ProcStat.TPi,
             ProcStat.Cn,
             ProcStat.TP,
             ProcStat.R,
             ProcStat.EO,
             ProcStat.C,
             ProcStat.EC,
             ProcStat.D
         };
         xIdx = sortOrder.IndexOf(x.ProcStatus);
         yIdx = sortOrder.IndexOf(y.ProcStatus);
         return(xIdx.CompareTo(yIdx));
     }
     //by priority
     if (x.Priority != y.Priority)           //if priorities are different
     {
         if (x.Priority == 0)
         {
             return(1);                           //x is greater than y. Priorities always come first.
         }
         if (y.Priority == 0)
         {
             return(-1);                           //x is less than y. Priorities always come first.
         }
         return(Defs.GetOrder(DefCat.TxPriorities, x.Priority).CompareTo(Defs.GetOrder(DefCat.TxPriorities, y.Priority)));
     }
     //priorities are the same, so sort by toothrange
     if (x.ToothRange != y.ToothRange)
     {
         //empty toothranges come before filled toothrange values
         return(x.ToothRange.CompareTo(y.ToothRange));
     }
     //toothranges are the same (usually empty), so compare toothnumbers
     if (x.ToothNum != y.ToothNum)
     {
         //this also puts invalid or empty toothnumbers before the others.
         return(Tooth.ToInt(x.ToothNum).CompareTo(Tooth.ToInt(y.ToothNum)));
     }
     //priority and toothnums are the same, so sort by proccode.
     if (x.CodeNum != y.CodeNum)
     {
         return(ProcedureCodes.GetProcCode(x.CodeNum).ProcCode.CompareTo(ProcedureCodes.GetProcCode(y.CodeNum).ProcCode));
     }
     //if everything else is the same, sort by ProcNum so sort is deterministic
     return(x.ProcNum.CompareTo(y.ProcNum));
 }
Beispiel #2
0
        public static DataTable GetTreeListTableForPatient(string patNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), patNum));
            }
            DataConnection dcon  = new DataConnection();
            DataTable      table = new DataTable("DocumentList");
            DataRow        row;
            DataTable      raw;
            string         command;
            //Rows are first added to the resultSet list so they can be sorted at the end as a larger group, then
            //they are placed in the datatable to be returned.
            List <Object> resultSet = new List <Object>();

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("DocNum");
            table.Columns.Add("MountNum");
            table.Columns.Add("DocCategory");
            table.Columns.Add("DateCreated");
            table.Columns.Add("docFolder");            //The folder order to which the Document category corresponds.
            table.Columns.Add("description");
            table.Columns.Add("ImgType");
            //Move all documents which are invisible to the first document category.
            command = "SELECT DocNum FROM document WHERE PatNum='" + patNum + "' AND "
                      + "DocCategory<0";
            raw = dcon.GetTable(command);
            if (raw.Rows.Count > 0)          //Are there any invisible documents?
            {
                command = "UPDATE document SET DocCategory='" + Defs.GetFirstForCategory(DefCat.ImageCats, true).DefNum
                          + "' WHERE PatNum='" + patNum + "' AND (";
                for (int i = 0; i < raw.Rows.Count; i++)
                {
                    command += "DocNum='" + PIn.Long(raw.Rows[i]["DocNum"].ToString()) + "' ";
                    if (i < raw.Rows.Count - 1)
                    {
                        command += "OR ";
                    }
                }
                command += ")";
                dcon.NonQ(command);
            }
            //Load all documents into the result table.
            command = "SELECT DocNum,DocCategory,DateCreated,Description,ImgType,MountItemNum FROM document WHERE PatNum='" + patNum + "'";
            raw     = dcon.GetTable(command);
            for (int i = 0; i < raw.Rows.Count; i++)
            {
                //Make sure hidden documents are never added (there is a small possibility that one is added after all are made visible).
                if (Defs.GetOrder(DefCat.ImageCats, PIn.Long(raw.Rows[i]["DocCategory"].ToString())) < 0)
                {
                    continue;
                }
                //Do not add individual documents which are part of a mount object.
                if (PIn.Long(raw.Rows[i]["MountItemNum"].ToString()) != 0)
                {
                    continue;
                }
                row                = table.NewRow();
                row["DocNum"]      = PIn.Long(raw.Rows[i]["DocNum"].ToString());
                row["MountNum"]    = 0;
                row["DocCategory"] = PIn.Long(raw.Rows[i]["DocCategory"].ToString());
                row["DateCreated"] = PIn.Date(raw.Rows[i]["DateCreated"].ToString());
                row["docFolder"]   = Defs.GetOrder(DefCat.ImageCats, PIn.Long(raw.Rows[i]["DocCategory"].ToString()));
                row["description"] = PIn.Date(raw.Rows[i]["DateCreated"].ToString()).ToString("d") + ": "
                                     + PIn.String(raw.Rows[i]["Description"].ToString());
                row["ImgType"] = PIn.Long(raw.Rows[i]["ImgType"].ToString());
                resultSet.Add(row);
            }
            //Move all mounts which are invisible to the first document category.
            command = "SELECT MountNum FROM mount WHERE PatNum='" + patNum + "' AND "
                      + "DocCategory<0";
            raw = dcon.GetTable(command);
            if (raw.Rows.Count > 0)           //Are there any invisible mounts?
            {
                command = "UPDATE mount SET DocCategory='" + Defs.GetFirstForCategory(DefCat.ImageCats, true).DefNum
                          + "' WHERE PatNum='" + patNum + "' AND (";
                for (int i = 0; i < raw.Rows.Count; i++)
                {
                    command += "MountNum='" + PIn.Long(raw.Rows[i]["MountNum"].ToString()) + "' ";
                    if (i < raw.Rows.Count - 1)
                    {
                        command += "OR ";
                    }
                }
                command += ")";
                dcon.NonQ(command);
            }
            //Load all mounts into the result table.
            command = "SELECT MountNum,DocCategory,DateCreated,Description,ImgType FROM mount WHERE PatNum='" + patNum + "'";
            raw     = dcon.GetTable(command);
            for (int i = 0; i < raw.Rows.Count; i++)
            {
                //Make sure hidden mounts are never added (there is a small possibility that one is added after all are made visible).
                if (Defs.GetOrder(DefCat.ImageCats, PIn.Long(raw.Rows[i]["DocCategory"].ToString())) < 0)
                {
                    continue;
                }
                row                = table.NewRow();
                row["DocNum"]      = 0;
                row["MountNum"]    = PIn.Long(raw.Rows[i]["MountNum"].ToString());
                row["DocCategory"] = PIn.Long(raw.Rows[i]["DocCategory"].ToString());
                row["DateCreated"] = PIn.Date(raw.Rows[i]["DateCreated"].ToString());
                row["docFolder"]   = Defs.GetOrder(DefCat.ImageCats, PIn.Long(raw.Rows[i]["DocCategory"].ToString()));
                row["description"] = PIn.Date(raw.Rows[i]["DateCreated"].ToString()).ToString("d") + ": "
                                     + PIn.String(raw.Rows[i]["Description"].ToString());
                row["ImgType"] = PIn.Long(raw.Rows[i]["ImgType"].ToString());
                resultSet.Add(row);
            }
            //We must sort the results after they are returned from the database, because the database software (i.e. MySQL)
            //cannot return sorted results from two or more result sets like we have here.
            resultSet.Sort(delegate(Object o1, Object o2) {
                DataRow r1     = (DataRow)o1;
                DataRow r2     = (DataRow)o2;
                int docFolder1 = Convert.ToInt32(r1["docFolder"].ToString());
                int docFolder2 = Convert.ToInt32(r2["docFolder"].ToString());
                if (docFolder1 < docFolder2)
                {
                    return(-1);
                }
                else if (docFolder1 > docFolder2)
                {
                    return(1);
                }
                return(PIn.Date(r1["DateCreated"].ToString()).CompareTo(PIn.Date(r2["DateCreated"].ToString())));
            });
            //Finally, move the results from the list into a data table.
            for (int i = 0; i < resultSet.Count; i++)
            {
                table.Rows.Add((DataRow)resultSet[i]);
            }
            return(table);
        }
Beispiel #3
0
 ///<summary>Compares two procedures and returns the order they should appear based on status, priority, toothrange, toothnum, then proccode.
 ///Uses the same logic as the other CompareProcedures but takes Procedure objects instead of DataRows.
 ///Does not sort Canadian labs correctly.  Make sure there are no Canadian labs present prior to comparing.</summary>
 public static int CompareProcedures(Procedure x, Procedure y)
 {
     //We cannot sort Canadian labs within this comparer because there can be multiple labs associated to one procedure.
     //This comparer doesn't have enough information in order to sort a procedure and correctly move the corresponding lab(s) with it.
     //Therefore, Canadian labs need to be sorted as an additional step after this comparer has been invoked.
     //=========================================================================================================================
     //if(CultureInfo.CurrentCulture.Name.EndsWith("CA") && x.ProcNumLab!=y.ProcNumLab) {//This code should not impact USA users
     //	int retVal=CanadianLabSortHelper(x,y);
     //	if(retVal!=0) {
     //		return retVal;
     //	}
     //}
     //=========================================================================================================================
     //first by status
     if (x.ProcStatus != y.ProcStatus)
     {
         //Cn,TP,R,EO,C,EC,D
         //EC procs will draw on top of C procs of same date in the 3D tooth chart,
         //but this is not a problem since C procs should always have a later date than EC procs.
         //EC must come after C so that group notes will come after their procedures in Progress Notes.
         int             xIdx, yIdx;
         List <ProcStat> sortOrder = new List <ProcStat>
         {                //The order of statuses in this list is very important and determines the sort order for procedures.
             ProcStat.TPi,
             ProcStat.Cn,
             ProcStat.TP,
             ProcStat.R,
             ProcStat.EO,
             ProcStat.C,
             ProcStat.EC,
             ProcStat.D
         };
         xIdx = sortOrder.IndexOf(x.ProcStatus);
         yIdx = sortOrder.IndexOf(y.ProcStatus);
         return(xIdx.CompareTo(yIdx));
     }
     //by priority
     if (x.Priority != y.Priority)           //if priorities are different
     {
         if (x.Priority == 0)
         {
             return(1);                           //x is greater than y. Priorities always come first.
         }
         if (y.Priority == 0)
         {
             return(-1);                           //x is less than y. Priorities always come first.
         }
         return(Defs.GetOrder(DefCat.TxPriorities, x.Priority).CompareTo(Defs.GetOrder(DefCat.TxPriorities, y.Priority)));
     }
     //priorities are the same, so sort by toothrange
     if (x.ToothRange != y.ToothRange)
     {
         //empty toothranges come before filled toothrange values
         return(x.ToothRange.CompareTo(y.ToothRange));
     }
     //toothranges are the same (usually empty), so compare toothnumbers
     if (x.ToothNum != y.ToothNum)
     {
         //this also puts invalid or empty toothnumbers before the others.
         return(Tooth.ToInt(x.ToothNum).CompareTo(Tooth.ToInt(y.ToothNum)));
     }
     //priority and toothnums are the same, so sort by proccode.
     if (x.CodeNum != y.CodeNum)
     {
         //GetProcCode(...).ProcCode can be null.
         //We do not protect the second call because comparing any string to null doesn't cause an error.
         string procCode = ProcedureCodes.GetProcCode(x.CodeNum).ProcCode ?? "";
         return(procCode.CompareTo(ProcedureCodes.GetProcCode(y.CodeNum).ProcCode));
     }
     //if everything else is the same, sort by ProcNum so sort is deterministic
     return(x.ProcNum.CompareTo(y.ProcNum));
 }
Beispiel #4
0
        ///<summary>The supplied DataRows must include the following columns: ProcStatus(optional),Priority(optional),ToothRange,ToothNum,ProcCode.  This sorts procedures based on priority, then tooth number, then procCode.  It does not care about dates or status.  Currently used in Account module, appointments, and Chart module sorting.  TP uses Procedures.ProcedureComparer.</summary>
        public static int CompareProcedures(DataRow x, DataRow y)
        {
            //first, by status
            if (x.Table.Columns.Contains("ProcStatus") && y.Table.Columns.Contains("ProcStatus"))
            {
                if (x["ProcStatus"].ToString() != y["ProcStatus"].ToString())
                {
                    //Cn,TP,R,EO,C,EC,D
                    //EC procs will draw on top of C procs of same date in the 3D tooth chart,
                    //but this is not a problem since C procs should always have a later date than EC procs.
                    //EC must come after C so that group notes will come after their procedures in Progress Notes.
                    int xIdx = 0;
                    switch (x["ProcStatus"].ToString())
                    {
                    case "8":                            //TPi
                        xIdx = 0;
                        break;

                    case "7":                            //Cn
                        xIdx = 1;
                        break;

                    case "1":                            //TP
                        xIdx = 2;
                        break;

                    case "5":                            //R
                        xIdx = 3;
                        break;

                    case "4":                            //EO
                        xIdx = 4;
                        break;

                    case "2":                            //C
                        xIdx = 5;
                        break;

                    case "3":                            //EC
                        xIdx = 6;
                        break;

                    case "6":                            //D
                        xIdx = 7;
                        break;
                    }
                    int yIdx = 0;
                    switch (y["ProcStatus"].ToString())
                    {
                    case "8":                            //TPi
                        yIdx = 0;
                        break;

                    case "7":                            //Cn
                        yIdx = 1;
                        break;

                    case "1":                            //TP
                        yIdx = 2;
                        break;

                    case "5":                            //R
                        yIdx = 3;
                        break;

                    case "4":                            //EO
                        yIdx = 4;
                        break;

                    case "2":                            //C
                        yIdx = 5;
                        break;

                    case "3":                            //EC
                        yIdx = 6;
                        break;

                    case "6":                            //D
                        yIdx = 7;
                        break;
                    }
                    return(xIdx.CompareTo(yIdx));
                }
            }
            //by priority
            if (x.Table.Columns.Contains("Priority") && y.Table.Columns.Contains("Priority"))
            {
                if (x["Priority"].ToString() != y["Priority"].ToString())               //if priorities are different
                {
                    if (x["Priority"].ToString() == "0")
                    {
                        return(1);                       //x is greater than y. Priorities always come first.
                    }
                    if (y["Priority"].ToString() == "0")
                    {
                        return(-1);                       //x is less than y. Priorities always come first.
                    }
                    return(Defs.GetOrder(DefCat.TxPriorities, PIn.Long(x["Priority"].ToString())).CompareTo
                               (Defs.GetOrder(DefCat.TxPriorities, PIn.Long(y["Priority"].ToString()))));
                }
            }
            //priorities are the same, so sort by toothrange
            if (x["ToothRange"].ToString() != y["ToothRange"].ToString())
            {
                //empty toothranges come before filled toothrange values
                return(x["ToothRange"].ToString().CompareTo(y["ToothRange"].ToString()));
            }
            //toothranges are the same (usually empty), so compare toothnumbers
            if (x["ToothNum"].ToString() != y["ToothNum"].ToString())
            {
                //this also puts invalid or empty toothnumbers before the others.
                return(Tooth.ToInt(x["ToothNum"].ToString()).CompareTo(Tooth.ToInt(y["ToothNum"].ToString())));
            }
            if (x["ProcCode"].ToString() != y["ProcCode"].ToString())
            {
                //priority and toothnums are the same, so sort by proccode if different.
                return(x["ProcCode"].ToString().CompareTo(y["ProcCode"].ToString()));
            }
            //priority, tooth number, and proccode are all the same.  Sort by ProcNum so we have a determinate order if everything else is the same.
            return(x["ProcNum"].ToString().CompareTo(y["ProcNum"].ToString()));
        }