diff --git a/trunk/siprp/FichaDataProvider.java b/trunk/siprp/FichaDataProvider.java index f3370ced..8ccaf1ff 100644 --- a/trunk/siprp/FichaDataProvider.java +++ b/trunk/siprp/FichaDataProvider.java @@ -19,6 +19,8 @@ import com.evolute.utils.ui.search.*; import com.evolute.utils.sql.*; import com.evolute.utils.strings.*; +import siprp.data.*; + /** * * @author pars @@ -523,4 +525,37 @@ public class FichaDataProvider extends MetaProvider implements SearchExecuter { return objects; } + public Object[] getDadosUltimaMarcacao( Integer trabalhadorID ) + throws Exception + { + Select select = + new Select( new String[]{ "marcacoes_trabalhador" }, + new String[]{ "MAX( data )" }, + new Field( "trabalhador_id" ).isEqual( trabalhadorID ).and( + new Field( "tipo" ).isEqual( Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ).and( + new Field( "realizada" ).isEqual( "y" ).or( + new Field( "estado" ).isEqual( new Integer( 2 ) ) ) ) ); + Virtual2DArray array = executer.executeQuery( select ); + if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) + { + return new Object[]{ null, null }; + } + Date data = ( Date ) array.get( 0, 0 ); + select = + new Select( new String[]{ "marcacoes_trabalhador" }, + new String[]{ "motivo", "id" }, + new Field( "data" ).isEqual( data ).and( + new Field( "trabalhador_id" ).isEqual( trabalhadorID ) ).and( + new Field( "tipo" ).isEqual( Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA ) ).and( + new Field( "realizada" ).isEqual( "y" ).or( + new Field( "estado" ).isEqual( new Integer( 2 ) ) ) ), + new String[]{ "id" }, null ); + array = executer.executeQuery( select ); + Integer tipo = ( Integer ) array.get( 0, 0 ); + if( tipo.intValue() == 5 ) + { + tipo = new Integer( 2 ); + } + return new Object[]{ data, tipo }; + } } diff --git a/trunk/siprp/ficha/ExamePanel.java b/trunk/siprp/ficha/ExamePanel.java index a5056a8d..af5f46d5 100644 --- a/trunk/siprp/ficha/ExamePanel.java +++ b/trunk/siprp/ficha/ExamePanel.java @@ -303,8 +303,14 @@ public class ExamePanel extends JPanel try { Integer marcacaoID = provider.getMarcacaoIDByTrabalhador( trabalhadorID ); + if( marcacaoID == null ) { + Object dadosMarcacao[] = provider.getDadosUltimaMarcacao( trabalhadorID ); + dataExamePanel.setDate( ( Date ) dadosMarcacao[ 0 ] ); + Integer tipo = ( Integer ) dadosMarcacao[ 1 ]; + int tipoValue = tipo != null ? tipo.intValue() : 0; + tipoGroup.setIntSelected( tipoValue > 0 ? tipoValue - 1 : 0 ); return; } marcacao = ( MarcacaoTrabalhadorData ) JDO.load( MarcacaoTrabalhadorData.class, marcacaoID );