package com.jasamedika.medifirst2000.dao;

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

@Repository("LaporanUjiHasilDao")
public interface LaporanUjiHasilDao extends PagingAndSortingRepository<LaporanUjiHasil, String> {
	
	@Query("select model from LaporanUjiHasil model where date(model.tanggalPenerimaanContoh) between date(:periodeAwal) and date(:periodeAkhir)")
	public List<LaporanUjiHasil> findByPeriode(@Param("periodeAwal") String periodeAwal,@Param("periodeAkhir") String periodeAkhir);

	@Query("select new map("
			+ " coalesce(p.contohDari,'-') as contohDari,"
			+ " coalesce(p.jenisContoh,'-') as jenisContoh,"
			+ " coalesce(p.nomorContoh,'-') as nomorContoh,"
			+ " coalesce(rekanan.namaRekanan,'namaRekanan') as namaRekanan,"
			+ " coalesce(p.jenisContoh,'-') as jenisContoh,"
			+ " coalesce(p.tanggalPenerimaanContoh,null) as tanggalPenerimaanContoh,"
			+ " coalesce(p.tanggalPengujianContohFrom,null) as tanggalPengujianContohFrom,"
			+ " coalesce(p.tanggalPengujianContohTo,null) as tanggalPengujianContohTo,"
			+ " coalesce(p.tipeLokasi,'-') as tipeLokasi,"
			+ " coalesce(p.uraianContoh,'-') as uraianContoh )"
			+ " from LaporanUjiHasil p"
			+ " left join p.rekanan rekanan where p.noRec=:noRec ")
	public Map<String,Object> findLaporanUjiHasilById(@Param("noRec") String noRec);

}
