forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
438 lines
14 KiB
438 lines
14 KiB
/*
|
|
* ExamePanel.java
|
|
*
|
|
* Created on 29 de Março de 2004, 11:57
|
|
*/
|
|
|
|
package siprp.ficha;
|
|
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import java.io.*;
|
|
import javax.swing.*;
|
|
import javax.swing.event.*;
|
|
import java.util.*;
|
|
|
|
import com.evolute.utils.documents.*;
|
|
import com.evolute.utils.data.*;
|
|
import com.evolute.utils.dataui.*;
|
|
import com.evolute.utils.metadb.*;
|
|
import com.evolute.utils.ui.*;
|
|
import com.evolute.utils.ui.button.*;
|
|
import com.evolute.utils.ui.panel.*;
|
|
|
|
import siprp.*;
|
|
import siprp.data.*;
|
|
/**
|
|
*
|
|
* @author fpalma
|
|
*/
|
|
public class ExamePanel extends JPanel
|
|
implements ChangeListener, ControllableComponent
|
|
{
|
|
private JCalendarPanel dataExamePanel;
|
|
private BetterButtonGroup tipoGroup;
|
|
private JRadioButton admissaoRadio;
|
|
private JRadioButton periodicoRadio;
|
|
private JRadioButton ocasionalRadio;
|
|
private JRadioButton outroRadio;
|
|
private RadioButtonFixedPanel ocasionalPanel;
|
|
private JTextField especificarText;
|
|
private JCalendarPanel proximoExamePanel;
|
|
private RadioButtonFixedPanel resultadoPanel;
|
|
private JTextField outrasFuncoesTexts[];
|
|
private JTextArea recomendacoesText;
|
|
|
|
private FichaDataProvider provider;
|
|
private ComponentsHashtable components;
|
|
|
|
private Integer trabalhadorID;
|
|
private MarcacaoTrabalhador marcacao;
|
|
|
|
/** Creates a new instance of ExamePanel */
|
|
public ExamePanel()
|
|
throws Exception
|
|
{
|
|
provider = (FichaDataProvider)FichaDataProvider.getProvider();
|
|
setupComponents();
|
|
setupComponentsHashtable();
|
|
}
|
|
|
|
private void setupComponents()
|
|
{
|
|
setBorder( BorderFactory.createTitledBorder(
|
|
BorderFactory.createEtchedBorder(),
|
|
"Exame M\u00e9dico" ) );
|
|
|
|
JPanel leftPanel = new JPanel();
|
|
JPanel rightPanel = new JPanel();
|
|
JPanel dataExameOuterPanel = new JPanel();
|
|
JLabel dataExameLabel = new JLabel( "Data do Exame" );
|
|
dataExamePanel = new JCalendarPanel( null );
|
|
JPanel tipoPanel = new JPanel();
|
|
tipoPanel.setBorder( BorderFactory.createTitledBorder(
|
|
BorderFactory.createEtchedBorder(), "Tipo" ) );
|
|
tipoGroup = new BetterButtonGroup( false );
|
|
admissaoRadio = new JRadioButton( "Admiss\u00e3o" );
|
|
tipoGroup.add( admissaoRadio );
|
|
periodicoRadio = new JRadioButton( "Peri\u00f3dico" );
|
|
tipoGroup.add( periodicoRadio );
|
|
ocasionalRadio = new JRadioButton( "Ocasional" );
|
|
tipoGroup.add( ocasionalRadio );
|
|
ocasionalRadio.addChangeListener( this );
|
|
outroRadio = new JRadioButton( "Outro" );
|
|
tipoGroup.add( outroRadio );
|
|
outroRadio.addChangeListener( this );
|
|
ocasionalPanel = new RadioButtonFixedPanel(
|
|
new IDObject[]{ new MappableObject( new Integer( 1 ), "Ap\u00f3s doen\u00e7a" ),
|
|
new MappableObject( new Integer( 2 ), "Ap\u00f3s acidente" ),
|
|
new MappableObject( new Integer( 3 ), "A pedido do trabalhador" ),
|
|
new MappableObject( new Integer( 4 ), "A pedido do servi\u00e7o" ),
|
|
new MappableObject( new Integer( 5 ), "Por mudan\u00e7a de fun\u00e7\u00e3o" ),
|
|
new MappableObject( new Integer( 6 ), "Por altera\u00e7\u00e3o das condi\u00e7\u00f5es de trabalho" ) },
|
|
false );
|
|
ocasionalPanel.setEnabled( false );
|
|
especificarText = new JTextField();
|
|
especificarText.setEnabled( false );
|
|
JPanel proximoExameOuterPanel = new JPanel();
|
|
JLabel proximoExameLabel = new JLabel( "Pr\u00f3ximo Exame" );
|
|
proximoExamePanel = new JCalendarPanel( null );
|
|
JPanel resultadoOuterPanel = new JPanel();
|
|
resultadoOuterPanel.setBorder( BorderFactory.createTitledBorder(
|
|
BorderFactory.createEtchedBorder(), "Resultado" ) );
|
|
resultadoPanel = new RadioButtonFixedPanel(
|
|
new IDObject[]{ new MappableObject( new Integer( 1 ), "Apto" ),
|
|
new MappableObject( new Integer( 2 ), "Apto condicionalmente" ),
|
|
new MappableObject( new Integer( 3 ), "Inapto temporariamente" ),
|
|
new MappableObject( new Integer( 4 ), "Inapto definitivamente" ) },
|
|
false );
|
|
JLabel outrasFuncoesLabel = new JLabel( "Outras fun\u00e7\u00f5es que pode desempenhar", JLabel.CENTER );
|
|
JPanel outrasFuncoesPanel = new JPanel();
|
|
JLabel outrasFuncoesLabels[] = new JLabel[ 4 ];
|
|
outrasFuncoesTexts = new JTextField[ 4 ];
|
|
for( int n = 0; n < 4; n++ )
|
|
{
|
|
outrasFuncoesLabels[ n ] = new JLabel( "" + ( n + 1 ) );
|
|
outrasFuncoesTexts[ n ] = new JTextField();
|
|
}
|
|
JScrollPane recomendacoesScp = new JScrollPane();
|
|
recomendacoesScp.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
|
|
recomendacoesScp.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
|
|
recomendacoesText = new JTextArea();
|
|
recomendacoesText.setLineWrap( true );
|
|
recomendacoesText.setWrapStyleWord( true );
|
|
recomendacoesText.setDocument( new MaximumLengthDocument( 300 ) );
|
|
recomendacoesScp.setViewportView( recomendacoesText );
|
|
recomendacoesScp.setBorder( BorderFactory.createTitledBorder(
|
|
BorderFactory.createEtchedBorder(),
|
|
"Outras recomenda\u00e7\u00f5es" ) );
|
|
|
|
setLayout( new GridLayout( 1, 2 ) );
|
|
add( leftPanel );
|
|
add( rightPanel );
|
|
|
|
leftPanel.setLayout( new BorderLayout() );
|
|
|
|
dataExameOuterPanel.setLayout( new BorderLayout() );
|
|
dataExameOuterPanel.add( dataExameLabel, BorderLayout.WEST );
|
|
dataExameOuterPanel.add( dataExamePanel, BorderLayout.CENTER );
|
|
leftPanel.add( dataExameOuterPanel, BorderLayout.NORTH );
|
|
leftPanel.add( tipoPanel, BorderLayout.CENTER );
|
|
proximoExameOuterPanel.setLayout( new BorderLayout() );
|
|
proximoExameOuterPanel.add( proximoExameLabel, BorderLayout.WEST );
|
|
proximoExameOuterPanel.add( proximoExamePanel, BorderLayout.CENTER );
|
|
leftPanel.add( proximoExameOuterPanel, BorderLayout.SOUTH );
|
|
|
|
GridBagLayout gridbag = new GridBagLayout();
|
|
tipoPanel.setLayout( gridbag );
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
constraints.insets = new Insets( 0, 1, 0, 1 );
|
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
constraints.weighty = 0;
|
|
constraints.gridheight = 1;
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
|
gridbag.setConstraints( admissaoRadio, constraints );
|
|
tipoPanel.add( admissaoRadio );
|
|
|
|
gridbag.setConstraints( periodicoRadio, constraints );
|
|
tipoPanel.add( periodicoRadio );
|
|
|
|
gridbag.setConstraints( ocasionalRadio, constraints );
|
|
tipoPanel.add( ocasionalRadio );
|
|
|
|
constraints.weightx = 0.1;
|
|
constraints.gridwidth = 1;
|
|
JPanel pad = new JPanel();
|
|
gridbag.setConstraints( pad, constraints );
|
|
tipoPanel.add( pad );
|
|
|
|
constraints.weightx = 0.9;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( ocasionalPanel, constraints );
|
|
tipoPanel.add( ocasionalPanel );
|
|
|
|
constraints.weightx = 0;
|
|
constraints.gridwidth = 1;
|
|
gridbag.setConstraints( outroRadio, constraints );
|
|
tipoPanel.add( outroRadio );
|
|
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( especificarText, constraints );
|
|
tipoPanel.add( especificarText );
|
|
|
|
|
|
gridbag = new GridBagLayout();
|
|
rightPanel.setLayout( gridbag );
|
|
constraints.fill = GridBagConstraints.BOTH;
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
constraints.gridheight = 1;
|
|
constraints.weighty = 0;
|
|
|
|
gridbag.setConstraints( resultadoOuterPanel, constraints );
|
|
rightPanel.add( resultadoOuterPanel );
|
|
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
//constraints.gridheight = GridBagConstraints.REMAINDER;
|
|
constraints.weighty = 1;
|
|
// JPanel recomendacoesOuterPanel = new JPanel();
|
|
// recomendacoesOuterPanel.setLayout( new GridLayout( 1, 1 ) );
|
|
// recomendacoesOuterPanel.add( recomendacoesScp );
|
|
gridbag.setConstraints( recomendacoesScp, constraints );
|
|
rightPanel.add( recomendacoesScp );
|
|
|
|
gridbag = new GridBagLayout();
|
|
resultadoOuterPanel.setLayout( gridbag );
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
constraints.gridheight = 1;
|
|
constraints.weighty = 0;
|
|
|
|
gridbag.setConstraints( resultadoPanel, constraints );
|
|
resultadoOuterPanel.add( resultadoPanel );
|
|
|
|
gridbag.setConstraints( outrasFuncoesLabel, constraints );
|
|
resultadoOuterPanel.add( outrasFuncoesLabel );
|
|
|
|
gridbag.setConstraints( outrasFuncoesPanel, constraints );
|
|
resultadoOuterPanel.add( outrasFuncoesPanel );
|
|
|
|
for( int n = 0; n < outrasFuncoesTexts.length; n++ )
|
|
{
|
|
constraints.weightx = 0.1;
|
|
constraints.gridwidth = 1;
|
|
pad = new JPanel();
|
|
gridbag.setConstraints( pad, constraints );
|
|
resultadoOuterPanel.add( pad );
|
|
|
|
constraints.weightx = 0;
|
|
gridbag.setConstraints( outrasFuncoesLabels[ n ], constraints );
|
|
resultadoOuterPanel.add( outrasFuncoesLabels[ n ] );
|
|
|
|
constraints.weightx = 1;
|
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
gridbag.setConstraints( outrasFuncoesTexts[ n ], constraints );
|
|
resultadoOuterPanel.add( outrasFuncoesTexts[ n ] );
|
|
}
|
|
}
|
|
|
|
private void setupComponentsHashtable()
|
|
{
|
|
components = new ComponentsHashtable();
|
|
components.putDummy( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.TIPO );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.DATA, dataExamePanel );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.OCASIONAL, ocasionalPanel );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.OUTRO_TIPO, especificarText );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.PROXIMO_EXAME, proximoExamePanel );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.RESULTADO, resultadoPanel );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.OUTRA_FUNCAO_1, outrasFuncoesTexts[ 0 ] );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.OUTRA_FUNCAO_2, outrasFuncoesTexts[ 1 ] );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.OUTRA_FUNCAO_3, outrasFuncoesTexts[ 2 ] );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.OUTRA_FUNCAO_4, outrasFuncoesTexts[ 3 ] );
|
|
components.putComponent( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.OUTRAS_RECOMENDACOES, recomendacoesText );
|
|
components.putDummy( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.TRABALHADOR_ID );
|
|
components.putDummy( FichaDataProvider.T_EXAMES + "." + FichaDataProvider.MEDICO_ID );
|
|
}
|
|
|
|
public void stateChanged( ChangeEvent e )
|
|
{
|
|
if( e.getSource().equals( ocasionalRadio ) )
|
|
{
|
|
ocasionalPanel.setEnabled( ocasionalRadio.isSelected() && ocasionalRadio.isEnabled() ) ;
|
|
}
|
|
else if( e.getSource().equals( outroRadio ) )
|
|
{
|
|
especificarText.setEnabled( outroRadio.isSelected() && outroRadio.isEnabled() ) ;
|
|
}
|
|
}
|
|
|
|
public void fill( Object value )
|
|
{
|
|
clear();
|
|
trabalhadorID = ( Integer ) value;
|
|
if( trabalhadorID == null )
|
|
{
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
Integer marcacaoID = provider.getMarcacaoIDByTrabalhador( trabalhadorID );
|
|
if( marcacaoID == null )
|
|
{
|
|
return;
|
|
}
|
|
marcacao = ( MarcacaoTrabalhador ) MarcacaoTrabalhador.load( MarcacaoTrabalhador.class, marcacaoID );
|
|
proximoExamePanel.setDate( (Date) marcacao.get( Marcacao.DATA ) );
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
ex.printStackTrace();
|
|
return;
|
|
}
|
|
|
|
// Integer trabID = (Integer) value;
|
|
// if( trabID == null )
|
|
// {
|
|
// return;
|
|
// }
|
|
// try
|
|
// {
|
|
// Integer id = provider.getLastExameIDForTrabalhador( trabID );
|
|
// if( id == null )
|
|
// {
|
|
// return;
|
|
// }
|
|
// MetaObject exame = provider.load( provider.EXAMES, new DBKey( id ) );
|
|
// byte pdf[] = (byte []) exame.getProperty( provider.PDF );
|
|
// if( pdf != null )
|
|
// {
|
|
// FileOutputStream fos = new FileOutputStream( "C:\\teste.pdf" );
|
|
// fos.write( pdf );
|
|
// fos.close();
|
|
// }
|
|
// }
|
|
// catch( Exception ex )
|
|
// {
|
|
// ex.printStackTrace();
|
|
// return;
|
|
// }
|
|
}
|
|
|
|
public Object save()
|
|
{
|
|
StringBuffer msg = new StringBuffer();
|
|
boolean hasMsg = false;
|
|
boolean hasData = false;
|
|
MetaObject exame;
|
|
if( dataExamePanel.getDate().after( new Date() ) )
|
|
{
|
|
throw new ValuesException( "N\u00E3o \u00E9 poss\u00EDvel gravar exames com datas futuras." );
|
|
}
|
|
try
|
|
{
|
|
String recomendacoes = recomendacoesText.getText();
|
|
String linhas[] = recomendacoes.split( "\\n" );
|
|
Vector linhasV = new Vector();
|
|
for( int n = 0; n < linhas.length; n++ )
|
|
{
|
|
if( linhas[ n ].trim().length() > 0 )
|
|
{
|
|
linhasV.add( linhas[ n ] );
|
|
}
|
|
}
|
|
if( linhasV.size() > 0 )
|
|
{
|
|
linhas = ( String[] ) linhasV.toArray( new String[0] );
|
|
boolean compress = false;
|
|
if( linhas.length == 2 )
|
|
{
|
|
linhas[ 0 ] += " ";
|
|
}
|
|
recomendacoes = "";
|
|
for( int n = 0; n < linhas.length; n++ )
|
|
{
|
|
recomendacoes += linhas[ n ];
|
|
}
|
|
}
|
|
recomendacoesText.setText( recomendacoes.trim() );
|
|
|
|
exame = provider.createObject( FichaDataProvider.EXAMES );
|
|
DBField fields[] = FichaDataProvider.EXAMES.getInsertFields();
|
|
String exameFields[] = new String[ fields.length ];
|
|
for( int i = 0; i < exameFields.length; ++i )
|
|
{
|
|
exameFields[ i ] = fields[ i ].FULL_NAME;
|
|
}
|
|
Hashtable hash = new Hashtable();
|
|
ComponentController.save( exameFields, hash, components );
|
|
Enumeration enum = hash.keys();
|
|
while( enum.hasMoreElements() )
|
|
{
|
|
String name = ( String )enum.nextElement();
|
|
exame.setProperty( name, hash.get( name ) );
|
|
}
|
|
int tipo = 0;
|
|
if( admissaoRadio.isSelected() )
|
|
{
|
|
tipo = 1;
|
|
}
|
|
else if( periodicoRadio.isSelected() )
|
|
{
|
|
tipo = 2;
|
|
}
|
|
else if( ocasionalRadio.isSelected() )
|
|
{
|
|
tipo = 3;
|
|
}
|
|
else if( outroRadio.isSelected() )
|
|
{
|
|
tipo = 4;
|
|
}
|
|
exame.setProperty( FichaDataProvider.TIPO, new Integer( tipo ) );
|
|
if( tipo != 3 )
|
|
{
|
|
exame.setProperty( FichaDataProvider.EXAMES.getFieldByName( FichaDataProvider.OCASIONAL ).FULL_NAME, null );
|
|
}
|
|
if( tipo != 4 )
|
|
{
|
|
exame.setProperty( FichaDataProvider.EXAMES.getFieldByName( FichaDataProvider.OUTRO_TIPO ).FULL_NAME, "" );
|
|
}
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
ex.printStackTrace();
|
|
return null;
|
|
}
|
|
if( hasMsg )
|
|
{
|
|
throw new ValuesException( msg.toString() );
|
|
}
|
|
return exame;
|
|
}
|
|
|
|
public void clear()
|
|
{
|
|
String names[] = (String[])components.keySet().toArray( new String[0] );
|
|
ComponentController.clear( names, components );
|
|
tipoGroup.setIntSelected( 0 );
|
|
dataExamePanel.setDate( new Date() );
|
|
marcacao = null;
|
|
}
|
|
|
|
public void setEnabled( boolean enable )
|
|
{
|
|
String names[] = (String[])components.keySet().toArray( new String[0] );
|
|
ComponentController.setEnabled( names, enable, components );
|
|
admissaoRadio.setEnabled( enable );
|
|
periodicoRadio.setEnabled( enable );
|
|
ocasionalRadio.setEnabled( enable );
|
|
outroRadio.setEnabled( enable );
|
|
ocasionalPanel.setEnabled( ocasionalRadio.isSelected() && ocasionalRadio.isEnabled() ) ;
|
|
especificarText.setEnabled( outroRadio.isSelected() && outroRadio.isEnabled() );
|
|
}
|
|
}
|