protected void Page_Init(object sender, EventArgs e)
    {
        ctx = new AriClinicContext("AriClinicContext");
        // security control, it must be a user logged
        if (Session["User"] == null)
            Response.Redirect("Default.aspx");
        else
        {
            user = (User)Session["User"];
            user = CntAriCli.GetUser(user.UserId, ctx);
            Process proc = (from p in ctx.Processes
                            where p.Code == "examinationassigned"
                            select p).FirstOrDefault<Process>();
            per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
            btnAccept.Visible = per.Modify;
        }

        // 
        if (Request.QueryString["ExaminationAssignedId"] != null)
        {
            examinationAssignedId = Int32.Parse(Request.QueryString["ExaminationAssignedId"]);
            examinationAssigned = CntAriCli.GetExaminationAssigned(examinationAssignedId, ctx);
            LoadData(examinationAssigned);
        }
        else
        {
            rdpExaminationDate.SelectedDate = DateTime.Now;
        }
        //
        if (Request.QueryString["PatientId"] != null)
        {
            patientId = int.Parse(Request.QueryString["PatientId"]);
            patient = CntAriCli.GetPatient(patientId, ctx);
            // fix rdc with patient
            rdcPatient.Items.Clear();
            rdcPatient.Items.Add(new RadComboBoxItem(patient.FullName, patient.PersonId.ToString()));
            rdcPatient.SelectedValue = patient.PersonId.ToString();
            rdcPatient.Enabled = false;
        }
        //
        if (Request.QueryString["VisitId"] != null)
        {
            visitId = int.Parse(Request.QueryString["VisitId"]);
            visit = CntAriCli.GetVisit(visitId, ctx);
            patientId = visit.Patient.PersonId;
            patient = CntAriCli.GetPatient(patientId, ctx);
            // fix rdc with patient
            rdcPatient.Items.Clear();
            rdcPatient.Items.Add(new RadComboBoxItem(patient.FullName, patient.PersonId.ToString()));
            rdcPatient.SelectedValue = patient.PersonId.ToString();
            rdcPatient.Enabled = false;
            //
            rdpExaminationDate.SelectedDate = visit.VisitDate;
        }
    }
Example #2
0
        public static void ImportExaminationsAssigned(OleDbConnection con, AriClinicContext ctx)
        {
            // (0) Borra tipos previos
            //ctx.Delete(ctx.WithoutGlassesTests);
            //ctx.Delete(ctx.GlassesTests);
            //ctx.Delete(ctx.ContactLensesTests);
            //ctx.Delete(ctx.OpticalObjectiveExaminations);
            //ctx.Delete(ctx.SubjectiveOpticalExaminations);
            //ctx.Delete(ctx.Cycloplegias);
            //ctx.Delete(ctx.PrescriptionGlasses);

            //ctx.Delete(ctx.Refractometries);
            //ctx.Delete(ctx.Biometries);
            //ctx.Delete(ctx.Paquimetries);
            //ctx.Delete(ctx.Topographies);

            //ctx.Delete(ctx.ExaminationAssigneds);
            //ctx.SaveChanges();

            // (1) Dar de alta los diferentes diagnósticos
            string sql = "SELECT * FROM HistExplor";
            cmd = new OleDbCommand(sql, con);
            da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "ConExploraciones");
            int nreg = ds.Tables["ConExploraciones"].Rows.Count;
            int reg = 0;
            foreach (DataRow dr in ds.Tables["ConExploraciones"].Rows)
            {
                reg++;
                Boolean newEx = false;
                Console.WriteLine("Exploraciones asignadas {0:#####0} de {1:#####0} {2}", reg, nreg, "EXPASG");
                int id = (int)dr["NumHis"];
                Patient patient = (from p in ctx.Patients
                                   where p.OftId == id
                                   select p).FirstOrDefault<Patient>();
                id = (int)dr["IdExEs"];
                Examination examination = (from ex in ctx.Examinations
                                           where ex.OftId == id
                                           select ex).FirstOrDefault<Examination>();
                DateTime examinationDate = (DateTime)dr["Fecha"];
                ExaminationAssigned examas = (from e in ctx.ExaminationAssigneds
                                              where e.Patient.PersonId == patient.PersonId
                                              && e.Examination.ExaminationId == examination.ExaminationId
                                              && e.ExaminationDate == examinationDate
                                              select e).FirstOrDefault<ExaminationAssigned>();
                if (examas == null)
                {
                    examas = new ExaminationAssigned();
                    newEx = true;
                }

                examas.Patient = patient;
                examas.Examination = examination;
                examas.ExaminationDate = examinationDate;
                examas.Comments = (string)dr["Hallazgos"];
                if ((int)dr["TipoProc"] == 1)
                {
                    id = (int)dr["ExtProc"];
                    examas.BaseVisit = (from bs in ctx.BaseVisits
                                        where bs.OftRefVisita == id
                                        select bs).FirstOrDefault<BaseVisit>();
                }
                switch (examas.Examination.ExaminationType.Code)
                {
                    case "general":
                        if (newEx) ctx.Add(examas);
                        ctx.SaveChanges();
                        break;
                    case "refractometry":
                        Refractometry refra;    
                        if (newEx)
                            refra = new Refractometry();
                        else
                            refra = (Refractometry)examas;
                        refra.Patient = examas.Patient;
                        refra.Examination = examas.Examination;
                        refra.ExaminationDate = examas.ExaminationDate;
                        refra.BaseVisit = examas.BaseVisit;
                        refra.Comments = examas.Comments;
                        id = (int)dr["ExtExEs"];
                        ProcessRefractometry(id, refra, con, ctx);
                        if (newEx) ctx.Add(refra);
                        ctx.SaveChanges();
                        break;
                    case "paquimetry":
                        Paquimetry paq;
                        if (newEx)
                            paq = new Paquimetry();
                        else
                            paq = (Paquimetry)examas;
                        paq.Patient = examas.Patient;
                        paq.Examination = examas.Examination;
                        paq.ExaminationDate = examas.ExaminationDate;
                        paq.BaseVisit = examas.BaseVisit;
                        paq.Comments = examas.Comments;
                        id = (int)dr["ExtExEs"];
                        ProcessPaquimetry(id, paq, con, ctx);
                        if (newEx) ctx.Add(paq);
                        ctx.SaveChanges();
                        break;
                    case "biometry":
                        Biometry bio;
                        if (newEx)
                            bio = new Biometry();
                        else
                            bio = (Biometry)examas;
                        bio.Patient = examas.Patient;
                        bio.Examination = examas.Examination;
                        bio.ExaminationDate = examas.ExaminationDate;
                        bio.BaseVisit = examas.BaseVisit;
                        bio.Comments = examas.Comments;
                        if (newEx) ctx.Add(bio);
                        ctx.SaveChanges();
                        break;
                    case "topography":
                        Topography top;
                        if (newEx)
                            top = new Topography();
                        else
                            top = (Topography)examas;
                        top.Patient = examas.Patient;
                        top.Examination = examas.Examination;
                        top.ExaminationDate = examas.ExaminationDate;
                        top.BaseVisit = examas.BaseVisit;
                        top.Comments = examas.Comments;
                        if (newEx) ctx.Add(top);
                        ctx.SaveChanges();
                        break;
                }
            }
        }
    protected void LoadData(ExaminationAssigned da)
    {
        // Load patient data
        rdcPatient.Items.Clear();
        rdcPatient.Items.Add(new RadComboBoxItem(da.Patient.FullName, da.Patient.PersonId.ToString()));

        // Load Examination data
        rdcExamination.Items.Clear();
        rdcExamination.Items.Add(new RadComboBoxItem(da.Examination.Name, da.Examination.ExaminationId.ToString()));

        rdpExaminationDate.SelectedDate = da.ExaminationDate;
        txtComments.Text = da.Comments;
    }
 protected void UnloadData(ExaminationAssigned da)
 {
     da.Patient = CntAriCli.GetPatient(int.Parse(rdcPatient.SelectedValue), ctx);
     da.ExaminationDate = (DateTime)rdpExaminationDate.SelectedDate;
     da.Examination = CntAriCli.GetExamination(int.Parse(rdcExamination.SelectedValue), ctx);
     if (visit != null)
         da.BaseVisit = visit;
     da.Comments = txtComments.Text;
 }
 protected bool CreateChange()
 {
     if (!DataOk())
         return false;
     if (examinationAssigned == null)
     {
         examinationAssigned = new ExaminationAssigned();
         UnloadData(examinationAssigned);
         ctx.Add(examinationAssigned);
     }
     else
     {
         examination = CntAriCli.GetExamination(examinationId, ctx);
         UnloadData(examinationAssigned);
     }
     ctx.SaveChanges();
     return true;
 }