@ -13,8 +13,10 @@ import java.awt.Component;
 
			
		
	
		
			
				
					import  java.awt.Dimension ;  
			
		
	
		
			
				
					import  java.awt.event.ActionEvent ;  
			
		
	
		
			
				
					import  java.awt.event.ActionListener ;  
			
		
	
		
			
				
					import  java.text.SimpleDateFormat ;  
			
		
	
		
			
				
					import  java.util.Date ;  
			
		
	
		
			
				
					import  java.util.EventObject ;  
			
		
	
		
			
				
					import  java.util.List ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					import  javax.swing.BorderFactory ;  
			
		
	
		
			
				
					import  javax.swing.ButtonGroup ;  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -31,10 +33,12 @@ import javax.swing.event.ChangeListener;
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					import  leaf.ui.LeafError ;  
			
		
	
		
			
				
					import  leaf.ui.LeafIconButton ;  
			
		
	
		
			
				
					import  siprp.database.cayenne.objects.HsEmailEstabelecimento ;  
			
		
	
		
			
				
					import  siprp.database.cayenne.objects.HsRelatorio ;  
			
		
	
		
			
				
					import  siprp.database.cayenne.objects.MarcacoesEstabelecimento ;  
			
		
	
		
			
				
					import  siprp.database.cayenne.objects.MarcacoesTecnicosHst ;  
			
		
	
		
			
				
					import  siprp.higiene.gestao.equipamentos.AdicionarEquipamentosPanel ;  
			
		
	
		
			
				
					import  siprp.medicina.processo.mail.MailSender ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					import  com.evolute.utils.ui.calendar.JCalendarPanel ;  
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -58,11 +62,9 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						private  final  JTextField  fieldNome1  =  new  JTextField ( ) ; 
 
			
		
	
		
			
				
						private  final  JTextField  fieldNome2  =  new  JTextField ( ) ; 
 
			
		
	
		
			
				
					//	private final JTextField fieldNome3 = new JTextField();
  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						private  final  JTextField  fieldFuncao1  =  new  JTextField ( ) ; 
 
			
		
	
		
			
				
						private  final  JTextField  fieldFuncao2  =  new  JTextField ( ) ; 
 
			
		
	
		
			
				
					//	private final JTextField fieldFuncao3 = new JTextField();
  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						private  final  LeafIconButton  buttonSave  =  LeafIconButton . createButton (  ICON_NAME_SAVE  ) ; 
 
			
		
	
		
			
				
						private  final  LeafIconButton  buttonRevert  =  LeafIconButton . createButton (  ICON_NAME_REVERT  ) ; 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -115,7 +117,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
							layout  =  new  TableLayout (  new  double [ ]  { 
 
			
		
	
		
			
				
									TableLayout . MINIMUM ,  TableLayout . FILL ,  TableLayout . MINIMUM ,  TableLayout . PREFERRED 
 
			
		
	
		
			
				
							} ,  new  double [ ]  { 
 
			
		
	
		
			
				
									TableLayout . MINIMUM ,  TableLayout . MINIMUM /*, TableLayout.MINIMUM*/ 
 
			
		
	
		
			
				
									TableLayout . MINIMUM ,  TableLayout . MINIMUM 
 
			
		
	
		
			
				
							}  ) ; 
 
			
		
	
		
			
				
							layout . setVGap (  5  ) ; 
 
			
		
	
		
			
				
							layout . setHGap (  5  ) ; 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -132,10 +134,6 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
							panelAcompanhantes . add (  fieldNome2 ,  new  TableLayoutConstraints (  1 ,  1  )  ) ; 
 
			
		
	
		
			
				
							panelAcompanhantes . add (  new  JLabel (  "Fun"  +  ccedil  +  atilde  +  "o"  ) ,  new  TableLayoutConstraints (  2 ,  1  )  ) ; 
 
			
		
	
		
			
				
							panelAcompanhantes . add (  fieldFuncao2 ,  new  TableLayoutConstraints (  3 ,  1  )  ) ; 
 
			
		
	
		
			
				
					//		panelAcompanhantes.add( new JLabel( "Nome" ), new TableLayoutConstraints( 0, 2 ) );
  
			
		
	
		
			
				
					//		panelAcompanhantes.add( fieldNome3, new TableLayoutConstraints( 1, 2 ) );
  
			
		
	
		
			
				
					//		panelAcompanhantes.add( new JLabel( "Fun" + ccedil + atilde + "o" ), new TableLayoutConstraints( 2, 2 ) );
  
			
		
	
		
			
				
					//		panelAcompanhantes.add( fieldFuncao3, new TableLayoutConstraints( 3, 2 ) );
  
			
		
	
		
			
				
							
 
			
		
	
		
			
				
							TableLayout  layout  =  new  TableLayout (  new  double [ ]  { 
 
			
		
	
		
			
				
									TableLayout . MINIMUM ,  TableLayout . MINIMUM ,  TableLayout . FILL ,  TableLayout . MINIMUM 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -170,10 +168,8 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
						{ 
 
			
		
	
		
			
				
							fieldFuncao1 . addCaretListener (  this  ) ; 
 
			
		
	
		
			
				
							fieldFuncao2 . addCaretListener (  this  ) ; 
 
			
		
	
		
			
				
					//		fieldFuncao3.addCaretListener( this );
  
			
		
	
		
			
				
							fieldNome1 . addCaretListener (  this  ) ; 
 
			
		
	
		
			
				
							fieldNome2 . addCaretListener (  this  ) ; 
 
			
		
	
		
			
				
					//		fieldNome3.addCaretListener( this );
  
			
		
	
		
			
				
							dataRelatorio . addChangeListener (  this  ) ; 
 
			
		
	
		
			
				
							radioInicial . addActionListener (  this  ) ; 
 
			
		
	
		
			
				
							radioPeriodica . addActionListener (  this  ) ; 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -198,7 +194,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
								@Override 
 
			
		
	
		
			
				
								public  void  actionPerformed (  ActionEvent  e  ) 
 
			
		
	
		
			
				
								{ 
 
			
		
	
		
			
				
									if (  isValidPlano ( )  & &  JOptionPane. OK_OPTION  = =   confirmSubmit( )  ) 
 
			
		
	
		
			
				
									if (  isValidPlano ( )  & &  ( )  ) 
 
			
		
	
		
			
				
									{ 
 
			
		
	
		
			
				
										submit ( ) ; 
 
			
		
	
		
			
				
									} 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -217,9 +213,9 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
							return  result ; 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						
 
			
		
	
		
			
				
						private  int  confirmSubmit ( ) 
 
			
		
	
		
			
				
						private  boolean  confirmSubmit ( ) 
 
			
		
	
		
			
				
						{ 
 
			
		
	
		
			
				
							return  JOptionPane . (  this ,  "Ao submeter o Plano de Actua" + ccedil + atilde + "o n" + atilde + "o ser" + aacute + " mais poss" + iacute + "vel alter" + aacute + "-lo. Deseja continuar?"  ) ; 
 
			
		
	
		
			
				
							return  JOptionPane . OK_OPTION = =  JOptionPane .  showConfirmDialog(  this ,  "Ao submeter o Plano de Actua" + ccedil + atilde + "o n" + atilde + "o ser" + aacute + " mais poss" + iacute + "vel alter" + aacute + "-lo. Deseja continuar?"  ) ; 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						
 
			
		
	
		
			
				
						private  void  submit ( ) 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -230,6 +226,7 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
								{ 
 
			
		
	
		
			
				
									relatorio . setIsSubmetido (  new  Date ( )  ) ; 
 
			
		
	
		
			
				
									relatorio . save ( ) ; 
 
			
		
	
		
			
				
									sendMail (  relatorio  ) ; 
 
			
		
	
		
			
				
									refresh ( ) ; 
 
			
		
	
		
			
				
									setRelatorio (  relatorio ,  false  ) ; 
 
			
		
	
		
			
				
								} 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -239,6 +236,70 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						
 
			
		
	
		
			
				
						private  void  sendMail (  HsRelatorio  relatorio  ) 
 
			
		
	
		
			
				
						{ 
 
			
		
	
		
			
				
							try 
 
			
		
	
		
			
				
							{ 
 
			
		
	
		
			
				
								MailSender  sender  =  new  MailSender ( ) ; 
 
			
		
	
		
			
				
								String  nomeEstabelecimento  =  relatorio . getToHsMarcacoesEstabelecimento ( ) . getToEstabelecimentos ( ) . getNome ( ) ; 
 
			
		
	
		
			
				
								MarcacoesTecnicosHst  tecnico  =  relatorio . getToHsMarcacoesEstabelecimento ( ) . getToMarcacoesTecnicosHst ( ) ; 
 
			
		
	
		
			
				
								String  nomeTecnico  =  tecnico  = =  null  ?  ""  :  tecnico . getNome ( ) ; 
 
			
		
	
		
			
				
								Date  dataVisita  =  relatorio . getToHsMarcacoesEstabelecimento ( ) . getData ( ) ; 
 
			
		
	
		
			
				
								String  dataVisitaString  =  new  SimpleDateFormat ( "dd/MM/yyyy" ) . format (  dataVisita  ) ; 
 
			
		
	
		
			
				
								String  subject  =  "Relatório da Avaliação de Riscos Laborais e Plano de Actuação de "  +  nomeEstabelecimento  +  " - auditoria de "  +  dataVisitaString ; 
 
			
		
	
		
			
				
								String  body  =  "Exmos. Senhores"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"Junto enviamos o relatório de avaliação de riscos laborais e "  + 
 
			
		
	
		
			
				
									"respectivo plano de actuação da auditoria realizada no dia "  + 
 
			
		
	
		
			
				
									dataVisitaString  +  
 
			
		
	
		
			
				
									"ao vosso estabelecimento de "  + 
 
			
		
	
		
			
				
									nomeEstabelecimento  + 
 
			
		
	
		
			
				
									". Aconselhamos que tenham em conta as não conformidades indicadas "  + 
 
			
		
	
		
			
				
									"nestes documentos e que preencham o plano de actuação por forma a "  + 
 
			
		
	
		
			
				
									"auxiliar-vos na planificação das medidas correctivas e para poderem "  + 
 
			
		
	
		
			
				
									"apresentá-los em caso de inspecção da ACT –   + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"Caso pretendam o nosso apoio ou necessitem de qualquer esclarecimento, contactem-nos, por favor, através do telefone (+351) 213 504 540."  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"Com os melhores cumprimentos, "  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									nomeTecnico  +  
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"SIPRP - Sociedade Ibérica de Prevenção de Riscos Profissionais "  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"Atrium Saldanha - Praça Duque de Saldanha, 1 - 9º G - 1050-094 Lisboa "  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"Telefone: (+351) 213 504 540 "  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"Fax: (+351) 213 504 549 "  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"E-mail: geral@siprp.pt "  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"URL: www.siprp.com "  + 
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"\n"  +  
 
			
		
	
		
			
				
									"\n"  + 
 
			
		
	
		
			
				
									"Esta é uma mensagem gerada automaticamente pelo nosso sistema, por favor não responda" ; 
 
			
		
	
		
			
				
								List < HsEmailEstabelecimento >  rels  =  relatorio . getToHsMarcacoesEstabelecimento ( ) . getToEstabelecimentos ( ) . getHsEmailEstabelecimento ( ) ; 
 
			
		
	
		
			
				
								for (  HsEmailEstabelecimento  rel  :  rels  ) 
 
			
		
	
		
			
				
								{ 
 
			
		
	
		
			
				
									sender . send (  rel . getToHsEmail ( ) . getEmail ( ) ,  "" ,  subject ,  body ,  null ,  null  ) ; 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							catch (  Exception  ex  ) 
 
			
		
	
		
			
				
							{ 
 
			
		
	
		
			
				
								ex . printStackTrace ( ) ; 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						
 
			
		
	
		
			
				
						private  void  save ( ) 
 
			
		
	
		
			
				
						{ 
 
			
		
	
		
			
				
							try 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -247,23 +308,12 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
								{ 
 
			
		
	
		
			
				
									relatorio . setData (  dataRelatorio . getDate ( )  ) ; 
 
			
		
	
		
			
				
									relatorio . setAvaliacaoInicial (  radioInicial . isSelected ( )  ) ; 
 
			
		
	
		
			
				
						//			MarcacoesEstabelecimento marcacao = relatorio.getToHsMarcacoesEstabelecimento();
 
 
			
		
	
		
			
				
						//			if( marcacao != null )
 
 
			
		
	
		
			
				
						//			{
 
 
			
		
	
		
			
				
						//				MarcacoesTecnicosHst tecnico = marcacao.getToMarcacoesTecnicosHst();
 
 
			
		
	
		
			
				
						//				if( tecnico != null )
 
 
			
		
	
		
			
				
						//				{
 
 
			
		
	
		
			
				
						//					tecnico.setNome( fieldTecnico.getText() );
 
 
			
		
	
		
			
				
						//				}
 
 
			
		
	
		
			
				
						//			}
 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								relatorio . setAcompanhante1 (  fieldNome1 . getText ( )  ) ; 
 
			
		
	
		
			
				
								relatorio . setAcompanhante2 (  fieldNome2 . getText ( )  ) ; 
 
			
		
	
		
			
				
					//			relatorio.setAcompanhante3( fieldNome3.getText() );
  
			
		
	
		
			
				
								
 
			
		
	
		
			
				
								relatorio . setFuncaoAcompanhante1 ( fieldFuncao1 . getText ( ) ) ; 
 
			
		
	
		
			
				
								relatorio . setFuncaoAcompanhante2 ( fieldFuncao2 . getText ( ) ) ; 
 
			
		
	
		
			
				
					//			relatorio.setFuncaoAcompanhante3(fieldFuncao3.getText());
  
			
		
	
		
			
				
								relatorio . save ( ) ; 
 
			
		
	
		
			
				
								refresh ( ) ; 
 
			
		
	
		
			
				
								buttonRevert . setEnabled (  false  ) ; 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -309,10 +359,8 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
							fieldTecnico . setText (  tecnicoName  ) ; 
 
			
		
	
		
			
				
							fieldNome1 . setText (  relatorio  = =  null  ?  null  :  relatorio . getAcompanhante1 ( )  ) ; 
 
			
		
	
		
			
				
							fieldNome2 . setText (  relatorio  = =  null  ?  null  :  relatorio . getAcompanhante2 ( )  ) ; 
 
			
		
	
		
			
				
					//		fieldNome3.setText( relatorio == null ? null : relatorio.getAcompanhante3() );
  
			
		
	
		
			
				
							fieldFuncao1 . setText (  relatorio  = =  null  ?  null  :  relatorio . getFuncaoAcompanhante1 ( )  ) ; 
 
			
		
	
		
			
				
							fieldFuncao2 . setText (  relatorio  = =  null  ?  null  :  relatorio . getFuncaoAcompanhante2 ( )  ) ; 
 
			
		
	
		
			
				
					//		fieldFuncao3.setText( relatorio == null ? null : relatorio.getFuncaoAcompanhante3() );
  
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						
 
			
		
	
		
			
				
						private  void  setEnabled ( ) 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -324,10 +372,8 @@ public class PanelRelatorio extends JPanel implements CaretListener, ChangeListe
 
			
		
	
		
			
				
							fieldTecnico . setEnabled (  false  ) ; 
 
			
		
	
		
			
				
							fieldNome1 . setEnabled (  enabled  ) ; 
 
			
		
	
		
			
				
							fieldNome2 . setEnabled (  enabled  ) ; 
 
			
		
	
		
			
				
					//		fieldNome3.setEnabled( enabled );
  
			
		
	
		
			
				
							fieldFuncao1 . setEnabled (  enabled  ) ; 
 
			
		
	
		
			
				
							fieldFuncao2 . setEnabled (  enabled  ) ; 
 
			
		
	
		
			
				
					//		fieldFuncao3.setEnabled( enabled );
  
			
		
	
		
			
				
							buttonSubmit . setEnabled (  enabled  ) ; 
 
			
		
	
		
			
				
						}