Example #1
0
        protected void rgEncounterResults_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                string strPatientID;
                strPatientID = e.Item.Cells[2].Text;

                // Get the patient information from data.
                TrinityClassLibrary_BL.Patient patient = TrinityClassLibrary_DAL.PatientProvider.Fetch(Convert.ToInt32(strPatientID));
                Session["Patient"] = patient;

                // Open the encounter in view or edit mode depending on the encounter status.
                switch (patient.EncounterStatus)
                {
                case "C":                           // Complete.
                case "D":                           // Discussion case.
                case "P":                           // Pending review.
                case "R":                           // Reviewed By Company.
                    Session["mode"] = "view";
                    break;

                case "I":                           // Incomplete.
                    Session["mode"] = "edit";
                    break;

                default:
                    break;
                }

                //string strJS;

                // Lets the patient page know we are returning from a search.
                Session["SearchComplete"] = true;

                //TODO: Remove all references of the patientid session variable and replace with uses of the patient session variable.
                //This is being kept until other code is modified.
                Session["PatientID"] = strPatientID;

                // Get the patient's rig information and store it to session.
                TrinityClassLibrary_BL.Rig rig = TrinityClassLibrary_DAL.RigProvider.Fetch(Convert.ToInt32(patient.RigID));
                Session["PatientRig"] = rig;

                // Redirect the parent window to the patient.apsx page.
                //strJS = "<script language='JavaScript'>window.opener.document.forms[0].action='patient.aspx';</script>";
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "changeURL", strJS);
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "close", "<script language='JavaScript'>window.opener.document.forms[0].submit(); window.close();</script>");

                Response.Redirect("patient.aspx");
            }
        }
Example #2
0
        protected void grdDocuments_ItemCommand(object sender, Telerik.WebControls.GridCommandEventArgs e)
        {
            if (e.CommandName != "Page")
            {
                int docID = Int32.Parse(e.CommandArgument.ToString());
                /* Sets the visible property of the selected document to allow non-admins to view the file */
                if (e.CommandName == "ShowDoc")
                {
                    using (TMM_DEPLOYEntities ef = new TMM_DEPLOYEntities())
                    {
                        var q = (from doc in ef.PatientDocument
                                 where doc.DocumentID == docID
                                 select doc).FirstOrDefault();

                        q.Visible = true;
                        ef.SaveChanges();
                    }
                }

                /* Sets the visible property of the selected document to deny non-admins the ability to view the file */
                if (e.CommandName == "HideDoc")
                {
                    using (TMM_DEPLOYEntities ef = new TMM_DEPLOYEntities())
                    {
                        var q = (from doc in ef.PatientDocument
                                 where doc.DocumentID == docID
                                 select doc).FirstOrDefault();

                        q.Visible = false;
                        ef.SaveChanges();
                    }
                }

                if (e.CommandName == "ViewDoc")
                {
                    try
                    {
                        using (TMM_DEPLOYEntities ef = new TMM_DEPLOYEntities())
                        {
                            var q = (from doc in ef.PatientDocument
                                     where doc.DocumentID == docID
                                     select doc).FirstOrDefault();

                            string   fileName = GetDocumentName(q.DocumentLink);
                            FileInfo fileInfo = new FileInfo(UploadLocation + docID.ToString());

                            // Get the network credentials and use them to impersonate the user with priviledges.
                            string UserName = System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString();
                            string Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString();
                            string Domain   = System.Configuration.ConfigurationManager.AppSettings["Domain"].ToString();

                            // Impersonate the user in order to get the document.
                            //CreateIdentity(UserName, Domain, Password);

                            // Set up the response to receive the file.
                            Response.Clear();
                            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                            Response.ContentType = "application/octet-stream";
                            Response.WriteFile(fileInfo.FullName);

                            // Get the file as a byte array and send it to the response.
                            Byte[] fileBytes = null;
                            using (FileStream fs = new FileStream(UploadLocation + docID.ToString(), FileMode.Open, FileAccess.Read))
                            {
                                try
                                {
                                    BinaryReader br = new BinaryReader(fs);
                                    fileBytes = br.ReadBytes((int)fileInfo.Length);

                                    using (BinaryWriter fw = new BinaryWriter(Response.OutputStream))
                                    {
                                        try
                                        {
                                            fw.Write(fileBytes, 0, fileBytes.Length);
                                        }
                                        catch
                                        {
                                            lblError.Text = "Error: Unable to retrieve the file requested.";
                                        }
                                    }
                                }
                                catch
                                {
                                    lblError.Text = "Error: Unable to read the file.";
                                }
                            }
                            Response.End();
                        }
                    }
                    catch
                    {
                    }
                }
            }

            LoadDocumentList();
        }