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

@Repository("PraAnestesiDokterBedahHeaderDao")
public interface PraAnestesiDokterBedahHeaderDao extends PagingAndSortingRepository<PraAnestesiDokterBedahHeader, String>{
	/*
	 * Add show data to get header and detail
	 * add by iwankasan
	 * date : 27.10.2017
	 */
	@Query("select new map(praAnestesiDokterBedahHeader.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 PraAnestesiDokterBedahHeader praAnestesiDokterBedahHeader " +
			" left join PraAnestesiDokterBedahHeader.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>> getPraAnestesiDokterByNoRecAntrian(@Param("noRec") String noRec);
	
	@Query("select new map(praAnestesiDokterBedahHeader.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 PraAnestesiDokterBedahHeader praAnestesiDokterBedahHeader " +
			" left join PraAnestesiDokterBedahHeader.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 praAnestesiDokterBedahHeader.noRec=:noRec")
	List<Map<String, Object>> getPraAnestesiDokterByNoRec(@Param("noRec") String noRec);
	
	@Query("select new map(praAnestesiDokterBedah.noRec as noRec, " +
 			" praAnestesiDokterBedah.keterangan as keterangan, " +
			" praAnestesiDokterBedah.ketTambahan as ketTambahan, " +
			" praAnestesiDokterBedah.yesNo as yesNo, " +
			" praAnestesiDokterBedah.statusEnabled as statusEnabled, " +
			" praAnestesiDokter.id as id, " +
			" praAnestesiDokter.reportDisplay as reportDisplay) " +
 			" from PraAnestesiDokterBedah praAnestesiDokterBedah " +
 			" left join praAnestesiDokterBedah.praAnestesiDokterBedahHeader praAnestesiDokterBedahHeader " +
 			" left join praAnestesiDokterBedah.praAnestesiDokter praAnestesiDokter " +
 			" where praAnestesiDokterBedah.statusEnabled in('true') " +
 			" and praAnestesiDokterBedahHeader.noRec=:noRec")
 	List<Map<String, Object>> getPraAnestesiDokterDetail(@Param("noRec") String noRec); 
}
