///<summary>Returns a list of all appointments and whether that appointment has a conflict for the given listChildOpNums. ///Used to determine if there are any overlapping appointments for ALL time between a 'master' op appointments and the 'child' ops appointments. ///If an appointment from one of the give child ops has a confilict with the master op, then the appointment.Tag will be true. ///Throws exceptions.</summary> public static List <ODTuple <Appointment, bool> > MergeApptCheck(long masterOpNum, List <long> listChildOpNums) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <ODTuple <Appointment, bool> > >(MethodBase.GetCurrentMethod(), masterOpNum, listChildOpNums)); } if (listChildOpNums == null || listChildOpNums.Count == 0) { return(new List <ODTuple <Appointment, bool> >()); } if (listChildOpNums.Contains(masterOpNum)) { throw new ApplicationException(Lans.g("Operatories", "The operatory to keep cannot be within the selected list of operatories to combine.")); } List <int> listApptStatus = new List <int>(); listApptStatus.Add((int)ApptStatus.Scheduled); listApptStatus.Add((int)ApptStatus.Complete); listApptStatus.Add((int)ApptStatus.Broken); listApptStatus.Add((int)ApptStatus.PtNote); //12/09/2016 - Query below originally created by Allen and moddified for job by Joe. string command = "SELECT childAppointments.*, " + "MAX(CASE WHEN " + "(childAppointments.AptDateTime <= MasterAppointments.AptDateTime AND childAppointments.AptDateTime + INTERVAL (LENGTH(childAppointments.Pattern) * 5) MINUTE > MasterAppointments.AptDateTime) " + "OR " + "(MasterAppointments.AptDateTime <= childAppointments.AptDateTime AND MasterAppointments.AptDateTime + INTERVAL (LENGTH(MasterAppointments.Pattern) * 5) MINUTE > childAppointments.AptDateTime) " + "THEN 1 ELSE 0 END) AS HasConflict " + "FROM ( " + "SELECT * " + "FROM appointment " + "WHERE Op =" + POut.Long(masterOpNum) + " " + "AND aptstatus IN (" + String.Join(",", listApptStatus) + ") " + ") MasterAppointments " + "CROSS JOIN ( " + "SELECT * " + "FROM appointment " + "WHERE Op IN (" + String.Join(",", listChildOpNums) + ") " + "AND aptstatus IN (" + String.Join(",", listApptStatus) + ") " + ") childAppointments " + "GROUP BY childAppointments.AptNum"; DataTable table = Db.GetTable(command); List <Appointment> list = AppointmentCrud.TableToList(table); List <ODTuple <Appointment, bool> > listTuplesAptConflicts = new List <ODTuple <Appointment, bool> >(); for (int i = 0; i < table.Rows.Count; i++) { Appointment appt = list.First(x => x.AptNum == PIn.Long(table.Rows[i]["AptNum"].ToString())); //Safe bool hasConflict = PIn.Bool(table.Rows[i]["HasConflict"].ToString()); listTuplesAptConflicts.Add(new ODTuple <Appointment, bool>(appt, hasConflict)); } return(listTuplesAptConflicts); }
///<summary>Returns a list of all appointments and whether that appointment has a conflict for the given listChildOpNums. ///Used to determine if there are any overlapping appointments for ALL time between a 'master' op appointments and the 'child' ops appointments. ///If an appointment from one of the give child ops has a confilict with the master op, then the appointment.Tag will be true. ///Throws exceptions.</summary> public static List <ODTuple <Appointment, bool> > MergeApptCheck(long masterOpNum, List <long> listChildOpNums) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <ODTuple <Appointment, bool> > >(MethodBase.GetCurrentMethod(), masterOpNum, listChildOpNums)); } if (listChildOpNums == null || listChildOpNums.Count == 0) { return(new List <ODTuple <Appointment, bool> >()); } if (listChildOpNums.Contains(masterOpNum)) { throw new ApplicationException(Lans.g("Operatories", "The operatory to keep cannot be within the selected list of operatories to combine.")); } string command = "SELECT * FROM appointment " + "WHERE Op IN (" + string.Join(",", listChildOpNums.Concat(new[] { masterOpNum })) + ") " + "AND AptStatus IN (" + string.Join(",", new[] { (int)ApptStatus.Scheduled, (int)ApptStatus.Complete, (int)ApptStatus.Broken, (int)ApptStatus.PtNote }) + ")"; List <Appointment> listApptsAll = AppointmentCrud.SelectMany(command); return(listApptsAll.Where(x => x.Op != masterOpNum).Select(x => new ODTuple <Appointment, bool>(x, HasConflict(x, listApptsAll))).ToList()); }