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

/**
 * @author Shakato
 */
@Repository("CheckOutOperationDao")
public interface CheckOutOperationDao extends PagingAndSortingRepository<CheckOutOperation, Integer> {
	@Query("select new map(a.id as id, a.name as name) from KesadaranCheckOut a")
	List<Map<String, Object>> getKesadaranCheckOut();
	
	@Query("select new map(a.id as id, a.name as name) from KelengkapanCheckOut a")
	List<Map<String, Object>> getKelengkapanCheckOut();
	
	/*
	 * Add show data to get
	 * add by iwankasan
	 * date : 27.10.2017
	 */
	@Query("select new map(checkOutOperation.noRec as noRec, " +
			" antrian.noRec as noRecAntrian, " +
			" checkOutOperation.jam as jam, " +
			" antrian.tglRegistrasi as tglRegistrasi, " +
			" kelas.id as idKelas, kelas.namaKelas as namaKelas, " +
			" ruangan.id as idRuangan, ruangan.namaRuangan as namaRuangan, " +
			" pegawai.id as idPegawai, pegawai.namaLengkap as namaPegawai, " +
			" pasien.jenisKelamin.jenisKelamin as jenisKelamin, " +
			" pasien.namaPasien as namaPasien, " +
			" pasien.noCm as noCm, alamats.alamatLengkap as alamatLengkap) " +
			" from CheckOutOperation checkOutOperation " +
			" left join checkOutOperation.pasienDaftar antrian " +
			" left join antrian.ruangan ruangan " +
			" left join antrian.kelas as kelas " +
			" left join antrian.pegawai pegawai " +
			" left join antrian.pasienDaftar pasienDaftar " +
			" left join pasienDaftar.pasien pasien " +
			" left join pasien.alamats alamats where checkOutOperation.noRec=:noRec")
	List<Map<String, Object>> getCheckOutByNoRec(@Param("noRec") String noRec);
	
	@Query("select new map(checkOutOperation.noRec as noRec, " +
			" antrian.noRec as noRecAntrian, " +
			" checkOutOperation.jam as jam, " +
			" antrian.tglRegistrasi as tglRegistrasi, " +
			" kelas.id as idKelas, kelas.namaKelas as namaKelas, " +
			" ruangan.id as idRuangan, ruangan.namaRuangan as namaRuangan, " +
			" pegawai.id as idPegawai, pegawai.namaLengkap as namaPegawai, " +
			" pasien.jenisKelamin.jenisKelamin as jenisKelamin, " +
			" pasien.namaPasien as namaPasien, " +
			" pasien.noCm as noCm, alamats.alamatLengkap as alamatLengkap) " +
			" from CheckOutOperation checkOutOperation " +
			" left join checkOutOperation.pasienDaftar antrian " +
			" left join antrian.ruangan ruangan " +
			" left join antrian.kelas as kelas " +
			" left join antrian.pegawai pegawai " +
			" left join antrian.pasienDaftar pasienDaftar " +
			" left join pasienDaftar.pasien pasien " +
			" left join pasien.alamats alamats where antrian.noRec=:noRec")
	List<Map<String, Object>> getCheckOutByNoRecAntrian(@Param("noRec") String noRec);

 	@Query("select new map(kesadaranCheckOutDetail.noRec as noRec, " +
 			" kesadaranCheckOutDetail.status as status, " +
 			" checkOutOperation.noRec as noRecCheckOutOperation, " +
 			" kesadaranCheckOut.id as idKesadaranCheckOut, " +
 			" kesadaranCheckOut.name as nameKesadaranCheckOut) " +
 			" from KesadaranCheckOutDetail kesadaranCheckOutDetail " +
 			" left join kesadaranCheckOutDetail.checkOutOperation checkOutOperation " +
 			" left join kesadaranCheckOutDetail.kesadaranCheckOut kesadaranCheckOut where checkOutOperation.noRec=:noRec")
 	List<Map<String, Object>> getKesadaranCheckOutDetail(@Param("noRec") String noRec);
 	
 	
 	@Query("select new map(kelengkapanCheckOutDetail.noRec as noRec, " +
 			" kelengkapanCheckOutDetail.keterangan as keterangan, " +
 			" checkOutOperation.noRec as noRecCheckOutOperation, " +
 			" kelengkapanCheckOut.id as idKelengkapanCheckOut, " +
 			" kelengkapanCheckOut.name as namekelengkapanCheckOut, " +
 			" statusYaTidak.id as idStatusYaTidak, " +
 			" statusYaTidak.name as nameStatusYaTidak) " +
 			" from KelengkapanCheckOutDetail kelengkapanCheckOutDetail " +
 			" left join kelengkapanCheckOutDetail.checkOutOperation checkOutOperation " +
 			" left join kelengkapanCheckOutDetail.kelengkapanCheckOut kelengkapanCheckOut " +
 			" left join kelengkapanCheckOutDetail.statusYaTidak statusYaTidak " +
 			" where checkOutOperation.noRec=:noRec")
 	List<Map<String, Object>> getKelengkapanCheckOutDetail(@Param("noRec") String noRec);
 	
 	@Query("select new map(pemeriksaanCheckOutDetail.noRec as noRec, " +
 			" pemeriksaanCheckOutDetail.keterangan as keterangan, " +
 			" checkOutOperation.noRec as noRecCheckOutOperation, " +
 			" pemeriksaanCheckOut.id as idpemeriksaanCheckOut, " +
 			" pemeriksaanCheckOut.name as namePemeriksaanCheckOut, " +
 			" statusYaTidak.id as idStatusYaTidak, " +
 			" statusYaTidak.name as nameStatusYaTidak) " +
 			" from PemeriksaanCheckOutDetail pemeriksaanCheckOutDetail " +
 			" left join pemeriksaanCheckOutDetail.checkOutOperation checkOutOperation " +
 			" left join pemeriksaanCheckOutDetail.pemeriksaanCheckOut pemeriksaanCheckOut " +
 			" left join pemeriksaanCheckOutDetail.statusYaTidak statusYaTidak where checkOutOperation.noRec=:noRec")
 	List<Map<String, Object>> getPemeriksaanCheckOutDetailDetail(@Param("noRec") String noRec);
 	
 	@Query("select new map(pemasanganCheckOutDetail.noRec as noRec, " +
 			" pemasanganCheckOutDetail.keterangan as keterangan, " +
 			" checkOutOperation.noRec as noRecCheckOutOperation, " +
 			" pemasanganCheckOut.id as idPemasanganCheckOut, " +
 			" pemasanganCheckOut.name as namePemasanganCheckOut, " +
 			" statusYaTidak.id as idStatusYaTidak, " +
 			" statusYaTidak.name as nameStatusYaTidak) " +
 			" from PemasanganCheckOutDetail pemasanganCheckOutDetail " +
 			" left join pemasanganCheckOutDetail.checkOutOperation checkOutOperation " +
 			" left join pemasanganCheckOutDetail.pemasanganCheckOut pemasanganCheckOut " +
 			" left join pemasanganCheckOutDetail.statusYaTidak statusYaTidak where checkOutOperation.noRec=:noRec")
 	List<Map<String, Object>> getPemasanganCheckOutDetail(@Param("noRec") String noRec);
 	

}
