From 73c7fe5c3bcb21ed51642d854362da3f717fb80c Mon Sep 17 00:00:00 2001 From: Diogo Neves Date: Mon, 21 Feb 2011 15:37:26 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@1616 bb69d46d-e84e-40c8-a05a-06db0d633741 --- branches/SIPRP/web/contents/user.html | 47 +- branches/SIPRP/web/contents/user_print.html | 25 +- .../web/src/siprp/pagina/GlobalConstants.java | 15 +- .../src/siprp/pagina/doGetListaEmpresas.java | 14 +- .../siprp/pagina/doGetListaTrabalhadores.java | 2 +- .../doGetListaTrabalhadoresPendentes.java | 1203 ++++++++--------- 6 files changed, 650 insertions(+), 656 deletions(-) diff --git a/branches/SIPRP/web/contents/user.html b/branches/SIPRP/web/contents/user.html index 5807e757..dd574756 100644 --- a/branches/SIPRP/web/contents/user.html +++ b/branches/SIPRP/web/contents/user.html @@ -189,28 +189,31 @@ #end #elseif( $query == "trabalhadores_pendentes" ) -
- - Pendente - - Marcado - - Tratado -
-
(*)ECD - Exames Complementares de Diagnóstico
- - - - - - - #foreach( $element in $v1 ) - #set ( $counter = $velocityCount - 1 ) - #set ( $dados_trabalhador = $v2.get($counter) ) - - - - - - #end -
NomeECD(*)Consulta
$dados_trabalhador.Nome
+
+ - Por Agendar + - Por Realizar +
+ + + + + + + #foreach ( $trabalhador in $v1 ) + + + + + + #end +
NomeConsultaTipo de Consulta
$trabalhador.nome_trabalhador + #if ( $trabalhador.estado_consulta ) + + #else + - + #end + $trabalhador.motivo_consulta
+ #else #foreach( $element in $v1 ) #set ( $counter = $velocityCount - 1 ) diff --git a/branches/SIPRP/web/contents/user_print.html b/branches/SIPRP/web/contents/user_print.html index 2d3106f0..589fd16c 100644 --- a/branches/SIPRP/web/contents/user_print.html +++ b/branches/SIPRP/web/contents/user_print.html @@ -62,9 +62,23 @@ #elseif( $query == "trabalhadores_pendentes" ) - + + + + + + + + #foreach ( $trabalhador in $v1 ) + + + + + + #end +
NomeConsultaTipo de Consulta
$trabalhador.nome_trabalhador$trabalhador.estado_consulta_print$trabalhador.motivo_consulta_print
+ + #*
(*)ECD - Exames Complementares de Diagnóstico
@@ -76,15 +90,14 @@ #set ( $counter = $velocityCount - 1 ) #set ( $dados_trabalhador = $v2.get($counter) ) - #end
  $dados_trabalhador.Nome $dados_trabalhador.Exame_estado $dados_trabalhador.Consulta_estado
+ *# + #end diff --git a/branches/SIPRP/web/src/siprp/pagina/GlobalConstants.java b/branches/SIPRP/web/src/siprp/pagina/GlobalConstants.java index 54442fd8..c057e83e 100644 --- a/branches/SIPRP/web/src/siprp/pagina/GlobalConstants.java +++ b/branches/SIPRP/web/src/siprp/pagina/GlobalConstants.java @@ -6,6 +6,8 @@ package siprp.pagina; +import java.util.Map; + /** * * @author fpalma @@ -34,7 +36,14 @@ public interface GlobalConstants public static final int TIPO_MARCACAO_EXAMES = 0; public static final int TIPO_MARCACAO_CONSULTA = 1; - public static final Integer ESTADO_POR_REALIZAR = new Integer( 0 ); - public static final Integer ESTADO_PARCIALMENTE_REALIZADO = new Integer( 1 ); - public static final Integer ESTADO_REALIZADO = new Integer( 2 ); + public static final int ESTADO_POR_REALIZAR = 0; + public static final int ESTADO_PARCIALMENTE_REALIZADO = 1; + public static final int ESTADO_REALIZADO = 2; + public static final int ESTADO_POR_AGENDAR = 7; + + + public static final int MOTIVO_ADMISSAO = 1; + public static final int MOTIVO_PERIODICO = 2; + public static final int MOTIVO_OCASIONAL = 3; + public static final int MOTIVO_PERIODICO_INICIAL = 5; } diff --git a/branches/SIPRP/web/src/siprp/pagina/doGetListaEmpresas.java b/branches/SIPRP/web/src/siprp/pagina/doGetListaEmpresas.java index 60303b2f..ab8879d4 100644 --- a/branches/SIPRP/web/src/siprp/pagina/doGetListaEmpresas.java +++ b/branches/SIPRP/web/src/siprp/pagina/doGetListaEmpresas.java @@ -11,10 +11,10 @@ import javax.servlet.http.*; import org.apache.velocity.*; import org.apache.velocity.app.*; -public class doGetListaEmpresas extends siprpServlet{ +public class doGetListaEmpresas extends siprpServlet +{ - /** Creates a new instance of doGetListaEmpresas */ - public doGetListaEmpresas(HttpServletRequest req, HttpServletResponse res) throws IOException + public doGetListaEmpresas( HttpServletRequest req, HttpServletResponse res ) throws IOException { ServletOutputStream out = res.getOutputStream(); Connection con = null ; @@ -42,7 +42,13 @@ empresa_nome = null; Class.forName(super.bdDriver); con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword ); dbQuery = new StringBuffer(); - dbQuery.append( "SELECT id, designacao_social, designacao_social_plain FROM empresas WHERE inactivo <> 'y' ORDER BY designacao_social_plain" ); + dbQuery.append( + "SELECT id, designacao_social, designacao_social_plain " + + "FROM empresas " + + "WHERE " + + "inactivo <> 'y' " + + "AND data_cancelamento IS NULL " + + "ORDER BY designacao_social_plain" ); stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) ); diff --git a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java index d37cb616..c340f84d 100644 --- a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java +++ b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadores.java @@ -24,7 +24,7 @@ public class doGetListaTrabalhadores extends siprpServlet } - public doGetListaTrabalhadores(HttpServletRequest req, HttpServletResponse res, String query) throws IOException + public doGetListaTrabalhadores(HttpServletRequest req, HttpServletResponse res, String query) throws Exception { boolean print = false; if( query != null ) diff --git a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java index 080cd09f..8920e88d 100644 --- a/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java +++ b/branches/SIPRP/web/src/siprp/pagina/doGetListaTrabalhadoresPendentes.java @@ -15,6 +15,7 @@ import java.sql.SQLException; import org.apache.velocity.*; import org.apache.velocity.app.*; +import org.apache.velocity.runtime.parser.node.GetExecutor; import com.evolute.utils.arrays.*; import com.evolute.utils.data.*; @@ -29,691 +30,653 @@ import com.evolute.utils.strings.*; public class doGetListaTrabalhadoresPendentes extends siprpServlet { - private static final long TRES_MESES = 3L * 30L * 24L * 60L * 60L * 1000L; - private static final long CATORZE_DIAS = 14L * 24L * 60L * 60L * 1000L; + private static final String DEFAULT_TIPO = "Admissão/Periódico Inicial"; - 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; + private static final Map< Integer, String > ESTADO_COR = new HashMap< Integer, String >(); + private static final Map< Integer, String > MOTIVO = new HashMap< Integer, String >(); + private static final Map< Integer, String > ESTADOS = new HashMap< Integer, String >(); - protected static int MOTIVO_ADMISSAO = 1; - protected static int MOTIVO_PERIODICA = 2; - protected static int MOTIVO_OCASIONAL = 3; - protected static int MOTIVO_PERIODICA_INICIAL = 5; - - protected static final Hashtable CORES_ESTADOS = new Hashtable(); - protected static final Hashtable TEXTOS_ESTADOS = new Hashtable(); static { - CORES_ESTADOS.put( new Integer( ESTADO_NAO_APLICAVEL ), "white" ); - CORES_ESTADOS.put( new Integer( ESTADO_PENDENTE ), "red" ); - CORES_ESTADOS.put( new Integer( ESTADO_MARCADO ), "yellow" ); - CORES_ESTADOS.put( new Integer( ESTADO_TRATADO ), "green" ); + ESTADOS.put( ESTADO_POR_REALIZAR, "Por Realizar" ); + ESTADOS.put( ESTADO_PARCIALMENTE_REALIZADO, "Parcialmente Realizada" ); + ESTADOS.put( ESTADO_REALIZADO, "Realizada" ); + ESTADOS.put( ESTADO_POR_AGENDAR, "Por Agendar" ); + + ESTADO_COR.put( ESTADO_POR_REALIZAR, "yellow" ); + ESTADO_COR.put( ESTADO_POR_AGENDAR, "red" ); - TEXTOS_ESTADOS.put( new Integer( ESTADO_NAO_APLICAVEL ), "n.a." ); - TEXTOS_ESTADOS.put( new Integer( ESTADO_PENDENTE ), "pendente" ); - TEXTOS_ESTADOS.put( new Integer( ESTADO_MARCADO ), "pendente" ); -// TEXTOS_ESTADOS.put( new Integer( ESTADO_TRATADO ), "green" ); +// MOTIVO.put( MOTIVO_ADMISSAO, "Admissão" ); + MOTIVO.put( MOTIVO_PERIODICO, "Periódico" ); + MOTIVO.put( MOTIVO_OCASIONAL, "Ocasional" ); +// MOTIVO.put( MOTIVO_PERIODICO_INICIAL, "Periódico Inicial" ); } - protected Date today; - protected long todayMillis; - - /** Creates a new instance of doGetListaTrabalhadores */ -// public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print) + + public doGetListaTrabalhadoresPendentes( HttpServletRequest req, HttpServletResponse res, boolean print ) + throws Exception + { + System.out.println( "\ndoGetListaTrabalhadoresPendentes() : " ); + + ServletOutputStream out = res.getOutputStream(); + HttpSession session = req.getSession( false ); + + String userRole = ( String ) session.getAttribute( sessionUserRole ); + String userName = ( String ) session.getAttribute( sessionUser ); + String empresaID = ( String ) session.getAttribute( sessionEmpresaId ); +// String empresaNome = ( String ) session.getAttribute( sessionCompanyName ); + String empresaNome = nomeEmpresa( null, empresaID ); + String estabelecimentoID = ( String ) session.getAttribute( sessionEstabelecimentoId ); + String estabelecimentoNome = nomeEstabelecimento( null, estabelecimentoID ); + + System.out.println( "\tuserName : " + userName ); + System.out.println( "\tuserRole : " + userRole ); + System.out.println( "\tempresaID : " + empresaID + " - " + empresaNome ); + System.out.println( "\testabelecimentoID : " + estabelecimentoID ); + + if ( superUserRole.equals( userRole ) || userRole.equals( empresaID ) ) + { + if ( verificaEstabelecimento( null, empresaID, estabelecimentoID ) ) + { + + List< Map< String, Object > > list = new LinkedList< Map< String, Object > >(); + + String query = "( " + + " select t.id, t.nome, m.id, m.data, m.tipo, m.motivo, m.estado " + + " from marcacoes_trabalhador m " + + " inner join trabalhadores t on ( t.id = m.trabalhador_id ) " + + " where " + + " m.deleted_stamp is null " + + " and t.estabelecimento_id = " + estabelecimentoID + " " + + " and t.inactivo != 'y' " + + " and t.data_demissao is null " + + " and m.data <= now() " + + " and m.tipo = " + TIPO_MARCACAO_CONSULTA + " " + + " and ( m.estado = " + ESTADO_POR_AGENDAR + " or m.estado = " + ESTADO_POR_REALIZAR + " ) " + + " and m.motivo in ( " + MOTIVO_PERIODICO + ", " + MOTIVO_OCASIONAL + " ) " + + " order by t.nome " + + ") " + + "union " + + "( " + + " select " + + " t.id, t.nome, m.id, m.data, m.tipo, m.motivo, m.estado " + + " from trabalhadores t " + + " left outer join marcacoes_trabalhador m on ( t.id = m.trabalhador_id ) " + + " where " + + " m.deleted_stamp is null " + + " and t.estabelecimento_id = " + estabelecimentoID + " " + + " and t.data_demissao is null " + + " and t.inactivo != 'y' " + + " and m.id is null " + + " order by t.nome " + + ") " + + "order by 2, 4, 7, 6"; + System.out.println( "\nQuery : " + query ); + + Virtual2DArray array = getExecuter().executeQuery( new Select( query ) ); + for ( int i = 0; i < array.columnLength(); i++ ) + { + Integer trabalhadorID = ( Integer ) array.get( i, 0 ); + String nome = ( String ) array.get( i, 1 ); + Integer estado = ( Integer ) array.get( i, 6 ); + Integer motivo = ( Integer ) array.get( i, 5 ); + + String estado_image = getEstadoImage( estado ); + String estado_print = getEstadoToPrint( estado ); + String motivo_string = getMotivoDescription( motivo ); + + Map< String, Object > map = new HashMap< String, Object >(); + map.put( "nome_trabalhador", nome ); + map.put( "estado_consulta", estado_image ); + map.put( "estado_consulta_print", estado_print ); + map.put( "motivo_consulta", motivo_string ); + map.put( "motivo_consulta_print", motivo_string ); + map.put( "link_trabalhador", "/" + servletName + "/?" + empresaID + "/" + estabelecimentoID + "/" + trabalhadorID ); + list.add( map ); + } + + HashMap hmValues = new HashMap(); + hmValues.put( "empresa_nome", empresaNome ); + hmValues.put( "empresa_id", empresaID ); + hmValues.put( "estabelecimento_nome", estabelecimentoNome ); + hmValues.put( "estabelecimento_id", estabelecimentoID ); + hmValues.put( "userRole", userRole ); + hmValues.put( "userName", userName ); + hmValues.put( msgTemplate , "" + empresaNome + "

" + estabelecimentoNome + "" ); + hmValues.put( templateUserRole, userRole ); + hmValues.put( templateQuery, "trabalhadores_pendentes" ); + hmValues.put( templateVector1, list ); + hmValues.put( templateVector2, null ); + hmValues.put( templateVector3, null ); + + out.println( mergeTemplate( hmValues, ! print ? authenticatedUserTemplate : authenticatedUserPrintTemplate ) ); + } + else // est nao pertence 'a empresa + { + out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) ); + } + } + else // Role nao permite ver esta informacao + { + out.println( mergeTemplate( super.msgAcessoNegado, userRole, super.errorTemplate ) ); + } + } + + private String getEstadoImage( Integer estadoID ) + { + String image = ESTADO_COR.get( estadoID ); + return image; + } + + private String getEstadoToPrint( Integer estadoID ) + { + String estado = ESTADOS.get( estadoID ); + return estado == null ? "-" : estado; + } + + private String getMotivoDescription( Integer motivoID ) + { + String motivo = MOTIVO.get( motivoID ); + return motivo == null ? DEFAULT_TIPO : motivo; + } + + + + + + +// public doGetListaTrabalhadoresPendentes( HttpServletRequest req, HttpServletResponse res, boolean print ) // throws IOException // { +// System.out.println( "\ndoGetListaTrabalhadoresPendentes() : " ); +// // 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); +// String userRole, empresaId, estabelecimentoId; +// 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(); +// { +// Executer executer = getExecuter(); +// today = new Date(); // 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 ) ) +// System.out.println( "\tuserRole : " + userRole ); +// System.out.println( "\tempresaID : " + empresaId ); +// System.out.println( "\testabelecimentoID : " + estabelecimentoId ); +// +// 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 a empresa ?? +// if ( verificaEstabelecimento( null, empresaId, estabelecimentoId ) ) // estabelecimento pertence 'a 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.deleted_stamp is null" +//// + " AND marcacoes_trabalhador.data < now()" +// + " 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.deleted_stamp is null" +//// + " AND marcacoes_trabalhador.data < now()" +// + " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_EXAMES + " )" +// + " ORDER BY 6, 8, 3 DESC "; +// Virtual2DArray 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 +//// + " 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 ) ); +// +// query = "SELECT trabalhadores.id, trabalhadores.nome " +// + "FROM trabalhadores " +// + "WHERE estabelecimento_id = " + estabelecimentoId +// + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL;"; +// Virtual2DArray trabalhadoresArray = executer.executeQuery( new Select( query ) ); +// +// Hashtable marcacoesPorID = new Hashtable(); +// Hashtable ocasionaisPorID = new Hashtable(); +// Hashtable nomesPorID = new Hashtable(); +// for( int n = 0; n < trabalhadoresArray.columnLength(); n++ ) +// { +// nomesPorID.put( trabalhadoresArray.get( n, 0 ), trabalhadoresArray.get( n, 1 ) ); +// } // -// for ( index = 0; index <= max; index++ ) +// preencherMarcacoes( array, nomesPorID, marcacoesPorID ); +// preencherMarcacoes( ocasionaisArray, 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 ) +// trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) ); +// } +// Arrays.sort( trabalhadores, new Comparator() { +// public int compare( Object o1, Object o2 ) // { -// break; +// String nome1 = StringPlainer.convertString( o1.toString() ); +// String nome2 = StringPlainer.convertString( o2.toString() ); +// return nome1.compareTo( nome2 ); // } -// 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 ) +// } ); +// +// for( int n = 0; n < trabalhadores.length; n++ ) +// { +// Integer trabalhadorID = trabalhadores[ n ].getID(); +// +// Object marcacoes[][] = new Object[ 0 ][ ]; +// if ( marcacoesPorID.containsKey( trabalhadorID ) ) // { -// continue; +// marcacoes = ( Object[][] ) ( ( Vector ) marcacoesPorID.get( trabalhadorID ) ).toArray( new Object[ 0 ][] ); // } -// switch( tipo.intValue() ) +// Object ocasionais[][] = new Object[ 0 ][ ]; +// if( ocasionaisPorID.containsKey( trabalhadorID ) ) // { -// case TIPO_MARCACAO_EXAMES: -// exames.add( marcacao ); -// break; -// -// case TIPO_MARCACAO_CONSULTA: -// consultas.add( marcacao ); -// break; +// 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( trabalhadorID, new Integer( empresaId ) ), +// perfilTemExames( trabalhadorID, new Integer( empresaId ) ) ); // } -// stmt.close(); -// -// sBuffer = new StringBuffer(); -// sBuffer.append(""+super.nomeEmpresa(con,empresaId)+"

" -// +super.nomeEstabelecimento(con, estabelecimentoId)+"" ); -// +// // 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( 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 ) ); // } -// con.close(); // } // 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 ) ); // } // } - 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 ); - Vector links = new Vector(); - Vector desc = new Vector(); - Vector descAdicional = new Vector(); - try - { - Executer executer = getExecuter(); - today = new Date(); - todayMillis = today.getTime(); - - 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 ?? - { - 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 ( 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, " - + "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 ( 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 "; - Virtual2DArray array = executer.executeQuery( new Select( query ) ); - - 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 ( 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 ) ); - - query = "SELECT trabalhadores.id, trabalhadores.nome " - + "FROM trabalhadores " - + "WHERE estabelecimento_id = " + estabelecimentoId - + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL;"; - Virtual2DArray trabalhadoresArray = executer.executeQuery( new Select( query ) ); - - Hashtable marcacoesPorID = new Hashtable(); - Hashtable ocasionaisPorID = new Hashtable(); - Hashtable nomesPorID = new Hashtable(); - for( int n = 0; n < trabalhadoresArray.columnLength(); n++ ) - { - nomesPorID.put( trabalhadoresArray.get( n, 0 ), trabalhadoresArray.get( n, 1 ) ); - } - - preencherMarcacoes( array, nomesPorID, marcacoesPorID ); - preencherMarcacoes( ocasionaisArray, 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++ ) - { - trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) ); - } - Arrays.sort( trabalhadores, new Comparator() { - public int compare( Object o1, Object o2 ) - { - String nome1 = StringPlainer.convertString( o1.toString() ); - String nome2 = StringPlainer.convertString( o2.toString() ); - return nome1.compareTo( nome2 ); - } - } ); - - for( int n = 0; n < trabalhadores.length; n++ ) - { - Integer trabalhadorID = trabalhadores[ n ].getID(); - - Object marcacoes[][] = new Object[ 0 ][ ]; - if ( marcacoesPorID.containsKey( trabalhadorID ) ) - { - marcacoes = ( Object[][] ) ( ( Vector ) marcacoesPorID.get( trabalhadorID ) ).toArray( new Object[ 0 ][] ); - } - Object ocasionais[][] = new Object[ 0 ][ ]; - if( ocasionaisPorID.containsKey( trabalhadorID ) ) - { - 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( trabalhadorID, new Integer( empresaId ) ), - perfilTemExames( trabalhadorID, new Integer( empresaId ) ) ); - } - - HashMap hmValues = new HashMap(); - hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) ); - hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) ); - 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 , "" + 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 ) - { - out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate ) ); - } - else - { - out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate ) ); - } - } - else // est nao pertence 'a empresa - { - out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) ); - } - } - else // Role nao permite ver esta informacao - { - 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 ) ); - } - } - - - protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID ) - { - for ( int index = 0; index < array.columnLength(); index++ ) - { - 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 ) ) - { - nomesPorID.put( id, nome ); - marcacoesPorID.put( id, new Vector() ); - } - if ( data != null ) - { - Object marcacao[] = new Object[] { data, estado, motivo, tipo }; - ( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao ); - } - } - } +// protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID ) +// { +// for ( int index = 0; index < array.columnLength(); index++ ) +// { +// 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 ) ) +// { +// nomesPorID.put( id, nome ); +// marcacoesPorID.put( id, new Vector() ); +// } +// if ( data != null ) +// { +// Object marcacao[] = new Object[] { data, estado, motivo, tipo }; +// ( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao ); +// } +// } +// } +// +// protected Object[][] agruparMarcacoes( Object marcacoes[][], Object ocasionais[][] ) +// { +// long 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 ) +// { +// for ( int n = 0; n < marcacoes.length; n++ ) +// { +// if ( grupo == null ) +// { +// grupo = new Object[ 5 ]; +// dataExame = null; +// estadoExame = null; +// dataConsulta = null; +// motivoConsulta = null; +// estadoConsulta = null; +// grupos.add( grupo ); +// } +// +// 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() ) +// { +// case TIPO_MARCACAO_EXAMES: +// if( dataConsulta == null && +// ( dataExame == null || estadoExame.intValue() < 2 ) ) +// { +// dataExame = data; +// estadoExame = estado; +// } +// else if( dataConsulta != null && 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; +// } +// } +// } +// if ( ocasionais != null ) +// { +// for ( int n = 0; n < ocasionais.length; n++ ) +// { +// grupo = new Object[ 5 ]; +// for( int i = 0; i < 3; i++ ) +// { +// grupo[ i ] = ocasionais[ n ][ i ]; +// } +// grupos.add( grupo ); +// } +// } +// +// 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 void acrescentarTrabalhador( String empresaID, String estabelecimentoID, +// IDObject trabalhador, java.util.Date dataFicha, +// 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 ) +// { +//// 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++ ) +// { +// 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 ) ) +// { +// break; +// } +// } +// +// index = index == -1 ? 0 : index; +// for ( ; index < marcacoes.length; index++ ) +// { +// dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ]; +// dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; +// boolean temConsulta = dataConsulta != null; +// 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 ) ) +// { +// break; +// } +// } +// +// if ( index >= marcacoes.length ) +// { +// index = marcacoes.length - 1; +// } +// else +// { +// 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 ( index > 0 ) +// { +// index--; +// } +// else +// { +// pendente = true; +// } +// } +// } +// } +// dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ]; +// Integer estadoConsulta = ( Integer ) marcacoes[ index ][ 1 ]; +// Integer motivoConsulta = ( Integer ) marcacoes[ index ][ 2 ]; +// dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; +// Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ]; +// if ( perfilConsultas ) +// { +// if ( dataConsulta == null || pendente ) +// { +// estado[ 0 ] = ESTADO_PENDENTE; +// } +// else if ( estadoConsulta == null || estadoConsulta.intValue() != 2 ) +// { +// estado[ 0 ] = ESTADO_MARCADO; +// } +// else +// { +// estado[ 0 ] = ESTADO_TRATADO; +// } +// } +// else +// { +// estado[ 0 ] = ESTADO_NAO_APLICAVEL; +// } +// +// if ( perfilExames ) +// { +// if ( dataExame == null || pendente ) +// { +// estado[ 1 ] = motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL ? +// ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL ; +// } +// else if ( estadoExame == null || estadoExame.intValue() != 2 ) +// { +// estado[ 1 ] = ESTADO_MARCADO; +// } +// else +// { +// estado[ 1 ] = ESTADO_TRATADO; +// } +// } +// else +// { +// estado[ 1 ] = ESTADO_NAO_APLICAVEL; +// } +// } +// +//// 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 ) +// { +//// 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 ); +// } +// } +// +// protected boolean perfilTemConsultas( Integer trabalhadorID, Integer empresaID ) +// throws Exception +// { +// String query = "SELECT a_consultas, b_consultas FROM empresas WHERE id = " + empresaID; +// return perfilTem( query, trabalhadorID ); +// } +// +// protected boolean perfilTemExames( Integer trabalhadorID, Integer empresaID ) +// throws Exception +// { +// 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 ); +// return perfil != null && consultas[ perfil.intValue() - 1 ]; +// } - protected Object[][] agruparMarcacoes( Object marcacoes[][], Object ocasionais[][] ) - { - long 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 ) - { - for ( int n = 0; n < marcacoes.length; n++ ) - { - if ( grupo == null ) - { - grupo = new Object[ 5 ]; - dataExame = null; - estadoExame = null; - dataConsulta = null; - motivoConsulta = null; - estadoConsulta = null; - grupos.add( grupo ); - } - - 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() ) - { - case TIPO_MARCACAO_EXAMES: - if( dataConsulta == null && - ( dataExame == null || estadoExame.intValue() < 2 ) ) - { - dataExame = data; - estadoExame = estado; - } - else if( dataConsulta != null && 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; - } - } - } - if ( ocasionais != null ) - { - for ( int n = 0; n < ocasionais.length; n++ ) - { - grupo = new Object[ 5 ]; - for( int i = 0; i < 3; i++ ) - { - grupo[ i ] = ocasionais[ n ][ i ]; - } - grupos.add( grupo ); - } - } - - 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 void acrescentarTrabalhador( String empresaID, String estabelecimentoID, - IDObject trabalhador, java.util.Date dataFicha, - 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 ) - { -// 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++ ) - { - 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 ) ) - { - break; - } - } - - index = index == -1 ? 0 : index; - for ( ; index < marcacoes.length; index++ ) - { - dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ]; - dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; - boolean temConsulta = dataConsulta != null; - 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 ) ) - { - break; - } - } - - if ( index >= marcacoes.length ) - { - index = marcacoes.length - 1; - } - else - { - 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 ( index > 0 ) - { - index--; - } - else - { - pendente = true; - } - } - } - } - dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ]; - Integer estadoConsulta = ( Integer ) marcacoes[ index ][ 1 ]; - Integer motivoConsulta = ( Integer ) marcacoes[ index ][ 2 ]; - dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; - Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ]; - if ( perfilConsultas ) - { - if ( dataConsulta == null || pendente ) - { - estado[ 0 ] = ESTADO_PENDENTE; - } - else if ( estadoConsulta == null || estadoConsulta.intValue() != 2 ) - { - estado[ 0 ] = ESTADO_MARCADO; - } - else - { - estado[ 0 ] = ESTADO_TRATADO; - } - } - else - { - estado[ 0 ] = ESTADO_NAO_APLICAVEL; - } - - if ( perfilExames ) - { - if ( dataExame == null || pendente ) - { - estado[ 1 ] = motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL ? - ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL ; - } - else if ( estadoExame == null || estadoExame.intValue() != 2 ) - { - estado[ 1 ] = ESTADO_MARCADO; - } - else - { - estado[ 1 ] = ESTADO_TRATADO; - } - } - else - { - estado[ 1 ] = ESTADO_NAO_APLICAVEL; - } - } - -// 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 ) - { -// 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 ); - } - } - protected boolean perfilTemConsultas( Integer trabalhadorID, Integer empresaID ) - throws Exception - { - String query = "SELECT a_consultas, b_consultas FROM empresas WHERE id = " + empresaID; - return perfilTem( query, trabalhadorID ); - } - protected boolean perfilTemExames( Integer trabalhadorID, Integer empresaID ) - throws Exception - { - 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 ); - return perfil != null && consultas[ perfil.intValue() - 1 ]; - }