コード例 #1
0
 ///<summary>Returns a DefNum for the special image category specified.  Returns 0 if no match found.</summary>
 public static long GetImageCat(ImageCategorySpecial specialCat)
 {
     Def[] defs = DefC.GetList(DefCat.ImageCats);
     for (int i = 0; i < defs.Length; i++)
     {
         if (defs[i].ItemValue.Contains(specialCat.ToString()))
         {
             return(defs[i].DefNum);
         }
     }
     return(0);
 }
コード例 #2
0
ファイル: Documents.cs プロジェクト: nampn/ODental
        ///<summary>Will return null if no picture for this patient.</summary>
        public static Document GetPatPictFromDb(long patNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <Document>(MethodBase.GetCurrentMethod(), patNum));
            }
            //first establish which category pat pics are in
            long defNumPicts = 0;

            Def[] defs = DefC.GetList(DefCat.ImageCats);
            for (int i = 0; i < defs.Length; i++)
            {
                if (Regex.IsMatch(defs[i].ItemValue, @"P"))
                {
                    defNumPicts = defs[i].DefNum;
                    break;
                }
            }
            if (defNumPicts == 0)          //no category set for picts
            {
                return(null);
            }
            //then find, limit 1 to get the most recent
            string command = "SELECT * FROM document "
                             + "WHERE document.PatNum=" + POut.Long(patNum)
                             + " AND document.DocCategory=" + POut.Long(defNumPicts)
                             + " ORDER BY DateCreated DESC";

            command = DbHelper.LimitOrderBy(command, 1);
            DataTable table = Db.GetTable(command);

            Document[] pictureDocs = Fill(table);
            if (pictureDocs == null || pictureDocs.Length < 1)        //no pictures
            {
                return(null);
            }
            return(pictureDocs[0]);
        }
コード例 #3
0
ファイル: Documents.cs プロジェクト: nampn/ODental
        ///<summary>Any filenames mentioned in the fileList which are not attached to the given patient are properly attached to that patient. Returns the total number of documents that were newly attached to the patient.</summary>
        public static int InsertMissing(Patient patient, List <string> fileList)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetInt(MethodBase.GetCurrentMethod(), patient, fileList));
            }
            int       countAdded = 0;
            string    command    = "SELECT FileName FROM document WHERE PatNum='" + patient.PatNum + "' ORDER BY FileName";
            DataTable table      = Db.GetTable(command);

            for (int j = 0; j < fileList.Count; j++)
            {
                string fileName = Path.GetFileName(fileList[j]);
                if (!IsAcceptableFileName(fileName))
                {
                    continue;
                }
                bool inList = false;
                for (int i = 0; i < table.Rows.Count && !inList; i++)
                {
                    inList = (table.Rows[i]["FileName"].ToString() == fileName);
                }
                if (!inList)
                {
                    Document doc = new Document();
                    doc.DateCreated = File.GetLastWriteTime(fileList[j]);
                    doc.Description = fileName;
                    doc.DocCategory = DefC.GetList(DefCat.ImageCats)[0].DefNum;                  //First category.
                    doc.FileName    = fileName;
                    doc.PatNum      = patient.PatNum;
                    Insert(doc, patient);
                    countAdded++;
                }
            }
            return(countAdded);
        }
コード例 #4
0
ファイル: Statements.cs プロジェクト: steev90/opendental
        ///<summary>For orderBy, use 0 for BillingType and 1 for PatientName.</summary>
        public static DataTable GetBilling(bool isSent, int orderBy, DateTime dateFrom, DateTime dateTo, long clinicNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), isSent, orderBy, dateFrom, dateTo, clinicNum));
            }
            DataTable table = new DataTable();
            DataRow   row;

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("amountDue");
            table.Columns.Add("balTotal");
            table.Columns.Add("billingType");
            table.Columns.Add("insEst");
            table.Columns.Add("IsSent");
            table.Columns.Add("lastStatement");
            table.Columns.Add("mode");
            table.Columns.Add("name");
            table.Columns.Add("PatNum");
            table.Columns.Add("payPlanDue");
            table.Columns.Add("StatementNum");
            List <DataRow> rows    = new List <DataRow>();
            string         command = "SELECT BalTotal,BillingType,FName,InsEst,statement.IsSent,"
                                     + "IFNULL(MAX(s2.DateSent)," + POut.Date(DateTime.MinValue) + ") LastStatement,"
                                     + "LName,MiddleI,statement.Mode_,PayPlanDue,Preferred,"
                                     + "statement.PatNum,statement.StatementNum "
                                     + "FROM statement "
                                     + "LEFT JOIN patient ON statement.PatNum=patient.PatNum "
                                     + "LEFT JOIN statement s2 ON s2.PatNum=patient.PatNum "
                                     + "AND s2.IsSent=1 ";

            if (PrefC.GetBool(PrefName.BillingIgnoreInPerson))
            {
                command += "AND s2.Mode_ !=1 ";
            }
            if (orderBy == 0)          //BillingType
            {
                command += "LEFT JOIN definition ON patient.BillingType=definition.DefNum ";
            }
            command += "WHERE statement.IsSent=" + POut.Bool(isSent) + " ";
            //if(dateFrom.Year>1800){
            command += "AND statement.DateSent>=" + POut.Date(dateFrom) + " ";      //greater than midnight this morning
            //}
            //if(dateFrom.Year>1800){
            command += "AND statement.DateSent<" + POut.Date(dateTo.AddDays(1)) + " ";      //less than midnight tonight
            //}
            if (clinicNum > 0)
            {
                command += "AND patient.ClinicNum=" + clinicNum + " ";
            }
            command += "GROUP BY BalTotal,BillingType,FName,InsEst,statement.IsSent,"
                       + "LName,MiddleI,statement.Mode_,PayPlanDue,Preferred,"
                       + "statement.PatNum,statement.StatementNum ";
            if (orderBy == 0)          //BillingType
            {
                command += "ORDER BY definition.ItemOrder,LName,FName,MiddleI,PayPlanDue";
            }
            else
            {
                command += "ORDER BY LName,FName";
            }
            DataTable     rawTable = Db.GetTable(command);
            Patient       pat;
            StatementMode mode;
            double        balTotal;
            double        insEst;
            double        payPlanDue;
            DateTime      lastStatement;

            for (int i = 0; i < rawTable.Rows.Count; i++)
            {
                row                = table.NewRow();
                balTotal           = PIn.Double(rawTable.Rows[i]["BalTotal"].ToString());
                insEst             = PIn.Double(rawTable.Rows[i]["InsEst"].ToString());
                payPlanDue         = PIn.Double(rawTable.Rows[i]["PayPlanDue"].ToString());
                row["amountDue"]   = (balTotal - insEst).ToString("F");
                row["balTotal"]    = balTotal.ToString("F");;
                row["billingType"] = DefC.GetName(DefCat.BillingTypes, PIn.Long(rawTable.Rows[i]["BillingType"].ToString()));
                if (insEst == 0)
                {
                    row["insEst"] = "";
                }
                else
                {
                    row["insEst"] = insEst.ToString("F");
                }
                row["IsSent"] = rawTable.Rows[i]["IsSent"].ToString();
                lastStatement = PIn.Date(rawTable.Rows[i]["LastStatement"].ToString());
                if (lastStatement.Year < 1880)
                {
                    row["lastStatement"] = "";
                }
                else
                {
                    row["lastStatement"] = lastStatement.ToShortDateString();
                }
                mode          = (StatementMode)PIn.Long(rawTable.Rows[i]["Mode_"].ToString());
                row["mode"]   = Lans.g("enumStatementMode", mode.ToString());
                pat           = new Patient();
                pat.LName     = rawTable.Rows[i]["LName"].ToString();
                pat.FName     = rawTable.Rows[i]["FName"].ToString();
                pat.Preferred = rawTable.Rows[i]["Preferred"].ToString();
                pat.MiddleI   = rawTable.Rows[i]["MiddleI"].ToString();
                row["name"]   = pat.GetNameLF();
                row["PatNum"] = rawTable.Rows[i]["PatNum"].ToString();
                if (payPlanDue == 0)
                {
                    row["payPlanDue"] = "";
                }
                else
                {
                    row["payPlanDue"] = payPlanDue.ToString("F");
                }
                row["StatementNum"] = rawTable.Rows[i]["StatementNum"].ToString();
                rows.Add(row);
            }
            for (int i = 0; i < rows.Count; i++)
            {
                table.Rows.Add(rows[i]);
            }
            return(table);
        }
コード例 #5
0
ファイル: ProcedureLogic.cs プロジェクト: nampn/ODental
        ///<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 TP module and Chart module sorting.</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,EC,C,D
                    int xIdx = 0;
                    switch (x["ProcStatus"].ToString())
                    {
                    case "7":                            //Cn
                        xIdx = 0;
                        break;

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

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

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

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

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

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

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

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

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

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

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

                    case "6":                            //D
                        yIdx = 6;
                        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(DefC.GetOrder(DefCat.TxPriorities, PIn.Long(x["Priority"].ToString())).CompareTo
                               (DefC.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())));
            }
            //priority and toothnums are the same, so sort by proccode.
            return(x["ProcCode"].ToString().CompareTo(y["ProcCode"].ToString()));
            //return 0;//priority, tooth number, and proccode are all the same
        }
コード例 #6
0
ファイル: Commlogs.cs プロジェクト: nampn/ODental
        ///<summary>Used when printing or emailing recall to make a commlog entry without any display.</summary>
        public static void InsertForRecall(long patNum, CommItemMode _mode, int numberOfReminders, long defNumNewStatus)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), patNum, _mode, numberOfReminders, defNumNewStatus);
                return;
            }
            long   recallType = Commlogs.GetTypeAuto(CommItemTypeAuto.RECALL);
            string command;
            string datesql = "CURDATE()";

            if (DataConnection.DBtype == DatabaseType.Oracle)
            {
                datesql = "(SELECT CURRENT_DATE FROM dual)";
            }
            if (recallType != 0)
            {
                command  = "SELECT COUNT(*) FROM commlog WHERE ";
                command += DbHelper.DateColumn("CommDateTime") + " = " + datesql;
                command += " AND PatNum=" + POut.Long(patNum) + " AND CommType=" + POut.Long(recallType)
                           + " AND Mode_=" + POut.Long((int)_mode)
                           + " AND SentOrReceived=1";
                if (Db.GetCount(command) != "0")
                {
                    return;
                }
            }
            Commlog com = new Commlog();

            com.PatNum         = patNum;
            com.CommDateTime   = DateTime.Now;
            com.CommType       = recallType;
            com.Mode_          = _mode;
            com.SentOrReceived = CommSentOrReceived.Sent;
            com.Note           = "";
            if (numberOfReminders == 0)
            {
                com.Note = Lans.g("FormRecallList", "Recall reminder.");
            }
            else if (numberOfReminders == 1)
            {
                com.Note = Lans.g("FormRecallList", "Second recall reminder.");
            }
            else if (numberOfReminders == 2)
            {
                com.Note = Lans.g("FormRecallList", "Third recall reminder.");
            }
            else
            {
                com.Note = Lans.g("FormRecallList", "Recall reminder:") + " " + (numberOfReminders + 1).ToString();
            }
            if (defNumNewStatus == 0)
            {
                com.Note += "  " + Lans.g("Commlogs", "Status None");
            }
            else
            {
                com.Note += "  " + DefC.GetName(DefCat.RecallUnschedStatus, defNumNewStatus);
            }
            com.UserNum = Security.CurUser.UserNum;
            Insert(com);
        }
コード例 #7
0
ファイル: ProcedureCodes.cs プロジェクト: nampn/ODental
        ///<summary>Used to check whether codes starting with T exist and are in a visible category.  If so, it moves them to the Obsolete category.  If the T code has never been used, then it deletes it.</summary>
        public static void TcodesClear()
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod());
                return;
            }
            //first delete any unused T codes
            string    command = @"SELECT CodeNum,ProcCode FROM procedurecode
				WHERE NOT EXISTS(SELECT * FROM procedurelog WHERE procedurelog.CodeNum=procedurecode.CodeNum)
				AND ProcCode LIKE 'T%'"                ;
            DataTable table   = Db.GetTable(command);
            long      codenum;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                codenum = PIn.Long(table.Rows[i]["CodeNum"].ToString());
                command = "DELETE FROM fee WHERE CodeNum=" + POut.Long(codenum);
                Db.NonQ(command);
                command = "DELETE FROM procedurecode WHERE CodeNum=" + POut.Long(codenum);
                Db.NonQ(command);
            }
            //then, move any other T codes to obsolete category
            command = @"SELECT DISTINCT ProcCat FROM procedurecode,definition 
				WHERE procedurecode.ProcCode LIKE 'T%'
				AND definition.IsHidden=0
				AND procedurecode.ProcCat=definition.DefNum"                ;
            table   = Db.GetTable(command);
            long catNum = DefC.GetByExactName(DefCat.ProcCodeCats, "Obsolete");         //check to make sure an Obsolete category exists.
            Def  def;

            if (catNum != 0)           //if a category exists with that name
            {
                def = DefC.GetDef(DefCat.ProcCodeCats, catNum);
                if (!def.IsHidden)
                {
                    def.IsHidden = true;
                    Defs.Update(def);
                    Defs.RefreshCache();
                }
            }
            if (catNum == 0)
            {
                def           = new Def();
                def.Category  = DefCat.ProcCodeCats;
                def.ItemName  = "Obsolete";
                def.ItemOrder = DefC.Long[(int)DefCat.ProcCodeCats].Length;
                def.IsHidden  = true;
                Defs.Insert(def);
                Defs.RefreshCache();
                catNum = def.DefNum;
            }
            for (int i = 0; i < table.Rows.Count; i++)
            {
                command = "UPDATE procedurecode SET ProcCat=" + POut.Long(catNum)
                          + " WHERE ProcCat=" + table.Rows[i][0].ToString()
                          + " AND procedurecode.ProcCode LIKE 'T%'";
                Db.NonQ(command);
            }
            //finally, set Never Used category to be hidden.  This isn't really part of clearing Tcodes, but is required
            //because many customers won't have that category hidden
            catNum = DefC.GetByExactName(DefCat.ProcCodeCats, "Never Used");
            if (catNum != 0)           //if a category exists with that name
            {
                def = DefC.GetDef(DefCat.ProcCodeCats, catNum);
                if (!def.IsHidden)
                {
                    def.IsHidden = true;
                    Defs.Update(def);
                    Defs.RefreshCache();
                }
            }
        }
コード例 #8
0
        public static DataTable GetPatientFormsTable(long patNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), patNum));
            }
            //DataConnection dcon=new DataConnection();
            DataTable table = new DataTable("");
            DataRow   row;

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("date");
            table.Columns.Add("dateOnly", typeof(DateTime));           //to help with sorting
            table.Columns.Add("dateTime", typeof(DateTime));
            table.Columns.Add("description");
            table.Columns.Add("DocNum");
            table.Columns.Add("imageCat");
            table.Columns.Add("SheetNum");
            table.Columns.Add("showInTerminal");
            table.Columns.Add("time");
            table.Columns.Add("timeOnly", typeof(TimeSpan));           //to help with sorting
            //but we won't actually fill this table with rows until the very end.  It's more useful to use a List<> for now.
            List <DataRow> rows = new List <DataRow>();
            //sheet---------------------------------------------------------------------------------------
            string command = "SELECT DateTimeSheet,SheetNum,Description,ShowInTerminal "
                             + "FROM sheet WHERE PatNum =" + POut.Long(patNum) + " "
                             + "AND (SheetType=" + POut.Long((int)SheetTypeEnum.PatientForm) + " OR SheetType=" + POut.Long((int)SheetTypeEnum.MedicalHistory);

            if (PrefC.GetBool(PrefName.PatientFormsShowConsent))
            {
                command += " OR SheetType=" + POut.Long((int)SheetTypeEnum.Consent);            //Show consent forms if pref is true.
            }
            command += ")";
            //+"ORDER BY ShowInTerminal";//DATE(DateTimeSheet),ShowInTerminal,TIME(DateTimeSheet)";
            DataTable rawSheet = Db.GetTable(command);
            DateTime  dateT;

            for (int i = 0; i < rawSheet.Rows.Count; i++)
            {
                row                = table.NewRow();
                dateT              = PIn.DateT(rawSheet.Rows[i]["DateTimeSheet"].ToString());
                row["date"]        = dateT.ToShortDateString();
                row["dateOnly"]    = dateT.Date;
                row["dateTime"]    = dateT;
                row["description"] = rawSheet.Rows[i]["Description"].ToString();
                row["DocNum"]      = "0";
                row["imageCat"]    = "";
                row["SheetNum"]    = rawSheet.Rows[i]["SheetNum"].ToString();
                if (rawSheet.Rows[i]["ShowInTerminal"].ToString() == "0")
                {
                    row["showInTerminal"] = "";
                }
                else
                {
                    row["showInTerminal"] = rawSheet.Rows[i]["ShowInTerminal"].ToString();
                }
                if (dateT.TimeOfDay != TimeSpan.Zero)
                {
                    row["time"] = dateT.ToString("h:mm") + dateT.ToString("%t").ToLower();
                }
                row["timeOnly"] = dateT.TimeOfDay;
                rows.Add(row);
            }
            //document---------------------------------------------------------------------------------------
            command = "SELECT DateCreated,DocCategory,DocNum,Description "
                      + "FROM document,definition "
                      + "WHERE document.DocCategory=definition.DefNum"
                      + " AND PatNum =" + POut.Long(patNum)
                      + " AND definition.ItemValue LIKE '%F%'";
            //+" ORDER BY DateCreated";
            DataTable rawDoc = Db.GetTable(command);
            long      docCat;

            for (int i = 0; i < rawDoc.Rows.Count; i++)
            {
                row                   = table.NewRow();
                dateT                 = PIn.DateT(rawDoc.Rows[i]["DateCreated"].ToString());
                row["date"]           = dateT.ToShortDateString();
                row["dateOnly"]       = dateT.Date;
                row["dateTime"]       = dateT;
                row["description"]    = rawDoc.Rows[i]["Description"].ToString();
                row["DocNum"]         = rawDoc.Rows[i]["DocNum"].ToString();
                docCat                = PIn.Long(rawDoc.Rows[i]["DocCategory"].ToString());
                row["imageCat"]       = DefC.GetName(DefCat.ImageCats, docCat);
                row["SheetNum"]       = "0";
                row["showInTerminal"] = "";
                if (dateT.TimeOfDay != TimeSpan.Zero)
                {
                    row["time"] = dateT.ToString("h:mm") + dateT.ToString("%t").ToLower();
                }
                row["timeOnly"] = dateT.TimeOfDay;
                rows.Add(row);
            }
            //Sorting
            for (int i = 0; i < rows.Count; i++)
            {
                table.Rows.Add(rows[i]);
            }
            DataView view = table.DefaultView;

            view.Sort = "dateOnly,showInTerminal,timeOnly";
            table     = view.ToTable();
            return(table);
        }
コード例 #9
0
ファイル: Documents.cs プロジェクト: nampn/ODental
        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='" + DefC.GetList(DefCat.ImageCats)[0].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 (DefC.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"]   = DefC.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='" + DefC.GetList(DefCat.ImageCats)[0].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 (DefC.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"]   = DefC.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);
        }