no message

git-svn-id: https://svn.coded.pt/svn/SIPRP@533 bb69d46d-e84e-40c8-a05a-06db0d633741
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Frederico Palma 20 years ago
parent 3ab4835e36
commit 175cfc70cb

@ -29,8 +29,8 @@ import com.evolute.utils.strings.*;
public class doGetListaTrabalhadoresPendentes public class doGetListaTrabalhadoresPendentes
extends siprpServlet extends siprpServlet
{ {
private static final int TRES_MESES = 3 * 30 * 24 * 60 * 60 * 1000; private static final long TRES_MESES = 3L * 30L * 24L * 60L * 60L * 1000L;
private static final int CATORZE_DIAS = 14 * 24 * 60 * 60 * 1000; private static final long CATORZE_DIAS = 14L * 24L * 60L * 60L * 1000L;
protected static final int ESTADO_NAO_APLICAVEL = 0; protected static final int ESTADO_NAO_APLICAVEL = 0;
protected static final int ESTADO_PENDENTE = 1; protected static final int ESTADO_PENDENTE = 1;
@ -289,12 +289,22 @@ public class doGetListaTrabalhadoresPendentes
+ " ORDER BY 6, 8, 3 DESC"; + " ORDER BY 6, 8, 3 DESC";
Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) ); Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) );
query = "SELECT trabalhadores.id, trabalhadores.nome "
+ "FROM trabalhadores "
+ "WHERE estabelecimento_id = " + estabelecimentoId
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL;";
Virtual2DArray trabalhadoresArray = executer.executeQuery( new Select( query ) );
Hashtable marcacoesPorID = new Hashtable(); Hashtable marcacoesPorID = new Hashtable();
Hashtable ocasionaisPorID = new Hashtable(); Hashtable ocasionaisPorID = new Hashtable();
Hashtable nomesPorID = new Hashtable(); Hashtable nomesPorID = new Hashtable();
for( int n = 0; n < trabalhadoresArray.columnLength(); n++ )
{
nomesPorID.put( trabalhadoresArray.get( n, 0 ), trabalhadoresArray.get( n, 1 ) );
}
preencherMarcacoes( array, nomesPorID, marcacoesPorID ); preencherMarcacoes( array, nomesPorID, marcacoesPorID );
preencherMarcacoes( array, nomesPorID, ocasionaisPorID ); preencherMarcacoes( ocasionaisArray, nomesPorID, ocasionaisPorID );
Integer ids[] = ( Integer[] ) nomesPorID.keySet().toArray( new Integer[0] ); Integer ids[] = ( Integer[] ) nomesPorID.keySet().toArray( new Integer[0] );
IDObject trabalhadores[] = new IDObject[ ids.length ]; IDObject trabalhadores[] = new IDObject[ ids.length ];
@ -313,13 +323,30 @@ public class doGetListaTrabalhadoresPendentes
for( int n = 0; n < trabalhadores.length; n++ ) for( int n = 0; n < trabalhadores.length; n++ )
{ {
Object marcacoes[][] = ( Object[][] ) ( ( Vector )marcacoesPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] ); Object marcacoes[][];
Object ocasionais[][] = ( Object[][] ) ( ( Vector )ocasionaisPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] ); if( marcacoesPorID.containsKey( trabalhadores[ n ].getID() ) )
{
marcacoes = ( Object[][] ) ( ( Vector )marcacoesPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] );
}
else
{
marcacoes = new Object[0][];
}
Object ocasionais[][];
if( ocasionaisPorID.containsKey( trabalhadores[ n ].getID() ) )
{
ocasionais = ( Object[][] ) ( ( Vector )ocasionaisPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] );
}
else
{
ocasionais = new Object[ 0 ][];
}
Object agrupadas[][] = agruparMarcacoes( marcacoes, ocasionais ); Object agrupadas[][] = agruparMarcacoes( marcacoes, ocasionais );
acrescentarTrabalhador( empresaId, estabelecimentoId, acrescentarTrabalhador( empresaId, estabelecimentoId,
trabalhadores[ n ], null, trabalhadores[ n ], null,
agrupadas, links, desc, agrupadas, links, desc,
true, true ); perfilTemConsultas( trabalhadores[ n ].getID(), new Integer( empresaId ) ),
perfilTemExames( trabalhadores[ n ].getID(), new Integer( empresaId ) ) );
} }
HashMap hmValues = new HashMap(); HashMap hmValues = new HashMap();
@ -384,14 +411,17 @@ public class doGetListaTrabalhadoresPendentes
nomesPorID.put( id, nome ); nomesPorID.put( id, nome );
marcacoesPorID.put( id, new Vector() ); marcacoesPorID.put( id, new Vector() );
} }
Object marcacao[] = new Object[]{ data, estado, motivo, tipo }; if( data != null )
( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao ); {
Object marcacao[] = new Object[]{ data, estado, motivo, tipo };
( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao );
}
} }
} }
protected Object[][] agruparMarcacoes( Object marcacoes[][], Object ocasionais[][] ) protected Object[][] agruparMarcacoes( Object marcacoes[][], Object ocasionais[][] )
{ {
int tresMeses = TRES_MESES; long tresMeses = TRES_MESES;
java.util.Date dataExame = null; java.util.Date dataExame = null;
Integer estadoExame = null; Integer estadoExame = null;
java.util.Date dataConsulta = null; java.util.Date dataConsulta = null;
@ -428,7 +458,7 @@ public class doGetListaTrabalhadoresPendentes
dataExame = data; dataExame = data;
estadoExame = estado; estadoExame = estado;
} }
else if( Math.abs( dataConsulta.getTime() - data.getTime() ) < tresMeses ) else if( dataConsulta != null && Math.abs( dataConsulta.getTime() - data.getTime() ) < tresMeses )
{ {
dataExame = data; dataExame = data;
estadoExame = estado; estadoExame = estado;
@ -472,9 +502,9 @@ public class doGetListaTrabalhadoresPendentes
for( int n = 0; n < ocasionais.length; n++ ) for( int n = 0; n < ocasionais.length; n++ )
{ {
grupo = new Object[ 5 ]; grupo = new Object[ 5 ];
for( int i = 0; i < ocasionais[ n ].length; i++ ) for( int i = 0; i < 3; i++ )
{ {
grupo[ i ] = ocasionais[ i ]; grupo[ i ] = ocasionais[ n ][ i ];
} }
grupos.add( grupo ); grupos.add( grupo );
} }
@ -501,6 +531,7 @@ public class doGetListaTrabalhadoresPendentes
{ {
int estado[] = new int[ 2 ]; int estado[] = new int[ 2 ];
int index = 0; int index = 0;
boolean pendente = false;
if( marcacoes.length == 0 ) if( marcacoes.length == 0 )
{ {
estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL; estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
@ -524,7 +555,6 @@ public class doGetListaTrabalhadoresPendentes
if( ( temConsulta && consultaAntiga && temExame && exameAntigo ) || if( ( temConsulta && consultaAntiga && temExame && exameAntigo ) ||
( temConsulta && consultaAntiga && !temExame && !exameAntigo ) || ( temConsulta && consultaAntiga && !temExame && !exameAntigo ) ||
( !temConsulta && !consultaAntiga && temExame && exameAntigo ) ) ( !temConsulta && !consultaAntiga && temExame && exameAntigo ) )
{ {
break; break;
} }
@ -533,12 +563,11 @@ public class doGetListaTrabalhadoresPendentes
{ {
index = 0; index = 0;
} }
else if( index < marcacoes.length - 1 ) // else if( index < marcacoes.length - 1 )
{ // {
index = 0; // index = 0;
} // }
boolean found = false; for( ; index < marcacoes.length; index++ )
for( ; !found && index < marcacoes.length; index++ )
{ {
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ]; dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
@ -548,7 +577,7 @@ public class doGetListaTrabalhadoresPendentes
long diffExame = temExame ? dataExame.getTime() - today.getTime() : 0; long diffExame = temExame ? dataExame.getTime() - today.getTime() : 0;
if( ( temConsulta && diffConsulta < CATORZE_DIAS ) || ( temExame && diffExame < CATORZE_DIAS ) ) if( ( temConsulta && diffConsulta < CATORZE_DIAS ) || ( temExame && diffExame < CATORZE_DIAS ) )
{ {
found = true; break;
} }
} }
if( index >= marcacoes.length ) if( index >= marcacoes.length )
@ -564,9 +593,17 @@ public class doGetListaTrabalhadoresPendentes
Calendar calToday = Calendar.getInstance(); Calendar calToday = Calendar.getInstance();
calToday.setTime( today ); calToday.setTime( today );
calToday.add( Calendar.YEAR, -2 ); calToday.add( Calendar.YEAR, -2 );
if( dataConsulta.before( calToday.getTime() ) ) if( ( dataConsulta != null && dataConsulta.before( calToday.getTime() ) )
|| ( dataConsulta == null && dataExame != null && dataExame.before( calToday.getTime() ) ) )
{ {
index++; if( index > 0 )
{
index--;
}
else
{
pendente = true;
}
} }
} }
} }
@ -577,7 +614,7 @@ public class doGetListaTrabalhadoresPendentes
Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ]; Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ];
if( perfilConsultas ) if( perfilConsultas )
{ {
if( dataConsulta == null ) if( dataConsulta == null || pendente )
{ {
estado[ 0 ] = ESTADO_PENDENTE; estado[ 0 ] = ESTADO_PENDENTE;
} }
@ -596,7 +633,7 @@ public class doGetListaTrabalhadoresPendentes
} }
if( perfilExames ) if( perfilExames )
{ {
if( dataExame == null ) if( dataExame == null || pendente )
{ {
if( motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL ) if( motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL )
{ {
@ -621,16 +658,60 @@ public class doGetListaTrabalhadoresPendentes
estado[ 1 ] = ESTADO_NAO_APLICAVEL; estado[ 1 ] = ESTADO_NAO_APLICAVEL;
} }
} }
links.add( "/"+servletName+"/?"+empresaID+"/"+estabelecimentoID+"/"+trabalhador.getID() ); if( estado[ 0 ] == 1 || estado[ 0 ] == 2 ||
HashMap dadosTrabalhador = new HashMap(); estado[ 1 ] == 1 || estado[ 1 ] == 2 )
dadosTrabalhador.put( "Nome", trabalhador.toString() ); {
dadosTrabalhador.put( "Consulta", CORES_ESTADOS.get( new Integer( estado[ 0 ] ) ) ); links.add( "/"+servletName+"/?"+empresaID+"/"+estabelecimentoID+"/"+trabalhador.getID() );
Object text = TEXTOS_ESTADOS.get( new Integer( estado[ 0 ] ) ); HashMap dadosTrabalhador = new HashMap();
dadosTrabalhador.put( "Consulta_estado", text != null ? text : marcacoes[ index ][ 0 ] ); dadosTrabalhador.put( "Nome", trabalhador.toString() );
dadosTrabalhador.put( "Exame", CORES_ESTADOS.get( new Integer( estado[ 1 ] ) ) ); dadosTrabalhador.put( "Consulta", CORES_ESTADOS.get( new Integer( estado[ 0 ] ) ) );
text = TEXTOS_ESTADOS.get( new Integer( estado[ 0 ] ) ); Object text = TEXTOS_ESTADOS.get( new Integer( estado[ 0 ] ) );
dadosTrabalhador.put( "Exame_estado", text != null ? text : marcacoes[ index ][ 3 ] ); dadosTrabalhador.put( "Consulta_estado", text != null ? text : marcacoes[ index ][ 0 ] );
dados.add( dadosTrabalhador ); dadosTrabalhador.put( "Exame", CORES_ESTADOS.get( new Integer( estado[ 1 ] ) ) );
text = TEXTOS_ESTADOS.get( new Integer( estado[ 1 ] ) );
dadosTrabalhador.put( "Exame_estado", text != null ? text : marcacoes[ index ][ 3 ] );
dados.add( dadosTrabalhador );
}
}
protected boolean perfilTemConsultas( Integer trabalhadorID, Integer empresaID )
throws Exception
{
Executer executer = getExecuter();
String query = "SELECT a_consultas, b_consultas FROM empresas WHERE id = " + empresaID;
Virtual2DArray array = executer.executeQuery( new Select( query ) );
boolean consultas[] = new boolean[]{ "y".equals( array.get( 0, 0 ) ), "n".equals( array.get( 0, 0 ) ) };
query = "SELECT perfil FROM trabalhadores WHERE id = " + trabalhadorID;
array = executer.executeQuery( new Select( query ) );
Integer perfil = ( Integer )array.get( 0, 0 );
if( perfil != null )
{
return consultas[ perfil.intValue() - 1 ];
}
else
{
return false;
}
}
protected boolean perfilTemExames( Integer trabalhadorID, Integer empresaID )
throws Exception
{
Executer executer = getExecuter();
String query = "SELECT a_exames, b_exames FROM empresas WHERE id = " + empresaID;
Virtual2DArray array = executer.executeQuery( new Select( query ) );
boolean consultas[] = new boolean[]{ "y".equals( array.get( 0, 0 ) ), "n".equals( array.get( 0, 0 ) ) };
query = "SELECT perfil FROM trabalhadores WHERE id = " + trabalhadorID;
array = executer.executeQuery( new Select( query ) );
Integer perfil = ( Integer )array.get( 0, 0 );
if( perfil != null )
{
return consultas[ perfil.intValue() - 1 ];
}
else
{
return false;
}
} }
// protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] ) // protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] )
@ -665,134 +746,134 @@ public class doGetListaTrabalhadoresPendentes
// return !(estadoConsultas && estadoExames); // return !(estadoConsultas && estadoExames);
// } // }
protected HashMap criarDadosTrabalhador( Integer id, String nome, // protected HashMap criarDadosTrabalhador( Integer id, String nome,
Object consultas[][], Object exames[][] ) // Object consultas[][], Object exames[][] )
throws Exception // throws Exception
{ // {
// dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' )," //// dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' ),"
// + " ( ultimo_exame IS NOT NULL AND realizado = 'y' )," //// + " ( ultimo_exame IS NOT NULL AND realizado = 'y' ),"
// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, " //// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), " //// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )" //// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
// + " FROM trabalhadores " //// + " FROM trabalhadores "
// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'" //// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR" //// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )" //// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )" //// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
// + " ORDER BY nome" ); //// + " ORDER BY nome" );
HashMap trabalhador = new HashMap(); // HashMap trabalhador = new HashMap();
trabalhador.put( "Nome", nome ); // trabalhador.put( "Nome", nome );
boolean uc = false; // boolean uc = false;
boolean ue = false; // boolean ue = false;
boolean pc = false; // boolean pc = false;
boolean pe = false; // boolean pe = false;
boolean quase_c = false; // boolean quase_c = false;
boolean quase_e = false; // boolean quase_e = false;
java.util.Date consultaAnterior = null; // java.util.Date consultaAnterior = null;
java.util.Date exameAnterior = null; // java.util.Date exameAnterior = null;
if( consultas.length > 0 ) // if( consultas.length > 0 )
{ // {
int anterior; // int anterior;
int proxima; // int proxima;
if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) ) // if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) )
{ // {
proxima = 0; // proxima = 0;
if( consultas.length >= 2 ) // if( consultas.length >= 2 )
{ // {
anterior = 1; // anterior = 1;
} // }
else // else
{ // {
anterior = -1; // anterior = -1;
} // }
} // }
else // else
{ // {
proxima = -1; // proxima = -1;
anterior = 0; // anterior = 0;
} // }
long diff = proxima > -1 ? ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 : 15; // long diff = proxima > -1 ? ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 : 15;
uc = anterior > -1 && "y".equals( consultas[ anterior ][ 1 ] ); // uc = anterior > -1 && "y".equals( consultas[ anterior ][ 1 ] );
if( uc ) // if( uc )
{ // {
consultaAnterior = ( java.util.Date ) consultas[ anterior ][ 0 ]; // consultaAnterior = ( java.util.Date ) consultas[ anterior ][ 0 ];
} // }
pc = proxima > -1; // pc = proxima > -1;
quase_c = pc && diff <= 14; // quase_c = pc && diff <= 14;
} // }
//
if( exames.length > 0 ) // if( exames.length > 0 )
{ // {
int anterior; // int anterior;
int proximo; // int proximo;
if( ( (java.util.Date) exames[ 0 ][ 0 ] ).after( today ) ) // if( ( (java.util.Date) exames[ 0 ][ 0 ] ).after( today ) )
{ // {
proximo = 0; // proximo = 0;
if( exames.length >= 2 ) // if( exames.length >= 2 )
{ // {
anterior = 1; // anterior = 1;
} // }
else // else
{ // {
anterior = -1; // anterior = -1;
} // }
} // }
else // else
{ // {
proximo = -1; // proximo = -1;
anterior = 0; // anterior = 0;
} // }
long diff = proximo > -1 ? ( ( ( java.util.Date )exames[ proximo ][ 0 ] ).getTime() - todayMillis ) / 86400000 : 15; // long diff = proximo > -1 ? ( ( ( java.util.Date )exames[ proximo ][ 0 ] ).getTime() - todayMillis ) / 86400000 : 15;
ue = anterior > -1 && "y".equals( exames[ anterior ][ 1 ] ); // ue = anterior > -1 && "y".equals( exames[ anterior ][ 1 ] );
if( ue ) // if( ue )
{ // {
exameAnterior = ( java.util.Date ) exames[ anterior ][ 0 ]; // exameAnterior = ( java.util.Date ) exames[ anterior ][ 0 ];
} // }
pe = proximo > -1; // pe = proximo > -1;
quase_e = pe && diff <= 14; // quase_e = pe && diff <= 14;
} // }
//
if( quase_c ) // if( quase_c )
{ // {
trabalhador.put( "Consulta", "yellow" ); // trabalhador.put( "Consulta", "yellow" );
trabalhador.put( "Consulta_estado", "pendente" ); // trabalhador.put( "Consulta_estado", "pendente" );
} // }
else if( uc ) // else if( uc )
{ // {
trabalhador.put( "Consulta", "green" ); // trabalhador.put( "Consulta", "green" );
trabalhador.put( "Consulta_estado", consultaAnterior ); // trabalhador.put( "Consulta_estado", consultaAnterior );
} // }
else if( pc ) // else if( pc )
{ // {
trabalhador.put( "Consulta", "yellow" ); // trabalhador.put( "Consulta", "yellow" );
trabalhador.put( "Consulta_estado", "pendente" ); // trabalhador.put( "Consulta_estado", "pendente" );
} // }
else // else
{ // {
trabalhador.put( "Consulta", "red" ); // trabalhador.put( "Consulta", "red" );
trabalhador.put( "Consulta_estado", "pendente" ); // trabalhador.put( "Consulta_estado", "pendente" );
} // }
//
if( quase_e ) // if( quase_e )
{ // {
trabalhador.put( "Exame", "yellow" ); // trabalhador.put( "Exame", "yellow" );
trabalhador.put( "Exame_estado", "pendente" ); // trabalhador.put( "Exame_estado", "pendente" );
} // }
else if( ue ) // else if( ue )
{ // {
trabalhador.put( "Exame", "green" ); // trabalhador.put( "Exame", "green" );
trabalhador.put( "Exame_estado", exameAnterior ); // trabalhador.put( "Exame_estado", exameAnterior );
} // }
else if( pe ) // else if( pe )
{ // {
trabalhador.put( "Exame", "yellow" ); // trabalhador.put( "Exame", "yellow" );
trabalhador.put( "Exame_estado", "pendente" ); // trabalhador.put( "Exame_estado", "pendente" );
} // }
else // else
{ // {
trabalhador.put( "Exame", "red" ); // trabalhador.put( "Exame", "red" );
trabalhador.put( "Exame_estado", "pendente" ); // trabalhador.put( "Exame_estado", "pendente" );
} // }
return trabalhador; // return trabalhador;
} // }
} }

Loading…
Cancel
Save