package siprp.medicina.exames.logic;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import leaf.ui.LeafLogic;
import siprp.database.cayenne.objects.Prestadores;
import siprp.database.cayenne.objects.TrabalhadoresEcd;
import siprp.database.cayenne.providers.MedicinaDAO;
import siprp.medicina.processo.data.TrabalhadoresEcdData;

public class RecepcaoExamesLogic extends LeafLogic
{
	
	@Action(isSave=true)
	public final static String ACTION_SELECT_ANALISADOR = "ACTION_SELECT_ANALISADOR";
	
	@Action(isSave=false)
	public final static String ACTION_SELECT_EXAME = "ACTION_SELECT_EXAME";
	
	@Action(isSave=false)
	public final static String ACTION_FILL_EXAMES = "ACTION_FILL_EXAMES";
	
	@Action(isSave=true)
	public final static String ACTION_RECEBER_EXAMES = "ACTION_RECEBER_EXAMES";
	
	@Action(isSave=false)
	public final static String ACTION_SORT = "ACTION_SORT";
	
	public Prestadores currentAnalisador = null;
	
	private MedicinaDAO dao = new MedicinaDAO();
	
	@LeafLogicActionBinding(actions=ACTION_SELECT_ANALISADOR)
	public void getExamesForAnalisador(Prestadores analisador)
	{
		currentAnalisador = analisador;
		if(analisador != null)
		{
			Collection<TrabalhadoresEcd> result = dao.getPendingExamesForAnalisador(currentAnalisador);
			runAction( ACTION_FILL_EXAMES, result );
		}
	}
	
	@LeafLogicActionBinding(actions=ACTION_RECEBER_EXAMES)
	public void receberExames(List<TrabalhadoresEcd> ecds)
	{
		if(ecds != null)
		{
			for( TrabalhadoresEcd ecd : ecds )
			{
				dao.saveObject( ecd );
			}
		}
	}
	
}
