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

@Repository("PemantauanAnestesiLokalDao")
public interface PemantauanAnestesiLokalDao extends PagingAndSortingRepository<AsuhanKeperawatanPeriOperatif, String>{
	@Query("select new map(a.id as id, a.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperatif a where a.flagAsuhan in ('Pemantauan Anestesi Lokal')")
	List<Map<String, Object>> getPemantaunAnestesiLokalHeader();
	
	@Query("select new map(a.id as id, a.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperatif a" +
			" where a.idParent in(275,286) and a.idParent=:id")
	List<Map<String, Object>> getPemantuanAnestesiLokalLevel1(@Param("id") int id);
	
	@Query("select new map(a.id as id, a.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperatif a where a.idParent in('294') and a.idParent=:id")
	List<Map<String, Object>> getPemantauanAnestesiLokalLevel2(@Param("id") int id);
	
	@Query("select new map(a.id as id, a.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperatif a where a.idParent in(295,309,323,337) and a.idParent=:id")
	List<Map<String, Object>> getPemantauanAnestesiLokalLevel3(@Param("id") int id);
	
	@Query("select new map(a.id as id, a.namaExternal as namaExternal) from AsuhanKeperawatanPeriOperatif a where a.id in(295,309,323,337)")
	List<Map<String, Object>> getTablePemantauanAnestesiLocalHeader();
	
	@Query("select new map(a.id as id, a.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperatif a where a.idParent in(295,309,323,337) and a.idParent=:id")
	List<Map<String, Object>> getTablePemantauanAnestesiLocalDetail(@Param("id") int id);
	
	@Query("select new map(a.id as id, a.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperatif a where a.id in(295,309,323,337)")
	List<Map<String, Object>> getTandaVital();
	
	@Query("select new map(a.noRec as noRec, a.noTrans as noTrans) " +
			" from AsuhanKeperawatanPeriOperasiHeader a " +
			" left join a.pasienDaftar antrian where " +
			" antrian.noRec=:noRec and a.noTrans like 'PA%'")
	List<Map<String, Object>> getPemantauanAnestesiByNoRecAntrian(@Param("noRec") String noRec);
	
	@Query("select new map(a.noTrans as noTrans, " +
			" a.tindakan as tindakan, a.noRec as noRec, " +
			" a.diagnosaPostOperasi as diagnosaPostOperasi, " +
			" a.operasiMulai as operasiMulai, a.operasiSelesai as operasiSelesai, " +
			" a.jamMasukOperasi as jamMasukOperasi, a.tanggal as tanggal, " +
			" a.jam as jam, dokterBedah.id as idDokterBedah, " +
			" dokterBedah.namaLengkap as nameDokterBedah, " +
			" asistenBedah.id as idAsistenBedah, " +
			" asistenBedah.namaLengkap as nameAsistenBedah, " +
			" perawatInstrumen1.id as idPerawatInstrumen1, " +
			" perawatInstrumen1.namaLengkap as namePerawatInstrumen1, " +
			" perawatInstrument2.id as idPerawatInstrumen2, " +
			" perawatInstrument2.namaLengkap as namePerawatInstrumen2, " +
			" perawatSirkuler.id as idPerawatSirkuler, " +
			" perawatSirkuler.namaLengkap as namePerawatSirkuler, " +
			" operatorAlatCanggih.id as idOperatorAlatCanggih, " +
			" operatorAlatCanggih.namaLengkap as nameOperatorAlatCanggih, " +
			" kelas.id as idKelas, kelas.namaKelas as namaKelas, " +
			" ruangan.id as idRuangan, ruangan.namaRuangan as namaRuangan, " +
			" pasien.jenisKelamin.jenisKelamin as jenisKelamin, " +
			" pasien.namaPasien as namaPasien, pasien.tglLahir as tglLahir, " +
			" pasien.noCm as noCm, alamats.alamatLengkap as alamatLengkap)" +
			" from AsuhanKeperawatanPeriOperasiHeader a " +
			" left join a.dokterBedah dokterBedah " +
			" left join a.asistenBedah asistenBedah " +
			" left join a.perawatInstrumen1 perawatInstrumen1 " +
			" left join a.perawatInstrument2 perawatInstrument2 " +
			" left join a.perawatSirkuler perawatSirkuler " +
			" left join a.operatorAlatCanggih operatorAlatCanggih " +
			" left join a.pasienDaftar antrian " +
			" left join antrian.ruangan ruangan " +
			" left join antrian.kelas kelas " +
			" left join antrian.pasienDaftar pasienDaftar " +
			" left join pasienDaftar.pasien pasien " +
			" left join pasien.alamats alamats " +
			" where a.statusEnabled in ('true') and a.noTrans=:notrans")
	Map<String, Object> getListAsuhanTransByNoTrans(@Param("notrans") String notrans);

	//keadaan bedah
	@Query("select new map(a.objekDataMasalahId as id, a.noRec as noRec, a.asuhankeperawatanHeaderId as noTrans, " +
			" b.id as dataMasalahId, a.keterangan as keterangan, b.flagAsuhan as flagAsuhan, " +
			" b.idParent as idParent, " +
			" b.flagHeader as flagHeader, b.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperasiTrans a left join a.objekDataMasalah b " +
			" where a.asuhankeperawatanHeaderId=:notrans and a.statusEnabled in ('true') and " +
			" b.flagAsuhan in('Keadaan Bedah')")
	List<Map<String, Object>> getListLaporanBedahTransByNoTrans(@Param("notrans") String notrans);
	
	//Pemeriksaan Fisik Bedah
	@Query("select new map(a.noRec as noRec, a.asuhankeperawatanHeaderId as noTrans, " +
			" b.id as id, a.keterangan as keterangan, b.flagAsuhan as flagAsuhan, " +
			" b.idParent as idParent, " +
			" b.flagHeader as flagHeader, b.namaExternal as namaExternal) " +
			" from AsuhanKeperawatanPeriOperasiTrans a left join a.objekDataMasalah b " +
			" where a.asuhankeperawatanHeaderId=:notrans and a.statusEnabled in ('true') and " +
			" b.flagAsuhan in('Pemeriksaan Fisik')")
	List<Map<String, Object>> getListFisikBedahTransByNoTrans(@Param("notrans") String notrans);
	
	//tanda-tanda vital
	@Query("select new map(a.noRec as noRec, " +
			" a.anestesiLokalId as noTrans," +
			" a.statusEnabled as statusEnabled,  " +
			" a.c15 as c15, a.c30 as c30, a.c35 as c35, " +
			" a.c45 as c45, a.c60 as c60, a.c75 as c75, a.c90 as c90, a.c105 as c105, " +
			" a.c120 as c120, a.c135 as c135, a.c165 as c165, " +
			" a.c180 as c180, a.c195 as c195," +
			" b.id as id, b.namaExternal as namaExternal) " +
			" from TandaVitalDetail a left join a.tandaVital b " +
			" where a.anestesiLokalId=:notrans and a.statusEnabled in ('true')")
	List<Map<String, Object>> getListTandaVitalTransByNoTrans(@Param("notrans") String notrans);


}
