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.
SIPRP/trunk/AnaliseAcidentesTrabalho/src/java/db/providers/AnalisesDataProvider.java

3400 lines
127 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.providers;
import beans.Acidentado;
import beans.AnaliseAcidente;
import beans.Causa;
import beans.Controle;
import beans.Correcao;
import beans.Departamento;
import beans.Estabelecimento;
import beans.Medico;
import beans.Medida;
import beans.Recomendacao;
import beans.Seccao;
import beans.TecnicoSaude;
import beans.TipoUtilizador;
import beans.Trabalhador;
import com.evolute.entity.evo.EvoDataProvider;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.sql.Expression;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Select2;
import com.evolute.utils.strings.StringPlainer;
import com.sun.rave.web.ui.model.Option;
import db.data.siprp.outer.AcidentadosData;
import db.data.siprp.outer.AnalisesAcidentesData;
import db.data.siprp.outer.CausasData;
import db.data.siprp.outer.ControleData;
import db.data.siprp.outer.MedidasData;
import db.data.siprp.outer.RecomendacoesData;
import global.Global;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.StringTokenizer;
import utils.Strings;
import utils.Utils;
/**
*
* @author lluis
*/
public class AnalisesDataProvider extends GenericDataProvider
{
private static AnalisesDataProvider INSTANCE = null;
private AnalisesDataProvider() throws Exception
{
super();
( ( EvoDataProvider ) getProvider() ).setIsUsingCache( false );
}
public static synchronized AnalisesDataProvider getInstance() throws Exception
{
if ( INSTANCE == null )
{
INSTANCE = new AnalisesDataProvider();
}
return INSTANCE;
}
public Controle getControle() throws Exception
{
ControleData controle = getProvider().load( ControleData.class, 1 );
// 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;
return toControleBean( controle );
}
public Controle getControloByAno( Integer ano ) throws Exception
{
List<ControleData> controles = getProvider().listLoad( ControleData.class, new Object[]{ ano },
new String[]{ ControleData.ANALISE_YEAR_FULL }, new String[]{ ControleData.ID_FULL } );
// Controle c = null;
// Statement st = createStatement();
// String sql = "SELECT * FROM controle WHERE analise_year = " + ano;
// ResultSet rs = st.executeQuery( sql );
//
// if ( rs.isBeforeFirst() )
// {
// rs.first();
// 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;
return toControleBean( controles.get( 0 ) );
}
public Controle createAnoNumeracao( Integer ano ) throws Exception
{
Controle c = new Controle();
// Integer newId = getMaxControleId();
// c.setId( newId );
c.setAnalise_year( ano );
c.setLast_analise_nr( new Integer( 0 ) );
// Statement st = createStatement();
// String sql = "INSERT INTO controle (id, analise_year, last_analise_nr) VALUES (";
// sql += c.getId() + ", ";
// sql += c.getAnalise_year() + ", ";
// sql += c.getLast_analise_nr() + ")";
// st.execute( sql );
ControleData controle = fromControleBean( c, true );
controle.save();
c.setId( controle.getId() );
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 = " + c.getId();
// st.execute( sql );
fromControleBean( c, false ).save();
}
protected ControleData fromControleBean( Controle controleBean, boolean criar )
throws Exception
{
ControleData controle;
if( !criar && controleBean.getId() != null )
{
controle = getProvider().load( ControleData.class, controleBean.getId() );
}
else
{
controle = new ControleData();
controle.setProvider( getProvider() );
}
controle.setAnalise_year( controleBean.getAnalise_year() );
controle.setLast_analise_nr( controleBean.getLast_analise_nr() );
return controle;
}
protected Controle toControleBean( ControleData controle )
{
Controle controleBean = new Controle();
controleBean.setId( controle.getId() );
controleBean.setAnalise_year( controle.getAnalise_year() );
controleBean.setLast_analise_nr( controle.getLast_analise_nr() );
return controleBean;
}
public String getExpression( String nome, Integer estabelecimentoID, String visitaDate, String POR, Integer fromYear )
{
String tables = "analises_acidentes";
String joinConditions = "";
String whereExpression = "analises_acidentes.apagada = 'n' ";
if ( nome != null || POR != null )
{
tables += ", acidentados";
joinConditions += "acidentados.id = analises_acidentes.acidentado_id AND ";
}
if ( nome != null )
{
nome = StringPlainer.convertString( nome.trim() );
nome = nome.replaceAll( " ", "%" );
whereExpression += "AND plain_utf8( acidentados.nome ) LIKE '%" + nome + "%' ";
}
if ( estabelecimentoID != null )
{
// estabelecimento = StringPlainer.convertString( estabelecimento.trim() );
// estabelecimento = estabelecimento.replaceAll( " ", "%" );
// tables += ", estabelecimentos";
// joinConditions += "analises_acidentes.estabelecimento_id = estabelecimentos.id AND ";
// whereExpression += "AND plain_utf8( estabelecimentos.nome ) LIKE '%" + estabelecimento + "%' ";
whereExpression += " AND analises_acidentes.estabelecimento_id = " + estabelecimentoID + " ";
}
if ( visitaDate != null )
{
whereExpression += "AND analises_acidentes.data_acidente = '" + visitaDate + "' ";
}
if ( POR != null )
{
whereExpression += "AND acidentados.numero_mecanografico LIKE '%" + POR.toUpperCase() + "%' ";
}
if( visitaDate == null )
{
whereExpression += " AND EXTRACT( year FROM analises_acidentes.data_acidente ) = " + fromYear + " ";
}
return "SELECT * FROM " + tables + " WHERE " + joinConditions + whereExpression + " ";
}
/*************************************************************************/
/********************************* ACTUAIS *******************************/
/*************************************************************************/
public ArrayList searchAnalisesActualSeg( Integer estabelecimento_id,
String nome, String visitaDate, String POR, String responsavel_loja, Integer fromYear )
throws Exception
{
if ( nome == null && visitaDate == null && POR == null )
{
return getAnalisesActuaisSegList( estabelecimento_id, responsavel_loja, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, null, visitaDate, POR, fromYear );
if ( responsavel_loja.matches( "y" ) )
{
sql += "AND (estado = " + Global.ESTADO_SEG + " OR (averiguacao_posterior = 'y' AND averiguacao_obs = '')" +
" OR estado = " + Global.ESTADO_ASSINATURA_SEG + ")" + " AND estabelecimento_id = " + estabelecimento_id +
" ORDER BY analise_nr";
}
else
{
sql += "AND (estado = " + Global.ESTADO_SEG + " OR (averiguacao_posterior = 'y' AND averiguacao_obs = ''))" +
" AND estabelecimento_id = " + estabelecimento_id +
" ORDER BY analise_nr";
}
System.out.println( "SQL: " + sql );
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesActuaisSegList( Integer estabelecimentoID, String responsavel_loja, Integer fromYear )
throws Exception
{
Expression where = new Field( "analises_acidentes.apagada" ).isEqual( "n" );
where = where.and( new Field( "analises_acidentes.estabelecimento_id" ).isEqual( estabelecimentoID ) );
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM analises_acidentes.data_acidente )" ).isEqual( fromYear ) );
}
Expression states = new Field( "analises_acidentes.estado" ).isEqual( Global.ESTADO_SEG ).or(
new Field( "analises_acidentes.averiguacao_posterior" ).isEqual( "y" ).and( new Field( "analises_acidentes.averiguacao_obs" ).isEqual( "" ) ) );
if ( "y".equals( responsavel_loja ) )
{
states = states.or( new Field( "analises_acidentes.estado" ).isEqual( Global.ESTADO_ASSINATURA_SEG ) );
}
where = where.and( states );
Select2 query = new Select2(
new String[]
{
"analises_acidentes"
},
new Integer[]
{
},
new Expression[]
{
},
new String[]
{
"*"
},
where,
new String[]
{
"analises_acidentes.analise_nr"
},
null, null, null );
// 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 = " + estabelecimentoID +
// " 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 = " + estabelecimentoID +
// " AND apagada = 'n' " +
// "ORDER BY analise_nr";
// }
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList searchAnalisesActualRH( Integer estabelecimento_id,
String nome, String visitaDate, String POR, String responsavel_loja, Integer fromYear )
throws Exception
{
if ( nome == null && visitaDate == null && POR == null )
{
return getAnalisesActuaisRhList( estabelecimento_id, responsavel_loja, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, null, visitaDate, POR, fromYear );
if ( responsavel_loja.matches( "y" ) )
{
sql += "AND (estado = " + Global.ESTADO_RH1 + " OR estado = " + Global.ESTADO_RH2 +
" OR estado = " + Global.ESTADO_ASSINATURA_RH + ") AND estabelecimento_id = " + estabelecimento_id +
" ORDER BY analise_nr";
}
else
{
sql += "AND (estado = " + Global.ESTADO_RH1 + " OR estado = " + Global.ESTADO_RH2 +
") AND estabelecimento_id = " + estabelecimento_id +
" ORDER BY analise_nr";
}
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesActuaisRhList( Integer estabelecimentoID, String responsavel_loja, Integer fromYear )
throws Exception
{
Expression where = new Field( "apagada" ).isEqual( "n" );
where = where.and( new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) );
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM analises_acidentes.data_acidente )" ).isEqual( fromYear ) );
}
Expression or = new Field( "estado" ).isEqual( Global.ESTADO_RH1 ).or( new Field( "estado" ).isEqual( Global.ESTADO_RH2 ) );
if ( "y".equals( responsavel_loja ) )
{
or = or.or( new Field( "estado" ).isEqual( Global.ESTADO_ASSINATURA_RH ) );
}
where = where.and( or );
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analise_nr" },
null, null, null );
// 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 = " + estabelecimentoID +
// " 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 = " + estabelecimentoID +
// " AND apagada = 'n' " +
// "ORDER BY analise_nr";
// }
System.out.println( "\ngetAnalisesActuaisRhList() : " + query.toString() + "\n" );
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList searchAnalisesActuaisHS( Integer estabelecimento_id,
String nome, Integer estabelecimentoID, String visitaDate, String POR, Integer fromYear )
throws Exception
{
if ( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
{
return getAnalisesActuaisHsList( estabelecimento_id, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, estabelecimentoID, visitaDate, POR, fromYear );
sql += "AND (estado = " + Global.ESTADO_HS + " OR estado = " + Global.ESTADO_FECHAR +
" OR estado = " + Global.ESTADO_CONSOLIDACAO + ")" +
" ORDER BY analise_nr";
System.out.println( "\nAnalisesDataProvider . searchAnalisesActuaisHS() :\n\t" + sql );
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesActuaisHsList( Integer estabelecimentoID, Integer fromYear ) throws Exception
{
Expression where = new Field( "apagada" ).isEqual( "n" ).and(
new Field( "estado" ).isEqual( Global.ESTADO_HS ).or( new Field( "estado" ).isEqual( Global.ESTADO_FECHAR ) ).or( new Field( "estado" ).isEqual( Global.ESTADO_CONSOLIDACAO ) ) );
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM data_acidente )" ).isEqual( fromYear ) );
}
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analise_nr" },
null, null, null
);
// 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";
System.out.println( "\nAnalisesDataProvider . getAnalisesActuaisHsList() : " + query.toString() );
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
/*************************************************************************/
/******************************* SEGUIMENTO ******************************/
/*************************************************************************/
public ArrayList searchAnalisesSeguimentoSeg( Integer estabelecimento_id,
String nome, String visitaDate, String POR, String responsavel_loja, Integer fromYear )
throws Exception
{
if ( nome == null && visitaDate == null && POR == null )
{
return getAnalisesSeguimentoSegList( estabelecimento_id, responsavel_loja, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, null, visitaDate, POR, fromYear );
if ( responsavel_loja.matches( "y" ) )
{
sql += "AND 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 + ")" +
")" + " ORDER BY analise_nr";
}
else
{
sql += "AND 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 +
")" + " ORDER BY analise_nr";
}
System.out.println( "SQL: " + sql );
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesSeguimentoSegList( Integer estabelecimento_id, String responsavel_loja, Integer fromYear )
throws Exception
{
String sql = null;
// TODO : change to Select2
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' ";
}
else
{
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' ";
}
if ( fromYear != null )
{
sql += " AND EXTRACT( year FROM analises_acidentes.data_acidente ) = " + fromYear + " ";
}
sql += " ORDER BY analise_nr ";
System.out.println( "\ngetAnalisesSeguimentoSegList() : " + sql + "\n" );
Statement st = createStatement();
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList searchAnalisesSeguimentoHS( Integer estabelecimento_id,
String nome, Integer estabelecimentoID, String visitaDate, String POR, Integer fromYear )
throws Exception
{
if ( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
{
return getAnalisesSeguimentoHsList( estabelecimento_id, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, estabelecimentoID, visitaDate, POR, fromYear );
sql += "AND (" +
"estado < " + Global.ESTADO_HS + " OR (estado > " + Global.ESTADO_HS + " AND estado < " + Global.ESTADO_CONSOLIDACAO + ") " +
"OR (estado > " + Global.ESTADO_CONSOLIDACAO + " AND estado < " + Global.ESTADO_FECHAR + ")" +
")" + " ORDER BY analise_nr";
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesSeguimentoHsList( Integer estabelecimentoID, Integer fromYear )
throws Exception
{
Expression where = new Field( "analises_acidentes.apagada" ).isEqual( "n" );
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM analises_acidentes.data_acidente )" ).isEqual( fromYear ) );
}
where = where.and(
new Field( "estado" ).isLess( Global.ESTADO_HS ).or( new Field( "estado" ).isGreater( Global.ESTADO_HS ).and( new Field( "estado" ).isLess( Global.ESTADO_CONSOLIDACAO ) ) ).or( new Field( "estado" ).isGreater( Global.ESTADO_CONSOLIDACAO ).and( new Field( "estado" ).isLess( Global.ESTADO_FECHAR ) ) ) );
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analises_acidentes.analise_nr" },
null, null, null
);
// 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;
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
System.out.println( "SEGUIMENTO HS SQL : " + query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList searchAnalisesSeguimentoRH( Integer estabelecimento_id,
String nome, String visitaDate, String POR, String responsavel_loja, Integer fromYear )
throws Exception
{
if ( nome == null && visitaDate == null && POR == null )
{
return getAnalisesSeguimentoRhList( estabelecimento_id, responsavel_loja, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, null, visitaDate, POR, fromYear );
if ( responsavel_loja.matches( "y" ) )
{
sql += "AND (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 +
" ORDER BY analise_nr";
}
else
{
sql += "AND ( 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 +
" ORDER BY analise_nr";
}
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesSeguimentoRhList( Integer estabelecimentoID, String responsavel_loja, Integer fromYear )
throws Exception
{
Expression where = new Field( "apagada" ).isEqual( "n" );
where = where.and( new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) );
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM analises_acidentes.data_acidente )" ).isEqual( fromYear ) );
}
Expression or = new Field( "estado" ).isEqual( Global.ESTADO_SEG );
or = or.or( new Field( "estado" ).isEqual( Global.ESTADO_HS ) );
or = or.or( new Field( "estado" ).isEqual( Global.ESTADO_CONSOLIDACAO ) );
or = or.or( new Field( "estado" ).isEqual( Global.ESTADO_ASSINATURA_SEG ) );
or = or.or( new Field( "estado" ).isEqual( Global.ESTADO_FECHAR ) );
if ( !"y".equals( responsavel_loja ) )
{
or = or.or( new Field( "estado" ).isEqual( Global.ESTADO_ASSINATURA_RH ) );
}
where = where.and( or );
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analise_nr" },
null, null, null
);
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList searchAnalisesSeguimentoMedico( Integer estabelecimento_id, String nome, String visitaDate, String POR, Integer fromYear )
throws Exception
{
if ( nome == null && visitaDate == null && POR == null )
{
return getAnalisesSeguimentoMedList( estabelecimento_id, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, null, visitaDate, POR, fromYear );
sql += "AND 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 +
" ORDER BY analise_nr";
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesSeguimentoMedList( Integer estabelecimentoID, Integer fromYear )
throws Exception
{
// 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 = " + estabelecimentoID + " AND apagada = 'n' ";
// if ( fromYear != null )
// {
// sql += " AND EXTRACT( year FROM analises_acidentes.data_acidente ) = " + fromYear + " ";
// }
// sql += " ORDER BY analise_nr ";
Expression where = new Field( "analises_acidentes.apagada" ).isEqual( "n" );
where = where.and( new Field( "analises_acidentes.estabelecimento_id" ).isEqual( estabelecimentoID ) );
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM analises_acidentes.data_acidente )" ).isEqual( fromYear ) );
}
where = where.and(
new Field( "analises_acidentes.estado" ).isLess( 5 ).or(
new Field( "analises_acidentes.estado" ).isEqual( 6 ).and( new Field( "analises_acidentes.estado_assinatura" ).isDifferent( 2 ) ) ).or(
new Field( "analises_acidentes.estado" ).isEqual( 6 ).and( new Field( "analises_acidentes.estado_assinatura" ).isEqual( 2 ) ).and( new Field( "analises_acidentes.ass_med" ).isEqual( "y" ) ) ).or(
new Field( "analises_acidentes.estado" ).isGreater( 6 ).and( new Field( "analises_acidentes.estado" ).isLess( 9 ) ) ) );
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analises_acidentes.analise_nr" },
null, null, null
);
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList searchAnalisesSeguimentoDirSiprp( String nome, Integer estabelecimentoID, String visitaDate, String POR, Integer fromYear )
throws Exception
{
if ( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
{
return getAnalisesSeguimentoDirSiprpList( fromYear );
}
String sql = getExpression( nome, estabelecimentoID, visitaDate, POR, fromYear );
sql += " AND estado < " + Global.ESTADO_CONCLUIDO + " ORDER BY analise_nr";
Statement st = createStatement();
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesSeguimentoDirSiprpList( Integer fromYear ) throws Exception
{
Expression where = new Field( "apagada" ).isEqual( "n" );
where = where.and( new Field( "estado" ).isLess( Global.ESTADO_CONCLUIDO ) );
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM analises_acidentes.data_acidente )" ).isEqual( fromYear ) );
}
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analise_nr" },
null, null, null
);
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList searchAnalisesSeguimentoDirGerRh(
String nome, Integer estabelecimentoID, String visitaDate, String POR, Integer fromYear )
throws Exception
{
return searchAnalisesSeguimentoDirSiprp( nome, estabelecimentoID, visitaDate, POR, fromYear );
}
public ArrayList getAnalisesSeguimentoDirGerRhList( Integer fromYear ) throws Exception
{
return getAnalisesSeguimentoDirSiprpList( fromYear );
}
public ArrayList searchAnalisesSeguimentoGestor( Integer estabelecimento_id,
String nome, Integer estabelecimentoID, String visitaDate, String POR, Integer fromYear )
throws Exception
{
if ( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
{
return getAnalisesSeguimentoGestorList( estabelecimento_id, fromYear );
}
Statement st = createStatement();
String sql = getExpression( nome, estabelecimentoID, visitaDate, POR, fromYear );
sql += "AND estado < " + Global.ESTADO_CONCLUIDO + " ";
if ( estabelecimento_id != null )
{
sql += " AND estabelecimento_id = " + estabelecimento_id + " ";
}
sql += " ORDER BY analise_nr";
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesSeguimentoGestorList( Integer estabelecimentoID, Integer fromYear )
throws Exception
{
Expression where = new Field( "apagada" ).isEqual( "n" );
where = where.and( new Field( "estado" ).isLess( Global.ESTADO_CONCLUIDO ) );
if ( estabelecimentoID != null )
{
where = where.and( new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) );
}
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM analises_acidentes.data_acidente )" ).isEqual( fromYear ) );
}
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analise_nr" },
null, null, null
);
Statement st = createStatement();
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
/*************************************************************************/
/****************************** CONCLUIDOS *******************************/
/*************************************************************************/
public ArrayList getAnalisesConcluidasList( Integer estabelecimentoID, Integer fromYear ) throws Exception
{
Statement st = createStatement();
Expression where = new Field( "estado" ).isEqual( Global.ESTADO_CONCLUIDO );
where = where.and( new Field( "apagada" ).isEqual( "n" ) );
if ( estabelecimentoID != null )
{
where = where.and( new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ) );
}
if ( fromYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM data_acidente )" ).isEqual( fromYear ) );
}
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "*" },
where,
new String[] { "analise_nr" },
null, null, null
);
System.out.println( "\ngetAnalisesConcluidasList() : " + query.toString() + "\n" );
ResultSet rs = st.executeQuery( query.toString() );
ArrayList list = fillAnaliseFields( rs );
return list;
}
public ArrayList getAnalisesConcluidasHsList( Integer fromYear ) throws Exception
{
return getAnalisesConcluidasList( null, fromYear );
}
public ArrayList searchAnalisesConcluidasList( Integer estabelecimento_id,
Integer ano, Integer mes, Integer dia, String POR, String nome, Integer estabelecimentoID, Integer fromYear )
throws Exception
{
String sql = null;
sql = getExpression( nome, estabelecimentoID, null, POR, ano == null ? fromYear : ano );
if ( estabelecimento_id != null && estabelecimento_id.intValue() > 0 )
{
sql += "AND analises_acidentes.estabelecimento_id = " + estabelecimento_id + " ";
}
if ( ano != null )
{
final DateFormat D_F = new SimpleDateFormat( "yyyy-MM-dd" );
Calendar calendar_from = Calendar.getInstance();
Calendar calendar_to = Calendar.getInstance();
calendar_from.set( Calendar.YEAR, ano.intValue() );
calendar_from.set( Calendar.MONTH, 0 );
calendar_from.set( Calendar.DATE, 1 );
calendar_to.set( Calendar.YEAR, ano.intValue() );
calendar_to.set( Calendar.MONTH, 11 );
calendar_to.set( Calendar.DATE, 31 );
if ( mes != null )
{
calendar_from.set( Calendar.MONTH, mes.intValue() - 1 );
calendar_to.set( Calendar.MONTH, mes.intValue() - 1 );
if ( dia != null )
{
calendar_from.set( Calendar.DATE, dia.intValue() );
calendar_to.set( Calendar.DATE, dia.intValue() );
}
else
{
calendar_from.set( Calendar.DATE, 1 );
calendar_to.set( Calendar.DATE, 31 );
}
}
else
{
calendar_from.set( Calendar.MONTH, 0 );
calendar_to.set( Calendar.MONTH, 11 );
}
Date dateStart = calendar_from.getTime();
Date dateEnd = calendar_to.getTime();
if ( dateStart.compareTo( dateEnd ) == 0 )
{
sql += "AND analises_acidentes.data_acidente = '" + D_F.format( dateStart ) + "' ";
}
else
{
sql += "AND ( analises_acidentes.data_acidente >= '" + D_F.format( dateStart ) + "' AND analises_acidentes.data_acidente <= '" + D_F.format( dateEnd ) + "' ) ";
}
}
sql += " AND estado = " + Global.ESTADO_CONCLUIDO + " ";
// if search parameters are null, account with fromYear
if ( ano == null && mes == null && dia == null && POR == null && nome == null && estabelecimentoID == null && fromYear != null )
{
sql += " AND EXTRACT( year FROM analises_acidentes.data_acidente ) = " + fromYear + " ";
}
sql += " ORDER BY analises_acidentes.analise_nr ASC ";
System.out.println( "CONCLUIDAS SQL: " + sql );
Statement st = createStatement();
ResultSet rs = st.executeQuery( sql );
ArrayList list = fillAnaliseFields( rs );
return list;
}
//by lino
// public ArrayList searchAanalisesConcluidasList( Integer estabelecimento_id,
// Integer ano, Integer mes, Integer dia, String por, String nome, String estabelecimento )
// throws Exception
// {
// Calendar cal = Calendar.getInstance();
// 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
{
return list;
}
Statement stlocal = createLocalStatement();
Statement stlocal1 = createLocalStatement();
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 );
String nome_acidentado = "";
String numero_mecanografico = "";
if ( rslocal.first() )
{
nome_acidentado = rslocal.getString( "nome" );
numero_mecanografico = rslocal.getString( "numero_mecanografico" );
}
a.setNome_acidentado( utils.Utils.unicodeToHTML( nome_acidentado ) );
a.setNumero_mecanografico( 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" ) ) );
a.setConcluido_por_desactivacao( rs.getBoolean( "concluido_por_desactivacao" ) );
a.setData_desactivacao( rs.getDate( "data_desactivacao" ) );
a.setComentario_desactivacao( rs.getString( "comentario_desactivacao" ) );
list.add( a );
}
while ( rs.next() );
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();
Statement stlocal = createLocalStatement();
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() );
}
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();
Statement stlocal = createLocalStatement();
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() );
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();
Statement stlocal = createLocalStatement();
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() );
return list;
}
public Trabalhador getTrabalhador( Integer id ) throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
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" ) );
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();
Statement stlocal = createLocalStatement();
String sql = "SELECT designacao_social FROM empresas WHERE id = " + empresa_id;
ResultSet rslocal = stlocal.executeQuery( sql );
rslocal.first();
String nome = rslocal.getString( "designacao_social" );
return nome;
}
public String getEstabelecimentoNome( Integer estabelecimento_id ) throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
String sql = "SELECT nome FROM estabelecimentos WHERE id = " + estabelecimento_id;
ResultSet rslocal = stlocal.executeQuery( sql );
String nome = "";
if ( rslocal.first() )
{
nome = rslocal.getString( "nome" );
}
return Utils.unicodeToHTML( nome );
}
public String getMedicoNome( Integer medico_id ) throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
String sql = "SELECT nome FROM medicos WHERE id = " + medico_id;
ResultSet rslocal = stlocal.executeQuery( sql );
rslocal.first();
String nome = rslocal.getString( "nome" );
return Utils.unicodeToHTML( nome );
}
public Medico getMedico( Integer id ) throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
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" ) );
return m;
}
public String getTecnicoSaudeNome( Integer tecnico_id ) throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
String sql = "SELECT nome FROM marcacoes_tecnicos_hst WHERE id = " + tecnico_id;
ResultSet rslocal = stlocal.executeQuery( sql );
rslocal.first();
String nome = rslocal.getString( "nome" );
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 );
AcidentadosData acidentado = fromAcidentadoBean( a, true );
acidentado.save();
return acidentado.getId();
}
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 );
AcidentadosData acidentado = fromAcidentadoBean( a, false );
acidentado.save();
}
public Integer getMaxControleId()
{
Statement st = createStatement();
String sql = "SELECT max(controle.id)+1 AS MAXCONTROLEID FROM controle";
try
{
ResultSet rs = st.executeQuery( sql );
rs.first();
Integer newId = new Integer( rs.getInt( "MAXCONTROLEID" ) );
if ( newId.intValue() == 0 )
{
newId = new Integer( 1 );
}
return newId;
}
catch ( Exception ex )
{
return new Integer( 1 );
}
}
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
{
// Integer newId = getMaxAnaliseId();
//calc analise_nr
java.util.Date data_acidente = new java.util.Date( a.getData_acidente().getTime() );
Calendar cal = new GregorianCalendar();
cal.setTime( data_acidente );
int ano = cal.get( Calendar.YEAR );
Controle c = getControloByAno( new Integer( ano ) );
if ( c == null )
{
c = createAnoNumeracao( new Integer( ano ) );
}
// 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 );
AnalisesAcidentesData analise = fromAnaliseAcidenteBean( a, true );
analise.save();
a.setId( analise.getId() );
// Insert insert = new Insert( "analises_acidentes", new Assignment[] {
//// new Assignment( new Field( "id" ), newId ),
// new Assignment( new Field( "averiguador" ), a.getAveriguador() ),
// new Assignment( new Field( "data_acidente" ), a.getData_acidente() ),
// new Assignment( new Field( "acidentado_id" ), a.getAcidentado_id() ),
// new Assignment( new Field( "estado" ), a.getEstado() ),
// new Assignment( new Field( "empresa_id" ), a.getEmpresa_id() ),
// new Assignment( new Field( "estabelecimento_id" ), a.getEstabelecimento_id() ),
// new Assignment( new Field( "horas_turno" ), a.getHoras_turno() ),
// new Assignment( new Field( "departamento_id" ), a.getDepartamento_id() ),
// new Assignment( new Field( "seccao_id" ), a.getSeccao_id() ),
// new Assignment( new Field( "local_trabalho" ), a.getLocal_trabalho() ),
// new Assignment( new Field( "tarefa" ), a.getTarefa() ),
// new Assignment( new Field( "substancias" ), a.getSubstancias() ),
// new Assignment( new Field( "condicoes" ), a.getCondicoes() ),
// new Assignment( new Field( "testemunhas" ), a.getTestemunhas() ),
// new Assignment( new Field( "causas" ), a.getCausas() ),
// new Assignment( new Field( "descricao" ), a.getDescricao() ),
// new Assignment( new Field( "conclusoes" ), a.getConclusoes() ),
// new Assignment( new Field( "accoes" ), a.getAccoes() ),
// new Assignment( new Field( "hora_acidente" ), a.getHora_acidente() ),
// new Assignment( new Field( "medico_id" ), a.getMedico_id() ),
// new Assignment( new Field( "tecnico_saude_id" ), a.getTecnico_saude_id() ),
// new Assignment( new Field( "averiguacao_posterior" ), a.getAveriguacao_posterior() ),
// new Assignment( new Field( "averiguacao_obs" ), a.getAveriguacao_obs() ),
// new Assignment( new Field( "data_inicio_processo" ), a.getData_inicio_processo() ),
// new Assignment( new Field( "analise_nr" ), analise_nr ),
// new Assignment( new Field( "coef_incapacidade" ), null ),
// new Assignment( new Field( "concluido_por_desactivacao" ), Boolean.FALSE ),
// new Assignment( new Field( "data_desactivacao" ), null ),
// new Assignment( new Field( "comentario_desactivacao" ), null ),
// } );
// Virtual2DArray array = getExecuter().executeQuery( insert );
// Integer insertedID = getInsertedID( array );
// System.out.println( "SQL : " + insert.toString() );
// System.out.println( "\nINSERTED ANALISE ID : " + insertedID );
// a.setId( insertedID );
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( "" );
}
if ( a.getConcluido_por_desactivacao() == null )
{
a.setConcluido_por_desactivacao( Boolean.FALSE );
a.setData_desactivacao( null );
a.setComentario_desactivacao( null );
}
if ( a.getConcluido_por_desactivacao() != null && a.getConcluido_por_desactivacao().equals( Boolean.TRUE ) && a.getData_desactivacao() == null )
{
a.setData_desactivacao( new Date() );
}
if ( a.getComentario_desactivacao() != null && "".equals( a.getComentario_desactivacao().trim() ) )
{
a.setComentario_desactivacao( null );
}
// 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_assinatura_seg() + "', ";
// }
// if ( a.getData_assinatura_rh() == null )
// {
// sql += "data_assinatura_rh = " + null + ", ";
// }
// else
// {
// sql += "data_assinatura_rh = '" + a.getData_assinatura_rh() + "', ";
// }
// 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 += "concluido_por_desactivacao = " + a.getConcluido_por_desactivacao() + ", ";
// sql += "comentario_desactivacao = " + ( a.getComentario_desactivacao() == null ? "null" : "'" + a.getComentario_desactivacao() + "'" ) + ", ";
// sql += "data_desactivacao = " + ( a.getData_desactivacao() == null ? "null" : "'" + new java.sql.Date( a.getData_desactivacao().getTime() ) + "'" );
// sql += " WHERE id = " + a.getId();
// System.out.println( "SQL UPDATE : " + sql );
// st.execute( sql );
AnalisesAcidentesData analise = fromAnaliseAcidenteBean( a, false );
analise.save();
}
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;
RecomendacoesData recomendacao = fromRecomendacaoBean( r, true );
recomendacao.save();
return recomendacao.getId();
}
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 );
fromRecomendacaoBean( r, false ).save();
}
protected RecomendacoesData fromRecomendacaoBean( Recomendacao recomendacaoBean, boolean criar )
throws Exception
{
RecomendacoesData recomendacao;
if( !criar && recomendacaoBean.getId() != null )
{
recomendacao = getProvider().load( RecomendacoesData.class, recomendacaoBean.getId() );
}
else
{
recomendacao = new RecomendacoesData();
recomendacao.setProvider( getProvider() );
}
recomendacao.setAnalise_id( recomendacaoBean.getAnalise_id() );
recomendacao.setRecomendacao( recomendacaoBean.getRecomendacao() );
return recomendacao;
}
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.getMedidaForSql() + "')";
// st.execute( sql );
//
// return newId;
MedidasData medida = fromMedidaBean( m, true );
medida.save();
return medida.getId();
}
public void updateMedida( Medida m ) throws Exception
{
// Statement st = createStatement();
// String sql = "UPDATE medidas SET analise_id = " + m.getAnalise_id() + ", ";
// sql += "medida = '" + m.getMedidaForSql() + "' ";
// sql += "WHERE id = " + m.getId();
// //System.out.println("SQL : " + sql);
// st.execute( sql );
fromMedidaBean( m, false ).save();
}
protected MedidasData fromMedidaBean( Medida medidaBean, boolean criar )
throws Exception
{
MedidasData medida;
if( !criar && medidaBean.getId() != null )
{
medida = getProvider().load( MedidasData.class, medidaBean.getId() );
}
else
{
medida = new MedidasData();
medida.setProvider( getProvider() );
}
medida.setAnalise_id( medidaBean.getAnalise_id() );
medida.setMedida( medidaBean.getMedida() );
return medida;
}
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();
Statement stlocal = createLocalStatement();
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" );
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();
Statement stlocal = createLocalStatement();
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++;
}
return listOptions;
}
public com.sun.rave.web.ui.model.Option[] getEstabelecimentosGestorList( Integer empresa_id, Boolean booGestor ) throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
ArrayList list = new ArrayList();
Estabelecimento e = null;
//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++;
}
return listOptions;
}
public com.sun.rave.web.ui.model.Option[] getMedicosList() throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
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++;
}
return listOptions;
}
public com.sun.rave.web.ui.model.Option[] getTecnicosSaudeList() throws Exception
{
// Dblocal dblocal = new Dblocal();
// dblocal.connect();
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement();
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++;
}
return listOptions;
}
public com.sun.rave.web.ui.model.Option[] getCausasAcidente( boolean toStatistics ) throws Exception
{
com.sun.rave.web.ui.model.Option[] options = null;
Select2 query = new Select2(
new String[] { CausasData.TABLENAME },
new Integer[] { },
new Expression[] { },
new String[] { CausasData.ID_FULL, CausasData.CAUSA_FULL },
new Field( CausasData.ACTIVA_FULL ).isEqual( "y" ),
new String[] { CausasData.ID_FULL, CausasData.CAUSA_FULL },
null, null, null
);
Virtual2DArray array = getExecuter().executeQuery( query );
if ( array != null )
{
options = new com.sun.rave.web.ui.model.Option[ array.columnLength() + 1 ];
options[ 0 ] = toStatistics ? new Option( "", "" ) : new Option( new Integer( 0 ), "-Seleccionar" );
for ( int i = 0; i < array.columnLength(); i++ )
{
Integer causaID = array.get( i, 0 );
String causa = array.get( i, 1 );
options[ (i+1) ] = new Option( causaID, causa );
}
}
return options;
}
// 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 );
Causa c = null;
if ( rs.first() )
{
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 List<Integer> getDistinctYears( Integer excludeYear ) throws Exception
{
List<Integer> result = new LinkedList<Integer>();
Expression where = new Field( "apagada" ).isEqual( "n" );
if ( excludeYear != null )
{
where = where.and( new Field( "EXTRACT( year FROM data_acidente )" ).notIn( new Integer[] { excludeYear } ) );
}
Select2 query = new Select2(
new String[] { "analises_acidentes" },
new Integer[] { },
new Expression[] { },
new String[] { "DISTINCT( cast( EXTRACT( year FROM data_acidente ) as integer ) ) AS ano" },
where,
new String[] { "ano DESC" },
null, null, null );
query.disableOrderFieldsVerification();
Virtual2DArray array = getExecuter().executeQuery( query );
for ( int i = 0; i < array.columnLength(); i++ )
{
Integer ano = array.get( i, 0 );
result.add( ano );
}
return result;
}
public ArrayList getAnosListFromAnalises() throws Exception
{
ArrayList list = new ArrayList();
String sql = "SELECT DISTINCT EXTRACT( year FROM data_acidente ) AS ano " +
"FROM analises_acidentes " +
"WHERE " +
"apagada = 'n' AND estado = " + Global.ESTADO_CONCLUIDO +
" ORDER BY ano";
Statement st = createStatement();
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;
}
public 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";
}
else if ( estado == Global.ESTADO_CONCLUIDO )
{
return "FASE 9 - CONCLUÍDO";
}
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;
}
public byte[] getLogoByEmpresa( Integer empresaID ) throws Exception
{
byte[] result = null;
String sql = "SELECT empresa_logo_id FROM empresas WHERE id = " + empresaID;
Statement st = createLocalStatement();
ResultSet rslocal = st.executeQuery( sql );
if ( rslocal.isBeforeFirst() )
{
rslocal.first();
Integer logoId = new Integer( rslocal.getInt( "empresa_logo_id" ) );
result = getLogo( logoId );
}
return result;
}
private byte[] getLogo( Integer logoID ) throws Exception
{
System.out.println( "AnalisesDataProvider . getLogo( " + logoID + " ) : " );
byte[] result = null;
String sql = "SELECT image_data FROM image WHERE id = " + logoID;
Statement st = createLocalStatement();
ResultSet rslocal = st.executeQuery( sql );
if ( rslocal.first() )
{
result = rslocal.getBytes( "image_data" );
}
System.out.println( "\tLOGO SIZE : " + ( result == null ? "null" : result.length ) );
return result;
}
protected AnalisesAcidentesData fromAnaliseAcidenteBean( AnaliseAcidente analiseBean, boolean criar )
throws Exception
{
AnalisesAcidentesData analise;
boolean nova = false;
if( !criar && analiseBean.getId() != null )
{
analise = getProvider().load( AnalisesAcidentesData.class, analiseBean.getId() );
}
else
{
analise = new AnalisesAcidentesData();
analise.setProvider( getProvider() );
nova = true;
}
analise.setAveriguador( analiseBean.getAveriguador() );
analise.setData_acidente( analiseBean.getData_acidente() );
analise.setAcidentado_id( analiseBean.getAcidentado_id() );
analise.setEstado( analiseBean.getEstado() );
analise.setEmpresa_id( analiseBean.getEmpresa_id() );
analise.setEstabelecimento_id( analiseBean.getEstabelecimento_id() );
analise.setHoras_turno( analiseBean.getHoras_turno() );
analise.setDepartamento_id( analiseBean.getDepartamento_id() );
analise.setSeccao_id( analiseBean.getSeccao_id() );
analise.setLocal_trabalho( analiseBean.getLocal_trabalho() );
analise.setTarefa( analiseBean.getTarefa() );
analise.setSubstancias( analiseBean.getSubstancias() );
analise.setCondicoes( analiseBean.getCondicoes() );
analise.setTestemunhas( analiseBean.getTestemunhas() );
analise.setCausas( analiseBean.getCausas() );
analise.setDescricao( analiseBean.getDescricao() );
analise.setConclusoes( analiseBean.getConclusoes() );
analise.setAccoes( analiseBean.getAccoes() );
analise.setHora_acidente( analiseBean.getHora_acidente() );
analise.setMedico_id( analiseBean.getMedico_id() );
analise.setTecnico_saude_id( analiseBean.getTecnico_saude_id() );
analise.setAveriguacao_posterior( analiseBean.getAveriguacao_posterior() );
analise.setAveriguacao_obs( analiseBean.getAveriguacao_obs() );
analise.setData_inicio_processo( analiseBean.getData_inicio_processo() );
analise.setAnalise_nr( analiseBean.getAnalise_nr() );
analise.setCoef_incapacidade( analiseBean.getCoef_incapacidade() );
analise.setConcluido_por_desactivacao( nova ? Boolean.FALSE : analiseBean.getConcluido_por_desactivacao() );
analise.setData_desactivacao( nova ? null : analiseBean.getData_desactivacao() );
analise.setComentario_desactivacao( nova ? null : analiseBean.getComentario_desactivacao() );
if( !nova )
{
analise.setFormacao_shst( analiseBean.getFormacao_shst() );
analise.setFormacao_shst_nao_porque( analiseBean.getFormacao_shst_nao_porque() );
analise.setOutros_acidentes_com_colaborador( analiseBean.getOutros_acidentes_com_colaborador() );
analise.setNr_acidentes_com_colaborador( analiseBean.getNr_acidentes_com_colaborador() );
analise.setNr_relatorio_acidente_colaborador1( analiseBean.getNr_relatorio_acidente_colaborador1() );
analise.setNr_relatorio_acidente_colaborador2( analiseBean.getNr_relatorio_acidente_colaborador2() );
analise.setNr_relatorio_acidente_colaborador3( analiseBean.getNr_relatorio_acidente_colaborador3() );
analise.setNr_relatorio_acidente_colaborador4( analiseBean.getNr_relatorio_acidente_colaborador4() );
analise.setAcidentes_outros_colaboradores( analiseBean.getAcidentes_outros_colaboradores() );
analise.setNr_acidentes_outros_colaboradores( analiseBean.getNr_acidentes_outros_colaboradores() );
analise.setNr_relatorio_acidente_outros_colaboradores1( analiseBean.getNr_relatorio_acidente_outros_colaboradores1() );
analise.setNr_relatorio_acidente_outros_colaboradores2( analiseBean.getNr_relatorio_acidente_outros_colaboradores2() );
analise.setNr_relatorio_acidente_outros_colaboradores3( analiseBean.getNr_relatorio_acidente_outros_colaboradores3() );
analise.setNr_relatorio_acidente_outros_colaboradores4( analiseBean.getNr_relatorio_acidente_outros_colaboradores4() );
analise.setLesao_cabeca( analiseBean.getLesao_cabeca() );
analise.setLesao_pescoco( analiseBean.getLesao_pescoco() );
analise.setLesao_tronco( analiseBean.getLesao_tronco() );
analise.setLesao_membro_sup_dir( analiseBean.getLesao_membro_sup_dir() );
analise.setLesao_membro_sup_esq( analiseBean.getLesao_membro_sup_esq() );
analise.setLesao_membro_inf_dir( analiseBean.getLesao_membro_inf_dir() );
analise.setLesao_membro_inf_esq( analiseBean.getLesao_membro_inf_esq() );
analise.setEspecif1( analiseBean.getEspecif1() );
analise.setEspecif2( analiseBean.getEspecif2() );
analise.setEspecif3( analiseBean.getEspecif3() );
analise.setEspecif4( analiseBean.getEspecif4() );
analise.setTipo_lesao( analiseBean.getTipo_lesao() );
analise.setTipo_incapacidade( analiseBean.getTipo_incapacidade() );
analise.setData_aval_incapacidade( analiseBean.getData_aval_incapacidade() );
analise.setData_rev_incapacidade( analiseBean.getData_rev_incapacidade() );
analise.setPeriodo_incapacidade_de( analiseBean.getPeriodo_incapacidade_de() );
analise.setPeriodo_incapacidade_a( analiseBean.getPeriodo_incapacidade_a() );
analise.setImg_flexao( analiseBean.getImg_flexao() );
analise.setImg_ext1( analiseBean.getImg_ext1() );
analise.setImg_ext2( analiseBean.getImg_ext2() );
analise.setImg_cab2( analiseBean.getImg_cab2() );
analise.setImg_cab3( analiseBean.getImg_cab3() );
analise.setImg_ma2( analiseBean.getImg_ma2() );
analise.setImg_ma3( analiseBean.getImg_ma3() );
analise.setImg_ma5( analiseBean.getImg_ma5() );
analise.setImg_ma6( analiseBean.getImg_ma6() );
analise.setImg_ma8( analiseBean.getImg_ma8() );
analise.setImg_ma10( analiseBean.getImg_ma10() );
analise.setImg_rot1( analiseBean.getImg_rot1() );
analise.setImg_rot2( analiseBean.getImg_rot2() );
analise.setImg_cab1( analiseBean.getImg_cab1() );
analise.setImg_cab4( analiseBean.getImg_cab4() );
analise.setImg_ma1( analiseBean.getImg_ma1() );
analise.setImg_ma4( analiseBean.getImg_ma4() );
analise.setImg_ma7( analiseBean.getImg_ma7() );
analise.setImg_ma9( analiseBean.getImg_ma9() );
analise.setRestricao_carga( analiseBean.getRestricao_carga() );
analise.setRestricao_motricidade( analiseBean.getRestricao_motricidade() );
analise.setRestricao_conducao( analiseBean.getRestricao_conducao() );
analise.setRestricao_vibracoes( analiseBean.getRestricao_vibracoes() );
analise.setRestricao_outras( analiseBean.getRestricao_outras() );
analise.setMed_observ( analiseBean.getMed_observ() );
analise.setEstado_assinatura( analiseBean.getEstado_assinatura() );
analise.setAss_consolidacao( analiseBean.getAss_consolidacao() );
analise.setAss_resp_seg( analiseBean.getAss_resp_seg() );
analise.setAss_resp_rh( analiseBean.getAss_resp_rh() );
analise.setData_consolidacao( analiseBean.getData_consolidacao() );
analise.setData_assinatura_seg( analiseBean.getData_assinatura_seg() );
analise.setData_assinatura_rh( analiseBean.getData_assinatura_rh() );
analise.setNome_resp_seg( analiseBean.getNome_resp_seg() );
analise.setNome_resp_rh( analiseBean.getNome_resp_rh() );
analise.setCorrecao( analiseBean.getCorrecao() );
analise.setObservacoes_correcao( analiseBean.getObservacoes_correcao() );
analise.setEstado_antes_correcao( analiseBean.getEstado_antes_correcao() );
analise.setAss_superior( analiseBean.getAss_superior() );
analise.setNome_superior( analiseBean.getNome_superior() );
analise.setNome_resp_consolidacao( analiseBean.getNome_resp_consolidacao() );
analise.setData_assinatura_superior( analiseBean.getData_assinatura_superior() );
analise.setRh_fase4( analiseBean.getRh_fase4() );
}
return analise;
}
protected AcidentadosData fromAcidentadoBean( Acidentado acidentadoBean, boolean criar )
throws Exception
{
AcidentadosData acidentado;
if( !criar && acidentadoBean.getId() != null )
{
acidentado = getProvider().load( AcidentadosData.class, acidentadoBean.getId() );
}
else
{
acidentado = new AcidentadosData();
acidentado.setProvider( getProvider() );
}
acidentado.setNome( acidentadoBean.getNome() );
acidentado.setData_nascimento( acidentadoBean.getData_nascimento() );
acidentado.setBilhete_identidade( acidentadoBean.getBilhete_identidade() );
acidentado.setMorada( acidentadoBean.getMorada() );
acidentado.setCod_postal( acidentadoBean.getCod_postal() );
acidentado.setLocalidade( acidentadoBean.getLocalidade() );
acidentado.setContacto_telefonico( acidentadoBean.getContacto_telefonico() );
acidentado.setData_admissao( acidentadoBean.getData_admissao() );
acidentado.setTurno( acidentadoBean.getTurno() );
acidentado.setFuncao( acidentadoBean.getFuncao() );
acidentado.setTrabalhador_id( acidentadoBean.getTrabalhador_id() );
acidentado.setNumero_mecanografico( acidentadoBean.getNumero_mecanografico() );
acidentado.setNome_superior_hierarquico( acidentadoBean.getNome_superior_hierarquico() );
acidentado.setEmail_superior_hierarquico( acidentadoBean.getEmail_superior_hierarquico() );
acidentado.setEstabelecimento_origem( acidentadoBean.getEstabelecimento_origem() );
acidentado.setData_email_superior_hierarquico( acidentadoBean.getData_email_superior_hierarquico() );
return acidentado;
}
}