예제 #1
0
  // Recupera todos os alertas do paciente para criar select box
  public String getAlertasPaciente(String codcli) {
    String sql = "";
    String resp = "";
    ResultSet rs = null;
    int cont = 1;

    try {
      // Cria statement para enviar sql
      stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

      sql += "SELECT alertas.*, alerta_paciente.* ";
      sql += "FROM alerta_paciente INNER JOIN alertas ON ";
      sql += "alerta_paciente.cod_alerta = alertas.cod_alerta ";
      sql += "WHERE alerta_paciente.cod_paci='" + codcli + "'";

      // Executa a pesquisa
      rs = stmt.executeQuery(sql);

      // Cabeçalho
      resp += "<table cellspacing=0 cellpadding=0 width='100%'>\n";
      resp += "<tr>\n";
      resp += "  <td class='tdMedium'><b>nº</b></td>\n";
      resp += "  <td class='tdMedium'><b>Alertas</b></td>\n";
      resp += "  <td class='tdMedium'><b>Início</b></td>\n";
      resp += "  <td class='tdMedium'><b>Fim</b></td>\n";
      resp += "  <td class='tdMedium'><b>Excluir</b></td>\n";
      resp += "</tr>\n";

      // Cria looping com a resposta
      while (rs.next()) {
        resp += "<tr>\n";
        resp += "  <td class='tdLight'>Alerta " + cont + "</td>\n";
        resp += "  <td class='tdLight'>" + rs.getString("alerta") + "</td>\n";
        resp += "  <td class='tdLight'>" + Util.formataData(rs.getString("de")) + "&nbsp;</td>\n";
        resp += "  <td class='tdLight'>" + Util.formataData(rs.getString("ate")) + "&nbsp;</td>\n";
        resp +=
            "  <td class='tdLight' align='center'><a title='Excluir alerta' href='Javascript:excluiralerta("
                + rs.getString("cod_alerta_paci")
                + ")'><img src='images/delete.gif' border=0></a></td>\n";
        resp += "</tr>\n";
        cont++;
      }

      resp += "</table>";
      rs.close();
      stmt.close();

      return resp;
    } catch (SQLException e) {
      return "ERRO: " + e.toString() + " SQL=" + sql;
    }
  }
예제 #2
0
  // Insere um alerta existente para um paciente
  public String insereAlertaCombo(String codcli, String cod_alerta, String de, String ate) {
    String sql = "";

    de = "'" + Util.formataDataInvertida(de) + "'";

    if (Util.isNull(ate)) ate = "null";
    else ate = "'" + Util.formataDataInvertida(ate) + "'";

    String nextcod = new Banco().getNext("alerta_paciente", "cod_alerta_paci");

    sql = "INSERT INTO alerta_paciente(cod_alerta_paci, cod_alerta, cod_paci, de, ate) ";
    sql += "VALUES(" + nextcod + "," + cod_alerta + "," + codcli + ",";
    sql += de + "," + ate + ")";

    // Retorno o resultado da execução do script (OK para sucesso)
    return new Banco().executaSQL(sql);
  }
 // ---TODO: This feels like a kludge.  Find a better way to handle it.
 public void respondToEditForm(HttpServletRequest request, HttpSession session) {
   String pid = request.getParameter("productid");
   if (pid != null) {
     try {
       int product_id = Integer.parseInt(pid);
       Product prod = Product.loadProduct(new Integer(product_id));
       if (prod == null) {
         Util.noteError(
             session, "Internal error: No product with ID " + product_id + " was found.");
       } else {
         setProduct(prod);
       }
     } catch (NumberFormatException e) {
       Util.noteError(session, "Internal error: Illegal productid: " + pid);
     }
   }
   super.respondToEditForm(request, session);
   Debug.println("Version.respondToEditForm: Setting 'record' to " + getProduct());
   session.setAttribute("record", getProduct());
 }
예제 #4
0
  // Cria um alerta novo e insere para o paciente
  public String insereAlertaNovo(
      String codcli, String alertanovo, String de, String ate, String cod_empresa) {
    String sql = "";

    de = "'" + Util.formataDataInvertida(de) + "'";

    if (Util.isNull(ate)) ate = "null";
    else ate = "'" + Util.formataDataInvertida(ate) + "'";

    String nextcodalerta = new Banco().getNext("alertas", "cod_alerta");

    sql = "INSERT INTO alertas(cod_alerta, cod_empresa, alerta) ";
    sql += "VALUES(" + nextcodalerta + "," + cod_empresa + ",'" + alertanovo + "')";
    new Banco().executaSQL(sql);

    String nextcod = new Banco().getNext("alerta_paciente", "cod_alerta_paci");

    sql = "INSERT INTO alerta_paciente(cod_alerta_paci, cod_alerta, cod_paci, de, ate) ";
    sql += "VALUES(" + nextcod + "," + nextcodalerta + "," + codcli + ",";
    sql += de + "," + ate + ")";

    return new Banco().executaSQL(sql);
  }
예제 #5
0
 /**
  * Returns canonical link to a bitstream in the item.
  *
  * @param item The DSpace Item that the bitstream is part of
  * @param bitstream The bitstream to link to
  * @returns a String link to the bitstream
  */
 private String makeBitstreamLink(Item item, Bitstream bitstream) {
   String name = bitstream.getName();
   StringBuilder result = new StringBuilder(contextPath);
   result.append("/bitstream/item/").append(String.valueOf(item.getID()));
   // append name although it isn't strictly necessary
   try {
     if (name != null) {
       result.append("/").append(Util.encodeBitstreamName(name, "UTF-8"));
     }
   } catch (UnsupportedEncodingException uee) {
     // just ignore it, we don't have to have a pretty
     // name on the end of the url because the sequence id will
     // locate it. However it means that links in this file might
     // not work....
   }
   result.append("?sequence=").append(String.valueOf(bitstream.getSequenceID()));
   return result.toString();
 }
예제 #6
0
  /* pesquisa: valor a ser pesquisado
   * campo: campo a ser pesquisado
   * ordem: ordem de resposta dos campos
   * numPag: número da página selecionada (paginação)
   * qtdeporpagina: quantidade de registros por página
   * tipo: tipo de pesquisa (exata, substring)
   * cod_empresa: código da empresa logada
   */
  public String[] getAlertas(
      String pesquisa,
      String campo,
      String ordem,
      int numPag,
      int qtdeporpagina,
      int tipo,
      String cod_empresa) {
    String resp[] = {"", ""};
    String sql = "";
    ResultSet rs = null;

    // Limpa espaços em branco antes e depois da pesquisa
    pesquisa = pesquisa.trim();

    sql += "SELECT * FROM alertas ";
    try {
      // Cria statement para enviar sql
      stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

      // Consulta exata
      if (tipo == 1) sql += "WHERE " + campo + "='" + pesquisa + "'";
      // Começando com o valor
      else if (tipo == 2) sql += "WHERE " + campo + " LIKE '" + pesquisa + "%'";
      // Com o valor no meio
      else if (tipo == 3) sql += "WHERE " + campo + " LIKE '%" + pesquisa + "%'";

      // Filtra pela empresa
      sql += " AND cod_empresa=" + cod_empresa;

      // Coloca na ordem
      sql += " ORDER BY " + ordem;

      // Executa a pesquisa
      rs = stmt.executeQuery(sql);

      // Vai para o último registro
      rs.last();

      // Captura a quantidade de linhas
      int numRows = rs.getRow();
      rs.close();

      // Cria paginação das páginas
      resp[1] = Util.criaPaginacao("alertas.jsp", numPag, qtdeporpagina, numRows);

      // Limita para uma quantidade de registros
      sql += " LIMIT " + ((numPag - 1) * qtdeporpagina) + "," + qtdeporpagina;

      // Executa a pesquisa novamente com o limitador
      rs = stmt.executeQuery(sql);

      // Cria looping com a resposta
      while (rs.next()) {
        resp[0] +=
            "<tr onClick=go('alertas.jsp?cod="
                + rs.getString("cod_alerta")
                + "') onMouseOver='trocaCor(this,1);' onMouseOut='trocaCor(this,2);'>";
        resp[0] += "<td width='100%' class='tdLight'>" + rs.getString("alerta") + "&nbsp;</td>\n";
        resp[0] += "</tr>";
      }

      // Se não retornar resposta, montar mensagem de não encontrado
      if (resp[0].equals("")) {
        resp[0] += "<tr>";
        resp[0] += " <td width='600' class='tdLight'>";
        resp[0] += "   Nenhum registro encontrado para a pesquisa";
        resp[0] += " </td>";
        resp[0] += "</tr>";
      }
      rs.close();
      stmt.close();
      return resp;

    } catch (SQLException e) {
      resp[0] = "Erro:" + e.toString();
      return resp;
    }
  }
예제 #7
0
 /**
  * Convert Key # -> _
  *
  * @param key
  * @return converted key
  */
 private String convertKey(String key) {
   String retValue = Util.replace(key, "#", "_");
   return retValue;
 } //  convertKey
 /** @see DatabaseRecord#initializeNewRecord */
 public void initializeNewRecord(HttpServletRequest request, HttpSession session) {
   int product_id = Util.parseInt(Util.getRequiredField(request, session, "productid"), 0);
   if (product_id != 0) {
     setProduct(Product.loadProduct(new Integer(product_id)));
   }
 }
예제 #9
0
  public void load(String queryFile, String modules, String tables)
      throws SQLException, IOException, InterruptedException, ExecutionException {
    Properties properties = new Properties();
    properties.load(new FileInputStream(queryFile));

    Collection<String> keys = properties.stringPropertyNames();

    // Filtering by validating if property starts with any of the module names
    if (!Config.ALL.equalsIgnoreCase(modules)) {
      keys =
          Util.filter(
              keys, "^(" + modules.replaceAll(Config.COMMA_SEPARATOR, Config.MODULE_SUFFIX) + ")");
    }

    // Filtering by table names
    if (!Config.ALL.equalsIgnoreCase(tables)) {
      keys =
          Util.filter(
              keys, "(" + tables.replaceAll(Config.COMMA_SEPARATOR, Config.TABLE_SUFFIX) + ")$");
    }

    logger.info("The final modules and tables that are being considered" + keys.toString());

    ExecutorService executor = Executors.newFixedThreadPool(keys.size() * 3);
    CompletionService completion = new ExecutorCompletionService(executor);

    for (String key : keys) {
      String query = properties.getProperty(key);
      key =
          (key.contains(Config.DOT_SEPARATOR)
              ? key.substring(key.indexOf(Config.DOT_SEPARATOR) + 1)
              : key);

      while (query.contains("[:")) {
        String param = query.substring(query.indexOf("[:") + 2, query.indexOf("]"));

        query = query.replaceFirst("\\[\\:" + param + "\\]", properties.getProperty(param));
      }
      int pages = 1;
      String base = "";
      if (config.srisvoltdb) {
        if (config.isPaginated) {
          try {
            // find count
            String countquery = query;
            if (countquery.contains("<") || countquery.contains(">")) {
              int bracketOpen = countquery.indexOf("<");
              int bracketClose = countquery.indexOf(">");
              String orderCol = countquery.substring(bracketOpen + 1, bracketClose);
              countquery = countquery.replace("<" + orderCol + ">", "");
            }
            VoltTable vcount = client.callProcedure("@AdHoc", countquery).getResults()[0];
            int count = vcount.getRowCount();
            pages = (int) Math.ceil((double) count / config.pageSize);
          } catch (Exception e) {
            System.out.println("Count formation failure!");
          }
        }
        // set up data in order
      } else {
        // find count
        String countquery = query.replace("*", "COUNT(*)");
        Connection conn =
            DriverManager.getConnection(config.jdbcurl, config.jdbcuser, config.jdbcpassword);
        base = conn.getMetaData().getDatabaseProductName().toLowerCase();
        System.out.println("BASE: " + base);
        Statement jdbcStmt =
            conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        if (countquery.contains("<") || countquery.contains(">")) {
          int bracketOpen = countquery.indexOf("<");
          int bracketClose = countquery.indexOf(">");
          String orderCol = countquery.substring(bracketOpen + 1, bracketClose);
          countquery = countquery.replace("<" + orderCol + ">", "");
        }
        ResultSet rcount = jdbcStmt.executeQuery(countquery);
        rcount.next();
        int count = Integer.parseInt(rcount.getArray(1).toString());

        // THIS IF NEEDS A WAY TO DETERMINE IF POSTGRES
        if (base.contains("postgres") && config.isPaginated) {
          pages = (int) Math.ceil((double) count / config.pageSize);
        }
        // set up data in order
      }
      // establish new SourceReaders and DestinationWriters for pages
      SourceReader[] sr = new SourceReader[pages];
      DestinationWriter[] cr = new DestinationWriter[pages];
      for (int i = 0; i < pages; i++) {
        sr[i] = new SourceReader();
        cr[i] = new DestinationWriter();
      }
      Controller processor =
          new Controller<ArrayList<Object[]>>(
              client, sr, cr, query, key.toUpperCase() + ".insert", config, pages, base);
      completion.submit(processor);
    }

    // wait for all tasks to complete.
    for (int i = 0; i < keys.size(); ++i) {
      logger.info(
          "****************"
              + completion.take().get()
              + " completed *****************"); // will block until the next sub task has
      // completed.
    }

    executor.shutdown();
  }