///<summary>Used when viewing various audit trails of specific types. This overload will return security logs for multiple objects (or fKeys). ///Typically you will only need a specific type audit log for one type. ///However, for things like ortho charts, each row (FK) in the database represents just one part of a larger ortho chart "object". ///Thus, to get the full experience of a specific type audit trail window, we need to get security logs for multiple objects (FKs) that ///comprise the larger object (what the user sees). Only implemented with ortho chart so far. FKeys can be null. ///Throws exceptions.</summary> public static SecurityLog[] Refresh(long patNum, List <Permissions> permTypes, List <long> fKeys) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <SecurityLog[]>(MethodBase.GetCurrentMethod(), patNum, permTypes, fKeys)); } string types = ""; for (int i = 0; i < permTypes.Count; i++) { if (i > 0) { types += " OR"; } types += " PermType=" + POut.Long((int)permTypes[i]); } string command = "SELECT * FROM securitylog " + "WHERE (" + types + ") "; if (fKeys != null && fKeys.Count > 0) { command += "AND FKey IN (" + String.Join(",", fKeys) + ") "; } if (patNum != 0) //appointments { command += " AND PatNum IN (" + string.Join(",", PatientLinks.GetPatNumsLinkedToRecursive(patNum, PatientLinkType.Merge).Select(x => POut.Long(x))) + ")"; } command += "ORDER BY LogDateTime"; List <SecurityLog> listLogs = Crud.SecurityLogCrud.SelectMany(command); return(listLogs.OrderBy(x => x.LogDateTime).ToArray()); }
///<summary>Used when viewing securityLog from the security admin window. PermTypes can be length 0 to get all types. ///Throws exceptions.</summary> public static SecurityLog[] Refresh(DateTime dateFrom, DateTime dateTo, Permissions permType, long patNum, long userNum, DateTime datePreviousFrom, DateTime datePreviousTo, int limit = 0) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <SecurityLog[]>(MethodBase.GetCurrentMethod(), dateFrom, dateTo, permType, patNum, userNum, datePreviousFrom, datePreviousTo, limit)); } string command = "SELECT securitylog.*,LName,FName,Preferred,MiddleI,LogHash FROM securitylog " + "LEFT JOIN patient ON patient.PatNum=securitylog.PatNum " + "LEFT JOIN securityloghash ON securityloghash.SecurityLogNum=securitylog.SecurityLogNum " + "WHERE LogDateTime >= " + POut.Date(dateFrom) + " " + "AND LogDateTime <= " + POut.Date(dateTo.AddDays(1)) + " " + "AND DateTPrevious >= " + POut.Date(datePreviousFrom) + " " + "AND DateTPrevious <= " + POut.Date(datePreviousTo.AddDays(1)); if (patNum != 0) { command += " AND securitylog.PatNum IN (" + string.Join(",", PatientLinks.GetPatNumsLinkedToRecursive(patNum, PatientLinkType.Merge).Select(x => POut.Long(x))) + ")"; } if (permType != Permissions.None) { command += " AND PermType=" + POut.Long((int)permType); } if (userNum != 0) { command += " AND UserNum=" + POut.Long(userNum); } command += " ORDER BY LogDateTime DESC"; //Using DESC so that the most recent ones appear in the list if (limit > 0) { command = DbHelper.LimitOrderBy(command, limit); } DataTable table = Db.GetTable(command); List <SecurityLog> listLogs = Crud.SecurityLogCrud.TableToList(table); for (int i = 0; i < listLogs.Count; i++) { if (table.Rows[i]["PatNum"].ToString() == "0") { listLogs[i].PatientName = ""; } else { listLogs[i].PatientName = table.Rows[i]["PatNum"].ToString() + "-" + Patients.GetNameLF(table.Rows[i]["LName"].ToString() , table.Rows[i]["FName"].ToString() , table.Rows[i]["Preferred"].ToString() , table.Rows[i]["MiddleI"].ToString()); } listLogs[i].LogHash = table.Rows[i]["LogHash"].ToString(); } return(listLogs.OrderBy(x => x.LogDateTime).ToArray()); }
///<summary>Used when viewing various audit trails of specific types. This overload will return security logs for multiple objects (or fKeys). Typically you will only need a specific type audit log for one type. However, for things like ortho charts, each row (FK) in the database represents just one part of a larger ortho chart "object". Thus, to get the full experience of a specific type audit trail window, we need to get security logs for multiple objects (FKs) that comprise the larger object (what the user sees). Only implemented with ortho chart so far. FKeys can be null.</summary> public static SecurityLog[] Refresh(long patNum, List <Permissions> permTypes, List <long> fKeys, bool includeArchived) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <SecurityLog[]>(MethodBase.GetCurrentMethod(), patNum, permTypes, fKeys, includeArchived)); } string types = ""; for (int i = 0; i < permTypes.Count; i++) { if (i > 0) { types += " OR"; } types += " PermType=" + POut.Long((int)permTypes[i]); } string command = "SELECT * FROM securitylog " + "WHERE (" + types + ") "; if (fKeys != null && fKeys.Count > 0) { command += "AND FKey IN (" + String.Join(",", fKeys) + ") "; } if (patNum != 0) //appointments { command += " AND PatNum IN (" + string.Join(",", PatientLinks.GetPatNumsLinkedToRecursive(patNum, PatientLinkType.Merge).Select(x => POut.Long(x))) + ")"; } command += "ORDER BY LogDateTime"; List <SecurityLog> listLogs = Crud.SecurityLogCrud.SelectMany(command); if (includeArchived) { string decryptedPass; CDT.Class1.Decrypt(PrefC.GetString(PrefName.ArchivePassHash), out decryptedPass); string connectionStrOrig = DataConnection.GetCurrentConnectionString(); DatabaseType dbTypeOrig = DataConnection.DBtype; DataConnection dcon = new DataConnection(); //Connect to archive database dcon.SetDb(PrefC.GetString(PrefName.ArchiveServerName) == ""?PrefC.GetString(PrefName.ArchiveServerURI):PrefC.GetString(PrefName.ArchiveServerName), "opendentalarchive", PrefC.GetString(PrefName.ArchiveUserName), decryptedPass, "", "", dbTypeOrig); listLogs.AddRange(Crud.SecurityLogCrud.SelectMany(command)); //Append results dcon.SetDb(connectionStrOrig, "", dbTypeOrig); //Reconnect to initial db } return(listLogs.OrderBy(x => x.LogDateTime).ToArray()); }
///<summary>Used when viewing securityLog from the security admin window. PermTypes can be length 0 to get all types. ///Throws exceptions.</summary> public static SecurityLog[] Refresh(DateTime dateFrom, DateTime dateTo, Permissions permType, long patNum, long userNum, DateTime datePreviousFrom, DateTime datePreviousTo, bool includeArchived, int limit = 0) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <SecurityLog[]>(MethodBase.GetCurrentMethod(), dateFrom, dateTo, permType, patNum, userNum, datePreviousFrom, datePreviousTo, includeArchived, limit)); } string command = "SELECT securitylog.*,LName,FName,Preferred,MiddleI,LogHash FROM securitylog " + "LEFT JOIN patient ON patient.PatNum=securitylog.PatNum " + "LEFT JOIN securityloghash ON securityloghash.SecurityLogNum=securitylog.SecurityLogNum " + "WHERE LogDateTime >= " + POut.Date(dateFrom) + " " + "AND LogDateTime <= " + POut.Date(dateTo.AddDays(1)) + " " + "AND DateTPrevious >= " + POut.Date(datePreviousFrom) + " " + "AND DateTPrevious <= " + POut.Date(datePreviousTo.AddDays(1)); if (patNum != 0) { command += " AND securitylog.PatNum IN (" + string.Join(",", PatientLinks.GetPatNumsLinkedToRecursive(patNum, PatientLinkType.Merge).Select(x => POut.Long(x))) + ")"; } if (permType != Permissions.None) { command += " AND PermType=" + POut.Long((int)permType); } if (userNum != 0) { command += " AND UserNum=" + POut.Long(userNum); } command += " ORDER BY LogDateTime DESC"; //Using DESC so that the most recent ones appear in the list if (limit > 0) { command = DbHelper.LimitOrderBy(command, limit); } DataTable table = Db.GetTable(command); List <SecurityLog> listLogs = Crud.SecurityLogCrud.TableToList(table); for (int i = 0; i < listLogs.Count; i++) { if (table.Rows[i]["PatNum"].ToString() == "0") { listLogs[i].PatientName = ""; } else { listLogs[i].PatientName = table.Rows[i]["PatNum"].ToString() + "-" + Patients.GetNameLF(table.Rows[i]["LName"].ToString() , table.Rows[i]["FName"].ToString() , table.Rows[i]["Preferred"].ToString() , table.Rows[i]["MiddleI"].ToString()); } listLogs[i].LogHash = table.Rows[i]["LogHash"].ToString(); } if (includeArchived) { //This will purposefully throw exceptions. DataTable tableArchive = MiscData.RunFuncOnArchiveDatabase <DataTable>(() => { return(Db.GetTable(command)); }); List <SecurityLog> listLogsArchive = Crud.SecurityLogCrud.TableToList(tableArchive); Dictionary <long, Patient> dictPats = Patients.GetMultPats(listLogsArchive.Select(x => x.PatNum).Distinct().ToList()) .ToDictionary(x => x.PatNum); for (int i = 0; i < listLogsArchive.Count; i++) { Patient pat; if (listLogsArchive[i].PatNum == 0 || !dictPats.TryGetValue(listLogsArchive[i].PatNum, out pat)) { listLogsArchive[i].PatientName = ""; } else { listLogsArchive[i].PatientName = listLogsArchive[i].PatNum + "-" + pat.GetNameLF(); } listLogsArchive[i].LogHash = tableArchive.Rows[i]["LogHash"].ToString(); } listLogs.AddRange(listLogsArchive); //Add archived entries to returned list. } return(listLogs.OrderBy(x => x.LogDateTime).ToArray()); }
///<summary>Used when viewing securityLog from the security admin window. PermTypes can be length 0 to get all types.</summary> public static SecurityLog[] Refresh(DateTime dateFrom, DateTime dateTo, Permissions permType, long patNum, long userNum, DateTime datePreviousFrom, DateTime datePreviousTo, bool includeArchived, int limit = 0) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <SecurityLog[]>(MethodBase.GetCurrentMethod(), dateFrom, dateTo, permType, patNum, userNum, datePreviousFrom, datePreviousTo, includeArchived, limit)); } string command = "SELECT securitylog.*,LName,FName,Preferred,MiddleI,LogHash FROM securitylog " + "LEFT JOIN patient ON patient.PatNum=securitylog.PatNum " + "LEFT JOIN securityloghash ON securityloghash.SecurityLogNum=securitylog.SecurityLogNum " + "WHERE LogDateTime >= " + POut.Date(dateFrom) + " " + "AND LogDateTime <= " + POut.Date(dateTo.AddDays(1)) + " " + "AND DateTPrevious >= " + POut.Date(datePreviousFrom) + " " + "AND DateTPrevious <= " + POut.Date(datePreviousTo.AddDays(1)); if (patNum != 0) { command += " AND securitylog.PatNum IN (" + string.Join(",", PatientLinks.GetPatNumsLinkedToRecursive(patNum, PatientLinkType.Merge).Select(x => POut.Long(x))) + ")"; } if (permType != Permissions.None) { command += " AND PermType=" + POut.Long((int)permType); } if (userNum != 0) { command += " AND UserNum=" + POut.Long(userNum); } command += " ORDER BY LogDateTime DESC"; //Using DESC so that the most recent ones appear in the list if (limit > 0) { command = DbHelper.LimitOrderBy(command, limit); } DataTable table = Db.GetTable(command); List <SecurityLog> listLogs = Crud.SecurityLogCrud.TableToList(table); for (int i = 0; i < listLogs.Count; i++) { if (table.Rows[i]["PatNum"].ToString() == "0") { listLogs[i].PatientName = ""; } else { listLogs[i].PatientName = table.Rows[i]["PatNum"].ToString() + "-" + Patients.GetNameLF(table.Rows[i]["LName"].ToString() , table.Rows[i]["FName"].ToString() , table.Rows[i]["Preferred"].ToString() , table.Rows[i]["MiddleI"].ToString()); } listLogs[i].LogHash = table.Rows[i]["LogHash"].ToString(); } if (includeArchived && dateFrom <= PrefC.GetDate(PrefName.ArchiveDate)) //They are attempting to find security logs that are prior to archived date. { string decryptedPass; CDT.Class1.Decrypt(PrefC.GetString(PrefName.ArchivePassHash), out decryptedPass); string connectionStrOrig = DataConnection.GetCurrentConnectionString(); DatabaseType dbTypeOrig = DataConnection.DBtype; DataConnection dcon = new DataConnection(); //Connect to archive database dcon.SetDb(PrefC.GetString(PrefName.ArchiveServerName) == ""?PrefC.GetString(PrefName.ArchiveServerURI):PrefC.GetString(PrefName.ArchiveServerName), "opendentalarchive", PrefC.GetString(PrefName.ArchiveUserName), decryptedPass, "", "", dbTypeOrig); DataTable tableArchive = Db.GetTable(command); //Query the archive List <SecurityLog> listLogsArchive = Crud.SecurityLogCrud.TableToList(tableArchive); dcon.SetDb(connectionStrOrig, "", dbTypeOrig); //Reconnect to initial db Dictionary <long, Patient> dictPats = Patients.GetMultPats(listLogsArchive.Select(x => x.PatNum).Distinct().ToList()) .ToDictionary(x => x.PatNum); for (int i = 0; i < listLogsArchive.Count; i++) { Patient pat; if (listLogsArchive[i].PatNum == 0 || !dictPats.TryGetValue(listLogsArchive[i].PatNum, out pat)) { listLogsArchive[i].PatientName = ""; } else { listLogsArchive[i].PatientName = listLogsArchive[i].PatNum + "-" + pat.GetNameLF(); } listLogsArchive[i].LogHash = tableArchive.Rows[i]["LogHash"].ToString(); } listLogs.AddRange(listLogsArchive); //Add archived entries to returned list. } return(listLogs.OrderBy(x => x.LogDateTime).ToArray()); }