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.
518 lines
15 KiB
518 lines
15 KiB
/*
|
|
* FichaWindow.java
|
|
*
|
|
* Created on 29 de Março de 2004, 11:50
|
|
*/
|
|
|
|
package siprp.ficha;
|
|
|
|
import siprp.*;
|
|
|
|
import java.awt.*;
|
|
import java.util.*;
|
|
import javax.swing.*;
|
|
import java.text.*;
|
|
|
|
import com.evolute.utils.metadb.*;
|
|
import com.evolute.utils.ui.*;
|
|
import com.evolute.utils.ui.search.*;
|
|
import com.evolute.utils.ui.window.*;
|
|
|
|
/**
|
|
*
|
|
* @author fpalma
|
|
*/
|
|
public class FichaWindow extends TabbedWindow
|
|
{
|
|
private UpperPanel upperPanel;
|
|
private EmpresaPanel empresaPanel;
|
|
private TrabalhadorPanel trabalhadorPanel;
|
|
private ObservacoesPanel observacoesPanel;
|
|
private ExamePanel examePanel;
|
|
|
|
private FichaDataProvider fdpProvider;
|
|
private Integer empresaID;
|
|
private Integer estabelecimentoID;
|
|
private Integer trabalhadorID;
|
|
|
|
private static int permissions[][] =
|
|
new int[][]{ { NEW_INDEX, CANCEL_INDEX, SAVE_INDEX } };
|
|
|
|
/** Creates a new instance of FichaWindow */
|
|
public FichaWindow()
|
|
throws Exception
|
|
{
|
|
super( new UpperPanel(), new String[]{ "Empresa/Trabalhador", "Exame" },
|
|
createPermissions( permissions ) );
|
|
setEditorManagerFactory( FichaAptidaoEditorManager.getEditorManagerFactory() );
|
|
upperPanel = (UpperPanel) getUpperPanel();
|
|
upperPanel.owner = this;
|
|
fdpProvider = ( FichaDataProvider ) FichaDataProvider.getProvider();
|
|
setupComponents();
|
|
}
|
|
|
|
private void setupComponents()
|
|
throws Exception
|
|
{
|
|
setSize( 700, 570 );
|
|
setResizable( false );
|
|
setTitle( "Ficha de Aptid\u00e3o" );
|
|
|
|
JPanel empresaTrabalhadorPanel = getTab( 0 );
|
|
JPanel exameRecomendacoesPanel = getTab( 1 );
|
|
|
|
GridBagLayout gridbag = new GridBagLayout();
|
|
empresaTrabalhadorPanel.setLayout( gridbag );
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
constraints.insets = new Insets( 0, 1, 0, 1 );
|
|
constraints.fill = GridBagConstraints.BOTH;
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
constraints.gridheight = 1;
|
|
constraints.weighty = 0;
|
|
|
|
empresaPanel = new EmpresaPanel();
|
|
empresaPanel.setEnabled( false );
|
|
gridbag.setConstraints( empresaPanel, constraints );
|
|
empresaTrabalhadorPanel.add( empresaPanel );
|
|
|
|
constraints.weighty = 0;
|
|
trabalhadorPanel = new TrabalhadorPanel();
|
|
gridbag.setConstraints( trabalhadorPanel, constraints );
|
|
empresaTrabalhadorPanel.add( trabalhadorPanel );
|
|
|
|
constraints.weighty = 1;
|
|
observacoesPanel = new ObservacoesPanel();
|
|
gridbag.setConstraints( observacoesPanel, constraints );
|
|
empresaTrabalhadorPanel.add( observacoesPanel );
|
|
|
|
|
|
gridbag = new GridBagLayout();
|
|
exameRecomendacoesPanel.setLayout( gridbag );
|
|
constraints = new GridBagConstraints();
|
|
constraints.insets = new Insets( 0, 1, 0, 1 );
|
|
constraints.fill = GridBagConstraints.BOTH;
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
constraints.gridheight = 1;
|
|
constraints.weighty = 0;
|
|
|
|
constraints.weighty = 1;
|
|
examePanel = new ExamePanel();
|
|
gridbag.setConstraints( examePanel, constraints );
|
|
exameRecomendacoesPanel.add( examePanel );
|
|
|
|
registerAction( new ActionHandler(){
|
|
public void execute()
|
|
{
|
|
print();
|
|
}
|
|
|
|
public boolean activate( boolean newAction, boolean editAction,
|
|
boolean cancelAction, boolean saveAction,
|
|
boolean deleteAction, boolean selectAction )
|
|
{
|
|
return saveAction || editAction;
|
|
}
|
|
}, "Imprimir",
|
|
"Imprimir Ficha", "print",
|
|
0, true );
|
|
}
|
|
|
|
public boolean save( int index )
|
|
{
|
|
new ProgressDialog( this, "A gravar...",
|
|
new Runnable(){
|
|
public void run()
|
|
{
|
|
|
|
}
|
|
});
|
|
StringBuffer msg = new StringBuffer();
|
|
MetaObject medico;
|
|
try
|
|
{
|
|
medico = (MetaObject)upperPanel.save();
|
|
}
|
|
catch( ValuesException vex )
|
|
{
|
|
msg.append( vex.getMessage() );
|
|
medico = null;
|
|
}
|
|
MetaObject estabelecimento;
|
|
try
|
|
{
|
|
estabelecimento = (MetaObject)empresaPanel.save();
|
|
}
|
|
catch( ValuesException vex )
|
|
{
|
|
msg.append( vex.getMessage() );
|
|
estabelecimento = null;
|
|
}
|
|
MetaObject trabalhador;
|
|
try
|
|
{
|
|
trabalhador = (MetaObject)trabalhadorPanel.save();
|
|
}
|
|
catch( ValuesException vex )
|
|
{
|
|
msg.append( vex.getMessage() );
|
|
trabalhador = null;
|
|
}
|
|
MetaObject exame;
|
|
try
|
|
{
|
|
exame = (MetaObject)examePanel.save();
|
|
}
|
|
catch( ValuesException vex )
|
|
{
|
|
msg.append( vex.getMessage() );
|
|
exame = null;
|
|
}
|
|
if( estabelecimento == null || trabalhador == null || exame == null || medico == null )
|
|
{
|
|
JOptionPane.showMessageDialog( this, msg.toString(), "Erro...", JOptionPane.ERROR_MESSAGE );
|
|
return false;
|
|
}
|
|
trabalhador.setProperty( fdpProvider.R_TRABALHADOR_ESTABELECIMENTO, estabelecimento );
|
|
trabalhador.setProperty( fdpProvider.OBSERVACOES, observacoesPanel.save() );
|
|
|
|
exame.setProperty( fdpProvider.R_EXAME_MEDICO, medico );
|
|
exame.setProperty( fdpProvider.R_EXAME_TRABALHADOR, trabalhador );
|
|
try
|
|
{
|
|
exame.save();
|
|
exame.setProperty( fdpProvider.PDF, createPDF( exame ) );
|
|
fdpProvider.savePDF( exame );
|
|
DBKey key = trabalhador.getPrimaryKeyValue();
|
|
DBField fields[] = fdpProvider.TRABALHADORES.getPrimaryKey();
|
|
trabalhadorID = new Integer( ((Number)key.getFieldValue( fields[ 0 ] )).intValue() );
|
|
createPDF( exame );
|
|
print();
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
DialogException.showExceptionMessage( ex, "Erro a guardar", true );
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public boolean newItem( int index )
|
|
{
|
|
fdpProvider.setSearch( FichaDataProvider.SEARCH_EMPRESAS );
|
|
SearchDialog search;
|
|
Integer oldID = empresaID;
|
|
// if( empresaID != null )
|
|
// {
|
|
// try
|
|
// {
|
|
// MetaObject empresa = fdpProvider.load( fdpProvider.EMPRESAS, new DBKey( empresaID ) );
|
|
// String designacao = (String) empresa.getProperty( fdpProvider.DESIGNACAO_SOCIAL );
|
|
// search = new SearchDialog( fdpProvider, null, true, new Object[]{ empresaID, designacao }, false );
|
|
// }
|
|
// catch( Exception ex )
|
|
// {
|
|
// search = new SearchDialog( fdpProvider, null, true, null, true );
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// search = new SearchDialog( fdpProvider, null, true, null, true );
|
|
// }
|
|
search = new SearchDialog( fdpProvider, null, true, null, true );
|
|
empresaID = ( Integer )search.getSelected();
|
|
|
|
if( empresaID == null )
|
|
{
|
|
if( search.getIsNew() )
|
|
{
|
|
estabelecimentoID = null;
|
|
trabalhadorID = null;
|
|
clear( 0 );
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
fdpProvider.setSearch( FichaDataProvider.SEARCH_ESTABELECIMENTOS );
|
|
fdpProvider.setSearchID( FichaDataProvider.SEARCH_EMPRESAS, empresaID.intValue() );
|
|
// if( oldID != null && oldID.equals( empresaID ) && estabelecimentoID != null )
|
|
// {
|
|
// try
|
|
// {
|
|
// MetaObject estabelecimento = fdpProvider.load( fdpProvider.ESTABELECIMENTOS, new DBKey( estabelecimentoID ) );
|
|
// String nome = (String) estabelecimento.getProperty( fdpProvider.NOME );
|
|
// search = new SearchDialog( fdpProvider, null, true, new Object[]{ estabelecimentoID, nome }, false );
|
|
// }
|
|
// catch( Exception ex )
|
|
// {
|
|
// search = new SearchDialog( fdpProvider, null, true, null, true );
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// search = new SearchDialog( fdpProvider, null, true, null, true );
|
|
// }
|
|
search = new SearchDialog( fdpProvider, null, true, null, true );
|
|
estabelecimentoID = ( Integer )search.getSelected();
|
|
|
|
if( estabelecimentoID == null )
|
|
{
|
|
if( search.getIsNew() )
|
|
{
|
|
trabalhadorID = null;
|
|
reload(0);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
fdpProvider.setSearch( FichaDataProvider.SEARCH_TRABALHADORES );
|
|
fdpProvider.setSearchID( FichaDataProvider.SEARCH_ESTABELECIMENTOS, estabelecimentoID.intValue() );
|
|
search = new SearchDialog( fdpProvider, null, true, null, true );
|
|
trabalhadorID = ( Integer )search.getSelected();
|
|
|
|
if( trabalhadorID == null )
|
|
{
|
|
if( search.getIsNew() )
|
|
{
|
|
reload(0);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
reload(0);
|
|
return true;
|
|
}
|
|
|
|
public boolean delete( int index )
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void reload( int index )
|
|
{
|
|
Integer upperData[] = new Integer[]{ empresaID, estabelecimentoID, trabalhadorID };
|
|
upperPanel.fill( upperData );
|
|
Object empresaData[] = new Object[]{ empresaID, estabelecimentoID };
|
|
empresaPanel.fill( empresaData );
|
|
trabalhadorPanel.fill( trabalhadorID );
|
|
observacoesPanel.fill( trabalhadorID );
|
|
examePanel.fill( trabalhadorID );
|
|
}
|
|
|
|
public void enableComponents( int index, boolean enable )
|
|
{
|
|
upperPanel.setEnabled( enable );
|
|
empresaPanel.setEnabled( enable );
|
|
trabalhadorPanel.setEnabled( enable );
|
|
observacoesPanel.setEnabled( enable );
|
|
examePanel.setEnabled( enable );
|
|
}
|
|
|
|
public void clear( int index )
|
|
{
|
|
upperPanel.clear();
|
|
empresaPanel.clear();
|
|
trabalhadorPanel.clear();
|
|
observacoesPanel.clear();
|
|
examePanel.clear();
|
|
}
|
|
|
|
public void print()
|
|
{
|
|
try
|
|
{
|
|
if( trabalhadorID == null )
|
|
{
|
|
System.out.println( "no trab" );
|
|
return;
|
|
}
|
|
|
|
Integer id = fdpProvider.getLastExameIDForTrabalhador( trabalhadorID );
|
|
if( id == null )
|
|
{
|
|
System.out.println( "no id" );
|
|
return;
|
|
}
|
|
MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( id ) );
|
|
byte pdf[] = (byte []) exame.getProperty( fdpProvider.PDF );
|
|
if( exame == null )
|
|
{
|
|
throw new Exception( "N\u00e3o existe exame" );
|
|
}
|
|
ExamePDF ePDF = new ExamePDF();
|
|
ePDF.print( pdf );
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
DialogException.showExceptionMessage( ex, "N\u00e3o foi poss\u00edvel imprimir", true );
|
|
}
|
|
}
|
|
|
|
public byte[] createPDF( MetaObject exame )
|
|
throws Exception
|
|
{
|
|
MetaObject medico = ( (MetaObject []) exame.getProperty( fdpProvider.R_EXAME_MEDICO ) )[0];
|
|
MetaObject trabalhador = ( (MetaObject []) exame.getProperty( fdpProvider.R_EXAME_TRABALHADOR ) )[0];
|
|
MetaObject estabelecimento = ( (MetaObject []) trabalhador.getProperty( fdpProvider.R_TRABALHADOR_ESTABELECIMENTO ) )[0];
|
|
MetaObject empresa = ( (MetaObject []) estabelecimento.getProperty( fdpProvider.R_ESTABELECIMENTO_EMPRESA ) )[0];
|
|
empresa.load( empresa.getPrimaryKeyValue() );
|
|
Hashtable ht = new Hashtable();
|
|
ht.put( "designacao_social", empresa.getProperty( fdpProvider.DESIGNACAO_SOCIAL ) );
|
|
ht.put( "estabelecimentos.nome", estabelecimento.getProperty( fdpProvider.NOME ) );
|
|
String aux = (String)estabelecimento.getProperty( fdpProvider.LOCALIDADE );
|
|
ht.put( "estabelecimentos.localidade", aux != null ? aux : "" );
|
|
Integer tipo = (Integer)empresa.getProperty( fdpProvider.SERVICO_SAUDE_TIPO );
|
|
switch( tipo.intValue() )
|
|
{
|
|
case 1:
|
|
ht.put( "servico_saude_tipo_interno", "" );
|
|
break;
|
|
case 2:
|
|
ht.put( "servico_saude_tipo_interempresas", "" );
|
|
break;
|
|
case 3:
|
|
ht.put( "servico_saude_tipo_externo", "" );
|
|
break;
|
|
case 4:
|
|
ht.put( "servico_saude_tipo_sns", "" );
|
|
break;
|
|
}
|
|
ht.put( "servico_saude_designacao", empresa.getProperty( fdpProvider.SERVICO_SAUDE_DESIGNACAO ) );
|
|
tipo = (Integer)empresa.getProperty( fdpProvider.SERVICO_HIGIENE_TIPO );
|
|
switch( tipo.intValue() )
|
|
{
|
|
case 1:
|
|
ht.put( "servico_higiene_tipo_interno", "" );
|
|
break;
|
|
case 2:
|
|
ht.put( "servico_higiene_tipo_interempresas", "" );
|
|
break;
|
|
case 3:
|
|
ht.put( "servico_higiene_tipo_externo", "" );
|
|
break;
|
|
case 4:
|
|
ht.put( "servico_higiene_outro", "" );
|
|
break;
|
|
}
|
|
ht.put( "servico_higiene_designacao", empresa.getProperty( fdpProvider.SERVICO_HIGIENE_DESIGNACAO ) );
|
|
ht.put( "trabalhadores.nome", trabalhador.getProperty( fdpProvider.NOME ) );
|
|
aux = (String)trabalhador.getProperty( fdpProvider.SEXO );
|
|
switch( aux.charAt( 0 ) )
|
|
{
|
|
case 'm':
|
|
ht.put( "sexo", "M" );
|
|
break;
|
|
case 'f':
|
|
ht.put( "sexo", "F" );
|
|
break;
|
|
}
|
|
DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );
|
|
Date data = ( Date )trabalhador.getProperty( fdpProvider.DATA_NASCIMENTO );
|
|
ht.put( "data_nascimento", data != null ? df.format( data ) : "" );
|
|
aux = (String)trabalhador.getProperty( fdpProvider.NACIONALIDADE );
|
|
ht.put( "nacionalidade", aux != null ? aux : "" );
|
|
aux = (String)trabalhador.getProperty( fdpProvider.NUMERO_MECANOGRAFICO );
|
|
ht.put( "numero_mecanografico", aux != null ? aux : "" );
|
|
data = ( Date )trabalhador.getProperty( fdpProvider.DATA_ADMISSAO );
|
|
ht.put( "data_admissao", data != null ? df.format( data ) : "" );
|
|
aux = (String)trabalhador.getProperty( fdpProvider.CATEGORIA );
|
|
ht.put( "categoria", aux != null ? aux : "" );
|
|
aux = (String)trabalhador.getProperty( fdpProvider.LOCAL_TRABALHO );
|
|
ht.put( "local_trabalho", aux != null ? aux : "" );
|
|
aux = (String)trabalhador.getProperty( fdpProvider.FUNCAO_PROPOSTA );
|
|
ht.put( "funcao_proposta", aux != null ? aux : "" );
|
|
data = ( Date )trabalhador.getProperty( fdpProvider.DATA_ADMISSAO_FUNCAO );
|
|
ht.put( "data_admissao_funcao", data != null ? df.format( data ) : "" );
|
|
aux = (String)trabalhador.getProperty( fdpProvider.OBSERVACOES );
|
|
ht.put( "observacoes", aux != null ? aux : "" );
|
|
data = ( Date )exame.getProperty( fdpProvider.DATA );
|
|
ht.put( "exames.data", data != null ? df.format( data ) : "" );
|
|
tipo = (Integer)exame.getProperty( fdpProvider.TIPO );
|
|
switch( tipo.intValue() )
|
|
{
|
|
case 1:
|
|
ht.put( "tipo_admissao", "" );
|
|
break;
|
|
case 2:
|
|
ht.put( "tipo_periodico", "" );
|
|
break;
|
|
case 3:
|
|
ht.put( "tipo_ocasional", "" );
|
|
tipo = (Integer)exame.getProperty( fdpProvider.OCASIONAL );
|
|
switch( tipo.intValue() )
|
|
{
|
|
case 1:
|
|
ht.put( "tipo_apos_doenca", "" );
|
|
break;
|
|
case 2:
|
|
ht.put( "tipo_apos_acidente", "" );
|
|
break;
|
|
case 3:
|
|
ht.put( "tipo_pedido_trabalhador", "" );
|
|
break;
|
|
case 4:
|
|
ht.put( "tipo_pedido_empresa", "" );
|
|
break;
|
|
case 5:
|
|
ht.put( "tipo_mudanca_funcao", "" );
|
|
break;
|
|
case 6:
|
|
ht.put( "tipo_trabalho", "" );
|
|
break;
|
|
}
|
|
break;
|
|
case 4:
|
|
aux = (String)exame.getProperty( fdpProvider.OUTRO_TIPO );
|
|
ht.put( "tipo_outro", aux != null ? aux : "" );
|
|
break;
|
|
}
|
|
tipo = (Integer)exame.getProperty( fdpProvider.RESULTADO );
|
|
switch( tipo.intValue() )
|
|
{
|
|
case 1:
|
|
ht.put( "resultado_apto", "" );
|
|
break;
|
|
case 2:
|
|
ht.put( "resultado_apto_condicionalmente", "" );
|
|
break;
|
|
case 3:
|
|
ht.put( "resultado_inapto_temp", "" );
|
|
break;
|
|
case 4:
|
|
ht.put( "resultado_inapto_def", "" );
|
|
break;
|
|
}
|
|
aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_1 );
|
|
ht.put( "outra_funcao_1", aux != null ? aux : "" );
|
|
aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_2 );
|
|
ht.put( "outra_funcao_2", aux != null ? aux : "" );
|
|
aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_3 );
|
|
ht.put( "outra_funcao_3", aux != null ? aux : "" );
|
|
aux = (String)exame.getProperty( fdpProvider.OUTRA_FUNCAO_4 );
|
|
ht.put( "outra_funcao_4", aux != null ? aux : "" );
|
|
aux = (String)exame.getProperty( fdpProvider.OUTRAS_RECOMENDACOES );
|
|
ht.put( "outras_recomendacoes", aux != null ? aux : "" );
|
|
data = ( Date )exame.getProperty( fdpProvider.PROXIMO_EXAME );
|
|
ht.put( "proximo_exame", data != null ? df.format( data ) : "" );
|
|
aux = (String)medico.getProperty( fdpProvider.NOME );
|
|
ht.put( "medicos.nome", aux != null ? aux : "" );
|
|
aux = (String)medico.getProperty( fdpProvider.NUMERO_CEDULA );
|
|
ht.put( "numero_cedula", aux != null ? aux : "" );
|
|
ExamePDF ePDF = new ExamePDF();
|
|
return ePDF.createPDF( ht );
|
|
}
|
|
|
|
}
|