/** * Guardar datos de una notificación rotavirus (agregar o actualizar) * * @param request con los datos de la notificación * @param response con el resultado de la acción * @throws ServletException * @throws IOException */ @RequestMapping( value = "save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = "application/json") protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String json = ""; String resultado = ""; String idNotificacion = ""; try { logger.debug("Guardando datos de Ficha Rotavirus"); BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF8")); json = br.readLine(); FichaRotavirus fichaRotavirus = jSonToFichaRotavirus(json); if (fichaRotavirus.getDaNotificacion() == null) { DaNotificacion noti = guardarNotificacion(json, request); fichaRotavirus.setDaNotificacion(noti); } else { if (fichaRotavirus.getFechaInicioDiarrea() != null) { fichaRotavirus .getDaNotificacion() .setFechaInicioSintomas(fichaRotavirus.getFechaInicioDiarrea()); daNotificacionService.updateNotificacion(fichaRotavirus.getDaNotificacion()); } } rotaVirusService.saveOrUpdate(fichaRotavirus); idNotificacion = fichaRotavirus.getDaNotificacion().getIdNotificacion(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); ex.printStackTrace(); resultado = messageSource.getMessage("msg.error.save.rota", null, null); resultado = resultado + ". \n " + ex.getMessage(); } finally { Map<String, String> map = new HashMap<String, String>(); map.put("mensaje", resultado); map.put("idNotificacion", idNotificacion); String jsonResponse = new Gson().toJson(map); response.getOutputStream().write(jsonResponse.getBytes()); response.getOutputStream().close(); } }
/** * Custom handler to create a new one. * * @param idPerson the ID of the person * @return a ModelMap with the model attributes for the respective view */ @RequestMapping("new/{idPerson}") public ModelAndView newFicha(@PathVariable("idPerson") long idPerson, HttpServletRequest request) throws Exception { String urlValidacion = ""; try { urlValidacion = seguridadService.validarLogin(request); // si la url esta vacia significa que la validaci�n del login fue exitosa if (urlValidacion.isEmpty()) urlValidacion = seguridadService.validarAutorizacionUsuario( request, ConstantsSecurity.SYSTEM_CODE, true); } catch (Exception e) { e.printStackTrace(); urlValidacion = "404"; } ModelAndView mav = new ModelAndView(); if (urlValidacion.isEmpty()) { boolean autorizado = true; FichaRotavirus fichaRotavirus = new FichaRotavirus(); DaNotificacion noti = new DaNotificacion(); Initialize(); SisPersona persona = personaService.getPersona(idPerson); long idUsuario = seguridadService.obtenerIdUsuario(request); // Si es usuario a nivel central se cargan todas las unidades asociados al SILAIS y municipio if (seguridadService.esUsuarioNivelCentral(idUsuario, ConstantsSecurity.SYSTEM_CODE)) { entidades = entidadAdmonService.getAllEntidadesAdtvas(); } else { entidades = seguridadService.obtenerEntidadesPorUsuario( (int) idUsuario, ConstantsSecurity.SYSTEM_CODE); } if (persona != null) { noti.setPersona(persona); fichaRotavirus.setDaNotificacion(noti); Divisionpolitica departamentoProce = divisionPoliticaService.getDepartamentoByMunicipi( fichaRotavirus .getDaNotificacion() .getPersona() .getMunicipioResidencia() .getCodigoNacional()); List<Divisionpolitica> municipiosResi = divisionPoliticaService.getMunicipiosFromDepartamento( departamentoProce.getCodigoNacional()); List<Comunidades> comunidades = comunidadesService.getComunidades( fichaRotavirus .getDaNotificacion() .getPersona() .getMunicipioResidencia() .getCodigoNacional()); mav.addObject("entidades", entidades); mav.addObject("autorizado", autorizado); mav.addObject("departamentoProce", departamentoProce); mav.addObject("municipiosResi", municipiosResi); mav.addObject("comunidades", comunidades); mav.addObject("fichaRotavirus", fichaRotavirus); mav.addAllObjects(mapModel); mav.setViewName("rotavirus/create"); } else { mav.setViewName("404"); } } else { mav.setViewName(urlValidacion); } return mav; }