no message

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

@ -17,6 +17,9 @@ import org.apache.velocity.*;
import org.apache.velocity.app.*;
import com.evolute.utils.arrays.*;
import com.evolute.utils.data.*;
import com.evolute.utils.db.*;
import com.evolute.utils.sql.*;
import com.evolute.utils.strings.*;
/**
@ -26,7 +29,10 @@ import com.evolute.utils.strings.*;
public class doGetListaTrabalhadoresPendentes
extends siprpServlet
{
protected static final int ESTADO_NAO_SE_APLICA = 0;
private static final int TRES_MESES = 3 * 30 * 24 * 60 * 60 * 1000;
private static final int CATORZE_DIAS = 14 * 24 * 60 * 60 * 1000;
protected static final int ESTADO_NAO_APLICAVEL = 0;
protected static final int ESTADO_PENDENTE = 1;
protected static final int ESTADO_MARCADO = 2;
protected static final int ESTADO_TRATADO = 3;
@ -40,14 +46,177 @@ public class doGetListaTrabalhadoresPendentes
protected long todayMillis;
/** Creates a new instance of doGetListaTrabalhadores */
public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print) throws IOException
// public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print)
// throws IOException
// {
// ServletOutputStream out = res.getOutputStream();
// Connection con = null ;
// Statement stmt = null ;
// ResultSet2DArray rs;
// StringBuffer dbQuery, sBuffer;
// String userRole, empresaId, estabelecimentoId, temp;
// 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
// {
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( "SELECT CURRENT_DATE" ) );
// today = ( java.sql.Date ) rs.get( 0, 0 );
// stmt.close();
// todayMillis = today.getTime();
//
// userRole = (String)session.getAttribute(super.sessionUserRole);
// empresaId = (String)session.getAttribute(super.sessionEmpresaId);
// estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
//
// if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
// {
// Class.forName(super.bdDriver);
// con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
// 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 trabalhadores.id, trabalhadores.nome, "
// + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
// + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo "
// + "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) "
// + "ORDER BY 6, 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();
//
// Integer trabalhadorID = new Integer( -1 );
// String nomeTrabalhador = "";
// Vector consultas = new Vector();
// Vector exames = new Vector();
//
// for ( index = 0; index <= max; index++ )
// {
// Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 );
// if( !id.equals( trabalhadorID ) )
// {
// Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][3] );
// Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][3] );
// 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();
// }
// if( index == max )
// {
// break;
// }
// 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 );
// Integer estado = ( Integer ) rs.get( index, 4 );
// Integer motivo = ( Integer ) rs.get( index, 6 );
// trabalhadorID = id;
// nomeTrabalhador = nome;
// Object marcacao[] = new Object[]{ data, estado, motivo };
// if( tipo == null )
// {
// continue;
// }
// switch( tipo.intValue() )
// {
// case TIPO_MARCACAO_EXAMES:
// exames.add( marcacao );
// break;
//
// case TIPO_MARCACAO_CONSULTA:
// consultas.add( marcacao );
// break;
// }
// }
// stmt.close();
//
// sBuffer = new StringBuffer();
// sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
// +super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
//
// HashMap hmValues = new HashMap();
// hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
// hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
// hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
// hmValues.put( "estabelecimento_id", estabelecimentoId );
// hmValues.put( "userRole", userRole );
// hmValues.put( "userName", session.getAttribute( sessionUser ) );
// hmValues.put( msgTemplate , sBuffer.toString() ) ;
// hmValues.put( templateUserRole, userRole);
// hmValues.put( templateQuery, "trabalhadores_pendentes" );
// hmValues.put( templateVector1,links);
// hmValues.put( templateVector2,desc);
// hmValues.put( templateVector3,null);
// if( !print )
// {
// 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) );
// }
// else // est não pertence à empresa
// {
// out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
// }
// con.close();
// }
// else // Role não permite ver esta informação
// {
// out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
// }
// }
// catch ( SQLException e )
// {
// e.printStackTrace();
// out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
// }
// catch ( Exception e )
// {
// e.printStackTrace();
// out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
// }
// }
public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print )
throws IOException
{
ServletOutputStream out = res.getOutputStream();
Connection con = null ;
Statement stmt = null ;
ResultSet2DArray rs;
StringBuffer dbQuery, sBuffer;
String userRole, empresaId, estabelecimentoId, temp;
String userRole, empresaId, estabelecimentoId;
HttpSession session = req.getSession(false);
Vector links = new Vector();
Vector desc = new Vector();
@ -56,117 +225,93 @@ public class doGetListaTrabalhadoresPendentes
// todayMillis = today.getTime();
try
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( "SELECT CURRENT_DATE" ) );
today = ( java.sql.Date ) rs.get( 0, 0 );
stmt.close();
{
Executer executer = getExecuter();
Virtual2DArray array = executer.executeQuery( new Select( "SELECT CURRENT_DATE" ) );
today = ( java.sql.Date ) array.get( 0, 0 );
todayMillis = today.getTime();
userRole = (String)session.getAttribute(super.sessionUserRole);
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
userRole = (String)session.getAttribute(sessionUserRole);
empresaId = (String)session.getAttribute(sessionEmpresaId);
estabelecimentoId = (String)session.getAttribute(sessionEstabelecimentoId);
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
if ( userRole.equals ( superUserRole ) || userRole.equals ( empresaId ) )
{
Class.forName(super.bdDriver);
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
if ( verificaEstabelecimento(null, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
{
//Class.forName(super.bdDriver);
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
dbQuery = new StringBuffer();
dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo "
+ "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) "
+ "ORDER BY 6, 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();
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.tipo = " + TIPO_MARCACAO_CONSULTA
+ " AND marcacoes_trabalhador.motivo <> " + MOTIVO_OCASIONAL + " )"
+ " UNION "
+ "( SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data + 90 "
+ "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.tipo = " + TIPO_MARCACAO_EXAMES + " )"
+ "ORDER BY 6, 8, 3 DESC ";
array = executer.executeQuery( new Select( query ) );
Integer trabalhadorID = new Integer( -1 );
String nomeTrabalhador = "";
Vector consultas = new Vector();
Vector exames = new Vector();
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.tipo = " + TIPO_MARCACAO_CONSULTA
+ " AND marcacoes_trabalhador.motivo = " + MOTIVO_OCASIONAL
+ " ORDER BY 6, 8, 3 DESC";
Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) );
Hashtable marcacoesPorID = new Hashtable();
Hashtable ocasionaisPorID = new Hashtable();
Hashtable nomesPorID = new Hashtable();
for ( index = 0; index <= max; index++ )
preencherMarcacoes( array, nomesPorID, marcacoesPorID );
preencherMarcacoes( array, nomesPorID, ocasionaisPorID );
Integer ids[] = ( Integer[] ) nomesPorID.keySet().toArray( new Integer[0] );
IDObject trabalhadores[] = new IDObject[ ids.length ];
for( int n = 0; n < ids.length; n++ )
{
Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 );
if( !id.equals( trabalhadorID ) )
{
Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][3] );
Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][3] );
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();
}
if( index == max )
{
break;
}
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 );
Integer estado = ( Integer ) rs.get( index, 4 );
Integer motivo = ( Integer ) rs.get( index, 6 );
trabalhadorID = id;
nomeTrabalhador = nome;
Object marcacao[] = new Object[]{ data, estado, motivo };
if( tipo == null )
{
continue;
}
switch( tipo.intValue() )
trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) );
}
Arrays.sort( trabalhadores, new Comparator(){
public int compare( Object o1, Object o2 )
{
case TIPO_MARCACAO_EXAMES:
exames.add( marcacao );
break;
case TIPO_MARCACAO_CONSULTA:
consultas.add( marcacao );
break;
String nome1 = StringPlainer.convertString( o1.toString() );
String nome2 = StringPlainer.convertString( o2.toString() );
return nome1.compareTo( nome2 );
}
} );
for( int n = 0; n < trabalhadores.length; n++ )
{
Object marcacoes[][] = ( Object[][] ) marcacoesPorID.get( trabalhadores[ n ].getID() );
Object ocasionais[][] = ( Object[][] ) ocasionaisPorID.get( trabalhadores[ n ].getID() );
Object agrupadas[][] = agruparMarcacoes( marcacoes, ocasionais );
}
stmt.close();
sBuffer = new StringBuffer();
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
HashMap hmValues = new HashMap();
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
hmValues.put( "estabelecimento_nome", nomeEstabelecimento( null, estabelecimentoId ) );
hmValues.put( "estabelecimento_id", estabelecimentoId );
hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate , sBuffer.toString() ) ;
hmValues.put( msgTemplate , "<b>"+nomeEmpresa(null,empresaId)+"</b><br><br><i>"
+nomeEstabelecimento(null, estabelecimentoId)+"</i>" ) ;
hmValues.put( templateUserRole, userRole);
hmValues.put( templateQuery, "trabalhadores_pendentes" );
hmValues.put( templateVector1,links);
@ -186,7 +331,6 @@ public class doGetListaTrabalhadoresPendentes
{
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
}
con.close();
}
else // Role não permite ver esta informação
{
@ -204,114 +348,223 @@ public class doGetListaTrabalhadoresPendentes
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
}
}
protected int[] classificarTrabalhador( Object consultas[][], Object exames[][] )
protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID )
{
int estado[] = new int[ 2 ];
int indiceProximaConsulta = -1;
int indiceProximaConsultaPeriodica = -1;
int indiceConsultaAnterior = -1;
int indiceConsultaAnteriorPeriodica = -1;
int indiceProximoExame = -1;
int indiceExameAnterior = -1;
if( consultas == null )
int max = array.columnLength();
for( int index = 0; index < max; index++ )
{
estado[ 0 ] = ESTADO_NAO_SE_APLICA;
Integer id = index < max ? ( Integer ) array.get( index, 0 ) : new Integer( -1 );
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 ) )
{
nomesPorID.put( id, nome );
marcacoesPorID.put( id, new Vector() );
}
Object marcacao[] = new Object[]{ data, estado, motivo, tipo };
( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao );
}
else if( consultas.length > 0 )
}
protected Object[][] agruparMarcacoes( Object marcacoes[][], Object ocasionais[][] )
{
int tresMeses = TRES_MESES;
java.util.Date dataExame = null;
Integer estadoExame = null;
java.util.Date dataConsulta = null;
Integer motivoConsulta = null;
Integer estadoConsulta = null;
Object grupo[] = null;
Vector grupos = new Vector();
if( marcacoes != null )
{
if( !today.after( (java.util.Date) consultas[ 0 ][ 0 ] ) )
for( int n = 0; n < marcacoes.length; n++ )
{
indiceProximaConsulta = 0;
if( ( ( Integer ) consultas[ 0 ][ 2 ] ).intValue() != MOTIVO_OCASIONAL )
if( grupo == null )
{
indiceProximaConsultaPeriodica = 0;
grupo = new Object[ 5 ];
dataExame = null;
estadoExame = null;
dataConsulta = null;
motivoConsulta = null;
estadoConsulta = null;
grupos.add( grupo );
}
}
for( int n = indiceProximaConsulta + 1; n < consultas.length; n++ )
{
if( today.after( (java.util.Date) consultas[ 0 ][ 0 ] ) &&
( ( Integer ) consultas[ 0 ][ 1 ] ).intValue() == 2 )
java.util.Date data = ( java.util.Date ) marcacoes[ n ][ 0 ];
Integer estado = ( Integer ) marcacoes[ n ][ 1 ];
Integer motivo = ( Integer ) marcacoes[ n ][ 2 ];
Integer tipo = ( Integer ) marcacoes[ n ][ 3 ];
switch( tipo.intValue() )
{
if( indiceConsultaAnterior == -1 )
{
indiceConsultaAnterior = n;
}
if( ( ( Integer ) consultas[ 0 ][ 2 ] ).intValue() != MOTIVO_OCASIONAL )
{
indiceConsultaAnteriorPeriodica = n;
case TIPO_MARCACAO_EXAMES:
if( dataConsulta == null &&
( dataExame == null || estadoExame.intValue() < 2 ) )
{
dataExame = data;
estadoExame = estado;
}
else if( Math.abs( dataConsulta.getTime() - data.getTime() ) < tresMeses )
{
dataExame = data;
estadoExame = estado;
}
else
{
grupo = null;
n--;
}
if( grupo != null )
{
grupo[ 3 ] = dataExame;
grupo[ 4 ] = estadoExame;
}
break;
case TIPO_MARCACAO_CONSULTA:
if( dataExame == null || Math.abs( dataExame.getTime() - data.getTime() ) < tresMeses )
{
dataConsulta = data;
estadoConsulta = estado;
motivoConsulta = motivo;
}
else
{
grupo = null;
n--;
}
if( grupo != null )
{
grupo[ 0 ] = dataConsulta;
grupo[ 1 ] = estadoConsulta;
grupo[ 2 ] = motivoConsulta;
}
break;
}
}
}
// estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) &&
// ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
}
if( exames == null )
{
estado[ 1 ] = ESTADO_NAO_SE_APLICA;
}
else if( exames.length > 0 )
if( ocasionais != null )
{
if( !today.after( (java.util.Date) exames[ 0 ][ 0 ] ) )
for( int n = 0; n < ocasionais.length; n++ )
{
indiceProximoExame = 0;
}
for( int n = indiceProximoExame + 1; n < exames.length; n++ )
{
if( today.after( (java.util.Date) exames[ 0 ][ 0 ] ) &&
( ( Integer ) exames[ 0 ][ 1 ] ).intValue() == 2 )
grupo = new Object[ 5 ];
for( int i = 0; i < ocasionais[ n ].length; i++ )
{
indiceExameAnterior = n;
break;
grupo[ i ] = ocasionais[ i ];
}
grupos.add( grupo );
}
// estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) &&
// ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
}
// else
// {
// estado[ 0 ] = ESTADO_PENDENTE;
// }
return estado;
Object agrupadas[][] = ( Object[][] ) grupos.toArray( new Object[ grupos.size() ][] );
Arrays.sort( agrupadas, new Comparator(){
public int compare( Object o1, Object o2 )
{
Object g1[] = ( Object[] ) o1;
Object g2[] = ( Object[] ) o2;
java.util.Date d1 = ( java.util.Date ) ( g1[ 0 ] != null ? g1[ 0 ] : g1[ 3 ] );
java.util.Date d2 = ( java.util.Date ) ( g2[ 0 ] != null ? g2[ 0 ] : g2[ 3 ] );
return d2.compareTo( d1 );
}
} );
return agrupadas;
}
protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] )
protected void acrescentarTrabalhador( IDObject trabalhador, java.util.Date dataFicha,
Object marcacoes[][], Vector links, Vector dados,
boolean perfilConsultas, boolean perfilExames )
{
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 estado[] = new int[ 2 ];
if( marcacoes.length == 0 )
{
int anterior;
int proxima;
if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) )
estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
estado[ 1 ] = perfilExames ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
}
else
{
java.util.Date dataConsulta;
java.util.Date dataExame;
int index = -1;
for( ; index + 1 < marcacoes.length; index++ )
{
proxima = 0;
if( consultas.length >= 2 )
{
anterior = 1;
}
else
int n = index + 1;
dataConsulta = ( java.util.Date ) marcacoes[ n ][ 0 ];
dataExame = ( java.util.Date ) marcacoes[ n ][ 3 ];
boolean temConsulta = dataConsulta != null;
boolean consultaAntiga = temConsulta && dataConsulta.before( today );
boolean temExame = dataExame != null;
boolean exameAntigo = temExame && dataExame.before( today );
if( ( temConsulta && consultaAntiga && temExame && exameAntigo ) ||
( temConsulta && consultaAntiga && !temExame && !exameAntigo ) ||
( !temConsulta && !consultaAntiga && temExame && exameAntigo ) )
{
anterior = -1;
break;
}
}
else
if( index == -1 )
{
proxima = -1;
anterior = 0;
index = 0;
}
else if( index < marcacoes.length - 1 )
{
index = 0;
}
boolean found = false;
for( ; !found; index++ )
{
// java.util.Date dataConsulta = ( java.util.Date ) marcacoes[ n ][ 0 ];
// java.util.Date dataExame = ( java.util.Date ) marcacoes[ n ][ 3 ];
// if( ( dataConsulta == null || dataConsulta.before( today ) ) !=
// ( dataExame == null || dataExame.before( today ) ) )
// {
// break;
// }
}
estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) &&
( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
}
return !(estadoConsultas && estadoExames);
}
// 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,
protected HashMap criarDadosTrabalhador( Integer id, String nome,
Object consultas[][], Object exames[][] )
throws Exception
{

@ -1,16 +1,21 @@
package siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import com.evolute.utils.*;
import com.evolute.utils.arrays.*;
import com.evolute.utils.db.*;
import com.evolute.utils.sql.*;
import com.evolute.utils.strings.*;
public class siprpServlet extends HttpServlet
implements GlobalConstants
{
@ -386,17 +391,26 @@ System.out.println( "query: " + queryString );
{
//Connection con = null ;
Statement stmt = null ;
ResultSet2DArray rs;
StringBuffer dbQuery;
Virtual2DArray rs;
String query;
try
{
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
dbQuery = new StringBuffer();
dbQuery.append( "SELECT empresa_id FROM estabelecimentos where id='"+estabelecimentoId+"'");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
query = "SELECT empresa_id FROM estabelecimentos where id='"+estabelecimentoId+"'";
if( con != null )
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
}
else
{
rs = getExecuter().executeQuery( new Select( query ) );
}
String temp=""+rs.get(0,0); // converter de int para String
stmt.close();
if( con != null )
{
stmt.close();
}
if ( empresaId.equals(temp) ) // estabelecimento pertence à empresa
{
return true;
@ -493,20 +507,28 @@ System.out.println( "query: " + queryString );
public String nomeEmpresa(Connection con, String empresaId)
{
Statement stmt = null ;
ResultSet2DArray rs;
StringBuffer dbQuery;
Virtual2DArray rs;
String returnString;
try
{
dbQuery = new StringBuffer();
dbQuery.append( "SELECT designacao_social FROM empresas WHERE id ='"+empresaId+"'");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
String query = "SELECT designacao_social FROM empresas WHERE id ='"+empresaId+"'";
if( con != null )
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
}
else
{
rs = getExecuter().executeQuery( new Select( query ) );
}
if( rs.columnLength() > 0 )
{
returnString = (String)rs.get(0,0);
stmt.close();
if( con != null )
{
stmt.close();
}
return returnString;
}
else
@ -524,20 +546,29 @@ System.out.println( "query: " + queryString );
public String nomeEstabelecimento(Connection con, java.lang.String estabelecimentoId)
{
Statement stmt = null ;
ResultSet2DArray rs;
Virtual2DArray rs;
StringBuffer dbQuery;
String returnString;
try
{
dbQuery = new StringBuffer();
dbQuery.append( "SELECT nome FROM estabelecimentos WHERE id ='"+estabelecimentoId+"'");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
String query = "SELECT nome FROM estabelecimentos WHERE id ='"+estabelecimentoId+"'";
if( con != null )
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
}
else
{
rs = getExecuter().executeQuery( new Select( query ) );
}
if( rs.columnLength() > 0 )
{
returnString = (String)rs.get(0,0);
stmt.close();
if( con != null )
{
stmt.close();
}
return returnString;
}
else
@ -599,5 +630,18 @@ System.out.println( "query: " + queryString );
err = err.replace( '+', ' ' );
out.println( mergeTemplate( err, innerErrorTemplate) );
}
protected Executer getExecuter()
throws Exception
{
ServletContext context = getServletContext();
DBManager dbm = ( DBManager ) context.getAttribute( Singleton.DEFAULT_DBMANAGER );
if( dbm == null )
{
dbm = new JDBCManager( bdLocalUrl, bdLocalUsername, bdLocalPassword , 10, 8, 8, null );
context.setAttribute( Singleton.DEFAULT_DBMANAGER, dbm );
}
return dbm.getSharedExecuter();
}
}

Loading…
Cancel
Save