diff --git a/trunk/siprp/FichaDataProvider.java b/trunk/siprp/FichaDataProvider.java index e57709af..2026e483 100644 --- a/trunk/siprp/FichaDataProvider.java +++ b/trunk/siprp/FichaDataProvider.java @@ -437,6 +437,40 @@ public class FichaDataProvider extends MetaProvider implements SearchExecuter { return objects; } + public Integer getEstabelecimentoIDForTrabalhador( Integer trabalhadorID ) + throws Exception + { + Select select = new Select( new String[]{ T_TRABALHADORES }, + new String[]{ ESTABELECIMENTO_ID }, + new Field( ID ).isEqual( trabalhadorID ).and( + new Field( INACTIVO ).isDifferent( "y" ) ), + null, null ); + Virtual2DArray array = executer.executeQuery( select ); + Integer estabelecimentoID = null; + if( array != null && array.columnLength() > 0 ) + { + estabelecimentoID = ( Integer )array.get( 0, 0 ); + } + return estabelecimentoID; + } + + public Integer getEmpresaIDForEstabelecimento( Integer estabelecimentoID ) + throws Exception + { + Select select = new Select( new String[]{ T_ESTABELECIMENTOS }, + new String[]{ EMPRESA_ID }, + new Field( ID ).isEqual( estabelecimentoID ).and( + new Field( INACTIVO ).isDifferent( "y" ) ), + null, null ); + Virtual2DArray array = executer.executeQuery( select ); + Integer empresaID = null; + if( array != null && array.columnLength() > 0 ) + { + empresaID = ( Integer )array.get( 0, 0 ); + } + return empresaID; + } + public Integer []getAvisosIDByTipoAndDate( Integer tipo, Date date ) throws Exception { diff --git a/trunk/siprp/ficha/FichaWindow.java b/trunk/siprp/ficha/FichaWindow.java index 9d02147b..d139b68b 100644 --- a/trunk/siprp/ficha/FichaWindow.java +++ b/trunk/siprp/ficha/FichaWindow.java @@ -56,6 +56,9 @@ public class FichaWindow extends TabbedWindow private static FichaWindow window = null; + private Integer imposedTrabalhadorID = null; + private SaveExameListener exameListener = null; + /** Creates a new instance of FichaWindow */ private FichaWindow() throws Exception @@ -311,7 +314,6 @@ public class FichaWindow extends TabbedWindow { iex.printStackTrace(); } -// // createPDF( exame ); // print(); } @@ -320,70 +322,90 @@ public class FichaWindow extends TabbedWindow 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 ) { - fdpProvider.setSearch( FichaDataProvider.SEARCH_EMPRESAS ); - SearchDialog search; - Integer oldID = empresaID; + 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(); + 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 + if( empresaID == null ) { - return false; + 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() ); + fdpProvider.setSearch( FichaDataProvider.SEARCH_ESTABELECIMENTOS ); + fdpProvider.setSearchID( FichaDataProvider.SEARCH_EMPRESAS, empresaID.intValue() ); - search = new SearchDialog( fdpProvider, null, false, null, true ); - estabelecimentoID = ( Integer )search.getSelected(); + search = new SearchDialog( fdpProvider, null, false, null, true ); + estabelecimentoID = ( Integer )search.getSelected(); - if( estabelecimentoID == null ) - { - if( search.getIsNew() ) + if( estabelecimentoID == null ) { - trabalhadorID = null; - reload(0); - return true; + if( search.getIsNew() ) + { + trabalhadorID = null; + reload(0); + return true; + } + else + { + return false; + } } - else + + 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() ) { - return false; + reload(0); + return true; } } - - 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 ) + else { - if( search.getIsNew() ) + trabalhadorID = imposedTrabalhadorID; + imposedTrabalhadorID = null; + try { - reload(0); - return true; + estabelecimentoID = fdpProvider.getEstabelecimentoIDForTrabalhador( trabalhadorID ); + empresaID = fdpProvider.getEmpresaIDForEstabelecimento( estabelecimentoID ); } - else + catch( Exception ex ) { + DialogException.showExceptionMessage( ex, "Erro a carregar dados.", true ); return false; } } + if( trabalhadorID == null ) + { + return false; + } reload(0); return true; } @@ -810,5 +832,20 @@ public class FichaWindow extends TabbedWindow } } - + 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; + } } diff --git a/trunk/siprp/ficha/SaveExameListener.java b/trunk/siprp/ficha/SaveExameListener.java new file mode 100644 index 00000000..ccb16da8 --- /dev/null +++ b/trunk/siprp/ficha/SaveExameListener.java @@ -0,0 +1,19 @@ +/* + * SaveExameListener.java + * + * Created on May 17, 2007, 12:33 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package siprp.ficha; + +/** + * + * @author lflores + */ +public interface SaveExameListener +{ + public void exameSaved( Integer trabalhadorID, Integer exameID ); +} diff --git a/trunk/siprp/medicina/processo/ProcessoPanel.java b/trunk/siprp/medicina/processo/ProcessoPanel.java index 881db9b3..dbc1418f 100644 --- a/trunk/siprp/medicina/processo/ProcessoPanel.java +++ b/trunk/siprp/medicina/processo/ProcessoPanel.java @@ -23,6 +23,8 @@ import java.util.HashMap; import java.util.Locale; import java.util.Vector; import javax.swing.*; +import siprp.ficha.FichaWindow; +import siprp.ficha.SaveExameListener; import siprp.medicina.MedicinaConstants; import siprp.medicina.MedicinaDataProvider; import siprp.medicina.processo.data.TrabalhadoresProcessoData; @@ -33,7 +35,7 @@ import siprp.medicina.processo.data.TrabalhadoresProcessoData; */ public class ProcessoPanel extends JPanel implements ActionListener, ControllableComponent, - MedicinaConstants, ProcessoConstants + MedicinaConstants, ProcessoConstants, SaveExameListener { private static final String ECDS_ICON_PATH = "siprp/medicina/processo/icons/ecds.png"; private static final String CONSULTA_ICON_PATH = "siprp/medicina/processo/icons/consulta.png"; @@ -204,6 +206,17 @@ public class ProcessoPanel extends JPanel protected void emitirFA() { + if( trabalhadorID != null ) + { + try + { + FichaWindow.getWindow().editTrabalhador( trabalhadorID, this ); + } + catch( Exception ex ) + { + DialogException.showException( ex ); + } + } } protected void fecharProcesso() @@ -360,4 +373,12 @@ public class ProcessoPanel extends JPanel { this.trabalhadorID = trabalhadorID; } + + public void exameSaved( Integer trabalhadorID, Integer exameID ) + { + if( trabalhadorID.equals( this.trabalhadorID ) ) + { + System.out.println( "NOTIFIED EXAME: " + exameID ); + } + } }