/* * FichaWindow.java * * Created on 29 de Marco de 2004, 11:50 */ package siprp.ficha; import java.awt.FileDialog; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FilenameFilter; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Hashtable; import java.util.Vector; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPanel; import org.jdom.Document; import org.jdom.Element; import org.jdom.output.XMLOutputter; import siprp.FichaDataProvider; import siprp.data.outer.EmpresasData; import siprp.data.outer.EstabelecimentosData; import siprp.data.outer.ExamesData; import siprp.data.outer.MedicosData; import siprp.data.outer.TrabalhadoresData; import siprp.importer.Importer; import siprp.lembretes.LembretesDataProvider; import siprp.medicina.MarcacoesMedicinaHandler; import siprp.printer.Printer; import siprp.ui.SIPRPTabbedWindow; import com.evolute.entity.ProviderInterface; import com.evolute.utils.Singleton; import com.evolute.utils.data.IDObject; import com.evolute.utils.strings.StringPlainer; import com.evolute.utils.ui.DialogException; import com.evolute.utils.ui.dialog.ListAction; import com.evolute.utils.ui.dialog.ListActionDialog; import com.evolute.utils.ui.search.SearchDialog; import com.evolute.utils.ui.window.ActionHandler; import com.evolute.utils.ui.window.ProgressDialog; /** * * @author fpalma */ public class FichaWindow extends SIPRPTabbedWindow implements ListAction, FichaAptidaoConstants { private static final long serialVersionUID = 1L; private ProviderInterface JDO; private UpperPanel upperPanel; private EmpresaPanel empresaPanel; private TrabalhadorPanel trabalhadorPanel; private ObservacoesPanel observacoesPanel; private ExamePanel examePanel; private LembretesDataProvider lembretesProvider; 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; private boolean useFO = false; /** 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 = ( ProviderInterface ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER ); marcacoesHandler = new MarcacoesMedicinaHandler(); lembretesProvider = LembretesDataProvider.getProvider(); setupComponents(); } public static FichaWindow getWindow() throws Exception { if( window == null ) { window = new FichaWindow(); } return window; } private void setupComponents() throws Exception { setSize( 800, 700 ); 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() // { // printOldFO(); // } // // public boolean activate( boolean newAction, boolean editAction, // boolean cancelAction, boolean saveAction, // boolean deleteAction, boolean selectAction ) // { // return saveAction || editAction; // } // }, "Imprimir Fichas Anteriores (novo)", // "Imprimir Fichas Anteriores (novo)", 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() { printToFile(); } public boolean activate( boolean newAction, boolean editAction, boolean cancelAction, boolean saveAction, boolean deleteAction, boolean selectAction ) { return saveAction || editAction; } }, "Exportar", "Exportar para PDF", null, 0, true ); // 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(); MedicosData medico; try { medico = (MedicosData)upperPanel.save(); } catch( ValuesException vex ) { msg.append( vex.getMessage() ); medico = null; } EstabelecimentosData estabelecimento; try { estabelecimento = (EstabelecimentosData)empresaPanel.save(); } catch( ValuesException vex ) { msg.append( vex.getMessage() ); estabelecimento = null; } TrabalhadoresData trabalhador; try { trabalhador = (TrabalhadoresData)trabalhadorPanel.save(); } catch( ValuesException vex ) { msg.append( vex.getMessage() ); trabalhador = null; } ExamesData exame; try { exame = (ExamesData)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; } String observacoes = ( String ) observacoesPanel.save(); estabelecimento.set( EstabelecimentosData.NOME_PLAIN, com.evolute.utils.strings.StringPlainer.convertString( ( String ) estabelecimento.get( EstabelecimentosData.NOME ) ) ); // trabalhador.setProperty( FichaDataProvider.R_TRABALHADOR_ESTABELECIMENTO, estabelecimento ); // trabalhador.setProperty( FichaDataProvider.OBSERVACOES, observacoesPanel.save() ); trabalhador.set( TrabalhadoresData.TO_ESTABELECIMENTO_ID, estabelecimento ); trabalhador.set( TrabalhadoresData.OBSERVACOES, observacoes ); trabalhador.set( TrabalhadoresData.NOME_PLAIN, com.evolute.utils.strings.StringPlainer.convertString( ( String ) trabalhador.get( TrabalhadoresData.NOME ) ) ); // exame.setProperty( FichaDataProvider.R_EXAME_MEDICO, medico ); // exame.setProperty( FichaDataProvider.R_EXAME_TRABALHADOR, trabalhador ); exame.set( ExamesData.TO_MEDICO_ID, medico ); exame.set( ExamesData.TO_TRABALHADOR_ID, trabalhador ); byte fo[] = null; try { fo = createFO( exame ); } catch( Exception ex ) { DialogException.showExceptionMessage( ex, "Erro a criar nova vers\u00e3o de ficha", true ); } try { // lflores - disable FO for now // System.out.println( "FO sz: " + fo.length ); exame.set( ExamesData.FO, fo ); exame.set( ExamesData.PDF, createPDF( exame ) ); // empresa.save(); // estabelecimento.save(); exame.save(); trabalhador.save(); try { if( medico != null ) { fdpProvider.setMedicoForEstabelecimento( ( Integer ) estabelecimento.get( EstabelecimentosData.ID ), ( Integer ) medico.get( MedicosData.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( TrabalhadoresData.ID ); try { //Marcacao.saveMarcacaoConsultaForTrabalhadorID( trabalhadorID, (Date)exame.get( ExamesData.PROXIMO_EXAME ) ); marcacoesHandler.ajustarMarcacoes( trabalhadorID, (Integer)exame.get( ExamesData.TIPO ), (Date)exame.get( ExamesData.DATA ), examePanel.getMotivoProximoExame(), (Date)exame.get( ExamesData.PROXIMO_EXAME ) ); } catch( Exception iex ) { iex.printStackTrace(); } Integer motivoProximoExame = (Integer) exame.get( ExamesData.TIPO ); if ( motivoProximoExame != null && motivoProximoExame.equals( new Integer( FichaAptidaoConstants.CODIGO_TIPO_OCASIONAL ) ) ) { Date proximoExameDate = (Date) exame.get( ExamesData.PROXIMO_EXAME ); if( proximoExameDate != null && proximoExameDate.getTime() > 0 ) { Calendar whenCal = Calendar.getInstance(); whenCal.setTime( proximoExameDate ); whenCal.add( Calendar.MONTH, -2 ); Date now = new Date(); Date when = whenCal.getTime(); lembretesProvider.criarLembreteFicha( exame, now.after( when ) ? now : when ); System.out.println(new Date() + ": A criar lembrete"); } } // createPDF( exame ); // print(); } catch( Exception ex ) { DialogException.showExceptionMessage( ex, "Erro a guardar", true ); return false; } if( exameListener != null ) { exameListener.exameSaved( trabalhadorID, ( Integer )exame.get( ExamesData.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, false ); } catch( Exception ex ) { DialogException.showExceptionMessage( ex, "N\u00e3o foi poss\u00edvel imprimir", true ); } } private void print( Integer exameID, boolean toFile ) throws Exception { // MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); ExamesData exame = (ExamesData) JDO.load( ExamesData.class, exameID ); if( exame == null ) { throw new Exception( "N\u00e3o existe exame" ); } byte fo[] = (byte []) exame.get( ExamesData.FO ); byte pdf[] = (byte []) exame.get( ExamesData.PDF ); if( toFile ) { TrabalhadoresData trabalhadorExame = exame.toTrabalhador_id(); String fileName = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadoresData.NOME ) ); SimpleDateFormat sdf = new SimpleDateFormat("_dd-MM-yyyy"); Date date = new Date(); fileName = fileName + sdf.format( date ); fileName = fileName.replace( ' ', '_' ); JFileChooser dialog = new JFileChooser(); dialog.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); int result = dialog.showSaveDialog( this ); if( result == JFileChooser.APPROVE_OPTION ) { File selectedFile = dialog.getSelectedFile(); if( selectedFile != null ) { String absolutePath = selectedFile.getAbsolutePath(); if( absolutePath != null ) { if(absolutePath.charAt( absolutePath.length() - 1) != File.separatorChar ) { absolutePath = absolutePath + File.separatorChar; } fileName = absolutePath + fileName + ".pdf"; } // if( fo != null ) // { // Printer.printFoToFile( fo, fileName, true ); // } // else // { Printer.printPDFToFile( pdf, fileName, true ); // } JOptionPane.showMessageDialog( this, "Ficha exportada para: " + fileName ); } } } else { // if( fo != null ) // { // FichaAptidaoCreator.getCreator().print( fo ); // } // else // { TrabalhadoresData trabalhadorExame = exame.toTrabalhador_id(); String nomeFicheiro = StringPlainer.convertString( ( String ) trabalhadorExame.get( TrabalhadoresData.NOME ) ); nomeFicheiro = nomeFicheiro.replaceAll( " ", "_" ); ePDF.print( pdf, nomeFicheiro ); // } } } private void printToFile() { try { if( trabalhadorID != null ) { Integer id = fdpProvider.getLastExameIDForTrabalhador( trabalhadorID ); if( id != null ) { print(id, true); } } } catch( Exception ex ) { DialogException.showExceptionMessage( ex, "N\u00e3o foi poss\u00edvel exportar", true ); } } // private void printFO( Integer exameID ) // throws Exception //{ //// MetaObject exame = fdpProvider.load( fdpProvider.EXAMES, new DBKey( exameID ) ); // ExamesData exame = (ExamesData) JDO.load( ExamesData.class, exameID ); // if( exame == null ) // { // throw new Exception( "N\u00e3o existe exame" ); // } // // // lflores - ignore FO (for now) // byte fo[] = (byte []) exame.get( ExamesData.FO ); // // if( fo != null ) // { // byte pdf[] = FichaAptidaoCreator.getCreator().createPDF( fo ); // new PDFFilePrinter( pdf, true ); // } //} public byte[] createFO( ExamesData exame ) throws Exception { byte xml[] = createXmlFromExame( exame ); // HashMap ht = createMapFromExame(exame); // ExamePDF ePDF = new ExamePDF(); // return ePDF.createPDF( ht ); return FichaAptidaoCreator.getCreator().createFO( xml ); } public byte[] createPDF( ExamesData exame ) throws Exception { // byte fo[] = exame.get( ExamesData.FO, fo ); HashMap ht = createMapFromExame( exame ); return ePDF.createPDF( ht ); // return FichaAptidaoCreator.getCreator().createPDF( fo ); } private HashMap createMapFromExame(final ExamesData exame) { MedicosData medico = exame.toMedico_id(); TrabalhadoresData trabalhador = exame.toTrabalhador_id(); EstabelecimentosData estabelecimento = trabalhador.toEstabelecimento_id(); EmpresasData empresa = estabelecimento.toEmpresa_id(); // empresa.load( empresa.getPrimaryKeyValue() ); HashMap ht = new HashMap(); ht.put( DESIGNACAO_SOCIAL, ( String )empresa.get( EmpresasData.DESIGNACAO_SOCIAL ) ); ht.put( ESTABELECIMENTOS_NOME, ( String )estabelecimento.get( EstabelecimentosData.NOME ) ); String aux = (String)estabelecimento.get( EstabelecimentosData.LOCALIDADE ); ht.put( ESTABELECIMENTOS_LOCALIDADE, aux != null ? aux : "" ); Integer tipo = (Integer)empresa.get( EmpresasData.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( EmpresasData.SERVICO_SAUDE_DESIGNACAO ) ); tipo = (Integer)empresa.get( EmpresasData.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( EmpresasData.SERVICO_HIGIENE_DESIGNACAO ) ); ht.put( TRABALHADORES_NOME, ( String )trabalhador.get( TrabalhadoresData.NOME ) ); aux = (String)trabalhador.get( TrabalhadoresData.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( TrabalhadoresData.DATA_NASCIMENTO ); ht.put( DATA_NASCIMENTO, data != null ? df.format( data ) : "" ); aux = (String)trabalhador.get( TrabalhadoresData.NACIONALIDADE ); ht.put( NACIONALIDADE, aux != null ? aux : "" ); aux = (String)trabalhador.get( TrabalhadoresData.NUMERO_MECANOGRAFICO ); ht.put( NUMERO_MECANOGRAFICO, aux != null ? aux : "" ); data = ( Date )trabalhador.get( TrabalhadoresData.DATA_ADMISSAO ); ht.put( DATA_ADMISSAO, data != null ? df.format( data ) : "" ); aux = (String)trabalhador.get( TrabalhadoresData.CATEGORIA ); ht.put( CATEGORIA, aux != null ? aux : "" ); aux = (String)trabalhador.get( TrabalhadoresData.LOCAL_TRABALHO ); ht.put( LOCAL_TRABALHO, aux != null ? aux : "" ); aux = (String)trabalhador.get( TrabalhadoresData.FUNCAO_PROPOSTA ); ht.put( FUNCAO_PROPOSTA, aux != null ? aux : "" ); data = ( Date )trabalhador.get( TrabalhadoresData.DATA_ADMISSAO_FUNCAO ); ht.put( DATA_ADMISSAO_FUNCAO, data != null ? df.format( data ) : "" ); aux = (String)trabalhador.get( TrabalhadoresData.OBSERVACOES ); ht.put( OBSERVACOES, aux != null ? aux : "" ); data = ( Date )exame.get( ExamesData.DATA ); ht.put( EXAMES_DATA, data != null ? df.format( data ) : "" ); tipo = (Integer)exame.get( ExamesData.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( ExamesData.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( ExamesData.OUTRO_TIPO ); // ht.put( "tipo_outro", aux != null ? aux : "" ); // break; } aux = (String)exame.get( ExamesData.OUTRO_TIPO ); ht.put( TIPO_OUTRO_TEXTO, aux != null ? aux : "" ); tipo = (Integer)exame.get( ExamesData.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( ExamesData.OUTRA_FUNCAO_1 ); ht.put( OUTRA_FUNCAO_1, aux != null ? aux : "" ); aux = (String)exame.get( ExamesData.OUTRA_FUNCAO_2 ); ht.put( OUTRA_FUNCAO_2, aux != null ? aux : "" ); aux = (String)exame.get( ExamesData.OUTRA_FUNCAO_3 ); ht.put( OUTRA_FUNCAO_3, aux != null ? aux : "" ); aux = (String)exame.get( ExamesData.OUTRA_FUNCAO_4 ); ht.put( OUTRA_FUNCAO_4, aux != null ? aux : "" ); aux = (String)exame.get( ExamesData.OUTRAS_RECOMENDACOES ); ht.put( OUTRAS_RECOMENDACOES, aux != null ? aux : "" ); data = ( Date )exame.get( ExamesData.PROXIMO_EXAME ); ht.put( PROXIMO_EXAME, data != null ? df.format( data ) : "n/d" ); aux = (String)medico.get( MedicosData.NOME ); ht.put( MEDICOS_NOME, aux != null ? aux : "" ); aux = (String)medico.get( MedicosData.NUMERO_CEDULA ); ht.put( NUMERO_CEDULA, aux != null ? aux : "" ); return ht; } private byte[] createXmlFromExame(final ExamesData exame) throws Exception { MedicosData medico = exame.toMedico_id(); TrabalhadoresData trabalhador = exame.toTrabalhador_id(); EstabelecimentosData estabelecimento = trabalhador.toEstabelecimento_id(); EmpresasData empresa = estabelecimento.toEmpresa_id(); Element rootElement = new Element( "FichaAptidao" ); Element portariaElement = new Element( "portaria" ); portariaElement.setText( "Portaria n. 299/2007, de 16 de Mar\u00e7o" ); rootElement.addContent( portariaElement ); Element empresaElement = new Element( "empresa" ); Element designacaoSocialEmpresaElement = new Element( "designacao-social" ); designacaoSocialEmpresaElement.setText( ( String )empresa.get( EmpresasData.DESIGNACAO_SOCIAL ) ); empresaElement.addContent( designacaoSocialEmpresaElement ); rootElement.addContent( empresaElement ); Integer tipoServicoSaude = (Integer)empresa.get( EmpresasData.SERVICO_SAUDE_TIPO ); Integer tipoServicoHigieneSeguranca = (Integer)empresa.get( EmpresasData.SERVICO_HIGIENE_TIPO ); Element estabelecimentoElement = new Element( "estabelecimento" ); Element nomeEstabelecimentoElement = new Element( "nome" ); nomeEstabelecimentoElement.setText( ( String )estabelecimento.get( EstabelecimentosData.NOME ) ); estabelecimentoElement.addContent( nomeEstabelecimentoElement ); Element localidadeEstabelecimentoElement = new Element( "localidade" ); localidadeEstabelecimentoElement.setText( ( String )estabelecimento.get( EstabelecimentosData.LOCALIDADE ) ); estabelecimentoElement.addContent( localidadeEstabelecimentoElement ); Element servicoSaudeEstabelecimentoElement = new Element( "servico-saude" ); Element tipoServicoSaudeEstabelecimentoElement = new Element( "tipo" ); Element internoTipoServicoSaudeEstabelecimentoElement = new Element( "interno" ); internoTipoServicoSaudeEstabelecimentoElement.setText( tipoServicoSaude.intValue() == 1 ? "y" : "n" ); tipoServicoSaudeEstabelecimentoElement.addContent( internoTipoServicoSaudeEstabelecimentoElement ); Element interempresasTipoServicoSaudeEstabelecimentoElement = new Element( "interempresas" ); interempresasTipoServicoSaudeEstabelecimentoElement.setText( tipoServicoSaude.intValue() == 2 ? "y" : "n" ); tipoServicoSaudeEstabelecimentoElement.addContent( interempresasTipoServicoSaudeEstabelecimentoElement ); Element externoTipoServicoSaudeEstabelecimentoElement = new Element( "externo" ); externoTipoServicoSaudeEstabelecimentoElement.setText( tipoServicoSaude.intValue() == 3 ? "y" : "n" ); tipoServicoSaudeEstabelecimentoElement.addContent( externoTipoServicoSaudeEstabelecimentoElement ); Element snsTipoServicoSaudeEstabelecimentoElement = new Element( "sns" ); snsTipoServicoSaudeEstabelecimentoElement.setText( tipoServicoSaude.intValue() == 4 ? "y" : "n" ); tipoServicoSaudeEstabelecimentoElement.addContent( snsTipoServicoSaudeEstabelecimentoElement ); servicoSaudeEstabelecimentoElement.addContent( tipoServicoSaudeEstabelecimentoElement ); Element designacaoServicoSaudeEstabelecimentoElement = new Element( "designacao" ); designacaoServicoSaudeEstabelecimentoElement.setText( ( String )empresa.get( EmpresasData.SERVICO_SAUDE_DESIGNACAO ) ); servicoSaudeEstabelecimentoElement.addContent( designacaoServicoSaudeEstabelecimentoElement ); estabelecimentoElement.addContent( servicoSaudeEstabelecimentoElement ); Element servicoHigieneSegurancaEstabelecimentoElement = new Element( "servico-higiene-seguranca" ); Element tipoServicoHigieneSegurancaEstabelecimentoElement = new Element( "tipo" ); Element internoTipoServicoHigieneSegurancaEstabelecimentoElement = new Element( "interno" ); internoTipoServicoHigieneSegurancaEstabelecimentoElement.setText( tipoServicoHigieneSeguranca.intValue() == 1 ? "y" : "n" ); tipoServicoHigieneSegurancaEstabelecimentoElement.addContent( internoTipoServicoHigieneSegurancaEstabelecimentoElement ); Element interempresasTipoServicoHigieneSegurancaEstabelecimentoElement = new Element( "interempresas" ); interempresasTipoServicoHigieneSegurancaEstabelecimentoElement.setText( tipoServicoHigieneSeguranca.intValue() == 2 ? "y" : "n" ); tipoServicoHigieneSegurancaEstabelecimentoElement.addContent( interempresasTipoServicoHigieneSegurancaEstabelecimentoElement ); Element externoTipoServicoHigieneSegurancaEstabelecimentoElement = new Element( "externo" ); externoTipoServicoHigieneSegurancaEstabelecimentoElement.setText( tipoServicoHigieneSeguranca.intValue() == 3 ? "y" : "n" ); tipoServicoHigieneSegurancaEstabelecimentoElement.addContent( externoTipoServicoHigieneSegurancaEstabelecimentoElement ); Element outroTipoServicoHigieneSegurancaEstabelecimentoElement = new Element( "outro" ); outroTipoServicoHigieneSegurancaEstabelecimentoElement.setText( tipoServicoHigieneSeguranca.intValue() == 4 ? "y" : "n" ); tipoServicoHigieneSegurancaEstabelecimentoElement.addContent( outroTipoServicoHigieneSegurancaEstabelecimentoElement ); servicoHigieneSegurancaEstabelecimentoElement.addContent( tipoServicoHigieneSegurancaEstabelecimentoElement ); Element designacaoServicoHigieneSegurancaEstabelecimentoElement = new Element( "designacao" ); designacaoServicoHigieneSegurancaEstabelecimentoElement.setText( ( String )empresa.get( EmpresasData.SERVICO_HIGIENE_DESIGNACAO ) ); servicoHigieneSegurancaEstabelecimentoElement.addContent( designacaoServicoHigieneSegurancaEstabelecimentoElement ); estabelecimentoElement.addContent( servicoHigieneSegurancaEstabelecimentoElement ); rootElement.addContent( estabelecimentoElement ); char sexo = ( (String)trabalhador.get( TrabalhadoresData.SEXO ) ).charAt( 0 ); DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT ); Date dataNascimento = ( Date )trabalhador.get( TrabalhadoresData.DATA_NASCIMENTO ); Date dataAdmissao = ( Date )trabalhador.get( TrabalhadoresData.DATA_ADMISSAO ); Date dataAdmissaoFuncao = ( Date )trabalhador.get( TrabalhadoresData.DATA_ADMISSAO_FUNCAO ); Element trabalhadorElement = new Element( "trabalhador" ); Element nomeTrabalhadorElement = new Element( "nome" ); nomeTrabalhadorElement.setText( ( String )trabalhador.get( TrabalhadoresData.NOME ) ); Element sexoTrabalhadorElement = new Element( "sexo" ); sexoTrabalhadorElement.setText( sexo == 'm' ? "Masculino" : "Feminino" ); trabalhadorElement.addContent( sexoTrabalhadorElement ); Element dataNascimentoTrabalhadorElement = new Element( "data-nascimento" ); dataNascimentoTrabalhadorElement.setText( dataNascimento != null ? df.format( dataNascimento ) : "" ); trabalhadorElement.addContent( dataNascimentoTrabalhadorElement ); Element nacionalidadeTrabalhadorElement = new Element( "nacionalidade" ); nacionalidadeTrabalhadorElement.setText( (String)trabalhador.get( TrabalhadoresData.NACIONALIDADE ) ); trabalhadorElement.addContent( nacionalidadeTrabalhadorElement ); trabalhadorElement.addContent( nomeTrabalhadorElement ); Element numeroMecanograficoTrabalhadorElement = new Element( "numero-mecanografico" ); numeroMecanograficoTrabalhadorElement.setText( (String)trabalhador.get( TrabalhadoresData.NUMERO_MECANOGRAFICO ) ); trabalhadorElement.addContent( numeroMecanograficoTrabalhadorElement ); Element dataAdmissaoTrabalhadorElement = new Element( "data-admissao" ); dataAdmissaoTrabalhadorElement.setText( dataAdmissao != null ? df.format( dataAdmissao ) : "" ); trabalhadorElement.addContent( dataAdmissaoTrabalhadorElement ); Element categoriaProfissionalTrabalhadorElement = new Element( "categoria-profissional" ); categoriaProfissionalTrabalhadorElement.setText( (String)trabalhador.get( TrabalhadoresData.CATEGORIA ) ); trabalhadorElement.addContent( categoriaProfissionalTrabalhadorElement ); Element localTrabalhoTrabalhadorElement = new Element( "local-trabalho" ); localTrabalhoTrabalhadorElement.setText( (String)trabalhador.get( TrabalhadoresData.LOCAL_TRABALHO ) ); trabalhadorElement.addContent( localTrabalhoTrabalhadorElement ); Element funcaoPropostaTrabalhadorElement = new Element( "funcao-proposta" ); funcaoPropostaTrabalhadorElement.setText( (String)trabalhador.get( TrabalhadoresData.FUNCAO_PROPOSTA ) ); Element dataAdmissaoFuncaoTrabalhadorElement = new Element( "data-admissao-funcao" ); dataAdmissaoFuncaoTrabalhadorElement.setText( dataAdmissaoFuncao != null ? df.format( dataAdmissaoFuncao ) : "" ); trabalhadorElement.addContent( dataAdmissaoFuncaoTrabalhadorElement ); trabalhadorElement.addContent( funcaoPropostaTrabalhadorElement ); rootElement.addContent( trabalhadorElement ); Element observacoesElement = new Element( "observacoes" ); observacoesElement.setText( (String)trabalhador.get( TrabalhadoresData.OBSERVACOES ) ); rootElement.addContent( observacoesElement ); Date dataExameMedico = ( Date )exame.get( ExamesData.DATA ); Integer tipoExameMedico = (Integer)exame.get( ExamesData.TIPO ); Integer tipoOcasionalExameMedico = (Integer)exame.get( ExamesData.OCASIONAL ); Integer resultadoExameMedico = (Integer)exame.get( ExamesData.RESULTADO ); Element exameMedicoElement = new Element( "exame-medico" ); Element dataExameMedicoElement = new Element( "data" ); dataExameMedicoElement.setText( dataExameMedico != null ? df.format( dataExameMedico ) : "" ); exameMedicoElement.addContent( dataExameMedicoElement ); Element tipoExameMedicoElement = new Element( "tipo" ); Element admissaoTipoExameMedicoElement = new Element( "admissao" ); admissaoTipoExameMedicoElement.setText( tipoExameMedico.intValue() == 1 ? "y" : "n" ); tipoExameMedicoElement.addContent( admissaoTipoExameMedicoElement ); Element periodicoTipoExameMedicoElement = new Element( "periodico" ); periodicoTipoExameMedicoElement.setText( tipoExameMedico.intValue() == 2 ? "y" : "n" ); tipoExameMedicoElement.addContent( periodicoTipoExameMedicoElement ); Element ocasionalTipoExameMedicoElement = new Element( "ocasional" ); ocasionalTipoExameMedicoElement.setText( tipoExameMedico.intValue() == 3 ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalTipoExameMedicoElement ); Element ocasionalDoencaTipoExameMedicoElement = new Element( "ocasional-doenca" ); ocasionalDoencaTipoExameMedicoElement.setText( ( tipoExameMedico.intValue() == 3 && tipoOcasionalExameMedico != null && tipoOcasionalExameMedico.intValue() == 1 ) ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalDoencaTipoExameMedicoElement ); Element ocasionalAcidenteTipoExameMedicoElement = new Element( "ocasional-acidente" ); ocasionalAcidenteTipoExameMedicoElement.setText( ( tipoExameMedico.intValue() == 3 && tipoOcasionalExameMedico != null && tipoOcasionalExameMedico.intValue() == 2 ) ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalAcidenteTipoExameMedicoElement ); Element ocasionalPedidoTrabalhadorTipoExameMedicoElement = new Element( "ocasional-pedido-trabalhador" ); ocasionalPedidoTrabalhadorTipoExameMedicoElement.setText( ( tipoExameMedico.intValue() == 3 && tipoOcasionalExameMedico != null && tipoOcasionalExameMedico.intValue() == 3 ) ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalPedidoTrabalhadorTipoExameMedicoElement ); Element ocasionalPedidoServicoTipoExameMedicoElement = new Element( "ocasional-pedido-servico" ); ocasionalPedidoServicoTipoExameMedicoElement.setText( ( tipoExameMedico.intValue() == 3 && tipoOcasionalExameMedico != null && tipoOcasionalExameMedico.intValue() == 4 ) ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalPedidoServicoTipoExameMedicoElement ); Element ocasionalMudancaoFuncaoTipoExameMedicoElement = new Element( "ocasional-mudanca-funcao" ); ocasionalMudancaoFuncaoTipoExameMedicoElement.setText( ( tipoExameMedico.intValue() == 3 && tipoOcasionalExameMedico != null && tipoOcasionalExameMedico.intValue() == 5 ) ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalMudancaoFuncaoTipoExameMedicoElement ); Element ocasionalAlteracaoCondicoesTrabalhoTipoExameMedicoElement = new Element( "ocasional-alteracao-condicoes-trabalho" ); ocasionalAlteracaoCondicoesTrabalhoTipoExameMedicoElement.setText( ( tipoExameMedico.intValue() == 3 && tipoOcasionalExameMedico != null && tipoOcasionalExameMedico.intValue() == 6 ) ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalAlteracaoCondicoesTrabalhoTipoExameMedicoElement ); Element ocasionalOutroTipoExameMedicoElement = new Element( "ocasional-outro" ); ocasionalOutroTipoExameMedicoElement.setText( ( tipoExameMedico.intValue() == 3 && tipoOcasionalExameMedico != null && tipoOcasionalExameMedico.intValue() == 10 ) ? "y" : "n" ); tipoExameMedicoElement.addContent( ocasionalOutroTipoExameMedicoElement ); Element ocasionalOutroDescricaoTipoExameMedicoElement = new Element( "ocasional-outro-descricao" ); ocasionalOutroDescricaoTipoExameMedicoElement.setText( (String)exame.get( ExamesData.OUTRO_TIPO ) ); tipoExameMedicoElement.addContent( ocasionalOutroDescricaoTipoExameMedicoElement ); exameMedicoElement.addContent( tipoExameMedicoElement ); Element resultadoExameMedicoElement = new Element( "resultado" ); Element aptoResultadoExameMedicoElement = new Element( "apto" ); aptoResultadoExameMedicoElement.setText( resultadoExameMedico.intValue() == 1 ? "y" : "n" ); resultadoExameMedicoElement.addContent( aptoResultadoExameMedicoElement ); Element aptoCondicionalmenteResultadoExameMedicoElement = new Element( "apto-condicionalmente" ); aptoCondicionalmenteResultadoExameMedicoElement.setText( resultadoExameMedico.intValue() == 2 ? "y" : "n" ); resultadoExameMedicoElement.addContent( aptoCondicionalmenteResultadoExameMedicoElement ); Element inaptoTemporariamenteResultadoExameMedicoElement = new Element( "inapto-temporariamente" ); inaptoTemporariamenteResultadoExameMedicoElement.setText( resultadoExameMedico.intValue() == 3 ? "y" : "n" ); resultadoExameMedicoElement.addContent( inaptoTemporariamenteResultadoExameMedicoElement ); Element inaptoDefinitivamenteResultadoExameMedicoElement = new Element( "inapto-definitivamente" ); inaptoDefinitivamenteResultadoExameMedicoElement.setText( resultadoExameMedico.intValue() == 4 ? "y" : "n" ); resultadoExameMedicoElement.addContent( inaptoDefinitivamenteResultadoExameMedicoElement ); Element outrasFuncoes1ResultadoExameMedicoElement = new Element( "outras-funcoes-1" ); outrasFuncoes1ResultadoExameMedicoElement.setText( (String)exame.get( ExamesData.OUTRA_FUNCAO_1 ) ); resultadoExameMedicoElement.addContent( outrasFuncoes1ResultadoExameMedicoElement ); Element outrasFuncoes2ResultadoExameMedicoElement = new Element( "outras-funcoes-2" ); outrasFuncoes2ResultadoExameMedicoElement.setText( (String)exame.get( ExamesData.OUTRA_FUNCAO_2 ) ); resultadoExameMedicoElement.addContent( outrasFuncoes2ResultadoExameMedicoElement ); Element outrasFuncoes3ResultadoExameMedicoElement = new Element( "outras-funcoes-3" ); outrasFuncoes3ResultadoExameMedicoElement.setText( (String)exame.get( ExamesData.OUTRA_FUNCAO_3 ) ); resultadoExameMedicoElement.addContent( outrasFuncoes3ResultadoExameMedicoElement ); Element outrasFuncoes4ResultadoExameMedicoElement = new Element( "outras-funcoes-4" ); outrasFuncoes4ResultadoExameMedicoElement.setText( (String)exame.get( ExamesData.OUTRA_FUNCAO_4 ) ); resultadoExameMedicoElement.addContent( outrasFuncoes4ResultadoExameMedicoElement ); exameMedicoElement.addContent( resultadoExameMedicoElement ); rootElement.addContent( exameMedicoElement ); Date dataProximoExame = ( Date )exame.get( ExamesData.PROXIMO_EXAME ); Element proximoExameElement = new Element( "proximo-element" ); proximoExameElement.setText( dataProximoExame != null ? df.format( dataProximoExame ) : "" ); rootElement.addContent( proximoExameElement ); Element outrasRecomendacoesElement = new Element( "outras-recomendacoes" ); outrasRecomendacoesElement.setText( (String)exame.get( ExamesData.OUTRAS_RECOMENDACOES ) ); rootElement.addContent( outrasRecomendacoesElement ); Element medicoElement = new Element( "medico" ); Element nomeMedicoElement = new Element( "nome" ); nomeMedicoElement.setText( (String)medico.get( MedicosData.NOME ) ); medicoElement.addContent( nomeMedicoElement ); Element cedulaMedicoElement = new Element( "cedula" ); cedulaMedicoElement.setText( (String)medico.get( MedicosData.NUMERO_CEDULA ) ); medicoElement.addContent( cedulaMedicoElement ); rootElement.addContent( medicoElement ); Document doc = new Document( rootElement ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new XMLOutputter().output( doc, baos ); return baos.toByteArray(); } 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 ); useFO = false; dialog.setVisible( true ); } } // private void printOldFO() // { // 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 ); // useFO = true; // dialog.setVisible( true ); // } // } public boolean executeListAction( int line, Object value ) { if( value != null ) { try { // if( useFO ) // { // ExamesData exame = (ExamesData) JDO.load( ExamesData.class, ( ( IDObject )value ).getID() ); // if( exame == null ) // { // throw new Exception( "N\u00e3o existe exame" ); // } // byte fo[] = (byte[]) exame.get( ExamesData.FO ); // Printer.printFO( fo ); // } // else // { print( ( ( IDObject )value ).getID(), false ); // } } 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 ) ); ExamesData exame = (ExamesData) JDO.load( ExamesData.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( ExamesData.DATA ) + "?", "...", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null ) == 0 ) { // exame.set( ExamesData.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; } public void editTrabalhador( Integer trabalhadorID, Date ultimaConsulta, Integer motivoProcesso, SaveExameListener listener ) { editTrabalhador(trabalhadorID,listener); examePanel.setup( ultimaConsulta, motivoProcesso ); } }