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.
		
		
		
		
		
			
		
			
				
					
					
						
							861 lines
						
					
					
						
							24 KiB
						
					
					
				
			
		
		
	
	
							861 lines
						
					
					
						
							24 KiB
						
					
					
				/*
 | 
						|
 * FichaWindow.java
 | 
						|
 *
 | 
						|
 * Created on 29 de Marco de 2004, 11:50
 | 
						|
 */
 | 
						|
 | 
						|
package siprp.ficha;
 | 
						|
 | 
						|
import siprp.*;
 | 
						|
import siprp.data.*;
 | 
						|
import siprp.importer.*;
 | 
						|
import siprp.medicina.*;
 | 
						|
 | 
						|
import java.awt.*;
 | 
						|
import java.io.*;
 | 
						|
import java.util.*;
 | 
						|
import javax.swing.*;
 | 
						|
import java.text.*;
 | 
						|
 | 
						|
import com.evolute.utils.*;
 | 
						|
import com.evolute.utils.data.*;
 | 
						|
import com.evolute.utils.jdo.*;
 | 
						|
import com.evolute.utils.metadb.*;
 | 
						|
import com.evolute.utils.strings.*;
 | 
						|
import com.evolute.utils.tracker.*;
 | 
						|
import com.evolute.utils.ui.*;
 | 
						|
import com.evolute.utils.ui.panel.*;
 | 
						|
import com.evolute.utils.ui.search.*;
 | 
						|
import com.evolute.utils.ui.window.*;
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @author  fpalma
 | 
						|
 */
 | 
						|
public class FichaWindow extends TabbedWindow
 | 
						|
	implements ListAction, FichaAptidaoConstants
 | 
						|
{	
 | 
						|
	private JDOProvider JDO;
 | 
						|
	
 | 
						|
	private UpperPanel upperPanel;
 | 
						|
	private EmpresaPanel empresaPanel;
 | 
						|
	private TrabalhadorPanel trabalhadorPanel;
 | 
						|
	private ObservacoesPanel observacoesPanel;
 | 
						|
	private ExamePanel examePanel;
 | 
						|
 | 
						|
	private FichaDataProvider fdpProvider;
 | 
						|
	private MarcacoesMedicinaHandler marcacoesHandler;
 | 
						|
	private Integer empresaID;
 | 
						|
	private Integer estabelecimentoID;
 | 
						|
	private Integer trabalhadorID;
 | 
						|
	
 | 
						|
	private final ExamePDF ePDF = new ExamePDF();
 | 
						|
	
 | 
						|
	private static int permissions[][] = 
 | 
						|
		new int[][]{ { NEW_INDEX, CANCEL_INDEX, SAVE_INDEX } };
 | 
						|
	
 | 
						|
	private static FichaWindow window = null;
 | 
						|
	
 | 
						|
	private Integer imposedTrabalhadorID = null;
 | 
						|
	private SaveExameListener exameListener = null;
 | 
						|
	
 | 
						|
	/** Creates a new instance of FichaWindow */
 | 
						|
	private 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();
 | 
						|
		JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER );
 | 
						|
		marcacoesHandler = new MarcacoesMedicinaHandler();
 | 
						|
		setupComponents();
 | 
						|
	}
 | 
						|
	
 | 
						|
	public static FichaWindow getWindow()
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		if( window == null )
 | 
						|
		{
 | 
						|
			window = new FichaWindow();
 | 
						|
		}
 | 
						|
		return window;
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void setupComponents()
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		setSize( 700, 640 );
 | 
						|
		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 );
 | 
						|
		
 | 
						|
		registerAction( new ActionHandler(){
 | 
						|
							public void execute()
 | 
						|
							{
 | 
						|
								printOld();
 | 
						|
							}
 | 
						|
							
 | 
						|
							public boolean activate( boolean newAction, boolean editAction, 
 | 
						|
														boolean cancelAction, boolean saveAction,
 | 
						|
														boolean deleteAction, boolean selectAction )
 | 
						|
							{
 | 
						|
								return saveAction || editAction;
 | 
						|
							}
 | 
						|
						}, "Imprimir Fichas Anteriores", 
 | 
						|
						"Imprimir Fichas Anteriores", null,
 | 
						|
						0, false );
 | 
						|
						
 | 
						|
		registerAction( new ActionHandler(){
 | 
						|
							public void execute()
 | 
						|
							{
 | 
						|
								deleteOld();
 | 
						|
							}
 | 
						|
							
 | 
						|
							public boolean activate( boolean newAction, boolean editAction, 
 | 
						|
														boolean cancelAction, boolean saveAction,
 | 
						|
														boolean deleteAction, boolean selectAction )
 | 
						|
							{
 | 
						|
								return saveAction || editAction;
 | 
						|
							}
 | 
						|
						}, "Apagar Fichas Anteriores", 
 | 
						|
						"Apagar Fichas Anteriores", null,
 | 
						|
						0, false );
 | 
						|
						
 | 
						|
//		registerAction( new ActionHandler(){
 | 
						|
//							public void execute()
 | 
						|
//							{
 | 
						|
//								excel();
 | 
						|
//							}
 | 
						|
//							
 | 
						|
//							public boolean activate( boolean newAction, boolean editAction, 
 | 
						|
//														boolean cancelAction, boolean saveAction,
 | 
						|
//														boolean deleteAction, boolean selectAction )
 | 
						|
//							{
 | 
						|
//								return saveAction;
 | 
						|
//							}
 | 
						|
//						}, "Importar", 
 | 
						|
//						"Importar de Excel", "excel",
 | 
						|
//						0, true );
 | 
						|
	}
 | 
						|
	
 | 
						|
	public boolean save( int index )
 | 
						|
	{
 | 
						|
		new ProgressDialog( this, "A gravar...", 
 | 
						|
							new Runnable(){
 | 
						|
								public void run()
 | 
						|
								{
 | 
						|
									
 | 
						|
								}
 | 
						|
							});
 | 
						|
		StringBuilder msg = new StringBuilder();
 | 
						|
		MedicoData medico;
 | 
						|
		try
 | 
						|
		{
 | 
						|
			medico = (MedicoData)upperPanel.save();
 | 
						|
		}
 | 
						|
		catch( ValuesException vex )
 | 
						|
		{
 | 
						|
			msg.append( vex.getMessage() );
 | 
						|
			medico = null;
 | 
						|
		}
 | 
						|
		EstabelecimentoData estabelecimento;
 | 
						|
		try
 | 
						|
		{
 | 
						|
			estabelecimento = (EstabelecimentoData)empresaPanel.save();
 | 
						|
		}
 | 
						|
		catch( ValuesException vex )
 | 
						|
		{
 | 
						|
			msg.append( vex.getMessage() );
 | 
						|
			estabelecimento = null;
 | 
						|
		}
 | 
						|
		TrabalhadorData trabalhador;
 | 
						|
		try
 | 
						|
		{
 | 
						|
			trabalhador = (TrabalhadorData)trabalhadorPanel.save();
 | 
						|
		}
 | 
						|
		catch( ValuesException vex )
 | 
						|
		{
 | 
						|
			msg.append( vex.getMessage() );
 | 
						|
			trabalhador = null;
 | 
						|
		}
 | 
						|
		ExameData exame;
 | 
						|
		try
 | 
						|
		{
 | 
						|
			exame = (ExameData)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;
 | 
						|
		}
 | 
						|
		estabelecimento.set( EstabelecimentoData.NOME_PLAIN, 
 | 
						|
									com.evolute.utils.strings.StringPlainer.convertString( ( String ) 
 | 
						|
										estabelecimento.get( EstabelecimentoData.NOME ) ) );
 | 
						|
		
 | 
						|
//		trabalhador.setProperty( FichaDataProvider.R_TRABALHADOR_ESTABELECIMENTO, estabelecimento );
 | 
						|
//		trabalhador.setProperty( FichaDataProvider.OBSERVACOES, observacoesPanel.save() );
 | 
						|
		trabalhador.set( TrabalhadorData.ESTABELECIMENTO, estabelecimento );
 | 
						|
		trabalhador.set( TrabalhadorData.OBSERVACOES, observacoesPanel.save() );
 | 
						|
		trabalhador.set( TrabalhadorData.NOME_PLAIN, 
 | 
						|
									com.evolute.utils.strings.StringPlainer.convertString( ( String ) 
 | 
						|
										trabalhador.get( TrabalhadorData.NOME ) ) );
 | 
						|
		
 | 
						|
 | 
						|
//		exame.setProperty( FichaDataProvider.R_EXAME_MEDICO, medico );
 | 
						|
//		exame.setProperty( FichaDataProvider.R_EXAME_TRABALHADOR, trabalhador );
 | 
						|
		exame.set( ExameData.MEDICO, medico );
 | 
						|
		exame.set( ExameData.TRABALHADOR, trabalhador );
 | 
						|
		try
 | 
						|
		{
 | 
						|
			// lflores - disable FO for now
 | 
						|
			byte fo[] = null; //createFO( exame );
 | 
						|
			
 | 
						|
	System.out.println( "FO sz: " + fo.length );
 | 
						|
			exame.set( ExameData.FO, fo );
 | 
						|
			exame.set( ExameData.PDF, createPDF( exame ) );
 | 
						|
			
 | 
						|
//			empresa.save();
 | 
						|
//			estabelecimento.save();
 | 
						|
		
 | 
						|
			exame.save();
 | 
						|
			trabalhador.save();
 | 
						|
			try
 | 
						|
			{
 | 
						|
				if( medico != null )
 | 
						|
				{
 | 
						|
					fdpProvider.setMedicoForEstabelecimento( ( Integer ) estabelecimento.get( EstabelecimentoData.ID ),
 | 
						|
																( Integer ) medico.get( MedicoData.ID ) );
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch( Exception mex )
 | 
						|
			{
 | 
						|
			}
 | 
						|
//			fdpProvider.savePDF( exame );
 | 
						|
			
 | 
						|
//			DBKey key = trabalhador.getPrimaryKeyValue();
 | 
						|
//			DBField fields[] = FichaDataProvider.TRABALHADORES.getPrimaryKey();
 | 
						|
//			trabalhadorID = new Integer( ((Number)key.getFieldValue( fields[ 0 ] )).intValue() );
 | 
						|
			trabalhadorID = ( Integer ) trabalhador.get( TrabalhadorData.ID );
 | 
						|
			try
 | 
						|
			{
 | 
						|
				//Marcacao.saveMarcacaoConsultaForTrabalhadorID( trabalhadorID, (Date)exame.get( ExameData.PROXIMO_EXAME ) );
 | 
						|
				marcacoesHandler.ajustarMarcacoes( 
 | 
						|
						trabalhadorID, (Integer)exame.get( ExameData.TIPO ), 
 | 
						|
						(Date)exame.get( ExameData.DATA ), 
 | 
						|
						examePanel.getMotivoProximoExame(), (Date)exame.get( ExameData.PROXIMO_EXAME ) );
 | 
						|
			}
 | 
						|
			catch( Exception iex )
 | 
						|
			{
 | 
						|
				iex.printStackTrace();
 | 
						|
			}
 | 
						|
//			createPDF( exame );
 | 
						|
//			print();
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
			DialogException.showExceptionMessage( ex, "Erro a guardar", true );
 | 
						|
			return false;
 | 
						|
		}
 | 
						|
		if( exameListener != null )
 | 
						|
		{
 | 
						|
			exameListener.exameSaved( trabalhadorID, ( Integer )exame.get( ExameData.ID ) );
 | 
						|
			exameListener = null;
 | 
						|
		}
 | 
						|
		return true;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public boolean newItem( int index )
 | 
						|
	{
 | 
						|
		exameListener = null;
 | 
						|
		if( imposedTrabalhadorID == null )
 | 
						|
		{
 | 
						|
			fdpProvider.setSearch( FichaDataProvider.SEARCH_EMPRESAS );
 | 
						|
			SearchDialog search;
 | 
						|
			Integer oldID = empresaID;
 | 
						|
 | 
						|
			search = new SearchDialog( fdpProvider, null, false, 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() );
 | 
						|
 | 
						|
			search = new SearchDialog( fdpProvider, null, false, 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, false, null, true );
 | 
						|
			trabalhadorID = ( Integer )search.getSelected();
 | 
						|
			if( trabalhadorID == null && search.getIsNew() )
 | 
						|
			{
 | 
						|
				reload(0);
 | 
						|
				return true;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			trabalhadorID = imposedTrabalhadorID;
 | 
						|
			imposedTrabalhadorID = null;
 | 
						|
			try
 | 
						|
			{
 | 
						|
				estabelecimentoID = fdpProvider.getEstabelecimentoIDForTrabalhador( trabalhadorID );
 | 
						|
				empresaID = fdpProvider.getEmpresaIDForEstabelecimento( estabelecimentoID );
 | 
						|
			}
 | 
						|
			catch( Exception ex )
 | 
						|
			{
 | 
						|
				DialogException.showExceptionMessage( ex, "Erro a carregar dados.", true );
 | 
						|
				return false;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		if( trabalhadorID == null )
 | 
						|
		{
 | 
						|
			return false;
 | 
						|
		}
 | 
						|
		reload(0);
 | 
						|
		return true;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public boolean delete( int index )
 | 
						|
	{
 | 
						|
		return true;
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void deleteOld()
 | 
						|
	{
 | 
						|
		if( trabalhadorID == null )
 | 
						|
		{
 | 
						|
			return;
 | 
						|
		}
 | 
						|
		Vector linhas;
 | 
						|
		try
 | 
						|
		{
 | 
						|
			IDObject fichas[] = fdpProvider.getAllFichasForTrabalhador( trabalhadorID );
 | 
						|
			linhas = new Vector( Arrays.asList( fichas ) );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
			DialogException.showExceptionMessage( ex, "Erro a criar lista de Fichas anteriores", true );
 | 
						|
			return;
 | 
						|
		}
 | 
						|
		ListActionDialog dialog = 
 | 
						|
			new ListActionDialog( this, "Apagar Fichas Anteriores", new String[]{ "Data" }, linhas, 
 | 
						|
							new ListAction(){
 | 
						|
								public String getListActionName()
 | 
						|
								{
 | 
						|
									return "Apagar";
 | 
						|
								}
 | 
						|
								
 | 
						|
								public boolean executeListAction( int line, Object value )
 | 
						|
								{
 | 
						|
									if( value == null )
 | 
						|
									{
 | 
						|
										return true;
 | 
						|
									}
 | 
						|
									try
 | 
						|
									{
 | 
						|
										delete( ( ( IDObject )value ).getID() );
 | 
						|
									}
 | 
						|
									catch( Exception ex )
 | 
						|
									{
 | 
						|
										DialogException.showExceptionMessage( ex, "Erro a Apagar Ficha", true );
 | 
						|
										return false;
 | 
						|
									}
 | 
						|
									return true;
 | 
						|
								}	
 | 
						|
							} );
 | 
						|
		dialog.setSize( 250, 200 );
 | 
						|
		dialog.setVisible( 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;
 | 
						|
			}
 | 
						|
			print( id );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
			DialogException.showExceptionMessage( ex, "N\u00e3o foi poss\u00edvel imprimir", true );
 | 
						|
		}
 | 
						|
	}
 | 
						|
		
 | 
						|
	private void print( Integer exameID )
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
//		MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) );		
 | 
						|
		ExameData exame = (ExameData) JDO.load( ExameData.class, exameID );
 | 
						|
		if( exame == null )
 | 
						|
		{
 | 
						|
			throw new Exception( "N\u00e3o existe exame" );
 | 
						|
		}
 | 
						|
		
 | 
						|
		// lflores - ignore FO (for now)
 | 
						|
		byte fo[] = null; //(byte []) exame.get( ExameData.FO );
 | 
						|
		byte pdf[] = (byte []) exame.get( ExameData.PDF );
 | 
						|
		
 | 
						|
		if( fo != null )
 | 
						|
		{
 | 
						|
			FichaAptidaoCreator.getCreator().print( fo );
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			TrabalhadorData trabalhadorExame = ( TrabalhadorData ) exame.get( ExameData.TRABALHADOR );
 | 
						|
			String nomeFicheiro = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadorData.NOME ) );
 | 
						|
			nomeFicheiro = nomeFicheiro.replaceAll( " ", "_" );
 | 
						|
			ePDF.print( pdf, nomeFicheiro );
 | 
						|
		}		
 | 
						|
	}
 | 
						|
		
 | 
						|
	public byte[] createFO( ExameData exame )
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		HashMap<String, String> ht = createMapFromExame(exame);
 | 
						|
//		ExamePDF ePDF = new ExamePDF();
 | 
						|
//		return ePDF.createPDF( ht );
 | 
						|
		
 | 
						|
		return FichaAptidaoCreator.getCreator().createFO( ht );
 | 
						|
	}
 | 
						|
 | 
						|
	public byte[] createPDF( ExameData exame )
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
		// byte fo[] = exame.get( ExameData.FO, fo );
 | 
						|
		HashMap<String, String> ht = createMapFromExame( exame );
 | 
						|
		return ePDF.createPDF( ht );
 | 
						|
//		return FichaAptidaoCreator.getCreator().createPDF( fo );
 | 
						|
	}
 | 
						|
	
 | 
						|
	private HashMap<String, String> createMapFromExame(final ExameData exame)
 | 
						|
	{
 | 
						|
		MedicoData medico = (MedicoData)exame.get( ExameData.MEDICO );
 | 
						|
		TrabalhadorData trabalhador = (TrabalhadorData) exame.get( ExameData.TRABALHADOR );
 | 
						|
		EstabelecimentoData estabelecimento = (EstabelecimentoData) trabalhador.get( TrabalhadorData.ESTABELECIMENTO );
 | 
						|
		EmpresaData empresa = (EmpresaData) estabelecimento.get( EstabelecimentoData.EMPRESA );
 | 
						|
//		empresa.load( empresa.getPrimaryKeyValue() );
 | 
						|
		HashMap<String,String> ht = new HashMap<String,String>();
 | 
						|
		ht.put( DESIGNACAO_SOCIAL, ( String )empresa.get( EmpresaData.DESIGNACAO_SOCIAL ) );
 | 
						|
		ht.put( ESTABELECIMENTOS_NOME, ( String )estabelecimento.get( EstabelecimentoData.NOME ) );
 | 
						|
		String aux = (String)estabelecimento.get( EstabelecimentoData.LOCALIDADE );
 | 
						|
		ht.put( ESTABELECIMENTOS_LOCALIDADE, aux != null ? aux : "" );
 | 
						|
		Integer tipo = (Integer)empresa.get( EmpresaData.SERVICO_SAUDE_TIPO );
 | 
						|
		ht.put( SERVICO_SAUDE_TIPO_INTERNO, SQUARE );
 | 
						|
		ht.put( SERVICO_SAUDE_TIPO_INTEREMPRESAS, SQUARE );
 | 
						|
		ht.put( SERVICO_SAUDE_TIPO_EXTERNO, SQUARE );
 | 
						|
		ht.put( SERVICO_SAUDE_TIPO_SNS, SQUARE );
 | 
						|
		switch( tipo.intValue() )
 | 
						|
		{
 | 
						|
			case 1:
 | 
						|
				ht.put( SERVICO_SAUDE_TIPO_INTERNO, CHECKED );
 | 
						|
				break;
 | 
						|
			case 2:
 | 
						|
				ht.put( SERVICO_SAUDE_TIPO_INTEREMPRESAS, CHECKED );
 | 
						|
				break;
 | 
						|
			case 3:
 | 
						|
				ht.put( SERVICO_SAUDE_TIPO_EXTERNO, CHECKED );
 | 
						|
				break;
 | 
						|
			case 4:
 | 
						|
				ht.put( SERVICO_SAUDE_TIPO_SNS, CHECKED );
 | 
						|
				break;
 | 
						|
		}
 | 
						|
		ht.put( SERVICO_SAUDE_DESIGNACAO, ( String )empresa.get( EmpresaData.SERVICO_SAUDE_DESIGNACAO ) );
 | 
						|
		tipo = (Integer)empresa.get( EmpresaData.SERVICO_HIGIENE_TIPO );
 | 
						|
		ht.put( SERVICO_HIGIENE_TIPO_INTERNO, SQUARE );
 | 
						|
		ht.put( SERVICO_HIGIENE_TIPO_INTEREMPRESAS, SQUARE );
 | 
						|
		ht.put( SERVICO_HIGIENE_TIPO_EXTERNO, SQUARE );
 | 
						|
		ht.put( SERVICO_HIGIENE_TIPO_OUTRO, SQUARE );
 | 
						|
		switch( tipo.intValue() )
 | 
						|
		{
 | 
						|
			case 1:
 | 
						|
				ht.put( SERVICO_HIGIENE_TIPO_INTERNO, CHECKED );
 | 
						|
				break;
 | 
						|
			case 2:
 | 
						|
				ht.put( SERVICO_HIGIENE_TIPO_INTEREMPRESAS, CHECKED );
 | 
						|
				break;
 | 
						|
			case 3:
 | 
						|
				ht.put( SERVICO_HIGIENE_TIPO_EXTERNO, CHECKED );
 | 
						|
				break;
 | 
						|
			case 4:
 | 
						|
				ht.put( SERVICO_HIGIENE_TIPO_OUTRO, CHECKED );
 | 
						|
				break;
 | 
						|
		}
 | 
						|
		ht.put( SERVICO_HIGIENE_DESIGNACAO, ( String )empresa.get( EmpresaData.SERVICO_HIGIENE_DESIGNACAO ) );
 | 
						|
		ht.put( TRABALHADORES_NOME, ( String )trabalhador.get( TrabalhadorData.NOME ) );
 | 
						|
		aux = (String)trabalhador.get( TrabalhadorData.SEXO );
 | 
						|
		switch( aux.charAt( 0 ) )
 | 
						|
		{
 | 
						|
			case 'm':
 | 
						|
				ht.put( SEXO, "Masculino" );
 | 
						|
				break;
 | 
						|
			case 'f':
 | 
						|
				ht.put( SEXO, "Feminino" );
 | 
						|
				break;
 | 
						|
		}
 | 
						|
		DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );
 | 
						|
		Date data = ( Date )trabalhador.get( TrabalhadorData.DATA_NASCIMENTO );
 | 
						|
		ht.put( DATA_NASCIMENTO, data != null ? df.format( data ) : "" );
 | 
						|
		aux = (String)trabalhador.get( TrabalhadorData.NACIONALIDADE );
 | 
						|
		ht.put( NACIONALIDADE, aux != null ? aux : "" );
 | 
						|
		aux = (String)trabalhador.get( TrabalhadorData.NUMERO_MECANOGRAFICO );
 | 
						|
		ht.put( NUMERO_MECANOGRAFICO, aux != null ? aux : "" );
 | 
						|
		data = ( Date )trabalhador.get( TrabalhadorData.DATA_ADMISSAO );
 | 
						|
		ht.put( DATA_ADMISSAO, data != null ? df.format( data ) : "" );
 | 
						|
		aux = (String)trabalhador.get( TrabalhadorData.CATEGORIA );
 | 
						|
		ht.put( CATEGORIA, aux != null ? aux : "" );
 | 
						|
		aux = (String)trabalhador.get( TrabalhadorData.LOCAL_TRABALHO );
 | 
						|
		ht.put( LOCAL_TRABALHO, aux != null ? aux : "" );
 | 
						|
		aux = (String)trabalhador.get( TrabalhadorData.FUNCAO_PROPOSTA );
 | 
						|
		ht.put( FUNCAO_PROPOSTA, aux != null ? aux : "" );
 | 
						|
		data = ( Date )trabalhador.get( TrabalhadorData.DATA_ADMISSAO_FUNCAO );
 | 
						|
		ht.put( DATA_ADMISSAO_FUNCAO, data != null ? df.format( data ) : "" );
 | 
						|
		aux = (String)trabalhador.get( TrabalhadorData.OBSERVACOES );
 | 
						|
		ht.put( OBSERVACOES, aux != null ? aux : "" );
 | 
						|
		data = ( Date )exame.get( ExameData.DATA );
 | 
						|
		ht.put( EXAMES_DATA, data != null ? df.format( data ) : "" );
 | 
						|
		tipo = (Integer)exame.get( ExameData.TIPO );
 | 
						|
		ht.put( TIPO_ADMISSAO, SQUARE );
 | 
						|
		ht.put( TIPO_PERIODICO, SQUARE );
 | 
						|
		ht.put( TIPO_OCASIONAL, SQUARE );
 | 
						|
		
 | 
						|
		ht.put( TIPO_APOS_DOENCA, SQUARE );
 | 
						|
		ht.put( TIPO_APOS_ACIDENTE, SQUARE );
 | 
						|
		ht.put( TIPO_PEDIDO_TRABALHADOR, SQUARE );
 | 
						|
		ht.put( TIPO_PEDIDO_EMPRESA, SQUARE );
 | 
						|
		ht.put( TIPO_MUDANCA_FUNCAO, SQUARE );
 | 
						|
		ht.put( TIPO_TRABALHO, SQUARE );
 | 
						|
		ht.put( TIPO_OUTRO, SQUARE );
 | 
						|
		
 | 
						|
		switch( tipo.intValue() )
 | 
						|
		{
 | 
						|
			case 1:
 | 
						|
				ht.put( TIPO_ADMISSAO, CHECKED );
 | 
						|
				break;
 | 
						|
			case 2:
 | 
						|
				ht.put( TIPO_PERIODICO, CHECKED );
 | 
						|
				break;
 | 
						|
			case 3:
 | 
						|
				ht.put( TIPO_OCASIONAL, CHECKED );
 | 
						|
				tipo = (Integer)exame.get( ExameData.OCASIONAL );
 | 
						|
				
 | 
						|
				switch( tipo.intValue() )
 | 
						|
				{
 | 
						|
					case 1:
 | 
						|
						ht.put( TIPO_APOS_DOENCA, CHECKED );
 | 
						|
						break;
 | 
						|
					case 2:
 | 
						|
						ht.put( TIPO_APOS_ACIDENTE, CHECKED );
 | 
						|
						break;
 | 
						|
					case 3:
 | 
						|
						ht.put( TIPO_PEDIDO_TRABALHADOR, CHECKED );
 | 
						|
						break;
 | 
						|
					case 4:
 | 
						|
						ht.put( TIPO_PEDIDO_EMPRESA, CHECKED );
 | 
						|
						break;
 | 
						|
					case 5:
 | 
						|
						ht.put( TIPO_MUDANCA_FUNCAO, CHECKED );
 | 
						|
						break;
 | 
						|
					case 6:
 | 
						|
						ht.put( TIPO_TRABALHO, CHECKED );
 | 
						|
						break;
 | 
						|
					case 10:
 | 
						|
						ht.put( TIPO_OUTRO, CHECKED );
 | 
						|
						break;
 | 
						|
				}
 | 
						|
				break;
 | 
						|
//			case 4:
 | 
						|
//				aux = (String)exame.get( ExameData.OUTRO_TIPO );
 | 
						|
//				ht.put( "tipo_outro", aux != null ? aux : "" );
 | 
						|
//				break;
 | 
						|
		}
 | 
						|
		aux = (String)exame.get( ExameData.OUTRO_TIPO );
 | 
						|
		ht.put( TIPO_OUTRO_TEXTO, aux != null ? aux : "" );
 | 
						|
		tipo = (Integer)exame.get( ExameData.RESULTADO );
 | 
						|
		ht.put( RESULTADO_APTO, SQUARE );
 | 
						|
		ht.put( RESULTADO_APTO_CONDICIONALMENTE, SQUARE );
 | 
						|
		ht.put( RESULTADO_INAPTO_TEMP, SQUARE );
 | 
						|
		ht.put( RESULTADO_INAPTO_DEF, SQUARE );
 | 
						|
		switch( tipo.intValue() )
 | 
						|
		{
 | 
						|
			case 1:
 | 
						|
				ht.put( RESULTADO_APTO, CHECKED );
 | 
						|
				break;
 | 
						|
			case 2:
 | 
						|
				ht.put( RESULTADO_APTO_CONDICIONALMENTE, CHECKED );
 | 
						|
				break;
 | 
						|
			case 3:
 | 
						|
				ht.put( RESULTADO_INAPTO_TEMP, CHECKED );
 | 
						|
				break;
 | 
						|
			case 4:
 | 
						|
				ht.put( RESULTADO_INAPTO_DEF, CHECKED );
 | 
						|
				break;
 | 
						|
		}
 | 
						|
		aux = (String)exame.get( ExameData.OUTRA_FUNCAO_1 );
 | 
						|
		ht.put( OUTRA_FUNCAO_1, aux != null ? aux : "" );
 | 
						|
		aux = (String)exame.get( ExameData.OUTRA_FUNCAO_2 );
 | 
						|
		ht.put( OUTRA_FUNCAO_2, aux != null ? aux : "" );
 | 
						|
		aux = (String)exame.get( ExameData.OUTRA_FUNCAO_3 );
 | 
						|
		ht.put( OUTRA_FUNCAO_3, aux != null ? aux : "" );
 | 
						|
		aux = (String)exame.get( ExameData.OUTRA_FUNCAO_4 );
 | 
						|
		ht.put( OUTRA_FUNCAO_4, aux != null ? aux : "" );
 | 
						|
		aux = (String)exame.get( ExameData.OUTRAS_RECOMENDACOES );
 | 
						|
		ht.put( OUTRAS_RECOMENDACOES, aux != null ? aux : "" );
 | 
						|
		data = ( Date )exame.get( ExameData.PROXIMO_EXAME );
 | 
						|
		ht.put( PROXIMO_EXAME, data != null ? df.format( data ) : "n/d" );
 | 
						|
		aux = (String)medico.get( MedicoData.NOME );
 | 
						|
		ht.put( MEDICOS_NOME, aux != null ? aux : "" );
 | 
						|
		aux = (String)medico.get( MedicoData.NUMERO_CEDULA );
 | 
						|
		ht.put( NUMERO_CEDULA, aux != null ? aux : "" );
 | 
						|
		return ht;
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void excel()
 | 
						|
	{
 | 
						|
		FileDialog fd = new FileDialog( this, "Escolha um ficheiro Excel:", FileDialog.LOAD );
 | 
						|
		fd.setDirectory( System.getProperty( "user.home" ) );
 | 
						|
		fd.setFilenameFilter( new FilenameFilter() {
 | 
						|
				public boolean accept( File dir, String name )
 | 
						|
				{
 | 
						|
					return (name!=null) && (name.indexOf( ".xls" ) != -1);
 | 
						|
				}
 | 
						|
			} );
 | 
						|
		fd.setVisible( true );
 | 
						|
		//String filename = "c:\\test.xls";
 | 
						|
		String filename = fd.getFile();
 | 
						|
		if( filename != null )
 | 
						|
		{
 | 
						|
			filename = fd.getDirectory() + File.separator + filename;
 | 
						|
			try
 | 
						|
			{
 | 
						|
				Importer importer = new Importer( this, filename, false, Importer.TYPE_ADMISSAO );
 | 
						|
				Hashtable hash = importer.getData();
 | 
						|
				if( hash != null )
 | 
						|
				{
 | 
						|
					trabalhadorPanel.setData( hash );
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch( Exception ex )
 | 
						|
			{
 | 
						|
				ex.printStackTrace();
 | 
						|
				JOptionPane.showMessageDialog( this, "Erro a importar", "Erro...", JOptionPane.ERROR_MESSAGE );
 | 
						|
			}
 | 
						|
		}
 | 
						|
		
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void printOld()
 | 
						|
	{
 | 
						|
		if( trabalhadorID != null )
 | 
						|
		{
 | 
						|
			Vector linhas;
 | 
						|
			try
 | 
						|
			{
 | 
						|
				IDObject fichas[] = fdpProvider.getAllFichasForTrabalhador( trabalhadorID );
 | 
						|
				linhas = new Vector( Arrays.asList( fichas ) );
 | 
						|
			}
 | 
						|
			catch( Exception ex )
 | 
						|
			{
 | 
						|
				DialogException.showExceptionMessage( ex, "Erro a criar lista de Fichas anteriores", true );
 | 
						|
				return;
 | 
						|
			}
 | 
						|
			ListActionDialog dialog = new ListActionDialog( this, "Imprimir Fichas Anteriores", new String[]{ "Data" },
 | 
						|
													linhas, this );
 | 
						|
			dialog.setSize( 250, 200 );
 | 
						|
			dialog.setVisible( true );
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public boolean executeListAction( int line, Object value )
 | 
						|
	{
 | 
						|
		if( value != null )
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				print( ( ( IDObject )value ).getID() );
 | 
						|
			}
 | 
						|
			catch( Exception ex )
 | 
						|
			{
 | 
						|
				DialogException.showExceptionMessage( ex, "Erro a imprimir Ficha", true );
 | 
						|
				return false;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		return true;
 | 
						|
	}	
 | 
						|
	
 | 
						|
	public String getListActionName()
 | 
						|
	{
 | 
						|
		return "Imprimir";
 | 
						|
	}
 | 
						|
	
 | 
						|
	private void delete( Integer exameID )
 | 
						|
		throws Exception
 | 
						|
	{
 | 
						|
//		MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) );
 | 
						|
		ExameData exame = (ExameData) JDO.load( ExameData.class, exameID );
 | 
						|
		if( exame == null )
 | 
						|
		{
 | 
						|
			throw new Exception( "N\u00e3o existe exame" );
 | 
						|
		}
 | 
						|
		if( JOptionPane.showConfirmDialog( this, 
 | 
						|
			"Tem a certeza que quer apagar o exame de " + exame.get( ExameData.DATA ) + "?",
 | 
						|
			"...", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null ) == 0 )
 | 
						|
		{
 | 
						|
//			exame.set( ExameData.INACTIVO, "y" );
 | 
						|
//			exame.save();
 | 
						|
			exame.delete();
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void editTrabalhador( Integer trabalhadorID, SaveExameListener listener )
 | 
						|
	{
 | 
						|
System.out.println( "edit trabalhador: " + trabalhadorID );
 | 
						|
		
 | 
						|
		if( isVisible() )
 | 
						|
		{
 | 
						|
			toFront();
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			setVisible( true );
 | 
						|
		}
 | 
						|
		imposedTrabalhadorID = trabalhadorID;
 | 
						|
		executeAction( NEW_INDEX );
 | 
						|
		exameListener = listener;
 | 
						|
	}
 | 
						|
}
 |