package com.jasamedika.medifirst2000.dao.custom;

import java.util.Date;
import java.util.List;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import com.jasamedika.medifirst2000.dao.custom.base.impl.CoreDaoImpl;
import com.jasamedika.medifirst2000.entities.HasilTriase;
import com.jasamedika.medifirst2000.util.CommonUtil;

/**
 * Repository Custom class
 * 
 * @author Adik
 * @param <T>
 */
@Repository
public class HasilTriaseDaoCustomImpl extends CoreDaoImpl<HasilTriase> implements HasilTriaseDaoCustom {

	public HasilTriaseDaoCustomImpl() {
		super(HasilTriase.class);
	}
	

	@Override
	public List<HasilTriase> findAllHasilTriasePagingList(String noRec, Date startDate, Date endDate) {
		
		StringBuffer buffer = new StringBuffer();
		buffer.append("select x from HasilTriase x where x.id IS NOT NULL ");
		if(CommonUtil.isNotNullOrEmpty(startDate) && CommonUtil.isNotNullOrEmpty(endDate)){
			buffer.append("and x.tanggalMasuk between :startDate and :endDate  ");
		}
		if(CommonUtil.isNotNullOrEmpty(noRec)) {
			buffer.append("and x.noRec=:noRec ");
		}
		Query query = em.createQuery(buffer.toString());
		if(CommonUtil.isNotNullOrEmpty(startDate) && CommonUtil.isNotNullOrEmpty(endDate)){
			query.setParameter("startDate", startDate);
			query.setParameter("endDate", endDate);
		}
		if(CommonUtil.isNotNullOrEmpty(noRec)) {
			query.setParameter("noRec", noRec);
		}
		return (List<HasilTriase>) query.getResultList();
	}
	
	


}
