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

@Repository("UskomPemeriksaanDao")
public interface UskomPemeriksaanDao extends PagingAndSortingRepository<UskomPemeriksaan, String>{


	@Query("select NEW Map("
			+ "a.noRec as noRec,"
			+ "a.luasPermukaanTubuh as luasPermukaanTubuh,"
			+ "a.diagnosa as diagnosa,"
			+ "b.noRec as noRegostrasi) "
			+ "from UskomPemeriksaan a "
			+ "left join a.noRegistrasi b "
			+ "where b.noRec=:noRec")
	Map<String, Object> getUskomPemeriksaan(
			@Param("noRec") String noRec);
	
	@Query("select NEW Map("
			+ "a.noRec as noRec,"
			+ "a.tanggal as tanggal,"
			+ "a.sistoleDistole as sistoleDistole,"
			+ "a.frekuensiNadi as frekuensiNadi,"
			+ "a.saturasi as saturasi,"
			+ "a.hemoglobin as hemoglobin,"
			+ "c.id as idPegawai,"
			+ "c.namaLengkap as namaLengkap) "
			+ "from UskomListPemeriksaan a "
			+ "left join a.uskomPemeriksaan b "
			+ "left join a.pegawai c "
			+ "where b.noRec=:noRec ")
	List<Map<String, Object>> getUskomListPemeriksaan(
			@Param("noRec") String noRec);
	
	@Query("select NEW Map("
			+ "a.noRec as noRec,"
			+ "a.nilai as nilai,"
			+ "b.id as idNilaiNormal,"
			+ "b.nilaiNormal as nilaiNormal,"
			+ "b.jenisPemeriksaan as jenisPemeriksaan)"
			+ "from UskomJenisPemeriksaan a "
			+ "left join a.uskomNilaiNormal b "
			+ "left join a.uskomListPemeriksaan c "
			+ "where c.noRec=:noRec")
	List<Map<String, Object>> getUskomJenisPemeriksaan(
			@Param("noRec") String noRec);
	
	@Query("select NEW Map("
			+ "a.id as idNilaiNormal,"
			+ "a.nilaiNormal as nilaiNormal,"
			+ "a.jenisPemeriksaan as jenisPemeriksaan) "
			+ "from UskomNilaiNormal a "
			+ "where :usia>=a.usiaAwal and :usia<=a.usiaAkhir ")
	List<Map<String, Object>> getUskomNilaiNormal(
			@Param("usia") Double usia);
}
