diff --git a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java
index dca6d6c5..d37cb616 100644
--- a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java
+++ b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java
@@ -23,7 +23,7 @@ public class doGetListaTrabalhadores extends siprpServlet
return rs;
}
- /** Creates a new instance of doGetListaTrabalhadores */
+
public doGetListaTrabalhadores(HttpServletRequest req, HttpServletResponse res, String query) throws IOException
{
boolean print = false;
@@ -90,100 +90,129 @@ public class doGetListaTrabalhadores extends siprpServlet
/** dados de consultas **/
- dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador "
- + "WHERE tipo = 1 and trabalhador_id = " + id
- + " ORDER BY data DESC";
- stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
- rs.getObjects();
- stmt.close();
- if( rs.columnLength() > 0 )
+// dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador "
+// + "WHERE tipo = 1 and trabalhador_id = " + id
+// + " ORDER BY data DESC";
+// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+// rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
+// rs.getObjects();
+// stmt.close();
+// if( rs.columnLength() > 0 )
+// {
+// java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
+// Integer estado2 = ( Integer ) rs.get( 0, 2 );
+// java.util.Date dataConsulta1;
+// Integer estado1;
+// String realizada1 = "";
+// String realizada2 = "";
+// if( rs.columnLength() >= 2 )
+// {
+// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
+// estado1 = ( Integer ) rs.get( 1, 2 );
+// }
+// else
+// {
+// dataConsulta1 = dataConsulta2;
+// estado1 = estado2;
+// }
+// if( ESTADO_REALIZADO.equals( estado2 ) || ( dataConsulta2 != null && today.after( dataConsulta2 ) ) )
+// {
+// trabalhador.put( "ultima_consulta", dataConsulta2 );
+// if( estado2.equals( ESTADO_POR_REALIZAR ) )
+// {
+// realizada2 = "não";
+// }
+// else if( estado2.equals( ESTADO_REALIZADO ) )
+// {
+// realizada2 = "sim";
+// }
+// trabalhador.put( "realizada", realizada2 );
+// trabalhador.put( "proxima_consulta", "" );
+// }
+// else
+// {
+// try
+// {
+// for( int c = 1; c < rs.columnLength(); c++ )
+// {
+// java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
+// dataConsulta1 = dataTemp;
+// estado1 = ( Integer ) rs.get( c, 2 );
+// if( dataTemp.after( today ) )
+// {
+// dataConsulta2 = dataTemp;
+// }
+// else
+// {
+// break;
+// }
+// }
+// }
+// catch( Exception ex )
+// {
+// ex.printStackTrace();
+// }
+// trabalhador.put( "proxima_consulta", dataConsulta2 );
+//
+// if( !dataConsulta2.equals( dataConsulta1 ) )
+// {
+// if( estado1.equals( ESTADO_POR_REALIZAR ) )
+// {
+// realizada1 = "não";
+// }
+// else if( estado1.equals( ESTADO_REALIZADO ) )
+// {
+// realizada1 = "sim";
+// }
+// trabalhador.put( "realizada", realizada1 );
+// trabalhador.put( "ultima_consulta", dataConsulta1 );
+// }
+// else
+// {
+// trabalhador.put( "ultima_consulta", "" );
+// trabalhador.put( "realizada", null );
+// }
+// }
+// }
+// else
+// {
+// trabalhador.put( "ultima_consulta", "" );
+// trabalhador.put( "realizada", null );
+// trabalhador.put( "proxima_consulta", "" );
+// }
+
+ dbQuery = "select id, data, estado " +
+ "from marcacoes_trabalhador " +
+ "where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + id + " " +
+ "order by data desc " +
+ "limit 1";
+ rs = executeQuery( con, dbQuery );
+
+ java.util.Date dataUltimaConsultaRealizada = null;
+ String consultaRealizada = "";
+ if ( rs.columnLength() > 0 )
{
- java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
- Integer estado2 = ( Integer ) rs.get( 0, 2 );
- java.util.Date dataConsulta1;
- // java.util.Date dataRelatorio1;
- // java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 );
- Integer estado1;
- String realizada1 = "";
- String realizada2 = "";
- if( rs.columnLength() >= 2 )
- {
- dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
- estado1 = ( Integer ) rs.get( 1, 2 );
- // dataRelatorio1 = (java.util.Date) rs.get( 1, 3 );
- }
- else
- {
- dataConsulta1 = dataConsulta2;
- estado1 = estado2;
- // dataRelatorio1 = dataRelatorio2;
- }
- if( ESTADO_REALIZADO.equals( estado2 ) || ( dataConsulta2 != null && today.after( dataConsulta2 ) ) )
- {
- trabalhador.put( "ultima_consulta", dataConsulta2 );
- if( estado2.equals( ESTADO_POR_REALIZAR ) )
- {
- realizada2 = "não";
- }
- else if( estado2.equals( ESTADO_REALIZADO ) )
- {
- realizada2 = "sim";
- }
- trabalhador.put( "realizada", realizada2 );
- trabalhador.put( "proxima_consulta", "" );
- }
- else
- {
- try
- {
- for( int c = 1; c < rs.columnLength(); c++ )
- {
- java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
- dataConsulta1 = dataTemp;
- estado1 = ( Integer ) rs.get( c, 2 );
- if( dataTemp.after( today ) )
- {
- dataConsulta2 = dataTemp;
- }
- else
- {
- break;
- }
- }
- }
- catch( Exception ex )
- {
- ex.printStackTrace();
- }
- trabalhador.put( "proxima_consulta", dataConsulta2 );
-
- if( !dataConsulta2.equals( dataConsulta1 ) )
- {
- if( estado1.equals( ESTADO_POR_REALIZAR ) )
- {
- realizada1 = "não";
- }
- else if( estado1.equals( ESTADO_REALIZADO ) )
- {
- realizada1 = "sim";
- }
- trabalhador.put( "realizada", realizada1 );
- trabalhador.put( "ultima_consulta", dataConsulta1 );
- }
- else
- {
- trabalhador.put( "ultima_consulta", "" );
- trabalhador.put( "realizada", null );
- }
- }
+ dataUltimaConsultaRealizada = ( java.util.Date ) rs.get( 0, 1 );
+ consultaRealizada = "Sim";
}
- else
+
+ dbQuery = "select id, data, estado " +
+ "from marcacoes_trabalhador " +
+ "where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + id + " " +
+ "order by data desc " +
+ "limit 1";
+ rs = executeQuery( con, dbQuery );
+
+ java.util.Date dataProximaConsulta = null;
+ if ( rs.columnLength() > 0 )
{
- trabalhador.put( "ultima_consulta", "" );
- trabalhador.put( "realizada", null );
- trabalhador.put( "proxima_consulta", "" );
+ dataProximaConsulta = ( java.util.Date ) rs.get( 0, 1 );
}
+
+ trabalhador.put( "ultima_consulta", dataUltimaConsultaRealizada == null ? "" : dataUltimaConsultaRealizada );
+ trabalhador.put( "realizada", consultaRealizada );
+ trabalhador.put( "proxima_consulta", dataProximaConsulta == null ? "" : dataProximaConsulta );
+ /** eof dados consulta **/
/** dados de exames **/
diff --git a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java
index 2eb9acc9..080cd09f 100644
--- a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java
+++ b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java
@@ -10,8 +10,8 @@ import java.io.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
-import java.sql.*;
import java.util.*;
+import java.sql.SQLException;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
@@ -57,7 +57,7 @@ public class doGetListaTrabalhadoresPendentes
// TEXTOS_ESTADOS.put( new Integer( ESTADO_TRATADO ), "green" );
}
- protected java.sql.Date today;
+ protected Date today;
protected long todayMillis;
/** Creates a new instance of doGetListaTrabalhadores */
@@ -227,43 +227,46 @@ public class doGetListaTrabalhadoresPendentes
// }
// }
- public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print )
+ public doGetListaTrabalhadoresPendentes( HttpServletRequest req, HttpServletResponse res, boolean print )
throws IOException
{
+ System.out.println( "\ndoGetListaTrabalhadoresPendentes() : " );
+
ServletOutputStream out = res.getOutputStream();
String userRole, empresaId, estabelecimentoId;
- HttpSession session = req.getSession(false);
+ HttpSession session = req.getSession( false );
Vector links = new Vector();
Vector desc = new Vector();
Vector descAdicional = new Vector();
-// today = new java.util.Date();
-// todayMillis = today.getTime();
-
+
try
{
Executer executer = getExecuter();
- Virtual2DArray array = executer.executeQuery( new Select( "SELECT CURRENT_DATE" ) );
- today = ( java.sql.Date ) array.get( 0, 0 );
+ today = new Date();
todayMillis = today.getTime();
- userRole = (String)session.getAttribute(sessionUserRole);
- empresaId = (String)session.getAttribute(sessionEmpresaId);
- estabelecimentoId = (String)session.getAttribute(sessionEstabelecimentoId);
+ userRole = ( String ) session.getAttribute( sessionUserRole );
+ empresaId = ( String ) session.getAttribute( sessionEmpresaId );
+ estabelecimentoId = ( String ) session.getAttribute( sessionEstabelecimentoId );
+ System.out.println( "\tuserRole : " + userRole );
+ System.out.println( "\tempresaID : " + empresaId );
+ System.out.println( "\testabelecimentoID : " + estabelecimentoId );
+
if ( userRole.equals ( superUserRole ) || userRole.equals ( empresaId ) )
{
- if ( verificaEstabelecimento(null, empresaId, estabelecimentoId) ) // estabelecimento pertence 'a empresa ??
+ if ( verificaEstabelecimento( null, empresaId, estabelecimentoId ) ) // estabelecimento pertence 'a empresa ??
{
- //Class.forName(super.bdDriver);
- //con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
String query = "( SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data "
+ "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 "
- + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
+ + " AND marcacoes_trabalhador.estado NOT IN ( 2, 3, 4, 5 ) "
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
+ + " AND marcacoes_trabalhador.deleted_stamp is null"
+ + " AND marcacoes_trabalhador.data < now()"
+ " AND marcacoes_trabalhador.motivo <> " + MOTIVO_OCASIONAL + " )"
+ " UNION "
+ "( SELECT trabalhadores.id, trabalhadores.nome, "
@@ -272,10 +275,12 @@ public class doGetListaTrabalhadoresPendentes
+ "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 "
- + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
+ + " AND marcacoes_trabalhador.estado NOT IN ( 2, 3, 4, 5 ) "
+ + " AND marcacoes_trabalhador.deleted_stamp is null"
+ + " AND marcacoes_trabalhador.data < now()"
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_EXAMES + " )"
- + "ORDER BY 6, 8, 3 DESC ";
- array = executer.executeQuery( new Select( query ) );
+ + " ORDER BY 6, 8, 3 DESC ";
+ Virtual2DArray array = executer.executeQuery( new Select( query ) );
query = "SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
@@ -283,9 +288,11 @@ public class doGetListaTrabalhadoresPendentes
+ "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 "
- + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
+ + " AND marcacoes_trabalhador.estado NOT IN ( 2, 3, 4, 5 ) "
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
+ " AND marcacoes_trabalhador.motivo = " + MOTIVO_OCASIONAL
+ + " AND marcacoes_trabalhador.data < now()"
+ + " AND marcacoes_trabalhador.deleted_stamp is null"
+ " ORDER BY 6, 8, 3 DESC";
Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) );
@@ -306,13 +313,13 @@ public class doGetListaTrabalhadoresPendentes
preencherMarcacoes( array, nomesPorID, marcacoesPorID );
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 ];
for( int n = 0; n < ids.length; n++ )
{
trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) );
}
- Arrays.sort( trabalhadores, new Comparator(){
+ Arrays.sort( trabalhadores, new Comparator() {
public int compare( Object o1, Object o2 )
{
String nome1 = StringPlainer.convertString( o1.toString() );
@@ -323,30 +330,25 @@ public class doGetListaTrabalhadoresPendentes
for( int n = 0; n < trabalhadores.length; n++ )
{
- Object marcacoes[][];
- if( marcacoesPorID.containsKey( trabalhadores[ n ].getID() ) )
+ Integer trabalhadorID = trabalhadores[ n ].getID();
+
+ Object marcacoes[][] = new Object[ 0 ][ ];
+ if ( marcacoesPorID.containsKey( trabalhadorID ) )
{
- marcacoes = ( Object[][] ) ( ( Vector )marcacoesPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] );
+ marcacoes = ( Object[][] ) ( ( Vector ) marcacoesPorID.get( trabalhadorID ) ).toArray( new Object[ 0 ][] );
}
- else
+ Object ocasionais[][] = new Object[ 0 ][ ];
+ if( ocasionaisPorID.containsKey( trabalhadorID ) )
{
- 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 ][];
+ ocasionais = ( Object[][] ) ( ( Vector ) ocasionaisPorID.get( trabalhadorID ) ).toArray( new Object[ 0 ][] );
}
+
Object agrupadas[][] = agruparMarcacoes( marcacoes, ocasionais );
acrescentarTrabalhador( empresaId, estabelecimentoId,
trabalhadores[ n ], null,
agrupadas, links, desc,
- perfilTemConsultas( trabalhadores[ n ].getID(), new Integer( empresaId ) ),
- perfilTemExames( trabalhadores[ n ].getID(), new Integer( empresaId ) ) );
+ perfilTemConsultas( trabalhadorID, new Integer( empresaId ) ),
+ perfilTemExames( trabalhadorID, new Integer( empresaId ) ) );
}
HashMap hmValues = new HashMap();
@@ -356,64 +358,64 @@ public class doGetListaTrabalhadoresPendentes
hmValues.put( "estabelecimento_id", estabelecimentoId );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
- hmValues.put( msgTemplate , ""+nomeEmpresa(null,empresaId)+"
"
- +nomeEstabelecimento(null, estabelecimentoId)+"" ) ;
- hmValues.put( templateUserRole, userRole);
+ hmValues.put( msgTemplate , "" + nomeEmpresa( null, empresaId ) + "
"
+ + nomeEstabelecimento( null, estabelecimentoId ) + "" ) ;
+ hmValues.put( templateUserRole, userRole );
hmValues.put( templateQuery, "trabalhadores_pendentes" );
- hmValues.put( templateVector1,links);
- hmValues.put( templateVector2,desc);
- hmValues.put( templateVector3,null);
- if( !print )
+ hmValues.put( templateVector1, links );
+ hmValues.put( templateVector2, desc );
+ hmValues.put( templateVector3, null );
+ if ( ! print )
{
- out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
+ out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate ) );
}
else
{
- out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate));
- }
-// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
+ out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate ) );
+ }
}
else // est nao pertence 'a empresa
{
- out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
+ out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) );
}
}
else // Role nao permite ver esta informacao
{
- out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
+ out.println( mergeTemplate( super.msgAcessoNegado, userRole, super.errorTemplate ) );
}
}
catch ( SQLException e )
{
e.printStackTrace();
- out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
+ out.println( mergeTemplate( super.msgErroBd, super.errorTemplate ) );
}
catch ( Exception e )
{
e.printStackTrace();
- out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
+ out.println( mergeTemplate( super.msgGenericError, super.errorTemplate ) );
}
}
+
protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID )
{
- int max = array.columnLength();
- for( int index = 0; index < max; index++ )
+ for ( int index = 0; index < array.columnLength(); index++ )
{
- Integer id = index < max ? ( Integer ) array.get( index, 0 ) : new Integer( -1 );
+ Integer id = ( Integer ) array.get( index, 0 );
Integer tipo = ( Integer ) array.get( index, 2 );
String nome = ( String ) array.get( index, 1 );
java.util.Date data = ( java.util.Date ) array.get( index, 3 );
Integer estado = ( Integer ) array.get( index, 4 );
Integer motivo = ( Integer ) array.get( index, 6 );
- if( !marcacoesPorID.containsKey( id ) )
+
+ if ( ! marcacoesPorID.containsKey( id ) )
{
nomesPorID.put( id, nome );
marcacoesPorID.put( id, new Vector() );
}
- if( data != null )
+ if ( data != null )
{
- Object marcacao[] = new Object[]{ data, estado, motivo, tipo };
+ Object marcacao[] = new Object[] { data, estado, motivo, tipo };
( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao );
}
}
@@ -430,11 +432,11 @@ public class doGetListaTrabalhadoresPendentes
Object grupo[] = null;
Vector grupos = new Vector();
- if( marcacoes != null )
+ if ( marcacoes != null )
{
- for( int n = 0; n < marcacoes.length; n++ )
+ for ( int n = 0; n < marcacoes.length; n++ )
{
- if( grupo == null )
+ if ( grupo == null )
{
grupo = new Object[ 5 ];
dataExame = null;
@@ -497,9 +499,9 @@ public class doGetListaTrabalhadoresPendentes
}
}
}
- if( ocasionais != null )
+ if ( ocasionais != null )
{
- for( int n = 0; n < ocasionais.length; n++ )
+ for ( int n = 0; n < ocasionais.length; n++ )
{
grupo = new Object[ 5 ];
for( int i = 0; i < 3; i++ )
@@ -511,7 +513,8 @@ public class doGetListaTrabalhadoresPendentes
}
Object agrupadas[][] = ( Object[][] ) grupos.toArray( new Object[ grupos.size() ][] );
- Arrays.sort( agrupadas, new Comparator(){
+ Arrays.sort( agrupadas, new Comparator()
+ {
public int compare( Object o1, Object o2 )
{
Object g1[] = ( Object[] ) o1;
@@ -529,20 +532,32 @@ public class doGetListaTrabalhadoresPendentes
Object marcacoes[][], Vector links, Vector dados,
boolean perfilConsultas, boolean perfilExames )
{
+
+// System.out.println( "\ndoGetListaTrabalhadoresPendentes . acrescentarTrabalhador( " + empresaID + ", " + estabelecimentoID + ", "
+// + trabalhador + ", " + dataFicha + ", " + marcacoes + ", " + links + ", " + dados + ", " + perfilConsultas + ", " + perfilExames + " ) : " );
+// System.out.println( "\tTrabalhador : " + trabalhador.getID() );
+
int estado[] = new int[ 2 ];
int index = 0;
boolean pendente = false;
- if( marcacoes.length == 0 )
+ if ( marcacoes.length == 0 )
{
+// System.out.println( "\tmarcacoes.length == 0 : true" );
+
estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
estado[ 1 ] = perfilExames ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
+
+// System.out.println( "\t\testado[ 0 ] : " + estado[ 0 ] );
+// System.out.println( "\t\testado[ 1 ] : " + estado[ 1 ] );
}
else
{
+// System.out.println( "\tmarcacoes.length == 0 : false" );
+
java.util.Date dataConsulta;
java.util.Date dataExame;
index = -1;
- for( ; index + 1 < marcacoes.length; index++ )
+ for ( ; index + 1 < marcacoes.length; index++ )
{
int n = index + 1;
dataConsulta = ( java.util.Date ) marcacoes[ n ][ 0 ];
@@ -553,21 +568,15 @@ public class doGetListaTrabalhadoresPendentes
boolean exameAntigo = temExame && dataExame.before( today );
if( ( temConsulta && consultaAntiga && temExame && exameAntigo ) ||
- ( temConsulta && consultaAntiga && !temExame && !exameAntigo ) ||
- ( !temConsulta && !consultaAntiga && temExame && exameAntigo ) )
+ ( temConsulta && consultaAntiga && ! temExame && ! exameAntigo ) ||
+ ( ! temConsulta && ! consultaAntiga && temExame && exameAntigo ) )
{
break;
}
}
- if( index == -1 )
- {
- index = 0;
- }
-// else if( index < marcacoes.length - 1 )
-// {
-// index = 0;
-// }
- for( ; index < marcacoes.length; index++ )
+
+ index = index == -1 ? 0 : index;
+ for ( ; index < marcacoes.length; index++ )
{
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
@@ -575,28 +584,29 @@ public class doGetListaTrabalhadoresPendentes
long diffConsulta = temConsulta ? dataConsulta.getTime() - today.getTime() : 0;
boolean temExame = dataExame != null;
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 ) )
{
break;
}
}
- if( index >= marcacoes.length )
+
+ if ( index >= marcacoes.length )
{
index = marcacoes.length - 1;
}
else
{
- if( marcacoes.length > 1 )
+ if ( marcacoes.length > 1 )
{
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
Calendar calToday = Calendar.getInstance();
calToday.setTime( today );
calToday.add( Calendar.YEAR, -2 );
- if( ( dataConsulta != null && dataConsulta.before( calToday.getTime() ) )
- || ( dataConsulta == null && dataExame != null && dataExame.before( calToday.getTime() ) ) )
+ if ( ( dataConsulta != null && dataConsulta.before( calToday.getTime() ) )
+ || ( dataConsulta == null && dataExame != null && dataExame.before( calToday.getTime() ) ) )
{
- if( index > 0 )
+ if ( index > 0 )
{
index--;
}
@@ -612,13 +622,13 @@ public class doGetListaTrabalhadoresPendentes
Integer motivoConsulta = ( Integer ) marcacoes[ index ][ 2 ];
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ];
- if( perfilConsultas )
+ if ( perfilConsultas )
{
- if( dataConsulta == null || pendente )
+ if ( dataConsulta == null || pendente )
{
estado[ 0 ] = ESTADO_PENDENTE;
}
- else if( estadoConsulta == null || estadoConsulta.intValue() != 2 )
+ else if ( estadoConsulta == null || estadoConsulta.intValue() != 2 )
{
estado[ 0 ] = ESTADO_MARCADO;
}
@@ -631,20 +641,15 @@ public class doGetListaTrabalhadoresPendentes
{
estado[ 0 ] = ESTADO_NAO_APLICAVEL;
}
- if( perfilExames )
+
+ if ( perfilExames )
{
- if( dataExame == null || pendente )
+ if ( dataExame == null || pendente )
{
- if( motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL )
- {
- estado[ 1 ] = ESTADO_PENDENTE;
- }
- else
- {
- estado[ 1 ] = ESTADO_NAO_APLICAVEL;
- }
+ estado[ 1 ] = motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL ?
+ ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL ;
}
- else if( estadoExame == null || estadoExame.intValue() != 2 )
+ else if ( estadoExame == null || estadoExame.intValue() != 2 )
{
estado[ 1 ] = ESTADO_MARCADO;
}
@@ -658,18 +663,29 @@ public class doGetListaTrabalhadoresPendentes
estado[ 1 ] = ESTADO_NAO_APLICAVEL;
}
}
- if( estado[ 0 ] == 1 || estado[ 0 ] == 2 ||
- estado[ 1 ] == 1 || estado[ 1 ] == 2 )
+
+// System.out.println( "\testado[ 0 ] : " + estado[ 0 ] );
+// System.out.println( "\testado[ 1 ] : " + estado[ 1 ] );
+
+ if ( estado[ 0 ] == 1 || estado[ 0 ] == 2 || estado[ 1 ] == 1 || estado[ 1 ] == 2 )
{
- links.add( "/"+servletName+"/?"+empresaID+"/"+estabelecimentoID+"/"+trabalhador.getID() );
+// System.out.println( "\t\testado[ 0 ] == 1 || estado[ 0 ] == 2 || estado[ 1 ] == 1 || estado[ 1 ] == 2 : true" );
+
+ links.add( "/" + servletName + "/?" + empresaID + "/" + estabelecimentoID + "/" + trabalhador.getID() );
HashMap dadosTrabalhador = new HashMap();
dadosTrabalhador.put( "Nome", trabalhador.toString() );
dadosTrabalhador.put( "Consulta", CORES_ESTADOS.get( new Integer( estado[ 0 ] ) ) );
Object text = TEXTOS_ESTADOS.get( new Integer( estado[ 0 ] ) );
+// System.out.println( "\t\t\tCONSULTA_ESTADO : " + text );
dadosTrabalhador.put( "Consulta_estado", text != null ? text : marcacoes[ index ][ 0 ] );
+// System.out.println( "\t\t\t\tFinal : " + dadosTrabalhador.get( "Consulta_estado" ) );
+
dadosTrabalhador.put( "Exame", CORES_ESTADOS.get( new Integer( estado[ 1 ] ) ) );
text = TEXTOS_ESTADOS.get( new Integer( estado[ 1 ] ) );
+// System.out.println( "\t\t\tEXAME_ESTADO : " + text );
dadosTrabalhador.put( "Exame_estado", text != null ? text : marcacoes[ index ][ 3 ] );
+// System.out.println( "\t\t\t\tFinal : " + dadosTrabalhador.get( "Exame_estado" ) );
+
dados.add( dadosTrabalhador );
}
}
@@ -677,43 +693,33 @@ public class doGetListaTrabalhadoresPendentes
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;
- }
+ return perfilTem( query, trabalhadorID );
}
protected boolean perfilTemExames( Integer trabalhadorID, Integer empresaID )
throws Exception
{
- Executer executer = getExecuter();
String query = "SELECT a_exames, b_exames FROM empresas WHERE id = " + empresaID;
+ return perfilTem( query, trabalhadorID );
+ }
+
+ private boolean perfilTem( String query, Integer trabalhadorID ) throws Exception
+ {
+ Executer executer = getExecuter();
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;
- }
+ return perfil != null && consultas[ perfil.intValue() - 1 ];
}
+
+
+
+
+
// protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] )
// {
// boolean estadoConsultas = false;
diff --git a/branches/SIPRP/web/src/siprp/pagina/doGetTrabalhador.java b/branches/SIPRP/web/src/siprp/pagina/doGetTrabalhador.java
index 91949d44..ac5af1dd 100644
--- a/branches/SIPRP/web/src/siprp/pagina/doGetTrabalhador.java
+++ b/branches/SIPRP/web/src/siprp/pagina/doGetTrabalhador.java
@@ -23,7 +23,7 @@ public class doGetTrabalhador extends siprpServlet
return rs;
}
- /** Creates a new instance of doGetTrabalhador */
+
public doGetTrabalhador(HttpServletRequest req, HttpServletResponse res) throws IOException
{
ServletOutputStream out = res.getOutputStream();
@@ -222,98 +222,130 @@ public class doGetTrabalhador extends siprpServlet
hmFuncionario.put( "resultado", null );
}
- query = "SELECT id, data, estado FROM marcacoes_trabalhador "
- + "WHERE tipo = 1 and trabalhador_id = " + trabalhadorId
- + " ORDER BY data DESC";
- stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- rs = new ResultSet2DArray( stmt.executeQuery( query ) );
- if( rs.columnLength() > 0 )
+
+ /** consulta dados **/
+ String queryUltima = "select id, data, estado " +
+ "from marcacoes_trabalhador " +
+ "where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + trabalhadorId + " " +
+ "order by data desc " +
+ "limit 1";
+ rs = executeQuery( con, queryUltima );
+
+ java.util.Date dataUltimaConsultaRealizada = null;
+ String consultaRealizada = "";
+ if ( rs.columnLength() > 0 )
{
- java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
- Integer estado1;
- Integer estado2 = ( Integer ) rs.get( 0, 2 );
- java.util.Date dataConsulta1;
-// java.util.Date dataRelatorio1;
-// java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 );
- String realizada1 = "";
- String realizada2 = "";
- if( rs.columnLength() >= 2 )
- {
- dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
- estado1 = ( Integer ) rs.get( 1, 2 );
-// dataRelatorio1 = (java.util.Date) rs.get( 1, 3 );
- }
- else
- {
- dataConsulta1 = dataConsulta2;
- estado1 = estado2;
-// dataRelatorio1 = dataRelatorio2;
- }
- if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
- {
- hmFuncionario.put( "ultima_consulta", dataConsulta2 );
- if( estado2.equals( ESTADO_REALIZADO ) )
- {
- realizada2 = "sim";
- }
- else
- {
- realizada2 = "não";
- }
- hmFuncionario.put( "realizada", realizada2 );
- hmFuncionario.put( "proxima_consulta", null );
- }
- else
- {
- try
- {
- for( int c = 1; c < rs.columnLength(); c++ )
- {
- java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
- dataConsulta1 = dataTemp;
- estado1 = ( Integer ) rs.get( c, 2 );
- if( dataTemp.after( today ) )
- {
- dataConsulta2 = dataTemp;
- }
- else
- {
- break;
- }
- }
- }
- catch( Exception ex )
- {
- ex.printStackTrace();
- }
- hmFuncionario.put( "proxima_consulta", dataConsulta2 );
- if( !dataConsulta2.equals( dataConsulta1 ) )
- {
- if( estado1.equals( ESTADO_REALIZADO ) )
- {
- realizada1 = "sim";
- }
- else
- {
- realizada1 = "não";
- }
- hmFuncionario.put( "realizada", realizada1 );
- hmFuncionario.put( "ultima_consulta", dataConsulta1 );
- }
- else
- {
- hmFuncionario.put( "ultima_consulta", null );
- hmFuncionario.put( "realizada", null );
- }
- }
+ dataUltimaConsultaRealizada = ( java.util.Date ) rs.get( 0, 1 );
+ consultaRealizada = "Sim";
}
- else
+
+ String queryProxima = "select id, data, estado " +
+ "from marcacoes_trabalhador " +
+ "where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + trabalhadorId + " " +
+ "order by data desc " +
+ "limit 1";
+ rs = executeQuery( con, queryProxima );
+
+ java.util.Date dataProximaConsulta = null;
+ if ( rs.columnLength() > 0 )
{
- hmFuncionario.put( "ultima_consulta", null );
- hmFuncionario.put( "realizada", null );
- hmFuncionario.put( "proxima_consulta", null );
+ dataProximaConsulta = ( java.util.Date ) rs.get( 0, 1 );
}
- stmt.close();
+
+ hmFuncionario.put( "ultima_consulta", dataUltimaConsultaRealizada == null ? "" : dataUltimaConsultaRealizada );
+ hmFuncionario.put( "realizada", consultaRealizada );
+ hmFuncionario.put( "proxima_consulta", dataProximaConsulta == null ? "" : dataProximaConsulta );
+
+// query = "SELECT id, data, estado FROM marcacoes_trabalhador "
+// + "WHERE tipo = 1 and trabalhador_id = " + trabalhadorId
+// + " ORDER BY data DESC";
+// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+// rs = new ResultSet2DArray( stmt.executeQuery( query ) );
+// if( rs.columnLength() > 0 )
+// {
+// java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
+// Integer estado1;
+// Integer estado2 = ( Integer ) rs.get( 0, 2 );
+// java.util.Date dataConsulta1;
+// String realizada1 = "";
+// String realizada2 = "";
+// if( rs.columnLength() >= 2 )
+// {
+// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
+// estado1 = ( Integer ) rs.get( 1, 2 );
+// }
+// else
+// {
+// dataConsulta1 = dataConsulta2;
+// estado1 = estado2;
+// }
+// if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
+// {
+// hmFuncionario.put( "ultima_consulta", dataConsulta2 );
+// if( estado2.equals( ESTADO_REALIZADO ) )
+// {
+// realizada2 = "sim";
+// }
+// else
+// {
+// realizada2 = "não";
+// }
+// hmFuncionario.put( "realizada", realizada2 );
+// hmFuncionario.put( "proxima_consulta", null );
+// }
+// else
+// {
+// try
+// {
+// for( int c = 1; c < rs.columnLength(); c++ )
+// {
+// java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
+// dataConsulta1 = dataTemp;
+// estado1 = ( Integer ) rs.get( c, 2 );
+// if( dataTemp.after( today ) )
+// {
+// dataConsulta2 = dataTemp;
+// }
+// else
+// {
+// break;
+// }
+// }
+// }
+// catch( Exception ex )
+// {
+// ex.printStackTrace();
+// }
+// hmFuncionario.put( "proxima_consulta", dataConsulta2 );
+// if( !dataConsulta2.equals( dataConsulta1 ) )
+// {
+// if( estado1.equals( ESTADO_REALIZADO ) )
+// {
+// realizada1 = "sim";
+// }
+// else
+// {
+// realizada1 = "não";
+// }
+// hmFuncionario.put( "realizada", realizada1 );
+// hmFuncionario.put( "ultima_consulta", dataConsulta1 );
+// }
+// else
+// {
+// hmFuncionario.put( "ultima_consulta", null );
+// hmFuncionario.put( "realizada", null );
+// }
+// }
+// }
+// else
+// {
+// hmFuncionario.put( "ultima_consulta", null );
+// hmFuncionario.put( "realizada", null );
+// hmFuncionario.put( "proxima_consulta", null );
+// }
+// stmt.close();
+ /** eof consulta dados **/
+
}
sBuffer = new StringBuffer();