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

/**
 * 
 * @author Adik
 */
@Repository("DiagnosaTindakanPasienDao")
public interface DiagnosaTindakanPasienDao extends PagingAndSortingRepository<DiagnosaTindakanPasien, String> {
	// custom query
	@Query("select model from DiagnosaTindakanPasien model where model.pasienDaftar.pasienDaftar.pasien.noCm=:noCm and model.tanggalPendaftaran=:tanggalPendaftaran")
	public List<DiagnosaTindakanPasien> findDiagnosaTindakanPasienByNoCmAndTglInput(@Param("noCm") String noCm,@Param("tanggalPendaftaran") Date tanggalPendaftaran);
	
	public List<DiagnosaTindakanPasien> findByPasienDaftarNoRec(String noRec);
	
	@Query("select a from DiagnosaTindakanPasien a where a.pasienDaftar.noRec=:noRec")
	public List<DiagnosaTindakanPasien> findDiagnosaTindakanPasienByAntrian(@Param("noRec") String noRec);
	
	@Query("select new Map(diagnosa.kdDiagnosaTindakan as kdDiagnosa, "+
			"diagnosa.namaDiagnosaTindakan as namaDiagnosa, "+
			"ruangan.namaRuangan as namaRuangan, "+
			"ruangan.id as idRuangan) "+
			"from DiagnosaTindakanPasien diagnosaTindakanPasien "+
			"left join diagnosaTindakanPasien.diagnosisTindakan diagnosis "+
			"left join diagnosis.diagnosaTindakan diagnosa "+
			"left join diagnosaTindakanPasien.pasienDaftar antrian  "+
			"left join antrian.pasienDaftar pasienDaftar "+
			"left join antrian.ruangan ruangan "+
			"where diagnosis.noRec is not null and  pasienDaftar.noRec = :noRecAntrian")
		public List<Map<String,Object>> getDiagnosaPasienByNoRecPasienDaftar(@Param("noRecAntrian")String noRec);


}
