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

@Repository("admisiRencanaPindahRuanganDao")
public interface AdmisiRencanaPindahRuanganDao extends PagingAndSortingRepository<AdmisiRencanaPindahRuangan, String>{

	@Query("select NEW Map("
			+ "a.noRec as noRecAdmisi, "
			+ "a.tglKeluarRencana as tglKeluarRencana, "
			+ "k.id as kelasRencanaId, "
			+ "l.id as ruanganRencanaId, "
			+ "m.id as kelasKamarRencanaId, "
			+ "a.noBedRencana as noBedRencana, "
			+ "a.keteranganLainya as keteranganLainya, "
			+ "n.id as kelasAwalId, "
			+ "o.id as ruanganAwalId, "
			+ "p.id as kelasKamarAwalId, "
			+ "c.noRec as noRecPasienDaftar, "
			+ "d.noCm as noCm, "
			+ "d.namaPasien as namaPasien, "
			+ "o.namaRuangan as ruanganAsal, "
			+ "n.namaKelas as kelasPerawatan, "
			+ "j.statusKeluar as status, "
			+ "i.jenisTarif as tipePambayaran, "
			+ "b.noRec as noRecAntrian) "
			+ "from AdmisiRencanaPindahRuangan a "
			+ "left join a.registrasiPelayananPasien b "
			+ "left join b.pasienDaftar c "
			+ "left join c.pasien d "
			+ "left join c.ruangan e "
			+ "left join c.kelas f "
			+ "left join c.kelompokPasien g "
			+ "left join c.statusKeluar h "
			+ "left join g.jenisTarif i "
			+ "left join a.statusKeluarRencana j "
			+ "left join a.kelasRencana k "
			+ "left join a.ruanganRencana l "
			+ "left join a.kelasKamarRencana m "
			+ "left join a.kelasAwal n "
			+ "left join a.ruanganAwal o "
			+ "left join a.kelasKamarAwal p "
			+ "where to_char(a.tglKeluarRencana,'yyyy-MM-dd') between :startDate and :endDate")
	List<Map<String, Object>> getDataGrid(@Param("startDate") String startDate,@Param("endDate") String endDate);
	
	@Query("select NEW Map("
			+ "a.noRec as noRecAdmisi, "
			+ "a.tglKeluarRencana as tglKeluarRencana, "
			+ "k.id as kelasRencanaId, "
			+ "l.id as ruanganRencanaId, "
			+ "m.id as kelasKamarRencanaId, "
			+ "a.noBedRencana as noBedRencana, "
			+ "a.keteranganLainya as keteranganLainya, "
			+ "n.id as kelasAwalId, "
			+ "o.id as ruanganAwalId, "
			+ "p.id as kelasKamarAwalId, "
			+ "c.noRec as noRecPasienDaftar, "
			+ "d.noCm as noCm, "
			+ "d.namaPasien as namaPasien, "
			+ "e.namaRuangan as ruanganAsal, "
			+ "f.namaKelas as kelasPerawatan, "
			+ "j.statusKeluar as status, "
			+ "i.jenisTarif as tipePambayaran, "
			+ "b.noRec as noRecAntrian) "
			+ "from AdmisiRencanaPindahRuangan a "
			+ "left join a.registrasiPelayananPasien b "
			+ "left join b.pasienDaftar c "
			+ "left join c.pasien d "
			+ "left join c.ruangan e "
			+ "left join c.kelas f "
			+ "left join c.kelompokPasien g "
			+ "left join c.statusKeluar h "
			+ "left join g.jenisTarif i "
			+ "left join a.statusKeluarRencana j "
			+ "left join a.kelasRencana k "
			+ "left join a.ruanganRencana l "
			+ "left join a.kelasKamarRencana m "
			+ "left join a.kelasAwal n "
			+ "left join a.ruanganAwal o "
			+ "left join a.kelasKamarAwal p "
			+ "where a.noRec=:noRec")
	Map<String, Object> getOneDataGrid(@Param("noRec") String noRec);
}
