From b5bfda6ff21e7b9cd709b362af608526b0bb6ccb Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Sun, 26 Feb 2006 19:33:40 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@232 bb69d46d-e84e-40c8-a05a-06db0d633741 --- trunk/siprp/FichaDataProvider.java | 37 ++++++++++++++++++++++ trunk/siprp/ficha/FichaWindow.java | 49 +++++++++--------------------- trunk/siprp/ficha/UpperPanel.java | 19 ++++++++++++ 3 files changed, 70 insertions(+), 35 deletions(-) diff --git a/trunk/siprp/FichaDataProvider.java b/trunk/siprp/FichaDataProvider.java index b5e28080..cbcb94f1 100644 --- a/trunk/siprp/FichaDataProvider.java +++ b/trunk/siprp/FichaDataProvider.java @@ -169,6 +169,7 @@ public class FichaDataProvider extends MetaProvider implements SearchExecuter { private int SEARCH_TRABALHADORES_ID = -1; private int SEARCH_EXAMES_ID = -1; + protected final Hashtable medicosEstabelecimentosHash = new Hashtable(); /** Creates a new instance of FichaDataProvider */ public FichaDataProvider() @@ -558,4 +559,40 @@ public class FichaDataProvider extends MetaProvider implements SearchExecuter { } return new Object[]{ data, tipo }; } + + public void setMedicoForEstabelecimento( Integer estabelecimentoID, Integer medicoID ) + throws Exception + { + Integer medicoAntigo = ( Integer ) medicosEstabelecimentosHash.get( estabelecimentoID ); + if( !medicoID.equals( medicoAntigo ) ) + { + Update update = + new Update( "estabelecimentos", + new Assignment[]{ + new Assignment( new Field( "medico_id" ), medicoID ) }, + new Field( "id" ).isEqual( estabelecimentoID ) ); + executer.executeQuery( update ); + medicosEstabelecimentosHash.put( estabelecimentoID, medicoID ); + } + } + + public Integer getMedicoForEstabelecimento( Integer estabelecimentoID ) + throws Exception + { + if( !medicosEstabelecimentosHash.containsKey( estabelecimentoID ) ) + { + Select select = + new Select( new String[]{ "estabelecimentos" }, + new String[]{ "medico_id" }, + new Field( "id" ).isEqual( estabelecimentoID ) ); + Virtual2DArray array = executer.executeQuery( select ); + Integer medicoID = ( Integer ) array.get( 0, 0 ); + if( medicoID == null ) + { + medicoID = new Integer( -1 ); + } + medicosEstabelecimentosHash.put( estabelecimentoID, medicoID ); + } + return ( Integer ) medicosEstabelecimentosHash.get( estabelecimentoID ); + } } diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index 18cbe5c9..9d9e1080 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -261,6 +261,17 @@ public class FichaWindow extends TabbedWindow // estabelecimento.save(); exame.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(); @@ -292,23 +303,7 @@ public class FichaWindow extends TabbedWindow 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, false, null, true ); empresaID = ( Integer )search.getSelected(); @@ -329,23 +324,7 @@ public class FichaWindow extends TabbedWindow 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, false, null, true ); estabelecimentoID = ( Integer )search.getSelected(); @@ -433,7 +412,7 @@ public class FichaWindow extends TabbedWindow } } ); dialog.setSize( 250, 200 ); - dialog.show(); + dialog.setVisible( true ); } public void reload( int index ) diff --git a/trunk/siprp/ficha/UpperPanel.java b/trunk/siprp/ficha/UpperPanel.java index 95bd8244..5a18bfd2 100644 --- a/trunk/siprp/ficha/UpperPanel.java +++ b/trunk/siprp/ficha/UpperPanel.java @@ -141,6 +141,25 @@ public class UpperPanel extends JPanel { estabelecimento = ( EstabelecimentoData ) JDO.load( EstabelecimentoData.class, estabelecimentoID ); nomeEstabelecimento = (String) estabelecimento.get( EstabelecimentoData.NOME ); + try + { + Integer medicoID = provider.getMedicoForEstabelecimento( estabelecimentoID ); + if( medicoID != null && medicoID.intValue() > -1 ) + { + for( int n = 0; n < medicosCombo.getItemCount(); n++ ) + { + IDObject medico = ( IDObject ) medicosCombo.getItemAt( n ); + if( medico.getID().equals( medicoID ) ) + { + medicosCombo.setSelectedIndex( n ); + break; + } + } + } + } + catch( Exception ex ) + { + } } if( empresaID != null ) {