forked from Coded/SIPRP
no message
git-svn-id: https://svn.coded.pt/svn/SIPRP@319 bb69d46d-e84e-40c8-a05a-06db0d6337410'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
parent
052556be6e
commit
ed616b3668
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* LocaisRealizacaoDataProvider.java
|
||||
*
|
||||
* Created on February 22, 2007, 10:44 AM
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package siprp.medicina.locais_realizacao;
|
||||
|
||||
import com.evolute.utils.Singleton;
|
||||
import com.evolute.utils.arrays.Virtual2DArray;
|
||||
import com.evolute.utils.db.DBManager;
|
||||
import com.evolute.utils.db.Executer;
|
||||
import com.evolute.utils.sql.Expression;
|
||||
import com.evolute.utils.sql.Field;
|
||||
import com.evolute.utils.sql.Select;
|
||||
import com.evolute.utils.sql.Select2;
|
||||
import com.evolute.utils.tables.ColumnizedMappable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fpalma
|
||||
*/
|
||||
public class LocaisRealizacaoDataProvider
|
||||
{
|
||||
private static final Object LOCK = new Object();
|
||||
private static LocaisRealizacaoDataProvider instance = null;
|
||||
|
||||
private Executer EXECUTER;
|
||||
|
||||
/** Creates a new instance of LocaisRealizacaoDataProvider */
|
||||
public LocaisRealizacaoDataProvider()
|
||||
throws Exception
|
||||
{
|
||||
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
|
||||
EXECUTER = dbm.getSharedExecuter( this );
|
||||
}
|
||||
|
||||
public static LocaisRealizacaoDataProvider getProvider()
|
||||
throws Exception
|
||||
{
|
||||
synchronized( LOCK )
|
||||
{
|
||||
if( instance == null )
|
||||
{
|
||||
instance = new LocaisRealizacaoDataProvider();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ColumnizedMappable[] getEmpresasComMarcacoes( Date data )
|
||||
throws Exception
|
||||
{
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos", "empresas" },
|
||||
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ),
|
||||
new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ),
|
||||
new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) },
|
||||
new String[]{ "DISTINCT empresas.id", "empresas.designacao_social", "empresas.designacao_social_plain" },
|
||||
new Field( "marcacoes_trabalhador.data" ).isEqual( data ),
|
||||
new String[]{ "empresas.designacao_social_plain" },
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
Virtual2DArray array = EXECUTER.executeQuery( select );
|
||||
ColumnizedMappable empresas[] = new ColumnizedMappable[ array.columnLength() ];
|
||||
for( int n = 0; n < empresas.length; n++ )
|
||||
{
|
||||
Integer id = ( Integer ) array.get( n, 0 );
|
||||
String designacao = ( String ) array.get( n, 1 );
|
||||
empresas[ n ] = new ColumnizedMappable( id, designacao );
|
||||
}
|
||||
return empresas;
|
||||
}
|
||||
|
||||
public ColumnizedMappable[] getEstabelecimentosComMarcacoesByEmpresa( Integer empresaID, Date data )
|
||||
throws Exception
|
||||
{
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos" },
|
||||
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ),
|
||||
new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) },
|
||||
new String[]{ "DISTINCT estabelecimentos.id", "estabelecimentos.nome", "estabelecimentos.nome_plain" },
|
||||
new Field( "marcacoes_trabalhador.data" ).isEqual( data ).and(
|
||||
new Field( "estabelecimentos.empresa_id" ).isEqual( empresaID ) ),
|
||||
new String[]{ "estabelecimentos.nome_plain" },
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
Virtual2DArray array = EXECUTER.executeQuery( select );
|
||||
ColumnizedMappable estabelecimentos[] = new ColumnizedMappable[ array.columnLength() ];
|
||||
for( int n = 0; n < estabelecimentos.length; n++ )
|
||||
{
|
||||
Integer id = ( Integer ) array.get( n, 0 );
|
||||
String nome = ( String ) array.get( n, 1 );
|
||||
estabelecimentos[ n ] = new ColumnizedMappable( id, nome );
|
||||
}
|
||||
return estabelecimentos;
|
||||
}
|
||||
|
||||
public int getNumeroMarcacoesByEstabelecimentoAndTipo( Integer estabelecimentoID, int tipo, Date data )
|
||||
throws Exception
|
||||
{
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "marcacoes_trabalhador", "trabalhadores" },
|
||||
new Integer[]{ Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
||||
new String[]{ "COUNT( * )" },
|
||||
new Field( "marcacoes_trabalhador.data" ).isEqual( data ).and(
|
||||
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and(
|
||||
new Field( "marcacoes_trabalhador.tipo" ).isEqual( tipo ) ),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
Virtual2DArray array = EXECUTER.executeQuery( select );
|
||||
if( array.columnLength() == 0 || array.get( 0, 0 ) == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( ( Number ) array.get( 0, 0 ) ).intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,342 @@
|
||||
/*
|
||||
* LocaisRealizacaoWindow.java
|
||||
*
|
||||
* Created on February 22, 2007, 10:19 AM
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package siprp.medicina.locais_realizacao;
|
||||
|
||||
import com.evolute.utils.data.IDObject;
|
||||
import com.evolute.utils.data.MappableObject;
|
||||
import com.evolute.utils.tables.BaseTable;
|
||||
import com.evolute.utils.tables.ColumnizedMappable;
|
||||
import com.evolute.utils.tables.VectorTableModel;
|
||||
import com.evolute.utils.tracker.TrackableWindow;
|
||||
import com.evolute.utils.ui.DialogException;
|
||||
import com.evolute.utils.ui.calendar.JCalendarPanel;
|
||||
import info.clearthought.layout.TableLayout;
|
||||
import info.clearthought.layout.TableLayoutConstraints;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.WindowConstants;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import siprp.data.Marcacao;
|
||||
import siprp.medicina.prestadores.PrestadoresDataProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fpalma
|
||||
*/
|
||||
public class LocaisRealizacaoWindow extends JFrame
|
||||
implements ActionListener, TrackableWindow, ListSelectionListener
|
||||
{
|
||||
protected static final Integer PRESTADOR_ID_SIPRP = new Integer( -1 );
|
||||
|
||||
protected static final IDObject PRESTADOR_SIPRP = new MappableObject( PRESTADOR_ID_SIPRP, "SIPRP" );
|
||||
|
||||
protected JCalendarPanel dataPanel;
|
||||
protected JButton carregarButton;
|
||||
protected JButton recarregarPrestadoresButton;
|
||||
protected VectorTableModel empresasModel;
|
||||
protected BaseTable empresasTable;
|
||||
protected VectorTableModel estabelecimentosModel;
|
||||
protected BaseTable estabelecimentosTable;
|
||||
protected JLabel numeroConsultasLabel;
|
||||
protected JComboBox prestadoresConsultasCombo;
|
||||
protected JButton enviarConsultasButton;
|
||||
protected JLabel numeroECDsLabel;
|
||||
protected JComboBox prestadoresECDsCombo;
|
||||
protected JButton enviarECDsButton;
|
||||
|
||||
|
||||
protected LocaisRealizacaoDataProvider provider;
|
||||
protected PrestadoresDataProvider prestadoresProvider;
|
||||
|
||||
/**
|
||||
* Creates a new instance of LocaisRealizacaoWindow
|
||||
*/
|
||||
public LocaisRealizacaoWindow()
|
||||
throws Exception
|
||||
{
|
||||
provider = LocaisRealizacaoDataProvider.getProvider();
|
||||
prestadoresProvider = PrestadoresDataProvider.getProvider();
|
||||
setupComponents();
|
||||
}
|
||||
|
||||
private void setupComponents()
|
||||
{
|
||||
setTitle( "Locais de Realiza\u00e7\u00e3o" );
|
||||
setSize( 1000, 700 );
|
||||
JLabel dataLabel = new JLabel( "Data" );
|
||||
dataPanel = new JCalendarPanel( this );
|
||||
carregarButton = new JButton( "Carregar" );
|
||||
carregarButton.addActionListener( this );
|
||||
recarregarPrestadoresButton = new JButton( "Recarregar Prestadores" );
|
||||
recarregarPrestadoresButton.addActionListener( this );
|
||||
empresasModel = new VectorTableModel( new String[]{ "empresa" } );
|
||||
empresasTable = new BaseTable( empresasModel );
|
||||
empresasTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
|
||||
empresasTable.getSelectionModel().addListSelectionListener( this );
|
||||
JScrollPane empresasScp = new JScrollPane( empresasTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||
estabelecimentosModel = new VectorTableModel( new String[]{ "estabelecimento" } );
|
||||
estabelecimentosTable = new BaseTable( estabelecimentosModel );
|
||||
estabelecimentosTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
|
||||
estabelecimentosTable.getSelectionModel().addListSelectionListener( this );
|
||||
JScrollPane estabelecimentosScp = new JScrollPane( estabelecimentosTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
||||
JLabel consultasLabel = new JLabel( "Consultas " );
|
||||
numeroConsultasLabel = new JLabel( " " );
|
||||
numeroConsultasLabel.setForeground( Color.green.darker() );
|
||||
prestadoresConsultasCombo = new JComboBox();
|
||||
enviarConsultasButton = new JButton( "Atribuir" );
|
||||
enviarConsultasButton.addActionListener( this );
|
||||
JLabel ecdsLabel = new JLabel( "ECDs " );
|
||||
numeroECDsLabel = new JLabel( " " );
|
||||
numeroECDsLabel.setForeground( Color.green.darker() );
|
||||
prestadoresECDsCombo = new JComboBox();
|
||||
enviarECDsButton = new JButton( "Atribuir" );
|
||||
enviarECDsButton.addActionListener( this );
|
||||
|
||||
getContentPane().setLayout( new BorderLayout( 5, 5 ) );
|
||||
JPanel upperPanel = new JPanel();
|
||||
getContentPane().add( upperPanel, BorderLayout.NORTH );
|
||||
JPanel centerPanel = new JPanel();
|
||||
getContentPane().add( centerPanel, BorderLayout.CENTER );
|
||||
|
||||
upperPanel.setLayout( new FlowLayout( FlowLayout.CENTER ) );
|
||||
upperPanel.add( dataLabel );
|
||||
upperPanel.add( dataPanel );
|
||||
upperPanel.add( carregarButton );
|
||||
upperPanel.add( recarregarPrestadoresButton );
|
||||
|
||||
centerPanel.setLayout( new GridLayout( 1, 3 ) );
|
||||
centerPanel.add( empresasScp );
|
||||
centerPanel.add( estabelecimentosScp );
|
||||
JPanel detalhesPanel = new JPanel();
|
||||
centerPanel.add( detalhesPanel );
|
||||
|
||||
double cols[] =
|
||||
new double[]{ TableLayout.MINIMUM, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.MINIMUM };
|
||||
double rows[] =
|
||||
new double[]{ TableLayout.FILL, TableLayout.MINIMUM, TableLayout.MINIMUM,
|
||||
TableLayout.FILL };
|
||||
TableLayout tableLayout = new TableLayout( cols,rows );
|
||||
detalhesPanel.setLayout( tableLayout );
|
||||
|
||||
detalhesPanel.add( consultasLabel, new TableLayoutConstraints( 0, 1 ) );
|
||||
detalhesPanel.add( numeroConsultasLabel, new TableLayoutConstraints( 1, 1 ) );
|
||||
detalhesPanel.add( prestadoresConsultasCombo, new TableLayoutConstraints( 2, 1 ) );
|
||||
detalhesPanel.add( enviarConsultasButton, new TableLayoutConstraints( 3, 1 ) );
|
||||
|
||||
detalhesPanel.add( ecdsLabel, new TableLayoutConstraints( 0, 2 ) );
|
||||
detalhesPanel.add( numeroECDsLabel, new TableLayoutConstraints( 1, 2 ) );
|
||||
detalhesPanel.add( prestadoresECDsCombo, new TableLayoutConstraints( 2, 2 ) );
|
||||
detalhesPanel.add( enviarECDsButton, new TableLayoutConstraints( 3, 2 ) );
|
||||
|
||||
setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
|
||||
addWindowListener( new WindowAdapter(){
|
||||
public void windowClosing( WindowEvent e )
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
public void windowOpened( WindowEvent e )
|
||||
{
|
||||
// setExtendedState( getExtendedState() | MAXIMIZED_BOTH );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
recarregarPrestadores();
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
}
|
||||
|
||||
public void open()
|
||||
{
|
||||
setVisible( true );
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
SwingUtilities.invokeLater( new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
setVisible( false );
|
||||
dispose();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
public boolean closeIfPossible()
|
||||
{
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
Object source = e.getSource();
|
||||
if( source.equals( carregarButton ) )
|
||||
{
|
||||
carregar();
|
||||
}
|
||||
else if( source.equals( recarregarPrestadoresButton ) )
|
||||
{
|
||||
recarregarPrestadores();
|
||||
}
|
||||
}
|
||||
|
||||
public void valueChanged(ListSelectionEvent e)
|
||||
{
|
||||
Object source = e.getSource();
|
||||
if( e.getValueIsAdjusting() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if( source.equals( empresasTable.getSelectionModel() ) )
|
||||
{
|
||||
mudarEmpresa();
|
||||
}
|
||||
else if( source.equals( estabelecimentosTable.getSelectionModel() ) )
|
||||
{
|
||||
mudarEstabelecimento();
|
||||
}
|
||||
}
|
||||
|
||||
protected void carregar()
|
||||
{
|
||||
empresasTable.clearSelection();
|
||||
Date data = dataPanel.getDate();
|
||||
if( data == null )
|
||||
{
|
||||
empresasModel.clearAll();
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
ColumnizedMappable empresas[] = provider.getEmpresasComMarcacoes( data );
|
||||
Vector values = empresasModel.getValues();
|
||||
values.clear();
|
||||
values.addAll( Arrays.asList( empresas ) );
|
||||
empresasModel.setValues( values );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
DialogException.showExceptionMessage( ex, "Erro a carregar empresas", true );
|
||||
}
|
||||
}
|
||||
|
||||
protected void mudarEmpresa()
|
||||
{
|
||||
estabelecimentosTable.clearSelection();
|
||||
Date data = dataPanel.getDate();
|
||||
int selected = empresasTable.getSelectedRow();
|
||||
if( data == null || selected == -1 )
|
||||
{
|
||||
estabelecimentosModel.clearAll();
|
||||
return;
|
||||
}
|
||||
Integer empresaID = ( ( ColumnizedMappable ) empresasModel.getRowAt( selected ) ).getID();
|
||||
try
|
||||
{
|
||||
ColumnizedMappable estabelecimentos[] =
|
||||
provider.getEstabelecimentosComMarcacoesByEmpresa( empresaID, data );
|
||||
Vector values = estabelecimentosModel.getValues();
|
||||
values.clear();
|
||||
values.addAll( Arrays.asList( estabelecimentos ) );
|
||||
estabelecimentosModel.setValues( values );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
DialogException.showExceptionMessage( ex, "Erro a carregar estabelecimentos", true );
|
||||
}
|
||||
}
|
||||
|
||||
protected void mudarEstabelecimento()
|
||||
{
|
||||
Date data = dataPanel.getDate();
|
||||
int selectedEstabelecimento = estabelecimentosTable.getSelectedRow();
|
||||
numeroConsultasLabel.setText( " " );
|
||||
numeroECDsLabel.setText( " " );
|
||||
enviarConsultasButton.setEnabled( false );
|
||||
enviarECDsButton.setEnabled( false );
|
||||
if( data == null || selectedEstabelecimento == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Integer estabelecimentoID = ( ( ColumnizedMappable ) estabelecimentosModel.getRowAt( selectedEstabelecimento ) ).getID();
|
||||
try
|
||||
{
|
||||
int countConsultas =
|
||||
provider.getNumeroMarcacoesByEstabelecimentoAndTipo( estabelecimentoID,
|
||||
Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA, data );
|
||||
int countECDs =
|
||||
provider.getNumeroMarcacoesByEstabelecimentoAndTipo( estabelecimentoID,
|
||||
Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES, data );
|
||||
if( countConsultas > 0 )
|
||||
{
|
||||
numeroConsultasLabel.setText( "" + countConsultas );
|
||||
enviarConsultasButton.setEnabled( true );
|
||||
}
|
||||
if( countECDs > 0 )
|
||||
{
|
||||
numeroECDsLabel.setText( "" + countECDs );
|
||||
enviarECDsButton.setEnabled( true );
|
||||
}
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
DialogException.showExceptionMessage( ex, "Erro a carregar detalhes", true );
|
||||
}
|
||||
}
|
||||
|
||||
protected void recarregarPrestadores()
|
||||
{
|
||||
try
|
||||
{
|
||||
IDObject prestadoresConsultas[] = prestadoresProvider.getPrestadoresConsultasActivos();
|
||||
IDObject prestadoresECDs[] = prestadoresProvider.getPrestadoresECDsActivos();
|
||||
prestadoresConsultasCombo.removeAllItems();
|
||||
prestadoresConsultasCombo.addItem( PRESTADOR_SIPRP );
|
||||
for( int n = 0; n < prestadoresConsultas.length; n++ )
|
||||
{
|
||||
prestadoresConsultasCombo.addItem( prestadoresConsultas[ n ] );
|
||||
}
|
||||
prestadoresECDsCombo.removeAllItems();
|
||||
prestadoresECDsCombo.addItem( PRESTADOR_SIPRP );
|
||||
for( int n = 0; n < prestadoresECDs.length; n++ )
|
||||
{
|
||||
prestadoresECDsCombo.addItem( prestadoresECDs[ n ] );
|
||||
}
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
DialogException.showExceptionMessage( ex, "Erro a carregar prestadores", true );
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue