Esempio n. 1
0
        public async Task <IActionResult> Index([FromRoute] int id)
        {
            try
            {
                var consultationsViewModel = new ConsultationsViewModel();
                consultationsViewModel.Patient = await _patientViewModelService.GetPatientWithConsultations(id);

                //   ViewBag.Data = familyViewModel.Patient.Siblings;
                return(View(consultationsViewModel));
            }
            catch (Exception exp)
            {
                throw (exp);
            }
        }
Esempio n. 2
0
        public ActionResult Edit(int id)
        {
            var doctor = db.Doctors.FirstOrDefault(d => d.userID == WebSecurity.CurrentUserId);

            var consultation = db.Consultations
                               .FirstOrDefault(c => c.ID == id &&
                                               (c.ended == false || EntityFunctions.TruncateTime(c.createDate)
                                                == EntityFunctions.TruncateTime(DateTime.Now)));

            if (consultation == null)
            {
                return(this.InvokeHttp404(HttpContext));
            }

            var model = new ConsultationsViewModel();

            GlobalHelpers.Transfer <Consultation, ConsultationsViewModel>(consultation, model);
            model.comments      = consultation.observations;
            model.analysisID    = consultation.Analyses.Select(a => a.ID).ToList();
            model.studyID       = consultation.Studies.Select(a => a.ID).ToList();
            model.procedureID   = consultation.Procedures.Select(a => a.ID).ToList();
            ViewBag.procedureID = db.Procedures.Where(p => p.status == true)
                                  .ToSelectListItems(p => p.name, p => p.ID.ToString(), p => model.procedureID != null && model.procedureID.Contains(p.ID));
            ViewBag.studyID = db.Studies.Where(p => p.status == true)
                              .ToSelectListItems(p => p.name, p => p.ID.ToString(), s => model.studyID != null && model.studyID.Contains(s.ID));
            ViewBag.analysisID = db.Analyses.Where(p => p.status == true)
                                 .ToSelectListItems(p => p.name, p => p.ID.ToString(), a => model.analysisID != null && model.analysisID.Contains(a.ID));
            ViewBag.medicineID = db.Medicines.Where(p => p.status == true)
                                 .ToSelectListItems(p => p.name, p => p.ID.ToString());
            ViewBag.diagnoseCode = db.ICD10
                                   .ToSelectListItems(
                i => i.Code + " - " + ((CultureHelper.GetCurrentNeutralCulture() == "es") ? i.Description_es : i.Description_en),
                i => i.Code
                );

            return(View(model));
        }
Esempio n. 3
0
        public ActionResult Edit(ConsultationsViewModel model)
        {
            var doctor  = db.Doctors.Find(model.doctorID);
            var patient = db.Patients.Find(model.patientID);

            if (model.nextAppointment != null)
            {
                // verificar si el doctor no ha definido sus reglas para consulta
                if (doctor.DoctorRules.Count() == 0)
                {
                    ModelState.AddModelError("nextAppointment", _("lblDcotorAPErr")); // Agregar error al modelo.
                }
                // verificar si el doctor consulta ese día.
                else if (!doctor.DoctorRules
                         .ElementAt(0).availableDays.Split(',')
                         .Contains(((int)((DateTime)model.nextAppointment).DayOfWeek).ToString()))
                {
                    ModelState.AddModelError("nextAppointment", _("lblDoctorConsDayErr"));
                }
                // verificar la cantidad de pacientes que han reservado cita ese día.
                else if (doctor.Appointments
                         .Where(a => a.appointmentDate.Date == ((DateTime)model.nextAppointment).Date).Count() >=
                         doctor.DoctorRules.ElementAt(0).maxPatients)
                {
                    ModelState.AddModelError(
                        "nextAppointment", string.Format(
                            _("lblDoctorMaxPatientsErr"),
                            doctor.DoctorRules.ElementAt(0).maxPatients
                            )
                        );
                }
                // verificar si el paciente tiene una cita con este doctor.
                else if (patient.Appointments.Where(a => a.status == true && a.doctorID == model.doctorID && a.finalStatus == null).Count() > 0)
                {
                    ModelState.AddModelError("nextAppointment", _("lblPatientAASErr"));
                }
            }

            if (ModelState.IsValid)
            {
                var c = db.Consultations.Find(model.ID);
                GlobalHelpers.Transfer <ConsultationsViewModel, Consultation>(model, c, "Patient");
                c.observations = model.comments;
                c.ended        = true;
                c.Analyses.Clear();
                c.Studies.Clear();
                c.Procedures.Clear();

                if (model.analysisID != null)
                {
                    foreach (int ID in model.analysisID)
                    {
                        c.Analyses.Add(db.Analyses.Find(ID));
                    }
                }

                if (model.studyID != null)
                {
                    foreach (int ID in model.studyID)
                    {
                        c.Studies.Add(db.Studies.Find(ID));
                    }
                }

                if (model.procedureID != null)
                {
                    foreach (int ID in model.procedureID)
                    {
                        c.Procedures.Add(db.Procedures.Find(ID));
                    }
                }

                if (model.nextAppointment != null)
                {
                    var appointment = new Appointment();
                    appointment.doctorID        = model.doctorID;
                    appointment.patientID       = model.patientID;
                    appointment.createUser      = WebSecurity.CurrentUserId;
                    appointment.appointmentDate = (DateTime)model.nextAppointment;
                    appointment.status          = true;
                    db.Appointments.Add(appointment);
                    c.Appointment = appointment;
                }
                db.Entry(c).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            var consultation = db.Consultations
                               .FirstOrDefault(c => c.ID == model.ID &&
                                               (c.ended == false || EntityFunctions.TruncateTime(c.createDate)
                                                == EntityFunctions.TruncateTime(DateTime.Now)));

            if (consultation == null)
            {
                return(this.InvokeHttp404(HttpContext));
            }

            model.Patient = consultation.Patient;

            ViewBag.procedureID = db.Procedures.Where(p => p.status == true)
                                  .ToSelectListItems(p => p.name, p => p.ID.ToString(), p => model.procedureID != null && model.procedureID.Contains(p.ID));
            ViewBag.studyID = db.Studies.Where(p => p.status == true)
                              .ToSelectListItems(p => p.name, p => p.ID.ToString(), s => model.studyID != null && model.studyID.Contains(s.ID));
            ViewBag.analysisID = db.Analyses.Where(p => p.status == true)
                                 .ToSelectListItems(p => p.name, p => p.ID.ToString(), a => model.analysisID != null && model.analysisID.Contains(a.ID));
            ViewBag.medicineID = db.Medicines.Where(p => p.status == true)
                                 .ToSelectListItems(p => p.name, p => p.ID.ToString());
            ViewBag.diagnoseCode = db.ICD10
                                   .ToSelectListItems(
                i => i.Code + " - " + ((CultureHelper.GetCurrentNeutralCulture() == "es") ? i.Description_es : i.Description_en),
                i => i.Code
                );

            return(View(model));
        }