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

@Repository("TimeOutControlDao")
public interface TimeOutControlDao extends PagingAndSortingRepository<TimeOutControl, String> {
	
		@Query("select new map(timeOutControl.noRec as noRec, " +
			" timeOutControl.halKhusus as halKhusus, " +
			" timeOutControl.namaAntibiotik as namaAntibiotik, " +
			" timeOutControl.dosisAntibiotik as dosisAntibiotik, " +
			" timeOutControl.fotoRadiologi.id as idFotoRadiologi, " +
			" timeOutControl.fotoRadiologi.name as nameFotoRadiologi, " +
			" timeOutControl.statusAntibiotikProfilaksis.id as idStatusAntiBiotikPro, " +
			" timeOutControl.statusAntibiotikProfilaksis.name as nameStatusAntiBiotikPro," +
			" antrian.noRec as noRecAntrian, " +
			" 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 TimeOutControl timeOutControl " +
			" left join timeOutControl.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 timeOutControl.noRec=:noRec")
	List<Map<String, Object>> getTimeOutByNoRec(@Param("noRec") String noRec);
	
	@Query("select new map(timeOutControl.noRec as noRec, " +
			" antrian.noRec as noRecAntrian, " +
			" 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 TimeOutControl timeOutControl " +
			" left join timeOutControl.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>> getTimeOutByNoRecAntrian(@Param("noRec") String noRec);



	@Query("select new map(pelaksana.noRec as noRec, " +
 			" timeOutControl.noRec as noRecTimeOutControl, " +
 			" jenisPegawai.id as idJenisPegawai, " +
 			" jenisPegawai.jenisPegawai as jenisPegawai, " +
 			" namaPelaksana.id as idPegawai, " +
 			" namaPelaksana.namaLengkap as namaPegawai) " +
 			" from Pelaksana pelaksana " +
 			" left join pelaksana.timeOutControl timeOutControl " +
 			" left join pelaksana.jenisPegawai jenisPegawai " +
 			" left join pelaksana.namaPelaksana namaPelaksana " +
 			" where timeOutControl.noRec=:noRec")
 	List<Map<String, Object>> getPelaksanaDetail(@Param("noRec") String noRec);
 
}
