forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2214 lines
105 KiB
2214 lines
105 KiB
/*
|
|
* AnalisesDataProvider.java
|
|
*
|
|
* Created on September 20, 2007, 1:44 PM
|
|
*
|
|
* To change this template, choose Tools | Template Manager
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package db;
|
|
|
|
import analiseacidentestrabalho.Acidentado;
|
|
import analiseacidentestrabalho.AnaliseAcidente;
|
|
import analiseacidentestrabalho.Causa;
|
|
import analiseacidentestrabalho.Controle;
|
|
import analiseacidentestrabalho.Correcao;
|
|
import analiseacidentestrabalho.Departamento;
|
|
import analiseacidentestrabalho.Estabelecimento;
|
|
import analiseacidentestrabalho.Medico;
|
|
import analiseacidentestrabalho.Medida;
|
|
import analiseacidentestrabalho.Recomendacao;
|
|
import analiseacidentestrabalho.Seccao;
|
|
import analiseacidentestrabalho.TecnicoSaude;
|
|
import analiseacidentestrabalho.TipoUtilizador;
|
|
import analiseacidentestrabalho.Trabalhador;
|
|
import com.sun.rave.web.ui.model.Option;
|
|
import global.Global;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSetMetaData;
|
|
import java.sql.Statement;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.GregorianCalendar;
|
|
import java.util.HashMap;
|
|
import java.util.ListIterator;
|
|
import java.util.StringTokenizer;
|
|
import utils.Strings;
|
|
import utils.Utils;
|
|
|
|
/**
|
|
*
|
|
* @author lluis
|
|
*/
|
|
public class AnalisesDataProvider {
|
|
// private final static int ESTADO_SEG = 1;
|
|
// private final static int ESTADO_RH1 = 2;
|
|
// private final static int ESTADO_HS = 3;
|
|
// private final static int ESTADO_RH2 = 4;
|
|
// private final static int ESTADO_MEDICO = 5;
|
|
// private final static int ESTADO_ASSINATURAS = 6;
|
|
// private final static int ESTADO_IMPRESSAO = 7;
|
|
// private final static int ESTADO_FECHAR = 8;
|
|
// private final static int ESTADO_CONCLUIDO = 9;
|
|
|
|
private final static int ESTADO_ASSINATURA_1 = 1;
|
|
private final static int ESTADO_ASSINATURA_2 = 2;
|
|
private final static int ESTADO_ASSINATURA_3 = 3;
|
|
|
|
private final static int ESTADO_ASSINATURA_RESP_SEG = 1;
|
|
private final static int ESTADO_ASSINATURA_SEG = 2;
|
|
private final static int ESTADO_ASSINATURA_HS = 3;
|
|
private final static int ESTADO_ASSINATURA_MED = 4;
|
|
private final static int ESTADO_ASSINATURA_RH = 5;
|
|
private final static int ESTADO_ASSINATURA_RESP_RH = 6;
|
|
|
|
|
|
/** Creates a new instance of AnalisesDataProvider */
|
|
public AnalisesDataProvider() {
|
|
}
|
|
|
|
public Controle getControle() throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM controle WHERE id = 1";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
Controle c = new Controle();
|
|
c.setId(new Integer( rs.getInt("id") ));
|
|
c.setAnalise_year( new Integer( rs.getInt( "analise_year" ) ));
|
|
c.setLast_analise_nr( new Integer( rs.getInt( "last_analise_nr" ) ) );
|
|
return c;
|
|
}
|
|
|
|
public void updateControle( Controle c ) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "UPDATE controle SET analise_year = " + c.getAnalise_year() + ", ";
|
|
sql += "last_analise_nr = " + c.getLast_analise_nr() + " ";
|
|
sql += "WHERE id = 1";
|
|
st.execute(sql);
|
|
}
|
|
|
|
|
|
public ArrayList getAnalisesActuaisSegList(Integer estabelecimento_id, String responsavel_loja) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "";
|
|
if(responsavel_loja.matches("y"))
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_SEG + " OR (averiguacao_posterior = 'y' AND averiguacao_obs = '')" + " OR estado = " + Global.ESTADO_ASSINATURA_SEG + ")" + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_SEG + " OR (averiguacao_posterior = 'y' AND averiguacao_obs = ''))" + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesActuaisRhList(Integer estabelecimento_id, String responsavel_loja) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "";
|
|
if(responsavel_loja.matches("y"))
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_RH1 + " OR estado = " + Global.ESTADO_RH2 + " OR estado = " + Global.ESTADO_ASSINATURA_RH + ") AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_RH1 + " OR estado = " + Global.ESTADO_RH2 + ") AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesActuaisHsList(Integer estabelecimento_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_HS + " OR estado = " + Global.ESTADO_FECHAR + " OR estado = " + Global.ESTADO_CONSOLIDACAO + ")" + " AND apagada = 'n' ORDER BY analise_nr"; //AND estabelecimento_id = " + estabelecimento_id;
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
// public ArrayList getAnalisesActuaisMedicoList(Integer estabelecimento_id) throws Exception
|
|
// {
|
|
// Statement st = createStatement();
|
|
// String sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_MEDICINA + " OR (estado = " + Global.ESTADO_ASSINATURAS + " AND estado_assinatura = 2 and ass_med = 'n')) AND estabelecimento_id = " + estabelecimento_id;
|
|
// ResultSet rs = st.executeQuery(sql);
|
|
// ArrayList list = fillAnaliseFields(rs);
|
|
// return list;
|
|
// }
|
|
|
|
|
|
public ArrayList getAnalisesSeguimentoSegList(Integer estabelecimento_id, String responsavel_loja) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
if(responsavel_loja.matches("y"))
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE estabelecimento_id = " + estabelecimento_id + " AND (estado > " + Global.ESTADO_SEG + " AND estado < " + Global.ESTADO_ASSINATURA_SEG + " AND (averiguacao_posterior = 'n' OR (averiguacao_posterior = 'y' AND averiguacao_obs <> '')) OR (estado > " + Global.ESTADO_ASSINATURA_SEG + " AND estado < " + Global.ESTADO_CONCLUIDO + "))" + " AND apagada = 'n' ORDER BY analise_nr";
|
|
// sql ="SELECT * FROM analises_acidentes WHERE estabelecimento_id = " + estabelecimento_id + " AND ((estado = 7 and ass_resp_seg = 'y') OR (estado > 1 AND estado < 7 AND (averiguacao_posterior = 'n' OR (averiguacao_posterior = 'y' AND averiguacao_obs <> ''))) OR (estado > 7 AND estado < 10))";
|
|
}
|
|
else
|
|
{
|
|
// sql ="SELECT * FROM analises_acidentes WHERE estabelecimento_id = " + estabelecimento_id + " AND ((estado > " + Global.ESTADO_SEG + " AND estado < 8 AND (averiguacao_posterior = 'n' OR (averiguacao_posterior = 'y' AND averiguacao_obs <> ''))) OR (estado > 7 AND estado < 10))";
|
|
sql ="SELECT * FROM analises_acidentes WHERE estabelecimento_id = " + estabelecimento_id + " AND ((estado > " + Global.ESTADO_SEG + " AND estado < " + Global.ESTADO_FECHAR + " AND (averiguacao_posterior = 'n' OR (averiguacao_posterior = 'y' AND averiguacao_obs <> ''))) OR estado = " + Global.ESTADO_FECHAR + ")" + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesSeguimentoHsList(Integer estabelecimento_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
sql ="SELECT * FROM analises_acidentes WHERE (estado < " + Global.ESTADO_HS + " OR (estado > " + Global.ESTADO_HS + " AND estado < " + Global.ESTADO_CONSOLIDACAO + ") OR (estado > " + Global.ESTADO_CONSOLIDACAO + " AND estado < " + Global.ESTADO_FECHAR + "))" + " AND apagada = 'n' ORDER BY analise_nr"; // AND estabelecimento_id = " + estabelecimento_id;
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
System.out.println("SEGUIMENTO HS SQL : " + sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesSeguimentoRhList(Integer estabelecimento_id, String responsavel_loja) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
if(responsavel_loja.matches("y"))
|
|
{
|
|
// sql ="SELECT * FROM analises_acidentes WHERE (estado = 1 OR estado = 3 OR estado = 6 OR (estado = 7 AND estado_assinatura < 2) OR estado = 9) AND estabelecimento_id = " + estabelecimento_id;
|
|
// sql ="SELECT * FROM analises_acidentes WHERE (estado = 1 OR estado = 3 OR estado = 6 OR (estado = 7 AND estado_assinatura < 2) OR (estado = 7 and ass_resp_rh = 'y') OR estado = 9) AND estabelecimento_id = " + estabelecimento_id;
|
|
sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_SEG + " OR estado = " + Global.ESTADO_HS + " OR estado = " + Global.ESTADO_CONSOLIDACAO + " OR estado = " + Global.ESTADO_ASSINATURA_SEG + " OR estado = " + Global.ESTADO_FECHAR + ") AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE (estado = " + Global.ESTADO_SEG + " OR estado = " + Global.ESTADO_HS + " OR estado = " + Global.ESTADO_CONSOLIDACAO + " OR estado = " + Global.ESTADO_ASSINATURA_SEG + " OR estado = " + Global.ESTADO_ASSINATURA_RH + " OR estado = " + Global.ESTADO_FECHAR + ") AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesSeguimentoMedList(Integer estabelecimento_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
sql ="SELECT * FROM analises_acidentes WHERE estado < 5 OR (estado = 6 AND estado_assinatura <> 2) OR (estado = 6 AND estado_assinatura = 2 AND ass_med = 'y') OR (estado > 6 AND estado < 9) AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesSeguimentoDirSiprpList() throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
sql ="SELECT * FROM analises_acidentes WHERE estado < " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesSeguimentoDirGerRhList() throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
sql ="SELECT * FROM analises_acidentes WHERE estado < " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesSeguimentoGestorList(Integer estabelecimento_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE estado < " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE estado < " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
return list;
|
|
}
|
|
|
|
|
|
|
|
public ArrayList getAnalisesConcluidasList(Integer estabelecimento_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "";
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql ="SELECT * FROM analises_acidentes WHERE estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getAnalisesConcluidasHsList() throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql ="SELECT * FROM analises_acidentes WHERE estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
|
|
return list;
|
|
}
|
|
|
|
public ArrayList searchAanalisesConcluidasList(Integer estabelecimento_id, Integer ano, Integer mes, Integer dia, String por, String nome) throws Exception
|
|
{
|
|
// Strings strings = new Strings();
|
|
Calendar cal = Calendar.getInstance();
|
|
// ArrayList list = new ArrayList();
|
|
// Dblocal dblocal = new Dblocal();
|
|
// dblocal.connect();
|
|
// Statement stlocal = dblocal.createStatement();
|
|
Statement st = createStatement();
|
|
String sql = "";
|
|
if(por != null)
|
|
{
|
|
por = por.toUpperCase();
|
|
}
|
|
if(nome != null)
|
|
{
|
|
nome = nome.toUpperCase();
|
|
}
|
|
|
|
if( ano != null)
|
|
{
|
|
if( mes != null)
|
|
{
|
|
if( dia != null)
|
|
{
|
|
cal.set( cal.YEAR, ano.intValue() );
|
|
cal.set( cal.MONTH, mes.intValue() -1 );
|
|
cal.set( cal.DATE, dia.intValue() );
|
|
java.sql.Date data_acidente = new java.sql.Date( cal.getTime().getTime() );
|
|
if(por != null && nome != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente = '" + data_acidente + "' AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente = '" + data_acidente + "' AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
else if(por != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente = '" + data_acidente + "' AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente = '" + data_acidente + "' AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
}
|
|
else if( nome != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente = '" + data_acidente + "' AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente = '" + data_acidente + "' AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE data_acidente = '" + data_acidente + "' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE data_acidente = '" + data_acidente + "' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cal.set( cal.YEAR, ano.intValue() );
|
|
cal.set( cal.MONTH, mes.intValue() -1 );
|
|
cal.set( cal.DATE, 1 );
|
|
java.sql.Date data_acidente_from = new java.sql.Date( cal.getTime().getTime() );
|
|
cal.set( cal.DATE, 31 );
|
|
java.sql.Date data_acidente_to = new java.sql.Date( cal.getTime().getTime() );
|
|
if(por != null && nome != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
else if(por != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
}
|
|
else if( nome != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
}
|
|
} // dia
|
|
} // mes
|
|
else
|
|
{
|
|
cal.set( cal.YEAR, ano.intValue() );
|
|
cal.set( cal.MONTH, 0 );
|
|
cal.set( cal.DATE, 1 );
|
|
java.sql.Date data_acidente_from = new java.sql.Date( cal.getTime().getTime() );
|
|
cal.set( cal.MONTH, 11 );
|
|
cal.set( cal.DATE, 31 );
|
|
java.sql.Date data_acidente_to = new java.sql.Date( cal.getTime().getTime() );
|
|
if(por != null && nome != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
else if(por != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
}
|
|
else if( nome != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE data_acidente >= '" + data_acidente_from + "' AND data_acidente <= '" + data_acidente_to + "' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
}
|
|
} // ano
|
|
else
|
|
{
|
|
if(por != null && nome != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND (numero_mecanografico LIKE '%" + por + "%' OR nome LIKE '%" + nome + "%') AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
}
|
|
else if(por != null)
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND numero_mecanografico LIKE '%" + por + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
}
|
|
else if( nome != null )
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes, acidentados WHERE acidentado_id = acidentados.id AND nome LIKE '%" + nome + "%' AND estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if(estabelecimento_id == null)
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE estado = " + Global.ESTADO_CONCLUIDO + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM analises_acidentes WHERE estado = " + Global.ESTADO_CONCLUIDO + " AND estabelecimento_id = " + estabelecimento_id + " AND apagada = 'n' ORDER BY analise_nr";
|
|
}
|
|
|
|
}
|
|
}
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillAnaliseFields(rs);
|
|
|
|
return list;
|
|
}
|
|
|
|
private ArrayList fillAnaliseFields(ResultSet rs) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
Statement stlocal1 = dblocal.createStatement();
|
|
|
|
ArrayList list = new ArrayList();
|
|
if(!rs.isBeforeFirst()) //rs empty
|
|
{
|
|
dblocal.close();
|
|
return list;
|
|
}
|
|
rs.first();
|
|
int nr = 0;
|
|
do
|
|
{
|
|
AnaliseAcidente a = new AnaliseAcidente();
|
|
a.setId(new Integer(rs.getInt("id")));
|
|
|
|
nr++;
|
|
a.setNr(new Integer(nr));
|
|
a.setData_acidente(rs.getDate("data_acidente"));
|
|
a.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
|
|
a.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
|
|
String sqllocal1 = "SELECT nome FROM estabelecimentos WHERE id = " + a.getEstabelecimento_id();
|
|
ResultSet rslocal1 = stlocal1.executeQuery(sqllocal1);
|
|
rslocal1.first();
|
|
a.setNome_estabelecimento( utils.Utils.unicodeToHTML( rslocal1.getString("nome") ) );
|
|
|
|
a.setEstado(new Integer(rs.getInt("estado")));
|
|
a.setEstado_assinatura(new Integer(rs.getInt("estado_assinatura")));
|
|
a.setFase(getFase(a.getEstado().intValue()));
|
|
a.setAcidentado_id(new Integer( rs.getInt("acidentado_id")));
|
|
Acidentado ac = getAcidentado(a.getAcidentado_id());
|
|
String sqllocal = "SELECT nome, numero_mecanografico FROM trabalhadores WHERE id = " + ac.getTrabalhador_id();
|
|
ResultSet rslocal = stlocal.executeQuery(sqllocal);
|
|
rslocal.first();
|
|
String nome_acidentado = rslocal.getString("nome");
|
|
a.setNome_acidentado(utils.Utils.unicodeToHTML(nome_acidentado));
|
|
a.setNumero_mecanografico(rslocal.getString("numero_mecanografico"));
|
|
Object horas_turno = rs.getObject("horas_turno");
|
|
if(horas_turno == null)
|
|
{
|
|
a.setHoras_turno(null);
|
|
}
|
|
else
|
|
{
|
|
a.setHoras_turno(new Integer(rs.getInt("horas_turno")));
|
|
}
|
|
|
|
a.setAveriguador(rs.getString("averiguador"));
|
|
//a.setSeccao(rs.getString("seccao"));
|
|
a.setDepartamento_id( new Integer(rs.getInt("departamento_id")) );
|
|
a.setSeccao_id( new Integer(rs.getInt("seccao_id")) );
|
|
a.setLocal_trabalho(rs.getString("local_trabalho"));
|
|
a.setTarefa(rs.getString("tarefa"));
|
|
a.setSubstancias(rs.getString("substancias"));
|
|
// a.setSuperior_hierarquico(rs.getString("superior_hierarquico"));
|
|
a.setCondicoes(rs.getString("condicoes"));
|
|
a.setTestemunhas(rs.getString("testemunhas"));
|
|
a.setCausas( new Integer(rs.getInt("causas")) );
|
|
a.setDescricao(rs.getString("descricao"));
|
|
a.setConclusoes(rs.getString("conclusoes"));
|
|
a.setAccoes(rs.getString("accoes"));
|
|
a.setAveriguacao_posterior(rs.getString("averiguacao_posterior"));
|
|
a.setAveriguacao_obs(rs.getString("averiguacao_obs"));
|
|
|
|
a.setHora_acidente(rs.getTime("hora_acidente"));
|
|
a.setFormacao_shst(rs.getString("formacao_shst"));
|
|
Object o = rs.getString("formacao_shst_nao_porque");
|
|
if(o == null)
|
|
{
|
|
a.setFormacao_shst_nao_porque("");
|
|
}
|
|
else
|
|
{
|
|
a.setFormacao_shst_nao_porque(rs.getString("formacao_shst_nao_porque"));
|
|
}
|
|
a.setOutros_acidentes_com_colaborador(rs.getString("outros_acidentes_com_colaborador"));
|
|
a.setNr_acidentes_com_colaborador(new Integer(rs.getInt("nr_acidentes_com_colaborador")));
|
|
a.setNr_relatorio_acidente_colaborador1(new Integer(rs.getInt("nr_relatorio_acidente_colaborador1")));
|
|
a.setNr_relatorio_acidente_colaborador2(new Integer(rs.getInt("nr_relatorio_acidente_colaborador2")));
|
|
a.setNr_relatorio_acidente_colaborador3(new Integer(rs.getInt("nr_relatorio_acidente_colaborador3")));
|
|
a.setNr_relatorio_acidente_colaborador4(new Integer(rs.getInt("nr_relatorio_acidente_colaborador4")));
|
|
a.setAcidentes_outros_colaboradores(rs.getString("acidentes_outros_colaboradores"));
|
|
a.setNr_acidentes_outros_colaboradores(new Integer(rs.getInt("nr_acidentes_outros_colaboradores")));
|
|
a.setNr_relatorio_acidente_outros_colaboradores1(new Integer(rs.getInt("nr_relatorio_acidente_outros_colaboradores1")));
|
|
a.setNr_relatorio_acidente_outros_colaboradores2(new Integer(rs.getInt("nr_relatorio_acidente_outros_colaboradores2")));
|
|
a.setNr_relatorio_acidente_outros_colaboradores3(new Integer(rs.getInt("nr_relatorio_acidente_outros_colaboradores3")));
|
|
a.setNr_relatorio_acidente_outros_colaboradores4(new Integer(rs.getInt("nr_relatorio_acidente_outros_colaboradores4")));
|
|
|
|
a.setLesao_cabeca(rs.getString("lesao_cabeca"));
|
|
a.setLesao_pescoco(rs.getString("lesao_pescoco"));
|
|
a.setLesao_tronco(rs.getString("lesao_tronco"));
|
|
a.setLesao_membro_sup_dir(rs.getString("lesao_membro_sup_dir"));
|
|
a.setLesao_membro_sup_esq(rs.getString("lesao_membro_sup_esq"));
|
|
a.setLesao_membro_inf_dir(rs.getString("lesao_membro_inf_dir"));
|
|
a.setLesao_membro_inf_esq(rs.getString("lesao_membro_inf_esq"));
|
|
Object ob = rs.getString("especif1");
|
|
if(ob == null)
|
|
{
|
|
a.setEspecif1("");
|
|
}
|
|
else
|
|
{
|
|
a.setEspecif1(rs.getString("especif1"));
|
|
}
|
|
ob = rs.getString("especif2");
|
|
if(ob == null)
|
|
{
|
|
a.setEspecif2("");
|
|
}
|
|
else
|
|
{
|
|
a.setEspecif2(rs.getString("especif2"));
|
|
}
|
|
ob = rs.getString("especif3");
|
|
if(ob == null)
|
|
{
|
|
a.setEspecif3("");
|
|
}
|
|
else
|
|
{
|
|
a.setEspecif3(rs.getString("especif3"));
|
|
}
|
|
ob = rs.getString("especif4");
|
|
if(ob == null)
|
|
{
|
|
a.setEspecif4("");
|
|
}
|
|
else
|
|
{
|
|
a.setEspecif4(rs.getString("especif4"));
|
|
}
|
|
ob = rs.getString("tipo_lesao");
|
|
if(ob == null)
|
|
{
|
|
a.setTipo_lesao("");
|
|
}
|
|
else
|
|
{
|
|
a.setTipo_lesao(rs.getString("tipo_lesao"));
|
|
}
|
|
a.setTipo_incapacidade(rs.getString("tipo_incapacidade"));
|
|
//a.setCoef_incapacidade(new Integer(( rs.getInt("coef_incapacidade") )));
|
|
a.setCoef_incapacidade((Integer) rs.getObject("coef_incapacidade"));
|
|
a.setData_aval_incapacidade(rs.getDate("data_aval_incapacidade"));
|
|
a.setData_rev_incapacidade(rs.getDate("data_rev_incapacidade"));
|
|
a.setPeriodo_incapacidade_de(rs.getDate("periodo_incapacidade_de"));
|
|
a.setPeriodo_incapacidade_a(rs.getDate("periodo_incapacidade_a"));
|
|
a.setImg_flexao(rs.getString("img_flexao"));
|
|
a.setImg_ext1(rs.getString("img_ext1"));
|
|
a.setImg_ext2(rs.getString("img_ext2"));
|
|
a.setImg_cab2(rs.getString("img_cab2"));
|
|
a.setImg_cab3(rs.getString("img_cab3"));
|
|
a.setImg_ma2(rs.getString("img_ma2"));
|
|
a.setImg_ma3(rs.getString("img_ma3"));
|
|
a.setImg_ma5(rs.getString("img_ma5"));
|
|
a.setImg_ma6(rs.getString("img_ma6"));
|
|
a.setImg_ma8(rs.getString("img_ma8"));
|
|
a.setImg_ma10(rs.getString("img_ma10"));
|
|
a.setImg_rot1(rs.getString("img_rot1"));
|
|
a.setImg_rot2(rs.getString("img_rot2"));
|
|
a.setImg_cab1(rs.getString("img_cab1"));
|
|
a.setImg_cab4(rs.getString("img_cab4"));
|
|
a.setImg_ma1(rs.getString("img_ma1"));
|
|
a.setImg_ma4(rs.getString("img_ma4"));
|
|
a.setImg_ma7(rs.getString("img_ma7"));
|
|
a.setImg_ma9(rs.getString("img_ma9"));
|
|
a.setRestricao_carga(new Integer( rs.getInt("restricao_carga") ));
|
|
a.setRestricao_motricidade(rs.getString("restricao_motricidade"));
|
|
a.setRestricao_conducao(rs.getString("restricao_conducao"));
|
|
a.setRestricao_vibracoes(rs.getString("restricao_vibracoes"));
|
|
ob = rs.getString("restricao_outras");
|
|
if(ob == null)
|
|
{
|
|
a.setRestricao_outras("");
|
|
}
|
|
else
|
|
{
|
|
a.setRestricao_outras(rs.getString("restricao_outras"));
|
|
}
|
|
ob = rs.getString("med_observ");
|
|
if(ob == null)
|
|
{
|
|
a.setMed_observ("");
|
|
}
|
|
else
|
|
{
|
|
a.setMed_observ(rs.getString("med_observ"));
|
|
}
|
|
a.setAnalise_nr(rs.getString("analise_nr"));
|
|
a.setMedico_id(new Integer(rs.getInt("medico_id")));
|
|
a.setTecnico_saude_id(new Integer(rs.getInt("tecnico_saude_id")));
|
|
|
|
//a.setAss_hs(rs.getString("ass_hs"));
|
|
//a.setAss_seg(rs.getString("ass_seg"));
|
|
a.setAss_resp_seg(rs.getString("ass_resp_seg"));
|
|
//a.setAss_med(rs.getString("ass_med"));
|
|
a.setAss_resp_rh(rs.getString("ass_resp_rh"));
|
|
a.setAss_consolidacao(rs.getString("ass_consolidacao"));
|
|
a.setData_consolidacao(rs.getDate("data_consolidacao"));
|
|
a.setData_assinatura_seg(rs.getDate("data_assinatura_seg"));
|
|
a.setData_assinatura_rh(rs.getDate("data_assinatura_rh"));
|
|
a.setNome_resp_seg(rs.getString("nome_resp_seg"));
|
|
a.setNome_resp_rh(rs.getString("nome_resp_rh"));
|
|
a.setCorrecao(rs.getString("correcao"));
|
|
a.setObservacoes_correcao(rs.getString("observacoes_correcao"));
|
|
a.setEstado_antes_correcao( new Integer(rs.getInt("estado_antes_correcao")));
|
|
a.setAss_superior(rs.getString("ass_superior"));
|
|
a.setNome_superior(rs.getString("nome_superior"));
|
|
a.setData_assinatura_superior(rs.getDate("data_assinatura_superior"));
|
|
a.setData_inicio_processo(rs.getDate("data_inicio_processo"));
|
|
a.setNome_resp_consolidacao(rs.getString("nome_resp_consolidacao"));
|
|
//System.out.println("ANALISE NR : " + a.getAnalise_nr());
|
|
a.setRh_fase4(new Integer( rs.getInt("rh_fase4") ));
|
|
list.add(a);
|
|
}while(rs.next());
|
|
dblocal.close();
|
|
|
|
|
|
return list;
|
|
}
|
|
|
|
public ArrayList searchTrabalhador(Integer empresa_id, Integer estabelecimento_id, String nrMecanografico, String nome) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql = "";
|
|
|
|
|
|
// trabalhadores do estabelecimento
|
|
if(nrMecanografico != null)
|
|
{
|
|
if(nome != null)
|
|
{
|
|
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND estabelecimento_id = " + estabelecimento_id + " AND (trabalhadores.nome LIKE '%" + nome + "%' OR LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%') AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND estabelecimento_id = " + estabelecimento_id + " AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(nome != null)
|
|
{
|
|
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND estabelecimento_id = " + estabelecimento_id + " AND trabalhadores.nome LIKE '%" + nome + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
}
|
|
}
|
|
|
|
System.out.println("TRABALHADORES SQL B : " + sql);
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
if(rslocal.isBeforeFirst())
|
|
{
|
|
rslocal.first();
|
|
do
|
|
{
|
|
Trabalhador t = new Trabalhador();
|
|
t.setId(new Integer(rslocal.getInt(1))); //id
|
|
String nome_trab = rslocal.getString(2);
|
|
t.setNome(utils.Utils.unicodeToHTML(nome_trab));
|
|
t.setData_nascimento(rslocal.getDate("data_nascimento"));
|
|
t.setFuncao(rslocal.getString("funcao_proposta"));
|
|
t.setData_admissao(rslocal.getDate("data_admissao"));
|
|
t.setNumero_mecanografico(rslocal.getString("numero_mecanografico"));
|
|
t.setEstabelecimento_id(new Integer( rslocal.getInt(7) ));
|
|
//if(nome != null)
|
|
//{
|
|
t.setEstabelecimento(utils.Utils.unicodeToHTML(rslocal.getString(8)));
|
|
//}
|
|
|
|
list.add(t);
|
|
}while(rslocal.next());
|
|
}
|
|
|
|
|
|
//restantes trabalhadores
|
|
if(nrMecanografico != null)
|
|
{
|
|
if(nome != null)
|
|
{
|
|
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND estabelecimento_id <> " + estabelecimento_id + " AND (trabalhadores.nome LIKE '%" + nome + "%' OR LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%') AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND estabelecimento_id <> " + estabelecimento_id + " AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(nome != null)
|
|
{
|
|
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND estabelecimento_id <> " + estabelecimento_id + " AND trabalhadores.nome LIKE '%" + nome + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
}
|
|
}
|
|
|
|
|
|
// if(nrMecanografico != null)
|
|
// {
|
|
// sql = "SELECT * FROM trabalhadores WHERE LOWER(numero_mecanografico) = '" + nrMecanografico.toLowerCase() + "'";
|
|
// }
|
|
// else if(nome != null)
|
|
// {
|
|
// sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND trabalhadores.nome LIKE '%" + nome + "%'";
|
|
// }
|
|
System.out.println("TRABALHADORES SQL : " + sql);
|
|
rslocal = stlocal.executeQuery(sql);
|
|
if(rslocal.isBeforeFirst())
|
|
{
|
|
rslocal.first();
|
|
do
|
|
{
|
|
Trabalhador t = new Trabalhador();
|
|
t.setId(new Integer(rslocal.getInt(1))); //id
|
|
String nome_trab = rslocal.getString(2);
|
|
t.setNome(utils.Utils.unicodeToHTML(nome_trab));
|
|
t.setData_nascimento(rslocal.getDate("data_nascimento"));
|
|
t.setFuncao(rslocal.getString("funcao_proposta"));
|
|
t.setData_admissao(rslocal.getDate("data_admissao"));
|
|
t.setNumero_mecanografico(rslocal.getString("numero_mecanografico"));
|
|
t.setEstabelecimento_id(new Integer( rslocal.getInt(7) ));
|
|
//if(nome != null)
|
|
//{
|
|
t.setEstabelecimento(utils.Utils.unicodeToHTML(rslocal.getString(8)));
|
|
//}
|
|
|
|
list.add(t);
|
|
}while(rslocal.next());
|
|
}
|
|
dblocal.close();
|
|
return list;
|
|
}
|
|
|
|
public ArrayList searchTrabalhador(Integer empresa_id, String nrMecanografico, String nome) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql = "";
|
|
|
|
StringTokenizer st = null;
|
|
|
|
if(nrMecanografico != null)
|
|
{
|
|
if(nome != null)
|
|
{
|
|
String sql1 = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (";
|
|
String sql2 = "";
|
|
String sql3 = ") AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
st = new StringTokenizer (nome);
|
|
int n = 0;
|
|
while (st.hasMoreTokens ()) {
|
|
if(n > 0)
|
|
{
|
|
sql2 += "AND ";
|
|
}
|
|
sql2 += "trabalhadores.nome LIKE '%" + st.nextToken () + "%' ";
|
|
n++;
|
|
}
|
|
sql = sql1 + sql2 + sql3;
|
|
//sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (trabalhadores.nome LIKE '%" + nome + "%' AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%') AND estabelecimentos.empresa_id = " + empresa_id;
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(nome != null)
|
|
{
|
|
//sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND trabalhadores.nome LIKE '%" + nome + "%' AND estabelecimentos.empresa_id = " + empresa_id;
|
|
String sql1 = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (";
|
|
String sql2 = "";
|
|
String sql3 = ") AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
|
|
st = new StringTokenizer (nome);
|
|
int n = 0;
|
|
while (st.hasMoreTokens ()) {
|
|
if(n > 0)
|
|
{
|
|
sql2 += "AND ";
|
|
}
|
|
sql2 += "trabalhadores.nome LIKE '%" + st.nextToken () + "%' ";
|
|
n++;
|
|
}
|
|
sql = sql1 + sql2 + sql3;
|
|
|
|
}
|
|
}
|
|
|
|
System.out.println("TRABALHADORES SQL A : " + sql);
|
|
// if(nrMecanografico != null)
|
|
// {
|
|
// sql = "SELECT * FROM trabalhadores WHERE LOWER(numero_mecanografico) = '" + nrMecanografico.toLowerCase() + "'";
|
|
// }
|
|
// else if(nome != null)
|
|
// {
|
|
// sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND trabalhadores.nome LIKE '%" + nome + "%'";
|
|
// }
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
do
|
|
{
|
|
Trabalhador t = new Trabalhador();
|
|
t.setId(new Integer(rslocal.getInt(1))); //id
|
|
String nome_trab = rslocal.getString(2);
|
|
t.setNome(utils.Utils.unicodeToHTML(nome_trab));
|
|
t.setData_nascimento(rslocal.getDate("data_nascimento"));
|
|
t.setFuncao(rslocal.getString("funcao_proposta"));
|
|
t.setData_admissao(rslocal.getDate("data_admissao"));
|
|
t.setNumero_mecanografico(rslocal.getString("numero_mecanografico"));
|
|
t.setEstabelecimento_id(new Integer( rslocal.getInt(7) ));
|
|
//if(nome != null)
|
|
//{
|
|
t.setEstabelecimento(utils.Utils.unicodeToHTML(rslocal.getString(8)));
|
|
//}
|
|
|
|
list.add(t);
|
|
}while(rslocal.next());
|
|
dblocal.close();
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getTrabalhadoresListByEstabelecimento(Integer estabelecimento_id) throws Exception
|
|
{
|
|
Utils utils = new Utils();
|
|
ArrayList list = new ArrayList();
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT * FROM trabalhadores WHERE estabelecimento_id = " + estabelecimento_id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
int nr = 0;
|
|
do
|
|
{
|
|
Trabalhador t = new Trabalhador();
|
|
t.setId(new Integer(rslocal.getInt("id")));
|
|
String nome = rslocal.getString("nome");
|
|
t.setNome(utils.unicodeToHTML(nome));
|
|
t.setData_nascimento(rslocal.getDate("data_nascimento"));
|
|
t.setFuncao(rslocal.getString("funcao_proposta"));
|
|
t.setData_admissao(rslocal.getDate("data_admissao"));
|
|
list.add(t);
|
|
}while(rslocal.next());
|
|
dblocal.close();
|
|
|
|
return list;
|
|
}
|
|
|
|
public Trabalhador getTrabalhador(Integer id) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT * FROM trabalhadores WHERE id = " + id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
Trabalhador t = new Trabalhador();
|
|
t.setId(new Integer(rslocal.getInt("id")));
|
|
t.setNome(rslocal.getString("nome"));
|
|
t.setData_nascimento(rslocal.getDate("data_nascimento"));
|
|
t.setFuncao(rslocal.getString("funcao_proposta"));
|
|
t.setData_admissao(rslocal.getDate("data_admissao"));
|
|
dblocal.close();
|
|
return t;
|
|
}
|
|
|
|
public Acidentado getAcidentado(Integer acidentado_id) throws Exception
|
|
{
|
|
Strings strings = new Strings();
|
|
Acidentado a = new Acidentado();
|
|
Statement st = createStatement();
|
|
String sql ="SELECT * FROM acidentados WHERE id = " + acidentado_id;
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
a.setId(new Integer(rs.getInt("id")));
|
|
a.setNome(rs.getString("nome"));
|
|
a.setData_nascimento(rs.getDate("data_nascimento"));
|
|
a.setBilhete_identidade(rs.getString("bilhete_identidade"));
|
|
a.setMorada(rs.getString("morada"));
|
|
a.setCod_postal(rs.getString("cod_postal"));
|
|
a.setLocalidade(rs.getString("localidade"));
|
|
a.setContacto_telefonico(rs.getString("contacto_telefonico"));
|
|
a.setData_admissao(rs.getDate("data_admissao"));
|
|
a.setTurno(rs.getString("turno"));
|
|
String funcao = rs.getString("funcao");
|
|
a.setFuncao(utils.Utils.unicodeToHTML(funcao));
|
|
a.setTrabalhador_id(new Integer(rs.getInt("trabalhador_id")));
|
|
a.setNumero_mecanografico(rs.getString("numero_mecanografico"));
|
|
a.setNome_superior_hierarquico(rs.getString("nome_superior_hierarquico"));
|
|
a.setEmail_superior_hierarquico(rs.getString("email_superior_hierarquico"));
|
|
a.setEstabelecimento_origem(rs.getString("estabelecimento_origem"));
|
|
a.setData_email_superior_hierarquico(rs.getDate("data_email_superior_hierarquico"));
|
|
//a.setAnalise_acidente_id(new Integer("analise_acidente_id"));
|
|
return a;
|
|
}
|
|
|
|
public String getEmpresaNome(Integer empresa_id) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT designacao_social FROM empresas WHERE id = " + empresa_id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
String nome = rslocal.getString("designacao_social");
|
|
dblocal.close();
|
|
return nome;
|
|
}
|
|
|
|
|
|
|
|
public String getEstabelecimentoNome(Integer estabelecimento_id) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT nome FROM estabelecimentos WHERE id = " + estabelecimento_id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
String nome = rslocal.getString("nome");
|
|
dblocal.close();
|
|
return Utils.unicodeToHTML(nome);
|
|
}
|
|
|
|
public String getMedicoNome(Integer medico_id) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT nome FROM medicos WHERE id = " + medico_id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
String nome = rslocal.getString("nome");
|
|
dblocal.close();
|
|
return Utils.unicodeToHTML(nome);
|
|
}
|
|
|
|
public Medico getMedico(Integer id) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT * FROM medicos WHERE id = " + id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
Medico m = new Medico();
|
|
m.setId(new Integer( rslocal.getInt("id") ));
|
|
m.setNome(rslocal.getString("nome"));
|
|
m.setNumero_cedula(rslocal.getString("numero_cedula"));
|
|
dblocal.close();
|
|
return m;
|
|
}
|
|
|
|
public String getTecnicoSaudeNome(Integer tecnico_id) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT nome FROM marcacoes_tecnicos_hst WHERE id = " + tecnico_id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
String nome = rslocal.getString("nome");
|
|
dblocal.close();
|
|
return nome;
|
|
}
|
|
|
|
|
|
public Integer getMaxAcidentadoId()
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "SELECT max(acidentados.id)+1 AS MAXACIDENTADOID FROM acidentados";
|
|
try
|
|
{
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
Integer newId = new Integer(rs.getInt("MAXACIDENTADOID"));
|
|
if(newId.intValue() == 0)
|
|
{
|
|
newId = new Integer(1);
|
|
}
|
|
return newId;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
return new Integer(1);
|
|
}
|
|
}
|
|
|
|
public Integer createAcidentado(Acidentado a) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxAcidentadoId();
|
|
String sql = "INSERT INTO acidentados (id, nome, data_nascimento, bilhete_identidade, morada, cod_postal, localidade, contacto_telefonico, data_admissao, turno, funcao, trabalhador_id, numero_mecanografico, nome_superior_hierarquico, email_superior_hierarquico, estabelecimento_origem, data_email_superior_hierarquico) VALUES (";
|
|
sql += newId + ", '";
|
|
sql += a.getNome() + "', ";
|
|
if(a.getData_nascimento() == null)
|
|
{
|
|
sql += null + ", '";
|
|
}
|
|
else
|
|
{
|
|
sql += "'" + a.getData_nascimento() + "', '";
|
|
}
|
|
//sql += a.getData_nascimento() + "', '";
|
|
sql += a.getBilhete_identidade() + "', '";
|
|
sql += a.getMorada() + "', '";
|
|
sql += a.getCod_postal() + "', '";
|
|
sql += a.getLocalidade() + "', '";
|
|
sql += a.getContacto_telefonico() + "', ";
|
|
if(a.getData_admissao() == null)
|
|
{
|
|
sql += null + ", '";
|
|
}
|
|
else
|
|
{
|
|
sql += "'" + a.getData_admissao() + "', '";
|
|
}
|
|
// sql += a.getData_admissao() + "', '";
|
|
sql += a.getTurno() + "', '";
|
|
sql += a.getFuncao() + "', ";
|
|
sql += a.getTrabalhador_id() + ", '";
|
|
sql += a.getNumero_mecanografico() + "', '";
|
|
sql += a.getNome_superior_hierarquico() + "', '";
|
|
sql += a.getEmail_superior_hierarquico() + "', '";
|
|
sql += a.getEstabelecimento_origem() + "', ";
|
|
if(a.getData_email_superior_hierarquico() == null)
|
|
{
|
|
sql += null + ")";
|
|
}
|
|
else
|
|
{
|
|
sql += "'" + a.getData_email_superior_hierarquico() + "')";
|
|
}
|
|
//sql += a.getAnalise_acidente_id() + ")";
|
|
System.out.println("SQL ACIDENTADO : " + sql);
|
|
st.execute(sql);
|
|
|
|
return newId;
|
|
}
|
|
|
|
public void updateAcidentado(Acidentado a) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "UPDATE acidentados SET nome = '" + a.getNome() + "', ";
|
|
if(a.getData_nascimento() == null)
|
|
{
|
|
sql += "data_nascimento = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_nascimento = '" + a.getData_nascimento() + "', ";
|
|
}
|
|
// sql += "data_nascimento = '" + a.getData_nascimento() + "', ";
|
|
sql += "bilhete_identidade = '" + a.getBilhete_identidade() + "', ";
|
|
sql += "morada = '" + a.getMorada() + "', ";
|
|
sql += "cod_postal = '" + a.getCod_postal() + "', ";
|
|
sql += "localidade = '" + a.getLocalidade() + "', ";
|
|
sql += "contacto_telefonico = '" + a.getContacto_telefonico() + "', ";
|
|
if(a.getData_admissao() == null)
|
|
{
|
|
sql += "data_admissao = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_admissao = '" + a.getData_admissao() + "', ";
|
|
}
|
|
// sql += "data_admissao = '" + a.getData_admissao() + "', ";
|
|
sql += "turno = '" + a.getTurno() + "', ";
|
|
sql += "funcao = '" + a.getFuncao() + "', ";
|
|
sql += "trabalhador_id = " + a.getTrabalhador_id() + ", ";
|
|
sql += "numero_mecanografico = '" + a.getNumero_mecanografico() + "', ";
|
|
sql += "nome_superior_hierarquico = '" + a.getNome_superior_hierarquico() + "', ";
|
|
sql += "email_superior_hierarquico = '" + a.getEmail_superior_hierarquico() + "', ";
|
|
sql += "estabelecimento_origem = '" + a.getEstabelecimento_origem() + "', ";
|
|
if(a.getData_email_superior_hierarquico() == null)
|
|
{
|
|
sql += "data_email_superior_hierarquico = " + null + " ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_email_superior_hierarquico = '" + a.getData_email_superior_hierarquico() + "' ";
|
|
}
|
|
//sql += "analise_acidente_id = '" + a.getAnalise_acidente_id() + " ";
|
|
sql += "WHERE id = " + a.getId();
|
|
System.out.println("SQL UPDATE ACIDENTADO : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public Integer getMaxAnaliseId()
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "SELECT max(analises_acidentes.id)+1 AS MAXANALISEID FROM analises_acidentes";
|
|
try
|
|
{
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
Integer newId = new Integer(rs.getInt("MAXANALISEID"));
|
|
if(newId.intValue() == 0 )
|
|
{
|
|
newId = new Integer(1);
|
|
}
|
|
return newId;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
return new Integer(1);
|
|
}
|
|
}
|
|
|
|
|
|
public AnaliseAcidente createAnalise(AnaliseAcidente a) throws Exception
|
|
{
|
|
Controle c = getControle();
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxAnaliseId();
|
|
|
|
//calc analise_nr
|
|
java.util.Date now = new java.util.Date();
|
|
Calendar cal = new GregorianCalendar();
|
|
cal.setTime(now);
|
|
int ano = cal.get(Calendar.YEAR);
|
|
if(c.getAnalise_year().intValue() != ano)
|
|
{
|
|
c.setAnalise_year(new Integer(ano));
|
|
c.setLast_analise_nr(new Integer(0));
|
|
}
|
|
//String seq_str = new Integer(10000 + newId.intValue()).toString();
|
|
int i_analise_nr = c.getLast_analise_nr().intValue() + 1;
|
|
c.setLast_analise_nr(new Integer(i_analise_nr));
|
|
//updateControle(c);
|
|
String seq_str = new Integer(10000 + i_analise_nr).toString();
|
|
String ano_str = new Integer(ano).toString();
|
|
String analise_nr = ano_str.substring(2) + "/" + seq_str.substring(1);
|
|
a.setAnalise_nr(analise_nr);
|
|
a.setId(newId);
|
|
|
|
String sql = "INSERT INTO analises_acidentes (id, averiguador, data_acidente, acidentado_id, estado, empresa_id, estabelecimento_id, horas_turno, departamento_id, seccao_id, local_trabalho, tarefa, substancias, condicoes, testemunhas, causas, descricao, conclusoes, accoes, hora_acidente, medico_id, tecnico_saude_id, averiguacao_posterior, averiguacao_obs, data_inicio_processo, analise_nr, coef_incapacidade) VALUES (";
|
|
sql += newId + ", '";
|
|
sql += a.getAveriguador() + "', '";
|
|
sql += a.getData_acidente() + "', ";
|
|
sql += a.getAcidentado_id() + ", ";
|
|
sql += a.getEstado() + ", ";
|
|
sql += a.getEmpresa_id() + ", ";
|
|
sql += a.getEstabelecimento_id() + ", ";
|
|
sql += a.getHoras_turno() + ", ";
|
|
sql += a.getDepartamento_id() + ", ";
|
|
sql += a.getSeccao_id() + ", '";
|
|
sql += a.getLocal_trabalho() + "', '";
|
|
sql += a.getTarefa() + "', '";
|
|
sql += a.getSubstancias() + "', '";
|
|
// sql += a.getSuperior_hierarquico() + "', '";
|
|
sql += a.getCondicoes() + "', '";
|
|
sql += a.getTestemunhas() + "', ";
|
|
sql += a.getCausas() + ", '";
|
|
sql += a.getDescricao() + "', '";
|
|
sql += a.getConclusoes() + "', '";
|
|
sql += a.getAccoes() + "', ";
|
|
if(a.getHora_acidente() == null)
|
|
{
|
|
sql += null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "'" + a.getHora_acidente() + "', ";
|
|
}
|
|
|
|
sql += a.getMedico_id() + ", ";
|
|
sql += a.getTecnico_saude_id() + ", '";
|
|
sql += a.getAveriguacao_posterior() + "', '";
|
|
sql += a.getAveriguacao_obs() + "', ";
|
|
if(a.getData_inicio_processo() == null)
|
|
{
|
|
sql += null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "'" + a.getData_inicio_processo() + "', '";
|
|
}
|
|
|
|
sql += analise_nr + "', ";
|
|
sql += null + ")";
|
|
// sql += a.getFormacao_shst() + "', '";
|
|
// sql += a.getFormacao_shst_nao_porque() + "', '";
|
|
// sql += a.getOutros_acidentes_com_colaborador() + "', ";
|
|
// sql += a.getNr_acidentes_com_colaborador() + ", ";
|
|
// sql += a.getNr_relatorio_acidente_colaborador1() + ", ";
|
|
// sql += a.getNr_relatorio_acidente_colaborador2() + ", ";
|
|
// sql += a.getNr_relatorio_acidente_colaborador3() + ", ";
|
|
// sql += a.getNr_relatorio_acidente_colaborador4() + ", '";
|
|
// sql += a.getAcidentes_outros_colaboradores()+ "', ";
|
|
// sql += a.getNr_acidentes_outros_colaboradores()+ ", ";
|
|
// sql += a.getNr_relatorio_acidente_outros_colaboradores1() + ", ";
|
|
// sql += a.getNr_relatorio_acidente_outros_colaboradores2() + ", ";
|
|
// sql += a.getNr_relatorio_acidente_outros_colaboradores3() + ", ";
|
|
// sql += a.getNr_relatorio_acidente_outros_colaboradores4() + ")";
|
|
System.out.println("SQL : " + sql);
|
|
st.execute(sql);
|
|
updateControle(c);
|
|
return a;
|
|
}
|
|
|
|
public void updateAnalise(AnaliseAcidente a) throws Exception
|
|
{
|
|
if(a.getEspecif1().matches("null"))
|
|
{
|
|
a.setEspecif1("");
|
|
}
|
|
if(a.getEspecif2().matches("null"))
|
|
{
|
|
a.setEspecif2("");
|
|
}
|
|
if(a.getEspecif3().matches("null"))
|
|
{
|
|
a.setEspecif3("");
|
|
}
|
|
if(a.getEspecif4().matches("null"))
|
|
{
|
|
a.setEspecif4("");
|
|
}
|
|
if(a.getRestricao_outras().matches("null"))
|
|
{
|
|
a.setRestricao_outras("");
|
|
}
|
|
if(a.getTipo_lesao().matches("null"))
|
|
{
|
|
a.setTipo_lesao("");
|
|
}
|
|
if(a.getMed_observ().matches("null"))
|
|
{
|
|
a.setMed_observ("");
|
|
}
|
|
if(a.getFormacao_shst_nao_porque().matches("null"))
|
|
{
|
|
a.setFormacao_shst_nao_porque("");
|
|
}
|
|
Statement st = createStatement();
|
|
String sql = "UPDATE analises_acidentes SET data_acidente = '" + a.getData_acidente() + "', ";
|
|
sql += "acidentado_id = " + a.getAcidentado_id() + ", ";
|
|
sql += "estado = " + a.getEstado() + ", ";
|
|
sql += "empresa_id = " + a.getEmpresa_id() + ", ";
|
|
sql += "estabelecimento_id = " + a.getEstabelecimento_id() + ", ";
|
|
sql += "horas_turno = " + a.getHoras_turno() + ", ";
|
|
sql += "departamento_id = " + a.getDepartamento_id() + ", ";
|
|
sql += "seccao_id = " + a.getSeccao_id() + ", ";
|
|
sql += "local_trabalho = '" + a.getLocal_trabalho() + "', ";
|
|
sql += "tarefa = '" + a.getTarefa() + "', ";
|
|
sql += "substancias = '" + a.getSubstancias() + "', ";
|
|
// sql += "superior_hierarquico = '" + a.getSuperior_hierarquico() + "', ";
|
|
sql += "condicoes = '" + a.getCondicoes() + "', ";
|
|
sql += "testemunhas = '" + a.getTestemunhas() + "', ";
|
|
sql += "causas = " + a.getCausas() + ", ";
|
|
sql += "descricao = '" + a.getDescricao() + "', ";
|
|
sql += "conclusoes = '" + a.getConclusoes() + "', ";
|
|
sql += "accoes = '" + a.getAccoes() + "', ";
|
|
sql += "averiguador = '" + a.getAveriguador() + "', ";
|
|
if(a.getHora_acidente() == null)
|
|
{
|
|
sql += "hora_acidente = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "hora_acidente = '" + a.getHora_acidente() + "', ";
|
|
}
|
|
|
|
sql += "formacao_shst = '" + a.getFormacao_shst() + "', ";
|
|
sql += "formacao_shst_nao_porque = '" + a.getFormacao_shst_nao_porque() + "', ";
|
|
sql += "outros_acidentes_com_colaborador = '" + a.getOutros_acidentes_com_colaborador() + "', ";
|
|
sql += "nr_acidentes_com_colaborador = " + a.getNr_acidentes_com_colaborador() + ", ";
|
|
sql += "nr_relatorio_acidente_colaborador1 = " + a.getNr_relatorio_acidente_colaborador1() + ", ";
|
|
sql += "nr_relatorio_acidente_colaborador2 = " + a.getNr_relatorio_acidente_colaborador2() + ", ";
|
|
sql += "nr_relatorio_acidente_colaborador3 = " + a.getNr_relatorio_acidente_colaborador3() + ", ";
|
|
sql += "nr_relatorio_acidente_colaborador4 = " + a.getNr_relatorio_acidente_colaborador4() + ", ";
|
|
sql += "acidentes_outros_colaboradores = '" + a.getAcidentes_outros_colaboradores() + "', ";
|
|
sql += "nr_acidentes_outros_colaboradores = " + a.getNr_acidentes_outros_colaboradores() + ", ";
|
|
sql += "nr_relatorio_acidente_outros_colaboradores1 = " + a.getNr_relatorio_acidente_outros_colaboradores1() + ", ";
|
|
sql += "nr_relatorio_acidente_outros_colaboradores2 = " + a.getNr_relatorio_acidente_outros_colaboradores2() + ", ";
|
|
sql += "nr_relatorio_acidente_outros_colaboradores3 = " + a.getNr_relatorio_acidente_outros_colaboradores3() + ", ";
|
|
sql += "nr_relatorio_acidente_outros_colaboradores4 = " + a.getNr_relatorio_acidente_outros_colaboradores4() + ", ";
|
|
sql += "lesao_cabeca = '" + a.getLesao_cabeca() + "', ";
|
|
sql += "lesao_pescoco = '" + a.getLesao_pescoco() + "', ";
|
|
sql += "lesao_tronco = '" + a.getLesao_tronco() + "', ";
|
|
sql += "lesao_membro_sup_dir = '" + a.getLesao_membro_sup_dir() + "', ";
|
|
sql += "lesao_membro_sup_esq = '" + a.getLesao_membro_sup_esq() + "', ";
|
|
sql += "lesao_membro_inf_dir = '" + a.getLesao_membro_inf_dir() + "', ";
|
|
sql += "lesao_membro_inf_esq = '" + a.getLesao_membro_inf_esq() + "', ";
|
|
sql += "especif1 = '" + a.getEspecif1() + "', ";
|
|
sql += "especif2 = '" + a.getEspecif2() + "', ";
|
|
sql += "especif3 = '" + a.getEspecif3() + "', ";
|
|
sql += "especif4 = '" + a.getEspecif4() + "', ";
|
|
sql += "tipo_lesao = '" + a.getTipo_lesao() + "', ";
|
|
sql += "tipo_incapacidade = '" + a.getTipo_incapacidade() + "', ";
|
|
sql += "coef_incapacidade = " + a.getCoef_incapacidade() + ", ";
|
|
if(a.getData_aval_incapacidade() == null)
|
|
{
|
|
sql += "data_aval_incapacidade = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_aval_incapacidade = '" + a.getData_aval_incapacidade() + "', ";
|
|
}
|
|
if(a.getData_rev_incapacidade() == null)
|
|
{
|
|
sql += "data_rev_incapacidade = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_rev_incapacidade = '" + a.getData_rev_incapacidade() + "', ";
|
|
}
|
|
if(a.getPeriodo_incapacidade_de() == null)
|
|
{
|
|
sql += "periodo_incapacidade_de = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "periodo_incapacidade_de = '" + a.getPeriodo_incapacidade_de() + "', ";
|
|
}
|
|
if(a.getPeriodo_incapacidade_a() == null)
|
|
{
|
|
sql += "periodo_incapacidade_a = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "periodo_incapacidade_a = '" + a.getPeriodo_incapacidade_a() + "', ";
|
|
}
|
|
sql += "img_flexao = '" + a.getImg_flexao() + "', ";
|
|
sql += "img_ext1 = '" + a.getImg_ext1() + "', ";
|
|
sql += "img_ext2 = '" + a.getImg_ext2() + "', ";
|
|
sql += "img_cab2 = '" + a.getImg_cab2() + "', ";
|
|
sql += "img_cab3 = '" + a.getImg_cab3() + "', ";
|
|
sql += "img_ma2 = '" + a.getImg_ma2() + "', ";
|
|
sql += "img_ma3 = '" + a.getImg_ma3() + "', ";
|
|
sql += "img_ma5 = '" + a.getImg_ma5() + "', ";
|
|
sql += "img_ma6 = '" + a.getImg_ma6() + "', ";
|
|
sql += "img_ma8 = '" + a.getImg_ma8() + "', ";
|
|
sql += "img_ma10 = '" + a.getImg_ma10() + "', ";
|
|
sql += "img_rot1 = '" + a.getImg_rot1() + "', ";
|
|
sql += "img_rot2 = '" + a.getImg_rot2() + "', ";
|
|
sql += "img_cab1 = '" + a.getImg_cab1() + "', ";
|
|
sql += "img_cab4 = '" + a.getImg_cab4() + "', ";
|
|
sql += "img_ma1 = '" + a.getImg_ma1() + "', ";
|
|
sql += "img_ma4 = '" + a.getImg_ma4() + "', ";
|
|
sql += "img_ma7 = '" + a.getImg_ma7() + "', ";
|
|
sql += "img_ma9 = '" + a.getImg_ma9() + "', ";
|
|
sql += "restricao_carga = " + a.getRestricao_carga() + ", ";
|
|
sql += "restricao_motricidade = '" + a.getRestricao_motricidade() + "', ";
|
|
sql += "restricao_conducao = '" + a.getRestricao_conducao() + "', ";
|
|
sql += "restricao_vibracoes = '" + a.getRestricao_vibracoes() + "', ";
|
|
sql += "restricao_outras = '" + a.getRestricao_outras() + "', ";
|
|
sql += "med_observ = '" + a.getMed_observ() + "', ";
|
|
sql += "estado_assinatura = " + a.getEstado_assinatura() + ", ";
|
|
sql += "tecnico_saude_id = " + a.getTecnico_saude_id() + ", ";
|
|
sql += "medico_id = " + a.getMedico_id() + ", ";
|
|
sql += "ass_consolidacao = '" + a.getAss_consolidacao() + "', ";
|
|
sql += "ass_resp_seg = '" + a.getAss_resp_seg() + "', ";
|
|
sql += "ass_resp_rh = '" + a.getAss_resp_rh() + "', ";
|
|
if(a.getData_consolidacao() == null)
|
|
{
|
|
sql += "data_consolidacao = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_consolidacao = '" + a.getData_consolidacao() + "', ";
|
|
}
|
|
if(a.getData_assinatura_seg() == null)
|
|
{
|
|
sql += "data_assinatura_seg = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_assinatura_seg = '" + a.getData_consolidacao() + "', ";
|
|
}
|
|
if(a.getData_assinatura_rh() == null)
|
|
{
|
|
sql += "data_assinatura_rh = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_assinatura_rh = '" + a.getData_consolidacao() + "', ";
|
|
}
|
|
sql += "nome_resp_seg = '" + a.getNome_resp_seg() + "', ";
|
|
sql += "nome_resp_rh = '" + a.getNome_resp_rh() + "', ";
|
|
sql += "correcao = '" + a.getCorrecao() + "', ";
|
|
sql += "observacoes_correcao = '" + a.getObservacoes_correcao() + "', ";
|
|
sql += "estado_antes_correcao = " + a.getEstado_antes_correcao() + ", ";
|
|
sql += "ass_superior = '" + a.getAss_superior() + "', ";
|
|
sql += "nome_superior = '" + a.getNome_superior() + "', ";
|
|
sql += "averiguacao_posterior = '" + a.getAveriguacao_posterior() + "', ";
|
|
sql += "averiguacao_obs = '" + a.getAveriguacao_obs() + "', ";
|
|
sql += "nome_resp_consolidacao = '" + a.getNome_resp_consolidacao() + "', ";
|
|
if(a.getData_assinatura_superior() == null)
|
|
{
|
|
sql += "data_assinatura_superior = " + null + ", ";
|
|
}
|
|
else
|
|
{
|
|
sql += "data_assinatura_superior = '" + a.getData_assinatura_superior() + "', ";
|
|
}
|
|
sql += "rh_fase4 = " + a.getRh_fase4() + " ";
|
|
sql += "WHERE id = " + a.getId();
|
|
System.out.println("SQL UPDATE : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public void changeEstado(Correcao c) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "UPDATE analises_acidentes SET correcao = '" + c.getCorrecao() + "', estado = " + c.getEstado_corr() + ", estado_antes_correcao = " + c.getEstado_actual() + ", observacoes_correcao = '" + c.getObservacoes() + "' WHERE id = " + c.getAnalise_id();
|
|
st.execute(sql);
|
|
}
|
|
|
|
public Integer getMaxRecomendacaoId()
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "SELECT max(recomendacoes.id)+1 AS MAXRECOMENDACAOID FROM recomendacoes";
|
|
try
|
|
{
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
Integer newId = new Integer(rs.getInt("MAXRECOMENDACAOID"));
|
|
if(newId.intValue() == 0)
|
|
{
|
|
newId = new Integer(1);
|
|
}
|
|
return newId;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
return new Integer(1);
|
|
}
|
|
}
|
|
|
|
public Integer createRecomendacao(Recomendacao r) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxRecomendacaoId();
|
|
String sql = "INSERT INTO recomendacoes (id, analise_id, recomendacao) VALUES (";
|
|
sql += newId + ", ";
|
|
sql += r.getAnalise_id() + ", '";
|
|
sql += r.getRecomendacao() + "')";
|
|
st.execute(sql);
|
|
|
|
return newId;
|
|
}
|
|
|
|
public void updateRecomendacao(Recomendacao r) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "UPDATE recomendacoes SET analise_id = " + r.getAnalise_id() + ", ";
|
|
sql += "recomendacao = '" + r.getRecomendacao() + "' ";
|
|
sql += "WHERE id = " + r.getId();
|
|
//System.out.println("SQL : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public void deleteRecomendacoesByAnalise(Integer analise_id) throws Exception
|
|
{
|
|
System.out.println("DELETE RECOMENDACOES");
|
|
Statement st = createStatement();
|
|
String sql = "DELETE FROM recomendacoes WHERE analise_id = " + analise_id;
|
|
st.execute(sql);
|
|
}
|
|
|
|
public void deleteAnaliseAcidente(Integer analise_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
//String sql = "DELETE FROM analises_acidentes WHERE id = " + analise_id;
|
|
String sql = "UPDATE analises_acidentes SET apagada = 'y' WHERE id = " + analise_id;
|
|
st.execute(sql);
|
|
}
|
|
|
|
public void deleteAcidentado(Integer acidentado_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "DELETE FROM acidentados WHERE id = " + acidentado_id;
|
|
st.execute(sql);
|
|
}
|
|
|
|
public ArrayList getRecomendacoesByAnalise(Integer analiseId) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM recomendacoes WHERE analise_id = " + analiseId;
|
|
//System.out.println("SQL : " + sql);
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
Recomendacao r = new Recomendacao();
|
|
r.setId(new Integer(rs.getInt("id")));
|
|
r.setAnalise_id(new Integer(rs.getInt("analise_id")));
|
|
r.setRecomendacao(rs.getString("recomendacao"));
|
|
list.add(r);
|
|
}while(rs.next());
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public Integer getMaxMedidaId()
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "SELECT max(medidas.id)+1 AS MAXMEDIDAID FROM medidas";
|
|
try
|
|
{
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
Integer newId = new Integer(rs.getInt("MAXMEDIDAID"));
|
|
if(newId.intValue() == 0)
|
|
{
|
|
newId = new Integer(1);
|
|
}
|
|
return newId;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
return new Integer(1);
|
|
}
|
|
}
|
|
|
|
public Integer createMedida(Medida m) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxMedidaId();
|
|
String sql = "INSERT INTO medidas (id, analise_id, medida) VALUES (";
|
|
sql += newId + ", ";
|
|
sql += m.getAnalise_id() + ", '";
|
|
sql += m.getMedida() + "')";
|
|
st.execute(sql);
|
|
|
|
return newId;
|
|
}
|
|
|
|
public void updateMedida(Medida m) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "UPDATE medidas SET analise_id = " + m.getAnalise_id() + ", ";
|
|
sql += "medida = '" + m.getMedida() + "' ";
|
|
sql += "WHERE id = " + m.getId();
|
|
//System.out.println("SQL : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public void deleteMedidasByAnalise(Integer analise_id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "DELETE FROM medidas WHERE analise_id = " + analise_id;
|
|
st.execute(sql);
|
|
}
|
|
|
|
public ArrayList getMedidasByAnalise(Integer analiseId) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM medidas WHERE analise_id = " + analiseId;
|
|
//System.out.println("SQL : " + sql);
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
Medida m = new Medida();
|
|
m.setId(new Integer(rs.getInt("id")));
|
|
m.setAnalise_id(new Integer(rs.getInt("analise_id")));
|
|
m.setMedida(rs.getString("medida"));
|
|
list.add(m);
|
|
}while(rs.next());
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
|
|
|
|
public String getNumeroCedula(Integer medico_id) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
String sql ="SELECT numero_cedula FROM medicos WHERE id = " + medico_id;
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
rslocal.first();
|
|
String numero_cedula = rslocal.getString("numero_cedula");
|
|
dblocal.close();
|
|
return numero_cedula;
|
|
}
|
|
|
|
public String getTipoDescricao(Integer tipo) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "SELECT descricao FROM tipos_utilizadores WHERE tipo = " + tipo;
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
String descricao = rs.getString("descricao");
|
|
return descricao;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getTiposList() throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
TipoUtilizador t = new TipoUtilizador();
|
|
t.setId(new Integer(0));
|
|
t.setTipo(new Integer(0));
|
|
t.setDescricao("");
|
|
list.add(t);
|
|
Statement st = createStatement();
|
|
String sql ="SELECT * FROM tipos_utilizadores WHERE activo = 'y' ORDER BY ordem";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
t = new TipoUtilizador();
|
|
t.setId(new Integer(rs.getInt("id")));
|
|
t.setTipo(new Integer(rs.getInt("tipo")));
|
|
t.setDescricao(rs.getString("descricao"));
|
|
//t.setActivo(rs.getString("activo"));
|
|
//t.setOrdem(new Integer(rs.getInt("ordem")));
|
|
list.add(t);
|
|
}while(rs.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
t = (TipoUtilizador) iter.next();
|
|
|
|
listOptions[i] = new Option(t.getTipo(), t.getDescricao());
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getTiposList(Integer permissao) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
TipoUtilizador t = new TipoUtilizador();
|
|
t.setId(new Integer(0));
|
|
t.setTipo(new Integer(0));
|
|
t.setDescricao("");
|
|
list.add(t);
|
|
Statement st = createStatement();
|
|
String sql ="SELECT * FROM tipos_utilizadores WHERE activo = 'y' ORDER BY ordem";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
t = new TipoUtilizador();
|
|
if(permissao.intValue() == 7) //director rh
|
|
{
|
|
t.setTipo(new Integer(rs.getInt("tipo")));
|
|
if(t.getTipo().intValue() == 1 || t.getTipo().intValue() == 2 || t.getTipo().intValue() == 6) // seguranca || rh || gestor
|
|
{
|
|
t.setId(new Integer(rs.getInt("id")));
|
|
t.setDescricao(rs.getString("descricao"));
|
|
//t.setActivo(rs.getString("activo"));
|
|
//t.setOrdem(new Integer(rs.getInt("ordem")));
|
|
list.add(t);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
t.setId(new Integer(rs.getInt("id")));
|
|
t.setTipo(new Integer(rs.getInt("tipo")));
|
|
t.setDescricao(rs.getString("descricao"));
|
|
//t.setActivo(rs.getString("activo"));
|
|
//t.setOrdem(new Integer(rs.getInt("ordem")));
|
|
list.add(t);
|
|
}
|
|
|
|
}while(rs.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
t = (TipoUtilizador) iter.next();
|
|
|
|
listOptions[i] = new Option(t.getTipo(), t.getDescricao());
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getEstabelecimentosList(Integer empresa_id, Boolean booGestor) throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
ArrayList list = new ArrayList();
|
|
Estabelecimento e = new Estabelecimento();
|
|
e.setId(new Integer(-1));
|
|
|
|
e.setNome("-Seleccionar-");
|
|
|
|
list.add(e);
|
|
if(booGestor.equals(new Boolean(true)))
|
|
{
|
|
e = new Estabelecimento();
|
|
e.setId(new Integer(0));
|
|
e.setNome("-Todos os estabelecimentos-");
|
|
|
|
list.add(e);
|
|
}
|
|
String sql ="SELECT * FROM estabelecimentos WHERE empresa_id = " + empresa_id + " AND inactivo = 'n' ORDER BY nome_plain";
|
|
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
if(rslocal.isBeforeFirst())
|
|
{
|
|
rslocal.first();
|
|
do
|
|
{
|
|
e = new Estabelecimento();
|
|
e.setId(new Integer(rslocal.getInt("id")));
|
|
//e.setNome_plain(rslocal.getString("nome_plain"));
|
|
e.setNome(rslocal.getString("nome"));
|
|
System.out.println("ESTABELECIMENTOAA : " + e.getId().toString() + " - " + e.getNome());
|
|
//t.setActivo(rs.getString("activo"));
|
|
//t.setOrdem(new Integer(rs.getInt("ordem")));
|
|
list.add(e);
|
|
}while(rslocal.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
e = (Estabelecimento) iter.next();
|
|
System.out.println("ESTABELECIMENTOL : " + e.getId().toString() + " - " + e.getNome());
|
|
listOptions[i] = new Option(e.getId(), Utils.unicodeToHTML(e.getNome()));
|
|
i++;
|
|
}
|
|
dblocal.close();
|
|
return listOptions;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getMedicosList() throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
ArrayList list = new ArrayList();
|
|
Medico m = new Medico();
|
|
m.setId(new Integer(0));
|
|
m.setNome("-Seleccionar-");
|
|
list.add(m);
|
|
String sql ="SELECT * FROM medicos WHERE inactivo = 'n'";
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
if(rslocal.isBeforeFirst())
|
|
{
|
|
rslocal.first();
|
|
do
|
|
{
|
|
m = new Medico();
|
|
m.setId(new Integer(rslocal.getInt("id")));
|
|
m.setNome(rslocal.getString("nome"));
|
|
list.add(m);
|
|
}while(rslocal.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
m = (Medico) iter.next();
|
|
|
|
listOptions[i] = new Option(m.getId(), Utils.unicodeToHTML(m.getNome()));
|
|
i++;
|
|
}
|
|
dblocal.close();
|
|
return listOptions;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getTecnicosSaudeList() throws Exception
|
|
{
|
|
Dblocal dblocal = new Dblocal();
|
|
dblocal.connect();
|
|
Statement stlocal = dblocal.createStatement();
|
|
ArrayList list = new ArrayList();
|
|
TecnicoSaude t = new TecnicoSaude();
|
|
t.setId(new Integer(0));
|
|
t.setNome("-Seleccionar-");
|
|
list.add(t);
|
|
String sql ="SELECT * FROM marcacoes_tecnicos_hst WHERE inactivo = 'n'";
|
|
ResultSet rslocal = stlocal.executeQuery(sql);
|
|
if(rslocal.isBeforeFirst())
|
|
{
|
|
rslocal.first();
|
|
do
|
|
{
|
|
t = new TecnicoSaude();
|
|
t.setId(new Integer(rslocal.getInt("id")));
|
|
t.setNome(rslocal.getString("nome"));
|
|
list.add(t);
|
|
}while(rslocal.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
t = (TecnicoSaude) iter.next();
|
|
|
|
listOptions[i] = new Option(t.getId(), Utils.unicodeToHTML(t.getNome()));
|
|
i++;
|
|
}
|
|
dblocal.close();
|
|
return listOptions;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getCausasList() throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Causa c = new Causa();
|
|
c.setId(new Integer(0));
|
|
c.setCausa("-Seleccionar-");
|
|
list.add(c);
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM causas WHERE activa = 'y'";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
c = new Causa();
|
|
c.setId( new Integer(rs.getInt("id")) );
|
|
c.setCausa(rs.getString("causa"));
|
|
list.add(c);
|
|
}while(rs.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
c = (Causa) iter.next();
|
|
|
|
listOptions[i] = new Option(c.getId(), c.getCausa());
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getDepartamentosList() throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Departamento d = new Departamento();
|
|
|
|
d.setId(new Integer(0));
|
|
d.setDescricao("-Todos-");
|
|
list.add(d);
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM departamentos WHERE activo = 'y'";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
d = new Departamento();
|
|
d.setId( new Integer(rs.getInt("id")) );
|
|
d.setDescricao(rs.getString("descricao"));
|
|
list.add(d);
|
|
}while(rs.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
d = (Departamento) iter.next();
|
|
|
|
listOptions[i] = new Option(d.getId(), d.getDescricao());
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public com.sun.rave.web.ui.model.Option[] getSeccoesList(Integer departamento_id) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Seccao s = new Seccao();
|
|
|
|
s.setId(new Integer(0));
|
|
s.setDescricao("-Seleccionar-");
|
|
list.add(s);
|
|
Statement st = createStatement();
|
|
String sql = "";
|
|
if(departamento_id == null) // todos
|
|
{
|
|
sql = "SELECT * FROM seccoes WHERE activo = 'y'";
|
|
}
|
|
else
|
|
{
|
|
sql = "SELECT * FROM seccoes WHERE activo = 'y' AND departamento_id = " + departamento_id;
|
|
}
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
s = new Seccao();
|
|
s.setId( new Integer(rs.getInt("id")) );
|
|
s.setDescricao(rs.getString("descricao"));
|
|
s.setDepartamento_id( new Integer(rs.getInt("departamento_id")) );
|
|
list.add(s);
|
|
}while(rs.next());
|
|
}
|
|
|
|
com.sun.rave.web.ui.model.Option[] listOptions = new com.sun.rave.web.ui.model.Option[list.size()];
|
|
ListIterator iter = list.listIterator();
|
|
int i = 0;
|
|
while(iter.hasNext())
|
|
{
|
|
s = (Seccao) iter.next();
|
|
|
|
listOptions[i] = new Option(s.getId(), s.getDescricao());
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
|
|
|
|
public Causa getCausa(Integer id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
sql ="SELECT * FROM causas WHERE id = " + id;
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
Causa c = new Causa();
|
|
c.setId( new Integer(rs.getInt("id")) );
|
|
c.setCausa(rs.getString("causa"));
|
|
return c;
|
|
}
|
|
|
|
public Seccao getSeccao(Integer id) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
sql ="SELECT * FROM seccoes WHERE id = " + id + " AND activo = 'y'";
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
rs.first();
|
|
Seccao s = new Seccao();
|
|
s.setId( new Integer(rs.getInt("id")) );
|
|
s.setDescricao(rs.getString("descricao"));
|
|
return s;
|
|
}
|
|
|
|
public ArrayList getAnosListFromAnalises() throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Statement st = createStatement();
|
|
String sql = null;
|
|
|
|
sql ="select distinct extract(year from data_acidente) as ano from analises_acidentes where estado = 10 order by ano";
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
Double dAno = new Double(rs.getDouble("ano"));
|
|
Integer iAno = new Integer(dAno.intValue());
|
|
list.add(iAno);
|
|
}while(rs.next());
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
|
|
|
|
private String getFase(int estado)
|
|
{
|
|
if(estado == Global.ESTADO_SEG)
|
|
{
|
|
return "FASE 1 - SEG - ABERTURA";
|
|
}
|
|
else if(estado == Global.ESTADO_RH1)
|
|
{
|
|
return "FASE 2 - RH - ACOMPANHAMENTO";
|
|
}
|
|
else if(estado == Global.ESTADO_HS)
|
|
{
|
|
return "FASE 3 - SIPRP - RECOMENDAÇÕES";
|
|
}
|
|
else if(estado == Global.ESTADO_RH2)
|
|
{
|
|
return "FASE 4 - RH - MEDIDAS + LESÃO";
|
|
}
|
|
// else if(estado == Global.ESTADO_MEDICINA)
|
|
// {
|
|
// return "Medicina";
|
|
// }
|
|
else if(estado == Global.ESTADO_CONSOLIDACAO)
|
|
{
|
|
return "FASE 5 - SIPRP - CONSOLIDAÇÃO";
|
|
}
|
|
// else if(estado == Global.ESTADO_ASSINATURAS)
|
|
// {
|
|
// return "Verificação";
|
|
// }
|
|
// else if(estado == Global.ESTADO_IMPRESSAO)
|
|
// {
|
|
// return "Impressão";
|
|
// }
|
|
else if(estado == Global.ESTADO_ASSINATURA_SEG)
|
|
{
|
|
return "FASE 6 - SEG - VERIFICAÇÃO SEG.";
|
|
}
|
|
else if(estado == Global.ESTADO_ASSINATURA_RH)
|
|
{
|
|
return "FASE 7 - RH - VERIFICAÇÃO RH";
|
|
}
|
|
else if(estado == Global.ESTADO_FECHAR)
|
|
{
|
|
return "FASE 8 - SIPRP - CONCLUSÃO";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public HashMap getMetaData(String table) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "select * from " + table;
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
|
|
HashMap hash = new HashMap();
|
|
int cols = rsmd.getColumnCount();
|
|
|
|
for(int i=0; i < cols; i++)
|
|
{
|
|
String field = rsmd.getColumnName(i + 1);
|
|
int len = rsmd.getPrecision(i+1);
|
|
hash.put(field, new Integer(len));
|
|
}
|
|
return hash;
|
|
}
|
|
|
|
private Statement createStatement()
|
|
{
|
|
Db db = new Db();
|
|
return db.createStatement();
|
|
}
|
|
|
|
}
|