void Initialize() throws Exception {
    try {

      departamentos = divisionPoliticaService.getAllDepartamentos();
      catClasif = catalogoService.getClasificacionesFinalRotavirus();
      catResp = catalogoService.getRespuesta();
      registroVacunas = catalogoService.getRegistrosVacuna();
      tipoVacunaRotavirus = catalogoService.getTiposVacunasRotavirus();
      caracteristaHeceses = catalogoService.getCaracteristasHeces();
      gradoDeshidratacions = catalogoService.getGradosDeshidratacion();
      condicionEgresos = catalogoService.getCondicionEgreso();
      salaRotaVirusList = catalogoService.getSalasRotaVirus();

      mapModel = new HashMap<>();

      mapModel.put("departamentos", departamentos);
      mapModel.put("catClasif", catClasif);
      mapModel.put("catResp", catResp);
      mapModel.put("registroVacunas", registroVacunas);
      mapModel.put("tipoVacunaRotavirus", tipoVacunaRotavirus);
      mapModel.put("caracteristaHeceses", caracteristaHeceses);
      mapModel.put("gradoDeshidratacions", gradoDeshidratacions);
      mapModel.put("condicionEgresos", condicionEgresos);
      mapModel.put("salas", salaRotaVirusList);

    } catch (Exception ex) {
      ex.printStackTrace();
      throw ex;
    }
  }
  /**
   * Agrega una notificación de tipo Rotavirus
   *
   * @param json con los datos de la ficha
   * @param request con datos de autenticación
   * @return DaNotificacion agregada
   * @throws Exception
   */
  public DaNotificacion guardarNotificacion(String json, HttpServletRequest request)
      throws Exception {

    logger.debug("Guardando Notificacion");
    DaNotificacion noti = new DaNotificacion();
    Integer personaId = null;
    Integer codSilaisAtencion = null;
    Integer codUnidadAtencion = null;
    String urgente = null;
    JsonObject jObjectJson = new Gson().fromJson(json, JsonObject.class);
    if (jObjectJson.get("personaId") != null
        && !jObjectJson.get("personaId").getAsString().isEmpty()) {
      personaId = jObjectJson.get("personaId").getAsInt();
    }
    if (jObjectJson.get("codSilaisAtencion") != null
        && !jObjectJson.get("codSilaisAtencion").getAsString().isEmpty()) {
      codSilaisAtencion = jObjectJson.get("codSilaisAtencion").getAsInt();
    }
    if (jObjectJson.get("codUnidadAtencion") != null
        && !jObjectJson.get("codUnidadAtencion").getAsString().isEmpty()) {
      codUnidadAtencion = jObjectJson.get("codUnidadAtencion").getAsInt();
    }
    if (jObjectJson.get("urgente") != null && !jObjectJson.get("urgente").getAsString().isEmpty()) {
      urgente = jObjectJson.get("urgente").getAsString();
    }

    if (personaId != null) {
      SisPersona persona = personaService.getPersona(personaId);
      noti.setPersona(persona);
      noti.setFechaRegistro(new Timestamp(new Date().getTime()));
      noti.setCodSilaisAtencion(entidadAdmonService.getSilaisByCodigo(codSilaisAtencion));
      noti.setCodUnidadAtencion(unidadesService.getUnidadByCodigo(codUnidadAtencion));
      long idUsuario = seguridadService.obtenerIdUsuario(request);
      noti.setUsuarioRegistro(usuarioService.getUsuarioById((int) idUsuario));
      noti.setCodTipoNotificacion(catalogoService.getTipoNotificacion("TPNOTI|RTV"));
      noti.setMunicipioResidencia(persona.getMunicipioResidencia());
      noti.setDireccionResidencia(persona.getDireccionResidencia());
      noti.setUrgente(catalogoService.getRespuesta(urgente));

      daNotificacionService.addNotification(noti);
      return noti;
    } else {
      throw new Exception();
    }
  }
  @Test
  public void shouldDeleteCatalogo() {
    Catalogo catalogo = new Catalogo();
    catalogo.setId(12L);
    service.delete(catalogo);

    verify(dao).excluir(captor.capture());
    assertEquals(catalogo.getId(), captor.getValue().getId());
  }
 @Test
 public void shouldSaveWithAListMusic() {
   Long[] ids = new Long[3];
   ids[0] = 1L;
   ids[1] = 2L;
   ids[2] = 3L;
   service.save(ids);
   verify(dao).incluir(captor.capture());
   List<Music> musics = captor.getValue().getMusic();
   assertNotNull("Should set a list of music", musics);
   assertEquals(ids[0], musics.get(0).getId());
   assertEquals(ids[1], musics.get(1).getId());
   assertEquals(ids[2], musics.get(2).getId());
 }
 @RequestMapping(value = "create", method = RequestMethod.GET)
 public ModelAndView initCreateFormTmp(Model model, HttpServletRequest request)
     throws Exception, ParseException {
   logger.debug("Crear un envio de ordenes de examen");
   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, false);
   } catch (Exception e) {
     e.printStackTrace();
     urlValidacion = "404";
   }
   ModelAndView mav = new ModelAndView();
   if (urlValidacion.isEmpty()) {
     mav.setViewName("tomaMx/sendOrders");
     long idUsuario = seguridadService.obtenerIdUsuario(request);
     List<EntidadesAdtvas> entidadesAdtvases = entidadAdmonService.getAllEntidadesAdtvas();
     List<TipoMx> tipoMxList = catalogosService.getTipoMuestra();
     List<Laboratorio> laboratorioList;
     // Si es usuario a nivel central se cargan todas las unidades asociados al SILAIS y municipio
     if (seguridadService.esUsuarioNivelCentral(idUsuario, ConstantsSecurity.SYSTEM_CODE)) {
       laboratorioList = envioMxService.getAllLaboratorios();
     } else {
       laboratorioList =
           envioMxService.getLaboratorios((int) idUsuario, ConstantsSecurity.SYSTEM_CODE);
     }
     mav.addObject("entidades", entidadesAdtvases);
     mav.addObject("tipoMuestra", tipoMxList);
     mav.addObject("laboratorios", laboratorioList);
   } else {
     mav.setViewName(urlValidacion);
   }
   return mav;
 }
  /**
   * * Convierte un JSON a objeto FichaRotavirus
   *
   * @param json con los datos de la ficha
   * @return FichaRotavirus
   * @throws ParseException
   */
  private FichaRotavirus jSonToFichaRotavirus(String json) throws ParseException {
    FichaRotavirus fichaRotavirus = new FichaRotavirus();
    JsonObject jObjectJson = new Gson().fromJson(json, JsonObject.class);
    String idNotificacion;
    String numExpediente = null;
    String codigo = null;
    // datos generales
    String nombreTutorAcompana = null;
    Boolean enGuarderia = null;
    String nombreGuarderia = null;
    // datos cl�nicos
    Date fechaInicioDiarrea = null;
    Integer noEvacuaciones24Hrs = null;
    Respuesta fiebre = null;
    Respuesta vomito = null;
    Integer noVomito24Hrs = null;
    Date fechaInicioVomito = null;
    CaracteristaHeces caracteristaHeces = null;
    String otraCaracteristicaHeces = null;
    GradoDeshidratacion gradoDeshidratacion = null;
    Integer diasHospitalizacion = null;
    Date fechaAlta = null;
    // tratamiento
    Respuesta usoAntibioticoPrevio = null;
    String plan = null;
    Boolean planB = null;
    Boolean planC = null;
    Respuesta antibioticoHospital = null;
    String cualAntibiotico = null;
    Boolean UCI = null;
    Integer diasUCI = null;
    Boolean altaUCIDiarrea = null;
    Date fechaTerminoDiarrea = null;
    Boolean ignoradoFechaTD = null;
    // historia vacunacion
    Respuesta vacunado = null;
    RegistroVacuna registroVacuna = null;
    TipoVacunaRotavirus tipoVacunaRotavirus = null;
    Boolean dosi1 = null;
    Date fechaAplicacionDosis1 = null;
    Boolean dosi2 = null;
    Date fechaAplicacionDosis2 = null;
    Boolean dosi3 = null;
    Date fechaAplicacionDosis3 = null;
    // datos laboratorio
    Respuesta tomoMuestraHeces = null;
    // Clasificaci�n final
    ClasificacionFinalRotavirus clasificacionFinal = null;
    CondicionEgreso condicionEgreso = null;
    // Responsable Informaci�n
    String nombreLlenaFicha = null;
    String epidemiologo = null;
    String nombreTomoMx = null;

    SalaRotaVirus sala = null;
    Date fechaIngreso = null;
    String telefonoTutor = null;

    if (jObjectJson.get("idNotificacion") != null
        && !jObjectJson.get("idNotificacion").getAsString().isEmpty()) {
      idNotificacion = jObjectJson.get("idNotificacion").getAsString();
      fichaRotavirus = rotaVirusService.getFichaById(idNotificacion);
    }

    if (jObjectJson.get("numExpediente") != null
        && !jObjectJson.get("numExpediente").getAsString().isEmpty())
      numExpediente = jObjectJson.get("numExpediente").getAsString();

    if (jObjectJson.get("codigo") != null && !jObjectJson.get("codigo").getAsString().isEmpty())
      codigo = jObjectJson.get("codigo").getAsString();

    if (jObjectJson.get("nombreTutorAcompana") != null
        && !jObjectJson.get("nombreTutorAcompana").getAsString().isEmpty())
      nombreTutorAcompana = jObjectJson.get("nombreTutorAcompana").getAsString();

    if (jObjectJson.get("enGuarderia") != null)
      enGuarderia = jObjectJson.get("enGuarderia").getAsBoolean();

    if (jObjectJson.get("nombreGuarderia") != null
        && !jObjectJson.get("nombreGuarderia").getAsString().isEmpty())
      nombreGuarderia = jObjectJson.get("nombreGuarderia").getAsString();

    if (jObjectJson.get("fechaInicioDiarrea") != null
        && !jObjectJson.get("fechaInicioDiarrea").getAsString().isEmpty())
      fechaInicioDiarrea =
          DateUtil.StringToDate(jObjectJson.get("fechaInicioDiarrea").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("noEvacuaciones24Hrs") != null
        && !jObjectJson.get("noEvacuaciones24Hrs").getAsString().isEmpty())
      noEvacuaciones24Hrs = jObjectJson.get("noEvacuaciones24Hrs").getAsInt();

    if (jObjectJson.get("fiebre") != null && !jObjectJson.get("fiebre").getAsString().isEmpty())
      fiebre = catalogoService.getRespuesta(jObjectJson.get("fiebre").getAsString());

    if (jObjectJson.get("vomito") != null && !jObjectJson.get("vomito").getAsString().isEmpty())
      vomito = catalogoService.getRespuesta(jObjectJson.get("vomito").getAsString());

    if (jObjectJson.get("noVomito24Hrs") != null
        && !jObjectJson.get("noVomito24Hrs").getAsString().isEmpty())
      noVomito24Hrs = jObjectJson.get("noVomito24Hrs").getAsInt();

    if (jObjectJson.get("fechaInicioVomito") != null
        && !jObjectJson.get("fechaInicioVomito").getAsString().isEmpty())
      fechaInicioVomito =
          DateUtil.StringToDate(jObjectJson.get("fechaInicioVomito").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("caracteristaHeces") != null
        && !jObjectJson.get("caracteristaHeces").getAsString().isEmpty())
      caracteristaHeces =
          catalogoService.getCaracteristaHeces(jObjectJson.get("caracteristaHeces").getAsString());

    if (jObjectJson.get("otraCaracteristicaHeces") != null
        && !jObjectJson.get("otraCaracteristicaHeces").getAsString().isEmpty())
      otraCaracteristicaHeces = jObjectJson.get("otraCaracteristicaHeces").getAsString();

    if (jObjectJson.get("gradoDeshidratacion") != null
        && !jObjectJson.get("gradoDeshidratacion").getAsString().isEmpty())
      gradoDeshidratacion =
          catalogoService.getGradoDeshidratacion(
              jObjectJson.get("gradoDeshidratacion").getAsString());

    if (jObjectJson.get("diasHospitalizacion") != null
        && !jObjectJson.get("diasHospitalizacion").getAsString().isEmpty())
      diasHospitalizacion = jObjectJson.get("diasHospitalizacion").getAsInt();

    if (jObjectJson.get("fechaAlta") != null
        && !jObjectJson.get("fechaAlta").getAsString().isEmpty())
      fechaAlta = DateUtil.StringToDate(jObjectJson.get("fechaAlta").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("usoAntibioticoPrevio") != null
        && !jObjectJson.get("usoAntibioticoPrevio").getAsString().isEmpty())
      usoAntibioticoPrevio =
          catalogoService.getRespuesta(jObjectJson.get("usoAntibioticoPrevio").getAsString());

    if (jObjectJson.get("plan") != null && !jObjectJson.get("plan").getAsString().isEmpty()) {
      plan = jObjectJson.get("plan").getAsString();
      if (plan.equals("planB")) planB = true;
      else planC = true;
    }

    if (jObjectJson.get("antibioticoHospital") != null
        && !jObjectJson.get("antibioticoHospital").getAsString().isEmpty())
      antibioticoHospital =
          catalogoService.getRespuesta(jObjectJson.get("antibioticoHospital").getAsString());

    if (jObjectJson.get("cualAntibiotico") != null
        && !jObjectJson.get("cualAntibiotico").getAsString().isEmpty())
      cualAntibiotico = jObjectJson.get("cualAntibiotico").getAsString();

    if (jObjectJson.get("UCI") != null) UCI = jObjectJson.get("UCI").getAsBoolean();

    if (jObjectJson.get("diasUCI") != null && !jObjectJson.get("diasUCI").getAsString().isEmpty())
      diasUCI = jObjectJson.get("diasUCI").getAsInt();

    if (jObjectJson.get("altaUCIDiarrea") != null)
      altaUCIDiarrea = jObjectJson.get("altaUCIDiarrea").getAsBoolean();

    if (jObjectJson.get("fechaTerminoDiarrea") != null
        && !jObjectJson.get("fechaTerminoDiarrea").getAsString().isEmpty())
      fechaTerminoDiarrea =
          DateUtil.StringToDate(jObjectJson.get("fechaTerminoDiarrea").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("ignoradoFTD") != null)
      ignoradoFechaTD = jObjectJson.get("ignoradoFTD").getAsBoolean();

    if (jObjectJson.get("vacunado") != null && !jObjectJson.get("vacunado").getAsString().isEmpty())
      vacunado = catalogoService.getRespuesta(jObjectJson.get("vacunado").getAsString());

    if (jObjectJson.get("registroVacuna") != null
        && !jObjectJson.get("registroVacuna").getAsString().isEmpty())
      registroVacuna =
          catalogoService.getRegistroVacuna(jObjectJson.get("registroVacuna").getAsString());

    if (jObjectJson.get("tipoVacunaRotavirus") != null
        && !jObjectJson.get("tipoVacunaRotavirus").getAsString().isEmpty())
      tipoVacunaRotavirus =
          catalogoService.getTipoVacunaRotavirus(
              jObjectJson.get("tipoVacunaRotavirus").getAsString());

    if (jObjectJson.get("dosi1") != null) dosi1 = jObjectJson.get("dosi1").getAsBoolean();

    if (jObjectJson.get("fechaAplicacionDosis1") != null
        && !jObjectJson.get("fechaAplicacionDosis1").getAsString().isEmpty())
      fechaAplicacionDosis1 =
          DateUtil.StringToDate(
              jObjectJson.get("fechaAplicacionDosis1").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("dosi2") != null) dosi2 = jObjectJson.get("dosi2").getAsBoolean();

    if (jObjectJson.get("fechaAplicacionDosis2") != null
        && !jObjectJson.get("fechaAplicacionDosis2").getAsString().isEmpty())
      fechaAplicacionDosis2 =
          DateUtil.StringToDate(
              jObjectJson.get("fechaAplicacionDosis2").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("dosi3") != null) dosi3 = jObjectJson.get("dosi3").getAsBoolean();

    if (jObjectJson.get("fechaAplicacionDosis3") != null
        && !jObjectJson.get("fechaAplicacionDosis3").getAsString().isEmpty())
      fechaAplicacionDosis3 =
          DateUtil.StringToDate(
              jObjectJson.get("fechaAplicacionDosis3").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("tomoMuestraHeces") != null
        && !jObjectJson.get("tomoMuestraHeces").getAsString().isEmpty())
      tomoMuestraHeces =
          catalogoService.getRespuesta(jObjectJson.get("tomoMuestraHeces").getAsString());

    if (jObjectJson.get("clasificacionFinal") != null
        && !jObjectJson.get("clasificacionFinal").getAsString().isEmpty())
      clasificacionFinal =
          catalogoService.getClasificacionFinalRotavirus(
              jObjectJson.get("clasificacionFinal").getAsString());

    if (jObjectJson.get("condicionEgreso") != null
        && !jObjectJson.get("condicionEgreso").getAsString().isEmpty())
      condicionEgreso =
          catalogoService.getCondicionEgreso(jObjectJson.get("condicionEgreso").getAsString());

    if (jObjectJson.get("nombreLlenaFicha") != null
        && !jObjectJson.get("nombreLlenaFicha").getAsString().isEmpty())
      nombreLlenaFicha = jObjectJson.get("nombreLlenaFicha").getAsString();

    if (jObjectJson.get("epidemiologo") != null
        && !jObjectJson.get("epidemiologo").getAsString().isEmpty())
      epidemiologo = jObjectJson.get("epidemiologo").getAsString();

    if (jObjectJson.get("sala") != null && !jObjectJson.get("sala").getAsString().isEmpty())
      sala = catalogoService.getSalaRotaVirus(jObjectJson.get("sala").getAsString());

    if (jObjectJson.get("fechaIngreso") != null
        && !jObjectJson.get("fechaIngreso").getAsString().isEmpty())
      fechaIngreso =
          DateUtil.StringToDate(jObjectJson.get("fechaIngreso").getAsString(), "dd/MM/yyyy");

    if (jObjectJson.get("nombreTomoMx") != null
        && !jObjectJson.get("nombreTomoMx").getAsString().isEmpty())
      nombreTomoMx = jObjectJson.get("nombreTomoMx").getAsString();

    if (jObjectJson.get("telefonoTutor") != null
        && !jObjectJson.get("telefonoTutor").getAsString().isEmpty())
      telefonoTutor = jObjectJson.get("telefonoTutor").getAsString();

    fichaRotavirus.setNombreTutorAcompana(nombreTutorAcompana);
    fichaRotavirus.setEnGuarderia(enGuarderia);
    fichaRotavirus.setNombreGuarderia(nombreGuarderia);
    fichaRotavirus.setFechaInicioDiarrea(fechaInicioDiarrea);
    fichaRotavirus.setNoEvacuaciones24Hrs(noEvacuaciones24Hrs);
    fichaRotavirus.setFiebre(fiebre);
    fichaRotavirus.setVomito(vomito);
    fichaRotavirus.setNoVomito24Hrs(noVomito24Hrs);
    fichaRotavirus.setFechaInicioVomito(fechaInicioVomito);
    fichaRotavirus.setCaracteristaHeces(caracteristaHeces);
    fichaRotavirus.setOtraCaracteristicaHeces(otraCaracteristicaHeces);
    fichaRotavirus.setGradoDeshidratacion(gradoDeshidratacion);
    fichaRotavirus.setDiasHospitalizacion(diasHospitalizacion);
    fichaRotavirus.setFechaAlta(fechaAlta);
    fichaRotavirus.setUsoAntibioticoPrevio(usoAntibioticoPrevio);
    fichaRotavirus.setPlanB(planB);
    fichaRotavirus.setPlanC(planC);
    fichaRotavirus.setAntibioticoHospital(antibioticoHospital);
    fichaRotavirus.setCualAntibiotico(cualAntibiotico);
    fichaRotavirus.setUCI(UCI);
    fichaRotavirus.setDiasUCI(diasUCI);
    fichaRotavirus.setAltaUCIDiarrea(altaUCIDiarrea);
    fichaRotavirus.setFechaTerminoDiarrea(fechaTerminoDiarrea);
    fichaRotavirus.setIgnoradoFechaTD(ignoradoFechaTD);
    fichaRotavirus.setVacunado(vacunado);
    fichaRotavirus.setRegistroVacuna(registroVacuna);
    fichaRotavirus.setTipoVacunaRotavirus(tipoVacunaRotavirus);
    fichaRotavirus.setDosi1(dosi1);
    fichaRotavirus.setDosi2(dosi2);
    fichaRotavirus.setDosi3(dosi3);
    fichaRotavirus.setFechaAplicacionDosis1(fechaAplicacionDosis1);
    fichaRotavirus.setFechaAplicacionDosis2(fechaAplicacionDosis2);
    fichaRotavirus.setFechaAplicacionDosis3(fechaAplicacionDosis3);
    fichaRotavirus.setTomoMuestraHeces(tomoMuestraHeces);
    fichaRotavirus.setClasificacionFinal(clasificacionFinal);
    fichaRotavirus.setCondicionEgreso(condicionEgreso);
    fichaRotavirus.setNombreLlenaFicha(nombreLlenaFicha);
    fichaRotavirus.setEpidemiologo(epidemiologo);
    fichaRotavirus.setNombreTomoMx(nombreTomoMx);
    fichaRotavirus.setSala(sala);
    fichaRotavirus.setFechaIngreso(fechaIngreso);
    fichaRotavirus.setNumExpediente(numExpediente);
    fichaRotavirus.setCodigo(codigo);
    fichaRotavirus.setTelefonoTutor(telefonoTutor);

    return fichaRotavirus;
  }
  @RequestMapping(
      value = "agregarEnvioOrdenes",
      method = RequestMethod.POST,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  protected void agregarEnvioOrdenes(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String json = "";
    String resultado = "";
    String strOrdenes = "";
    String idEnvio = "";
    int cantOrdenes = 0;
    int cantOrdenesProc = 0;
    try {
      BufferedReader br =
          new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF8"));
      json = br.readLine();
      // Recuperando Json enviado desde el cliente
      JsonObject jsonpObject = new Gson().fromJson(json, JsonObject.class);
      strOrdenes = jsonpObject.get("ordenes").toString();
      cantOrdenes = jsonpObject.get("cantOrdenes").getAsInt();
      String nombreTransporta = jsonpObject.get("nombreTransporta").getAsString();
      Float temperaturaTermo = jsonpObject.get("temperaturaTermo").getAsFloat();
      String laboratorioProcedencia = jsonpObject.get("laboratorioProcedencia").getAsString();

      long idUsuario = seguridadService.obtenerIdUsuario(request);
      Usuarios usuario = usuarioService.getUsuarioById((int) idUsuario);
      // Se obtiene estado enviado a laboratorio
      Laboratorio labDestino = envioMxService.getLaboratorio(laboratorioProcedencia);

      DaEnvioMx envioOrden = new DaEnvioMx();

      envioOrden.setUsarioRegistro(usuario);
      envioOrden.setFechaHoraEnvio(new Timestamp(new Date().getTime()));
      envioOrden.setNombreTransporta(nombreTransporta);
      envioOrden.setTemperaturaTermo(temperaturaTermo);
      // envioOrden.setTiempoEspera(CalcularDiferenciaHorasFechas());
      envioOrden.setLaboratorioDestino(labDestino);

      EstadoMx estadoMx = catalogosService.getEstadoMx("ESTDMX|ENV");

      try {
        idEnvio = envioMxService.addEnvioOrden(envioOrden);
      } catch (Exception ex) {
        resultado = messageSource.getMessage("msg.sending.error.add", null, null);
        resultado = resultado + ". \n " + ex.getMessage();
        ex.printStackTrace();
      }
      if (!idEnvio.isEmpty()) {
        envioOrden.setIdEnvio(idEnvio);

        JsonObject jObjectOrdenes = new Gson().fromJson(strOrdenes, JsonObject.class);
        for (int i = 0; i < cantOrdenes; i++) {
          String idSoli = jObjectOrdenes.get(String.valueOf(i)).getAsString();
          DaTomaMx tomaMxUpd = tomaMxService.getTomaMxById(idSoli);
          tomaMxUpd.setEnvio(envioOrden);
          tomaMxUpd.setEstadoMx(estadoMx);
          tomaMxService.updateTomaMx(tomaMxUpd);
          List<DaSolicitudDx> solicitudDxList =
              tomaMxService.getRutinasByIdMX(tomaMxUpd.getIdTomaMx());
          for (DaSolicitudDx solicitudDx : solicitudDxList) {
            solicitudDx.setLabProcesa(envioOrden.getLaboratorioDestino());
            tomaMxService.updateSolicitudDx(solicitudDx);
          }
          cantOrdenesProc++;
        }
      }
    } catch (Exception ex) {
      logger.error(ex.getMessage(), ex);
      ex.printStackTrace();
      resultado = messageSource.getMessage("msg.sending.error", null, null);
      resultado = resultado + ". \n " + ex.getMessage();

    } finally {
      Map<String, String> map = new HashMap<String, String>();
      map.put("idEnvio", idEnvio);
      map.put("cantOrdenes", String.valueOf(cantOrdenes));
      map.put("cantOrdenesProc", String.valueOf(cantOrdenesProc));
      map.put("mensaje", resultado);
      map.put("ordenes", strOrdenes);
      String jsonResponse = new Gson().toJson(map);
      response.getOutputStream().write(jsonResponse.getBytes());
      response.getOutputStream().close();
    }
  }