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

@Repository("PraAnestesiDao")
public interface PraAnestesiDao extends PagingAndSortingRepository<PraAnestesi, String> {
	//date : 25.08.2017
	//author : iwankasan
	//menampilkan master praAnestesi
	//untuk pasien diberikan flag = 0
	//show data get master anestesi for pasien
	@Query("select new map(a.noUrut as noUrut, a.Keterangan as keterangan, a.reportDisplay as reportDisplay, "
			+ " a.flagPaseinDokter as flagPasein, a.headerNo as headerNo, a.id as id) "
			+ " from PraAnestesi a where a.flagPaseinDokter in(0)")
	List<Map<String, Object>> getPraAnestesiPasien();
	
	//date : 29.08.2017
	//author : iwankasan
	//get pasien yang hanya memiliki rencanaoperasi
	//data pasien diget dari nocm RencanaOperasi
	//flag untuk penanda pasien yang sudah dioperasi blm di-set, sehingga pasien akan ditampilkan semua
	@Query("select new map(d.id as pasienId, case when (d.jenisKelaminId = 1) then ('Laki-Laki')"
			+ " when (d.jenisKelaminId = 2) then ('Perempuan') end as jenisKelamin, "
			+ " d.tglLahir as tglLahir, d.namaPasien as namaPasien"
			+ " ) from RencanaOperasi a, AntrianPasienDiPeriksa b, PasienDaftar c, Pasien d where "
			+ " a.noCmId = b.noRec and b.pasienDaftarId = c.noRec and c.pasienId = d.id")
	List<Map<String, Object>> getPasienByRencanaOperasi();
	
	//date : 29.08.2017
	//author : iwankasan
	//show data pasien yang sudah difilter berdasarkan getPasienByRencanaOperasi
	@Query("select new map(d.id as pasienId, case when (d.jenisKelaminId = 1) then ('Laki-Laki')"
			+ " when (d.jenisKelaminId = 2) then ('Perempuan') end as jenisKelamin, "
			+ " d.tglLahir as tglLahir, d.namaPasien as namaPasien"
			+ " ) from RencanaOperasi a, AntrianPasienDiPeriksa b, PasienDaftar c, Pasien d where "
			+ " a.noCmId = b.noRec and b.pasienDaftarId = c.noRec and c.pasienId = d.id and d.id =:id")
	Map<String, Object> getPasienById(@Param("id") int id);
	
	//pra-anestedi/sedasi
	//author : iwankasan
	//get dokter anestesi perawat
	//untuk dokter/perawat flag =1
	//header
	@Query("select new map(a.id as id, a.reportDisplay as namaExternal, " +
			" a.Keterangan as keterangan) from PraAnestesi " +
			" a where a.flagPaseinDokter in(1) and a.headerNo is null")
	List<Map<String, Object>> getPraAnestesiPerawatHeader();
	
	
	//pra-anestedi/sedasi
	//author : iwankasan
	//get dokter anestesi perawat
	//untuk dokter/perawat flag =1
	//detail
	@Query("select new map(a.id as id, a.reportDisplay as namaExternal, " +
			" a.Keterangan as keterangan) from " +
			" PraAnestesi a where a.flagPaseinDokter in(1) " +
			" and a.headerNo in(35,52,66) and a.headerNo=:id")
	List<Map<String, Object>> getPraAnestesiPerawatDetail(@Param("id") int id);
	
	//pra-anestedi/sedasi
	//author : iwankasan
	//get dokter anestesi perawat
	//untuk dokter/perawat flag =1
	//detail
	@Query("select new map(a.id as id, a.reportDisplay as namaExternal, " +
			" a.Keterangan as keterangan) from " +
			" PraAnestesi a where a.flagPaseinDokter in(1) " +
			" and a.headerNo in(67,70,76,81,91,96,103) and a.headerNo=:id")
	List<Map<String, Object>> getPraAnestesiPerawatDetailLevel1(@Param("id") int id);
	
	
	//pra-anestedi/sedasi
	//author : iwankasan
	//get dokter anestesi perawat
	//untuk dokter/perawat flag =1
	//detail level 1
	@Query("select new map(a.id as id, a.reportDisplay as namaExternal, " +
			" a.Keterangan as keterangan) from " +
			" PraAnestesi a where a.flagPaseinDokter in(1) " +
			" and a.headerNo in(70,99,104,107,110) and a.headerNo=:id")
	List<Map<String, Object>> getPraAnestesiPerawatDetailLevel2(@Param("id") int id);
	
	
	
	/*
	//pra-anestedi/sedasi
	//author : iwankasan
	//get dokter anestesi perawat
	//untuk dokter/perawat flag =1
	//header Perencanaan
	@Query("select new map(a.id as id, a.reportDisplay as namaExternal, " +
			" a.Keterangan as keterangan) from PraAnestesi " +
			" a where a.flagPaseinDokter in(1) a.id in(66) and a.headerNo is null")
	List<Map<String, Object>> getPraAnestesiPerawatPerencanaanHeader();
	
	//pra-anestedi/sedasi
	//author : iwankasan
	//get dokter anestesi perawat
	//untuk dokter/perawat flag =1
	//child-level-1 Perencanaan
	@Query("select new map(a.id as id, a.reportDisplay as namaExternal, " +
			" a.Keterangan as keterangan) from PraAnestesi " +
			" a where a.flagPaseinDokter in(1) a.headerNo in(66)")
	List<Map<String, Object>> getPraAnestesiPerawatPerencanaanLevel1();
	*/
}
