package com.jasamedika.medifirst2000.dao;

import java.util.List;

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.KeteranganSurvey;
import com.jasamedika.medifirst2000.entities.MappingPertanyaanToKeterangan;
import com.jasamedika.medifirst2000.entities.PertanyaanSurvey;

@Repository("MappingPertanyaanToKeteranganDao")
public interface MappingPertanyaanToKeteranganDao extends PagingAndSortingRepository<MappingPertanyaanToKeterangan, String>{
	
	@Query("select p.jumlah from MappingPertanyaanToKeterangan p where p.pertanyaanSurvey.id=:idPertanyaan and p.keteranganSurvey.id=:idKeterangan ")
	public Integer getJumlahByPertanyaanDanKeterangan(@Param("idPertanyaan") Integer idPertanyaan, @Param("idKeterangan") Integer idKeterangan);
	
	@Query("select p from MappingPertanyaanToKeterangan p where p.pertanyaanSurvey.id=:idPertanyaan and p.keteranganSurvey.id=:idKeterangan ")
	public MappingPertanyaanToKeterangan getByPertanyaanDanKeterangan(@Param("idPertanyaan") Integer idPertanyaan, @Param("idKeterangan") Integer idKeterangan);
	
	@Query("select distinct(p.pertanyaanSurvey) from MappingPertanyaanToKeterangan p ")
	public List<PertanyaanSurvey> getPertanyaanSurveyFromMapping();
	
	@Query("select p from MappingPertanyaanToKeterangan p where p.pertanyaanSurvey.id=:id")
	public List<MappingPertanyaanToKeterangan> getMappingByIdPertanyaan(@Param("id") Integer id);
	
	@Query("select p.keteranganSurvey from MappingPertanyaanToKeterangan p where p.noRec=:noRec")
	public KeteranganSurvey getKeteranganSurveyByNorecMapping(@Param("noRec") String noRec);
	
}
