public static void InsertStudyGroup(object studyId, object referringPhysicianId, object userId)
 {
     RISDatabaseAccessLayer databaseAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)databaseAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("sp_insert_study_group", connection);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.AddWithValue("@studyId", studyId);
     command.Parameters.AddWithValue("@userId", referringPhysicianId);
     command.Parameters.AddWithValue("@adminUserId", userId);
     command.ExecuteNonQuery();
 }
 public static DataTable GetAllUsers()
 {
     RISDatabaseAccessLayer databaseAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)databaseAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("SELECT [UserId], [LoginName], [Password], [Name], [IsActive] FROM [tUsers]", connection);
     command.CommandType = CommandType.Text;
     SqlDataAdapter da = new SqlDataAdapter(command);
     DataTable dtResults = new DataTable();
     da.Fill(dtResults);
     connection.Close();
     return dtResults;
 }
 public static DataTable GetUserGroupsWithDefaults(int userid)
 {
     RISDatabaseAccessLayer databaseAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)databaseAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("sp_get_groups_for_user_defaults", connection);
     command.Parameters.AddWithValue("@userid", userid);
     command.CommandType = CommandType.StoredProcedure;
     SqlDataAdapter da = new SqlDataAdapter(command);
     DataTable dtResults = new DataTable();
     da.Fill(dtResults);
     connection.Close();
     return dtResults;
 }
 private void BindList()
 {
     RISDatabaseAccessLayer dataAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)dataAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("sp_get_roles_for_user", connection);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.AddWithValue("@userId", loggedInUserId);
     SqlDataReader reader = command.ExecuteReader();
     ddlRoles.DataSource = reader;
     ddlRoles.DataMember = "Name";
     ddlRoles.DataTextField = "Name";
     ddlRoles.DataValueField = "RoleId";
     ddlRoles.DataBind();
     connection.Close();
 }
 public static int GetRoleCount(int userId)
 {
     int numOfRoles = 0;
     RISDatabaseAccessLayer databaseAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)databaseAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("sp_get_num_user_roles", connection);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.AddWithValue("@userId", userId);
     SqlDataReader reader = command.ExecuteReader();
     if (reader.Read())
     {
         numOfRoles = reader.GetInt32(0);
     }
     connection.Close();
     return numOfRoles;
 }
 public static void BindModalitiesDDL(string addText, DropDownList ddl)
 {
     RISDatabaseAccessLayer dataAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)dataAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("sp_get_modalities", connection);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.AddWithValue("@addText", addText);
     SqlDataReader reader = command.ExecuteReader();
     ddl.DataSource = reader;
     ddl.DataMember = "Name";
     ddl.DataTextField = "Name";
     ddl.DataValueField = "ModalityId";
     ddl.DataBind();
     reader.Close();
     connection.Close();
 }
    private void FillTemplatesList()
    {
        RISDatabaseAccessLayer db = new RISDatabaseAccessLayer();
        string query = "select tTemplates.TemplateId,tTemplates.[Name] from tTemplates "
            + " inner join tTemplateUsers on tTemplates.TemplateId = tTemplateUsers.TemplateId "
            + " inner join tModalities on tTemplates.ModalityId = tModalities.ModalityId "
            + " where tTemplateUsers.UserId = " + Request["userId"]
            + " and tModalities.Name = '" + Request["modalityName"] + "'";

        SqlConnection con = (SqlConnection)db.GetConnection();
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt = new DataTable();
        da.SelectCommand = cmd;
        da.Fill(dt);

        //Populating Drop down list of templates
        if (dt.Rows.Count > 0)
        {
            DropDownList ddlTemplates = new DropDownList();
            ddlTemplates.ID = "ddlTemplates";
            ddlTemplates.DataSource = dt;
            ddlTemplates.DataTextField = "Name";
            ddlTemplates.DataValueField = "TemplateId";
            ddlTemplates.DataBind();

            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            Label label = new Label();
            label.ID = "lblTemplate";
            label.Text = "Template:";
            label.RenderControl(oHtmlTextWriter);

            ddlTemplates.RenderControl(oHtmlTextWriter);

            Response.Write(oHtmlTextWriter.InnerWriter);
            Response.Write("<input id='btnLoadTemplate' type='button' value='Apply Template' onclick='getReportText()'/>");
            Response.End();
        }
        else
        {
            Response.Write("<i>No Templates Found</i>");
            Response.End();
        }
    }
    protected override void Page_Load_Extended(object sender, EventArgs e)
    {
        int studyId = int.Parse(Request[ParameterNames.Request.StudyId]);
        SqlConnection connection = null;
        SqlCommand command = null;
        SqlDataReader reader = null;
        try
        {

            StringBuilder query = new StringBuilder(" SELECT tImages.Path FROM tImages ");
            query.Append(" INNER JOIN tSeries ON tSeries.SeriesId = tImages.SeriesId ");
            query.Append(" WHERE tSeries.StudyId = @StudyId ");

            RISDatabaseAccessLayer risDatabase = new RISDatabaseAccessLayer();
            connection = (SqlConnection)risDatabase.GetConnection();
            connection.Open();
            command = new SqlCommand(query.ToString(), connection);
            command.Parameters.AddWithValue("@StudyId", studyId);
            reader = command.ExecuteReader();
            int count = 1;
            while (reader.Read())
            {
                appletParams.Append(getAppletParam(count++, reader.GetString(0)));
            }
            if (appletParams.Length > 0)
            {
                Log(studyId);
            }
            else
            {
                Session[ParameterNames.Session.ErrorMessage] = "No files found for the study";
                Response.Redirect("~/SharedPages/ErrorPage.aspx");
            }
        }
        finally
        {
            if (reader != null) reader.Close();
            //if (command != null) command.Close();
            if (connection != null) connection.Close();
        }
    }
 private ArrayList GetRISList()
 {
     RISObject risObject = GetRISObject();
     QueryBuilder query = risObject.GetSelectQuery();
     query.AddText(GetRISWhereClause());
     RISDatabaseAccessLayer dataAccessLayer = new RISDatabaseAccessLayer();
     SqlDataReader reader = (SqlDataReader)dataAccessLayer.ExecuteQuery(query);
     ArrayList risObjects = new ArrayList();
     while (reader.Read())
     {
         risObject.Load(reader);
         risObjects.Add(risObject);
         risObject = GetRISObject();
     }
     reader.Close();
     dataAccessLayer.CloseConnection();
     return risObjects;
 }
        protected override void PerformPostSaveTasks(RISObject risObject)
        {
            if (hospital != null)
            {
                StudyObject risStudy = (StudyObject)risObject;

                RISDatabaseAccessLayer databaseAccessLayer = new RISDatabaseAccessLayer();
                SqlConnection connection = (SqlConnection)databaseAccessLayer.GetConnection();
                connection.Open();
                SqlCommand command = new SqlCommand("sp_insert_study_group", connection);
                command.Parameters.AddWithValue("@studyId", risStudy.GetPrimaryKey().Value);
                command.Parameters.AddWithValue("@hospitalId", hospital.HospitalId.Value);
                command.Parameters.AddWithValue("@adminUserId", GenericDataMigrator.AdminUserId);
                command.CommandType = CommandType.StoredProcedure;
                command.ExecuteNonQuery();
                connection.Close();
            }
        }
 public List<StudyListPageObject> GetData()
 {
     SqlConnection connection = null;
     List<StudyListPageObject> data = new List<StudyListPageObject>();
     try
     {
         RISDatabaseAccessLayer dal = new RISDatabaseAccessLayer();
         connection = (SqlConnection)dal.GetConnection();
         connection.Open();
         SqlCommand command = GetQuery(QueryType.SELECT);
         command.Connection = connection;
         SqlDataReader reader = command.ExecuteReader();
         while(reader.Read())
         {
             data.Add(GetStudyListPageObject(reader));
         }
         reader.Close();
     }
     finally
     {
         if(connection != null)connection.Close();
     }
     return data;
 }
    private void BindBodyPart(int modalityId)
    {
        RISDatabaseAccessLayer db = new RISDatabaseAccessLayer();
        string query = "SELECT '[-- Select --]' AS BodyPart UNION select DISTINCT BodyPart AS BodyPart from tTemplates "
            + " WHERE tTemplates.ModalityId = " + modalityId;

        SqlConnection con = (SqlConnection)db.GetConnection();
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt = new DataTable();
        da.SelectCommand = cmd;
        da.Fill(dt);

        //Populating Drop down list of templates
        if (dt.Rows.Count > 0)
        {
            ddlBodyParts.DataSource = dt;
            ddlBodyParts.DataTextField = "BodyPart";
            ddlBodyParts.DataValueField = "BodyPart";
            ddlBodyParts.DataBind();
        }
    }
 private void fillAllRolesList()
 {
     RISDatabaseAccessLayer dataAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)dataAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("select RoleId,Name from tRoles", connection);
     BindListBox(command, lbOtherRoles);
     connection.Close();
 }
    protected override void Page_Load_Extended(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            if (Request[Params.UserId] != null)
            {
                lbUserId.Text = Request[Params.UserId];

                UserObject user = new UserObject();
                user.UserId.Value = int.Parse(lbUserId.Text.Trim());
                user.Load();
                if (user.IsLoaded)
                {
                    tbLoginName.Text = user.LoginName.Value.ToString();
                    tbLoginName.Enabled = false;
                    tbPassword.Text = user.Password.Value.ToString();
                    tbConfirmPassword.Text = user.Password.Value.ToString();
                    string strFirstName = "";
                    string strLastName = "";
                    RISUtility.GetFirstLastName(user.Name.Value.ToString(), ref strFirstName, ref strLastName);
                    tbFirstName.Text = strFirstName.Trim();
                    tbLastName.Text = strLastName.Trim();
                    cbIsActive.Checked = (bool)user.IsActive.Value;

                }
                RISDatabaseAccessLayer dataAccess = new RISDatabaseAccessLayer();
                SqlConnection connection = (SqlConnection)dataAccess.GetConnection();
                connection.Open();
                SqlCommand command = new SqlCommand("sp_get_roles_for_user", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@userId", int.Parse(Request[Params.UserId]));

                BindListBox(command, lbUserRoles);
                SqlCommand command2 = new SqlCommand("sp_get_roles_not_for_user", connection);
                command2.CommandType = CommandType.StoredProcedure;
                command2.Parameters.AddWithValue("@userId", int.Parse(Request[Params.UserId]));
                BindListBox(command2, lbOtherRoles);
                connection.Close();
            }
            else
            {
                fillAllRolesList();
            }
        }
    }
 //public StudyListModal(int currentPage,int sortBy,string isAsc,string hdPatientId,string patientId,string patientName,int modalityId,int studyStatusId,string procedure,string radiologist,string physician,DateTime fromDate,DateTime toDate,int loggedInUseRoleId,int loggedInUserId)
 //{
 //    this.currentPage = currentPage;
 //    this.sortBy = sortBy;
 //    this.isAsc = isAsc;
 //    this.hdPatientId = hdPatientId;
 //    this.patientId = patientId;
 //    this.patientName = patientName;
 //    this.modalityId = modalityId;
 //    this.studyStatusId = studyStatusId;
 //    this.procedure = procedure;
 //    this.radiologist = radiologist;
 //    this.physician = physician;
 //    this.fromDate = fromDate;
 //    this.examDate = -2;
 //    this.toDate = toDate;
 //    this.loggedInUserRoleId = loggedInUserRoleId;
 //    this.loggedInUserId = loggedInUserId;
 //}
 public int GetRecordCount()
 {
     SqlConnection connection = null;
     int recCount = 0;
     try
     {
         RISDatabaseAccessLayer dal = new RISDatabaseAccessLayer();
         connection = (SqlConnection)dal.GetConnection();
         connection.Open();
         SqlCommand command = GetQuery(QueryType.COUNT);
         command.Connection = connection;
         recCount = (int)command.ExecuteScalar();
     }
     finally
     {
         if (connection != null) connection.Close();
     }
     return recCount;
 }
 public static void BindUserDDLForGroup(int roleId, int groupId,string addText, DropDownList ddl)
 {
     RISDatabaseAccessLayer dataAccess = new RISDatabaseAccessLayer();
     SqlConnection connection = (SqlConnection)dataAccess.GetConnection();
     connection.Open();
     SqlCommand command = new SqlCommand("sp_get_users_for_role_in_group", connection);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.AddWithValue("@roleId", roleId);
     command.Parameters.AddWithValue("@groupId", groupId);
     command.Parameters.AddWithValue("@addText", addText);
     SqlDataReader reader = command.ExecuteReader();
     ddl.DataSource = reader;
     ddl.DataMember = "Name";
     ddl.DataTextField = "Name";
     ddl.DataValueField = "UserId";
     ddl.DataBind();
     reader.Close();
     connection.Close();
 }
    protected override void Page_Load_Extended(object sender, EventArgs e)
    {
        startPage = int.Parse(intStartPage.Value);
        endPage = startPage + WebConstants.Pages -1;
        if (IsPostBack == false)
        {
            FillDDL();
            if (loggedInUserRoleId == Constants.Roles.Radiologist)
            {
                lblClient.Visible = true;
                ddlClient.Visible = true;
                //ddlClient.DataSource
                RISDatabaseAccessLayer db = new RISDatabaseAccessLayer();
                string query = "select ClientId,Name from tClients";
                SqlConnection con = (SqlConnection)db.GetConnection();
                SqlCommand cmd = new SqlCommand(query, con);
                SqlDataAdapter da = new SqlDataAdapter();
                DataTable dt = new DataTable();
                da.SelectCommand = cmd;
                da.Fill(dt);

                //Populating Drop down list of templates
                if (dt.Rows.Count > 0)
                {
                    ddlClient.DataSource = dt;
                    ddlClient.DataTextField = "Name";
                    ddlClient.DataValueField = "ClientId";
                    ddlClient.DataBind();
                }
            }
        }
        /*
        if (hfCarryStatus.Value.ToString() != "x")
        {
            string labels = hfCarryStatus.Value.ToString();
            string[] labelsArray = labels.Split(',');
            foreach (string label in labelsArray)
            {
                    cblStatus.Items.FindByText(label).Selected = true;
            }
        }
        else
        {
            cblStatus.Items.FindByText("[All]").Selected = true;
            statusText.Text = "[All]";

        }
        if (hfCarryModality.Value.ToString() != "x")
        {
            string labels = hfCarryModality.Value.ToString();
            string[] labelsArray = labels.Split(',');
            foreach (string label in labelsArray)
            {
                    cblModality.Items.FindByText(label).Selected = true;
            }
        }
        else
        {
            cblModality.Items.FindByText("[All]").Selected = true;
            modalityText.Text = "[All]";

        }
         */
        if (Request["hfAction"] != null)
        {
            if (Request["hfAction"] == "release")
            {
                if (Request["releaseToRad"] != null)
                {
                    string[] studyIds = Request["releaseToRad"].Split(',');
                    foreach (string studyId in studyIds)
                    {
                        StudyObject study = new StudyObject();
                        study.StudyId.Value = studyId;
                        study.Load(loggedInUserId);
                        if (study.IsLoaded)
                        {
                            if (study.HospitalId.Value != null && study.ReferringPhysicianId.Value != null)
                            {
                                study.StudyStatusId.Value = Constants.StudyStatusTypes.New;
                                study.Save(loggedInUserId);
                            }
                            else
                            {
                                SetErrorMessage("One or more exams could not be released to Radiologists as they have missing data");
                            }
                        }
                    }
                }
            }
        }
        ExecuteProcedure();
        ClearData();
        StringBuilder url = new StringBuilder();
        url.Append("http://").Append(Request.Url.Authority);
        if(Request.ApplicationPath.Length > 0)
            url.Append(Request.ApplicationPath).Append("/");
        url.Append("WebServices/");
        hfWebServicesHomeURL.Value = url.ToString();
        url.Append("FindingService.asmx");
        hfSURL.Value = url.ToString();
        hfLoggedInUserId.Value = loggedInUserId.ToString();
        hfLoggedInUserName.Value = loggedInUser.Name.Value.ToString();
        hfLoggedInUserRoleId.Value = loggedInUserRoleId.ToString();
    }