///<summary>Gets all tasks for one of the 3 dated trunks. startDate only applies if showing Done.</summary> public static List <Task> RefreshDatedTrunk(DateTime date, TaskDateType dateType, bool showDone, DateTime startDate, long currentUserNum) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <Task> >(MethodBase.GetCurrentMethod(), date, dateType, showDone, startDate, currentUserNum)); } DateTime dateFrom = DateTime.MinValue; DateTime dateTo = DateTime.MaxValue; if (dateType == TaskDateType.Day) { dateFrom = date; dateTo = date; } else if (dateType == TaskDateType.Week) { dateFrom = date.AddDays(-(int)date.DayOfWeek); dateTo = dateFrom.AddDays(6); } else if (dateType == TaskDateType.Month) { dateFrom = new DateTime(date.Year, date.Month, 1); dateTo = dateFrom.AddMonths(1).AddDays(-1); } string command = "SELECT task.*, " + "(SELECT COUNT(*) FROM taskunread WHERE task.TaskNum=taskunread.TaskNum " + "AND taskunread.UserNum=" + POut.Long(currentUserNum) + ") IsUnread, " //Not sure if this makes sense here + "(SELECT LName FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType=" + POut.Int((int)TaskObjectType.Patient) + ") LName, " + "(SELECT FName FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType=" + POut.Int((int)TaskObjectType.Patient) + ") FName, " + "(SELECT Preferred FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType=" + POut.Int((int)TaskObjectType.Patient) + ") Preferred " + "FROM task " + "WHERE DateTask >= " + POut.Date(dateFrom) + " AND DateTask <= " + POut.Date(dateTo) + " AND DateType=" + POut.Long((int)dateType); if (showDone) { command += " AND (TaskStatus !=" + POut.Long((int)TaskStatusEnum.Done) + " OR DateTimeFinished > " + POut.Date(startDate) + ")"; //of if done, then restrict date } else { command += " AND TaskStatus !=" + POut.Long((int)TaskStatusEnum.Done); } command += " ORDER BY DateTimeEntry"; DataTable table = Db.GetTable(command); return(TableToList(table)); }
///<summary>Gets all task lists from the database for a certain DateType. ///If doIncludeArchived is false, also excludes child lists of archived lists.</summary> public static List <TaskList> GetForDateType(TaskDateType dateType, bool doIncludeArchived) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <TaskList> >(MethodBase.GetCurrentMethod(), dateType, doIncludeArchived)); } List <TaskList> listTaskLists = GetAll(); Dictionary <long, TaskList> dictAllTaskLists = listTaskLists.ToDictionary(x => x.TaskListNum); listTaskLists.RemoveAll(x => x.DateType != dateType || //We are excluding archived lists AND The current task list or any of its ancestors are archived (!doIncludeArchived && (x.TaskListStatus == TaskListStatusEnum.Archived || IsAncestorTaskListArchived(ref dictAllTaskLists, x, true)))); return(listTaskLists); }
///<summary>Gets all task lists for one of the 3 dated trunks. filterClinicFkey and filterRegionFkey are only used for NewTaskCount and do not ///affect which TaskLists are returned by this method. Pass filterClinicFkey=0 and filterRegionFkey=0 to intentionally bypass filtering.</summary> public static List <TaskList> RefreshDatedTrunk(DateTime date, TaskDateType dateType, long userNum, long filterClinicFkey = 0, long filterRegionFkey = 0) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <TaskList> >(MethodBase.GetCurrentMethod(), date, dateType, userNum, filterClinicFkey, filterRegionFkey)); } DateTime dateFrom = DateTime.MinValue; DateTime dateTo = DateTime.MaxValue; if (dateType == TaskDateType.Day) { dateFrom = date; dateTo = date; } else if (dateType == TaskDateType.Week) { dateFrom = date.AddDays(-(int)date.DayOfWeek); dateTo = dateFrom.AddDays(6); } else if (dateType == TaskDateType.Month) { dateFrom = new DateTime(date.Year, date.Month, 1); dateTo = dateFrom.AddMonths(1).AddDays(-1); } string command = "SELECT tasklist.*," + "(SELECT COUNT(*) FROM taskancestor,task "; command += BuildFilterJoins(filterClinicFkey); command += "WHERE taskancestor.TaskListNum=tasklist.TaskListNum " + "AND task.TaskNum=taskancestor.TaskNum " + "AND COALESCE(task.ReminderGroupId,'')='' "; //No reminder tasks //if(PrefC.GetBool(PrefName.TasksNewTrackedByUser)) { // command+="AND EXISTS(SELECT * FROM taskunread WHERE taskunread.TaskNum=task.TaskNum)"; //} //else { command += "AND task.TaskStatus=" + POut.Int((int)TaskStatusEnum.New); //} command += BuildFilterWhereClause(userNum, filterClinicFkey, filterRegionFkey); command += ") 'NewTaskCount' " + "FROM tasklist " + "WHERE DateTL >= " + POut.Date(dateFrom) + " AND DateTL <= " + POut.Date(dateTo) + " AND DateType=" + POut.Long((int)dateType) + " ORDER BY tasklist.Descript,tasklist.DateTimeEntry"; return(TableToList(Db.GetTable(command))); }
///<summary>All repeating items for one date type with no heirarchy.</summary> public static List <TaskList> RefreshRepeating(TaskDateType dateType) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <TaskList> >(MethodBase.GetCurrentMethod(), dateType)); } string command = "SELECT tasklist.*," + "(SELECT COUNT(*) FROM taskancestor,task WHERE taskancestor.TaskListNum=tasklist.TaskListNum " + "AND task.TaskNum=taskancestor.TaskNum AND task.TaskStatus=0) " //See the note in RefreshRepeatingTrunk. Behavior needs to be tested. + "FROM tasklist " + "WHERE IsRepeating=1 " + "AND DateType=" + POut.Long((int)dateType) + " " + "ORDER BY DateTimeEntry"; return(TableToList(Db.GetTable(command))); }
///<summary>All repeating items for one date type with no heirarchy.</summary> public static List <Task> RefreshRepeating(TaskDateType dateType, long currentUserNum) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <Task> >(MethodBase.GetCurrentMethod(), dateType, currentUserNum)); } string command = "SELECT task.*, " + "(SELECT COUNT(*) FROM taskunread WHERE task.TaskNum=taskunread.TaskNum " + "AND taskunread.UserNum=" + POut.Long(currentUserNum) + ") IsUnread " //Don't know if this makes sense here + "FROM task " + "WHERE IsRepeating=1 " + "AND DateType=" + POut.Long((int)dateType) + " " + "ORDER BY DateTimeEntry"; DataTable table = Db.GetTable(command); return(TableToList(table)); }
///<summary>All repeating items for one date type with no heirarchy.</summary> public static List <TaskList> RefreshRepeating(TaskDateType dateType) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <TaskList> >(MethodBase.GetCurrentMethod(), dateType)); } string command = "SELECT tasklist.*," + "(SELECT COUNT(*) FROM taskancestor,task WHERE taskancestor.TaskListNum=tasklist.TaskListNum " + "AND task.TaskNum=taskancestor.TaskNum AND task.TaskStatus=" + POut.Int((int)TaskStatusEnum.New) + " " + "AND COALESCE(task.ReminderGroupId,'')='') 'NewTaskCount' " //No reminder tasks //See the note in RefreshRepeatingTrunk. Behavior needs to be tested. + "FROM tasklist " + "WHERE IsRepeating=1 " + "AND DateType=" + POut.Long((int)dateType) + " " + "ORDER BY tasklist.Descript,tasklist.DateTimeEntry"; return(TableToList(Db.GetTable(command))); }
///<summary>Gets all task lists for one of the 3 dated trunks.</summary> public static List <TaskList> RefreshDatedTrunk(DateTime date, TaskDateType dateType) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <TaskList> >(MethodBase.GetCurrentMethod(), date, dateType)); } DateTime dateFrom = DateTime.MinValue; DateTime dateTo = DateTime.MaxValue; if (dateType == TaskDateType.Day) { dateFrom = date; dateTo = date; } else if (dateType == TaskDateType.Week) { dateFrom = date.AddDays(-(int)date.DayOfWeek); dateTo = dateFrom.AddDays(6); } else if (dateType == TaskDateType.Month) { dateFrom = new DateTime(date.Year, date.Month, 1); dateTo = dateFrom.AddMonths(1).AddDays(-1); } string command = "SELECT tasklist.*," + "(SELECT COUNT(*) FROM taskancestor,task WHERE taskancestor.TaskListNum=tasklist.TaskListNum " + "AND task.TaskNum=taskancestor.TaskNum "; //if(PrefC.GetBool(PrefName.TasksNewTrackedByUser)) { // command+="AND EXISTS(SELECT * FROM taskunread WHERE taskunread.TaskNum=task.TaskNum)"; //} //else { command += "AND task.TaskStatus=0"; //} command += ") " + "FROM tasklist " + "WHERE DateTL >= " + POut.Date(dateFrom) + " AND DateTL <= " + POut.Date(dateTo) + " AND DateType=" + POut.Long((int)dateType) + " ORDER BY DateTimeEntry"; return(TableToList(Db.GetTable(command))); }
///<summary>All repeating items for one date type with no heirarchy.</summary> public static List <Task> RefreshRepeating(TaskDateType dateType, long currentUserNum) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <Task> >(MethodBase.GetCurrentMethod(), dateType, currentUserNum)); } string command = "SELECT task.*, " + "(SELECT COUNT(*) FROM taskunread WHERE task.TaskNum=taskunread.TaskNum " + "AND taskunread.UserNum=" + POut.Long(currentUserNum) + ") IsUnread, " //Not sure if this makes sense here + "(SELECT LName FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType=" + POut.Int((int)TaskObjectType.Patient) + ") LName, " + "(SELECT FName FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType=" + POut.Int((int)TaskObjectType.Patient) + ") FName, " + "(SELECT Preferred FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType=" + POut.Int((int)TaskObjectType.Patient) + ") Preferred " + "FROM task " + "WHERE IsRepeating=1 " + "AND DateType=" + POut.Long((int)dateType) + " " + "ORDER BY DateTimeEntry"; DataTable table = Db.GetTable(command); return(TableToList(table)); }
///<summary>All repeating items for one date type with no heirarchy.</summary> public static List<Task> RefreshRepeating(TaskDateType dateType,long currentUserNum) { if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { return Meth.GetObject<List<Task>>(MethodBase.GetCurrentMethod(),dateType,currentUserNum); } string command= "SELECT task.*, " +"(SELECT COUNT(*) FROM taskunread WHERE task.TaskNum=taskunread.TaskNum " +"AND taskunread.UserNum="+POut.Long(currentUserNum)+") IsUnread "//Don't know if this makes sense here +"FROM task " +"WHERE IsRepeating=1 " +"AND DateType="+POut.Long((int)dateType)+" " +"ORDER BY DateTimeEntry"; DataTable table=Db.GetTable(command); return TableToList(table); }
///<summary>Gets all tasks for one of the 3 dated trunks. startDate only applies if showing Done.</summary> public static List<Task> RefreshDatedTrunk(DateTime date,TaskDateType dateType,bool showDone,DateTime startDate,long currentUserNum) { if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { return Meth.GetObject<List<Task>>(MethodBase.GetCurrentMethod(),date,dateType,showDone,startDate,currentUserNum); } DateTime dateFrom=DateTime.MinValue; DateTime dateTo=DateTime.MaxValue; if(dateType==TaskDateType.Day) { dateFrom=date; dateTo=date; } else if(dateType==TaskDateType.Week) { dateFrom=date.AddDays(-(int)date.DayOfWeek); dateTo=dateFrom.AddDays(6); } else if(dateType==TaskDateType.Month) { dateFrom=new DateTime(date.Year,date.Month,1); dateTo=dateFrom.AddMonths(1).AddDays(-1); } string command= "SELECT task.*, " +"(SELECT COUNT(*) FROM taskunread WHERE task.TaskNum=taskunread.TaskNum " +"AND taskunread.UserNum="+POut.Long(currentUserNum)+") IsUnread "//don't know if this makes sense here +"FROM task " +"WHERE DateTask >= "+POut.Date(dateFrom) +" AND DateTask <= "+POut.Date(dateTo) +" AND DateType="+POut.Long((int)dateType); if(showDone){ command+=" AND (TaskStatus !="+POut.Long((int)TaskStatusEnum.Done) +" OR DateTimeFinished > "+POut.Date(startDate)+")";//of if done, then restrict date } else{ command+=" AND TaskStatus !="+POut.Long((int)TaskStatusEnum.Done); } command+=" ORDER BY DateTimeEntry"; DataTable table=Db.GetTable(command); return TableToList(table); }
///<summary>Gets all task lists for one of the 3 dated trunks.</summary> public static List<TaskList> RefreshDatedTrunk(DateTime date,TaskDateType dateType){ if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { return Meth.GetObject<List<TaskList>>(MethodBase.GetCurrentMethod(),date,dateType); } DateTime dateFrom=DateTime.MinValue; DateTime dateTo=DateTime.MaxValue; if(dateType==TaskDateType.Day) { dateFrom=date; dateTo=date; } else if(dateType==TaskDateType.Week) { dateFrom=date.AddDays(-(int)date.DayOfWeek); dateTo=dateFrom.AddDays(6); } else if(dateType==TaskDateType.Month) { dateFrom=new DateTime(date.Year,date.Month,1); dateTo=dateFrom.AddMonths(1).AddDays(-1); } string command= "SELECT tasklist.*," +"(SELECT COUNT(*) FROM taskancestor,task WHERE taskancestor.TaskListNum=tasklist.TaskListNum " +"AND task.TaskNum=taskancestor.TaskNum "; //if(PrefC.GetBool(PrefName.TasksNewTrackedByUser)) { // command+="AND EXISTS(SELECT * FROM taskunread WHERE taskunread.TaskNum=task.TaskNum)"; //} //else { command+="AND task.TaskStatus="+POut.Int((int)TaskStatusEnum.New); //} command+=") 'NewTaskCount' " +"FROM tasklist " +"WHERE DateTL >= "+POut.Date(dateFrom) +" AND DateTL <= "+POut.Date(dateTo) +" AND DateType="+POut.Long((int)dateType) +" ORDER BY tasklist.Descript,tasklist.DateTimeEntry"; return TableToList(Db.GetTable(command)); }
///<summary>All repeating items for one date type with no heirarchy.</summary> public static List<TaskList> RefreshRepeating(TaskDateType dateType){ if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { return Meth.GetObject<List<TaskList>>(MethodBase.GetCurrentMethod(),dateType); } string command= "SELECT tasklist.*," +"(SELECT COUNT(*) FROM taskancestor,task WHERE taskancestor.TaskListNum=tasklist.TaskListNum " +"AND task.TaskNum=taskancestor.TaskNum AND task.TaskStatus="+POut.Int((int)TaskStatusEnum.New)+") 'NewTaskCount' " //See the note in RefreshRepeatingTrunk. Behavior needs to be tested. +"FROM tasklist " +"WHERE IsRepeating=1 " +"AND DateType="+POut.Long((int)dateType)+" " +"ORDER BY tasklist.Descript,tasklist.DateTimeEntry"; return TableToList(Db.GetTable(command)); }
///<summary>Creates a TaskList. If parent is not 0, then a parentDesc must also be provided.</summary> public static TaskList CreateTaskList(string descript = "", long parent = 0, bool isRepeating = false, TaskDateType dateType = TaskDateType.None, long fromNum = 0, TaskObjectType objectType = TaskObjectType.None, string parentDesc = "", GlobalTaskFilterType globalTaskFilterType = GlobalTaskFilterType.None) { TaskList taskList = new TaskList { Descript = descript, Parent = parent, DateTL = DateTime.MinValue, IsRepeating = isRepeating, DateType = dateType, FromNum = fromNum, ObjectType = objectType, DateTimeEntry = DateTime.Now, ParentDesc = parentDesc, NewTaskCount = 0, GlobalTaskFilterType = globalTaskFilterType, }; TaskLists.Insert(taskList); return(taskList); }
///<summary>Gets all tasks for a given taskList. But the 5 trunks don't have parents: For main trunk use date.Min and TaskListNum=0. For Repeating trunk use date.Min isRepeating and TaskListNum=0. For the 3 dated trunks, use a date and a dateType. Date and TaskListNum are mutually exclusive. Also used to get all repeating tasks for one dateType without any heirarchy: supply listNum=-1.</summary> public static Task[] Refresh(int listNum, DateTime date, TaskDateType dateType, bool isRepeating) { DateTime dateFrom = DateTime.MinValue; DateTime dateTo = DateTime.MaxValue; string where = ""; if (date.Year > 1880) { //date supplied always indicates one of 3 dated trunks. //the value of listNum is completely ignored if (dateType == TaskDateType.Day) { dateFrom = date; dateTo = date; } else if (dateType == TaskDateType.Week) { dateFrom = date.AddDays(-(int)date.DayOfWeek); dateTo = dateFrom.AddDays(6); } else if (dateType == TaskDateType.Month) { dateFrom = new DateTime(date.Year, date.Month, 1); dateTo = dateFrom.AddMonths(1).AddDays(-1); } where = "DateTask >= " + POut.PDate(dateFrom) + " AND DateTask <= " + POut.PDate(dateTo) + " " + "AND DateType=" + POut.PInt((int)dateType) + " "; } else //no date supplied. { if (listNum == 0) //main trunk or repeating trunk { where = "TaskListNum=" + POut.PInt(listNum) + " AND DateTask < '1880-01-01'" + " AND IsRepeating=" + POut.PBool(isRepeating) + " "; } else if (listNum == -1 && isRepeating) //all repeating items with no heirarchy { where = "IsRepeating=1 " + "AND DateType=" + POut.PInt((int)dateType) + " "; } else //any child { where = "TaskListNum=" + POut.PInt(listNum) + " "; //+" AND IsRepeating="+POut.PBool(isRepeating)+" "; } } string command = "SELECT * FROM task " + "WHERE " + where + "ORDER BY DateTimeEntry"; DataTable table = General.GetTable(command); Task[] List = new Task[table.Rows.Count]; for (int i = 0; i < table.Rows.Count; i++) { List[i] = new Task(); List[i].TaskNum = PIn.PInt(table.Rows[i][0].ToString()); List[i].TaskListNum = PIn.PInt(table.Rows[i][1].ToString()); List[i].DateTask = PIn.PDate(table.Rows[i][2].ToString()); List[i].KeyNum = PIn.PInt(table.Rows[i][3].ToString()); List[i].Descript = PIn.PString(table.Rows[i][4].ToString()); List[i].TaskStatus = PIn.PBool(table.Rows[i][5].ToString()); List[i].IsRepeating = PIn.PBool(table.Rows[i][6].ToString()); List[i].DateType = (TaskDateType)PIn.PInt(table.Rows[i][7].ToString()); List[i].FromNum = PIn.PInt(table.Rows[i][8].ToString()); List[i].ObjectType = (TaskObjectType)PIn.PInt(table.Rows[i][9].ToString()); List[i].DateTimeEntry = PIn.PDateT(table.Rows[i][10].ToString()); } return(List); }
///<summary>Creates a TaskSubscription, dateTimeEntry will be DateTime.Now if not specified.</summary> public static Task CreateTask(long taskListNum = 0, long keyNum = 0, string descript = "", TaskStatusEnum taskStatus = TaskStatusEnum.New, bool isRepeating = false, TaskDateType dateType = TaskDateType.None, long fromNum = 0, TaskObjectType objectType = TaskObjectType.None, DateTime dateTimeEntry = new DateTime(), long userNum = 0, bool isUnread = false, string parentDesc = "", string patientName = "", long priorityDefNum = 0, string reminderGroupId = "", TaskReminderType reminderType = TaskReminderType.NoReminder, int reminderFrequency = 0) { if (dateTimeEntry == DateTime.MinValue) { dateTimeEntry = DateTime.Now; } Task task = new Task { TaskListNum = taskListNum, DateTask = DateTime.MinValue, KeyNum = keyNum, Descript = descript, TaskStatus = taskStatus, IsRepeating = isRepeating, DateType = dateType, FromNum = fromNum, ObjectType = objectType, DateTimeEntry = dateTimeEntry, UserNum = userNum, DateTimeFinished = DateTime.MinValue, IsUnread = isUnread, ParentDesc = parentDesc, PatientName = patientName, PriorityDefNum = priorityDefNum, ReminderGroupId = reminderGroupId, ReminderType = reminderType, ReminderFrequency = reminderFrequency, DateTimeOriginal = DateTime.Now }; Tasks.Insert(task); task = Tasks.GetOne(task.TaskNum); //Make sure task matches Db. Avoids problems with DateTime columns. return(task); }
///<summary>All repeating items for one date type with no heirarchy.</summary> public static List<Task> RefreshRepeating(TaskDateType dateType,long currentUserNum) { if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) { return Meth.GetObject<List<Task>>(MethodBase.GetCurrentMethod(),dateType,currentUserNum); } string command= "SELECT task.*, " +"(SELECT COUNT(*) FROM taskunread WHERE task.TaskNum=taskunread.TaskNum " +"AND taskunread.UserNum="+POut.Long(currentUserNum)+") IsUnread, "//Not sure if this makes sense here +"(SELECT LName FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType="+POut.Int((int)TaskObjectType.Patient)+") LName, " +"(SELECT FName FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType="+POut.Int((int)TaskObjectType.Patient)+") FName, " +"(SELECT Preferred FROM patient WHERE task.KeyNum=patient.PatNum AND task.ObjectType="+POut.Int((int)TaskObjectType.Patient)+") Preferred " +"FROM task " +"WHERE IsRepeating=1 " +"AND DateType="+POut.Long((int)dateType)+" " +"ORDER BY DateTimeEntry"; DataTable table=Db.GetTable(command); return TableToList(table); }