forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2669 lines
98 KiB
2669 lines
98 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.dbmodel.DBColumn;
|
|
import com.evolute.dbmodel.ModelProvider;
|
|
import com.evolute.entity.evo.EvoDataProvider;
|
|
import com.evolute.utils.Singleton;
|
|
import com.evolute.utils.arrays.Virtual2DArray;
|
|
import com.evolute.utils.db.Connector;
|
|
import com.evolute.utils.sql.Expression;
|
|
import com.evolute.utils.sql.Field;
|
|
import com.evolute.utils.sql.Select;
|
|
import com.evolute.utils.sql.Select2;
|
|
import com.evolute.utils.strings.StringPlainer;
|
|
import com.sun.rave.web.ui.model.Option;
|
|
|
|
import db.DBConstants;
|
|
import db.DBPropertiesLoader;
|
|
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.DepartamentosData;
|
|
import db.data.siprp.outer.MedidasData;
|
|
import db.data.siprp.outer.RecomendacoesData;
|
|
import db.data.siprp.outer.SeccoesData;
|
|
import db.data.siprp.outer.TiposUtilizadoresData;
|
|
import db.data.siprp.outer.EstabelecimentosData;
|
|
import global.Global;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.SQLException;
|
|
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
|
|
*/
|
|
@SuppressWarnings( "UnusedParameters" )
|
|
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 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 } );
|
|
return controles.size() > 0 ? toControleBean( controles.get( 0 ) ) : null;
|
|
}
|
|
|
|
public Controle createAnoNumeracao( Integer ano ) throws Exception
|
|
{
|
|
Controle c = new Controle();
|
|
c.setAnalise_year( ano );
|
|
c.setLast_analise_nr( 0 );
|
|
|
|
ControleData controle = fromControleBean( c, true );
|
|
controle.save();
|
|
c.setId( controle.getId() );
|
|
return c;
|
|
}
|
|
|
|
public void updateControle( Controle c ) throws Exception
|
|
{
|
|
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;
|
|
}
|
|
|
|
/*************************************************************************/
|
|
/********************************* ACTUAIS *******************************/
|
|
/**
|
|
* *********************************************************************
|
|
*/
|
|
public ArrayList< AnaliseAcidente > searchAnalisesActualSeg( Integer empresa_id, Integer estabelecimento_id, String
|
|
nome, String visitaDate, String POR, String responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesActuaisSegList( empresa_id, estabelecimento_id, responsavel_loja, fromYear );
|
|
}
|
|
else
|
|
{
|
|
CommonExpression commonExpression = new CommonExpression( nome, null, visitaDate, POR, fromYear ).invoke();
|
|
Expression where = commonExpression.getWhere();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
if( responsavel_loja.matches( "y" ) )
|
|
{
|
|
where = where
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_SEG )
|
|
.or( new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "y" )
|
|
.and( new Field( AnalisesAcidentesData.AVERIGUACAO_OBS_FULL ).isEqual( "" ) ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_SEG ) ) )
|
|
.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) );
|
|
}
|
|
else
|
|
{
|
|
where = where
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_SEG )
|
|
.or( new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "y" )
|
|
.and( new Field( AnalisesAcidentesData.AVERIGUACAO_OBS_FULL ).isEqual( "" ) ) ) )
|
|
.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesActuaisSegList( Integer empresa_id, Integer estabelecimentoID, String
|
|
responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
// where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
Expression states = new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_SEG ).or(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "y" )
|
|
.and( new Field( AnalisesAcidentesData.AVERIGUACAO_OBS_FULL ).isEqual( "" ) ) );
|
|
if( "y".equals( responsavel_loja ) )
|
|
{
|
|
states = states.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_SEG ) );
|
|
}
|
|
where = where.and( states );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null );
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesActualRH( Integer empresa_id, Integer estabelecimento_id, String
|
|
nome, String visitaDate, String POR, String responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesActuaisRhList( empresa_id, estabelecimento_id, responsavel_loja, fromYear );
|
|
}
|
|
else
|
|
{
|
|
CommonExpression commonExpression = new CommonExpression( nome, null, visitaDate, POR, fromYear ).invoke();
|
|
Expression where = commonExpression.getWhere();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
if( responsavel_loja.matches( "y" ) )
|
|
{
|
|
where = where.and(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_RH1 )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_RH2 ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_RH ) )
|
|
).and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) );
|
|
}
|
|
else
|
|
{
|
|
where = where.and(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_RH1 )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_RH2 ) )
|
|
).and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesActuaisRhList( Integer empresa_id, Integer estabelecimentoID, String
|
|
responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
// where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
Expression or = new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_RH1 )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_RH2 ) );
|
|
if( "y".equals( responsavel_loja ) )
|
|
{
|
|
or = or.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_RH ) );
|
|
}
|
|
where = where.and( or );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null );
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesActuaisHS( Integer empresa_id, Integer estabelecimento_id, String
|
|
nome, Integer estabelecimentoID, String visitaDate, String POR, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesActuaisHsList( empresa_id, estabelecimento_id, fromYear );
|
|
}
|
|
else
|
|
{
|
|
CommonExpression commonExpression =
|
|
new CommonExpression( nome, estabelecimentoID, visitaDate, POR, fromYear ).invoke();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
Expression where = commonExpression.getWhere().and(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_HS )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_FECHAR ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_CONSOLIDACAO ) )
|
|
);
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesActuaisHsList( Integer empresa_id, Integer estabelecimentoID, Integer
|
|
fromYear ) throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" ).and(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_HS )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_FECHAR ) )
|
|
.or( new Field( "estado" ).isEqual( Global.ESTADO_CONSOLIDACAO ) ) );
|
|
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null
|
|
);
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
/*************************************************************************/
|
|
/******************************* SEGUIMENTO ******************************/
|
|
/**
|
|
* *********************************************************************
|
|
*/
|
|
public ArrayList< AnaliseAcidente > searchAnalisesSeguimentoSeg( Integer empresa_id, Integer estabelecimento_id,
|
|
String nome, String visitaDate, String POR,
|
|
String responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesSeguimentoSegList( empresa_id, estabelecimento_id, responsavel_loja, fromYear );
|
|
}
|
|
else
|
|
{
|
|
CommonExpression commonExpression = new CommonExpression( nome, null, visitaDate, POR, fromYear ).invoke();
|
|
Expression where = commonExpression.getWhere();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
if( responsavel_loja.matches( "y" ) )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_ASSINATURA_SEG ) ).and(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "n" ).or(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "y" )
|
|
.and( new Field( AnalisesAcidentesData.AVERIGUACAO_OBS_FULL ).isDifferent( "" ) ) ) ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_ASSINATURA_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONCLUIDO ) ) ) );
|
|
}
|
|
else
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_FECHAR ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_FECHAR ) ).and(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "n" ).or(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "y" )
|
|
.and( new Field( AnalisesAcidentesData.AVERIGUACAO_OBS_FULL ).isDifferent( "" ) ) ) ) ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesSeguimentoSegList( Integer empresa_id, Integer estabelecimento_id,
|
|
String responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
String tables[] = new String[]{ AnalisesAcidentesData.TABLENAME };
|
|
Expression where = new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id )
|
|
.and( new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" ) );
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
if( responsavel_loja.matches( "y" ) )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_ASSINATURA_SEG ) ).and(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "n" ).or(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "y" )
|
|
.and( new Field( AnalisesAcidentesData.AVERIGUACAO_OBS_FULL ).isDifferent( "" ) ) ) ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_ASSINATURA_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONCLUIDO ) ) ) );
|
|
}
|
|
else
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_FECHAR ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_FECHAR ) ).and(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "n" ).or(
|
|
new Field( AnalisesAcidentesData.AVERIGUACAO_POSTERIOR_FULL ).isEqual( "y" )
|
|
.and( new Field( AnalisesAcidentesData.AVERIGUACAO_OBS_FULL ).isDifferent( "" ) ) ) ) ) );
|
|
}
|
|
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query =
|
|
new Select2( tables, new Integer[]{ }, new Expression[]{ }, new String[]{ "*" }, where, order, null, null,
|
|
null );
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesSeguimentoHS( Integer empresa_id, Integer estabelecimento_id,
|
|
String nome, Integer estabelecimentoID,
|
|
String visitaDate, String POR, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesSeguimentoHsList( empresa_id, estabelecimento_id, fromYear );
|
|
}
|
|
else
|
|
{
|
|
|
|
CommonExpression commonExpression =
|
|
new CommonExpression( nome, estabelecimentoID, visitaDate, POR, fromYear ).invoke();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
Expression where = commonExpression.getWhere().
|
|
and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_HS ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_HS )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONSOLIDACAO ) ) ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_CONSOLIDACAO )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_FECHAR ) ) ) );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesSeguimentoHsList( Integer empresa_id, Integer estabelecimentoID,
|
|
Integer fromYear )
|
|
throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
where = where.and(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_HS )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_HS )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONSOLIDACAO ) ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_CONSOLIDACAO )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_FECHAR ) ) ) );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null
|
|
);
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesSeguimentoRH( Integer empresa_id, Integer estabelecimento_id,
|
|
String nome, String visitaDate, String POR,
|
|
String responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesSeguimentoRhList( empresa_id, estabelecimento_id, responsavel_loja, fromYear );
|
|
}
|
|
else
|
|
{
|
|
CommonExpression commonExpression = new CommonExpression( nome, null, visitaDate, POR, fromYear ).invoke();
|
|
Expression where = commonExpression.getWhere();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
if( responsavel_loja.matches( "y" ) )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_SEG )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_HS ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_CONSOLIDACAO ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_SEG ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_FECHAR ) ) );
|
|
}
|
|
else
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_SEG )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_HS ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_CONSOLIDACAO ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_SEG ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_RH ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_FECHAR ) ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesSeguimentoRhList( Integer empresa_id, Integer estabelecimentoID,
|
|
String responsavel_loja, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
Expression or = new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_SEG )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_HS ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_CONSOLIDACAO ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_SEG ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_FECHAR ) );
|
|
if( !"y".equals( responsavel_loja ) )
|
|
{
|
|
or = or.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_RH ) );
|
|
}
|
|
where = where.and( or );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null
|
|
);
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesSeguimentoMedico( Integer empresa_id, Integer estabelecimento_id,
|
|
String nome, String visitaDate, String POR,
|
|
Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesSeguimentoMedList( empresa_id, estabelecimento_id, fromYear );
|
|
}
|
|
else
|
|
{
|
|
|
|
CommonExpression commonExpression = new CommonExpression( nome, null, visitaDate, POR, fromYear ).invoke();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
Expression where = commonExpression.getWhere()
|
|
.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONSOLIDACAO ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isDifferent( Global.ESTADO_RH1 ) ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_ASSINATURA_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_RH1 ) )
|
|
.and( new Field( "ass_med" ).isEqual( "y" ) ) )
|
|
.or( new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( Global.ESTADO_ASSINATURA_SEG )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONCLUIDO ) ) );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesSeguimentoMedList( Integer empresa_id, Integer estabelecimentoID,
|
|
Integer fromYear )
|
|
throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
where = where.and(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( 5 ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( 6 )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_ASSINATURA_FULL ).isDifferent( 2 ) ) ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( 6 )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_ASSINATURA_FULL ).isEqual( 2 ) )
|
|
.and( new Field( "analises_acidentes.ass_med" ).isEqual( "y" ) ) ).or(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isGreater( 6 )
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( 9 ) ) ) );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null
|
|
);
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesSeguimentoDirSiprp( Integer empresa_id, String nome, Integer
|
|
estabelecimentoID, String visitaDate, String POR, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesSeguimentoDirSiprpList( fromYear );
|
|
}
|
|
else
|
|
{
|
|
|
|
CommonExpression commonExpression =
|
|
new CommonExpression( nome, estabelecimentoID, visitaDate, POR, fromYear ).invoke();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
Expression where = commonExpression.getWhere()
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONCLUIDO ) );
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesSeguimentoDirSiprpList( Integer fromYear ) throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONCLUIDO ) );
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null
|
|
);
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesSeguimentoDirGerRh( Integer empresa_id, String nome, Integer
|
|
estabelecimentoID, String visitaDate, String POR, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
return searchAnalisesSeguimentoDirSiprp( empresa_id, nome, estabelecimentoID, visitaDate, POR, fromYear );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesSeguimentoDirGerRhList( Integer fromYear ) throws Exception
|
|
{
|
|
return getAnalisesSeguimentoDirSiprpList( fromYear );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesSeguimentoGestor( Integer empresa_id, Integer estabelecimento_id,
|
|
String nome, Integer estabelecimentoID,
|
|
String visitaDate, String POR, Integer fromYear )
|
|
throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > res;
|
|
if( nome == null && estabelecimentoID == null && visitaDate == null && POR == null )
|
|
{
|
|
res = getAnalisesSeguimentoGestorList( empresa_id, estabelecimento_id, fromYear );
|
|
}
|
|
else
|
|
{
|
|
CommonExpression commonExpression =
|
|
new CommonExpression( nome, estabelecimentoID, visitaDate, POR, fromYear ).invoke();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
Expression where = commonExpression.getWhere()
|
|
.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONCLUIDO ) );
|
|
|
|
if( estabelecimento_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimento_id ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
res = fillAnaliseFields( result );
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesSeguimentoGestorList( Integer empresa_id, Integer estabelecimentoID,
|
|
Integer fromYear )
|
|
throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isLess( Global.ESTADO_CONCLUIDO ) );
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null
|
|
);
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
/*************************************************************************/
|
|
/****************************** CONCLUIDOS *******************************/
|
|
/**
|
|
* *********************************************************************
|
|
*/
|
|
public ArrayList< AnaliseAcidente > getAnalisesConcluidasList( Integer empresa_id, Integer estabelecimentoID, Integer
|
|
fromYear ) throws Exception
|
|
{
|
|
Expression where = new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_CONCLUIDO );
|
|
where = where.and( new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" ) );
|
|
if( estabelecimentoID != null && estabelecimentoID > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
if( fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{ "*" },
|
|
where,
|
|
new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL },
|
|
null, null, null
|
|
);
|
|
|
|
System.out.println( "\ngetAnalisesConcluidasList() : " + query.toString() + "\n" );
|
|
|
|
System.out.println( "SQL: " + query.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( query );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > getAnalisesConcluidasHsList( Integer fromYear ) throws Exception
|
|
{
|
|
return getAnalisesConcluidasList( null, null, fromYear );
|
|
}
|
|
|
|
public ArrayList< AnaliseAcidente > searchAnalisesConcluidasList( Integer empresa_id, Integer estabelecimento_id,
|
|
Integer ano, Integer mes, Integer dia, String POR,
|
|
String nome, Integer estabelecimentoID,
|
|
Integer fromYear )
|
|
throws Exception
|
|
{
|
|
CommonExpression commonExpression =
|
|
new CommonExpression( nome, estabelecimentoID, null, POR, ano == null ? fromYear : ano ).invoke();
|
|
Expression where = commonExpression.getWhere();
|
|
String[] tables = commonExpression.getTables();
|
|
Integer[] joinTypes = commonExpression.getJoinTypes();
|
|
Expression[] joinConditions = commonExpression.getJoinConditions();
|
|
|
|
String[] order = new String[]{ AnalisesAcidentesData.ANALISE_NR_FULL };
|
|
|
|
if( estabelecimento_id != null && estabelecimento_id > 0 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( 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 );
|
|
calendar_from.set( Calendar.MONTH, 0 );
|
|
calendar_from.set( Calendar.DATE, 1 );
|
|
|
|
calendar_to.set( Calendar.YEAR, ano );
|
|
calendar_to.set( Calendar.MONTH, 11 );
|
|
calendar_to.set( Calendar.DATE, 31 );
|
|
|
|
if( mes != null )
|
|
{
|
|
calendar_from.set( Calendar.MONTH, mes - 1 );
|
|
calendar_to.set( Calendar.MONTH, mes - 1 );
|
|
|
|
if( dia != null )
|
|
{
|
|
calendar_from.set( Calendar.DATE, dia );
|
|
calendar_to.set( Calendar.DATE, dia );
|
|
}
|
|
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 )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.DATA_ACIDENTE_FULL ).isEqual( D_F.format( dateStart ) ) );
|
|
}
|
|
else
|
|
{
|
|
where =
|
|
where.and( new Field( AnalisesAcidentesData.DATA_ACIDENTE_FULL ).isGreaterOrEqual( D_F.format( dateStart )
|
|
) )
|
|
.and( new Field( AnalisesAcidentesData.DATA_ACIDENTE_FULL ).isLessOrEqual( D_F.format( dateEnd ) ) );
|
|
}
|
|
}
|
|
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_CONCLUIDO ) );
|
|
|
|
if( ano == null && mes == null && dia == null && POR == null && nome == null && estabelecimentoID == null &&
|
|
fromYear != null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" ).isEqual( fromYear ) );
|
|
}
|
|
|
|
if( empresa_id != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.EMPRESA_ID_FULL ).isEqual( empresa_id ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( tables, joinTypes, joinConditions, new String[]{ "*" }, where, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
|
|
Virtual2DArray result = getExecuter().executeQuery( select );
|
|
return fillAnaliseFields( result );
|
|
}
|
|
|
|
private ArrayList< AnaliseAcidente > fillAnaliseFields( Virtual2DArray rs ) throws Exception
|
|
{
|
|
ArrayList< AnaliseAcidente > list = new ArrayList< AnaliseAcidente >();
|
|
if( rs.rowCount() > 0 ) //rs not empty
|
|
{
|
|
Expression exp;
|
|
Select select;
|
|
Virtual2DArray subresult;
|
|
String nome_estabelecimento;
|
|
Acidentado ac;
|
|
Integer acidentado_id;
|
|
Integer estabelecimento_id;
|
|
String nome_acidentado;
|
|
String numero_mecanografico;
|
|
Integer estado;
|
|
|
|
for( int i = 0; i < rs.rowCount(); i++ )
|
|
{
|
|
|
|
|
|
estabelecimento_id = rs.get( i, "estabelecimento_id" );
|
|
acidentado_id = rs.get( i, "acidentado_id" );
|
|
ac = getAcidentado( acidentado_id );
|
|
|
|
exp = new Field( db.data.siprp_local.outer.EstabelecimentosData.ID_FULL ).isEqual( estabelecimento_id );
|
|
select = new Select2( db.data.siprp_local.outer.EstabelecimentosData.TABLENAME, exp,
|
|
db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL );
|
|
subresult = getLocalExecuter().executeQuery( select );
|
|
nome_estabelecimento = ( subresult.rowCount() > 0 ) ? ( String ) subresult.get( 0, "nome" ) : "";
|
|
|
|
exp = new Field( db.data.siprp_local.outer.TrabalhadoresData.ID_FULL ).isEqual( ac.getTrabalhador_id() );
|
|
select = new Select2( db.data.siprp_local.outer.TrabalhadoresData.TABLENAME, exp,
|
|
db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL );
|
|
subresult = getLocalExecuter().executeQuery( select );
|
|
nome_acidentado = ( subresult.rowCount() > 0 ) ? ( String ) subresult.get( 0, "nome" ) : "";
|
|
numero_mecanografico =
|
|
( subresult.rowCount() > 0 ) ? ( String ) subresult.get( 0, "numero_mecanografico" ) : "";
|
|
|
|
estado = rs.get( i, "estado" );
|
|
|
|
AnaliseAcidente acidente = AnaliseAcidente
|
|
.build()
|
|
.withId( ( Integer ) rs.get( i, "id" ) )
|
|
.withNr( i )
|
|
.withData_acidente( ( java.sql.Date ) rs.get( i, "data_acidente" ) )
|
|
.withEmpresa_id( ( Integer ) rs.get( i, "empresa_id" ) )
|
|
.withEstabelecimento_id( estabelecimento_id )
|
|
.withNome_estabelecimento( Utils.unicodeToHTML( nome_estabelecimento ) )
|
|
.withEstado( estado )
|
|
.withEstado_assinatura( ( Integer ) rs.get( i, "estado_assinatura" ) )
|
|
.withFase( getFase( estado ) )
|
|
.withAcidentado_id( acidentado_id )
|
|
.withNome_acidentado( Utils.unicodeToHTML( nome_acidentado ) )
|
|
.withNumero_mecanografico( numero_mecanografico )
|
|
.withHoras_turno( ( Integer ) rs.get( i, "horas_turno" ) )
|
|
.withAveriguador( ( String ) rs.get( i, "averiguador" ) )
|
|
.withDepartamento_id( ( Integer ) rs.get( i, "departamento_id" ) )
|
|
.withSeccao_id( ( Integer ) rs.get( i, "seccao_id" ) )
|
|
.withLocal_trabalho( ( String ) rs.get( i, "local_trabalho" ) );
|
|
|
|
|
|
acidente = acidente
|
|
.withTarefa( ( String ) rs.get( i, "tarefa" ) )
|
|
.withSubstancias( ( String ) rs.get( i, "substancias" ) )
|
|
.withCondicoes( ( String ) rs.get( i, "condicoes" ) )
|
|
.withTestemunhas( ( String ) rs.get( i, "testemunhas" ) )
|
|
.withCausas( ( Integer ) rs.get( i, "causas" ) )
|
|
.withDescricao( ( String ) rs.get( i, "descricao" ) )
|
|
.withConclusoes( ( String ) rs.get( i, "conclusoes" ) )
|
|
.withAccoes( ( String ) rs.get( i, "accoes" ) )
|
|
.withAveriguacao_posterior( ( String ) rs.get( i, "averiguacao_posterior" ) )
|
|
.withAveriguacao_obs( ( String ) rs.get( i, "averiguacao_obs" ) )
|
|
.withHora_acidente( ( java.sql.Time ) rs.get( i, "hora_acidente" ) )
|
|
.withFormacao_shst( ( String ) rs.get( i, "formacao_shst" ) )
|
|
.withFormacao_shst_nao_porque( Strings.nullToEmpty( ( String ) rs.get( i, "formacao_shst_nao_porque" ) ) );
|
|
|
|
|
|
acidente = acidente
|
|
.withOutros_acidentes_com_colaborador( ( String ) rs.get( i, "outros_acidentes_com_colaborador" ) )
|
|
.withNr_acidentes_com_colaborador( ( Integer ) rs.get( i, "nr_acidentes_com_colaborador" ) )
|
|
.withNr_relatorio_acidente_colaborador1( ( Integer ) rs.get( i, "nr_relatorio_acidente_colaborador1" ) )
|
|
.withNr_relatorio_acidente_colaborador2( ( Integer ) rs.get( i, "nr_relatorio_acidente_colaborador2" ) )
|
|
.withNr_relatorio_acidente_colaborador3( ( Integer ) rs.get( i, "nr_relatorio_acidente_colaborador3" ) )
|
|
.withNr_relatorio_acidente_colaborador4( ( Integer ) rs.get( i, "nr_relatorio_acidente_colaborador4" ) )
|
|
.withAcidentes_outros_colaboradores( ( String ) rs.get( i, "acidentes_outros_colaboradores" ) )
|
|
.withNr_acidentes_outros_colaboradores( ( Integer ) rs.get( i, "nr_acidentes_outros_colaboradores" ) )
|
|
.withNr_relatorio_acidente_outros_colaboradores1(
|
|
( Integer ) rs.get( i, "nr_relatorio_acidente_outros_colaboradores1" ) )
|
|
.withNr_relatorio_acidente_outros_colaboradores2(
|
|
( Integer ) rs.get( i, "nr_relatorio_acidente_outros_colaboradores2" ) )
|
|
.withNr_relatorio_acidente_outros_colaboradores3(
|
|
( Integer ) rs.get( i, "nr_relatorio_acidente_outros_colaboradores3" ) )
|
|
.withNr_relatorio_acidente_outros_colaboradores4(
|
|
( Integer ) rs.get( i, "nr_relatorio_acidente_outros_colaboradores4" ) )
|
|
.withLesao_cabeca( ( String ) rs.get( i, "lesao_cabeca" ) )
|
|
.withLesao_pescoco( ( String ) rs.get( i, "lesao_pescoco" ) )
|
|
.withLesao_tronco( ( String ) rs.get( i, "lesao_tronco" ) );
|
|
|
|
acidente = acidente
|
|
.withLesao_membro_sup_dir( ( String ) rs.get( i, "lesao_membro_sup_dir" ) )
|
|
.withLesao_membro_sup_esq( ( String ) rs.get( i, "lesao_membro_sup_esq" ) )
|
|
.withLesao_membro_inf_dir( ( String ) rs.get( i, "lesao_membro_inf_dir" ) )
|
|
.withLesao_membro_inf_esq( ( String ) rs.get( i, "lesao_membro_inf_esq" ) )
|
|
.withEspecif1( Strings.nullToEmpty( ( String ) rs.get( i, "especif1" ) ) )
|
|
.withEspecif2( Strings.nullToEmpty( ( String ) rs.get( i, "especif2" ) ) )
|
|
.withEspecif3( Strings.nullToEmpty( ( String ) rs.get( i, "especif3" ) ) )
|
|
.withEspecif4( Strings.nullToEmpty( ( String ) rs.get( i, "especif4" ) ) )
|
|
.withTipo_lesao( Strings.nullToEmpty( ( String ) rs.get( i, "tipo_lesao" ) ) )
|
|
.withTipo_incapacidade( ( String ) rs.get( i, "tipo_incapacidade" ) )
|
|
.withCoef_incapacidade( ( Integer ) rs.get( i, "coef_incapacidade" ) )
|
|
.withData_aval_incapacidade( ( java.sql.Date ) rs.get( i, "data_aval_incapacidade" ) )
|
|
.withData_rev_incapacidade( ( java.sql.Date ) rs.get( i, "data_rev_incapacidade" ) )
|
|
.withPeriodo_incapacidade_de( ( java.sql.Date ) rs.get( i, "periodo_incapacidade_de" ) )
|
|
.withPeriodo_incapacidade_a( ( java.sql.Date ) rs.get( i, "periodo_incapacidade_a" ) );
|
|
|
|
acidente = acidente
|
|
.withImg_flexao( ( String ) rs.get( i, "img_flexao" ) )
|
|
.withImg_ext1( ( String ) rs.get( i, "img_ext1" ) )
|
|
.withImg_ext2( ( String ) rs.get( i, "img_ext2" ) )
|
|
.withImg_cab2( ( String ) rs.get( i, "img_cab2" ) )
|
|
.withImg_cab3( ( String ) rs.get( i, "img_cab3" ) )
|
|
.withImg_ma2( ( String ) rs.get( i, "img_ma2" ) )
|
|
.withImg_ma3( ( String ) rs.get( i, "img_ma3" ) )
|
|
.withImg_ma5( ( String ) rs.get( i, "img_ma5" ) )
|
|
.withImg_ma6( ( String ) rs.get( i, "img_ma6" ) )
|
|
.withImg_ma8( ( String ) rs.get( i, "img_ma8" ) )
|
|
.withImg_ma10( ( String ) rs.get( i, "img_ma10" ) )
|
|
.withImg_rot1( ( String ) rs.get( i, "img_rot1" ) )
|
|
.withImg_rot2( ( String ) rs.get( i, "img_rot2" ) )
|
|
.withImg_cab1( ( String ) rs.get( i, "img_cab1" ) )
|
|
.withImg_cab4( ( String ) rs.get( i, "img_cab4" ) )
|
|
.withImg_ma1( ( String ) rs.get( i, "img_ma1" ) )
|
|
.withImg_ma4( ( String ) rs.get( i, "img_ma4" ) )
|
|
.withImg_ma7( ( String ) rs.get( i, "img_ma7" ) )
|
|
.withImg_ma9( ( String ) rs.get( i, "img_ma9" ) );
|
|
|
|
acidente = acidente
|
|
.withRestricao_carga( ( Integer ) rs.get( i, "restricao_carga" ) )
|
|
.withRestricao_motricidade( ( String ) rs.get( i, "restricao_motricidade" ) )
|
|
.withRestricao_conducao( ( String ) rs.get( i, "restricao_conducao" ) )
|
|
.withRestricao_vibracoes( ( String ) rs.get( i, "restricao_vibracoes" ) )
|
|
.withRestricao_outras( Strings.nullToEmpty( ( String ) rs.get( i, "restricao_outras" ) ) )
|
|
.withMed_observ( Strings.nullToEmpty( ( String ) rs.get( i, "med_observ" ) ) )
|
|
.withAnalise_nr( ( String ) rs.get( i, "analise_nr" ) )
|
|
.withMedico_id( ( Integer ) rs.get( i, "medico_id" ) )
|
|
.withTecnico_saude_id( ( Integer ) rs.get( i, "tecnico_saude_id" ) )
|
|
.withAss_resp_seg( ( String ) rs.get( i, "ass_resp_seg" ) )
|
|
.withAss_resp_rh( ( String ) rs.get( i, "ass_resp_rh" ) )
|
|
.withAss_consolidacao( ( String ) rs.get( i, "ass_consolidacao" ) );
|
|
|
|
acidente = acidente
|
|
.withData_consolidacao( ( java.sql.Date ) rs.get( i, "data_consolidacao" ) )
|
|
.withData_assinatura_seg( ( java.sql.Date ) rs.get( i, "data_assinatura_seg" ) )
|
|
.withData_assinatura_rh( ( java.sql.Date ) rs.get( i, "data_assinatura_rh" ) )
|
|
.withNome_resp_seg( ( String ) rs.get( i, "nome_resp_seg" ) )
|
|
.withNome_resp_rh( ( String ) rs.get( i, "nome_resp_rh" ) )
|
|
.withCorrecao( ( String ) rs.get( i, "correcao" ) )
|
|
.withObservacoes_correcao( ( String ) rs.get( i, "observacoes_correcao" ) )
|
|
.withEstado_antes_correcao( ( Integer ) rs.get( i, "estado_antes_correcao" ) )
|
|
.withAss_superior( ( String ) rs.get( i, "ass_superior" ) )
|
|
.withNome_superior( ( String ) rs.get( i, "nome_superior" ) )
|
|
.withData_assinatura_superior( ( java.sql.Date ) rs.get( i, "data_assinatura_superior" ) )
|
|
.withData_inicio_processo( ( java.sql.Date ) rs.get( i, "data_inicio_processo" ) )
|
|
.withNome_resp_consolidacao( ( String ) rs.get( i, "nome_resp_consolidacao" ) );
|
|
|
|
acidente = acidente
|
|
.withRh_fase4( ( Integer ) rs.get( i, "rh_fase4" ) )
|
|
.withConcluido_por_desactivacao( ( Boolean ) rs.get( i, "concluido_por_desactivacao" ) )
|
|
.withData_desactivacao( ( Date ) rs.get( i, "data_desactivacao" ) )
|
|
.withComentario_desactivacao( ( String ) rs.get( i, "comentario_desactivacao" ) )
|
|
.withParticipado( "y".equals( rs.get( i, "participado" ) ) )
|
|
.withNomeResponsavelParticipacao( ( String ) rs.get( i, "nome_responsavel_participacao" ) )
|
|
.withDataParticipacao( ( Date ) rs.get( i, "data_participacao" ) )
|
|
.end();
|
|
|
|
list.add( acidente );
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public ArrayList< Trabalhador > searchTrabalhador( Integer empresa_id, Integer estabelecimento_id,
|
|
String nrMecanografico, String nome )
|
|
throws Exception
|
|
{
|
|
ArrayList< Trabalhador > list = new ArrayList< Trabalhador >();
|
|
|
|
// All
|
|
|
|
String[] fields =
|
|
{ db.data.siprp_local.outer.TrabalhadoresData.ID_FULL, db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.DATA_NASCIMENTO_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.FUNCAO_PROPOSTA_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.DATA_ADMISSAO_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL,
|
|
db.data.siprp_local.outer.EstabelecimentosData.ID_FULL,
|
|
db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL };
|
|
|
|
String[] tables = { db.data.siprp_local.outer.TrabalhadoresData.TABLENAME,
|
|
db.data.siprp_local.outer.EstabelecimentosData.TABLENAME };
|
|
|
|
Expression[] joinExp = { new Field( db.data.siprp_local.outer.TrabalhadoresData.ESTABELECIMENTO_ID_FULL )
|
|
.isEqual( new Field( db.data.siprp_local.outer.EstabelecimentosData.ID_FULL ) ) };
|
|
|
|
Integer[] joinTypes = { Select2.JOIN_INNER };
|
|
|
|
Expression whereExp =
|
|
new Field( db.data.siprp_local.outer.EstabelecimentosData.EMPRESA_ID_FULL ).isEqual( empresa_id )
|
|
.and( new Field( db.data.siprp_local.outer.TrabalhadoresData.INACTIVO_FULL ).isEqual( "n" ) );
|
|
|
|
String[] order = { db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL };
|
|
|
|
// trabalhadores do estabelecimento
|
|
|
|
Expression firstWhereExp =
|
|
whereExp.and( new Field( db.data.siprp_local.outer.EstabelecimentosData.ID_FULL ).isEqual( estabelecimento_id
|
|
) );
|
|
|
|
if( nrMecanografico != null )
|
|
{
|
|
if( nome != null )
|
|
{
|
|
firstWhereExp = firstWhereExp.and(
|
|
new Field( db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL ).isILike( "%" + nome + "%" ).or(
|
|
new Field( "lower(" + db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL + ")" )
|
|
.isLike( "%" + nrMecanografico.toLowerCase() + "%" ) ) );
|
|
}
|
|
else
|
|
{
|
|
firstWhereExp = firstWhereExp.and(
|
|
new Field( "lower(" + db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL + ")" )
|
|
.isLike( "%" + nrMecanografico.toLowerCase() + "%" ) );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if( nome != null )
|
|
{
|
|
firstWhereExp = firstWhereExp
|
|
.and( new Field( db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL ).isILike( "%" + nome + "%" ) );
|
|
}
|
|
}
|
|
|
|
Select select = new Select2( tables, joinTypes, joinExp, fields, firstWhereExp, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
Virtual2DArray result = getLocalExecuter().executeQuery( select );
|
|
|
|
for( int i = 0; i < result.rowCount(); i++ )
|
|
{
|
|
Integer rId = result.get( i, 0 );
|
|
String rNome = result.get( i, 1 );
|
|
Date rDataNascimento = result.get( i, 2 );
|
|
String rFuncao = result.get( i, 3 );
|
|
Date rDataAdmissao = result.get( i, 4 );
|
|
String rNumeroMecanografico = result.get( i, 5 );
|
|
Integer rEstabelecimentoId = result.get( i, 6 );
|
|
String rEstabelecimentoNome = result.get( i, 7 );
|
|
|
|
Trabalhador trabalhador = Trabalhador
|
|
.createTrabalhador()
|
|
.withId( rId )
|
|
.withNome( rNome )
|
|
.withData_nascimento( new java.sql.Date( rDataNascimento.getTime() ) )
|
|
.withFuncao( rFuncao )
|
|
.withData_admissao( new java.sql.Date( rDataAdmissao.getTime() ) )
|
|
.withNumero_mecanografico( rNumeroMecanografico )
|
|
.withEstabelecimento_id( rEstabelecimentoId )
|
|
.withEstabelecimento( rEstabelecimentoNome );
|
|
|
|
list.add( trabalhador );
|
|
}
|
|
|
|
//restantes trabalhadores
|
|
|
|
Expression secondWhereExp = whereExp
|
|
.and( new Field( db.data.siprp_local.outer.EstabelecimentosData.ID_FULL ).isDifferent( estabelecimento_id ) );
|
|
|
|
if( nrMecanografico != null )
|
|
{
|
|
if( nome != null )
|
|
{
|
|
secondWhereExp = secondWhereExp.and(
|
|
new Field( db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL ).isILike( "%" + nome + "%" ).or(
|
|
new Field( "lower(" + db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL + ")" )
|
|
.isLike( "%" + nrMecanografico.toLowerCase() + "%" ) ) );
|
|
}
|
|
else
|
|
{
|
|
secondWhereExp = secondWhereExp.and(
|
|
new Field( "lower(" + db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL + ")" )
|
|
.isLike( "%" + nrMecanografico.toLowerCase() + "%" ) );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if( nome != null )
|
|
{
|
|
secondWhereExp = secondWhereExp
|
|
.and( new Field( db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL ).isILike( "%" + nome + "%" ) );
|
|
}
|
|
}
|
|
|
|
|
|
select = new Select2( tables, joinTypes, joinExp, fields, secondWhereExp, order, null, null, null );
|
|
|
|
System.out.println( "SQL: " + select.toString() );
|
|
|
|
result = getLocalExecuter().executeQuery( select );
|
|
|
|
for( int i = 0; i < result.rowCount(); i++ )
|
|
{
|
|
Integer rId = result.get( i, 0 );
|
|
String rNome = result.get( i, 1 );
|
|
Date rDataNascimento = result.get( i, 2 );
|
|
String rFuncao = result.get( i, 3 );
|
|
Date rDataAdmissao = result.get( i, 4 );
|
|
String rNumeroMecanografico = result.get( i, 5 );
|
|
Integer rEstabelecimentoId = result.get( i, 6 );
|
|
String rEstabelecimentoNome = result.get( i, 7 );
|
|
|
|
Trabalhador trabalhador = Trabalhador
|
|
.createTrabalhador()
|
|
.withId( rId )
|
|
.withNome( rNome )
|
|
.withData_nascimento( new java.sql.Date( rDataNascimento.getTime() ) )
|
|
.withFuncao( rFuncao )
|
|
.withData_admissao( new java.sql.Date( rDataAdmissao.getTime() ) )
|
|
.withNumero_mecanografico( rNumeroMecanografico )
|
|
.withEstabelecimento_id( rEstabelecimentoId )
|
|
.withEstabelecimento( rEstabelecimentoNome );
|
|
|
|
list.add( trabalhador );
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public ArrayList< Trabalhador > searchTrabalhador( Integer empresa_id, String nrMecanografico, String nome )
|
|
throws Exception
|
|
{
|
|
ArrayList< Trabalhador > list = new ArrayList< Trabalhador >();
|
|
|
|
StringTokenizer st;
|
|
|
|
Expression expr =
|
|
new Field( db.data.siprp_local.outer.EstabelecimentosData.EMPRESA_ID_FULL ).isEqual( empresa_id ).and(
|
|
new Field( db.data.siprp_local.outer.TrabalhadoresData.INACTIVO_FULL ).isEqual( "n" ) )
|
|
.and( new Field( db.data.siprp_local.outer.EstabelecimentosData.INACTIVO_FULL ).isEqual( "n" ) );
|
|
|
|
if( nome != null )
|
|
{
|
|
st = new StringTokenizer( nome );
|
|
while( st.hasMoreTokens() )
|
|
{
|
|
expr = expr.and(
|
|
new Field( db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL ).isILike( "%" + st.nextToken() + "%" ) );
|
|
}
|
|
}
|
|
if( nrMecanografico != null )
|
|
{
|
|
expr = expr.and( new Field( db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL )
|
|
.isILike( nrMecanografico.toLowerCase() ) );
|
|
}
|
|
|
|
Select select =
|
|
new Select2( new String[]{ db.data.siprp_local.outer.TrabalhadoresData.TABLENAME,
|
|
db.data.siprp_local.outer.EstabelecimentosData.TABLENAME },
|
|
new Integer[]{ Select2.JOIN_INNER },
|
|
new Expression[]{ new Field( db.data.siprp_local.outer.TrabalhadoresData.ESTABELECIMENTO_ID_FULL )
|
|
.isEqual( new Field( EstabelecimentosData.ID_FULL ) ) },
|
|
new String[]{ db.data.siprp_local.outer.TrabalhadoresData.ID_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.NOME_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.DATA_NASCIMENTO_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.FUNCAO_PROPOSTA_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.DATA_ADMISSAO_FULL,
|
|
db.data.siprp_local.outer.TrabalhadoresData.NUMERO_MECANOGRAFICO_FULL,
|
|
db.data.siprp_local.outer.EstabelecimentosData.ID_FULL,
|
|
db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL },
|
|
expr,
|
|
null,
|
|
null,
|
|
null,
|
|
null );
|
|
|
|
System.out.println( "TRABALHADORES SQL (NOVO) : " + select );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
System.out.println( "Encontrei : " + array.rowCount() );
|
|
for( int n = 0; n < array.rowCount(); n++ )
|
|
{
|
|
try
|
|
{
|
|
Trabalhador t = new Trabalhador();
|
|
t.setId( ( Integer ) array.get( n, 0 ) );
|
|
String nome_trab = array.get( n, 1 );
|
|
t.setNome( utils.Utils.unicodeToHTML( nome_trab ) );
|
|
t.setData_nascimento( ( java.sql.Date ) array.get( n, 2 ) );
|
|
t.setFuncao( ( String ) array.get( n, 3 ) );
|
|
t.setData_admissao( ( java.sql.Date ) array.get( n, 4 ) );
|
|
t.setNumero_mecanografico( ( String ) array.get( n, 5 ) );
|
|
t.setEstabelecimento_id( ( Integer ) array.get( n, 6 ) );
|
|
t.setEstabelecimento( utils.Utils.unicodeToHTML( ( String ) array.get( n, 7 ) ) );
|
|
list.add( t );
|
|
System.out.println( nome_trab );
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
System.out.println( "na lista vao : " + list.size() );
|
|
return list;
|
|
}
|
|
|
|
@SuppressWarnings( "UnusedDeclaration" )
|
|
public Trabalhador getTrabalhador( Integer id ) throws Exception
|
|
{
|
|
return new Trabalhador( EvoBaseProvider.getInstance().
|
|
getLocalProvider().load(
|
|
db.data.siprp_local.outer.TrabalhadoresData.class,
|
|
new Object[]{ id },
|
|
new String[]{ db.data.siprp_local.outer.TrabalhadoresData.ID_FULL }, null ) );
|
|
}
|
|
|
|
public Acidentado getAcidentado( Integer acidentado_id ) throws Exception
|
|
{
|
|
return new Acidentado( EvoBaseProvider.getInstance().
|
|
getProvider().load(
|
|
AcidentadosData.class,
|
|
new Object[]{ acidentado_id },
|
|
new String[]{ AcidentadosData.ID_FULL }, null )
|
|
);
|
|
}
|
|
|
|
public String getEmpresaNome( Integer empresa_id ) throws Exception
|
|
{
|
|
Expression dataFilter = new Field( db.data.siprp_local.outer.EmpresasData.ID_FULL ).isEqual( empresa_id );
|
|
Select select = new Select2( db.data.siprp_local.outer.EmpresasData.TABLENAME, dataFilter,
|
|
db.data.siprp_local.outer.EmpresasData.DESIGNACAO_SOCIAL_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? Utils.unicodeToHTML( ( String ) array.get( 0, 0 ) ) : "";
|
|
}
|
|
|
|
public String getEstabelecimentoNome( Integer estabelecimento_id ) throws Exception
|
|
{
|
|
Expression dataFilter =
|
|
new Field( db.data.siprp_local.outer.EstabelecimentosData.ID_FULL ).isEqual( estabelecimento_id );
|
|
Select select = new Select2( db.data.siprp_local.outer.EstabelecimentosData.TABLENAME, dataFilter,
|
|
db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? Utils.unicodeToHTML( ( String ) array.get( 0, 0 ) ) : "";
|
|
}
|
|
|
|
@SuppressWarnings( "UnusedDeclaration" )
|
|
public String getMedicoNome( Integer medico_id ) throws Exception
|
|
{
|
|
Expression dataFilter = new Field( db.data.siprp_local.outer.MedicosData.ID_FULL ).isEqual( medico_id );
|
|
Select select = new Select2( db.data.siprp_local.outer.MedicosData.TABLENAME, dataFilter,
|
|
db.data.siprp_local.outer.MedicosData.NOME_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? Utils.unicodeToHTML( ( String ) array.get( 0, 0 ) ) : "";
|
|
}
|
|
|
|
public Medico getMedico( Integer id ) throws Exception
|
|
{
|
|
return new Medico( EvoBaseProvider.getInstance().
|
|
getLocalProvider().load(
|
|
db.data.siprp_local.outer.MedicosData.class,
|
|
new Object[]{ id },
|
|
new String[]{ db.data.siprp_local.outer.MedicosData.ID_FULL }, null )
|
|
);
|
|
}
|
|
|
|
public String getTecnicoSaudeNome( Integer tecnico_id ) throws Exception
|
|
{
|
|
Expression dataFilter = new Field( db.data.siprp_local.outer.MarcacoesTecnicosHstData.ID_FULL ).isEqual(
|
|
tecnico_id );
|
|
Select select = new Select2( db.data.siprp_local.outer.MarcacoesTecnicosHstData.TABLENAME, dataFilter,
|
|
db.data.siprp_local.outer.MarcacoesTecnicosHstData.NOME_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? Utils.unicodeToHTML( ( String ) array.get( 0, 0 ) ) : "";
|
|
}
|
|
|
|
public Integer createAcidentado( Acidentado a ) throws Exception
|
|
{
|
|
AcidentadosData acidentado = fromAcidentadoBean( a, true );
|
|
acidentado.save();
|
|
return acidentado.getId();
|
|
}
|
|
|
|
public void updateAcidentado( Acidentado a ) throws Exception
|
|
{
|
|
AcidentadosData acidentado = fromAcidentadoBean( a, false );
|
|
acidentado.save();
|
|
}
|
|
|
|
public AnaliseAcidente createAnalise( AnaliseAcidente a ) throws Exception
|
|
{
|
|
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( ano );
|
|
if( c == null )
|
|
{
|
|
c = createAnoNumeracao( ano );
|
|
}
|
|
int i_analise_nr = c.getLast_analise_nr() + 1;
|
|
c.setLast_analise_nr( i_analise_nr );
|
|
String seq_str = Integer.toString( 10000 + i_analise_nr );
|
|
String ano_str = Integer.toString( ano );
|
|
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() );
|
|
|
|
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 );
|
|
}
|
|
|
|
AnalisesAcidentesData analise = fromAnaliseAcidenteBean( a, false );
|
|
|
|
analise.save();
|
|
}
|
|
|
|
public void changeEstado( Correcao c ) throws Exception
|
|
{
|
|
AnalisesAcidentesData analisesAcidentesData = EvoBaseProvider
|
|
.getInstance().getProvider().load( AnalisesAcidentesData.class, new Object[]{ c.getAnalise_id() },
|
|
new String[]{ AnalisesAcidentesData.ID_FULL }, null );
|
|
|
|
analisesAcidentesData.update( c );
|
|
analisesAcidentesData.save();
|
|
analisesAcidentesData.refresh();
|
|
}
|
|
|
|
public Integer createRecomendacao( Recomendacao r ) throws Exception
|
|
{
|
|
RecomendacoesData recomendacao = fromRecomendacaoBean( r, true );
|
|
recomendacao.save();
|
|
return recomendacao.getId();
|
|
}
|
|
|
|
@SuppressWarnings( "UnusedDeclaration" )
|
|
public void updateRecomendacao( Recomendacao r )
|
|
throws Exception
|
|
{
|
|
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
|
|
{
|
|
|
|
for( RecomendacoesData recomendacoesData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
RecomendacoesData.class, new Object[]{ analise_id },
|
|
new String[]{ RecomendacoesData.ANALISE_ID_FULL }, new String[]{ RecomendacoesData.ANALISE_ID_FULL } ) )
|
|
{
|
|
recomendacoesData.delete();
|
|
}
|
|
}
|
|
|
|
public void deleteAnaliseAcidente( Integer analise_id ) throws Exception
|
|
{
|
|
|
|
for( AnalisesAcidentesData analisesAcidentesData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
AnalisesAcidentesData.class, new Object[]{ analise_id },
|
|
new String[]{ AnalisesAcidentesData.ID_FULL }, new String[]{ AnalisesAcidentesData.ID_FULL } ) )
|
|
{
|
|
analisesAcidentesData.setApagada( "y" );
|
|
analisesAcidentesData.save();
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings( "UnusedDeclaration" )
|
|
public void deleteAcidentado( Integer acidentado_id ) throws Exception
|
|
{
|
|
|
|
for( AcidentadosData acidentadosData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
AcidentadosData.class, new Object[]{ acidentado_id },
|
|
new String[]{ AcidentadosData.ID_FULL }, new String[]{ AcidentadosData.ID_FULL } ) )
|
|
{
|
|
acidentadosData.delete();
|
|
}
|
|
}
|
|
|
|
public ArrayList< Recomendacao > getRecomendacoesByAnalise( Integer analiseId ) throws Exception
|
|
{
|
|
|
|
ArrayList< Recomendacao > list = new ArrayList< Recomendacao >();
|
|
|
|
for( RecomendacoesData recomendacoesData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
RecomendacoesData.class, new Object[]{ analiseId },
|
|
new String[]{ RecomendacoesData.ANALISE_ID_FULL }, new String[]{ RecomendacoesData.ID_FULL } ) )
|
|
{
|
|
list.add( new Recomendacao( recomendacoesData ) );
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public Integer createMedida( Medida m ) throws Exception
|
|
{
|
|
MedidasData medida = fromMedidaBean( m, true );
|
|
medida.save();
|
|
|
|
return medida.getId();
|
|
}
|
|
|
|
@SuppressWarnings( "UnusedDeclaration" )
|
|
public void updateMedida( Medida m ) throws Exception
|
|
{
|
|
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
|
|
{
|
|
|
|
for( MedidasData medidasData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
MedidasData.class, new Object[]{ analise_id },
|
|
new String[]{ MedidasData.ANALISE_ID_FULL }, new String[]{ MedidasData.ANALISE_ID_FULL } ) )
|
|
{
|
|
medidasData.delete();
|
|
}
|
|
}
|
|
|
|
public ArrayList< Medida > getMedidasByAnalise( Integer analiseId ) throws Exception
|
|
{
|
|
|
|
ArrayList< Medida > list = new ArrayList< Medida >();
|
|
|
|
for( MedidasData medidasData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
MedidasData.class, new Object[]{ analiseId },
|
|
new String[]{ MedidasData.ANALISE_ID_FULL }, new String[]{ MedidasData.ID_FULL } ) )
|
|
{
|
|
list.add( new Medida( medidasData ) );
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public String getNumeroCedula( Integer medico_id ) throws Exception
|
|
{
|
|
Expression dataFilter = new Field( db.data.siprp_local.outer.MedicosData.ID_FULL ).isEqual( medico_id );
|
|
Select select = new Select2( db.data.siprp_local.outer.MedicosData.TABLENAME, dataFilter,
|
|
db.data.siprp_local.outer.MedicosData.NUMERO_CEDULA_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? Utils.unicodeToHTML( ( String ) array.get( 0, 0 ) ) : "";
|
|
}
|
|
|
|
public String getTipoDescricao( Integer tipo ) throws Exception
|
|
{
|
|
Expression dataFilter = new Field( TiposUtilizadoresData.TIPO_FULL ).isEqual( tipo );
|
|
Select select = new Select2( TiposUtilizadoresData.TABLENAME, dataFilter, TiposUtilizadoresData.DESCRICAO_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? Utils.unicodeToHTML( ( String ) array.get( 0, 0 ) ) : "";
|
|
}
|
|
|
|
public Option[] getTiposList() throws Exception
|
|
{
|
|
ArrayList< TipoUtilizador > list = new ArrayList< TipoUtilizador >();
|
|
TipoUtilizador t = new TipoUtilizador();
|
|
t.setId( 0 );
|
|
t.setTipo( 0 );
|
|
t.setDescricao( "" );
|
|
list.add( t );
|
|
|
|
for( TiposUtilizadoresData tiposUtilizadoresData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
TiposUtilizadoresData.class, new Object[]{ "y" },
|
|
new String[]{ TiposUtilizadoresData.ACTIVO_FULL }, new String[]{ TiposUtilizadoresData.ORDEM_FULL } ) )
|
|
{
|
|
list.add( new TipoUtilizador( tiposUtilizadoresData ) );
|
|
}
|
|
|
|
return getOptions( list );
|
|
}
|
|
|
|
private Option[] getOptions( ArrayList< TipoUtilizador > list )
|
|
{
|
|
TipoUtilizador t;
|
|
Option[] listOptions = new Option[list.size()];
|
|
ListIterator< TipoUtilizador > iter = list.listIterator();
|
|
int i = 0;
|
|
while( iter.hasNext() )
|
|
{
|
|
t = iter.next();
|
|
|
|
listOptions[i] = new Option( t.getTipo(), t.getDescricao() );
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public Option[] getTiposList( Integer permissao ) throws Exception
|
|
{
|
|
ArrayList< TipoUtilizador > list = new ArrayList< TipoUtilizador >();
|
|
TipoUtilizador t = new TipoUtilizador();
|
|
t.setId( 0 );
|
|
t.setTipo( 0 );
|
|
t.setDescricao( "" );
|
|
list.add( t );
|
|
|
|
for( TiposUtilizadoresData tiposUtilizadoresData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
TiposUtilizadoresData.class, new Object[]{ "y" },
|
|
new String[]{ TiposUtilizadoresData.ACTIVO_FULL }, new String[]{ TiposUtilizadoresData.ORDEM_FULL } ) )
|
|
{
|
|
|
|
list.add( new TipoUtilizador( tiposUtilizadoresData, permissao ) );
|
|
}
|
|
|
|
return getOptions( list );
|
|
}
|
|
|
|
public Option[] getEstabelecimentosList( Integer empresa_id, Boolean booGestor ) throws Exception
|
|
{
|
|
ArrayList< Estabelecimento > list = new ArrayList< Estabelecimento >();
|
|
|
|
Estabelecimento e = new Estabelecimento();
|
|
e.setId( -1 );
|
|
e.setNome( "-Seleccionar-" );
|
|
list.add( e );
|
|
|
|
if( booGestor.equals( Boolean.TRUE ) )
|
|
{
|
|
e = new Estabelecimento();
|
|
e.setId( 0 );
|
|
e.setNome( "-Todos os estabelecimentos-" );
|
|
|
|
list.add( e );
|
|
}
|
|
|
|
for( db.data.siprp_local.outer.EstabelecimentosData estabelecimentosData :
|
|
EvoBaseProvider.getInstance().getLocalProvider().listLoad(
|
|
db.data.siprp_local.outer.EstabelecimentosData.class, new Object[]{ "n", empresa_id },
|
|
new String[]{ db.data.siprp_local.outer.EstabelecimentosData.INACTIVO_FULL,
|
|
db.data.siprp_local.outer.EstabelecimentosData.EMPRESA_ID_FULL },
|
|
new String[]{ db.data.siprp_local.outer.EstabelecimentosData.NOME_PLAIN_FULL } ) )
|
|
{
|
|
|
|
list.add( new Estabelecimento( estabelecimentosData ) );
|
|
}
|
|
|
|
return getOptionsEstabelecimento( list );
|
|
}
|
|
|
|
private Option[] getOptionsEstabelecimento( ArrayList< Estabelecimento > list )
|
|
{
|
|
Estabelecimento e;
|
|
Option[] listOptions = new Option[list.size()];
|
|
ListIterator< Estabelecimento > iter = list.listIterator();
|
|
int i = 0;
|
|
while( iter.hasNext() )
|
|
{
|
|
e = 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 Option[] getEstabelecimentosGestorList( Integer empresa_id, Boolean booGestor ) throws Exception
|
|
{
|
|
ArrayList< Estabelecimento > list = new ArrayList< Estabelecimento >();
|
|
|
|
if( booGestor.equals( Boolean.TRUE ) )
|
|
{
|
|
Estabelecimento e = new Estabelecimento();
|
|
e.setId( 0 );
|
|
e.setNome( "-Todos os estabelecimentos-" );
|
|
|
|
list.add( e );
|
|
}
|
|
|
|
for( db.data.siprp_local.outer.EstabelecimentosData estabelecimentosData :
|
|
EvoBaseProvider.getInstance().getLocalProvider().listLoad(
|
|
db.data.siprp_local.outer.EstabelecimentosData.class, new Object[]{ "n", empresa_id },
|
|
new String[]{ db.data.siprp_local.outer.EstabelecimentosData.INACTIVO_FULL,
|
|
db.data.siprp_local.outer.EstabelecimentosData.EMPRESA_ID_FULL },
|
|
new String[]{ db.data.siprp_local.outer.EstabelecimentosData.NOME_PLAIN_FULL } ) )
|
|
{
|
|
|
|
list.add( new Estabelecimento( estabelecimentosData ) );
|
|
}
|
|
|
|
return getOptionsEstabelecimento( list );
|
|
}
|
|
|
|
public Option[] getMedicosList() throws Exception
|
|
{
|
|
ArrayList< Medico > list = new ArrayList< Medico >();
|
|
Medico m = new Medico();
|
|
m.setId( 0 );
|
|
m.setNome( "-Seleccionar-" );
|
|
list.add( m );
|
|
|
|
for( db.data.siprp_local.outer.MedicosData medicosData :
|
|
EvoBaseProvider.getInstance().getLocalProvider().listLoad(
|
|
db.data.siprp_local.outer.MedicosData.class, new Object[]{ "n" },
|
|
new String[]{ db.data.siprp_local.outer.MedicosData.INACTIVO_FULL },
|
|
new String[]{ db.data.siprp_local.outer.MedicosData.NOME_FULL } ) )
|
|
{
|
|
|
|
list.add( new Medico( medicosData ) );
|
|
}
|
|
|
|
return getOptionsMedicos( list );
|
|
}
|
|
|
|
private Option[] getOptionsMedicos( ArrayList< Medico > list )
|
|
{
|
|
Medico m;
|
|
Option[] listOptions = new Option[list.size()];
|
|
ListIterator< Medico > iter = list.listIterator();
|
|
int i = 0;
|
|
while( iter.hasNext() )
|
|
{
|
|
m = iter.next();
|
|
|
|
listOptions[i] = new Option( m.getId(), Utils.unicodeToHTML( m.getNome() ) );
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public Option[] getTecnicosSaudeList() throws Exception
|
|
{
|
|
ArrayList< TecnicoSaude > list = new ArrayList< TecnicoSaude >();
|
|
TecnicoSaude t = new TecnicoSaude();
|
|
t.setId( 0 );
|
|
t.setNome( "-Seleccionar-" );
|
|
list.add( t );
|
|
|
|
for( db.data.siprp_local.outer.MarcacoesTecnicosHstData marcacoesTecnicosHstData :
|
|
EvoBaseProvider.getInstance().getLocalProvider().listLoad(
|
|
db.data.siprp_local.outer.MarcacoesTecnicosHstData.class, new Object[]{ "n" },
|
|
new String[]{ db.data.siprp_local.outer.MarcacoesTecnicosHstData.INACTIVO_FULL },
|
|
new String[]{ db.data.siprp_local.outer.MarcacoesTecnicosHstData.NOME_FULL } ) )
|
|
{
|
|
|
|
list.add( new TecnicoSaude( marcacoesTecnicosHstData ) );
|
|
}
|
|
|
|
return getOptionsTecnicosSaude( list );
|
|
}
|
|
|
|
private Option[] getOptionsTecnicosSaude( ArrayList< TecnicoSaude > list )
|
|
{
|
|
TecnicoSaude t;
|
|
Option[] listOptions = new Option[list.size()];
|
|
ListIterator< TecnicoSaude > iter = list.listIterator();
|
|
int i = 0;
|
|
while( iter.hasNext() )
|
|
{
|
|
t = iter.next();
|
|
|
|
listOptions[i] = new Option( t.getId(), Utils.unicodeToHTML( t.getNome() ) );
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
|
|
public Option[] getCausasAcidente( boolean toStatistics ) throws Exception
|
|
{
|
|
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 Option[array.rowCount() + 1];
|
|
options[0] = toStatistics ? new Option( "", "" ) : new Option( 0, "-Seleccionar" );
|
|
for( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer causaID = array.get( i, 0 );
|
|
String causa = array.get( i, 1 );
|
|
options[( i + 1 )] = new Option( causaID, causa );
|
|
}
|
|
}
|
|
return options;
|
|
}
|
|
|
|
public Option[] getDepartamentosList() throws Exception
|
|
{
|
|
ArrayList< Departamento > list = new ArrayList< Departamento >();
|
|
Departamento d = new Departamento();
|
|
|
|
d.setId( 0 );
|
|
d.setDescricao( "-Todos-" );
|
|
list.add( d );
|
|
|
|
for( DepartamentosData departamentosData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
DepartamentosData.class, new Object[]{ "y" },
|
|
new String[]{ DepartamentosData.ACTIVO_FULL },
|
|
new String[]{ DepartamentosData.ID_FULL } ) )
|
|
{
|
|
list.add( new Departamento( departamentosData ) );
|
|
}
|
|
|
|
return getOptionsDepartamentos( list );
|
|
}
|
|
|
|
private Option[] getOptionsDepartamentos( ArrayList< Departamento > list )
|
|
{
|
|
Departamento d;
|
|
Option[] listOptions = new Option[list.size()];
|
|
ListIterator< Departamento > iter = list.listIterator();
|
|
int i = 0;
|
|
while( iter.hasNext() )
|
|
{
|
|
d = iter.next();
|
|
|
|
listOptions[i] = new Option( d.getId(), d.getDescricao() );
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public Option[] getSeccoesList( Integer departamento_id ) throws Exception
|
|
{
|
|
ArrayList< Seccao > list = new ArrayList< Seccao >();
|
|
Seccao s = new Seccao();
|
|
|
|
s.setId( 0 );
|
|
s.setDescricao( "-Seleccionar-" );
|
|
list.add( s );
|
|
|
|
Object[] values;
|
|
String[] names;
|
|
|
|
if( departamento_id == null )
|
|
{
|
|
values = new Object[]{ "y" };
|
|
names = new String[]{ SeccoesData.ACTIVO_FULL };
|
|
}
|
|
else
|
|
{
|
|
values = new Object[]{ "y", departamento_id };
|
|
names = new String[]{ SeccoesData.ACTIVO_FULL, SeccoesData.DEPARTAMENTO_ID_FULL };
|
|
}
|
|
|
|
for( SeccoesData seccoesData :
|
|
EvoBaseProvider.getInstance().getProvider().listLoad(
|
|
SeccoesData.class, values, names,
|
|
new String[]{ SeccoesData.ID_FULL } ) )
|
|
{
|
|
list.add( new Seccao( seccoesData ) );
|
|
}
|
|
|
|
return getOptionsSeccoes( list );
|
|
}
|
|
|
|
private Option[] getOptionsSeccoes( ArrayList< Seccao > list )
|
|
{
|
|
Seccao s;
|
|
Option[] listOptions = new Option[list.size()];
|
|
ListIterator< Seccao > iter = list.listIterator();
|
|
int i = 0;
|
|
while( iter.hasNext() )
|
|
{
|
|
s = iter.next();
|
|
|
|
listOptions[i] = new Option( s.getId(), s.getDescricao() );
|
|
i++;
|
|
}
|
|
return listOptions;
|
|
}
|
|
|
|
public Causa getCausa( Integer id ) throws Exception
|
|
{
|
|
return new Causa( EvoBaseProvider.getInstance().
|
|
getProvider().load(
|
|
CausasData.class,
|
|
new Object[]{ id },
|
|
new String[]{ CausasData.ID_FULL }, null )
|
|
);
|
|
}
|
|
|
|
public Seccao getSeccao( Integer id ) throws Exception
|
|
{
|
|
return new Seccao( EvoBaseProvider.getInstance().
|
|
getProvider().load(
|
|
SeccoesData.class,
|
|
new Object[]{ id },
|
|
new String[]{ SeccoesData.ID_FULL }, null )
|
|
);
|
|
}
|
|
|
|
public List< Integer > getDistinctYears( Integer excludeYear ) throws Exception
|
|
{
|
|
List< Integer > result = new LinkedList< Integer >();
|
|
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
if( excludeYear != null )
|
|
{
|
|
where = where.and( new Field( "EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " )" )
|
|
.notIn( new Integer[]{ excludeYear } ) );
|
|
}
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{
|
|
"DISTINCT( cast( EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " ) 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.rowCount(); i++ )
|
|
{
|
|
Integer ano = array.get( i, 0 );
|
|
result.add( ano );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public ArrayList< Integer > getAnosListFromAnalises() throws Exception
|
|
{
|
|
ArrayList< Integer > list = new ArrayList< Integer >();
|
|
|
|
Expression where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" ).and(
|
|
new Field( AnalisesAcidentesData.ESTADO_FULL ).isEqual( Global.ESTADO_CONCLUIDO )
|
|
);
|
|
|
|
Select2 query = new Select2(
|
|
new String[]{ AnalisesAcidentesData.TABLENAME },
|
|
new Integer[]{ },
|
|
new Expression[]{ },
|
|
new String[]{
|
|
"DISTINCT( cast( EXTRACT( year FROM " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + " ) 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.rowCount(); i++ )
|
|
{
|
|
Integer ano = array.get( i, 0 );
|
|
list.add( ano );
|
|
}
|
|
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\u00c7\u00d5ES";
|
|
}
|
|
else if( estado == Global.ESTADO_RH2 )
|
|
{
|
|
return "FASE 4 - RH - MEDIDAS + LES\u00c3O";
|
|
}
|
|
else if( estado == Global.ESTADO_CONSOLIDACAO )
|
|
{
|
|
return "FASE 5 - SIPRP - CONSOLIDA\u00c7\u00c3O";
|
|
}
|
|
else if( estado == Global.ESTADO_ASSINATURA_SEG )
|
|
{
|
|
return "FASE 6 - SEG - VERIFICA\u00c7\u00c3O SEG.";
|
|
}
|
|
else if( estado == Global.ESTADO_ASSINATURA_RH )
|
|
{
|
|
return "FASE 7 - RH - VERIFICA\u00c7\u00c3O RH";
|
|
}
|
|
else if( estado == Global.ESTADO_FECHAR )
|
|
{
|
|
return "FASE 8 - SIPRP - CONCLUS\u00c3O";
|
|
}
|
|
else if( estado == Global.ESTADO_CONCLUIDO )
|
|
{
|
|
return "FASE 9 - CONCLU\u00cdDO";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static final ModelProvider MODEL_PROVIDER;
|
|
|
|
static
|
|
{
|
|
|
|
ModelProvider tmp = null;
|
|
try
|
|
{
|
|
Connection connection = ( Connection ) Singleton.getInstance( "CONNECTION_OBJECT" );
|
|
if( connection == null )
|
|
{
|
|
String connectionURL = ( String ) Singleton.getInstance( DBConstants.CONNECTION_URL );
|
|
String username = DBPropertiesLoader.getInstance().findProperty( DBConstants.USERNAME_SIPRP );
|
|
String password = DBPropertiesLoader.getInstance().findProperty( DBConstants.PASSWORD_SIPRP );
|
|
|
|
try
|
|
{
|
|
connection = Connector.getConnection( connectionURL, username, password );
|
|
}
|
|
catch( SQLException ignored )
|
|
{
|
|
}
|
|
}
|
|
tmp = new ModelProvider( connection );
|
|
}
|
|
catch( Exception ignored )
|
|
{
|
|
|
|
}
|
|
MODEL_PROVIDER = tmp;
|
|
}
|
|
|
|
public HashMap< String, Integer > getMetaData( String table ) throws Exception
|
|
{
|
|
HashMap< String, Integer > hash = new HashMap< String, Integer >();
|
|
|
|
for( DBColumn column : MODEL_PROVIDER.getTableByName( table ).getColumns() )
|
|
{
|
|
hash.put( ( String ) column.get( DBColumn.NAME ), ( Integer ) column.get( DBColumn.LENGTH ) );
|
|
}
|
|
return hash;
|
|
}
|
|
|
|
public byte[] getLogoByEmpresa( Integer empresaID ) throws Exception
|
|
{
|
|
Expression dataFilter = new Field( db.data.siprp_local.outer.EmpresasData.ID_FULL ).isEqual( empresaID );
|
|
Select select = new Select2( db.data.siprp_local.outer.EmpresasData.TABLENAME, dataFilter,
|
|
db.data.siprp_local.outer.EmpresasData.EMPRESA_LOGO_ID_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? getLogo( ( Integer ) array.get( 0, 0 ) ) : null;
|
|
}
|
|
|
|
private byte[] getLogo( Integer logoID ) throws Exception
|
|
{
|
|
Expression dataFilter = new Field( db.data.siprp_local.outer.ImageData.ID_FULL ).isEqual( logoID );
|
|
Select select = new Select2( db.data.siprp_local.outer.ImageData.TABLENAME, dataFilter,
|
|
db.data.siprp_local.outer.ImageData.IMAGE_DATA_FULL );
|
|
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
|
|
return array.rowCount() > 0 ? ( byte[] ) array.get( 0, 0 ) : null;
|
|
}
|
|
|
|
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() );
|
|
}
|
|
analise.setParticipado( ( analiseBean.getParticipado() != null && analiseBean.getParticipado() ) ? "y" : "n" );
|
|
analise.setNome_responsavel_participacao( analiseBean.getNomeResponsavelParticipacao() );
|
|
analise.setData_participacao( analiseBean.getDataParticipacao() );
|
|
|
|
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;
|
|
}
|
|
|
|
private static class CommonExpression
|
|
{
|
|
private String nome;
|
|
private String visitaDate;
|
|
private String por;
|
|
private Integer fromYear;
|
|
private Expression where;
|
|
private String[] tables;
|
|
private Expression[] joinConditions;
|
|
private Integer[] joinTypes;
|
|
private Integer estabelecimentoID;
|
|
|
|
public CommonExpression( String nome, Integer estabelecimentoID, String visitaDate, String por, Integer fromYear )
|
|
{
|
|
this.nome = nome;
|
|
this.estabelecimentoID = estabelecimentoID;
|
|
this.visitaDate = visitaDate;
|
|
this.por = por;
|
|
this.fromYear = fromYear;
|
|
}
|
|
|
|
public Expression getWhere()
|
|
{
|
|
return where;
|
|
}
|
|
|
|
public String[] getTables()
|
|
{
|
|
return tables;
|
|
}
|
|
|
|
public Expression[] getJoinConditions()
|
|
{
|
|
return joinConditions;
|
|
}
|
|
|
|
public Integer[] getJoinTypes()
|
|
{
|
|
return joinTypes;
|
|
}
|
|
|
|
public CommonExpression invoke()
|
|
{
|
|
where = new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" );
|
|
tables = null;
|
|
joinConditions = null;
|
|
joinTypes = null;
|
|
|
|
if( nome != null || por != null )
|
|
{
|
|
tables = new String[]{ AnalisesAcidentesData.TABLENAME, AcidentadosData.TABLENAME };
|
|
joinTypes = new Integer[]{ Select2.JOIN_INNER };
|
|
joinConditions =
|
|
new Expression[]{ new Field( AcidentadosData.ID_FULL ).isEqual( AnalisesAcidentesData.ACIDENTADO_ID_FULL ) };
|
|
}
|
|
else
|
|
{
|
|
tables = new String[]{ AnalisesAcidentesData.TABLENAME };
|
|
}
|
|
|
|
if( nome != null )
|
|
{
|
|
nome = StringPlainer.convertString( nome.trim() );
|
|
nome = nome.replaceAll( " ", "%" );
|
|
where = where.and( new Field( "plain_utf8( " + AcidentadosData.NOME_FULL + " )" ).isILike( "%" + nome + "%" ) );
|
|
}
|
|
if( visitaDate != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.DATA_ACIDENTE_FULL ).isEqual( visitaDate ) );
|
|
}
|
|
if( estabelecimentoID != null )
|
|
{
|
|
where = where.and( new Field( AnalisesAcidentesData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) );
|
|
}
|
|
if( por != null )
|
|
{
|
|
where =
|
|
where.and( new Field( AcidentadosData.NUMERO_MECANOGRAFICO_FULL ).isILike( "%" + por.toUpperCase() + "%" ) );
|
|
}
|
|
|
|
if( visitaDate == null )
|
|
{
|
|
where = where.and(
|
|
new Field( "EXTRACT( year from " + AnalisesAcidentesData.DATA_ACIDENTE_FULL + ")" ).isEqual( fromYear ) );
|
|
}
|
|
return this;
|
|
}
|
|
}
|
|
}
|