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

@Repository("PraAnestesiPasienHeaderDao")
public interface PraAnestesiPasienHeaderDao  extends PagingAndSortingRepository<PraAnestesiPasienHeader, String>{
	/*
	 * Add show data to get header and detail
	 * add by iwankasan
	 * date : 27.10.2017
	 */
	@Query("select new map(praAnestesiPasienHeader.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 PraAnestesiPasienHeader praAnestesiPasienHeader " +
			" left join praAnestesiPasienHeader.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>> getPraAnestesiPasienByNoRecAntrian(@Param("noRec") String noRec);
	
	@Query("select new map(praAnestesiPasienHeader.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 PraAnestesiPasienHeader praAnestesiPasienHeader " +
			" left join praAnestesiPasienHeader.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 praAnestesiPasienHeader.noRec=:noRec")
	List<Map<String, Object>> getPraAnestesiPasienByNoRec(@Param("noRec") String noRec);
	
	@Query("select new map(praAnestesiPasienBedah.noRec as noRec, " +
 			" praAnestesiPasienBedah.keterangan as keterangan, " +
			" praAnestesiPasienBedah.ketTambahan as ketTambahan, " +
 			" praAnestesiPasienBedah.ketTambahan2 as ketTambahan2, " +
			" praAnestesiPasienBedah.ketTambahan3 as ketTambahan3, " +
			" praAnestesiPasienBedah.yesNo as yesNo, " +
			" praAnestesiPasienBedah.yesNo as yesNo, " +
			" praAnestesiPasienBedah.statusEnabled as statusEnabled, " +
			" praAnestesiPasien.id as id, " +
			" praAnestesiPasien.reportDisplay as reportDisplay, " +
 			" praAnestesiPasienHeader.noRec as noRecHeader)" +
 			" from PraAnestesiPasienBedah praAnestesiPasienBedah " +
 			" left join praAnestesiPasienBedah.praAnestesiPasienHeader praAnestesiPasienHeader " +
 			" left join praAnestesiPasienBedah.praAnestesiPasien praAnestesiPasien " +
 			" where praAnestesiPasienBedah.statusEnabled in('true') " +
 			" and praAnestesiPasienHeader.noRec=:noRec")
 	List<Map<String, Object>> getPraAnestesiPasienDetail(@Param("noRec") String noRec);

}
