@ -23,7 +23,9 @@ import org.apache.velocity.app.*;
public class doGetListaTrabalhadoresPendentes
extends siprpServlet
{
protected java . util . Date today ;
protected long todayMillis ;
/** Creates a new instance of doGetListaTrabalhadores */
public doGetListaTrabalhadoresPendentes ( HttpServletRequest req , HttpServletResponse res , boolean print ) throws IOException
{
@ -37,6 +39,9 @@ public class doGetListaTrabalhadoresPendentes
Vector links = new Vector ( ) ;
Vector desc = new Vector ( ) ;
Vector descAdicional = new Vector ( ) ;
today = new java . util . Date ( ) ;
todayMillis = today . getTime ( ) ;
try
{
userRole = ( String ) session . getAttribute ( super . sessionUserRole ) ;
@ -46,89 +51,88 @@ public class doGetListaTrabalhadoresPendentes
if ( userRole . equals ( super . superUserRole ) | | userRole . equals ( empresaId ) )
{
Class . forName ( super . bdDriver ) ;
con = DriverManager . getConnection ( super . bdUrl , super . bdUsername , super . bd Password ) ;
con = DriverManager . getConnection ( bdLocalUrl , bdLocalUsername , bdLocal Password ) ;
if ( super . verificaEstabelecimento ( con , empresaId , estabelecimentoId ) ) // estabelecimento pertence à empresa ??
{
//Class.forName(super.bdDriver);
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
dbQuery = new StringBuffer ( ) ;
dbQuery . append ( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' ),"
+ " ( ultimo_exame IS NOT NULL AND realizado = 'y' ),"
+ " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
+ " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
+ " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
+ " FROM trabalhadores "
+ " WHERE estabelecimento_id = '" + estabelecimentoId + "'"
+ " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
+ " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
+ " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
+ " ORDER BY nome" ) ;
dbQuery . append ( "SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.realizada "
+ "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id )"
+ "WHERE estabelecimento_id = " + estabelecimentoId
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
+ "ORDER BY 2, 3, 4 DESC " ) ;
// dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' ),"
// + " ( ultimo_exame IS NOT NULL AND realizado = 'y' ),"
// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
// + " FROM trabalhadores "
// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
// + " ORDER BY nome" );
stmt = con . createStatement ( ResultSet . TYPE_SCROLL_INSENSITIVE , ResultSet . CONCUR_READ_ONLY ) ;
rs = new ResultSet2DArray ( stmt . executeQuery ( dbQuery . toString ( ) ) ) ;
int index = 0 ;
int max = rs . columnLength ( ) ;
while ( index < max )
Integer trabalhadorID = new Integer ( - 1 ) ;
String nomeTrabalhador = "" ;
Vector consultas = new Vector ( ) ;
Vector exames = new Vector ( ) ;
for ( index = 0 ; index < = max ; index + + )
{
temp = "" + rs . get ( index , 0 ) ; // converter de int para String
dbQuery = new StringBuffer ( ) ;
dbQuery . append ( "/" + super . servletName + "/?" + empresaId + "/" + estabelecimentoId + "/" + temp ) ; // contruir url
links . add ( dbQuery . toString ( ) ) ;
HashMap trabalhador = new HashMap ( ) ;
trabalhador . put ( "Nome" , ( String ) rs . get ( index , 1 ) ) ;
boolean uc = ( ( Boolean ) rs . get ( index , 2 ) ) . booleanValue ( ) ;
boolean ue = ( ( Boolean ) rs . get ( index , 3 ) ) . booleanValue ( ) ;
boolean pc = ( ( Boolean ) rs . get ( index , 4 ) ) . booleanValue ( ) ;
boolean pe = ( ( Boolean ) rs . get ( index , 5 ) ) . booleanValue ( ) ;
boolean quase_c = ( ( Boolean ) rs . get ( index , 6 ) ) . booleanValue ( ) ;
boolean quase_e = ( ( Boolean ) rs . get ( index , 7 ) ) . booleanValue ( ) ;
if ( quase_c )
{
trabalhador . put ( "Consulta" , "yellow" ) ;
trabalhador . put ( "Consulta_estado" , "marcado" ) ;
}
else if ( uc )
{
trabalhador . put ( "Consulta" , "green" ) ;
trabalhador . put ( "Consulta_estado" , "tratado" ) ;
}
else if ( pc )
Integer id = index < max ? ( Integer ) rs . get ( index , 0 ) : new Integer ( - 1 ) ;
if ( ! id . equals ( trabalhadorID ) )
{
trabalhador . put ( "Consulta" , "yellow" ) ;
trabalhador . put ( "Consulta_estado" , "marcado" ) ;
Object listaConsultas [ ] [ ] = ( Object [ ] [ ] ) consultas . toArray ( new Object [ consultas . size ( ) ] [ 2 ] ) ;
Object listaExames [ ] [ ] = ( Object [ ] [ ] ) exames . toArray ( new Object [ exames . size ( ) ] [ 2 ] ) ;
if ( trabalhadorID . intValue ( ) > - 1 & &
verificarTrabalhador ( listaConsultas , listaExames ) )
{
temp = "" + rs . get ( index - 1 , 0 ) ; // converter de int para String
dbQuery = new StringBuffer ( ) ;
dbQuery . append ( "/" + super . servletName + "/?" + empresaId + "/" + estabelecimentoId + "/" + temp ) ; // contruir url
links . add ( dbQuery . toString ( ) ) ;
desc . add ( criarDadosTrabalhador ( con , trabalhadorID , nomeTrabalhador , listaConsultas , listaExames ) ) ;
}
exames . clear ( ) ;
consultas . clear ( ) ;
}
else
if ( index = = max )
{
trabalhador . put ( "Consulta" , "red" ) ;
trabalhador . put ( "Consulta_estado" , "pendente" ) ;
break ;
}
if ( quase_e )
Integer tipo = ( Integer ) rs . get ( index , 2 ) ;
String nome = ( String ) rs . get ( index , 1 ) ;
java . util . Date data = ( java . util . Date ) rs . get ( index , 3 ) ;
String realizada = ( String ) rs . get ( index , 4 ) ;
trabalhadorID = id ;
nomeTrabalhador = nome ;
Object marcacao [ ] = new Object [ ] { data , realizada } ;
if ( tipo = = null )
{
trabalhador . put ( "Exame" , "yellow" ) ;
trabalhador . put ( "Exame_estado" , "marcado" ) ;
continue ;
}
else if ( ue )
switch( tipo . intValue ( ) )
{
trabalhador . put ( "Exame" , "green" ) ;
trabalhador . put ( "Exame_estado" , "tratado" ) ;
case TIPO_MARCACAO_EXAMES :
exames . add ( marcacao ) ;
break ;
case TIPO_MARCACAO_CONSULTA :
consultas . add ( marcacao ) ;
break ;
}
else if ( pe )
{
trabalhador . put ( "Exame" , "yellow" ) ;
trabalhador . put ( "Exame_estado" , "marcado" ) ;
}
else
{
trabalhador . put ( "Exame" , "red" ) ;
trabalhador . put ( "Exame_estado" , "pendente" ) ;
}
desc . add ( trabalhador ) ;
+ + index ;
}
stmt . close ( ) ;
sBuffer = new StringBuffer ( ) ;
sBuffer . append ( "<b>" + super . nomeEmpresa ( con , empresaId ) + "</b><br><br><i>"
+ super . nomeEstabelecimento ( con , estabelecimentoId ) + "</i>" ) ;
@ -179,4 +183,156 @@ public class doGetListaTrabalhadoresPendentes
}
}
protected boolean verificarTrabalhador ( Object consultas [ ] [ ] , Object exames [ ] [ ] )
{
boolean estadoConsultas = false ;
boolean estadoExames = ( exames . length = = 0 ) | | ( ( java . util . Date ) exames [ 0 ] [ 0 ] ) . before ( today ) | |
( ( ( ( java . util . Date ) exames [ 0 ] [ 0 ] ) . getTime ( ) - todayMillis ) / 86400000 > 14 ) ;
if ( consultas . length > 0 )
{
int anterior ;
int proxima ;
if ( ( ( java . util . Date ) consultas [ 0 ] [ 0 ] ) . after ( today ) )
{
proxima = 0 ;
if ( consultas . length > = 2 )
{
anterior = 1 ;
}
else
{
anterior = - 1 ;
}
}
else
{
proxima = - 1 ;
anterior = 0 ;
}
estadoConsultas = anterior > = 0 & & "y" . equals ( consultas [ anterior ] [ 1 ] ) & &
( proxima = = - 1 | | ( ( ( java . util . Date ) consultas [ proxima ] [ 0 ] ) . getTime ( ) - todayMillis ) / 86400000 > 14 ) ;
}
return ! ( estadoConsultas & & estadoExames ) ;
}
protected HashMap criarDadosTrabalhador ( Connection con , Integer id , String nome ,
Object consultas [ ] [ ] , Object exames [ ] [ ] )
throws Exception
{
// dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' ),"
// + " ( ultimo_exame IS NOT NULL AND realizado = 'y' ),"
// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
// + " FROM trabalhadores "
// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
// + " ORDER BY nome" );
HashMap trabalhador = new HashMap ( ) ;
trabalhador . put ( "Nome" , nome ) ;
boolean uc = false ;
boolean ue = false ;
boolean pc = false ;
boolean pe = false ;
boolean quase_c = false ;
boolean quase_e = false ;
if ( consultas . length > 0 )
{
int anterior ;
int proxima ;
if ( ( ( java . util . Date ) consultas [ 0 ] [ 0 ] ) . after ( today ) )
{
proxima = 0 ;
if ( consultas . length > = 2 )
{
anterior = 1 ;
}
else
{
anterior = - 1 ;
}
}
else
{
proxima = - 1 ;
anterior = 0 ;
}
long diff = proxima > - 1 ? ( ( ( java . util . Date ) consultas [ proxima ] [ 0 ] ) . getTime ( ) - todayMillis ) / 86400000 : 15 ;
uc = anterior > - 1 & & "y" . equals ( consultas [ anterior ] [ 1 ] ) ;
pc = proxima > - 1 ;
quase_c = pc & & diff < = 14 ;
}
if ( exames . length > 0 )
{
int anterior ;
int proximo ;
if ( ( ( java . util . Date ) exames [ 0 ] [ 0 ] ) . after ( today ) )
{
proximo = 0 ;
if ( exames . length > = 2 )
{
anterior = 1 ;
}
else
{
anterior = - 1 ;
}
}
else
{
proximo = - 1 ;
anterior = 0 ;
}
long diff = proximo > - 1 ? ( ( ( java . util . Date ) exames [ proximo ] [ 0 ] ) . getTime ( ) - todayMillis ) / 86400000 : 15 ;
ue = anterior > - 1 & & "y" . equals ( exames [ anterior ] [ 1 ] ) ;
pe = proximo > - 1 ;
quase_e = pe & & diff < = 14 ;
}
if ( quase_c )
{
trabalhador . put ( "Consulta" , "yellow" ) ;
trabalhador . put ( "Consulta_estado" , "marcado" ) ;
}
else if ( uc )
{
trabalhador . put ( "Consulta" , "green" ) ;
trabalhador . put ( "Consulta_estado" , "tratado" ) ;
}
else if ( pc )
{
trabalhador . put ( "Consulta" , "yellow" ) ;
trabalhador . put ( "Consulta_estado" , "marcado" ) ;
}
else
{
trabalhador . put ( "Consulta" , "red" ) ;
trabalhador . put ( "Consulta_estado" , "pendente" ) ;
}
if ( quase_e )
{
trabalhador . put ( "Exame" , "yellow" ) ;
trabalhador . put ( "Exame_estado" , "marcado" ) ;
}
else if ( ue )
{
trabalhador . put ( "Exame" , "green" ) ;
trabalhador . put ( "Exame_estado" , "tratado" ) ;
}
else if ( pe )
{
trabalhador . put ( "Exame" , "yellow" ) ;
trabalhador . put ( "Exame_estado" , "marcado" ) ;
}
else
{
trabalhador . put ( "Exame" , "red" ) ;
trabalhador . put ( "Exame_estado" , "pendente" ) ;
}
return trabalhador ;
}
}