forked from Coded/SIPRP
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							299 lines
						
					
					
						
							10 KiB
						
					
					
				
			
		
		
	
	
							299 lines
						
					
					
						
							10 KiB
						
					
					
				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 org.apache.velocity.*;
 | 
						|
import org.apache.velocity.app.*;
 | 
						|
 | 
						|
public class doGetTrabalhador extends siprpServlet
 | 
						|
{
 | 
						|
    
 | 
						|
    /** Creates a new instance of doGetTrabalhador */
 | 
						|
	public doGetTrabalhador(HttpServletRequest req, HttpServletResponse res) throws IOException
 | 
						|
	{
 | 
						|
		ServletOutputStream out = res.getOutputStream();
 | 
						|
		Connection con = null ;
 | 
						|
		Statement stmt = null ;
 | 
						|
		ResultSet2DArray rs;
 | 
						|
		StringBuffer dbQuery, sBuffer;
 | 
						|
		String userRole, empresaId, estabelecimentoId, trabalhadorId, temp;
 | 
						|
		HttpSession session = req.getSession(false);
 | 
						|
		Vector names = new Vector();
 | 
						|
		Vector values = new Vector();
 | 
						|
		java.util.Date today = new java.util.Date();
 | 
						|
 | 
						|
		try
 | 
						|
		{
 | 
						|
			userRole = (String)session.getAttribute(super.sessionUserRole);
 | 
						|
			empresaId = (String)session.getAttribute(super.sessionEmpresaId);
 | 
						|
			estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
 | 
						|
			trabalhadorId = (String)session.getAttribute(super.sessionTrabalhadorId);   
 | 
						|
 | 
						|
			Class.forName(super.bdDriver);
 | 
						|
			con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
 | 
						|
 | 
						|
			if ( ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
 | 
						|
				&& super.verificaEstabelecimento(con, empresaId, estabelecimentoId)
 | 
						|
				&& super.verificaTrabalhador(con, estabelecimentoId,  trabalhadorId) )
 | 
						|
			{
 | 
						|
 | 
						|
				dbQuery = new StringBuffer();
 | 
						|
				dbQuery.append( " SELECT sexo, categoria, data_nascimento, nome, numero_mecanografico "
 | 
						|
								+ "FROM trabalhadores  where id='"+trabalhadorId+"'");
 | 
						|
				stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 | 
						|
				rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
 | 
						|
 | 
						|
				//		int index=0;
 | 
						|
				//                int max = super.trabalhadorDescFields.length;
 | 
						|
 | 
						|
				HashMap hmFuncionario = new HashMap();
 | 
						|
				if( rs.columnLength() > 0 )
 | 
						|
				{
 | 
						|
					String tmp;
 | 
						|
					hmFuncionario.put( "sexo", rs.get( 0, "sexo" ) );
 | 
						|
					hmFuncionario.put( "categoria", rs.get( 0, "categoria" ) );
 | 
						|
					hmFuncionario.put( "data_nascimento", rs.get( 0, "data_nascimento" ) );
 | 
						|
					hmFuncionario.put( "nome", rs.get( 0, "nome" ) );
 | 
						|
					hmFuncionario.put( "numero", rs.get( 0, "numero_mecanografico" ) );
 | 
						|
					stmt.close();
 | 
						|
					
 | 
						|
					String query = "SELECT id, data, realizada, data_relatorio FROM marcacoes_trabalhador "
 | 
						|
									+ "WHERE tipo = 0 and trabalhador_id = " + trabalhadorId
 | 
						|
									+ " ORDER BY data DESC";
 | 
						|
					stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 | 
						|
					rs = new ResultSet2DArray( stmt.executeQuery( query ) );
 | 
						|
					if( rs.columnLength() > 0 )
 | 
						|
					{
 | 
						|
						java.util.Date dataExame2 = ( java.util.Date ) rs.get( 0, 1 );
 | 
						|
						String realizado2 = ( String ) rs.get( 0, 2 );
 | 
						|
						java.util.Date dataExame1;
 | 
						|
						String realizado1;
 | 
						|
						if( rs.columnLength() > 1 )
 | 
						|
						{
 | 
						|
							dataExame1 = ( java.util.Date ) rs.get( 1, 1 );
 | 
						|
							realizado1 = ( String ) rs.get( 1, 2 );
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							dataExame1 = dataExame2;
 | 
						|
							realizado1 = realizado2;
 | 
						|
						}
 | 
						|
						if( "y".equals( realizado2 ) || today.after( dataExame2 ) )
 | 
						|
						{
 | 
						|
							hmFuncionario.put( "ultimo_exame", dataExame2 );
 | 
						|
							if( realizado2.equals( "n" ) )
 | 
						|
							{
 | 
						|
								realizado2 = "não";
 | 
						|
							}
 | 
						|
							else if( realizado2.equals( "s" ) || realizado2.equals( "y" ) )
 | 
						|
							{
 | 
						|
								realizado2 = "sim";
 | 
						|
							}
 | 
						|
							hmFuncionario.put( "realizado", realizado2 );
 | 
						|
							hmFuncionario.put( "proximo_exame", null );
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							hmFuncionario.put( "proximo_exame", dataExame2 );
 | 
						|
							if( !dataExame2.equals( dataExame1 ) )
 | 
						|
							{
 | 
						|
								hmFuncionario.put( "ultimo_exame", dataExame1 );
 | 
						|
								if( realizado1.equals( "n" ) )
 | 
						|
								{
 | 
						|
									realizado1 = "não";
 | 
						|
								}
 | 
						|
								else if( realizado1.equals( "s" ) || realizado1.equals( "y" ) )
 | 
						|
								{
 | 
						|
									realizado1 = "sim";
 | 
						|
								}
 | 
						|
								hmFuncionario.put( "realizado", realizado1 );
 | 
						|
							}
 | 
						|
							else
 | 
						|
							{
 | 
						|
								hmFuncionario.put( "ultimo_exame", null );
 | 
						|
								hmFuncionario.put( "realizado", null );
 | 
						|
							}
 | 
						|
						}
 | 
						|
					}
 | 
						|
					else
 | 
						|
					{
 | 
						|
						hmFuncionario.put( "ultimo_exame", null );
 | 
						|
						hmFuncionario.put( "realizado", null );
 | 
						|
						hmFuncionario.put( "proximo_exame", null );
 | 
						|
					}
 | 
						|
					stmt.close();
 | 
						|
					
 | 
						|
					query = "SELECT MAX(id) FROM exames WHERE trabalhador_id = " + trabalhadorId + " AND inactivo <> 'y'";
 | 
						|
					stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 | 
						|
					rs = new ResultSet2DArray( stmt.executeQuery( query ) );
 | 
						|
					Integer fichaId = null;
 | 
						|
					if( rs.columnLength() > 0 )
 | 
						|
					{
 | 
						|
						fichaId = ( Integer ) rs.get( 0, 0 );
 | 
						|
					}
 | 
						|
					stmt.close();
 | 
						|
					
 | 
						|
					if( fichaId != null )
 | 
						|
					{
 | 
						|
						query = "SELECT data, resultado FROM exames WHERE id = " + fichaId;
 | 
						|
						stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 | 
						|
						rs = new ResultSet2DArray( stmt.executeQuery( query ) );
 | 
						|
						Integer resultadoFicha = (Integer) rs.get( 0, 1 );
 | 
						|
						stmt.close();
 | 
						|
						if( resultadoFicha != null )
 | 
						|
						{
 | 
						|
							switch( resultadoFicha.intValue() )
 | 
						|
							{
 | 
						|
								case 1:
 | 
						|
									hmFuncionario.put( "resultado", "Apto" );
 | 
						|
									break;
 | 
						|
								case 2:
 | 
						|
									hmFuncionario.put( "resultado", "Apto Condicionalmente" );
 | 
						|
									break;
 | 
						|
								case 3:
 | 
						|
									hmFuncionario.put( "resultado", "Inapto Temporariamente" );
 | 
						|
									break;
 | 
						|
								case 4:
 | 
						|
									hmFuncionario.put( "resultado", "Inapto Definitivamente" );
 | 
						|
									break;
 | 
						|
								default:
 | 
						|
									hmFuncionario.put( "resultado", null );
 | 
						|
							}
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							hmFuncionario.put( "resultado", null );
 | 
						|
						}
 | 
						|
					}
 | 
						|
					else
 | 
						|
					{
 | 
						|
						hmFuncionario.put( "resultado", null );
 | 
						|
					}
 | 
						|
					
 | 
						|
					query = "SELECT id, data, realizada FROM marcacoes_trabalhador "
 | 
						|
							+ "WHERE tipo = 1 and trabalhador_id = " + trabalhadorId
 | 
						|
							+ " ORDER BY data DESC";
 | 
						|
					stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 | 
						|
					rs = new ResultSet2DArray( stmt.executeQuery( query ) );
 | 
						|
					if( rs.columnLength() > 0 )
 | 
						|
					{
 | 
						|
						java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
 | 
						|
						String realizada2 = ( String ) rs.get( 0, 2 );
 | 
						|
						java.util.Date dataConsulta1;
 | 
						|
//						java.util.Date dataRelatorio1;
 | 
						|
//						java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 );
 | 
						|
						String realizada1;
 | 
						|
						if( rs.columnLength() >= 2 )
 | 
						|
						{
 | 
						|
							dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
 | 
						|
							realizada1 = ( String ) rs.get( 1, 2 );
 | 
						|
//							dataRelatorio1 = (java.util.Date) rs.get( 1, 3 );
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							dataConsulta1 = dataConsulta2;
 | 
						|
							realizada1 = realizada2;
 | 
						|
//							dataRelatorio1 = dataRelatorio2;
 | 
						|
						}
 | 
						|
						if( "y".equals( realizada2 ) || today.after( dataConsulta2 ) )
 | 
						|
						{
 | 
						|
							hmFuncionario.put( "ultima_consulta", dataConsulta2 );
 | 
						|
							if( realizada2.equals( "n" ) )
 | 
						|
							{
 | 
						|
								realizada2 = "não";
 | 
						|
							}
 | 
						|
							else if( realizada2.equals( "s" ) || realizada2.equals( "y" ) )
 | 
						|
							{
 | 
						|
								realizada2 = "sim";
 | 
						|
							}
 | 
						|
							hmFuncionario.put( "realizada", realizada2 );
 | 
						|
							hmFuncionario.put( "proxima_consulta", null );
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							hmFuncionario.put( "proxima_consulta", dataConsulta2 );
 | 
						|
							if( !dataConsulta2.equals( dataConsulta1 ) )
 | 
						|
							{
 | 
						|
								if( realizada1.equals( "n" ) )
 | 
						|
								{
 | 
						|
									realizada1 = "não";
 | 
						|
								}
 | 
						|
								else if( realizada1.equals( "s" ) || realizada1.equals( "y" ) )
 | 
						|
								{
 | 
						|
									realizada1 = "sim";
 | 
						|
								}
 | 
						|
								hmFuncionario.put( "realizada", realizada1 );
 | 
						|
								hmFuncionario.put( "ultima_consulta", dataConsulta1 );
 | 
						|
							}
 | 
						|
							else
 | 
						|
							{
 | 
						|
								hmFuncionario.put( "ultima_consulta", null );
 | 
						|
								hmFuncionario.put( "realizada", null );
 | 
						|
							}
 | 
						|
						}
 | 
						|
					}
 | 
						|
					else
 | 
						|
					{
 | 
						|
						hmFuncionario.put( "ultima_consulta", null );
 | 
						|
						hmFuncionario.put( "realizada", null );
 | 
						|
						hmFuncionario.put( "proxima_consulta", null );
 | 
						|
					}
 | 
						|
					stmt.close();
 | 
						|
				}
 | 
						|
 | 
						|
				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 ) );
 | 
						|
 | 
						|
				/*Dados para marcacao de consulta/exame*/
 | 
						|
				session.setAttribute( "session_estabelecimento_nome", hmValues.get( "estabelecimento_nome" ) );
 | 
						|
				session.setAttribute( "session_funcionario_nome", hmFuncionario.get( "nome" ) );
 | 
						|
				session.setAttribute( "session_funcionario_numero", hmFuncionario.get( "numero" ) );
 | 
						|
 | 
						|
				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, super.queryStringTrabalhador );
 | 
						|
				hmValues.put( "funcionario", hmFuncionario );
 | 
						|
				//hmValues.put( templateVector1,names);
 | 
						|
				//hmValues.put( templateVector2,values);
 | 
						|
				//hmValues.put( templateVector3,null);
 | 
						|
				out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));  
 | 
						|
 | 
						|
				//		out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhador, names, values, null, super.authenticatedUserTemplate) ); 
 | 
						|
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
 | 
						|
			}
 | 
						|
			con.close();
 | 
						|
		}
 | 
						|
		catch ( SQLException e )
 | 
						|
		{
 | 
						|
			e.printStackTrace();
 | 
						|
			out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
 | 
						|
		}
 | 
						|
		catch ( Exception e )
 | 
						|
		{
 | 
						|
			e.printStackTrace();
 | 
						|
			out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
 | 
						|
		}
 | 
						|
 | 
						|
	}
 | 
						|
 | 
						|
}
 |