///<summary>Inserts one ProcApptColor into the database. Provides option to use the existing priKey.</summary> internal static long Insert(ProcApptColor procApptColor,bool useExistingPK) { if(!useExistingPK && PrefC.RandomKeys) { procApptColor.ProcApptColorNum=ReplicationServers.GetKey("procapptcolor","ProcApptColorNum"); } string command="INSERT INTO procapptcolor ("; if(useExistingPK || PrefC.RandomKeys) { command+="ProcApptColorNum,"; } command+="CodeRange,ShowPreviousDate,ColorText) VALUES("; if(useExistingPK || PrefC.RandomKeys) { command+=POut.Long(procApptColor.ProcApptColorNum)+","; } command+= "'"+POut.String(procApptColor.CodeRange)+"'," + POut.Bool (procApptColor.ShowPreviousDate)+"," + POut.Int (procApptColor.ColorText.ToArgb())+")"; if(useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { procApptColor.ProcApptColorNum=Db.NonQ(command,true); } return procApptColor.ProcApptColorNum; }
///<summary>Inserts one ProcApptColor into the database. Returns the new priKey.</summary> public static long Insert(ProcApptColor procApptColor) { if (DataConnection.DBtype == DatabaseType.Oracle) { procApptColor.ProcApptColorNum = DbHelper.GetNextOracleKey("procapptcolor", "ProcApptColorNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(procApptColor, true)); } catch (Oracle.DataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { procApptColor.ProcApptColorNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(procApptColor, false)); } }
///<summary>Inserts one ProcApptColor into the database. Returns the new priKey.</summary> internal static long Insert(ProcApptColor procApptColor) { if(DataConnection.DBtype==DatabaseType.Oracle) { procApptColor.ProcApptColorNum=DbHelper.GetNextOracleKey("procapptcolor","ProcApptColorNum"); int loopcount=0; while(loopcount<100){ try { return Insert(procApptColor,true); } catch(Oracle.DataAccess.Client.OracleException ex){ if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){ procApptColor.ProcApptColorNum++; loopcount++; } else{ throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return Insert(procApptColor,false); } }
///<summary>Inserts one ProcApptColor into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(ProcApptColor procApptColor, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO procapptcolor ("; if (!useExistingPK && isRandomKeys) { procApptColor.ProcApptColorNum = ReplicationServers.GetKeyNoCache("procapptcolor", "ProcApptColorNum"); } if (isRandomKeys || useExistingPK) { command += "ProcApptColorNum,"; } command += "CodeRange,ShowPreviousDate,ColorText) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(procApptColor.ProcApptColorNum) + ","; } command += "'" + POut.String(procApptColor.CodeRange) + "'," + POut.Bool(procApptColor.ShowPreviousDate) + "," + POut.Int(procApptColor.ColorText.ToArgb()) + ")"; if (useExistingPK || isRandomKeys) { Db.NonQ(command); } else { procApptColor.ProcApptColorNum = Db.NonQ(command, true, "ProcApptColorNum", "procApptColor"); } return(procApptColor.ProcApptColorNum); }
///<summary>Inserts one ProcApptColor into the database. Provides option to use the existing priKey.</summary> public static long Insert(ProcApptColor procApptColor, bool useExistingPK) { if (!useExistingPK && PrefC.RandomKeys) { procApptColor.ProcApptColorNum = ReplicationServers.GetKey("procapptcolor", "ProcApptColorNum"); } string command = "INSERT INTO procapptcolor ("; if (useExistingPK || PrefC.RandomKeys) { command += "ProcApptColorNum,"; } command += "CodeRange,ShowPreviousDate,ColorText) VALUES("; if (useExistingPK || PrefC.RandomKeys) { command += POut.Long(procApptColor.ProcApptColorNum) + ","; } command += "'" + POut.String(procApptColor.CodeRange) + "'," + POut.Bool(procApptColor.ShowPreviousDate) + "," + POut.Int(procApptColor.ColorText.ToArgb()) + ")"; if (useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { procApptColor.ProcApptColorNum = Db.NonQ(command, true); } return(procApptColor.ProcApptColorNum); }
///<summary>Updates one ProcApptColor in the database.</summary> public static void Update(ProcApptColor procApptColor) { string command = "UPDATE procapptcolor SET " + "CodeRange = '" + POut.String(procApptColor.CodeRange) + "', " + "ShowPreviousDate= " + POut.Bool(procApptColor.ShowPreviousDate) + ", " + "ColorText = " + POut.Int(procApptColor.ColorText.ToArgb()) + " " + "WHERE ProcApptColorNum = " + POut.Long(procApptColor.ProcApptColorNum); Db.NonQ(command); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List<ProcApptColor> TableToList(DataTable table){ List<ProcApptColor> retVal=new List<ProcApptColor>(); ProcApptColor procApptColor; for(int i=0;i<table.Rows.Count;i++) { procApptColor=new ProcApptColor(); procApptColor.ProcApptColorNum= PIn.Long (table.Rows[i]["ProcApptColorNum"].ToString()); procApptColor.CodeRange = PIn.String(table.Rows[i]["CodeRange"].ToString()); procApptColor.ShowPreviousDate= PIn.Bool (table.Rows[i]["ShowPreviousDate"].ToString()); procApptColor.ColorText = Color.FromArgb(PIn.Int(table.Rows[i]["ColorText"].ToString())); retVal.Add(procApptColor); } return retVal; }
///<summary>Inserts one ProcApptColor into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(ProcApptColor procApptColor) { if (DataConnection.DBtype == DatabaseType.MySql) { return(InsertNoCache(procApptColor, false)); } else { if (DataConnection.DBtype == DatabaseType.Oracle) { procApptColor.ProcApptColorNum = DbHelper.GetNextOracleKey("procapptcolor", "ProcApptColorNum"); //Cacheless method } return(InsertNoCache(procApptColor, true)); } }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <ProcApptColor> TableToList(DataTable table) { List <ProcApptColor> retVal = new List <ProcApptColor>(); ProcApptColor procApptColor; for (int i = 0; i < table.Rows.Count; i++) { procApptColor = new ProcApptColor(); procApptColor.ProcApptColorNum = PIn.Long(table.Rows[i]["ProcApptColorNum"].ToString()); procApptColor.CodeRange = PIn.String(table.Rows[i]["CodeRange"].ToString()); procApptColor.ShowPreviousDate = PIn.Bool(table.Rows[i]["ShowPreviousDate"].ToString()); procApptColor.ColorText = Color.FromArgb(PIn.Int(table.Rows[i]["ColorText"].ToString())); retVal.Add(procApptColor); } return(retVal); }
///<summary>Returns true if Update(ProcApptColor,ProcApptColor) would make changes to the database. ///Does not make any changes to the database and can be called before remoting role is checked.</summary> public static bool UpdateComparison(ProcApptColor procApptColor, ProcApptColor oldProcApptColor) { if (procApptColor.CodeRange != oldProcApptColor.CodeRange) { return(true); } if (procApptColor.ShowPreviousDate != oldProcApptColor.ShowPreviousDate) { return(true); } if (procApptColor.ColorText != oldProcApptColor.ColorText) { return(true); } return(false); }
///<summary>Updates one ProcApptColor in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables. Returns true if an update occurred.</summary> public static bool Update(ProcApptColor procApptColor, ProcApptColor oldProcApptColor) { string command = ""; if (procApptColor.CodeRange != oldProcApptColor.CodeRange) { if (command != "") { command += ","; } command += "CodeRange = '" + POut.String(procApptColor.CodeRange) + "'"; } if (procApptColor.ShowPreviousDate != oldProcApptColor.ShowPreviousDate) { if (command != "") { command += ","; } command += "ShowPreviousDate = " + POut.Bool(procApptColor.ShowPreviousDate) + ""; } if (procApptColor.ColorText != oldProcApptColor.ColorText) { if (command != "") { command += ","; } command += "ColorText = " + POut.Int(procApptColor.ColorText.ToArgb()) + ""; } if (command == "") { return(false); } command = "UPDATE procapptcolor SET " + command + " WHERE ProcApptColorNum = " + POut.Long(procApptColor.ProcApptColorNum); Db.NonQ(command); return(true); }
///<summary>Updates one ProcApptColor in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables.</summary> internal static void Update(ProcApptColor procApptColor,ProcApptColor oldProcApptColor) { string command=""; if(procApptColor.CodeRange != oldProcApptColor.CodeRange) { if(command!=""){ command+=",";} command+="CodeRange = '"+POut.String(procApptColor.CodeRange)+"'"; } if(procApptColor.ShowPreviousDate != oldProcApptColor.ShowPreviousDate) { if(command!=""){ command+=",";} command+="ShowPreviousDate = "+POut.Bool(procApptColor.ShowPreviousDate)+""; } if(procApptColor.ColorText != oldProcApptColor.ColorText) { if(command!=""){ command+=",";} command+="ColorText = "+POut.Int(procApptColor.ColorText.ToArgb())+""; } if(command==""){ return; } command="UPDATE procapptcolor SET "+command +" WHERE ProcApptColorNum = "+POut.Long(procApptColor.ProcApptColorNum); Db.NonQ(command); }
///<summary>Updates one ProcApptColor in the database.</summary> internal static void Update(ProcApptColor procApptColor) { string command="UPDATE procapptcolor SET " +"CodeRange = '"+POut.String(procApptColor.CodeRange)+"', " +"ShowPreviousDate= "+POut.Bool (procApptColor.ShowPreviousDate)+", " +"ColorText = "+POut.Int (procApptColor.ColorText.ToArgb())+" " +"WHERE ProcApptColorNum = "+POut.Long(procApptColor.ProcApptColorNum); Db.NonQ(command); }
///<summary>Inserts one ProcApptColor into the database. Returns the new priKey.</summary> public static long Insert(ProcApptColor procApptColor) { return(Insert(procApptColor, false)); }
private void butApptProcs_Click(object sender, EventArgs e) { if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This will fix procedure descriptions in the Appt module that aren't correctly showing tooth numbers.\r\nContinue?")) { return; } Cursor = Cursors.WaitCursor; //The ApptProcDescript region is also in FormProcEdit.SaveAndClose() and FormApptEdit.UpdateToDB() Make any changes there as well. #region ApptProcDescript List <long> aptNums = new List <long>(); Appointment[] aptList = Appointments.GetForPeriod(DateTime.Now.Date.AddMonths(-6), DateTime.MaxValue.AddDays(-10)); for (int i = 0; i < aptList.Length; i++) { aptNums.Add(aptList[i].AptNum); } for (int i = 0; i < aptList.Length; i++) { //This gets the list of procedures in the correct order. DataTable procTable = Appointments.GetProcTable(aptList[i].PatNum.ToString(), aptList[i].AptNum.ToString(), ((int)aptList[i].AptStatus).ToString(), aptList[i].AptDateTime.ToString()); Appointment newApt = aptList[i].Clone(); newApt.ProcDescript = ""; newApt.ProcsColored = ""; int count = 0; for (int j = 0; j < procTable.Rows.Count; j++) { if (procTable.Rows[j]["attached"].ToString() != "1") { continue; } string procDescOne = ""; string procCode = procTable.Rows[j]["ProcCode"].ToString(); if (count > 0) { newApt.ProcDescript += ", "; } switch (procTable.Rows[j]["TreatArea"].ToString()) { case "1": //TreatmentArea.Surf: procDescOne += "#" + Tooth.GetToothLabel(procTable.Rows[j]["ToothNum"].ToString()) + "-" + procTable.Rows[j]["Surf"].ToString() + "-"; //""#12-MOD-" break; case "2": //TreatmentArea.Tooth: procDescOne += "#" + Tooth.GetToothLabel(procTable.Rows[j]["ToothNum"].ToString()) + "-"; //"#12-" break; default: //area 3 or 0 (mouth) break; case "4": //TreatmentArea.Quad: procDescOne += procTable.Rows[j]["Surf"].ToString() + "-"; //"UL-" break; case "5": //TreatmentArea.Sextant: procDescOne += "S" + procTable.Rows[j]["Surf"].ToString() + "-"; //"S2-" break; case "6": //TreatmentArea.Arch: procDescOne += procTable.Rows[j]["Surf"].ToString() + "-"; //"U-" break; case "7": //TreatmentArea.ToothRange: //strLine+=table.Rows[j][13].ToString()+" ";//don't show range break; } procDescOne += procTable.Rows[j]["AbbrDesc"].ToString(); newApt.ProcDescript += procDescOne; //Color and previous date are determined by ProcApptColor object ProcApptColor pac = ProcApptColors.GetMatch(procCode); System.Drawing.Color pColor = System.Drawing.Color.Black; string prevDateString = ""; if (pac != null) { pColor = pac.ColorText; if (pac.ShowPreviousDate) { prevDateString = Procedures.GetRecentProcDateString(newApt.PatNum, newApt.AptDateTime, pac.CodeRange); if (prevDateString != "") { prevDateString = " (" + prevDateString + ")"; } } } newApt.ProcsColored += "<span color=\"" + pColor.ToArgb().ToString() + "\">" + procDescOne + prevDateString + "</span>"; count++; } Appointments.Update(newApt, aptList[i]); } #endregion Cursor = Cursors.Default; MsgBox.Show(this, "Done. Please refresh Appt module to see the changes."); }
/* * ///<summary>Only used in GetSearchResults. All times between start and stop get set to true in provBarSched.</summary> * private static void SetProvBarSched(ref bool[] provBarSched,TimeSpan timeStart,TimeSpan timeStop){ * int startI=GetProvBarIndex(timeStart); * int stopI=GetProvBarIndex(timeStop); * for(int i=startI;i<=stopI;i++){ * provBarSched[i]=true; * } * } * * private static int GetProvBarIndex(TimeSpan time) { * return (int)(((double)time.Hours*(double)60/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement)//aptTimeIncr=minutesPerIncr +(double)time.Minutes/(double)PrefC.GetLong(PrefName.AppointmentTimeIncrement)) *(double)ApptDrawing.LineH*ApptDrawing.RowsPerIncr) * /ApptDrawing.LineH;//rounds down * }*/ ///<summary>Used by UI when it needs a recall appointment placed on the pinboard ready to schedule. This method creates the appointment and attaches all appropriate procedures. It's up to the calling class to then place the appointment on the pinboard. If the appointment doesn't get scheduled, it's important to delete it. If a recallNum is not 0 or -1, then it will create an appt of that recalltype.</summary> public static Appointment CreateRecallApt(Patient patCur, List <Procedure> procList, List <InsPlan> planList, long recallNum, List <InsSub> subList) { List <Recall> recallList = Recalls.GetList(patCur.PatNum); Recall recallCur = null; if (recallNum > 0) { recallCur = Recalls.GetRecall(recallNum); } else { for (int i = 0; i < recallList.Count; i++) { if (recallList[i].RecallTypeNum == RecallTypes.PerioType || recallList[i].RecallTypeNum == RecallTypes.ProphyType) { if (!recallList[i].IsDisabled) { recallCur = recallList[i]; } break; } } } if (recallCur == null) // || recallCur.DateDue.Year<1880){ { throw new ApplicationException(Lan.g("AppointmentL", "No special type recall is due.")); //Typically never happens because everyone has a recall. However, it can happen when patients have custom recalls due } if (recallCur.DateScheduled.Date > DateTime.Today) { throw new ApplicationException(Lan.g("AppointmentL", "Recall has already been scheduled for ") + recallCur.DateScheduled.ToShortDateString()); } Appointment AptCur = new Appointment(); AptCur.PatNum = patCur.PatNum; AptCur.AptStatus = ApptStatus.UnschedList; //In all places where this is used, the unsched status with no aptDateTime will cause the appt to be deleted when the pinboard is cleared. if (patCur.PriProv == 0) { AptCur.ProvNum = PrefC.GetLong(PrefName.PracticeDefaultProv); } else { AptCur.ProvNum = patCur.PriProv; } AptCur.ProvHyg = patCur.SecProv; if (AptCur.ProvHyg != 0) { AptCur.IsHygiene = true; } AptCur.ClinicNum = patCur.ClinicNum; //whether perio or prophy: List <string> procs = RecallTypes.GetProcs(recallCur.RecallTypeNum); string recallPattern = RecallTypes.GetTimePattern(recallCur.RecallTypeNum); if (RecallTypes.IsSpecialRecallType(recallCur.RecallTypeNum) && patCur.Birthdate.AddYears(PrefC.GetInt(PrefName.RecallAgeAdult)) > ((recallCur.DateDue > DateTime.Today)?recallCur.DateDue:DateTime.Today)) //For example, if pt's 12th birthday falls after recall date. { for (int i = 0; i < RecallTypeC.Listt.Count; i++) { if (RecallTypeC.Listt[i].RecallTypeNum == RecallTypes.ChildProphyType) { List <string> childprocs = RecallTypes.GetProcs(RecallTypeC.Listt[i].RecallTypeNum); if (childprocs.Count > 0) { procs = childprocs; //overrides adult procs. } string childpattern = RecallTypes.GetTimePattern(RecallTypeC.Listt[i].RecallTypeNum); if (childpattern != "") { recallPattern = childpattern; //overrides adult pattern. } } } } //convert time pattern to 5 minute increment StringBuilder savePattern = new StringBuilder(); for (int i = 0; i < recallPattern.Length; i++) { savePattern.Append(recallPattern.Substring(i, 1)); if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 10) { savePattern.Append(recallPattern.Substring(i, 1)); } if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 15) { savePattern.Append(recallPattern.Substring(i, 1)); savePattern.Append(recallPattern.Substring(i, 1)); } } if (savePattern.ToString() == "") { if (PrefC.GetLong(PrefName.AppointmentTimeIncrement) == 15) { savePattern.Append("///XXX///"); } else { savePattern.Append("//XX//"); } } AptCur.Pattern = savePattern.ToString(); //Add films------------------------------------------------------------------------------------------------------ if (RecallTypes.IsSpecialRecallType(recallCur.RecallTypeNum)) //if this is a prophy or perio { for (int i = 0; i < recallList.Count; i++) { if (recallCur.RecallNum == recallList[i].RecallNum) { continue; //already handled. } if (recallList[i].IsDisabled) { continue; } if (recallList[i].DateDue.Year < 1880) { continue; } if (recallList[i].DateDue > recallCur.DateDue && //if film due date is after prophy due date recallList[i].DateDue > DateTime.Today) //and not overdue { continue; } //incomplete: exclude manual recall types procs.AddRange(RecallTypes.GetProcs(recallList[i].RecallTypeNum)); } } AptCur.ProcDescript = ""; AptCur.ProcsColored = ""; for (int i = 0; i < procs.Count; i++) { string procDescOne = ""; if (i > 0) { AptCur.ProcDescript += ", "; } procDescOne += ProcedureCodes.GetProcCode(procs[i]).AbbrDesc; AptCur.ProcDescript += procDescOne; //Color and previous date are determined by ProcApptColor object ProcApptColor pac = ProcApptColors.GetMatch(procs[i]); System.Drawing.Color pColor = System.Drawing.Color.Black; string prevDateString = ""; if (pac != null) { pColor = pac.ColorText; if (pac.ShowPreviousDate) { prevDateString = Procedures.GetRecentProcDateString(AptCur.PatNum, AptCur.AptDateTime, pac.CodeRange); if (prevDateString != "") { prevDateString = " (" + prevDateString + ")"; } } } AptCur.ProcsColored += "<span color=\"" + pColor.ToArgb().ToString() + "\">" + procDescOne + prevDateString + "</span>"; } AptCur.TimeLocked = PrefC.GetBool(PrefName.AppointmentTimeIsLocked); Appointments.Insert(AptCur); Procedure ProcCur; List <PatPlan> patPlanList = PatPlans.Refresh(patCur.PatNum); List <Benefit> benefitList = Benefits.Refresh(patPlanList, subList); InsPlan priplan = null; InsSub prisub = null; if (patPlanList.Count > 0) { prisub = InsSubs.GetSub(patPlanList[0].InsSubNum, subList); priplan = InsPlans.GetPlan(prisub.PlanNum, planList); } double insfee; double standardfee; for (int i = 0; i < procs.Count; i++) { ProcCur = new Procedure(); //this will be an insert //procnum ProcCur.PatNum = patCur.PatNum; ProcCur.AptNum = AptCur.AptNum; ProcCur.CodeNum = ProcedureCodes.GetCodeNum(procs[i]); ProcCur.ProcDate = DateTime.Now; ProcCur.DateTP = DateTime.Now; //Check if it's a medical procedure. bool isMed = false; ProcCur.MedicalCode = ProcedureCodes.GetProcCode(ProcCur.CodeNum).MedicalCode; if (ProcCur.MedicalCode != null && ProcCur.MedicalCode != "") { isMed = true; } //Get fee schedule for medical or dental. long feeSch; if (isMed) { feeSch = Fees.GetMedFeeSched(patCur, planList, patPlanList, subList); } else { feeSch = Fees.GetFeeSched(patCur, planList, patPlanList, subList); } //Get the fee amount for medical or dental. if (PrefC.GetBool(PrefName.MedicalFeeUsedForNewProcs) && isMed) { insfee = Fees.GetAmount0(ProcedureCodes.GetProcCode(ProcCur.MedicalCode).CodeNum, feeSch); } else { insfee = Fees.GetAmount0(ProcCur.CodeNum, feeSch); } if (priplan != null && priplan.PlanType == "p") //PPO { standardfee = Fees.GetAmount0(ProcCur.CodeNum, Providers.GetProv(Patients.GetProvNum(patCur)).FeeSched); if (standardfee > insfee) { ProcCur.ProcFee = standardfee; } else { ProcCur.ProcFee = insfee; } } else { ProcCur.ProcFee = insfee; } //surf //toothnum //Procedures.Cur.ToothRange=""; //ProcCur.NoBillIns=ProcedureCodes.GetProcCode(ProcCur.CodeNum).NoBillIns; //priority ProcCur.ProcStatus = ProcStat.TP; ProcCur.Note = ""; //Procedures.Cur.PriEstim= //Procedures.Cur.SecEstim= //claimnum ProcCur.ProvNum = patCur.PriProv; //Procedures.Cur.Dx= ProcCur.ClinicNum = patCur.ClinicNum; //nextaptnum ProcCur.BaseUnits = ProcedureCodes.GetProcCode(ProcCur.CodeNum).BaseUnits; ProcCur.DiagnosticCode = PrefC.GetString(PrefName.ICD9DefaultForNewProcs); Procedures.Insert(ProcCur); //no recall synch required Procedures.ComputeEstimates(ProcCur, patCur.PatNum, new List <ClaimProc>(), false, planList, patPlanList, benefitList, patCur.Age, subList); if (Programs.UsingOrion) { FormProcEdit FormP = new FormProcEdit(ProcCur, patCur.Copy(), Patients.GetFamily(patCur.PatNum)); FormP.IsNew = true; FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { //any created claimprocs are automatically deleted from within procEdit window. try{ Procedures.Delete(ProcCur.ProcNum); //also deletes the claimprocs } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { //Do not synch. Recalls based on ScheduleByDate reports in Orion mode. //Recalls.Synch(PatCur.PatNum); } } } return(AptCur); }