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.PengkajianAwalTransaksi;

@Repository("PengkajianAwalTransaksiDao")
public interface PengkajianAwalTransaksiDao extends PagingAndSortingRepository<PengkajianAwalTransaksi, String>{
	
	@Query("select a.noRec from PengkajianAwalTransaksi a "
			+ "left join a.pengkajianAwalBaru b "
			+ "where b.noRec=:noRec ")
	String getNoRecByPap(
			@Param("noRec") String noRec);
	
	@Query("select a.noRec from PengkajianAwalTransaksi a "
			+ "left join a.pengkajianLanjutan b "
			+ "where b.noRec=:noRec ")
	String getNoRecByPLanjutan(
			@Param("noRec") String noRec);

	@Query("select a.nilai from DetailPengkajianAwal a "
			+ "left join a.pengkajianAwal b "
			+ "left join a.pengkajianAwalTransaksi c "
			+ "left join c.pengkajianAwalBaru e "
			+ "where b.id=:id and e.noRec=:noRec ")
	String getNilaiDetail(
			@Param("id") Integer id, 
			@Param("noRec") String noRec);
	@Query("select a.nilai from DetailPengkajianAwal a "
			+ "left join a.pengkajianAwal b "
			+ "left join a.pengkajianAwalTransaksi c "
			+ "left join c.pengkajianLanjutan e "
			+ "where b.id=:id and e.noRec=:noRec ")
	String getNilaiDetailLanjutan(
			@Param("id") Integer id, 
			@Param("noRec") String noRec);
	@Query("select a.nilai from DetailPengkajianAwal a "
			+ "left join a.pengkajianAwal b "
			+ "left join a.pengkajianAwalTransaksi c "
			+ "left join c.pengkajianAwalBaru e "
			+ "where b.id=:id and e.noRec=:noRec ")
	List<String> getNilaiDetailList(
			@Param("id") Integer id, 
			@Param("noRec") String noRec);
	
	@Query("select a.nilai from DetailPengkajianAwal a "
			+ "left join a.pengkajianAwal b "
			+ "left join a.pengkajianAwalTransaksi c "
			+ "left join c.pengkajianLanjutan e "
			+ "where b.id=:id and e.noRec=:noRec ")
	List<String> getNilaiDetailListLanjutan(
			@Param("id") Integer id, 
			@Param("noRec") String noRec);
	
}
