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.
		
		
		
		
		
			
		
			
				
					
					
						
							406 lines
						
					
					
						
							9.8 KiB
						
					
					
				
			
		
		
	
	
							406 lines
						
					
					
						
							9.8 KiB
						
					
					
				 /*
 | 
						|
 * ProcessoController.java
 | 
						|
 *
 | 
						|
 * Created on 25 de Abril de 2007, 15:10
 | 
						|
 *
 | 
						|
 * To change this template, choose Tools | Template Manager
 | 
						|
 * and open the template in the editor.
 | 
						|
 */
 | 
						|
 | 
						|
package siprp.medicina.processo;
 | 
						|
 | 
						|
import com.evolute.utils.Singleton;
 | 
						|
import com.evolute.utils.data.MappableObject;
 | 
						|
import com.evolute.utils.jdo.JDOProvider;
 | 
						|
import com.evolute.utils.ui.DialogException;
 | 
						|
import javax.swing.event.ListSelectionEvent;
 | 
						|
import javax.swing.event.ListSelectionListener;
 | 
						|
import siprp.data.TrabalhadorData;
 | 
						|
import siprp.medicina.processo.detalhes.DetalhesProcessoPanel;
 | 
						|
import siprp.medicina.processo.estrutura.EstruturaProcessoPanel;
 | 
						|
 | 
						|
/**
 | 
						|
 *
 | 
						|
 * @author Frederico
 | 
						|
 */
 | 
						|
public class ProcessoController 
 | 
						|
	implements ProcessoListener, ListSelectionListener
 | 
						|
{
 | 
						|
	protected ProcessoUpperPanel processoUpperPanel;
 | 
						|
	protected EstruturaProcessoPanel estruturaProcessoPanel;
 | 
						|
	protected ProcessoPanel processoPanel;
 | 
						|
	protected DetalhesProcessoPanel detalhesProcessoPanel;
 | 
						|
	protected ProcessoDataProvider provider;
 | 
						|
	
 | 
						|
	protected JDOProvider JDO;
 | 
						|
	
 | 
						|
	protected Integer idProcesso;
 | 
						|
	protected Integer idMarcacao;
 | 
						|
	protected Integer idData;
 | 
						|
		
 | 
						|
	/** Creates a new instance of ProcessoController */
 | 
						|
	public ProcessoController( ProcessoUpperPanel processoUpperPanel, EstruturaProcessoPanel estruturaProcessoPanel, 
 | 
						|
								ProcessoPanel processoPanel, DetalhesProcessoPanel detalhesProcessoPanel )
 | 
						|
			throws Exception
 | 
						|
	{
 | 
						|
		this.processoUpperPanel = processoUpperPanel;
 | 
						|
		this.estruturaProcessoPanel = estruturaProcessoPanel;
 | 
						|
		this.processoPanel = processoPanel;
 | 
						|
		this.detalhesProcessoPanel = detalhesProcessoPanel;
 | 
						|
		processoUpperPanel.addListSelectionListener( this );
 | 
						|
		estruturaProcessoPanel.addProcessoListener( this );
 | 
						|
		processoPanel.addProcessoListener( this );
 | 
						|
		detalhesProcessoPanel.addProcessoListener( this );
 | 
						|
		
 | 
						|
		provider = ProcessoDataProvider.getProvider();
 | 
						|
		JDO = ( JDOProvider ) Singleton.getInstance( Singleton.DEFAULT_JDO_PROVIDER );
 | 
						|
	}
 | 
						|
 | 
						|
	public void processoStateChanged(ProcessoEvent e)
 | 
						|
	{
 | 
						|
		int accao = e.getAccao();
 | 
						|
		switch( accao )
 | 
						|
		{
 | 
						|
			case ProcessoEvent.ACCAO_RECARREGAR_TRABALHADOR:
 | 
						|
				recarregarTrabalhador( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_PROCESSO:
 | 
						|
				escolherProcesso( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_CONSULTA:
 | 
						|
				escolherConsulta( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_ECDS:
 | 
						|
				escolherECDs( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_FA:
 | 
						|
				escolherFichaAptidao( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_DATA:
 | 
						|
				escolherData( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_OBSERVACOES:
 | 
						|
				escolherObservacoes( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_MAIL:
 | 
						|
				escolherMail( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCOLHER_MOTIVO:
 | 
						|
				escolherMotivo( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_MARCAR_CONSULTA:
 | 
						|
				marcarConsulta( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_MARCAR_ECDS:
 | 
						|
				marcarECDs( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_EMITIR_FA:
 | 
						|
				emitirFichaAptidao( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_FECHAR:
 | 
						|
				fecharProcesso( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_MUDAR_ESTADO_MARCACAO:
 | 
						|
				mudarEstadoMarcacao( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_MUDAR_DATA_MARCACAO:
 | 
						|
				mudarDataMarcacao( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCREVER_OBSERVACOES:
 | 
						|
				escreverObservacoes( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
			case ProcessoEvent.ACCAO_ESCREVER_MAIL:
 | 
						|
				escreverMail( e );
 | 
						|
				break;
 | 
						|
				
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void recarregarTrabalhador( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		idProcesso = null;
 | 
						|
		estruturaProcessoPanel.reload();
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherProcesso( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			processoPanel.fill( idProcesso );
 | 
						|
			detalhesProcessoPanel.setProcessoID( idProcesso );
 | 
						|
			detalhesProcessoPanel.clear();
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherConsulta( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			Integer idProcessoAntigo = idProcesso;
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			processoPanel.fill( idProcesso );
 | 
						|
			detalhesProcessoPanel.setProcessoID( idProcesso );
 | 
						|
			idMarcacao = e.getObjecto( ProcessoEvent.TIPO_CONSULTA );
 | 
						|
			detalhesProcessoPanel.setConsulta( idMarcacao );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherECDs( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			Integer idProcessoAntigo = idProcesso;
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			processoPanel.fill( idProcesso );
 | 
						|
			detalhesProcessoPanel.setProcessoID( idProcesso );
 | 
						|
 | 
						|
			idMarcacao = e.getObjecto( ProcessoEvent.TIPO_ECDS );
 | 
						|
			detalhesProcessoPanel.setECDs( idMarcacao );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherFichaAptidao( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			Integer idFichaAptidao = e.getObjecto( ProcessoEvent.TIPO_FICHA_APTIDAO );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherData( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			Integer idProcessoAntigo = idProcesso;
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			processoPanel.fill( idProcesso );
 | 
						|
			detalhesProcessoPanel.setProcessoID( idProcesso );
 | 
						|
			Integer idConsulta = e.getObjecto( ProcessoEvent.TIPO_CONSULTA );
 | 
						|
			Integer idECDs = e.getObjecto( ProcessoEvent.TIPO_ECDS );
 | 
						|
			Integer idData = e.getObjecto( ProcessoEvent.TIPO_DATA );
 | 
						|
			if( idConsulta != null )
 | 
						|
			{
 | 
						|
				idMarcacao = idConsulta;
 | 
						|
				detalhesProcessoPanel.setConsulta( idConsulta );
 | 
						|
			}
 | 
						|
			else if( idECDs != null )
 | 
						|
			{
 | 
						|
				idMarcacao = idECDs;
 | 
						|
				detalhesProcessoPanel.setECDs( idECDs );
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				idMarcacao = null;
 | 
						|
				detalhesProcessoPanel.clear();
 | 
						|
			}
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherObservacoes( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			escolherData( e );
 | 
						|
			Integer idObservacoes = e.getObjecto( ProcessoEvent.TIPO_OBSERVACOES );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherMail( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			escolherData( e );
 | 
						|
			Integer idMail = e.getObjecto( ProcessoEvent.TIPO_MAIL );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escolherMotivo( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			estruturaProcessoPanel.actualizarProcessoEscolhido( idProcesso );
 | 
						|
			detalhesProcessoPanel.setProcessoID( idProcesso );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
			DialogException.showExceptionMessage( ex, "Erro a actualizar dados", true );
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void marcarConsulta( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			detalhesProcessoPanel.setConsulta( null );
 | 
						|
			
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void marcarECDs( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			detalhesProcessoPanel.setECDs( null );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void emitirFichaAptidao( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			estruturaProcessoPanel.actualizarProcessoEscolhido( idProcesso );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void fecharProcesso( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			estruturaProcessoPanel.actualizarProcessoEscolhido( idProcesso );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void mudarEstadoMarcacao( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			Integer idConsulta = e.getObjecto( ProcessoEvent.TIPO_CONSULTA );
 | 
						|
			Integer idECDs = e.getObjecto( ProcessoEvent.TIPO_ECDS );
 | 
						|
			idMarcacao = idConsulta != null ? idConsulta : idECDs;
 | 
						|
			estruturaProcessoPanel.actualizarMarcacaoEscolhida( idProcesso, idMarcacao );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void mudarDataMarcacao( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			Integer idConsulta = e.getObjecto( ProcessoEvent.TIPO_CONSULTA );
 | 
						|
			Integer idECDs = e.getObjecto( ProcessoEvent.TIPO_ECDS );
 | 
						|
			idMarcacao = idConsulta != null ? idConsulta : idECDs;
 | 
						|
			estruturaProcessoPanel.actualizarMarcacaoEscolhida( idProcesso, idMarcacao );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escreverObservacoes( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			Integer idConsulta = e.getObjecto( ProcessoEvent.TIPO_CONSULTA );
 | 
						|
			Integer idECDs = e.getObjecto( ProcessoEvent.TIPO_ECDS );
 | 
						|
			idMarcacao = idConsulta != null ? idConsulta : idECDs;
 | 
						|
			estruturaProcessoPanel.actualizarMarcacaoEscolhida( idProcesso, idMarcacao );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	public void escreverMail( ProcessoEvent e )
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			idProcesso = e.getObjecto( ProcessoEvent.TIPO_PROCESSO );
 | 
						|
			Integer idConsulta = e.getObjecto( ProcessoEvent.TIPO_CONSULTA );
 | 
						|
			Integer idECDs = e.getObjecto( ProcessoEvent.TIPO_ECDS );
 | 
						|
			idMarcacao = idConsulta != null ? idConsulta : idECDs;
 | 
						|
			estruturaProcessoPanel.actualizarMarcacaoEscolhida( idProcesso, idMarcacao );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	public void valueChanged(ListSelectionEvent e)
 | 
						|
	{
 | 
						|
		try
 | 
						|
		{
 | 
						|
			Integer ids[] = ( Integer [] ) processoUpperPanel.save();
 | 
						|
			Integer trabalhadorID = ids[ 2 ];
 | 
						|
			processoPanel.setTrabalhadorID( trabalhadorID );
 | 
						|
			if( trabalhadorID != null )
 | 
						|
			{
 | 
						|
				TrabalhadorData trabalhador = ( TrabalhadorData ) JDO.load( TrabalhadorData.class, trabalhadorID );
 | 
						|
				estruturaProcessoPanel.setTrabalhador( new MappableObject( trabalhadorID, trabalhador.get( TrabalhadorData.NOME ) ) );
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				estruturaProcessoPanel.clear();
 | 
						|
			}
 | 
						|
			processoPanel.clear();
 | 
						|
			detalhesProcessoPanel.clear();
 | 
						|
			processoPanel.setTrabalhadorID( trabalhadorID );
 | 
						|
			detalhesProcessoPanel.setTrabalhadorID( trabalhadorID );
 | 
						|
		}
 | 
						|
		catch( Exception ex )
 | 
						|
		{
 | 
						|
			DialogException.showExceptionMessage( ex, "Erro a carregar trabalhador", true );
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |