public int GrabarGestante(GestanteModel gestante, short modo)
 {
     return(_db.sproc_AddUpdateGestante(modo,
                                        gestante.GestanteKey,
                                        gestante.GestanteNroDocumento,
                                        gestante.Nombres,
                                        gestante.APaterno,
                                        gestante.AMaterno,
                                        gestante.FechaNacimiento,
                                        gestante.FechaUltimaRegla,
                                        gestante.FechaProbableParto,
                                        gestante.PresionSistolicaBase,
                                        gestante.PresionDiastolicaBase,
                                        gestante.DiagnosticoIngreso,
                                        gestante.DiagnosticoIntermedio1,
                                        gestante.DiagnosticoIntermedio2,
                                        gestante.DiagnosticoEgreso,
                                        gestante.EstablecimientoId,
                                        gestante.EstablecimientoNotificacionId,
                                        gestante.GestanteTelefono,
                                        gestante.GestanteDireccion,
                                        gestante.GestanteEmail,
                                        gestante.DistritoId,
                                        string.Empty,
                                        string.Empty,
                                        gestante.UsuarioEditor,
                                        gestante.HorarioMensaje
                                        ).SingleOrDefault() ?? 0);
 }
        public List <string> ObtenerTelefonosParaAlerta(GestanteModel gestante)
        {
            var listaTelefonos = _db.Usuarios.Where(e => e.RecibeAlertas == 1 &&
                                                    e.EstablecimientoId == gestante.EstablecimientoNotificacionId &&
                                                    e.AspNetUsers.PhoneNumber != null &&
                                                    e.AspNetUsers.PhoneNumber.Length > 0)
                                 .Select(e => e.AspNetUsers.PhoneNumber);

            return(listaTelefonos.ToList());
        }
        private List <string> EjecutarValidaciones(GestanteModel gestante)
        {
            int           year    = DateTime.Today.Year;
            DateTime      hoy     = DateTime.Today;
            List <string> errores = new List <string>();

            if (gestante.GestanteKey == 0 &&
                gestanteManager.ObtenerGestanteKeyByGestanteNroDocumento(gestante.GestanteNroDocumento) > 0)
            {
                errores.Add("Ya existe una gestante registrada en el programa con el DNI ingresado.");
            }
            int gestanteKey = gestanteManager.ObtenerGestanteKeyByGestanteTelefono(gestante.GestanteTelefono);

            if (gestanteKey > 0 && gestanteKey != gestante.GestanteKey)
            {
                errores.Add("Ya existe una gestante registrada en el programa con el numero de celular ingresado.");
            }
            if (gestante.FechaNacimiento.Value > hoy)
            {
                errores.Add("La fecha de nacimiento no puede ser en el futuro.");
            }
            if (year - gestante.FechaUltimaRegla.Value.Year > 1)
            {
                errores.Add("La fecha de última regla no puede ser anterior a 1 año.");
            }
            if (gestante.FechaUltimaRegla.Value > hoy)
            {
                errores.Add("La fecha de última regla no puede ser en el futuro.");
            }
            if (gestante.FechaUltimaRegla.Value <= gestante.FechaNacimiento.Value)
            {
                errores.Add("La fecha de última regla no puede ser menor que la fecha de nacimiento.");
            }
            if (gestante.FechaProbableParto.Value <= hoy)
            {
                errores.Add("La fecha  probable de parto no puede ser en el pasado.");
            }
            if (gestante.FechaProbableParto.Value <= gestante.FechaUltimaRegla.Value)
            {
                errores.Add("La fecha probable de parto no puede ser menor que la fecha de última regla.");
            }
            if (gestante.PresionSistolicaBase < 10 || gestante.PresionSistolicaBase > 280)
            {
                errores.Add("La presion sistólica base está fuera del rango válido (10 - 280).");
            }
            if (gestante.PresionDiastolicaBase < 10 || gestante.PresionDiastolicaBase > 280)
            {
                errores.Add("La presion diastólica base está fuera del rango válido (10 - 280).");
            }
            return(errores);
        }
        // GET: Gestante/Ver/5
        public ActionResult Ver(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GestanteModel gestante = gestanteManager.MostrarGestante((int)id);

            if (gestante == null)
            {
                return(HttpNotFound());
            }
            ConfigurarMenues();
            return(View(gestante));
        }
        // GET: Gestante/Editar/5
        public ActionResult Editar(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RegistrarAccion((byte)AccionSesion.Accesar, (byte)ObjetoSesion.EditarGestante, null);
            GestanteModel gestante = gestanteManager.MostrarGestante((int)id);

            if (gestante == null)
            {
                return(HttpNotFound());
            }
            ConfigurarMenues();
            ConfigurarViewBag(gestante);
            return(View(gestante));
        }
 public ActionResult Editar([Bind(Include = "GestanteKey,GestanteNroDocumento,Nombres,APaterno,AMaterno,FechaNacimiento,EstablecimientoId,EstablecimientoNotificacionId,FechaUltimaRegla," +
                                            "FechaProbableParto,PresionSistolicaBase,PresionDiastolicaBase,DiagnosticoIngreso,DiagnosticoIntermedio1,DiagnosticoIntermedio2,DiagnosticoEgreso," +
                                            "GestanteDireccion,GestanteEmail,GestanteTelefono,HorarioMensaje,DistritoId")] GestanteModel gestante)
 {
     foreach (var error in EjecutarValidaciones(gestante))
     {
         ModelState.AddModelError(string.Empty, error);
     }
     if (ModelState.IsValid)
     {
         gestante.UsuarioEditor = ObtenerUsuarioKeyLogeado();
         int updatedGestanteKey = gestanteManager.GrabarGestante(gestante, 1);
         RegistrarAccion((byte)AccionSesion.Actualizar, (byte)ObjetoSesion.EditarGestante, updatedGestanteKey);
         return(RedirectToAction("Index"));
     }
     ConfigurarMenues();
     ConfigurarViewBag(gestante);
     return(View(gestante));
 }
 private void ConfigurarViewBag(GestanteModel gestante = null)
 {
     if (gestante != null)
     {
         var listaEntidadesEstablecimiento = establecimientoManager.ListarEstablecimientos();
         ViewBag.EstablecimientoId = new SelectList(listaEntidadesEstablecimiento, "EstablecimientoId", "Descripcion",
                                                    gestante.EstablecimientoId);
         ViewBag.EstablecimientoNotificacionId = new SelectList(listaEntidadesEstablecimiento, "EstablecimientoId", "Descripcion",
                                                                gestante.EstablecimientoNotificacionId);
         ViewBag.DistritoId = new SelectList(utilManager.ListarUbigeos("EsDist"), "CodUbigeo", "Nombre", gestante.DistritoId);
     }
     else
     {
         var listaEstablecimientos = new SelectList(establecimientoManager.ListarEstablecimientos(), "EstablecimientoId", "Descripcion");
         ViewBag.EstablecimientoId             = listaEstablecimientos;
         ViewBag.EstablecimientoNotificacionId = listaEstablecimientos;
         ViewBag.DistritoId = new SelectList(utilManager.ListarUbigeos("EsDist"), "CodUbigeo", "Nombre");
     }
 }
 public ActionResult Crear([Bind(Include = "GestanteNroDocumento,Nombres,APaterno,AMaterno,FechaNacimiento,EstablecimientoId,EstablecimientoNotificacionId,FechaUltimaRegla," +
                                           "FechaProbableParto,PresionSistolicaBase,PresionDiastolicaBase,DiagnosticoIngreso,DiagnosticoIntermedio1,DiagnosticoIntermedio2,DiagnosticoEgreso," +
                                           "GestanteDireccion,GestanteEmail,GestanteTelefono,HorarioMensaje,DistritoId")] GestanteModel gestante)
 {
     foreach (var error in EjecutarValidaciones(gestante))
     {
         ModelState.AddModelError(string.Empty, error);
     }
     if (ModelState.IsValid)
     {
         gestante.UsuarioEditor = ObtenerUsuarioKeyLogeado();
         int newGestanteKey = gestanteManager.GrabarGestante(gestante, 0);
         NotificacionManager.GrabarNotificacion(gestante.GestanteTelefono, "Msg. Confirmacion",
                                                "Bienvenida. Usted ha sido registrada en el programa de monitoreo a distancia de gestantes con preeclampsia leve. Gracias");
         RegistrarAccion((byte)AccionSesion.Crear, (byte)ObjetoSesion.CrearGestante, newGestanteKey);
         return(RedirectToAction("Index"));
     }
     ConfigurarMenues();
     ConfigurarViewBag(gestante);
     return(View(gestante));
 }
        public GestanteModel MostrarGestante(int id)
        {
            Gestante gestante  = _db.Gestantes.Find(id);
            Ubigeo   distrito  = _db.Ubigeos.FirstOrDefault(E => E.CodUbigeo == gestante.DistritoId);
            Ubigeo   provincia = _db.Ubigeos.FirstOrDefault(E => E.CodUbigeo == gestante.ProvinciaId);
            Ubigeo   region    = _db.Ubigeos.FirstOrDefault(E => E.CodUbigeo == gestante.RegionId);

            if (gestante != null)
            {
                GestanteModel gestanteModel = new GestanteModel();
                gestanteModel.GestanteKey          = gestante.GestanteKey;
                gestanteModel.GestanteId           = gestante.GestanteId;
                gestanteModel.GestanteNroDocumento = gestante.GestanteNroDocumento;
                gestanteModel.Nombres                       = gestante.Nombres;
                gestanteModel.APaterno                      = gestante.APaterno;
                gestanteModel.AMaterno                      = gestante.AMaterno;
                gestanteModel.FechaNacimiento               = gestante.FechaNacimiento;
                gestanteModel.EstablecimientoId             = gestante.EstablecimientoId;
                gestanteModel.Establecimiento               = gestante.Establecimiento.Descripcion;
                gestanteModel.EstablecimientoNotificacionId = gestante.EstablecimientoNotificacionId;
                gestanteModel.EstablecimientoNotificacion   = gestante.EstablecimientoNotificacion.Descripcion;
                gestanteModel.FechaUltimaRegla              = gestante.FechaUltimaRegla;
                gestanteModel.FechaProbableParto            = gestante.FechaProbableParto;
                gestanteModel.PresionSistolicaBase          = gestante.PresionSistolicaBase;
                gestanteModel.PresionDiastolicaBase         = gestante.PresionDiastolicaBase;
                gestanteModel.DiagnosticoIngreso            = gestante.DiagnosticoIngreso;
                gestanteModel.DiagIngreso                   = gestante.DiagIngreso != null ?
                                                              gestante.DiagIngreso.Descripcion : string.Empty;
                gestanteModel.DiagIngresoCie10 = gestante.DiagIngreso != null ?
                                                 gestante.DiagIngreso.Id10 : string.Empty;
                gestanteModel.DiagnosticoIntermedio1 = gestante.DiagnosticoIntermedio1;
                gestanteModel.DiagIntermedio1        = gestante.DiagIntermedio1 != null ?
                                                       gestante.DiagIntermedio1.Descripcion : string.Empty;
                gestanteModel.DiagIntermedio1Cie10 = gestante.DiagIntermedio1 != null ?
                                                     gestante.DiagIntermedio1.Id10 : string.Empty;
                gestanteModel.DiagnosticoIntermedio2 = gestante.DiagnosticoIntermedio2;
                gestanteModel.DiagIntermedio2        = gestante.DiagIntermedio2 != null ?
                                                       gestante.DiagIntermedio2.Descripcion : string.Empty;
                gestanteModel.DiagIntermedio2Cie10 = gestante.DiagIntermedio2 != null ?
                                                     gestante.DiagIntermedio2.Id10 : string.Empty;
                gestanteModel.DiagnosticoEgreso = gestante.DiagnosticoEgreso;
                gestanteModel.DiagEgreso        = gestante.DiagEgreso != null ?
                                                  gestante.DiagEgreso.Descripcion : string.Empty;
                gestanteModel.DiagEgresoCie10 = gestante.DiagEgreso != null ?
                                                gestante.DiagEgreso.Id10 : string.Empty;
                gestanteModel.DistritoId        = gestante.DistritoId;
                gestanteModel.Distrito          = distrito != null ? distrito.Nombre : string.Empty;
                gestanteModel.ProvinciaId       = gestante.ProvinciaId;
                gestanteModel.Provincia         = provincia != null ? provincia.Nombre : string.Empty;
                gestanteModel.RegionId          = gestante.RegionId;
                gestanteModel.Region            = region != null ? region.Nombre : string.Empty;
                gestanteModel.GestanteDireccion = gestante.GestanteDireccion;
                gestanteModel.GestanteEmail     = gestante.GestanteEmail;
                gestanteModel.GestanteTelefono  = gestante.GestanteTelefono;
                gestanteModel.HorarioMensaje    = gestante.HorarioMensaje;
                return(gestanteModel);
            }
            else
            {
                return(null);
            }
        }