Exemplo n.º 1
0
        ///<summary>Takes a user entered string and validates/formats it for the database.  Throws an ApplicationException if any formatting errors.  User string can contain spaces, dashes, and commas, too.</summary>
        public static string FormatRangeForDb(string toothNumbers)
        {
            if (toothNumbers == null)
            {
                return("");
            }
            toothNumbers = toothNumbers.Replace(" ", "");         //remove all spaces
            if (toothNumbers == "")
            {
                return("");
            }
            string[]      toothArray = toothNumbers.Split(',');     //some items will contain dashes
            List <string> toothList  = new List <string>();
            string        rangebegin;
            string        rangeend;
            int           beginint;
            int           endint;

            //not sure how to handle supernumerary.  Probably just not acceptable.
            for (int i = 0; i < toothArray.Length; i++)
            {
                if (toothArray[i].Contains("-"))
                {
                    rangebegin = toothArray[i].Split('-')[0];
                    rangeend   = toothArray[i].Split('-')[1];
                    if (!IsValidEntry(rangebegin))
                    {
                        throw new ApplicationException(rangebegin + " " + Lans.g("Tooth", "is not a valid tooth number."));
                    }
                    if (!IsValidEntry(rangeend))
                    {
                        throw new ApplicationException(rangeend + " " + Lans.g("Tooth", "is not a valid tooth number."));
                    }
                    beginint = Tooth.ToOrdinal(GetToothId(rangebegin));
                    endint   = Tooth.ToInt(GetToothId(rangeend));
                    if (endint < beginint)
                    {
                        throw new ApplicationException("Range specified is impossible.");
                    }
                    while (beginint <= endint)
                    {
                        toothList.Add(Tooth.FromOrdinal(beginint));
                        beginint++;
                    }
                }
                else
                {
                    if (!IsValidEntry(toothArray[i]))
                    {
                        throw new ApplicationException(toothArray[i] + " " + Lans.g("Tooth", "is not a valid tooth number."));
                    }
                    toothList.Add(Tooth.GetToothId(toothArray[i]));
                }
            }
            toothList.Sort(new ToothComparer());
            string retVal = "";

            for (int i = 0; i < toothList.Count; i++)
            {
                if (i > 0)
                {
                    retVal += ",";
                }
                retVal += toothList[i];
            }
            return(retVal);
        }
Exemplo n.º 2
0
        public static DataTable GetData(List <long> listProvNums, List <long> listClinicNums, DateTime dateStart, DateTime dateEnd, bool includeNoNotes,
                                        bool includeUnsignedNotes, ToothNumberingNomenclature toothNumberFormat, ProcNoteGroupBy groupBy)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), listProvNums, listClinicNums, dateStart, dateEnd, includeNoNotes, includeUnsignedNotes,
                                     toothNumberFormat, groupBy));
            }
            string whereNoNote       = "";
            string whereUnsignedNote = "";
            string whereNotesClause  = "";

            if (includeNoNotes)
            {
                whereNoNote = @"
					LEFT JOIN (
						SELECT procedurelog.PatNum,procedurelog.ProcDate
						FROM procedurelog
						INNER JOIN procnote ON procnote.ProcNum=procedurelog.ProcNum
						INNER JOIN procedurecode ON procedurecode.CodeNum=procedurelog.CodeNum
							AND procedurecode.ProcCode NOT IN ('D9986','D9987')
						WHERE procedurelog.ProcDate BETWEEN "                         + POut.Date(dateStart) + " AND " + POut.Date(dateEnd) + @"
						AND (procedurelog.ProcStatus="                         + POut.Int((int)ProcStat.C) + " OR (procedurelog.ProcStatus=" + POut.Int((int)ProcStat.EC)
                              + @" AND procedurecode.ProcCode='~GRP~'))"
                              + @" GROUP BY procedurelog.PatNum,procedurelog.ProcDate
					) hasNotes ON hasNotes.PatNum=procedurelog.PatNum AND hasNotes.ProcDate=procedurelog.ProcDate "                    ;
                whereNotesClause = "AND (n1.ProcNum IS NOT NULL OR hasNotes.PatNum IS NULL) ";
            }
            if (includeUnsignedNotes)
            {
                if (includeNoNotes)
                {
                    whereNotesClause = "AND (n1.ProcNum IS NOT NULL OR hasNotes.PatNum IS NULL OR unsignedNotes.ProcNum IS NOT NULL)";
                }
                else
                {
                    whereNotesClause = "AND (n1.ProcNum IS NOT NULL OR unsignedNotes.ProcNum IS NOT NULL)";
                }
                whereUnsignedNote = @"
					LEFT JOIN procnote unsignedNotes ON unsignedNotes.ProcNum=procedurelog.ProcNum
						AND unsignedNotes.Signature=''
						AND	TRIM(unsignedNotes.Note)!=''
						AND unsignedNotes.EntryDateTime= (SELECT MAX(n2.EntryDateTime) 
								FROM procnote n2 
								WHERE unsignedNotes.ProcNum = n2.ProcNum) "                                ;
            }
            string command = @"SELECT MAX(procedurelog.ProcDate) ProcDate,MAX(CONCAT(CONCAT(patient.LName, ', '),patient.FName)) PatName,procedurelog.PatNum,
				(CASE WHEN COUNT(procedurelog.ProcNum)=1 THEN MAX(procedurecode.ProcCode) ELSE '' END) ProcCode,
				(CASE WHEN COUNT(procedurelog.ProcNum)=1 THEN MAX(procedurecode.Descript) ELSE '"                 + Lans.g("FormRpProcNote", "Multiple procedures") + @"' END) Descript,
				(CASE WHEN COUNT(procedurelog.ProcNum)=1 THEN MAX(procedurelog.ToothNum) ELSE '' END) ToothNum,
				(CASE WHEN COUNT(procedurelog.ProcNum)=1 THEN MAX(procedurelog.Surf) ELSE '' END) Surf "
                             + (includeNoNotes || includeUnsignedNotes?",(CASE WHEN MAX(n1.ProcNum) IS NOT NULL THEN 'X' ELSE '' END) AS Incomplete ":"")
                             + (includeNoNotes?",(CASE WHEN MAX(hasNotes.PatNum) IS NULL THEN 'X' ELSE '' END) AS HasNoNote ":"")
                             + (includeUnsignedNotes?",(CASE WHEN MAX(unsignedNotes.ProcNum) IS NOT NULL THEN 'X' ELSE '' END) AS HasUnsignedNote ":"") + @" 
				FROM procedurelog
				INNER JOIN patient ON procedurelog.PatNum = patient.PatNum 
				INNER JOIN procedurecode ON procedurelog.CodeNum = procedurecode.CodeNum 
					AND procedurecode.ProcCode NOT IN ('D9986','D9987')
				"                 + (includeNoNotes || includeUnsignedNotes?"LEFT":"INNER") + @" JOIN procnote n1 ON procedurelog.ProcNum = n1.ProcNum 
					AND (n1.Note LIKE '%""""%' OR n1.Note REGEXP '"                     + @"\[Prompt:""[a-zA-Z_0-9 ]+""\]') "//looks for either "" (pre 17.3) or [Prompt:"{word}"] (post 17.3)
                             + @" AND n1.EntryDateTime= (SELECT MAX(n2.EntryDateTime) 
				FROM procnote n2 
				WHERE n1.ProcNum = n2.ProcNum) "
                             + whereNoNote + " "
                             + whereUnsignedNote + @"
				WHERE procedurelog.ProcDate BETWEEN "                 + POut.Date(dateStart) + " AND " + POut.Date(dateEnd) + @"
				AND (procedurelog.ProcStatus="                 + POut.Int((int)ProcStat.C)
                             + " OR (procedurelog.ProcStatus=" + POut.Int((int)ProcStat.EC) + " "
                             + @" AND procedurecode.ProcCode='~GRP~')) "
                             + whereNotesClause;

            if (listProvNums.Count > 0)
            {
                command += @"AND procedurelog.ProvNum IN (" + String.Join(",", listProvNums) + ") ";
            }
            if (listClinicNums.Count > 0)
            {
                command += @"AND procedurelog.ClinicNum IN (" + String.Join(",", listClinicNums) + ") ";
            }
            if (groupBy == ProcNoteGroupBy.Patient)
            {
                command += @"GROUP BY procedurelog.PatNum ";
            }
            else if (groupBy == ProcNoteGroupBy.DateAndPatient)
            {
                command += @"GROUP BY procedurelog.ProcDate,procedurelog.PatNum ";
            }
            else
            {
                command += "GROUP BY procedurelog.ProcNum ";
            }
            command += @"ORDER BY ProcDate, LName";
            DataTable table = ReportsComplex.RunFuncOnReportServer(() => Db.GetTable(command));

            foreach (DataRow row in table.Rows)
            {
                row["ToothNum"] = Tooth.ToInternat(row["ToothNum"].ToString(), toothNumberFormat);
            }
            return(table);
        }
Exemplo n.º 3
0
        ///<summary>The supplied toothNumbers will be a series of tooth numbers separated by commas.  They will be in american format..  For display purposes, ranges will use dashes, and international numbers will be used.</summary>
        public static string FormatRangeForDisplay(string toothNumbers)
        {
            if (toothNumbers == null)
            {
                return("");
            }
            toothNumbers = toothNumbers.Replace(" ", "");         //remove all spaces
            if (toothNumbers == "")
            {
                return("");
            }
            string[] toothArray = toothNumbers.Split(',');
            if (toothArray.Length == 1)
            {
                return(Tooth.GetToothLabel(toothArray[0]));
            }
            else if (toothArray.Length == 2)
            {
                return(Tooth.GetToothLabel(toothArray[0]) + "," + Tooth.GetToothLabel(toothArray[1]));           //just two numbers separated by comma
            }
            Array.Sort <string>(toothArray, new ToothComparer());
            StringBuilder strbuild = new StringBuilder();
            //List<string> toothList=new List<string>();
            //strbuild.Append(Tooth.ToInternat(toothArray[0]));//always show the first number
            int currentNum;
            int nextNum;
            int numberInaRow = 1;          //must have 3 in a row to trigger dash

            for (int i = 0; i < toothArray.Length - 1; i++)
            {
                //in each loop, we are comparing the current number with the next number
                currentNum = Tooth.ToOrdinal(toothArray[i]);
                nextNum    = Tooth.ToOrdinal(toothArray[i + 1]);
                if (nextNum - currentNum == 1 && currentNum != 16 && currentNum != 32)         //if sequential (sequences always break at end of arch)
                {
                    numberInaRow++;
                }
                else
                {
                    numberInaRow = 1;
                }
                if (numberInaRow < 3)               //the next number is not sequential,or if it was a sequence, and it's now broken
                {
                    if (strbuild.Length > 0 && strbuild[strbuild.Length - 1] != '-')
                    {
                        strbuild.Append(",");
                    }
                    strbuild.Append(Tooth.GetToothLabel(toothArray[i]));
                }
                else if (numberInaRow == 3)               //this way, the dash only gets added exactly once
                {
                    strbuild.Append("-");
                }
                //else do nothing
            }
            if (strbuild.Length > 0 && strbuild[strbuild.Length - 1] != '-')
            {
                strbuild.Append(",");
            }
            strbuild.Append(Tooth.GetToothLabel(toothArray[toothArray.Length - 1]));          //always show the last number
            return(strbuild.ToString());
        }
Exemplo n.º 4
0
        private static DataTable GetProcTable(string patNum, string aptNum, string apptStatus)
        {
            DataConnection dcon  = new DataConnection();
            DataTable      table = new DataTable("Procedure");
            DataRow        row;

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("attached");            //0 or 1
            table.Columns.Add("CodeNum");
            table.Columns.Add("descript");
            table.Columns.Add("fee");
            table.Columns.Add("priority");
            table.Columns.Add("ProcCode");
            table.Columns.Add("ProcNum");
            table.Columns.Add("ProcStatus");
            table.Columns.Add("ProvNum");
            table.Columns.Add("status");
            table.Columns.Add("toothNum");
            table.Columns.Add("Surf");
            string command = "SELECT procedurecode.ProcCode,AptNum,PlannedAptNum,Priority,ProcFee,ProcNum,ProcStatus,Surf,ToothNum, "
                             + "procedurecode.Descript,procedurelog.CodeNum,procedurelog.ProvNum "
                             + "FROM procedurelog LEFT JOIN procedurecode ON procedurelog.CodeNum=procedurecode.CodeNum "
                             + "WHERE PatNum=" + patNum  //sort later
                             + " AND (ProcStatus=1 OR "; //tp

            if (apptStatus == "6")                       //planned
            {
                command += "PlannedAptNum=" + aptNum + ")";
            }
            else
            {
                command += "AptNum=" + aptNum + ") ";
                //+"AND (AptNum=0 OR AptNum="+aptNum+")";//exclude procs attached to other appts.
            }
            DataTable rawProc = dcon.GetTable(command);

            for (int i = 0; i < rawProc.Rows.Count; i++)
            {
                row = table.NewRow();
                if (apptStatus == "6")              //planned
                {
                    row["attached"] = (rawProc.Rows[i]["PlannedAptNum"].ToString() == aptNum) ? "1" : "0";
                }
                else
                {
                    row["attached"] = (rawProc.Rows[i]["AptNum"].ToString() == aptNum) ? "1" : "0";
                }
                row["CodeNum"]  = rawProc.Rows[i]["CodeNum"].ToString();
                row["descript"] = "";
                if (rawProc.Rows[i]["AptNum"].ToString() != "0" && rawProc.Rows[i]["AptNum"].ToString() != aptNum)
                {
                    row["descript"] = Lan.g("FormApptEdit", "(other appt)");
                }
                row["descript"]  += rawProc.Rows[i]["Descript"].ToString();
                row["fee"]        = PIn.PDouble(rawProc.Rows[i]["ProcFee"].ToString()).ToString("F");
                row["priority"]   = DefB.GetName(DefCat.TxPriorities, PIn.PInt(rawProc.Rows[i]["Priority"].ToString()));
                row["ProcCode"]   = rawProc.Rows[i]["ProcCode"].ToString();
                row["ProcNum"]    = rawProc.Rows[i]["ProcNum"].ToString();
                row["ProcStatus"] = rawProc.Rows[i]["ProcStatus"].ToString();
                row["ProvNum"]    = rawProc.Rows[i]["ProvNum"].ToString();
                row["status"]     = ((ProcStat)PIn.PInt(rawProc.Rows[i]["ProcStatus"].ToString())).ToString();
                row["toothNum"]   = Tooth.ToInternat(rawProc.Rows[i]["ToothNum"].ToString());
                row["Surf"]       = rawProc.Rows[i]["Surf"].ToString();
                table.Rows.Add(row);
            }
            return(table);
        }
Exemplo n.º 5
0
        ///<summary>If aptnum is specified, then the dates are ignored.  If getting data for one planned appt, then pass isPlanned=true.  This changes which procedures are retrieved.</summary>
        private static DataTable GetPeriodApptsTable(string strDateStart, string strDateEnd, string strAptNum, string strIsPlanned)
        {
            DateTime       dateStart = PIn.PDate(strDateStart);
            DateTime       dateEnd   = PIn.PDate(strDateEnd);
            int            aptNum    = PIn.PInt(strAptNum);
            bool           isPlanned = PIn.PBool(strIsPlanned);
            DataConnection dcon      = new DataConnection();
            DataTable      table     = new DataTable("Appointments");
            DataRow        row;

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("age");
            table.Columns.Add("addrNote");
            table.Columns.Add("apptModNote");
            table.Columns.Add("aptDate");
            table.Columns.Add("aptDay");
            table.Columns.Add("aptLength");
            table.Columns.Add("aptTime");
            table.Columns.Add("AptDateTime");
            table.Columns.Add("AptNum");
            table.Columns.Add("AptStatus");
            table.Columns.Add("Assistant");
            table.Columns.Add("billingType");
            table.Columns.Add("chartNumber");
            table.Columns.Add("chartNumAndName");
            table.Columns.Add("confirmed");
            table.Columns.Add("Confirmed");
            table.Columns.Add("contactMethods");
            table.Columns.Add("creditIns");
            table.Columns.Add("famFinUrgNote");
            table.Columns.Add("hmPhone");
            table.Columns.Add("ImageFolder");
            table.Columns.Add("insurance");
            table.Columns.Add("IsHygiene");
            table.Columns.Add("lab");
            table.Columns.Add("MedUrgNote");
            table.Columns.Add("Note");
            table.Columns.Add("Op");
            table.Columns.Add("patientName");
            table.Columns.Add("PatNum");
            table.Columns.Add("patNum");
            table.Columns.Add("GuarNum");
            table.Columns.Add("patNumAndName");
            table.Columns.Add("Pattern");
            table.Columns.Add("preMedFlag");
            table.Columns.Add("procs");
            table.Columns.Add("production");
            table.Columns.Add("productionVal");
            table.Columns.Add("provider");
            table.Columns.Add("ProvHyg");
            table.Columns.Add("ProvNum");
            table.Columns.Add("wkPhone");
            table.Columns.Add("wirelessPhone");
            string command = "SELECT p1.Abbr ProvAbbr,p2.Abbr HygAbbr,patient.AddrNote,"
                             + "patient.ApptModNote,AptDateTime,appointment.AptNum,AptStatus,Assistant,"
                             + "patient.BillingType,patient.BirthDate,patient.Guarantor,"
                             + "patient.ChartNumber,Confirmed,patient.CreditType,DateTimeChecked,DateTimeRecd,DateTimeSent,"
                             + "guar.FamFinUrgNote,patient.FName,patient.HmPhone,patient.ImageFolder,IsHygiene,IsNewPatient,"
                             + "LabCaseNum,patient.LName,patient.MedUrgNote,patient.MiddleI,Note,Op,appointment.PatNum,"
                             + "Pattern,patplan.PlanNum,patient.PreferConfirmMethod,patient.PreferContactMethod,patient.Preferred,"
                             + "patient.PreferRecallMethod,patient.Premed,"
                             + "(SELECT SUM(ProcFee) FROM procedurelog ";

            if (isPlanned)
            {
                command += "WHERE procedurelog.PlannedAptNum=appointment.AptNum) Production, ";
            }
            else
            {
                command += "WHERE procedurelog.AptNum=appointment.AptNum) Production, ";
            }
            command += "ProvHyg,appointment.ProvNum,patient.WirelessPhone,patient.WkPhone "
                       + "FROM appointment LEFT JOIN patient ON patient.PatNum=appointment.PatNum "
                       + "LEFT JOIN provider p1 ON p1.ProvNum=appointment.ProvNum "
                       + "LEFT JOIN provider p2 ON p2.ProvNum=appointment.ProvHyg ";
            if (isPlanned)
            {
                command += "LEFT JOIN labcase ON labcase.PlannedAptNum=appointment.AptNum ";
            }
            else
            {
                command += "LEFT JOIN labcase ON labcase.AptNum=appointment.AptNum ";
            }
            command += "LEFT JOIN patient guar ON guar.PatNum=patient.Guarantor "
                       + "LEFT JOIN patplan ON patplan.PatNum=patient.PatNum ";
            if (aptNum == 0)
            {
                command += "WHERE AptDateTime >= " + POut.PDate(dateStart) + " "
                           + "AND AptDateTime < " + POut.PDate(dateEnd.AddDays(1)) + " "
                           + "AND (AptStatus=1 OR AptStatus=2 OR AptStatus=4 OR AptStatus=5 OR AptStatus=7 OR AptStatus=8) ";
            }
            else
            {
                command += "WHERE appointment.AptNum=" + POut.PInt(aptNum);
            }
            command += " GROUP BY appointment.AptNum";
            DataTable raw = dcon.GetTable(command);

            command = "SELECT AbbrDesc,procedurelog.AptNum,procedurelog.CodeNum,PlannedAptNum,Surf,ToothNum,TreatArea "
                      + "FROM procedurelog,appointment,procedurecode ";
            if (isPlanned)
            {
                command += "WHERE procedurelog.PlannedAptNum=appointment.AptNum ";
            }
            else
            {
                command += "WHERE procedurelog.AptNum=appointment.AptNum ";
            }
            command += "AND procedurelog.CodeNum=procedurecode.CodeNum ";
            if (aptNum == 0)
            {
                command += "AND AptDateTime >= " + POut.PDate(dateStart) + " "
                           + "AND AptDateTime < " + POut.PDate(dateEnd.AddDays(1)) + " ";
            }
            else
            {
                command += "AND appointment.AptNum=" + POut.PInt(aptNum);
            }
            DataTable rawProc = dcon.GetTable(command);

            //procs for flag, InsNotSent
            command = "SELECT patient.PatNum, patient.Guarantor "
                      + "FROM patient,procedurecode,procedurelog,claimproc "
                      + "WHERE claimproc.procnum=procedurelog.procnum "
                      + "AND patient.PatNum=procedurelog.PatNum "
                      + "AND procedurelog.CodeNum=procedurecode.CodeNum "
                      + "AND claimproc.NoBillIns=0 "
                      + "AND procedurelog.ProcFee>0 "
                      + "AND claimproc.Status=6 "         //estimate
                      + "AND procedurelog.procstatus=2 "
                      + "AND procedurelog.ProcDate >= " + POut.PDate(DateTime.Now.AddYears(-1)) + " "
                      + "AND procedurelog.ProcDate <= " + POut.PDate(DateTime.Now) + " "
                      + "GROUP BY patient.Guarantor";
            DataTable rawInsProc = dcon.GetTable(command);
            DateTime  aptDate;
            TimeSpan  span;
            int       hours;
            int       minutes;
            DateTime  labDate;
            DateTime  birthdate;

            for (int i = 0; i < raw.Rows.Count; i++)
            {
                row = table.NewRow();
                if (raw.Rows[i]["AddrNote"].ToString() != "")
                {
                    row["addrNote"] = Lan.g("Appointments", "AddrNote: ") + raw.Rows[i]["AddrNote"].ToString();
                }
                aptDate            = PIn.PDateT(raw.Rows[i]["AptDateTime"].ToString());
                row["AptDateTime"] = aptDate;
                birthdate          = PIn.PDate(raw.Rows[i]["Birthdate"].ToString());
                row["age"]         = Lan.g("Appointments", "Age: ");
                if (birthdate.Year > 1880)
                {
                    row["age"] += PatientB.DateToAgeString(birthdate);
                }
                else
                {
                    row["age"] += "?";
                }
                if (raw.Rows[i]["ApptModNote"].ToString() != "")
                {
                    row["apptModNote"] = Lan.g("Appointments", "ApptModNote: ") + raw.Rows[i]["ApptModNote"].ToString();
                }
                row["aptDate"] = aptDate.ToShortDateString();
                row["aptDay"]  = aptDate.ToString("dddd");
                span           = TimeSpan.FromMinutes(raw.Rows[i]["Pattern"].ToString().Length *5);
                hours          = span.Hours;
                minutes        = span.Minutes;
                if (hours == 0)
                {
                    row["aptLength"] = minutes.ToString() + Lan.g("Appointments", " Min");
                }
                else if (hours == 1)
                {
                    row["aptLength"] = hours.ToString() + Lan.g("Appointments", " Hr, ")
                                       + minutes.ToString() + Lan.g("Appointments", " Min");
                }
                else
                {
                    row["aptLength"] = hours.ToString() + Lan.g("Appointments", " Hrs, ")
                                       + minutes.ToString() + Lan.g("Appointments", " Min");
                }
                row["aptTime"]     = aptDate.ToShortTimeString();
                row["AptNum"]      = raw.Rows[i]["AptNum"].ToString();
                row["AptStatus"]   = raw.Rows[i]["AptStatus"].ToString();
                row["Assistant"]   = raw.Rows[i]["Assistant"].ToString();
                row["billingType"] = DefB.GetName(DefCat.BillingTypes, PIn.PInt(raw.Rows[i]["BillingType"].ToString()));
                if (raw.Rows[i]["ChartNumber"].ToString() != "")
                {
                    row["chartNumber"] = raw.Rows[i]["ChartNumber"].ToString();
                }
                //row["ChartNumber"]=raw.Rows[i]["ChartNumber"].ToString();
                row["chartNumAndName"] = "";
                if (raw.Rows[i]["IsNewPatient"].ToString() == "1")
                {
                    row["chartNumAndName"] = "NP-";
                }
                row["chartNumAndName"] += raw.Rows[i]["ChartNumber"].ToString() + " "
                                          + PatientB.GetNameLF(raw.Rows[i]["LName"].ToString(), raw.Rows[i]["FName"].ToString(),
                                                               raw.Rows[i]["Preferred"].ToString(), raw.Rows[i]["MiddleI"].ToString());
                row["confirmed"]      = DefB.GetName(DefCat.ApptConfirmed, PIn.PInt(raw.Rows[i]["Confirmed"].ToString()));
                row["Confirmed"]      = raw.Rows[i]["Confirmed"].ToString();
                row["contactMethods"] = "";
                if (raw.Rows[i]["PreferConfirmMethod"].ToString() != "0")
                {
                    row["contactMethods"] += Lan.g("Appointments", "Confirm Method: ")
                                             + ((ContactMethod)PIn.PInt(raw.Rows[i]["PreferConfirmMethod"].ToString())).ToString();
                }
                if (raw.Rows[i]["PreferContactMethod"].ToString() != "0")
                {
                    if (row["contactMethods"].ToString() != "")
                    {
                        row["contactMethods"] += "\r\n";
                    }
                    row["contactMethods"] += Lan.g("Appointments", "Contact Method: ")
                                             + ((ContactMethod)PIn.PInt(raw.Rows[i]["PreferContactMethod"].ToString())).ToString();
                }
                if (raw.Rows[i]["PreferRecallMethod"].ToString() != "0")
                {
                    if (row["contactMethods"].ToString() != "")
                    {
                        row["contactMethods"] += "\r\n";
                    }
                    row["contactMethods"] += Lan.g("Appointments", "Recall Method: ")
                                             + ((ContactMethod)PIn.PInt(raw.Rows[i]["PreferRecallMethod"].ToString())).ToString();
                }
                row["creditIns"] = raw.Rows[i]["CreditType"].ToString();
                //figure out if pt's family has ins claims that need to be created
                bool InsToSend = false;
                for (int j = 0; j < rawInsProc.Rows.Count; j++)
                {
                    if (raw.Rows[i]["PlanNum"].ToString() != "" && raw.Rows[i]["PlanNum"].ToString() != "0")
                    {
                        if (raw.Rows[i]["Guarantor"].ToString() == rawInsProc.Rows[j]["Guarantor"].ToString() ||
                            raw.Rows[i]["Guarantor"].ToString() == rawInsProc.Rows[j]["PatNum"].ToString())
                        {
                            InsToSend = true;
                        }
                    }
                }
                if (InsToSend)
                {
                    row["creditIns"] += "!";
                }
                else if (raw.Rows[i]["PlanNum"].ToString() != "" && raw.Rows[i]["PlanNum"].ToString() != "0")
                {
                    row["creditIns"] += "I";
                }
                if (raw.Rows[i]["FamFinUrgNote"].ToString() != "")
                {
                    row["famFinUrgNote"] = Lan.g("Appointments", "FamFinUrgNote: ") + raw.Rows[i]["FamFinUrgNote"].ToString();
                }
                row["hmPhone"]     = Lan.g("Appointments", "Hm: ") + raw.Rows[i]["HmPhone"].ToString();
                row["ImageFolder"] = raw.Rows[i]["ImageFolder"].ToString();
                if (raw.Rows[i]["PlanNum"].ToString() != "" && raw.Rows[i]["PlanNum"].ToString() != "0")
                {
                    row["insurance"] = Lan.g("Appointments", "Insured");
                }
                row["IsHygiene"] = raw.Rows[i]["IsHygiene"].ToString();
                row["lab"]       = "";
                if (raw.Rows[i]["LabCaseNum"].ToString() != "")
                {
                    labDate = PIn.PDateT(raw.Rows[i]["DateTimeChecked"].ToString());
                    if (labDate.Year > 1880)
                    {
                        row["lab"] = Lan.g("Appointments", "Lab Quality Checked");
                    }
                    else
                    {
                        labDate = PIn.PDateT(raw.Rows[i]["DateTimeRecd"].ToString());
                        if (labDate.Year > 1880)
                        {
                            row["lab"] = Lan.g("Appointments", "Lab Received");
                        }
                        else
                        {
                            labDate = PIn.PDateT(raw.Rows[i]["DateTimeSent"].ToString());
                            if (labDate.Year > 1880)
                            {
                                row["lab"] = Lan.g("Appointments", "Lab Sent");                             //sent but not received
                            }
                            else
                            {
                                row["lab"] = Lan.g("Appointments", "Lab Not Sent");
                            }
                        }
                    }
                }
                row["MedUrgNote"] = raw.Rows[i]["MedUrgNote"].ToString();
                row["Note"]       = raw.Rows[i]["Note"].ToString();
                row["Op"]         = raw.Rows[i]["Op"].ToString();
                if (raw.Rows[i]["IsNewPatient"].ToString() == "1")
                {
                    row["patientName"] = "NP-";
                }
                row["patientName"] += PatientB.GetNameLF(raw.Rows[i]["LName"].ToString(), raw.Rows[i]["FName"].ToString(),
                                                         raw.Rows[i]["Preferred"].ToString(), raw.Rows[i]["MiddleI"].ToString());
                row["PatNum"]        = raw.Rows[i]["PatNum"].ToString();
                row["patNum"]        = "PatNum: " + raw.Rows[i]["PatNum"].ToString();
                row["GuarNum"]       = raw.Rows[i]["Guarantor"].ToString();
                row["patNumAndName"] = "";
                if (raw.Rows[i]["IsNewPatient"].ToString() == "1")
                {
                    row["patNumAndName"] = "NP-";
                }
                row["patNumAndName"] += raw.Rows[i]["PatNum"].ToString() + " "
                                        + PatientB.GetNameLF(raw.Rows[i]["LName"].ToString(), raw.Rows[i]["FName"].ToString(),
                                                             raw.Rows[i]["Preferred"].ToString(), raw.Rows[i]["MiddleI"].ToString());
                row["Pattern"] = raw.Rows[i]["Pattern"].ToString();
                if (raw.Rows[i]["Premed"].ToString() == "1")
                {
                    row["preMedFlag"] = Lan.g("Appointments", "Premedicate");
                }
                row["procs"] = "";
                for (int p = 0; p < rawProc.Rows.Count; p++)
                {
                    if (!isPlanned && rawProc.Rows[p]["AptNum"].ToString() != raw.Rows[i]["AptNum"].ToString())
                    {
                        continue;
                    }
                    if (isPlanned && rawProc.Rows[p]["PlannedAptNum"].ToString() != raw.Rows[i]["AptNum"].ToString())
                    {
                        continue;
                    }
                    if (row["procs"].ToString() != "")
                    {
                        row["procs"] += ", ";
                    }
                    switch (rawProc.Rows[p]["TreatArea"].ToString())
                    {
                    case "1":                                                       //TreatmentArea.Surf:
                        row["procs"] += "#" + Tooth.ToInternat(rawProc.Rows[p]["ToothNum"].ToString()) + "-"
                                        + rawProc.Rows[p]["Surf"].ToString() + "-"; //""#12-MOD-"
                        break;

                    case "2":                                                                                 //TreatmentArea.Tooth:
                        row["procs"] += "#" + Tooth.ToInternat(rawProc.Rows[p]["ToothNum"].ToString()) + "-"; //"#12-"
                        break;

                    default:                            //area 3 or 0 (mouth)
                        break;

                    case "4":                                                     //TreatmentArea.Quad:
                        row["procs"] += rawProc.Rows[p]["Surf"].ToString() + "-"; //"UL-"
                        break;

                    case "5":                                                           //TreatmentArea.Sextant:
                        row["procs"] += "S" + rawProc.Rows[p]["Surf"].ToString() + "-"; //"S2-"
                        break;

                    case "6":                                                     //TreatmentArea.Arch:
                        row["procs"] += rawProc.Rows[p]["Surf"].ToString() + "-"; //"U-"
                        break;

                    case "7":                            //TreatmentArea.ToothRange:
                        //strLine+=table.Rows[j][13].ToString()+" ";//don't show range
                        break;
                    }
                    row["procs"] += rawProc.Rows[p]["AbbrDesc"].ToString();
                }
                row["production"]    = PIn.PDouble(raw.Rows[i]["Production"].ToString()).ToString("c");
                row["productionVal"] = raw.Rows[i]["Production"].ToString();
                if (raw.Rows[i]["IsHygiene"].ToString() == "1")
                {
                    row["provider"] = raw.Rows[i]["HygAbbr"].ToString();
                    if (raw.Rows[i]["ProvAbbr"].ToString() != "")
                    {
                        row["provider"] += " (" + raw.Rows[i]["ProvAbbr"].ToString() + ")";
                    }
                }
                else
                {
                    row["provider"] = raw.Rows[i]["ProvAbbr"].ToString();
                    if (raw.Rows[i]["HygAbbr"].ToString() != "")
                    {
                        row["provider"] += " (" + raw.Rows[i]["HygAbbr"].ToString() + ")";
                    }
                }
                row["ProvNum"]       = raw.Rows[i]["ProvNum"].ToString();
                row["ProvHyg"]       = raw.Rows[i]["ProvHyg"].ToString();
                row["wirelessPhone"] = Lan.g("Appointments", "Cell: ") + raw.Rows[i]["WirelessPhone"].ToString();
                row["wkPhone"]       = Lan.g("Appointments", "Wk: ") + raw.Rows[i]["WkPhone"].ToString();
                table.Rows.Add(row);
            }
            return(table);
        }
Exemplo n.º 6
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,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
        }
Exemplo n.º 7
0
        ///<summary>If a substitute exists for the given proc code, then it will give the CodeNum of that code.
        ///Otherwise, it will return the codeNum for the given procCode.</summary>
        public static long GetSubstituteCodeNum(string procCode, string toothNum)
        {
            //No need to check RemotingRole; no call to db.
            long codeNum = 0;

            if (string.IsNullOrEmpty(procCode))
            {
                return(codeNum);
            }
            ODException.SwallowAnyException(() => {
                ProcedureCode procedureCode = _procedureCodeCache.GetOne(procCode);
                codeNum = procedureCode.CodeNum;
                if (!string.IsNullOrEmpty(procedureCode.SubstitutionCode))
                {
                    //Swallow any following exceptions because the old code would first check and make sure the key was in the dictionary.
                    ODException.SwallowAnyException(() => {
                        if (procedureCode.SubstOnlyIf == SubstitutionCondition.Always)
                        {
                            codeNum = _procedureCodeCache.GetOne(procedureCode.SubstitutionCode).CodeNum;
                        }
                        else if (procedureCode.SubstOnlyIf == SubstitutionCondition.Molar && Tooth.IsMolar(toothNum))
                        {
                            codeNum = _procedureCodeCache.GetOne(procedureCode.SubstitutionCode).CodeNum;
                        }
                        else if (procedureCode.SubstOnlyIf == SubstitutionCondition.SecondMolar && Tooth.IsSecondMolar(toothNum))
                        {
                            codeNum = _procedureCodeCache.GetOne(procedureCode.SubstitutionCode).CodeNum;
                        }
                    });
                }
            });
            return(codeNum);
        }
Exemplo n.º 8
0
 ///<summary>Helper method so that we do not have to duplicate code.  The length of toothValues must match the length of chartOrigVals.</summary>
 private static void ProcessScreenChartHelper(long patNum, List <string> toothValues, ScreenChartType chartType, long provNum, long sheetNum
                                              , List <string> chartOrigVals)
 {
     //No need to check RemotingRole; no call to db.
     for (int i = 0; i < toothValues.Count; i++)       //toothValues is in the order from low to high tooth number in the chart
     {
         if (!toothValues[i].Contains("S"))            //No sealant, nothing to do.
         {
             continue;
         }
         //Logic to determine if the "S" changed surfaces or was erased between the time the toothchart was opened and when it was submitted.
         string[] newSurfaces  = toothValues[i].Split(',');
         string[] origSurfaces = chartOrigVals[i].Split(',');
         bool     isDiff       = false;
         for (int j = 0; j < origSurfaces.Length; j++)                                                                   //Both arrays have the same length unless the chart doesn't exist in the original.
         {
             if ((newSurfaces[j] == "S" && origSurfaces[j] != "S") || (newSurfaces[j] != "S" && origSurfaces[j] == "S")) //"S" changed surfaces or was removed.
             {
                 isDiff = true;
                 break;
             }
         }
         //If there is no difference don't make any duplicates.  We don't care if they changed a surface from N to PS for example, only S surfaces are important.
         if (!isDiff)
         {
             continue;                    //All the "S" surfaces are the same.
         }
         string surf     = "";
         int    toothNum = 0;
         bool   isMolar  = false;
         bool   isRight  = false;
         bool   isLing   = false;
         string tooth    = "";
         #region Parse ScreenChart FieldValues
         if (i <= 1)               //Top left quadrant of toothchart
         {
             toothNum = i + 2;
             isMolar  = true;
             isRight  = true;
             isLing   = true;
         }
         else if (i > 1 && i <= 3)             //Top middle-left quadrant of toothchart
         {
             toothNum = i + 2;
             isMolar  = false;
             isRight  = true;
             isLing   = true;
         }
         else if (i > 3 && i <= 5)             //Top middle-right quadrant of toothchart
         {
             toothNum = i + 8;
             isMolar  = false;
             isRight  = false;
             isLing   = true;
         }
         else if (i > 5 && i <= 7)             //Top right quadrant of toothchart
         {
             toothNum = i + 8;
             isMolar  = true;
             isRight  = false;
             isLing   = true;
         }
         else if (i > 7 && i <= 9)             //Lower right quadrant of toothchart
         {
             toothNum = i + 10;
             isMolar  = true;
             isRight  = false;
             isLing   = false;
         }
         else if (i > 9 && i <= 11)             //Lower middle-right quadrant of toothchart
         {
             toothNum = i + 10;
             isMolar  = false;
             isRight  = false;
             isLing   = false;
         }
         else if (i > 11 && i <= 13)             //Lower middle-left quadrant of toothchart
         {
             toothNum = i + 16;
             isMolar  = false;
             isRight  = true;
             isLing   = false;
         }
         else if (i > 13)               //Lower left quadrant of toothchart
         {
             toothNum = i + 16;
             isMolar  = true;
             isRight  = true;
             isLing   = false;
         }
         if (isMolar)
         {
             if (isRight)
             {
                 if (newSurfaces[0] == "S")
                 {
                     surf += "D";
                 }
                 if (newSurfaces[1] == "S")
                 {
                     surf += "M";
                 }
             }
             else                      //Is Left side
             {
                 if (newSurfaces[0] == "S")
                 {
                     surf += "M";
                 }
                 if (newSurfaces[1] == "S")
                 {
                     surf += "D";
                 }
             }
             if (isLing && newSurfaces[2] == "S")
             {
                 surf += "L";
             }
             if (!isLing && newSurfaces[2] == "S")
             {
                 surf += "B";
             }
         }
         else                  //Front teeth, only look at 3rd surface position in control as that's the only one the user can see.
         {
             if (newSurfaces[2] == "S")
             {
                 surf = "O";                      //NOTE: Not sure what surface to enter here... This is just a placeholder for now until we figure it out...
             }
         }
         if (toothNum != 0)
         {
             tooth = toothNum.ToString();
         }
         #endregion Parse Toothchart FieldValues
         surf = Tooth.SurfTidyForDisplay(surf, tooth);
         if (chartType == ScreenChartType.TP)               //Create TP'd sealant procs if they don't already exist for this patient.
         {
             if (Procedures.GetProcForPatByToothSurfStat(patNum, toothNum, surf, ProcStat.TP) != null)
             {
                 continue;
             }
             Procedure proc = Procedures.CreateProcForPatNum(patNum, ProcedureCodes.GetCodeNum("D1351"), surf, tooth, ProcStat.TP, provNum);
             if (proc != null)
             {
                 SecurityLogs.MakeLogEntry(Permissions.ProcEdit, patNum, "D1351 " + Lans.g("Screens", "treatment planned during screening with tooth")
                                           + " " + proc.ToothNum.ToString() + " " + Lans.g("Screens", "and surface") + " " + proc.Surf);
             }
         }
         else if (chartType == ScreenChartType.C)
         {
             Procedure proc = Procedures.GetProcForPatByToothSurfStat(patNum, toothNum, surf, ProcStat.TP);
             if (proc == null)                   //A TP procedure does not already exist.
             {
                 proc = Procedures.CreateProcForPatNum(patNum, ProcedureCodes.GetCodeNum("D1351"), surf, tooth, ProcStat.C, provNum);
             }
             else                      //TP proc already exists, set it complete.
             {
                 Procedure procOld = proc.Copy();
                 proc.ProcStatus = ProcStat.C;
                 proc.DateEntryC = DateTime.Now;
                 Procedures.Update(proc, procOld);
             }
             if (proc != null)
             {
                 SecurityLogs.MakeLogEntry(Permissions.ProcComplCreate, patNum, "D1351 " + Lans.g("Screens", "set complete during screening with tooth")
                                           + " " + proc.ToothNum.ToString() + " " + Lans.g("Screens", "and surface") + " " + proc.Surf);
             }
         }
     }
     if (chartType == ScreenChartType.C)
     {
         Recalls.Synch(patNum);
     }
 }
Exemplo n.º 9
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));
 }
Exemplo n.º 10
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()));
        }
Exemplo n.º 11
0
 ///<summary>A generic comparison that puts primary teeth after perm teeth.</summary>
 public int Compare(string toothA, string toothB)
 {
     return(Tooth.ToOrdinal(toothA).CompareTo(Tooth.ToOrdinal(toothB)));
 }
Exemplo n.º 12
0
        private static DataTable GetProgNotes(int patNum, bool isAuditMode)
        {
            DataConnection dcon  = new DataConnection();
            DataTable      table = new DataTable("ProgNotes");
            DataRow        row;

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("ADACode");
            table.Columns.Add("aptDateTime", typeof(DateTime));
            table.Columns.Add("colorBackG");
            table.Columns.Add("colorText");
            table.Columns.Add("CommlogNum");
            table.Columns.Add("description");
            table.Columns.Add("dx");
            table.Columns.Add("Dx");
            table.Columns.Add("note");
            table.Columns.Add("Priority");
            table.Columns.Add("procDate");
            table.Columns.Add("ProcDate", typeof(DateTime));
            table.Columns.Add("procFee");
            table.Columns.Add("ProcNum");
            table.Columns.Add("ProcNumLab");
            table.Columns.Add("procStatus");
            table.Columns.Add("ProcStatus");
            table.Columns.Add("prov");
            table.Columns.Add("RxNum");
            table.Columns.Add("signature");
            table.Columns.Add("Surf");
            table.Columns.Add("toothNum");
            table.Columns.Add("ToothNum");
            table.Columns.Add("ToothRange");
            table.Columns.Add("user");
            //table.Columns.Add("");
            //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>();
            //Procedures-----------------------------------------------------------------------------------------------------
            string command = "SELECT ProcDate,ProcStatus,ToothNum,Surf,Dx,procedurelog.ADACode,ProcNum,procedurecode.Descript,"
                             + "provider.Abbr,ProcFee,ProcNumLab,appointment.AptDateTime,Priority,ToothRange "
                             + "FROM procedurelog "
                             + "LEFT JOIN procedurecode ON procedurecode.ADACode=procedurelog.ADACode "
                             + "LEFT JOIN provider ON provider.ProvNum=procedurelog.ProvNum "
                             + "LEFT JOIN appointment ON appointment.AptNum=procedurelog.AptNum "
                             + "AND (appointment.AptStatus=" + POut.PInt((int)ApptStatus.Scheduled)
                             + " OR appointment.AptStatus=" + POut.PInt((int)ApptStatus.ASAP)
                             + " OR appointment.AptStatus=" + POut.PInt((int)ApptStatus.Broken)
                             + " OR appointment.AptStatus=" + POut.PInt((int)ApptStatus.Complete)
                             + ") WHERE procedurelog.PatNum=" + POut.PInt(patNum);

            if (!isAuditMode)
            {
                command += " AND ProcStatus !=6";     //don't include deleted
            }
            command += " ORDER BY ProcDate";          //we'll just have to reorder it anyway
            DataTable rawProcs = dcon.GetTable(command);

            command = "SELECT ProcNum,EntryDateTime,UserNum,Note,"
                      + "CASE WHEN Signature!='' THEN 1 ELSE 0 END AS SigPresent "
                      + "FROM procnote WHERE PatNum=" + POut.PInt(patNum)
                      + " ORDER BY EntryDateTime";         // but this helps when looping for notes
            DataTable      rawNotes = dcon.GetTable(command);
            DateTime       dateT;
            List <DataRow> labRows = new List <DataRow>();        //Canadian lab procs, which must be added in a loop at the very end.

            for (int i = 0; i < rawProcs.Rows.Count; i++)
            {
                row                = table.NewRow();
                row["ADACode"]     = rawProcs.Rows[i]["ADACode"].ToString();
                row["aptDateTime"] = PIn.PDateT(rawProcs.Rows[i]["AptDateTime"].ToString());
                row["colorBackG"]  = Color.White.ToArgb();
                if (((DateTime)row["aptDateTime"]).Date == DateTime.Today)
                {
                    row["colorBackG"] = DefB.Long[(int)DefCat.MiscColors][6].ItemColor.ToArgb().ToString();
                }
                switch ((ProcStat)PIn.PInt(rawProcs.Rows[i]["ProcStatus"].ToString()))
                {
                case ProcStat.TP:
                    row["colorText"] = DefB.Long[(int)DefCat.ProgNoteColors][0].ItemColor.ToArgb().ToString();
                    break;

                case ProcStat.C:
                    row["colorText"] = DefB.Long[(int)DefCat.ProgNoteColors][1].ItemColor.ToArgb().ToString();
                    break;

                case ProcStat.EC:
                    row["colorText"] = DefB.Long[(int)DefCat.ProgNoteColors][2].ItemColor.ToArgb().ToString();
                    break;

                case ProcStat.EO:
                    row["colorText"] = DefB.Long[(int)DefCat.ProgNoteColors][3].ItemColor.ToArgb().ToString();
                    break;

                case ProcStat.R:
                    row["colorText"] = DefB.Long[(int)DefCat.ProgNoteColors][4].ItemColor.ToArgb().ToString();
                    break;

                case ProcStat.D:
                    row["colorText"] = Color.Black.ToArgb().ToString();
                    break;
                }
                row["CommlogNum"]  = 0;
                row["description"] = rawProcs.Rows[i]["Descript"].ToString();
                row["dx"]          = DefB.GetValue(DefCat.Diagnosis, PIn.PInt(rawProcs.Rows[i]["Dx"].ToString()));
                row["Dx"]          = rawProcs.Rows[i]["Dx"].ToString();
                //note-----------------------------------------------------------------------------------------------------------
                if (isAuditMode)                                  //we will include all notes for each proc.  We will concat and make readable.
                {
                    for (int n = 0; n < rawNotes.Rows.Count; n++) //loop through each note
                    {
                        if (rawProcs.Rows[i]["ProcNum"].ToString() != rawNotes.Rows[n]["ProcNum"].ToString())
                        {
                            continue;
                        }
                        if (row["Note"].ToString() != "")                                                    //if there is an existing note
                        {
                            row["note"] += "\r\n------------------------------------------------------\r\n"; //start a new line
                        }
                        row["note"] += PIn.PDateT(rawNotes.Rows[n]["EntryDateTime"].ToString()).ToString();
                        row["note"] += "  " + UserodB.GetName(PIn.PInt(rawNotes.Rows[n]["UserNum"].ToString()));
                        if (rawNotes.Rows[n]["SigPresent"].ToString() == "1")
                        {
                            row["note"] += "  " + Lan.g("ChartModule", "(signed)");
                        }
                        row["note"] += "\r\n" + rawNotes.Rows[n]["Note"].ToString();
                    }
                }
                else                                                   //we just want the most recent note
                {
                    for (int n = rawNotes.Rows.Count - 1; n >= 0; n--) //loop through each note, backwards.
                    {
                        if (rawProcs.Rows[i]["ProcNum"].ToString() != rawNotes.Rows[n]["ProcNum"].ToString())
                        {
                            continue;
                        }
                        row["user"] = UserodB.GetName(PIn.PInt(rawNotes.Rows[n]["UserNum"].ToString()));
                        row["note"] = rawNotes.Rows[n]["Note"].ToString();
                        if (rawNotes.Rows[n]["SigPresent"].ToString() == "1")
                        {
                            row["signature"] = Lan.g("ChartModule", "Signed");
                        }
                        else
                        {
                            row["signature"] = "";
                        }
                        break;                        //out of note loop.
                    }
                }
                row["Priority"] = rawProcs.Rows[i]["Priority"].ToString();
                dateT           = PIn.PDateT(rawProcs.Rows[i]["ProcDate"].ToString());
                if (dateT.Year < 1880)
                {
                    row["procDate"] = "";
                }
                else
                {
                    row["procDate"] = dateT.ToShortDateString();
                }
                row["ProcDate"]   = dateT;
                row["procFee"]    = PIn.PDouble(rawProcs.Rows[i]["ProcFee"].ToString()).ToString("F");
                row["ProcNum"]    = rawProcs.Rows[i]["ProcNum"].ToString();
                row["ProcNumLab"] = rawProcs.Rows[i]["ProcNumLab"].ToString();
                row["procStatus"] = Lan.g("enumProcStat", ((ProcStat)PIn.PInt(rawProcs.Rows[i]["ProcStatus"].ToString())).ToString());
                row["ProcStatus"] = rawProcs.Rows[i]["ProcStatus"].ToString();
                row["prov"]       = rawProcs.Rows[i]["Abbr"].ToString();
                row["RxNum"]      = 0;
                row["Surf"]       = rawProcs.Rows[i]["Surf"].ToString();
                row["toothNum"]   = Tooth.ToInternat(rawProcs.Rows[i]["ToothNum"].ToString());
                row["ToothNum"]   = rawProcs.Rows[i]["ToothNum"].ToString();
                row["ToothRange"] = rawProcs.Rows[i]["ToothRange"].ToString();
                if (rawProcs.Rows[i]["ProcNumLab"].ToString() == "0")              //normal proc
                {
                    rows.Add(row);
                }
                else
                {
                    row["description"] = "-----" + row["description"].ToString();
                    labRows.Add(row);                    //these will be added in the loop at the end
                }
            }
            //Commlog-----------------------------------------------------------------------------------------------------------
            command = "SELECT CommlogNum,CommDateTime,CommType,Note FROM commlog WHERE PatNum=" + POut.PInt(patNum)
                      + " ORDER BY CommDateTime";
            DataTable rawComm = dcon.GetTable(command);

            for (int i = 0; i < rawComm.Rows.Count; i++)
            {
                row = table.NewRow();
                row["colorBackG"]  = Color.White.ToArgb();
                row["colorText"]   = DefB.Long[(int)DefCat.ProgNoteColors][6].ItemColor.ToArgb().ToString();
                row["CommlogNum"]  = rawComm.Rows[i]["CommlogNum"].ToString();
                row["description"] = Lan.g("ChartModule", "Comm - ")
                                     + Lan.g("enumCommItemType", ((CommItemType)PIn.PInt(rawComm.Rows[i]["CommType"].ToString())).ToString());
                row["note"] = rawComm.Rows[i]["Note"].ToString();
                dateT       = PIn.PDateT(rawComm.Rows[i]["CommDateTime"].ToString());
                if (dateT.Year < 1880)
                {
                    row["procDate"] = "";
                }
                else
                {
                    row["procDate"] = dateT.ToShortDateString();
                }
                row["ProcDate"] = dateT;
                row["ProcNum"]  = 0;
                row["RxNum"]    = 0;
                rows.Add(row);
            }
            //Rx------------------------------------------------------------------------------------------------------------------
            command = "SELECT RxNum,RxDate,Drug,Disp,ProvNum,Notes FROM rxpat WHERE PatNum=" + POut.PInt(patNum)
                      + " ORDER BY RxDate";
            DataTable rawRx = dcon.GetTable(command);

            for (int i = 0; i < rawRx.Rows.Count; i++)
            {
                row = table.NewRow();
                row["colorBackG"]  = Color.White.ToArgb();
                row["colorText"]   = DefB.Long[(int)DefCat.ProgNoteColors][5].ItemColor.ToArgb().ToString();
                row["CommlogNum"]  = 0;
                row["description"] = Lan.g("ChartModule", "Rx - ") + rawRx.Rows[i]["Drug"].ToString() + " - #" + rawRx.Rows[i]["Disp"].ToString();
                row["note"]        = rawRx.Rows[i]["Notes"].ToString();
                dateT = PIn.PDate(rawRx.Rows[i]["RxDate"].ToString());
                if (dateT.Year < 1880)
                {
                    row["procDate"] = "";
                }
                else
                {
                    row["procDate"] = dateT.ToShortDateString();
                }
                row["ProcDate"] = dateT;
                row["ProcNum"]  = 0;
                row["RxNum"]    = rawRx.Rows[i]["RxNum"].ToString();
                rows.Add(row);
            }
            //Sorting
            rows.Sort(CompareChartRows);
            //Canadian lab procedures need to come immediately after their corresponding proc---------------------------------
            for (int i = 0; i < labRows.Count; i++)
            {
                for (int r = 0; r < rows.Count; r++)
                {
                    if (rows[r]["ProcNum"].ToString() == labRows[i]["ProcNumLab"].ToString())
                    {
                        rows.Insert(r + 1, labRows[i]);
                        break;
                    }
                }
            }
            for (int i = 0; i < rows.Count; i++)
            {
                table.Rows.Add(rows[i]);
            }
            return(table);
        }