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.
		
		
		
		
		
			
		
			
				
					
					
						
							296 lines
						
					
					
						
							9.2 KiB
						
					
					
				
			
		
		
	
	
							296 lines
						
					
					
						
							9.2 KiB
						
					
					
				| /*
 | |
|  * FichaDataProvider.java
 | |
|  *
 | |
|  * Created on 30 de Março de 2004, 11:31
 | |
|  */
 | |
| 
 | |
| package siprp;
 | |
| 
 | |
| import com.evolute.utils.*;
 | |
| import com.evolute.utils.arrays.*;
 | |
| import com.evolute.utils.db.*;
 | |
| import com.evolute.utils.db.keyretrievers.*;
 | |
| import com.evolute.utils.metadb.*;
 | |
| import com.evolute.utils.ui.search.*;
 | |
| import com.evolute.utils.sql.*;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author  pars
 | |
|  */
 | |
| public class FichaDataProvider extends MetaProvider implements SearchExecuter {
 | |
| 
 | |
| 	private static final Object LOCK = new Object();
 | |
| 	private static FichaDataProvider instance = null;
 | |
| 	private final Executer executer;
 | |
| 
 | |
| 	// empresas
 | |
| 	public static final String T_EMPRESAS = "empresas";
 | |
| 	public static final String ID = "id";
 | |
| 	public static final String DESIGNACAO_SOCIAL = "designacao_social";
 | |
| 	public static final String SERVICO_SAUDE_TIPO = "servico_saude_tipo";
 | |
| 	public static final String SERVICO_SAUDE_DESIGNACAO = "servico_saude_designacao";
 | |
| 	public static final String SERVICO_HIGIENE_TIPO = "servico_higiene_tipo";
 | |
| 	public static final String SERVICO_HIGIENE_DESIGNACAO = "servico_higiene_designacao";
 | |
| 	public static final String INACTIVO = "inactivo";
 | |
| 
 | |
| 	public static final DBTable EMPRESAS =
 | |
| 			new DBTable( T_EMPRESAS,
 | |
| 					new String[]{ DESIGNACAO_SOCIAL,
 | |
| 							SERVICO_SAUDE_TIPO,
 | |
| 							SERVICO_SAUDE_DESIGNACAO,
 | |
| 							SERVICO_HIGIENE_TIPO,
 | |
| 							SERVICO_HIGIENE_DESIGNACAO,
 | |
| 							INACTIVO },
 | |
| 					ID );
 | |
| 	
 | |
| 	// estabelecimentos
 | |
| 	public static final String T_ESTABELECIMENTOS = "estabelecimentos";
 | |
| 	// ID
 | |
| 	public static final String NOME = "nome";
 | |
| 	public static final String LOCALIDADE = "localidade";
 | |
| 	public static final String EMPRESA_ID = "empresa_id";
 | |
| 	// INACTIVO
 | |
| 
 | |
| 	public static final DBTable ESTABELECIMENTOS =
 | |
| 			new DBTable( T_ESTABELECIMENTOS,
 | |
| 					new String[]{ NOME, LOCALIDADE, EMPRESA_ID, INACTIVO },
 | |
| 					ID );
 | |
| 
 | |
| 	// trabalhadores
 | |
| 	public static final String T_TRABALHADORES = "trabalhadores";
 | |
| 	// ID
 | |
| 	// public static final String NOME = "nome";
 | |
| 	public static final String SEXO = "sexo";
 | |
| 	public static final String DATA_NASCIMENTO = "data_nascimento";
 | |
| 	public static final String NACIONALIDADE = "nacionalidade";
 | |
| 	public static final String NUMERO_MECANOGRAFICO = "numero_mecanografico";
 | |
| 	public static final String DATA_ADMISSAO = "data_admissao";
 | |
| 	public static final String CATEGORIA = "categoria";
 | |
| 	public static final String LOCAL_TRABALHO = "local_trabalho";
 | |
| 	public static final String FUNCAO_PROPOSTA = "funcao_proposta";
 | |
| 	public static final String DATA_ADMISSAO_FUNCAO = "data_admissao_funcao";
 | |
| 	public static final String OBSERVACOES = "observacoes";
 | |
| 	public static final String ESTABELECIMENTO_ID = "estabelecimento_id";
 | |
| 	// INACTIVO
 | |
| 
 | |
| 	public static final DBTable TRABALHADORES =
 | |
| 			new DBTable( T_TRABALHADORES,
 | |
| 					new String[]{ NOME, SEXO, DATA_NASCIMENTO,
 | |
| 							NACIONALIDADE, NUMERO_MECANOGRAFICO,
 | |
| 							DATA_ADMISSAO, CATEGORIA, LOCAL_TRABALHO,
 | |
| 							FUNCAO_PROPOSTA, DATA_ADMISSAO_FUNCAO,
 | |
| 							OBSERVACOES, ESTABELECIMENTO_ID, INACTIVO },
 | |
| 					ID );
 | |
| 	
 | |
| 	//medicos
 | |
| 	public static final String T_MEDICOS = "medicos";
 | |
| 	
 | |
| 	public static final String NUMERO_CEDULA = "numero_cedula";
 | |
| 	
 | |
| 	public static final DBTable MEDICOS =
 | |
| 			new DBTable( T_MEDICOS,
 | |
| 					new String[]{ NOME, NUMERO_CEDULA }, ID );
 | |
| 		
 | |
| 	// exames
 | |
| 	public static final String T_EXAMES = "exames";
 | |
| 	// ID
 | |
| 	public static final String DATA = "data";
 | |
| 	public static final String TIPO = "tipo";
 | |
| 	public static final String OCASIONAL = "ocasional";
 | |
| 	public static final String OUTRO_TIPO = "outro_tipo";
 | |
| 	public static final String RESULTADO = "resultado";
 | |
| 	public static final String OUTRA_FUNCAO_1 = "outra_funcao_1";
 | |
| 	public static final String OUTRA_FUNCAO_2 = "outra_funcao_2";
 | |
| 	public static final String OUTRA_FUNCAO_3 = "outra_funcao_3";
 | |
| 	public static final String OUTRA_FUNCAO_4 = "outra_funcao_4";
 | |
| 	public static final String PROXIMO_EXAME = "proximo_exame";
 | |
| 	public static final String OUTRAS_RECOMENDACOES = "outras_recomendacoes";
 | |
| 	public static final String TRABALHADOR_ID = "trabalhador_id";	
 | |
| 	public static final String MEDICO_ID = "medico_id";	
 | |
| 
 | |
| 	public static final DBTable EXAMES =
 | |
| 			new DBTable( T_EXAMES,
 | |
| 					new String[]{ DATA, TIPO, OCASIONAL,
 | |
| 							OUTRO_TIPO, RESULTADO, OUTRA_FUNCAO_1,
 | |
| 							OUTRA_FUNCAO_2, OUTRA_FUNCAO_3,
 | |
| 							OUTRA_FUNCAO_4, PROXIMO_EXAME,
 | |
| 							OUTRAS_RECOMENDACOES, TRABALHADOR_ID, MEDICO_ID },
 | |
| 					ID );
 | |
| 
 | |
| 	public static DBReference R_ESTABELECIMENTO_EMPRESA = new DBReference( ESTABELECIMENTOS.getFieldByName( EMPRESA_ID ) );
 | |
| 	public static DBReference R_TRABALHADOR_ESTABELECIMENTO = new DBReference( TRABALHADORES.getFieldByName( ESTABELECIMENTO_ID ) );
 | |
| 	public static DBReference R_EXAME_TRABALHADOR = new DBReference( EXAMES.getFieldByName( TRABALHADOR_ID ) );
 | |
| 	public static DBReference R_EXAME_MEDICO = new DBReference( EXAMES.getFieldByName( MEDICO_ID ) );
 | |
| 	static
 | |
| 	{
 | |
| 		try
 | |
| 		{
 | |
| 			EXAMES.addRelation( MEDICOS,
 | |
| 						new DBField[]{ EXAMES.getFieldByName( MEDICO_ID ) },
 | |
| 						"R_EXAMES_MEDICOS" );
 | |
| 			EXAMES.addRelation( TRABALHADORES,
 | |
| 						new DBField[]{ EXAMES.getFieldByName( TRABALHADOR_ID ) },
 | |
| 						"R_EXAMES_TRABALHADORES" );
 | |
| 			TRABALHADORES.addRelation( ESTABELECIMENTOS,
 | |
| 						new DBField[]{ TRABALHADORES.getFieldByName( ESTABELECIMENTO_ID ) },
 | |
| 						"R_TRABALHADORES_ESTABELECIMENTOS" );
 | |
| 			ESTABELECIMENTOS.addRelation( EMPRESAS,
 | |
| 						new DBField[]{ ESTABELECIMENTOS.getFieldByName( EMPRESA_ID ) },
 | |
| 						"R_ESTABELECIMENTOS_EMPRESAS" );
 | |
| 			EMPRESAS.disableSave( INACTIVO );
 | |
| 			ESTABELECIMENTOS.disableSave( INACTIVO );
 | |
| 			TRABALHADORES.disableSave( INACTIVO );
 | |
| 		}
 | |
| 		catch( Exception e )
 | |
| 		{
 | |
| 			throw new RuntimeException( e );
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	public static final int SEARCH_EMPRESAS = 0;
 | |
| 	public static final int SEARCH_ESTABELECIMENTOS = 1;
 | |
| 	public static final int SEARCH_TRABALHADORES = 2;
 | |
| 	public static final int SEARCH_EXAMES = 3;
 | |
| 	private int SEARCH = 0;
 | |
| 	private int SEARCH_EMPRESAS_ID = -1;
 | |
| 	private int SEARCH_ESTABELECIMENTOS_ID = -1;
 | |
| 	private int SEARCH_TRABALHADORES_ID = -1;
 | |
| 	private int SEARCH_EXAMES_ID = -1;
 | |
| 	
 | |
| 
 | |
| 	/** Creates a new instance of FichaDataProvider */
 | |
| 	public FichaDataProvider()
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ );
 | |
| 		executer = dbm.getSharedExecuter( this );
 | |
| 
 | |
| 		setDBTable( EXAMES );
 | |
| 		
 | |
| 	}
 | |
| 	
 | |
| 	public static MetaProvider getProvider()
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		synchronized( LOCK )
 | |
| 		{
 | |
| 			if( instance == null )
 | |
| 			{
 | |
| 				instance = new FichaDataProvider();
 | |
| 			}
 | |
| 		}
 | |
| 		return instance;
 | |
| 	}
 | |
| 	
 | |
| 	public String[] getColumnNames() {
 | |
| 		return new String[]{ "Nome" };
 | |
| 	}
 | |
| 	
 | |
| 	public String getSearchTitle() {
 | |
| 		switch( SEARCH )
 | |
| 		{
 | |
| 			case SEARCH_EMPRESAS:
 | |
| 				return "Procurar empresa";
 | |
| 			case SEARCH_ESTABELECIMENTOS:
 | |
| 				return "Procurar estabelecimento";
 | |
| 			case SEARCH_TRABALHADORES:
 | |
| 				return "Procurar trabalhador";
 | |
| 			case SEARCH_EXAMES:
 | |
| 				return "Procurar exame";
 | |
| 		}
 | |
| 		return "";
 | |
| 	}
 | |
| 	
 | |
| 	public boolean hasDetails() {
 | |
| 		return false;
 | |
| 	}
 | |
| 
 | |
| 	public void setSearch( int what )
 | |
| 	{
 | |
| 		switch( what )
 | |
| 		{
 | |
| 			case SEARCH_EMPRESAS:
 | |
| 			case SEARCH_ESTABELECIMENTOS:
 | |
| 			case SEARCH_TRABALHADORES:
 | |
| 			case SEARCH_EXAMES:
 | |
| 				SEARCH = what;
 | |
| 				break;
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	public void setSearchID( int what, int id )
 | |
| 	{
 | |
| 		switch( what )
 | |
| 		{
 | |
| 			case SEARCH_EMPRESAS:
 | |
| 				SEARCH_EMPRESAS_ID = id;
 | |
| 				break;
 | |
| 			case SEARCH_ESTABELECIMENTOS:
 | |
| 				SEARCH_ESTABELECIMENTOS_ID = id;
 | |
| 				break;
 | |
| 			case SEARCH_TRABALHADORES:
 | |
| 				SEARCH_TRABALHADORES_ID = id;
 | |
| 				break;
 | |
| 			case SEARCH_EXAMES:
 | |
| 				SEARCH_EXAMES_ID = id;
 | |
| 				break;
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	public Virtual2DArray search( String pattern ) throws Exception {
 | |
| 		switch( SEARCH )
 | |
| 		{
 | |
| 			case SEARCH_EMPRESAS:
 | |
| 				return searchEmpresas( pattern );
 | |
| 			case SEARCH_ESTABELECIMENTOS:
 | |
| 				return searchEstabelecimentos( pattern );
 | |
| 			case SEARCH_TRABALHADORES:
 | |
| 				return searchTrabalhadores( pattern );
 | |
| 			case SEARCH_EXAMES:
 | |
| 				return searchExames( pattern );
 | |
| 		}
 | |
| 		return null;
 | |
| 	}
 | |
| 	
 | |
| 	public Virtual2DArray searchEmpresas( String pattern ) throws Exception {
 | |
| 		Select select = new Select( "SELECT e.id, e.designacao_social FROM empresas e ORDER BY lower( e.designacao_social );" );
 | |
| 		return executer.executeQuery( select );
 | |
| 	}
 | |
| 
 | |
| 	public Virtual2DArray searchEstabelecimentos( String pattern ) throws Exception {
 | |
| 		Select select = new Select( "SELECT e.id, e.nome FROM estabelecimentos e WHERE empresa_id = " + SEARCH_EMPRESAS_ID
 | |
| 									+ " ORDER BY lower( e.nome )");
 | |
| 		return executer.executeQuery( select );
 | |
| 	}
 | |
| 
 | |
| 	public Virtual2DArray searchTrabalhadores( String pattern ) throws Exception {
 | |
| 		Select select = 
 | |
| 			new Select( "SELECT t.id, t.nome FROM trabalhadores t, estabelecimentos es "
 | |
| 						+ " WHERE t.estabelecimento_id = es.id "
 | |
| 						+ " AND es.empresa_id = " + SEARCH_EMPRESAS_ID + " ORDER BY lower(t.nome);" );
 | |
| 		return executer.executeQuery( select );
 | |
| 	}
 | |
| 
 | |
| 	public Virtual2DArray searchExames( String pattern ) throws Exception {
 | |
| 		Select select = new Select( "SELECT e.id, e.data FROM exames e "
 | |
| 									+ " WHERE e.trabalhador_id = " + SEARCH_TRABALHADORES_ID 
 | |
| 									+ " ORDER BY e.data DESC;" );
 | |
| 		return executer.executeQuery( select );
 | |
| 	}
 | |
| 
 | |
| 	public void showDetails(SearchDialog dialog, Object o) throws Exception {
 | |
| 	}
 | |
| 	
 | |
| 	public Object [][]getAllMedicos()
 | |
| 		throws Exception 
 | |
| 	{
 | |
| 		Select select = new Select( new String[]{ T_MEDICOS },
 | |
| 									new String[]{ ID, NOME, NUMERO_CEDULA },
 | |
| 									null, new String[]{ NOME }, null );
 | |
| 		Virtual2DArray array = executer.executeQuery( select );
 | |
| 		return array.getObjects();
 | |
| 	}
 | |
| 	
 | |
| }
 |