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.
742 lines
25 KiB
742 lines
25 KiB
package siprp.logic;
|
|
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.atilde;
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.ccedil;
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.iacute;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
|
import siprp.data.outer.EmpresasData;
|
|
import siprp.data.outer.EstabelecimentosData;
|
|
import siprp.data.outer.HsAreaData;
|
|
import siprp.data.outer.HsEmailEstabelecimentoData;
|
|
import siprp.data.outer.HsEquipamentoData;
|
|
import siprp.data.outer.HsLegislacaoCategoriaData;
|
|
import siprp.data.outer.HsLegislacaoData;
|
|
import siprp.data.outer.HsLegislacaoEstabelecimentoData;
|
|
import siprp.data.outer.HsNormalizacaoData;
|
|
import siprp.data.outer.HsNormalizacaoEstabelecimentoData;
|
|
import siprp.data.outer.HsPostoData;
|
|
import siprp.data.outer.HsPostoEstabelecimentoData;
|
|
import siprp.data.outer.HsPostoRiscoData;
|
|
import siprp.data.outer.HsRelatorioAreaData;
|
|
import siprp.data.outer.HsRelatorioData;
|
|
import siprp.data.outer.HsRelatorioLegislacaoData;
|
|
import siprp.data.outer.HsRelatorioMedidaData;
|
|
import siprp.data.outer.HsRelatorioNormalizacaoData;
|
|
import siprp.data.outer.HsRelatorioPostoData;
|
|
import siprp.data.outer.HsRelatorioPostoMedidaData;
|
|
import siprp.data.outer.HsRelatorioPostoRiscoData;
|
|
import siprp.data.outer.HsRelatorioRiscoData;
|
|
import siprp.data.outer.HsRelatorioRiscoValorQualitativoData;
|
|
import siprp.data.outer.HsRiscoData;
|
|
import siprp.data.outer.HsRiscoEmpresaData;
|
|
import siprp.data.outer.HsRiscoMedidaData;
|
|
import siprp.data.outer.HsRiscoTemaData;
|
|
import siprp.data.provider.MedicinaDataProvider;
|
|
import siprp.data.provider.PlanoActuacaoDataProvider;
|
|
import siprp.logic.node.AreaNode;
|
|
import siprp.logic.node.AreaRelatorioNode;
|
|
import siprp.logic.node.NodeMedida;
|
|
import siprp.logic.node.NodeRisco;
|
|
import siprp.logic.node.NodeRiscoTema;
|
|
import siprp.logic.node.PostoNode;
|
|
import siprp.logic.node.PostoRelatorioNode;
|
|
|
|
import com.evolute.entity.evo.EvoJoinObject;
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
import com.evolute.utils.ui.trees.TreeTools;
|
|
|
|
public class HigieneSegurancaLogic
|
|
{
|
|
|
|
private static PlanoActuacaoDataProvider planoProvider = null;
|
|
private static MedicinaDataProvider medicinaProvider = null;
|
|
|
|
static
|
|
{
|
|
try
|
|
{
|
|
planoProvider = PlanoActuacaoDataProvider.getProvider();
|
|
medicinaProvider = MedicinaDataProvider.getProvider();
|
|
}
|
|
catch ( Exception e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getRiscosTree()
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
List< HsRiscoTemaData > temas = planoProvider.getAllRiscoTemas();
|
|
if( temas != null )
|
|
{
|
|
for( HsRiscoTemaData tema : temas )
|
|
{
|
|
NodeRiscoTema temaNode = new NodeRiscoTema( tema );
|
|
for( HsRiscoData risco : tema.fromHsRisco_tema_id() )
|
|
{
|
|
NodeRisco riscoNode = new NodeRisco( risco );
|
|
for( HsRiscoMedidaData rel : risco.fromHsRiscoMedida_risco_id() )
|
|
{
|
|
riscoNode.add( new NodeMedida( rel ) );
|
|
}
|
|
temaNode.add( riscoNode );
|
|
}
|
|
result.add( temaNode );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getRiscosTree( EmpresasData empresa )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
for( HsRiscoEmpresaData rel : empresa.fromHsRiscoEmpresa_empresa_id() )
|
|
{
|
|
HsRiscoData risco = rel.toRisco_id();
|
|
HsRiscoTemaData tema = risco.toTema_id();
|
|
DefaultMutableTreeNode temaNode = TreeTools.findNodeWithUserObject( tema, result );
|
|
if( temaNode == null )
|
|
{
|
|
temaNode = new NodeRiscoTema( tema );
|
|
result.add(temaNode);
|
|
}
|
|
temaNode.add( new NodeRisco( risco ) );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getAreasTree( EmpresasData empresa )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
if( empresa != null )
|
|
{
|
|
for( HsAreaData area : empresa.fromHsArea_empresa_id() )
|
|
{
|
|
AreaNode areaNode = new AreaNode(area);
|
|
for( HsPostoData posto : area.fromHsPosto_area_id() )
|
|
{
|
|
if( posto != null && posto.getDeleted_date() == null )
|
|
{
|
|
areaNode.add( new PostoNode( posto ) );
|
|
}
|
|
}
|
|
result.add( areaNode );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getAreasTree( EstabelecimentosData estabelecimento )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
if( estabelecimento != null )
|
|
{
|
|
List<HsPostoEstabelecimentoData> postos = estabelecimento.fromHsPostoEstabelecimento_estabelecimento_id();
|
|
for( HsPostoEstabelecimentoData rel : postos )
|
|
{
|
|
HsPostoData posto = rel.toPosto_id();
|
|
HsAreaData area = posto.toArea_id();
|
|
DefaultMutableTreeNode areaNode = TreeTools.findNodeWithUserObject( area, result );
|
|
if( areaNode == null )
|
|
{
|
|
areaNode = new AreaNode( area );
|
|
result.add( areaNode );
|
|
}
|
|
areaNode.add( new PostoNode( posto ) );
|
|
}
|
|
TreeTools.sort( result );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getPostosTree( EstabelecimentosData estabelecimento )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
if( estabelecimento != null )
|
|
{
|
|
List<HsPostoEstabelecimentoData> postos = estabelecimento.fromHsPostoEstabelecimento_estabelecimento_id();
|
|
for( HsPostoEstabelecimentoData rel : postos )
|
|
{
|
|
result.add( new PostoNode( rel.toPosto_id() ) );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static List<EmpresasData> getAllEmpresas()
|
|
{
|
|
return medicinaProvider.getAllEmpresas();
|
|
}
|
|
|
|
public static List<HsRelatorioRiscoValorQualitativoData> getAllValoresQualitativos()
|
|
{
|
|
return planoProvider.getAllValoresQualitativos();
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getAreasRelatorioTree( HsRelatorioData relatorio )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
if( relatorio != null )
|
|
{
|
|
List<HsRelatorioAreaData> areas = relatorio.fromHsRelatorioArea_relatorio_id();
|
|
for( HsRelatorioAreaData area : areas )
|
|
{
|
|
if( area.getDeleted_date() == null )
|
|
{
|
|
AreaRelatorioNode areaNode = new AreaRelatorioNode(area);
|
|
for( HsRelatorioPostoData posto : area.fromHsRelatorioPosto_area_id() )
|
|
{
|
|
if( posto.getDeleted_date() == null )
|
|
{
|
|
areaNode.add( new PostoRelatorioNode( posto ) );
|
|
}
|
|
}
|
|
result.add( areaNode );
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static void reverterRelatorio( HsRelatorioData relatorio )
|
|
{
|
|
// System.out.println( "\nreverterRelatorio( " + relatorio + " ) : " );
|
|
|
|
try
|
|
{
|
|
if(relatorio != null)
|
|
{
|
|
EstabelecimentosData estabelecimento = relatorio.toMarcacao_id() == null ? null : relatorio.toMarcacao_id().toEstabelecimento_id();
|
|
if( estabelecimento != null )
|
|
{
|
|
deleteRelatorioContents( relatorio );
|
|
reverterAreas( relatorio, estabelecimento );
|
|
reverterLegislacao( relatorio, estabelecimento, false );
|
|
reverterNormalizacao( relatorio, estabelecimento, false );
|
|
}
|
|
}
|
|
}
|
|
catch( Exception e )
|
|
{
|
|
ErrorLogger.logException(e);
|
|
}
|
|
}
|
|
|
|
private static void deleteRelatorioContents( HsRelatorioData relatorio ) throws Exception
|
|
{
|
|
planoProvider.deleteRelatorioContents( relatorio == null ? null : relatorio.getId() );
|
|
}
|
|
|
|
private static void reverterAreas( HsRelatorioData relatorio, EstabelecimentosData estabelecimento ) throws Exception
|
|
{
|
|
// List< HsRelatorioAreaData > areas = relatorio.fromHsRelatorioArea_relatorio_id();
|
|
// for ( HsRelatorioAreaData area : areas )
|
|
// {
|
|
// List< HsRelatorioPostoData > postos = area.fromHsRelatorioPosto_area_id();
|
|
// for ( HsRelatorioPostoData posto : postos )
|
|
// {
|
|
// for( HsRelatorioPostoRiscoData rRisco : posto.fromHsRelatorioPostoRisco_posto_id() )
|
|
// {
|
|
// rRisco.delete();
|
|
// rRisco.toRisco_id().delete();
|
|
// }
|
|
// for( HsRelatorioPostoMedidaData rMedida : posto.fromHsRelatorioPostoMedida_posto_id() )
|
|
// {
|
|
// rMedida.delete();
|
|
// rMedida.toMedida_id().delete();
|
|
// }
|
|
// posto.delete();
|
|
// }
|
|
// area.delete();
|
|
// }
|
|
// relatorio.save();
|
|
List< HsPostoEstabelecimentoData > postos = estabelecimento.fromHsPostoEstabelecimento_estabelecimento_id();
|
|
reverterPostos( relatorio, postos );
|
|
relatorio.save();
|
|
}
|
|
|
|
private static void reverterPostos( HsRelatorioData relatorio, List< HsPostoEstabelecimentoData > postos ) throws Exception
|
|
{
|
|
// System.out.println( "\nreverterPostos( " + postos + " ) :" );
|
|
|
|
HashMap< HsAreaData, HsRelatorioAreaData > areasInserted = new HashMap< HsAreaData, HsRelatorioAreaData >();
|
|
for( HsPostoEstabelecimentoData rel : postos )
|
|
{
|
|
HsPostoData posto = rel.toPosto_id();
|
|
HsAreaData area = posto.toArea_id();
|
|
if( posto.getDeleted_date() == null && area.getDeleted_date() == null )
|
|
{
|
|
HsRelatorioPostoData newPosto = createRelatorioPostoFromHsPosto( relatorio, areasInserted.get( area ), posto );
|
|
areasInserted.put( area, newPosto.toArea_id() );
|
|
}
|
|
}
|
|
}
|
|
|
|
public static HsRelatorioPostoData createRelatorioPostoFromHsPosto( HsRelatorioData relatorio, HsRelatorioAreaData rArea, HsPostoData posto )
|
|
throws Exception
|
|
{
|
|
relatorio.save();
|
|
if( rArea == null )
|
|
{
|
|
HsAreaData area = posto.toArea_id();
|
|
rArea = new HsRelatorioAreaData();
|
|
updateRelatorioAreaFromHsArea( relatorio, rArea, area );
|
|
}
|
|
|
|
HsRelatorioPostoData rPosto = new HsRelatorioPostoData();
|
|
updateRelatorioPostoFromHsPosto( rPosto, rArea, posto );
|
|
revertMedidasAndRiscos( relatorio.getId(), posto, rPosto );
|
|
rPosto.save();
|
|
return rPosto;
|
|
}
|
|
|
|
public static void updateRelatorioAreaFromHsArea( HsRelatorioData relatorio, HsRelatorioAreaData rArea, HsAreaData area ) throws Exception
|
|
{
|
|
// System.out.println( "\nupdateRelatorioAreaFromHsArea( " + rArea + ", " + area + " ) : " );
|
|
|
|
rArea.setDescription( area.getDescription() );
|
|
rArea.setOrdem( area.getOrdem() );
|
|
rArea.setToRelatorio_id( relatorio );
|
|
rArea.setHs_area_id( area.getId() );
|
|
rArea.save();
|
|
}
|
|
|
|
public static void updateRelatorioPostoFromHsPosto( HsRelatorioPostoData rPosto, HsRelatorioAreaData rArea, HsPostoData posto ) throws Exception
|
|
{
|
|
// System.out.println( "\nupdateRelatorioPostoFromHsPosto( " + rPosto + ", " + rArea + ", " + posto + " ) : " );
|
|
|
|
rPosto.setDescription( posto.getDescription() );
|
|
rPosto.setIs_principal( posto.getIs_principal() );
|
|
rPosto.setHs_posto_id( posto.getId() );
|
|
rPosto.setToArea_id( rArea );
|
|
rPosto.save();
|
|
}
|
|
|
|
public static void addRiscoToRelatorioPosto( Integer relatorioID, HsRiscoData risco, Integer order, HsRelatorioPostoData rPosto ) throws Exception
|
|
{
|
|
|
|
// HsRelatorioRiscoData relatorioRisco = planoProvider.loadRelatorioRiscoByRiscoID( relatorioID, risco.getId() );
|
|
// if ( relatorioRisco == null )
|
|
// {
|
|
HsRelatorioRiscoData relatorioRisco = new HsRelatorioRiscoData();
|
|
relatorioRisco.setToRelatorio_id( rPosto.toArea_id().toRelatorio_id() );
|
|
relatorioRisco.setDescription( risco.getDescription() );
|
|
relatorioRisco.setHs_risco_id( risco.getId() );
|
|
relatorioRisco.save();
|
|
// }
|
|
|
|
// HsRelatorioPostoRiscoData rPostoRisco = planoProvider.loadRelatorioPostoRisco( rPosto.getId(), relatorioRisco.getId() );
|
|
// if ( rPostoRisco == null )
|
|
// {
|
|
HsRelatorioPostoRiscoData rPostoRisco = new HsRelatorioPostoRiscoData();
|
|
rPostoRisco.setToPosto_id( rPosto );
|
|
rPostoRisco.setToRisco_id( relatorioRisco );
|
|
rPostoRisco.setOrdem( order );
|
|
rPostoRisco.save();
|
|
// }
|
|
|
|
for( HsRiscoMedidaData riscoMedida : risco.fromHsRiscoMedida_risco_id() )
|
|
{
|
|
// HsRelatorioMedidaData rMedida = planoProvider.loadRelatorioMedidaByMedidaID( riscoMedida.getMedida_id() );
|
|
// if( rMedida != null )
|
|
// {
|
|
// if( rMedida.toRisco_id() != null )
|
|
// {
|
|
// if( !relatorioID.equals( rMedida.toRisco_id().getRelatorio_id() ) )
|
|
// {
|
|
// rMedida = null;
|
|
// }
|
|
// }
|
|
// }
|
|
// if ( rMedida == null )
|
|
// {
|
|
HsRelatorioMedidaData rMedida = new HsRelatorioMedidaData();
|
|
rMedida.setDescription( riscoMedida.toMedida_id().getDescription() );
|
|
rMedida.setRequesitos_legais( riscoMedida.toMedida_id().getRequesitos_legais());
|
|
rMedida.setToRisco_id( relatorioRisco );
|
|
rMedida.setHs_medida_id( riscoMedida.toMedida_id().getId() );
|
|
rMedida.save();
|
|
// }
|
|
|
|
// HsRelatorioPostoMedidaData rPostoMedida = planoProvider.loadRelatorioPostoMedida( rPosto.getId(), rMedida.getId() );
|
|
// if ( rPostoMedida == null )
|
|
// {
|
|
HsRelatorioPostoMedidaData rPostoMedida = new HsRelatorioPostoMedidaData();
|
|
rPostoMedida.setIs_plano_actuacao( false );
|
|
rPostoMedida.setToMedida_id( rMedida );
|
|
rPostoMedida.setToPosto_id( rPosto );
|
|
rPostoMedida.save();
|
|
// }
|
|
}
|
|
|
|
}
|
|
|
|
private static void revertMedidasAndRiscos( Integer relatorioID, HsPostoData posto, HsRelatorioPostoData rPosto ) throws Exception
|
|
{
|
|
for( HsPostoRiscoData postoRisco : posto.fromHsPostoRisco_posto_id() )
|
|
{
|
|
addRiscoToRelatorioPosto( relatorioID, postoRisco.toRisco_id(), postoRisco.getOrdem(), rPosto );
|
|
}
|
|
}
|
|
|
|
public static void reverterLegislacao( HsRelatorioData relatorio, EstabelecimentosData estabelecimento, boolean delete ) throws Exception
|
|
{
|
|
// System.out.println( "\nreverterLegislacao( " + estabelecimento + " ) : " );
|
|
|
|
// List< HsRelatorioLegislacaoData > listLegislacao = relatorio.fromHsRelatorioLegislacao_hs_relatorio_id();
|
|
// for ( HsRelatorioLegislacaoData legislacao : listLegislacao )
|
|
// {
|
|
// legislacao.delete();
|
|
// }
|
|
// int legislacaoSize = relatorio.fromHsRelatorioLegislacao_hs_relatorio_id().size();
|
|
// for(int i = 0; i < legislacaoSize; ++i )
|
|
// {
|
|
// relatorio.fromHsRelatorioLegislacao_hs_relatorio_id().get( 0 ).delete();
|
|
// }
|
|
if( delete )
|
|
{
|
|
for( HsRelatorioLegislacaoData rl : relatorio.fromHsRelatorioLegislacao_hs_relatorio_id() )
|
|
{
|
|
rl.delete();
|
|
}
|
|
}
|
|
for( HsLegislacaoEstabelecimentoData rel : estabelecimento.fromHsLegislacaoEstabelecimento_estabelecimento_id() )
|
|
{
|
|
HsLegislacaoData legislacao = rel.toLegislacao_id();
|
|
HsRelatorioLegislacaoData relatorioLegislacao = criarRelatorioLegislacao( relatorio, legislacao );
|
|
relatorioLegislacao.setOrdem( rel.getOrdem() );
|
|
relatorioLegislacao.save();
|
|
}
|
|
}
|
|
|
|
private static HsRelatorioLegislacaoData criarRelatorioLegislacao( HsRelatorioData relatorio, HsLegislacaoData legislacao )
|
|
{
|
|
// System.out.println( "\ncriarRelatorioLegislacao( " + legislacao + " ) : " );
|
|
|
|
HsRelatorioLegislacaoData result = null;
|
|
if( relatorio != null && legislacao != null )
|
|
{
|
|
result = new HsRelatorioLegislacaoData();
|
|
result.setCategoria( legislacao.toCategoria_id() == null ? null : legislacao.toCategoria_id().getDescription() );
|
|
result.setToHs_relatorio_id( relatorio );
|
|
result.setHs_legislacao_id( legislacao.getId() );
|
|
result.setDescricao( legislacao.getDescription() );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static void reverterNormalizacao( HsRelatorioData relatorio, EstabelecimentosData estabelecimento, boolean delete ) throws Exception
|
|
{
|
|
// System.out.println( "\nreverterNormalizacao( " + estabelecimento + " ) : " );
|
|
|
|
// List< HsRelatorioNormalizacaoData > normalizacoes = relatorio.fromHsRelatorioNormalizacao_hs_relatorio_id();
|
|
// for ( HsRelatorioNormalizacaoData normalizacao : normalizacoes )
|
|
// {
|
|
// normalizacao.delete();
|
|
// }
|
|
// int normalizacaoSize = relatorio.fromHsRelatorioNormalizacao_hs_relatorio_id().size();
|
|
// for(int i = 0; i < normalizacaoSize; ++i )
|
|
// {
|
|
// relatorio.fromHsRelatorioNormalizacao_hs_relatorio_id().get( 0 ).delete();
|
|
// }
|
|
if( delete )
|
|
{
|
|
for( HsRelatorioNormalizacaoData rn : relatorio.fromHsRelatorioNormalizacao_hs_relatorio_id() )
|
|
{
|
|
rn.delete();
|
|
}
|
|
}
|
|
for( HsNormalizacaoEstabelecimentoData rel : estabelecimento.fromHsNormalizacaoEstabelecimento_estabelecimento_id() )
|
|
{
|
|
HsNormalizacaoData normalizacao = rel.toNormalizacao_id();
|
|
HsRelatorioNormalizacaoData relatorioNormalizacao = criarRelatorioNormalizacao( relatorio, normalizacao );
|
|
relatorioNormalizacao.save();
|
|
}
|
|
}
|
|
|
|
private static HsRelatorioNormalizacaoData criarRelatorioNormalizacao( HsRelatorioData relatorio, HsNormalizacaoData normalizacao )
|
|
{
|
|
// System.out.println( "\ncriarRelatorioNormalizacao( " + normalizacao + " ) : " );
|
|
|
|
HsRelatorioNormalizacaoData result = null;
|
|
if( relatorio != null && normalizacao != null )
|
|
{
|
|
result = new HsRelatorioNormalizacaoData();
|
|
result.setCodigo( normalizacao.getCodigo() );
|
|
result.setDescricao( normalizacao.getDescricao() );
|
|
result.setToHs_relatorio_id( relatorio );
|
|
result.setHs_normalizacao_id( normalizacao.getId() );
|
|
result.setPortuguesa( normalizacao.getPortuguesa() );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static boolean isProbabilidadeValida( Integer probabilidade )
|
|
{
|
|
return probabilidade != null && probabilidade > 0 && probabilidade <= 4;
|
|
}
|
|
|
|
public static boolean isSeveridadeValida( Integer severidade )
|
|
{
|
|
return severidade != null && severidade > 0 && severidade <= 4;
|
|
}
|
|
|
|
public static boolean isRelatorioRiscoPreenchido( HsRelatorioPostoRiscoData rel )
|
|
{
|
|
boolean hasQual = rel.toValor_qualitativo_id() != null;
|
|
boolean hasQuant = false;
|
|
if( !hasQual )
|
|
{
|
|
hasQuant = HigieneSegurancaLogic.isSeveridadeValida( rel.getSeveridade() );
|
|
hasQuant &= HigieneSegurancaLogic.isProbabilidadeValida( rel.getSeveridade() );
|
|
}
|
|
return hasQual || hasQuant;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getLegislacaoGeral()
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
for( HsLegislacaoData legislacao : planoProvider.getAllLegislacaoGeral() )
|
|
{
|
|
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao );
|
|
result.add( legislacaoNode );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getLegislacaoEspecifica()
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
for( HsLegislacaoCategoriaData categoria : planoProvider.getAllLegislacaoCategorias() )
|
|
{
|
|
DefaultMutableTreeNode categoriaNode = new DefaultMutableTreeNode( categoria );
|
|
for( HsLegislacaoData legislacao: categoria.fromHsLegislacao_categoria_id() )
|
|
{
|
|
if( legislacao.getDeleted_date() == null )
|
|
{
|
|
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( legislacao );
|
|
categoriaNode.add( legislacaoNode );
|
|
}
|
|
}
|
|
result.add( categoriaNode );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getNormalizacaoTree( boolean portuguesa )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o " + ( portuguesa ? "Portuguesa" : "Internacional" ) );
|
|
for( HsNormalizacaoData normalizacao : planoProvider.getNormalizacao( portuguesa ) )
|
|
{
|
|
DefaultMutableTreeNode normalizacaoNode = new DefaultMutableTreeNode( normalizacao );
|
|
result.add( normalizacaoNode );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getNormalizacaoTreeForEmpresa( EmpresasData empresa )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
DefaultMutableTreeNode portuguesa = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o Portuguesa" );
|
|
DefaultMutableTreeNode internacional = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o Internacional" );
|
|
for( HsNormalizacaoData normalizacao : planoProvider.getNormalizacaoForEmpresa( true, empresa ) )
|
|
{
|
|
// if( empresa == null || hasEmpresa( normalizacao, empresa ) )
|
|
// {
|
|
DefaultMutableTreeNode normalizacaoNode = new DefaultMutableTreeNode( normalizacao );
|
|
portuguesa.add( normalizacaoNode );
|
|
// }
|
|
}
|
|
for( HsNormalizacaoData normalizacao : planoProvider.getNormalizacaoForEmpresa( false, empresa ) )
|
|
{
|
|
// if( empresa == null || hasEmpresa( normalizacao, empresa ) )
|
|
// {
|
|
DefaultMutableTreeNode normalizacaoNode = new DefaultMutableTreeNode( normalizacao );
|
|
internacional.add( normalizacaoNode );
|
|
// }
|
|
}
|
|
result.add( portuguesa );
|
|
result.add( internacional );
|
|
return result;
|
|
}
|
|
|
|
// private static boolean hasEmpresa( HsNormalizacaoData normalizacao, EmpresasData empresa )
|
|
// {
|
|
// boolean result = false;
|
|
// if( normalizacao != null && empresa != null )
|
|
// {
|
|
// for( HsNormalizacaoEmpresaData rel : normalizacao.fromHsNormalizacaoEmpresa_normalizacao_id() )
|
|
// {
|
|
// result = empresa.equals( rel.toEmpresa_id() );
|
|
// if( result )
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
// return result;
|
|
// }
|
|
|
|
public static DefaultMutableTreeNode getNormalizacaoTreeForEstabelecimento( EstabelecimentosData estabelecimento )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
DefaultMutableTreeNode portuguesa = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o Portuguesa" );
|
|
DefaultMutableTreeNode internacional = new DefaultMutableTreeNode("Normaliza" + ccedil + atilde + "o Internacional" );
|
|
for( HsNormalizacaoData normalizacao : planoProvider.getNormalizacaoForEstabelecimento( true, estabelecimento ) )
|
|
{
|
|
// if( estabelecimento == null || hasEstabelecimento( normalizacao, estabelecimento ) )
|
|
// {
|
|
DefaultMutableTreeNode normalizacaoNode = new DefaultMutableTreeNode( normalizacao );
|
|
portuguesa.add( normalizacaoNode );
|
|
// }
|
|
}
|
|
for( HsNormalizacaoData normalizacao : planoProvider.getNormalizacaoForEstabelecimento( false, estabelecimento ) )
|
|
{
|
|
// if( estabelecimento == null || hasEstabelecimento( normalizacao, estabelecimento ) )
|
|
// {
|
|
DefaultMutableTreeNode normalizacaoNode = new DefaultMutableTreeNode( normalizacao );
|
|
internacional.add( normalizacaoNode );
|
|
// }
|
|
}
|
|
result.add( portuguesa );
|
|
result.add( internacional );
|
|
return result;
|
|
}
|
|
|
|
private static boolean hasEstabelecimento( HsNormalizacaoData normalizacao, EstabelecimentosData estabelecimento )
|
|
{
|
|
boolean result = false;
|
|
if( normalizacao != null && estabelecimento != null )
|
|
{
|
|
for( HsNormalizacaoEstabelecimentoData rel : normalizacao.fromHsNormalizacaoEstabelecimento_normalizacao_id() )
|
|
{
|
|
result = estabelecimento.equals( rel.toEstabelecimento_id() );
|
|
if( result )
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getLegislacaoTreeForEmpresa( EmpresasData empresa )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
DefaultMutableTreeNode geral = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o de aplica" + ccedil + atilde + "o geral" );
|
|
DefaultMutableTreeNode especifica = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o espec" + iacute + "fica" );
|
|
Map<Integer,DefaultMutableTreeNode> categorias = new HashMap<Integer, DefaultMutableTreeNode>();
|
|
for( HsLegislacaoData legislacao : planoProvider.getAllLegislacaoForEmpresa( empresa ) )
|
|
{
|
|
DefaultMutableTreeNode categoriaNode = legislacao.getCategoria_id() == null ? null : categorias.get( legislacao.getCategoria_id() );
|
|
if( categoriaNode == null && legislacao.getCategoria_id() != null )
|
|
{
|
|
categoriaNode = new DefaultMutableTreeNode( legislacao.toCategoria_id() );
|
|
categorias.put( legislacao.getCategoria_id(), categoriaNode );
|
|
especifica.add( categoriaNode );
|
|
}
|
|
if( categoriaNode == null )
|
|
{
|
|
geral.add( new DefaultMutableTreeNode( legislacao ) );
|
|
}
|
|
else
|
|
{
|
|
categoriaNode.add( new DefaultMutableTreeNode( legislacao ) );
|
|
}
|
|
}
|
|
result.add( geral );
|
|
result.add( especifica );
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getLegislacaoTreeForEstabelecimento( EstabelecimentosData estabelecimento )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
DefaultMutableTreeNode geral = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o de aplica" + ccedil + atilde + "o geral" );
|
|
DefaultMutableTreeNode especifica = new DefaultMutableTreeNode( "Legisla" + ccedil + atilde + "o espec" + iacute + "fica" );
|
|
if( estabelecimento != null )
|
|
{
|
|
for( HsLegislacaoEstabelecimentoData rel : estabelecimento.fromHsLegislacaoEstabelecimento_estabelecimento_id() )
|
|
{
|
|
HsLegislacaoData legislacao = rel.toLegislacao_id();
|
|
if( legislacao != null )
|
|
{
|
|
HsLegislacaoCategoriaData categoria = legislacao.toCategoria_id();
|
|
if( categoria == null )
|
|
{
|
|
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( rel.toLegislacao_id() );
|
|
geral.add( legislacaoNode );
|
|
}
|
|
else
|
|
{
|
|
DefaultMutableTreeNode categoriaNode = TreeTools.findNodeWithUserObject( categoria, especifica );
|
|
if( categoriaNode == null )
|
|
{
|
|
categoriaNode = new DefaultMutableTreeNode(categoria);
|
|
especifica.add(categoriaNode);
|
|
}
|
|
DefaultMutableTreeNode legislacaoNode = new DefaultMutableTreeNode( rel.toLegislacao_id() );
|
|
categoriaNode.add( legislacaoNode );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
result.add( geral );
|
|
result.add( especifica );
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getEquipamentosTree()
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
List<HsEquipamentoData> equipamentos = planoProvider.getAllEquipamentos();
|
|
if( equipamentos != null )
|
|
{
|
|
for( HsEquipamentoData equipamento : equipamentos )
|
|
{
|
|
result.add( new DefaultMutableTreeNode( equipamento ) );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DefaultMutableTreeNode getEmailsForEstabelecimento( EstabelecimentosData estabelecimento )
|
|
{
|
|
DefaultMutableTreeNode result = new DefaultMutableTreeNode();
|
|
List<HsEmailEstabelecimentoData> emails = planoProvider.getEmailsForEstabelecimento( estabelecimento );
|
|
if( emails != null )
|
|
{
|
|
for( HsEmailEstabelecimentoData rel : emails )
|
|
{
|
|
result.add( new DefaultMutableTreeNode( rel ) );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static HsRiscoData findHsRiscoFor( HsRelatorioRiscoData relatorioRisco )
|
|
{
|
|
HsRiscoData risco = null;
|
|
List<HsRiscoData> riscos = planoProvider.findHsRiscosFor( relatorioRisco );
|
|
if( !riscos.isEmpty() )
|
|
{
|
|
risco = riscos.get( 0 );
|
|
}
|
|
return risco;
|
|
}
|
|
|
|
public static List<EvoJoinObject> getRelatorioMedidasForPosto( HsRelatorioPostoData posto ) throws Exception
|
|
{
|
|
return planoProvider.getRelatorioMedidasForPosto( posto );
|
|
}
|
|
|
|
|
|
}
|