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

/**
 * Repository class for TransferPasienInternal
 * 
 * @author Askur
 */
@Repository("TransferPasienInternalDao")
public interface TransferPasienInternalDao extends PagingAndSortingRepository<TransferPasienInternal, String> {
	
	@Query("select NEW map (peralatan.name as namaPeralatan, "+
			"peralatan.id as id) "+
			"from Peralatan peralatan "+
			"where peralatan.metodePemindahanPasien is :values ")
	List<Map<String,Object>> findPeralatan(@Param("values") Boolean values);
	
	@Query("select transferPasienInternal.noRec  "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.pasienDaftar antrianPasien "+
			"where antrianPasien.noRec =:values ")
	String findTransferPasienInternal(@Param("values") String values);
	
	@Query("select pasienDaftar.noRegistrasi "+
			"from AntrianPasienDiPeriksa antrian "+
			"left join antrian.pasienDaftar pasienDaftar "+
			"where antrian.noRec =:noRec ")
	String findNoRegistrasi(@Param("noRec") String noRec);
	
	/*@Query("select new map (model.checked as checked, model.noRec as noRec, "+
			"subModel.name as name, subModel.id as id) "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.detailInformasiMedis model "+
			"left join model.informasiMedis subModel "+
			"where transferPasienInternal.noRec =:noRec ")
	List<Map<String,Object>> findDetailInformasiMedis(@Param("noRec") String noRec);*/
	
	@Query("select model.noRec as noRec,subModel.namaDiagnosa as name, "+
			"subModel.id as id "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.diagnosaSekunder model "+
			"left join model.diagnosa subModel "+
			"where transferPasienInternal.noRec =:noRec ")
	List<Map<String,Object>> findDetailDiagnosaSekunder(@Param("noRec") String noRec);
	
	@Query("select new map (model.noRec as noRec, "+
			"subModel.name as name, subModel.id as id) "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.detailPeralatan model "+
			"left join model.peralatan subModel "+
			"where transferPasienInternal.noRec =:noRec ")
	List<Map<String,Object>> findDetailPeralatan(@Param("noRec") String noRec);
	
	@Query("select new map (model.noRec as noRec, "+
			"subModel.namaLengkap as name, subModel.id as id) "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.detailPetugasPendamping model "+
			"left join model.pegawai subModel "+
			"where transferPasienInternal.noRec =:noRec ")
	List<Map<String,Object>> findDetailPetugasPendamping(@Param("noRec") String noRec);
	
	@Query("select new map (model.noRec as noRec, model.jumlah as jumlah, "+
			"model.dosis as dosis, model.frekuensi as frekuensi, "+
			"subModel.namaProduk as name, subModel.id as id) "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.detailTerapiSaatPindah model "+
			"left join model.obat subModel "+
			"where transferPasienInternal.noRec =:noRec ")
	List<Map<String,Object>> findDetailTerapiSaatPindah(@Param("noRec") String noRec);
	
	@Query("select new map (model.noRec as noRec, "+
			"batangTumbuh.name as batangTumbuh, "+
			"batangTumbuh.id as idBatangTumbuh, "+
			"berguling.name as berguling, "+
			"berguling.id as idberguling, "+
			"duduk.name as duduk, "+
			"duduk.id as idduduk, "+
			"ekstremitasAtas.name as ekstremitasAtas, "+
			"ekstremitasAtas.id as idekstremitasAtas, "+
			"ekstremitasBawah.name as ekstremitasBawah, "+
			"ekstremitasBawah.id as idekstremitasBawah, "+
			"hPBatangTubuhDanPerineum.name as hPBatangTubuhDanPerineum, "+
			"hPBatangTubuhDanPerineum.id as idhPBatangTubuhDanPerineum, "+
			"hPEkstremitasBawah.name as hPEkstremitasBawah, "+
			"hPEkstremitasBawah.id as idhPEkstremitasBawah, "+
			"hPTraktusDigestivus.name as hPTraktusDigestivus, "+
			"hPTraktusDigestivus.id as idhPTraktusDigestivus, "+
			"hPTraktusUrinarius.name as hPTraktusUrinarius, "+
			"hPTraktusUrinarius.id as idhPTraktusUrinarius, "+
			"hPWajahRambutTangan.name as hPWajahRambutTangan, "+
			"hPWajahRambutTangan.id as idhPWajahRambutTangan, "+
			"jalanKaki.name as jalanKaki, "+
			"jalanKaki.id as idjalanKaki, "+
			"kursiRoda.name as kursiRoda, "+
			"kursiRoda.id as idkursiRoda, "+
			"makanan.name as makanan, "+
			"makanan.id as idmakanan) "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.statusKemandirian model "+
			"left join model.batangTumbuh as batangTumbuh "+
			"left join model.berguling as berguling "+
			"left join model.duduk as duduk "+
			"left join model.ekstremitasAtas as ekstremitasAtas "+
			"left join model.ekstremitasBawah as ekstremitasBawah "+
			"left join model.hPBatangTubuhDanPerineum as hPBatangTubuhDanPerineum "+
			"left join model.hPEkstremitasBawah as hPEkstremitasBawah "+
			"left join model.hPTraktusDigestivus as hPTraktusDigestivus "+
			"left join model.hPTraktusUrinarius as hPTraktusUrinarius "+
			"left join model.hPWajahRambutTangan as hPWajahRambutTangan "+
			"left join model.jalanKaki as  jalanKaki "+
			"left join model.kursiRoda as kursiRoda "+
			"left join model.makanan as makanan "+
			"where transferPasienInternal.noRec =:noRec ")
	Map<String,Object> findStatusKemandirian(@Param("noRec") String noRec);

	@Query("select new map ( transferPasienInternal.noRec as noRec, "+
			"pasienDaftar.noRec as noRecPasienDaftar, "+
			"alergi.id as idAlergi, alergi.namaAlergi as namaAlergi, "+
			"asalRuangan.namaRuangan as namaRuangan, asalRuangan.id as idRuangan, "+
			"diagnosa.namaDiagnosa as namaDiagnosa, diagnosa.id as idDiagnosa, "+
			"dokterjaga.namaLengkap as dokterJaga, dokterjaga.id as idDokterJaga, "+
			"tenaga.id as idTenaga, tenaga.name as tenaga, "+
			"statusPsikologis.name as statusPsikologis,  "+
			"statusPsikologis.id as idStatusPsikologis, "+
			"ruangSelanjutnya.namaRuangan as ruanganSelanjutnya, "+
			"ruangSelanjutnya.id as idRuanganSelanjutnya, "+
			"resikoJatuh.name as resikojatuh, resikoJatuh.id as idResikoJatuh, "+
			"petugasMengantar.namaLengkap as petugasMengantar, "+
			"petugasMengantar.id as idpetugasMengantar, "+
			"petugasMenerima.namaLengkap as petugasMenerima, "+
			"petugasMenerima.id as idpetugasMenerima, "+
			"keadaanPasien.name as keadaanPasien, "+
			"keadaanPasien.id as idkeadaanPasien, "+
			"jenisNyeri.name as jenisNyeri, "+
			"jenisNyeri.id as idjenisNyeri, "+
			"isPasien.name as isPasienTahu, "+
			"isPasien.id as idIsPasienTahu, "+
			"keluarga.name as isKeluargaTahu, "+
			"keluarga.id as idkeluargaTahu, "+
			"fasilitas.name as fasilitas, "+
			"fasilitas.id as idfasilitas, "+
			"dokterPengirim.id as iddokterPengirim, "+
			"dokterPengirim.namaLengkap as dokterPengirim, "+
			"dpjp.namaLengkap as dpjp, "+
			"dpjp.id as iddpjp) "+
			"from TransferPasienInternal transferPasienInternal "+
			"left join transferPasienInternal.alergi alergi "+
			"left join transferPasienInternal.asalRuanganRawat asalRuangan "+
			"left join transferPasienInternal.diagnosaUtama diagnosa "+
			"left join transferPasienInternal.dokterJaga dokterjaga "+
			"left join transferPasienInternal.dokterPenanggungJawab dpjp "+
			"left join transferPasienInternal.dokterYangMengirim dokterPengirim "+
			"left join transferPasienInternal.fasilitas fasilitas "+
			"left join transferPasienInternal.isKeluargaDiberiTahuAlasanPemindahan keluarga "+
			"left join transferPasienInternal.isPasienDiberiTahuAlasanPemindahan isPasien "+
			"left join transferPasienInternal.jenisNyeri jenisNyeri "+
			"left join transferPasienInternal.keadaanPasien keadaanPasien "+
			"left join transferPasienInternal.petugasYangMenerima petugasMenerima "+
			"left join transferPasienInternal.petugasYangMengantar petugasMengantar "+
			"left join transferPasienInternal.resikoJatuh resikoJatuh "+
			"left join transferPasienInternal.ruangRawatSelanjutnya ruangSelanjutnya "+
			"left join transferPasienInternal.statusPsikologis statusPsikologis "+
			"left join transferPasienInternal.tenaga tenaga "+
			"left join transferPasienInternal.pasienDaftar pasienDaftar "+
			"where to_char(transferPasienInternal.tanggalInput,'yyyy-MM-dd') between :startDate and :endDate")
	List<Map<String,Object>> findTransferPasienInternal(@Param("startDate") String startDate,@Param("endDate") String endDate);
}
