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

@Repository("BatalRegistrasiDao")
public interface BatalRegistrasiDao extends PagingAndSortingRepository<BatalRegistrasi, String> {
	
	@Query(" select batal.noRec "+
			"from BatalRegistrasi batal "+
			"left join batal.pasienDaftar pasienDaftar "+
			"where pasienDaftar.noRec = :noRec ")
	public List<String> findBatalRegistrasi(@Param("noRec") String noRec);
	
	@Query(" select new map (pelayanan.noRec as noRec, struk.nostruk as noStruk, sbm.nosbm as noSbm) "+
			"from PelayananPasien pelayanan "+
			"left join pelayanan.pasienDaftar antrian "+
			"left join antrian.pasienDaftar pasienDaftar "+
			"left join pelayanan.strukPelayanan struk "+
			"left join struk.nosbmlast sbm "+
			"where pasienDaftar.noRec = :noRec ")
	public List<Map<String,Object>> findPasienInPelayananPasien(@Param("noRec") String noRec);
	
	@Query(" select new map (batal.alasanPembatalan as alasan, "+
			"to_char(batal.tanggalPembatalan, 'dd-mm-yyyy HH:mm') as tanggalPembatalan, "+
			"pembatal.name as pembatal, "+
			"pembatal.id as idPembatal, "+
			"pegawai.namaLengkap as pegawai, "+
			"pegawai.id as idPegawai, "+
			"pasienDaftar.noRec as noRecPasienDaftar) "+
			"from BatalRegistrasi batal "+
			"left join batal.pembatalan pembatal "+
			"left join batal.pegawai pegawai "+
			"left join batal.pasienDaftar pasienDaftar "+
			"where to_char(batal.tanggalPembatalan, 'dd-mm-yyyy') between :startDate and :endDate ")
	public List<Map<String,Object>> findPembatalan(@Param("startDate") String startDate,@Param("endDate") String endDate);


}
