package com.jasamedika.medifirst2000.dao;

import java.util.Date;
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.PapKeluhanUtama;

/**
 * Repository class for PAPCatatan
 * 
 * @author Askur
 */
@Repository("PapKeluhanUtamaDao")
public interface PapKeluhanUtamaDao extends PagingAndSortingRepository<PapKeluhanUtama, String> {
	
	@Query("select model from PapKeluhanUtama model where model.pasienDaftar.pasienDaftar.pasien.noCm=:noCm and model.tglInput=:tglInput")
	public PapKeluhanUtama findPapKeluhanUtamaByNoCmAndTglInput(@Param("noCm") String noCm,@Param("tglInput") Date tglInput);
	
	@Query("select a.keluhanUtama, to_char(a.tglInput,'dd-MM-yyyy'), to_char(a.pasienDaftar.tglRegistrasi,'dd-MM-yyyy'), a.pasienDaftar.ruangan.namaRuangan from PapKeluhanUtama a where a.pasienDaftar.pasienDaftar.pasien.noCm=:noCm")
	public List<Object[]> findPapKeluhanUtamaByNoCm(@Param("noCm") String noCm);
	
	@Query("select a.keluhanUtama, to_char(a.tglInput,'dd-MM-yyyy'), to_char(a.pasienDaftar.tglRegistrasi,'dd-MM-yyyy'), a.pasienDaftar.ruangan.namaRuangan from PapKeluhanUtama a where a.pasienDaftar.pasienDaftar.pasien.noCm=:noCm and to_char(a.tglInput,'yyyy-MM-dd')=:tglInput")
	public List<Object[]> findPapKeluhanUtamaByNoCmAndTglInput(@Param("noCm") String noCm,@Param("tglInput") String tglInput);

	public PapKeluhanUtama findByPasienDaftarNoRec(String noRec);		

	@Query("select model from PapKeluhanUtama model where model.pasienDaftar.pasienDaftar.pasien.noCm=:noCm and model.tglInput=:tglInput")
	public List<PapKeluhanUtama> findPapKeluhanUtamaByNoCmAndTglInputList(@Param("noCm") String noCm,@Param("tglInput") Date tglInput);

}
