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

/**
 * Repository class for PAPCatatan
 * 
 * @author Askur
 */
@Repository("PapMataDao")
public interface PapMataDao extends PagingAndSortingRepository<PapMata, String> {
	/*@Query("select model from PapMata model where model.pasien.noCm=:noCm and model.tglInput=:tglInput")
	public PapMata findPapMataByNoCmAndTglInput(@Param("noCm") String noCm,@Param("tglInput") Date tglInput);
	
	@Query("select b.dataVisus.name, b.isNilai,c.dataKoreksi.name,c.isNilai, d.dataKacamata.name,d.isNilai, e.dataTonometri.name,e.isNilai, f.dataAplasnasi.name,f.isNilai, a.streak, to_char(a.tglInput,'yyyy-MM-dd') from PapMata a, PapDataVisus b, PapDataKoreksi c,PapDataKacamata d, PapDataTonometri e,PapDataAplasnasi f where a.noRec = b.papMataId and a.noRec = c.papMataId and a.noRec = d.papMataId and a.noRec = e.papMataId and a.noRec = f.papMataId and a.pasien.noCm=:noCm ")
	public List<Object[]> findPapMataByNoCm(@Param("noCm") String noCm);*/
	
	@Query("select new map (papMata.anelOD as anelOD, "+
			"papMata.anelOS as anelOS, "+
			"papMata.aplanasiOD as aplanasiOD, "+
			"papMata.aplanasiOS as aplanasiOS, "+
			"papMata.diagnosaKlinik as diagnosaKlinik, "+
			"papMata.kacamataLamaBaca as kacamataLamaBaca, "+
			"papMata.kacamataLamaOD as kacamataLamaOD, "+
			"papMata.kacamataLamaOS as kacamataLamaOS, "+
			"papMata.kedudukanBolaMataOD as kedudukanBolaMataOD, "+
			"papMata.kedudukanBolaMataOS as kedudukanBolaMataOS, "+
			"papMata.kodePenyakit as kodePenyakit, "+
			"papMata.koreksiOD as koreksiOD, "+
			"papMata.koreksiOS as koreksiOS, "+
			"papMata.noRec as noRec, "+
			"papMata.pengobatanDiRumah as pengobatanDiRumah, "+
			"papMata.pengobatanPoliklinik as pengobatanPoliklinik, "+
			"papMata.sistemLacrimal as sistemLacrimal, "+
			"to_char(papMata.tglInput, 'yyyy-MM-dd') as tglInput, "+
			"papMata.tonometriOD as tonometriOD, "+
			"papMata.tonometriOS as tonometriOS, "+
			"papMata.visusOD as visusOD, "+
			"papMata.visusOS as visusOS) "+
			"from PapMata papMata "+
			"left join papMata.dokterKonsulen dokter "+
			"left join papMata.pasienDaftar antrian "+
			"where to_char(papMata.tglInput, 'yyyy-MM-dd') between :startDate and :endDate") 
	public List<Map<String,Object>> findPapMataByTglInput(@Param("startDate") String startDate,@Param("endDate") String endDate);
	
	@Query("select new map (dataMataSet.noRec as norecDataMataSet, "+
			"dataMataSet.isNilai as isNilai, "+
			"data.id as idData, "+
			"data.name as name) "+
			"from PapMata papMata "+
			"left join papMata.dataKacamataSet dataMataSet "+
			"left join dataMataSet.dataMata data "+
			"where papMata.noRec =:noRec") 
	public List<Map<String,Object>> findPapDataMata(@Param("noRec") String noRec);
	
	@Query("select new map (kategoriKlinikMataSet.noRec as norecDataMataSet, "+
			"kategoriKlinikMataSet.keterangan as keterangan, "+
			"data.id as idData, "+
			"data.name as name) "+
			"from PapMata papMata "+
			"left join papMata.kategoriKlinikMataSet kategoriKlinikMataSet "+
			"left join kategoriKlinikMataSet.kategoriKlinikMata data "+
			"where papMata.noRec =:noRec and data.streak is null") 
	public List<Map<String,Object>> findPapKategoriMata(@Param("noRec") String noRec);
	
	@Query("select new map (kategoriKlinikMataSet.noRec as norecDataMataSet, "+
			"kategoriKlinikMataSet.keterangan as keterangan, "+
			"data.id as idData, "+
			"data.name as name) "+
			"from PapMata papMata "+
			"left join papMata.kategoriKlinikMataSet kategoriKlinikMataSet "+
			"left join kategoriKlinikMataSet.kategoriKlinikMata data "+
			"where papMata.noRec =:noRec and data.streak is true") 
	public Map<String,Object> findPapMataStreak(@Param("noRec") String noRec);
	
	@Query("select new map (data.id as id, "+
			"data.name as name, "+
			"data.jenis as jenis) "+
			"from DataMata data "+
			"where jenis =:jenis") 
	public List<Map<String,Object>> findListDataMata(@Param("jenis") String jenis);
	
	@Query("select new map (data.id as id, "+
			"data.name as name) "+
			"from KategoriKlinikMata data "+
			"where data.streak is null order by data.name asc") 
	public List<Map<String,Object>> findListKategoriMata();
	
	@Query("select new map (data.id as id, "+
			"data.name as name) "+
			"from KategoriKlinikMata data "+
			"where data.streak is true order by data.name asc") 
	public List<Map<String,Object>> findListStreak();
	
	@Query("select new map (papMata.anelOD as anelOD, "+
			"papMata.anelOS as anelOS, "+
			"papMata.aplanasiOD as aplanasiOD, "+
			"papMata.aplanasiOS as aplanasiOS, "+
			"papMata.diagnosaKlinik as diagnosaKlinik, "+
			"papMata.kacamataLamaBaca as kacamataLamaBaca, "+
			"papMata.kacamataLamaOD as kacamataLamaOD, "+
			"papMata.kacamataLamaOS as kacamataLamaOS, "+
			"papMata.kedudukanBolaMataOD as kedudukanBolaMataOD, "+
			"papMata.kedudukanBolaMataOS as kedudukanBolaMataOS, "+
			"papMata.kodePenyakit as kodePenyakit, "+
			"papMata.koreksiOD as koreksiOD, "+
			"papMata.koreksiOS as koreksiOS, "+
			"papMata.noRec as noRec, "+
			"papMata.pengobatanDiRumah as pengobatanDiRumah, "+
			"papMata.pengobatanPoliklinik as pengobatanPoliklinik, "+
			"papMata.sistemLacrimal as sistemLacrimal, "+
			"to_char(papMata.tglInput, 'yyyy-MM-dd') as tglInput, "+
			"papMata.tonometriOD as tonometriOD, "+
			"papMata.tonometriOS as tonometriOS, "+
			"papMata.visusOD as visusOD, "+
			"papMata.visusOS as visusOS) "+
			"from PapMata papMata "+
			"left join papMata.dokterKonsulen dokter "+
			"left join papMata.pasienDaftar antrian "+
			"where papMata.noRec = :noRec") 
	public Map<String,Object> findPapMataByNoRec(@Param("noRec") String noRec);

}
