protected void btn_Guardar_Click(object sender, EventArgs e)
    {
        BL.Paciente g_Paciente = new BL.Paciente();
        try
        {
            if (txt_Expediente.Text != "" && txt_Historiador.Text != "" && txt_Edad.Text != ""
                && txt_Sexo.Text != "" && txt_Informante.Text != "" && txt_Remitente.Text != "" && elm1.Value != "")
            {
                if (g_Paciente.isDoctor(Session["nombre_usuario"].ToString()))
                {
                    string t_Doc = nombreDoctro();
                    if (t_Doc != null)
                    {
                        Thread.CurrentThread.CurrentCulture = new CultureInfo("pl-PL");
                        if (g_Paciente.guardarHAdultos(g_Expediente, Convert.ToInt32(Session["Centro_idNum"].ToString())
                            , Convert.ToInt32(txt_Edad.Text),dls_Lateralidad.SelectedItem.Text, txt_Informante.Text, DateTime.Now, Session["nombre_usuario"].ToString()
                            , txt_Remitente.Text, elm1.Value))
                        {
                            txt_Expediente.Text = g_Expediente.ToString();
                            buscarCargar();
                            grd_Historial.Visible = true;
                            lb_Mensaje.Text = "Se guardo correctamente";
                            dls_Lateralidad.Enabled = false;
                            defLateralidad();
                            btn_Guardar.Enabled = false;
                            btn_Guardar.Visible = false;
                            btn_Nuevo.Enabled = false;
                            btn_Nuevo.Visible = false;
                            datosPanel(false);
                        }
                        else
                        {
                            lb_Mensaje.Text = "No se pudo guardar";
                        }
                    }
                    else
                    {
                        lb_Mensaje.Text = "Error al obtener el nombre del doctor";
                    }
                }
                else
                {
                    lb_Mensaje.Text = "No tiene permisos para esta opción";
                }
            }
            else
            {
                lb_Mensaje.Text = "Hay datos Vacios";
            }
        }
        catch
        {

        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            List<string> permisos = (List<string>)Session["Permisos_usuario"];
            bool permisoEncontrado = false;
            Paciente pac = new Paciente();

            foreach (string rol in permisos)
            {
                if (rol.Equals("pSegPac"))
                {
                    permisoEncontrado = true;
                    break;
                }
            }

            if (!permisoEncontrado)
            {
                //Si no tiene permiso redireccionamos
                //Response.Write("<script>alert('Usted no posee permisos suficientes para accesar a este recurso')</script>");
                Response.Redirect("NoAccess.aspx");
            }

            if (!IsPostBack)
            {
                if (!pac.isDoctor(Session.Contents["nombre_usuario"].ToString()))
                    cargarDoctores();
                else
                    cargarDoctor();
            }

            ceFechaFinal.SelectedDate = DateTime.Now;
            ceFechaInicio.SelectedDate = DateTime.Now;
        }
        catch (Exception error)
        {
            Session["Error_Msg"] = error.Message;
            Response.Redirect("~/Error.aspx", true);
        }
    }
    private void cargarDoctores()
    {
        try
        {
            BL.Empleados doctores = new BL.Empleados();
            Usuarios usuarios = new Usuarios();
            Paciente pac = new Paciente();

            List<string> usuariosTemp = usuarios.RetrieveUserNames();
            List<string> usersDocs = new List<string>();
            List<long> ids = new List<long>();
            List<string> nombres = new List<string>();
            List<string> apellido = new List<string>();
            List<string> segundoApellido = new List<string>();

            foreach (string doc in usuariosTemp)
            {
                if (pac.isDoctor(doc))
                {
                    ids.Add(usuarios.retriveEmpId(doc));
                    usersDocs.Add(doc);
                }
            }

            foreach (long codigo in ids)
            {
                nombres.Add(doctores.obtenerNombresDoctores(codigo));
                apellido.Add(doctores.obtenerApellidoDoctores(codigo));
                segundoApellido.Add(doctores.obtenerSegundoApellidoDoctores(codigo));
            }

            ListItem temporal = new ListItem();
            temporal.Text = "--- Todos ---";
            temporal.Value = "todos";
            temporal.Selected = true;
            ddlDoctor.Items.Add(temporal);

            for (int i = 0; i < nombres.Count; i++)
            {
                ListItem item = new ListItem();
                item.Text = nombres[i] + " " + apellido[i] + " " + segundoApellido[i];
                item.Value = usersDocs[i].ToString();
                ddlDoctor.Items.Add(item);
            }
        }
        catch (Exception error)
        {
            Session["Error_Msg"] = error.Message;
            Response.Redirect("~/Error.aspx", true);
        }
    }