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 org.apache.velocity.app.*;
import com.evolute.utils.arrays.*; 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.*; import com.evolute.utils.strings.*;
/** /**
@ -26,7 +29,10 @@ import com.evolute.utils.strings.*;
public class doGetListaTrabalhadoresPendentes public class doGetListaTrabalhadoresPendentes
extends siprpServlet 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_PENDENTE = 1;
protected static final int ESTADO_MARCADO = 2; protected static final int ESTADO_MARCADO = 2;
protected static final int ESTADO_TRATADO = 3; protected static final int ESTADO_TRATADO = 3;
@ -40,14 +46,177 @@ public class doGetListaTrabalhadoresPendentes
protected long todayMillis; protected long todayMillis;
/** Creates a new instance of doGetListaTrabalhadores */ /** 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(); ServletOutputStream out = res.getOutputStream();
Connection con = null ; String userRole, empresaId, estabelecimentoId;
Statement stmt = null ;
ResultSet2DArray rs;
StringBuffer dbQuery, sBuffer;
String userRole, empresaId, estabelecimentoId, temp;
HttpSession session = req.getSession(false); HttpSession session = req.getSession(false);
Vector links = new Vector(); Vector links = new Vector();
Vector desc = new Vector(); Vector desc = new Vector();
@ -57,116 +226,92 @@ public class doGetListaTrabalhadoresPendentes
try try
{ {
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); Executer executer = getExecuter();
rs = new ResultSet2DArray( stmt.executeQuery( "SELECT CURRENT_DATE" ) ); Virtual2DArray array = executer.executeQuery( new Select( "SELECT CURRENT_DATE" ) );
today = ( java.sql.Date ) rs.get( 0, 0 ); today = ( java.sql.Date ) array.get( 0, 0 );
stmt.close();
todayMillis = today.getTime(); todayMillis = today.getTime();
userRole = (String)session.getAttribute(super.sessionUserRole); userRole = (String)session.getAttribute(sessionUserRole);
empresaId = (String)session.getAttribute(super.sessionEmpresaId); empresaId = (String)session.getAttribute(sessionEmpresaId);
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId); estabelecimentoId = (String)session.getAttribute(sessionEstabelecimentoId);
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) ) if ( userRole.equals ( superUserRole ) || userRole.equals ( empresaId ) )
{ {
Class.forName(super.bdDriver); if ( verificaEstabelecimento(null, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
{ {
//Class.forName(super.bdDriver); //Class.forName(super.bdDriver);
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword ); //con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
dbQuery = new StringBuffer(); String query = "( SELECT trabalhadores.id, trabalhadores.nome, "
dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, " + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, " + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data "
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo " + "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id ) "
+ "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id )" + "WHERE estabelecimento_id = " + estabelecimentoId
+ "WHERE estabelecimento_id = " + estabelecimentoId + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL " + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
+ " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) " + " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
+ "ORDER BY 6, 3, 4 DESC " ); + " AND marcacoes_trabalhador.motivo <> " + MOTIVO_OCASIONAL + " )"
// dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' )," + " UNION "
// + " ( ultimo_exame IS NOT NULL AND realizado = 'y' )," + "( SELECT trabalhadores.id, trabalhadores.nome, "
// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, " + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), " + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data + 90 "
// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )" + "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id ) "
// + " FROM trabalhadores " + "WHERE estabelecimento_id = " + estabelecimentoId
// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'" + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR" + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )" + " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_EXAMES + " )"
// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )" + "ORDER BY 6, 8, 3 DESC ";
// + " ORDER BY nome" ); array = executer.executeQuery( new Select( query ) );
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) ); query = "SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
int index=0; + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data "
int max = rs.columnLength(); + "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id ) "
+ "WHERE estabelecimento_id = " + estabelecimentoId
Integer trabalhadorID = new Integer( -1 ); + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
String nomeTrabalhador = ""; + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
Vector consultas = new Vector(); + " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
Vector exames = new Vector(); + " AND marcacoes_trabalhador.motivo = " + MOTIVO_OCASIONAL
+ " ORDER BY 6, 8, 3 DESC";
for ( index = 0; index <= max; index++ ) Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) );
Hashtable marcacoesPorID = new Hashtable();
Hashtable ocasionaisPorID = new Hashtable();
Hashtable nomesPorID = new Hashtable();
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 ); trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) );
if( !id.equals( trabalhadorID ) ) }
{ Arrays.sort( trabalhadores, new Comparator(){
Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][3] ); public int compare( Object o1, Object o2 )
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; String nome1 = StringPlainer.convertString( o1.toString() );
String nome2 = StringPlainer.convertString( o2.toString() );
return nome1.compareTo( nome2 );
} }
switch( tipo.intValue() ) } );
{
case TIPO_MARCACAO_EXAMES:
exames.add( marcacao );
break;
case TIPO_MARCACAO_CONSULTA: for( int n = 0; n < trabalhadores.length; n++ )
consultas.add( marcacao ); {
break; 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(); HashMap hmValues = new HashMap();
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) ); hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) ); 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( "estabelecimento_id", estabelecimentoId );
hmValues.put( "userRole", userRole ); hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) ); 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( templateUserRole, userRole);
hmValues.put( templateQuery, "trabalhadores_pendentes" ); hmValues.put( templateQuery, "trabalhadores_pendentes" );
hmValues.put( templateVector1,links); hmValues.put( templateVector1,links);
@ -186,7 +331,6 @@ public class doGetListaTrabalhadoresPendentes
{ {
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) ); out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
} }
con.close();
} }
else // Role não permite ver esta informação else // Role não permite ver esta informação
{ {
@ -205,113 +349,222 @@ public class doGetListaTrabalhadoresPendentes
} }
} }
protected int[] classificarTrabalhador( Object consultas[][], Object exames[][] ) protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID )
{ {
int estado[] = new int[ 2 ]; int max = array.columnLength();
int indiceProximaConsulta = -1; for( int index = 0; index < max; index++ )
int indiceProximaConsultaPeriodica = -1;
int indiceConsultaAnterior = -1;
int indiceConsultaAnteriorPeriodica = -1;
int indiceProximoExame = -1;
int indiceExameAnterior = -1;
if( consultas == null )
{ {
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( grupo == null )
if( ( ( Integer ) consultas[ 0 ][ 2 ] ).intValue() != MOTIVO_OCASIONAL )
{ {
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++ ) java.util.Date data = ( java.util.Date ) marcacoes[ n ][ 0 ];
{ Integer estado = ( Integer ) marcacoes[ n ][ 1 ];
if( today.after( (java.util.Date) consultas[ 0 ][ 0 ] ) && Integer motivo = ( Integer ) marcacoes[ n ][ 2 ];
( ( Integer ) consultas[ 0 ][ 1 ] ).intValue() == 2 ) Integer tipo = ( Integer ) marcacoes[ n ][ 3 ];
switch( tipo.intValue() )
{ {
if( indiceConsultaAnterior == -1 ) case TIPO_MARCACAO_EXAMES:
{ if( dataConsulta == null &&
indiceConsultaAnterior = n; ( dataExame == null || estadoExame.intValue() < 2 ) )
} {
if( ( ( Integer ) consultas[ 0 ][ 2 ] ).intValue() != MOTIVO_OCASIONAL ) dataExame = data;
{ estadoExame = estado;
indiceConsultaAnteriorPeriodica = n; }
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; 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; grupo = new Object[ 5 ];
} for( int i = 0; i < ocasionais[ n ].length; i++ )
for( int n = indiceProximoExame + 1; n < exames.length; n++ )
{
if( today.after( (java.util.Date) exames[ 0 ][ 0 ] ) &&
( ( Integer ) exames[ 0 ][ 1 ] ).intValue() == 2 )
{ {
indiceExameAnterior = n; grupo[ i ] = ocasionais[ i ];
break;
} }
grupos.add( grupo );
} }
// estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) &&
// ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
} }
// else Object agrupadas[][] = ( Object[][] ) grupos.toArray( new Object[ grupos.size() ][] );
// { Arrays.sort( agrupadas, new Comparator(){
// estado[ 0 ] = ESTADO_PENDENTE; public int compare( Object o1, Object o2 )
// } {
Object g1[] = ( Object[] ) o1;
return estado; 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; int estado[] = new int[ 2 ];
boolean estadoExames = ( exames.length == 0 ) || ( ( java.util.Date )exames[ 0 ][ 0 ] ).before(today) ||
( ( ( ( java.util.Date )exames[ 0 ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); if( marcacoes.length == 0 )
if( consultas.length > 0 )
{ {
int anterior; estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
int proxima; estado[ 1 ] = perfilExames ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) ) }
else
{
java.util.Date dataConsulta;
java.util.Date dataExame;
int index = -1;
for( ; index + 1 < marcacoes.length; index++ )
{ {
proxima = 0; int n = index + 1;
if( consultas.length >= 2 ) dataConsulta = ( java.util.Date ) marcacoes[ n ][ 0 ];
{ dataExame = ( java.util.Date ) marcacoes[ n ][ 3 ];
anterior = 1; boolean temConsulta = dataConsulta != null;
} boolean consultaAntiga = temConsulta && dataConsulta.before( today );
else 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; index = 0;
anterior = 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 HashMap criarDadosTrabalhador( Connection con, Integer id, String nome, // 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( Integer id, String nome,
Object consultas[][], Object exames[][] ) Object consultas[][], Object exames[][] )
throws Exception throws Exception
{ {

@ -1,16 +1,21 @@
package siprp.pagina; package siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*; import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.http.*; import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import org.apache.velocity.*; import org.apache.velocity.*;
import org.apache.velocity.app.*; 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 public class siprpServlet extends HttpServlet
implements GlobalConstants implements GlobalConstants
{ {
@ -386,17 +391,26 @@ System.out.println( "query: " + queryString );
{ {
//Connection con = null ; //Connection con = null ;
Statement stmt = null ; Statement stmt = null ;
ResultSet2DArray rs; Virtual2DArray rs;
StringBuffer dbQuery; String query;
try try
{ {
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword ); //con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
dbQuery = new StringBuffer(); query = "SELECT empresa_id FROM estabelecimentos where id='"+estabelecimentoId+"'";
dbQuery.append( "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( dbQuery.toString()) ); 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 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 if ( empresaId.equals(temp) ) // estabelecimento pertence à empresa
{ {
return true; return true;
@ -493,20 +507,28 @@ System.out.println( "query: " + queryString );
public String nomeEmpresa(Connection con, String empresaId) public String nomeEmpresa(Connection con, String empresaId)
{ {
Statement stmt = null ; Statement stmt = null ;
ResultSet2DArray rs; Virtual2DArray rs;
StringBuffer dbQuery;
String returnString; String returnString;
try try
{ {
dbQuery = new StringBuffer(); String query = "SELECT designacao_social FROM empresas WHERE id ='"+empresaId+"'";
dbQuery.append( "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( dbQuery.toString()) ); 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 ) if( rs.columnLength() > 0 )
{ {
returnString = (String)rs.get(0,0); returnString = (String)rs.get(0,0);
stmt.close(); if( con != null )
{
stmt.close();
}
return returnString; return returnString;
} }
else else
@ -524,20 +546,29 @@ System.out.println( "query: " + queryString );
public String nomeEstabelecimento(Connection con, java.lang.String estabelecimentoId) public String nomeEstabelecimento(Connection con, java.lang.String estabelecimentoId)
{ {
Statement stmt = null ; Statement stmt = null ;
ResultSet2DArray rs; Virtual2DArray rs;
StringBuffer dbQuery; StringBuffer dbQuery;
String returnString; String returnString;
try try
{ {
dbQuery = new StringBuffer(); String query = "SELECT nome FROM estabelecimentos WHERE id ='"+estabelecimentoId+"'";
dbQuery.append( "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( dbQuery.toString()) ); 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 ) if( rs.columnLength() > 0 )
{ {
returnString = (String)rs.get(0,0); returnString = (String)rs.get(0,0);
stmt.close(); if( con != null )
{
stmt.close();
}
return returnString; return returnString;
} }
else else
@ -599,5 +630,18 @@ System.out.println( "query: " + queryString );
err = err.replace( '+', ' ' ); err = err.replace( '+', ' ' );
out.println( mergeTemplate( err, innerErrorTemplate) ); 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