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

@Repository("GawatDaruratDao")
public interface GawatDaruratDao extends PagingAndSortingRepository<GawatDarurat, String> {	
	
//	@Query("select model from GawatDarurat model "
//			+ "left join model.antrianPasienDiPeriksa a where a.noRec=:noRec")
//	GawatDarurat findByNoRecAntrian(@Param("noRec") String noRec);
	
	@Query("select NEW Map("
			+ "a.noRec as noRec,"
			+ "a.skorNyeri as skorNyeri,"
			+ "a.lokasi as lokasi,"
			+ "a.durasi as durasi,"
			+ "a.pencetus as pencetus,"
			+ "a.jamPenentuanKematian as jamPenentuanKematian,"
			+ "a.skorResikoJatuh as skorResikoJatuh,"
			+ "a.isapLendir as isapLendir,"
			+ "a.pasangOroPharsingAirway as pasangOroPharsingAirway,"
			+ "a.aturPosisi1 as aturPosisi1,"
			+ "a.aturPosisi2 as aturPosisi2,"
			+ "a.monitorIntakeOutput as monitorIntakeOutput,"
			+ "a.monitorTtvdanSp021 as monitorTtvdanSp021,"
			+ "a.monitorTtvdanSp022 as monitorTtvdanSp022,"
			+ "a.berikanOksigen1 as berikanOksigen1,"
			+ "a.berikanOksigen2 as berikanOksigen2,"
			+ "a.pasangInfus1 as pasangInfus1,"
			+ "a.pasangInfus2 as pasangInfus2,"
			+ "a.pasangEtt1 as pasangEtt1,"
			+ "a.pasangEtt2 as pasangEtt2,"
			+ "a.defibrasi1 as defibrasi1,"
			+ "a.defibrasi2 as defibrasi2,"
			+ "a.pemeriksaanLaboratorium as pemeriksaanLaboratorium,"
			+ "a.pemberiObat as pemberiObat,"
			+ "a.lainnya as lainnya,"
			+ "a.skor as skor,"
			+ "b.noRec as noRegistrasi,"
			+ "c.id as skalaNyeriId,"
			+ "c.skalaNyeri as skalaNyeri,"
			+ "d.id as jenisNyeriId,"
			+ "d.name as jenisNyeri,"
			+ "e.id as statusPasienId,"
			+ "e.name as statusPasien,"
			+ "e.nilai as nilaiStatusPasien,"
			+ "f.id as tandaKehidupanId,"
			+ "g.id as psikologisId,"
			+ "g.name as psikologis,"
			+ "h.id as resikoJatuhId,"
			+ "h.name as resikoJatuh,"
			+ "i.id as diagnosaKeperawatanId,"
			+ "i.name as diagnosaKeperawatan,"
			+ "j.id as ruanganPerawatId,"
			+ "j.name as ruanganPerawat) "
			+ "from GawatDarurat a "
			+ "left join a.antrianPasienDiPeriksa b "
			+ "left join a.skalaNyeri c "
			+ "left join a.jenisNyeri d "
			+ "left join a.statusPasien e "
			+ "left join a.tandaKehidupan f "
			+ "left join a.psikologis g "
			+ "left join a.resikoJatuh h "
			+ "left join a.diagnosaKeperawatan i "
			+ "left join a.ruanganPerawat j "
			+ "where b.noRec=:noRec")
	Map<String, Object> find(@Param("noRec") String noRec);
	
	@Query("select NEW Map("
			+ "c.id as id,"
			+ "c.name as name) "
			+ "from MapStatusImageToGawatDarurat a "
			+ "left join a.gawatDarurat b "
			+ "left join a.statusImageGawatDarurat c "
			+ "where b.noRec=:noRec")
	List<Map<String, Object>> findStatusGambar(@Param("noRec") String noRec);
	
	@Query("select NEW Map("
			+ "c.id as id,"
			+ "c.name as name) "
			+ "from MapStatusKeputusanToGawatDarurat a "
			+ "left join a.gawatDarurat b "
			+ "left join a.statusKeputusan c "
			+ "where b.noRec=:noRec")
	List<Map<String, Object>> findDiputuskan(@Param("noRec") String noRec);
	
}
