package com.jasamedika.medifirst2000.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.PapAlergi;

/**
 * Repository class for PAPAlergi
 * 
 * @author Askur
 */
@Repository("PapAlergiDao")
public interface PapAlergiDao extends PagingAndSortingRepository<PapAlergi, String> {
	@Query("select model from PapAlergi model where model.pasienDaftar.pasienDaftar.pasien.noCm=:noCm and model.tglInput=:tglInput")
	public PapAlergi findPapAlergiByNoCmAndTglInput(@Param("noCm") String noCm,@Param("tglInput") Date tglInput);
	@Query("select Count(model) from PapAlergi model where model.pasienDaftar.noRec =:noRec")
	public Integer findByCountAntrian(@Param("noRec")String noRec);
	
	@Query("select model.alergi.namaAlergi, model.reaksi, model.alergiId, model.keteranganData from PapAlergi model where model.pasienDaftar.pasienDaftar.pasien.noCm=:noCm and to_char(model.tglInput,'yyyy-MM-dd')=:tglInput")
	public List<Object[]> findPapAlergiByNoCmAndTglInput(@Param("noCm") String noCm,@Param("tglInput") String tglInput);
	
	@Query("select model.alergi.namaAlergi, model.reaksi, model.alergiId, model.keteranganData from PapAlergi model where model.pasienDaftar.pasienDaftar.pasien.noCm=:noCm")
	public List<Object[]> findPapAlergiByNoCm(@Param("noCm") String noCm);
	
	@Query("select new Map(model.keteranganData as namaAlergi) "
			+"from PapAlergi model " 
			+"left join model.pasienDaftar pasiendaftar "
			+"where pasiendaftar.noRec=:noRecAntrian")
		public List<Map<String,Object>> getAlergisByNoRec(@Param("noRecAntrian")String noRec);

}
