From f6ab1288e7cfe3bed2a4428febaeb5c8794a2f2d Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Tue, 13 Apr 2004 21:45:12 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@48 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/siprp/FichaDataProvider.java | 1 + trunk/siprp/ficha/ExamePDF.java | 12 ++ trunk/siprp/ficha/FichaWindow.java | 211 ++++++++++++++++++++++++++++- 3 files changed, 222 insertions(+), 2 deletions(-) diff --git a/trunk/siprp/FichaDataProvider.java b/trunk/siprp/FichaDataProvider.java index 2432fa6e..081a8384 100644 --- a/trunk/siprp/FichaDataProvider.java +++ b/trunk/siprp/FichaDataProvider.java @@ -140,6 +140,7 @@ public class FichaDataProvider extends MetaProvider implements SearchExecuter { new DBField[]{ ESTABELECIMENTOS.getFieldByName( EMPRESA_ID ) }, "R_ESTABELECIMENTOS_EMPRESAS" ); EMPRESAS.disableSave( INACTIVO ); + EMPRESAS.disableSave( SERVICO_SAUDE_DESIGNACAO ); ESTABELECIMENTOS.disableSave( INACTIVO ); TRABALHADORES.disableSave( INACTIVO ); EXAMES.disableSave( PDF ); diff --git a/trunk/siprp/ficha/ExamePDF.java b/trunk/siprp/ficha/ExamePDF.java index f16417fe..99883b4b 100644 --- a/trunk/siprp/ficha/ExamePDF.java +++ b/trunk/siprp/ficha/ExamePDF.java @@ -88,6 +88,18 @@ public class ExamePDF { } } + public void print( byte []pdf ) + throws Exception + { + FileOutputStream fos = new FileOutputStream( System.getProperty( "user.home" ) + "\\report_ficha.pdf" ); + fos.write( pdf ); + fos.close(); + System.out.println( "File saved." ); + Process proc = Runtime.getRuntime().exec( "cmd.exe /c \"" + System.getProperty( "user.home" ) + "\\report_ficha.pdf\"" ); + proc.waitFor(); + new File( System.getProperty( "user.home" ) + "\\report_ficha.pdf" ).delete(); + } + public byte[] createPDF( Hashtable values ) { Document document = new Document(); diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index d9313e71..adb278a9 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -11,6 +11,7 @@ import siprp.*; import java.awt.*; import java.util.*; import javax.swing.*; +import java.text.*; import com.evolute.utils.metadb.*; import com.evolute.utils.ui.*; @@ -100,6 +101,22 @@ public class FichaWindow extends TabbedWindow 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 ) @@ -165,9 +182,13 @@ public class FichaWindow extends TabbedWindow try { exame.save(); - ExamePDF ePDF = new ExamePDF(); - exame.setProperty( fdpProvider.PDF, ePDF.createPDF( new Hashtable() ) ); + 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 ) { @@ -307,4 +328,190 @@ public class FichaWindow extends TabbedWindow 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 ); + } + }