public DataTable GetCTCLookup(int terminologyId) { string sql = @" SELECT grades.AE_Grade, grades.AE_Grade_Description, terms.CTC_AE_Toxicity_ShortDesc, terms.AE_Category_Description FROM CTC_AE_Toxicity_Grades grades INNER JOIN CTC_AE_Toxicity_Terms terms ON terms.MedDRA_Code = grades.MedDRA_Code AND terms.AE_TerminologyID = grades.AE_TerminologyID WHERE grades.AE_TerminologyID = @TerminologyId --AND terms.CTC_AE_Toxicity_ShortDesc LIKE '%Fatigue%' --AND terms.AE_Category_Description = 'CONSTITUTIONAL SYMPTOMS' ORDER BY grades.AE_Grade "; SqlCommand cmd = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(cmd, "TerminologyId", terminologyId); DataSet ds = DataAccessHelper.GetList(cmd); return(ds.Tables[0]); }
/// <summary> /// Returns a list of Surveys and Items by specified match expression ('%Like Match%' or 'Exact Match') /// </summary> /// <param name="patientId"></param> /// <param name="type"></param> /// <param name="fromDate"></param> /// <param name="toDate"></param> /// <returns></returns> public DataTable GetSurveysAndItemsByType(int patientId, string type, DateTime?fromDate, DateTime?toDate) { string sql = @" SELECT a.SurveyId, a.SurveyDateText, a.SurveyDate, a.SurveyType, b.SurveyItemId, b.SurveyItemNum, b.SurveyItem, b.SurveyItemResult FROM Surveys a INNER JOIN SurveyItems b ON a.SurveyId = b.SurveyId WHERE a.PatientId = @PatientId AND a.SurveyType {0} @SurveyType ORDER BY a.SurveyDate "; bool isLike = type.Contains("%"); SqlCommand com = DataAccessHelper.CreateSqlCommand(string.Format(sql, isLike ? "LIKE" : "=")); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); DataAccessHelper.AddStringInputParam(com, "SurveyType", type); DataAccessHelper.AddInputParam(com, "FromDate", fromDate, true); DataAccessHelper.AddInputParam(com, "ToDate", toDate, true); DataTable dt = DataAccessHelper.GetRecord(com).Tables[0]; return(dt); }
public DataSet FormGetBiopsyTRUSVolumeRecords(int PatientId, string FormName, string FormType) { DataSet ds = new DataSet(); string sql = ""; if (FormType == "Dynamic") { sql = @" SELECT * FROM Pathology INNER JOIN ProstateBiopsyPath ON ProstateBiopsyPath.PathologyId = Pathology.PathologyID LEFT JOIN (SELECT Diagnostics.PatientId, Diagnostics.DiagnosticId, DxDateText, ImgProstateVolume FROM Diagnostics INNER JOIN DxImageProstate ON DxImageProstate.DiagnosticId = Diagnostics.DiagnosticId WHERE DxType = 'TRUS' GROUP BY Diagnostics.DiagnosticId, DxDateText, ImgProstateVolume, Diagnostics.PatientId) trus ON trus.DxDateText = Pathology.PathDateText WHERE (Pathology.PatientId = @PatientId AND trus.PatientId = @PatientId) ORDER BY PathDate ASC"; SqlCommand com = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(com, "PatientId", PatientId); ds = DataAccessHelper.GetRecord(com); } return(ds); }
/// <summary> /// Returns a list of Surveys and Items by specified match expression ('%Like Match%' or 'Exact Match') /// </summary> /// <param name="patientId"></param> /// <param name="type"></param> /// <returns></returns> public DataTable GetMostRecentSurveyWithItemsByType(int patientId, string type) { string sql = @" SELECT * FROM ( SELECT TOP 1 * FROM Surveys WHERE PatientId = @PatientId AND SurveyType {0} @SurveyType ORDER BY SurveyDate DESC ) a INNER JOIN SurveyItems b ON a.SurveyId = b.SurveyId ORDER BY b.SurveyItemNum "; bool isLike = type.Contains("%"); SqlCommand com = DataAccessHelper.CreateSqlCommand(string.Format(sql, isLike ? "LIKE" : "=")); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); DataAccessHelper.AddStringInputParam(com, "SurveyType", type); DataTable dt = DataAccessHelper.GetRecord(com).Tables[0]; return(dt); }
/// <summary> /// Returns a list of Sections for a Survey, ordered by MIN(QuestionNum) /// </summary> /// <param name="metaSurveyId"></param> /// <returns></returns> public DataTable GetSurveySections(int metaSurveyId) { // OLD CODE, Group questions with empty sections //string sql = "SELECT ISNULL(Section,'') as Section,ISNULL(Page,'') as Page FROM MetadataSurveyQuestions WHERE MetadataSurveyId = @MetadataSurveyId "; //sql += "GROUP BY Section,Page ORDER BY MIN(SortNumber)"; // NEW CODE, questions with no sections will be grouped seperately string sql = "SELECT * FROM ( "; sql += "SELECT DISTINCT MIN(SortNumber) SortNumber, Page, Section "; sql += "FROM MetadataSurveyQuestions "; sql += "WHERE Section IS NOT NULL AND Section <> '' AND MetadataSurveyId = @MetadataSurveyId "; sql += "GROUP BY Page, Section "; sql += "UNION ALL "; sql += "SELECT DISTINCT SortNumber, Page, Section "; sql += "FROM MetadataSurveyQuestions "; sql += "WHERE (Section IS NULL OR Section = '') AND MetadataSurveyId = @MetadataSurveyId "; sql += "GROUP BY SortNumber, Page, Section "; sql += ") SurveySections "; sql += "ORDER BY SurveySections.SortNumber ASC, SurveySections.Page ASC, SurveySections.Section ASC"; SqlCommand com = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(com, "MetadataSurveyId", metaSurveyId); DataTable dt = DataAccessHelper.GetRecord(com).Tables[0]; return(dt); }
/// <summary> /// Returns a list of Contacts assoicated with the user /// </summary> /// <param name="userId"></param> /// <returns></returns> public DataTable GetUserContacts(int userId) { string sql = @" SELECT u.UserId, u.UserName, u.UserFirstName, u.UserLastName, u.UserEmail, c.ContactId, c.FirstName, c.LastName FROM Users u INNER JOIN Contact c ON u.UserId = c.UserId WHERE u.UserId = @UserId "; SqlCommand cmd = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(cmd, "UserId", userId); DataTable dt = DataAccessHelper.GetRecord(cmd).Tables[0]; return(dt); }
/// <summary> /// Returns a list of Organizations associated with the user /// </summary> /// <param name="userId"></param> /// <returns></returns> public DataTable GetUserOrganizations(int userId) { string sql = @" SELECT u.UserId, u.UserName, u.UserFirstName, u.UserLastName, u.UserEmail, c.ContactId, c.FirstName, c.LastName, oc.OrganizationContactId, o.OrganizationId, o.Name, o.ShortName, o.OrgNum FROM Users u INNER JOIN Contact c ON u.UserId = c.UserId INNER JOIN ProjectOrganization_ProjectContact oc ON c.ContactId = oc.ContactId INNER JOIN ProjectOrganization o ON oc.OrganizationId = o.OrganizationId WHERE u.UserId = @UserId "; SqlCommand cmd = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(cmd, "UserId", userId); DataTable dt = DataAccessHelper.GetRecord(cmd).Tables[0]; return(dt); }
/// <summary> /// Returns if the user has changed their password with # days from Today /// </summary> /// <param name="userName">the user to query</param> /// <param name="days">the number of days to search back from Today</param> /// <returns></returns> public bool UserChangedPasswordWithinAllowablePeriod(string userName, int days) { SqlCommand com = DataAccessHelper.CreateCommand("spInsertUsersRecord"); DataAccessHelper.AddStringInputParam(com, "UserName", userName); DataAccessHelper.AddIntInputParam(com, "ElapsedDays", days); Hashtable outParams = DataAccessHelper.ExecuteScalar(com); if (outParams["HasUpdatedPassword"] != System.DBNull.Value && ((bool)outParams["HasUpdatedPassword"]) == false) { return(false); } else { return(true); } // tried the below and finally gave up and created a proc // string sql = "select DISTINCT AuditLog_Users.UserPassword from AuditLog_Users inner join Users on AuditLog_Users.UserId = Users.UserId where AuditLog_Users.UpdatedTime > (GETDATE() - " + days + ") and Users.UserName = '******' AND AuditLog_Users.UserPassword <> Users.UserPassword"; // string sql = @"SELECT DISTINCT AuditLog_Users.UserPassword FROM AuditLog_Users INNER JOIN Users ON AuditLog_Users.UserId = Users.UserId WHERE DATEDIFF(day,AuditLog_Users.LoggedTime,GETDATE()) < {0} AND Users.UserName = '******' AND AuditLog_Users.UserPassword <> Users.UserPassword"; // string sql = @"SELECT DISTINCT AuditLog_Users.UserPassword FROM AuditLog_Users inner join Users ON AuditLog_Users.UserId = Users.UserId // WHERE DATEDIFF(day, COALESCE(AuditLog_Users.UpdatedTime, AuditLog_Users.EnteredTime), GETDATE()) > {0} // AND Users.UserName = '******' AND AuditLog_Users.UserPassword <> Users.UserPassword"; //SqlCommand com = DataAccessHelper.CreateSqlCommand(string.Format(sql, days, userName)); //DataTable dt = DataAccessHelper.GetRecord(com).Tables[0]; //return dt.Rows.Count > 0; }
public DataTable GetUserLoginsCountByMonthInRange(int userId, DateTime minDate, DateTime maxDate) { string sql = @" SELECT ul.UserId, -- how often user logged in by year and month YEAR(ul.UserLoginTime) AS LoginYear, MONTH(ul.UserLoginTime) AS LoginMonth, COUNT(ul.UserLoginTime) AS LoginCount FROM UserLogins ul WHERE -- restrict to user ul.UserId = @UserId AND -- restrict to logins within past year ul.UserLoginTime >= @StartDate AND ul.UserLogintime <= @EndDate GROUP BY ul.UserId, -- group by year and month YEAR(ul.UserLoginTime), MONTH(ul.UserLoginTime) ORDER BY LoginYear DESC, LoginMonth DESC "; SqlCommand com = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(com, "UserId", userId); DataAccessHelper.AddDateTimeInputParam(com, "StartDate", minDate); DataAccessHelper.AddDateTimeInputParam(com, "EndDate", maxDate); DataTable dt = DataAccessHelper.GetRecord(com).Tables[0]; return(dt); }
public void LogLoginAttempt(string userName, int loginId, string errorMessage, string IP, string userAgent, string browser, string platform, string javascript, string cookies, string screenResolution, string colorDepth) { if (errorMessage.Length > 50) { errorMessage = errorMessage.Substring(0, 50); } if (userAgent.Length > 255) { userAgent = userAgent.Substring(0, 255); } SqlCommand com = DataAccessHelper.CreateCommand("spInsertUserLoginAttempt"); DataAccessHelper.AddStringInputParam(com, "UserName", userName); DataAccessHelper.AddDateTimeInputParam(com, "UserLoginAttemptTime", DateTime.Now); DataAccessHelper.AddIntInputParam(com, "UserLoginId", loginId); DataAccessHelper.AddStringInputParam(com, "UserErrorMessage", errorMessage); DataAccessHelper.AddStringInputParam(com, "UserIP", IP); DataAccessHelper.AddStringInputParam(com, "UserUserAgent", userAgent); DataAccessHelper.AddStringInputParam(com, "UserBrowser", browser); DataAccessHelper.AddStringInputParam(com, "UserPlatform", platform); DataAccessHelper.AddStringInputParam(com, "UserJavascript", javascript); DataAccessHelper.AddStringInputParam(com, "UserCookies", cookies); DataAccessHelper.AddStringInputParam(com, "UserScreenResolution", screenResolution); DataAccessHelper.AddStringInputParam(com, "UserColorDepth", colorDepth); DataAccessHelper.ExecuteScalar(com); }
public DataTable DoToxAdverseEventSearch(int terminologyId, string searchTerm) { string sql = @" SELECT DISTINCT terms.CTC_AE_Toxicity_Description AS ToxDesc, terms.CTC_AE_Toxicity_TermID, categories.AE_CategoryID FROM CTC_AE_Toxicity_Terms terms INNER JOIN CTC_AE_Category categories ON terms.AE_CategoryID = categories.AE_CategoryID WHERE categories.AE_TerminologyID = @TerminologyId AND terms.CTC_AE_Toxicity_Description LIKE @Search ORDER BY categories.AE_CategoryID ASC "; SqlCommand cmd = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(cmd, "TerminologyId", terminologyId); DataAccessHelper.AddStringInputParam(cmd, "Search", "%" + searchTerm + "%"); DataSet ds = DataAccessHelper.GetList(cmd); return(ds.Tables[0]); }
public DataSet FormGetFamMemDiagnosisSpecialRecords(int PatientId, string FormName, string FormType, string searchField, string searchClause, string searchFilter) { DataSet ds = new DataSet(); string sql = ""; if (FormType == "Dynamic") { sql = "SELECT * "; sql += "FROM FamilyMembers "; sql += "INNER JOIN FamilyMemberDiagnosis ON FamilyMemberDiagnosis.FamilyMemberId = FamilyMembers.FamilyMemberId "; sql += "WHERE (PatientId = @PatientId) "; sql += "AND " + searchField + " " + searchClause + " (" + searchFilter + ") "; sql += "ORDER BY FamilyMemberDiagnosisId ASC "; SqlCommand com = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(com, "PatientId", PatientId); ds = DataAccessHelper.GetRecord(com); } return(ds); }
/// <summary> /// Gets a uniform view of Field Metadata by the table's specific filters. /// Represents the UNION of disease specific and DEFAULT metadata. /// </summary> /// <param name="filter">A pair representing the filter MetadataTable's filter</param> /// <param name="diseaseId">The optional DiseaseId filter</param> /// <returns>A uniform view of a table's fields and metadata</returns> private static DataTable GetFieldMetadata(KeyValuePair <string, object> filter, int?diseaseId) { // build WHERE clause string whereSQL = string.Format( @" -- restrict to current table fields, disease and non-disease values only WHERE a.{0} = @{0} AND (a.DiseaseId = @DiseaseId OR a.DiseaseId IS NULL) ", filter.Key); // create command SqlCommand com = DataAccessHelper.CreateSqlCommand(string.Format(GET_FIELD_METADATA_SQL, whereSQL)); // add params if (filter.Value is int) { DataAccessHelper.AddIntInputParam(com, filter.Key, filter.Value); } else if (filter.Value is string) { DataAccessHelper.AddStringInputParam(com, filter.Key, (string)filter.Value); } DataAccessHelper.AddInputParam(com, "DiseaseId", diseaseId, true); return(DataAccessHelper.GetRecord(com).Tables[0]); }
/// <summary> /// SELECT * /// FROM FieldMetadata /// WHERE TableId = @TableId /// </summary> /// <param name="tableId"></param> /// <returns></returns> public DataTable GetFieldMetadataByTableId(int tableId) { SqlCommand com = DataAccessHelper.CreateCommand("spGetFieldMetadataByTableId"); DataAccessHelper.AddIntInputParam(com, "TableId", tableId); return(DataAccessHelper.GetRecord(com).Tables[0]); }
public DataSet GetEformsRecord(int eformId) { SqlCommand com = DataAccessHelper.CreateCommand("spGetEFormsRecord"); DataAccessHelper.AddIntInputParam(com, "EformId", eformId); return(DataAccessHelper.GetRecord(com)); }
public int InsertEFormsRecord(int userId, int patientId, string eformName, string eformXml, string currentStatus, object eformApptTime, string eformApptPhysician, string userName) { SqlCommand com = DataAccessHelper.CreateCommand("spInsertEFormsRecord"); DataAccessHelper.AddIntInputParam(com, "UserId", userId); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); DataAccessHelper.AddStringInputParam(com, "EformName", eformName); DataAccessHelper.AddTextInputParam(com, "EformXml", eformXml); DataAccessHelper.AddStringInputParam(com, "CurrentStatus", currentStatus); DataAccessHelper.AddDateTimeInputParam(com, "EformApptTime", DataAccessHelper.ToDBDate(eformApptTime)); DataAccessHelper.AddStringInputParam(com, "EformApptPhysician", eformApptPhysician); DataAccessHelper.AddStringInputParam(com, "UpdatedBy", userName); DataAccessHelper.AddDateTimeInputParam(com, "UpdatedTime", DateTime.Now); DataAccessHelper.AddStringInputParam(com, "EnteredBy", userName); DataAccessHelper.AddDateTimeInputParam(com, "EnteredTime", DateTime.Now); DataAccessHelper.AddIntOutputParam(com, "NewPrimaryKey"); Hashtable outParams = DataAccessHelper.ExecuteScalar(com); if (outParams["NewPrimaryKey"] != System.DBNull.Value) { return((int)outParams["NewPrimaryKey"]); } else { return(-1); } }
/// <summary> /// Executes a simple select on the RelatedRecords table with list of fields and their realted values /// </summary> /// <param name="fieldsAndValues">a mapping of fields to value, i.,e., SrcTable="Patients",SrcPriKey=1,etc...</param> /// <returns></returns> private static DataTable ExecuteSimpleSelect(Dictionary <string, object> fieldsAndValues) { SqlCommand com = DataAccessHelper.CreateSqlCommand(""); List <string> sqlParams = new List <string>(fieldsAndValues.Count); foreach (string paramName in fieldsAndValues.Keys) { object paramValue = fieldsAndValues[paramName]; Type paramType = paramValue.GetType(); string param_expr = "{0} = @{0}"; string full_expr = string.Format(param_expr, paramName); if (paramType == typeof(int)) { DataAccessHelper.AddIntInputParam(com, paramName, paramValue); sqlParams.Add(full_expr); } else if (paramType == typeof(string)) { DataAccessHelper.AddStringInputParam(com, paramName, paramValue.ToString()); sqlParams.Add(full_expr); } } // Add default source system sqlParams.Add("SrcSystem = @SrcSystem"); DataAccessHelper.AddStringInputParam(com, "SrcSystem", CAISIS_SRC_SYSTEM); // generate dynamic sql, "select * from table where a = @a AND b = @b AND c = @c ..." com.CommandText = "SELECT * FROM RelatedRecords WHERE " + string.Join(" AND ", sqlParams.ToArray()); // execute statement and return table DataTable dt = DataAccessHelper.GetRecord(com).Tables[0]; return(dt); }
/// <summary> /// Takes a Diagnostic SQL Query and filters Diagnostics by list of DxTypes /// </summary> /// <param name="baseSQL"></param> /// <returns></returns> private static SqlCommand GetFilteredDiagnosticType(string baseSQL, int patientId, params string[] types) { string sql = baseSQL; sql += " WHERE Diagnostics.PatientId = @PatientId "; sql += "AND ("; string[] paramList = new string[types.Length]; for (int i = 0; i < types.Length; i++) { string paramName = "DxType_" + i; paramList[i] = " Diagnostics.DxType LIKE '%' + @" + paramName + " + '%' "; } sql += string.Join(" OR ", paramList); sql += ")"; SqlCommand com = DataAccessHelper.CreateSqlCommand(sql); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); for (int i = 0; i < types.Length; i++) { string paramName = "DxType_" + i; string paramValue = types[i]; DataAccessHelper.AddStringInputParam(com, paramName, paramValue); } return(com); }
public DataSet GetGroupsInDataset(int datasetId) { SqlCommand com = DataAccessHelper.CreateCommand("spGetGroupsInDataset"); DataAccessHelper.AddIntInputParam(com, "DatasetId", datasetId); return(DataAccessHelper.GetList(com)); }
public DataSet ValidatePatientDisease(int patientId, int diseaseId) { SqlCommand com = DataAccessHelper.CreateCommand("spGetPatientDiseasesRecord"); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); DataAccessHelper.AddIntInputParam(com, "DiseaseId", diseaseId); return(DataAccessHelper.GetList(com)); }
public DataSet GetUsersLastFiveRecordChanges(string userId) { SqlCommand com = DataAccessHelper.CreateCommand("spRptAdminLastFiveUsersRecordChanges"); DataAccessHelper.AddIntInputParam(com, "UserID", int.Parse(userId)); return(GetRecord(com, null)); }
/// <summary> /// Returns records of files that have the same table name and primary key of the table. /// </summary> /// <param name="tableName">table name</param> /// <param name="tablePrimaryKey">primary key of record in table</param> /// <returns></returns> public DataSet GetRecordsByTableAndTablePK(string tableName, int tablePrimaryKey) { SqlCommand com = DataAccessHelper.CreateCommand("spGetFiles"); DataAccessHelper.AddStringInputParam(com, "TableName", tableName); DataAccessHelper.AddIntInputParam(com, "TablePrimaryKey", tablePrimaryKey); return(DataAccessHelper.GetRecord(com)); }
public DataSet GetDxImageProstateRecentDosimetry(int patientId) { SqlCommand com = DataAccessHelper.CreateCommand("spGetDxImageProstateRecentDosimetry"); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); return(DataAccessHelper.GetRecord(com)); }
public DataSet GetEformsInbox(int UserId, string Status) { SqlCommand com = DataAccessHelper.CreateCommand("spGetEFormsInbox"); DataAccessHelper.AddIntInputParam(com, "UserId", UserId); DataAccessHelper.AddStringInputParam(com, "CurrentStatus", Status); return(DataAccessHelper.GetRecord(com)); }
public DataSet GetPatientOpenEformByName(int patientId, string eformName) { SqlCommand com = DataAccessHelper.CreateCommand("spGetPatientOpenEFormByName"); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); DataAccessHelper.AddStringInputParam(com, "EFormName", eformName); return(DataAccessHelper.GetRecord(com)); }
public DataSet GetUsersWithPermission(int datasetId, string permission) { SqlCommand com = DataAccessHelper.CreateCommand("spGetUsersWithPermission"); DataAccessHelper.AddIntInputParam(com, "DatasetId", datasetId); DataAccessHelper.AddStringInputParam(com, "Permission", permission); return(DataAccessHelper.GetRecord(com)); }
public DataSet ValidatePatientProtocol(int PatientId, int ProtocolId) { SqlCommand com = DataAccessHelper.CreateCommand("spValidatePatientProtocol"); DataAccessHelper.AddIntInputParam(com, "PatientId", PatientId); DataAccessHelper.AddIntInputParam(com, "ProtocolId", ProtocolId); return(DataAccessHelper.GetList(com)); }
public DataSet GetBrachyPatientReportFields(int patientId) { SqlCommand com = DataAccessHelper.CreateCommand("spRptBrachyCommonFields"); DataAccessHelper.AddIntInputParam(com, "PatientId", patientId); return(DataAccessHelper.GetList(com)); }
public DataSet GetPatientProtocol(int patientProtocolId) { SqlCommand com = DataAccessHelper.CreateCommand("spGetPatientProtocolsRecord"); DataAccessHelper.AddIntInputParam(com, "PatientProtocolId", patientProtocolId); return(DataAccessHelper.GetRecord(com)); }
public DataSet GetByUserId(int userId) { SqlCommand com = DataAccessHelper.CreateCommand("spGetUsersRecordByUserId"); DataAccessHelper.AddIntInputParam(com, "UserId", userId); return(DataAccessHelper.GetRecord(com)); }