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.
150 lines
4.7 KiB
150 lines
4.7 KiB
package siprp.database.cayenne.providers;
|
|
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.apache.cayenne.DataObjectUtils;
|
|
import org.apache.cayenne.PersistenceState;
|
|
import org.apache.cayenne.exp.ExpressionFactory;
|
|
import org.apache.cayenne.query.SelectQuery;
|
|
|
|
import siprp.database.cayenne.objects.BaseObject;
|
|
import siprp.database.cayenne.objects.Empresas;
|
|
import siprp.database.cayenne.objects.Exames;
|
|
import siprp.database.cayenne.objects.LembretesTipos;
|
|
import siprp.database.cayenne.objects.Prestadores;
|
|
import siprp.database.cayenne.objects.PrtGruposProtocolo;
|
|
import siprp.database.cayenne.objects.Trabalhadores;
|
|
import siprp.database.cayenne.objects.TrabalhadoresConsultasDatas;
|
|
import siprp.database.cayenne.objects.TrabalhadoresEcd;
|
|
import siprp.database.cayenne.objects.TrabalhadoresEcdsDatas;
|
|
import siprp.database.cayenne.objects.TrabalhadoresProcesso;
|
|
import siprp.medicina.MedicinaConstants;
|
|
import siprp.medicina.processo.ProcessoConstants;
|
|
|
|
public class MedicinaDAO extends MainDAO implements MedicinaConstants
|
|
{
|
|
// private static final String defaultPrestadorName = "SIPRP";
|
|
private Prestadores defaultPrestador = Prestadores.prestadorNulo;
|
|
|
|
public Trabalhadores getTrabalhadorByID( Integer id )
|
|
{
|
|
return (Trabalhadores) DataObjectUtils.objectForPK( context, Trabalhadores.class, id );
|
|
}
|
|
|
|
public TrabalhadoresConsultasDatas getConsultaMarcacaoByID( Integer id )
|
|
{
|
|
return (TrabalhadoresConsultasDatas) DataObjectUtils.objectForPK( context, TrabalhadoresConsultasDatas.class, id );
|
|
}
|
|
|
|
public TrabalhadoresEcdsDatas getExameMarcacaoByID( Integer id )
|
|
{
|
|
return (TrabalhadoresEcdsDatas) DataObjectUtils.objectForPK( context, TrabalhadoresEcdsDatas.class, id );
|
|
}
|
|
|
|
|
|
public Exames getExameForExameID( Integer currentFichaExameID )
|
|
{
|
|
return (Exames) DataObjectUtils.objectForPK( context, Exames.class, currentFichaExameID );
|
|
}
|
|
|
|
public LembretesTipos getTipoLembretesCustomizavel( )
|
|
{
|
|
return (LembretesTipos) DataObjectUtils.objectForPK( context, LembretesTipos.class, 1 );
|
|
}
|
|
|
|
public List<Empresas> getAllEmpresas()
|
|
{
|
|
SelectQuery query = new SelectQuery( Empresas.class );
|
|
query.andQualifier( ExpressionFactory.noMatchExp( Empresas.INACTIVO_PROPERTY, "y" ) );
|
|
query.addOrdering( Empresas.DESIGNACAO_SOCIAL_PLAIN_PROPERTY, true );
|
|
List<Empresas> allEmpresas = context.performQuery( query );
|
|
return allEmpresas;
|
|
}
|
|
|
|
public List<Prestadores> getAllPrestadores()
|
|
{
|
|
SelectQuery query = new SelectQuery( Prestadores.class );
|
|
query.andQualifier( ExpressionFactory.matchExp( Prestadores.ACTIVO_PROPERTY, "y" ) );
|
|
query.addOrdering( Prestadores.NOME_PROPERTY, true );
|
|
List<Prestadores> allPrestadores = context.performQuery( query );
|
|
return allPrestadores;
|
|
}
|
|
|
|
public List<PrtGruposProtocolo> getAllPrtGruposProtocolo()
|
|
{
|
|
SelectQuery query = new SelectQuery( PrtGruposProtocolo.class );
|
|
query.addOrdering( PrtGruposProtocolo.DESCRICAO_PLAIN_PROPERTY, true );
|
|
List<PrtGruposProtocolo> allPrtGruposProtocolo= context.performQuery( query );
|
|
return allPrtGruposProtocolo;
|
|
}
|
|
|
|
public BaseObject saveObject( BaseObject object )
|
|
{
|
|
if( object != null )
|
|
{
|
|
if( object.getPersistenceState() == PersistenceState.NEW )
|
|
{
|
|
context.registerNewObject( object );
|
|
}
|
|
context.commitChanges();
|
|
}
|
|
return object;
|
|
}
|
|
|
|
|
|
public void deleteObject( BaseObject object )
|
|
{
|
|
if( object != null )
|
|
{
|
|
context.deleteObject( object );
|
|
context.commitChanges();
|
|
}
|
|
}
|
|
|
|
public void rollback()
|
|
{
|
|
context.rollbackChanges();
|
|
context.unregisterObjects( context.uncommittedObjects() );
|
|
context.deleteObjects( context.newObjects() );
|
|
}
|
|
|
|
public void fecharProcesso( TrabalhadoresProcesso currentProcesso )
|
|
{
|
|
currentProcesso.setEstado( ProcessoConstants.PROCESSO_FECHADO_CODE );
|
|
context.commitChanges();
|
|
}
|
|
|
|
public Prestadores getDefaultPrestador()
|
|
{
|
|
return defaultPrestador;
|
|
}
|
|
|
|
public Collection<TrabalhadoresEcd> getPendingExamesForAnalisador( Prestadores currentAnalisador )
|
|
{
|
|
Map<TrabalhadoresEcd, TrabalhadoresEcd> resultMap = new HashMap<TrabalhadoresEcd, TrabalhadoresEcd>();
|
|
SelectQuery query = new SelectQuery( TrabalhadoresEcd.class, ExpressionFactory.matchExp(TrabalhadoresEcd.DATA_RECEPCAO_PROPERTY, null ));
|
|
List<TrabalhadoresEcd> all = context.performQuery( query );
|
|
for( TrabalhadoresEcd ecd : all )
|
|
{
|
|
TrabalhadoresEcdsDatas data = ecd.getToTrabalhadoresEcdsDatas();
|
|
if(new Integer(MedicinaConstants.ESTADO_REALIZADO).equals( data.getEstado()))
|
|
{
|
|
|
|
if(currentAnalisador.equals( ecd.getToAnalisador() ))
|
|
{
|
|
resultMap.put( ecd ,ecd );
|
|
}else if( Prestadores.prestadorNulo.equals( currentAnalisador ) && ecd.getToAnalisador() == null )
|
|
{
|
|
resultMap.put( ecd, ecd );
|
|
}
|
|
}
|
|
}
|
|
return resultMap.values();
|
|
}
|
|
|
|
|
|
}
|