package com.jasamedika.medifirst2000.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.Modifying;
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.SignInOperation;

/**
 * @author Shakato
 */
@Repository("SignInOperationDao")
public interface SignInOperationDao extends PagingAndSortingRepository<SignInOperation, Integer> {
	/*
	 * Add show data to get
	 * add by iwankasan
	 * date : 27.10.2017
	 */
	@Query("select new map(signInOperation.noRec as noRec, " +
			" antrian.noRec as noRecAntrian, " +
			" antrian.tglRegistrasi as tglRegistrasi, " +
			" kelas.id as idKelas, kelas.namaKelas as namaKelas, " +
			" ruangan.id as idRuangan, ruangan.namaRuangan as namaRuangan, " +
			" pegawai.id as idPegawai, pegawai.namaLengkap as namaPegawai, " +
			" pasien.jenisKelamin.jenisKelamin as jenisKelamin, " +
			" pasien.namaPasien as namaPasien, " +
			" signInOperation.statusEnabled as statusEnabled," +
			" pasien.noCm as noCm, alamats.alamatLengkap as alamatLengkap) " +
			" from SignInOperation signInOperation " +
			" left join signInOperation.pasienDaftar antrian " +
			" left join antrian.ruangan ruangan " +
			" left join antrian.kelas as kelas " +
			" left join antrian.pegawai pegawai " +
			" left join antrian.pasienDaftar pasienDaftar " +
			" left join pasienDaftar.pasien pasien " +
			" left join pasien.alamats alamats where " +
			" signInOperation.statusEnabled in('true') and signInOperation.noRec=:noRec")
	List<Map<String, Object>> getSingInByNoRec(@Param("noRec") String noRec);
	
	@Query("select new map(signInOperation.noRec as noRec, " +
			" antrian.noRec as noRecAntrian, " +
			" antrian.tglRegistrasi as tglRegistrasi, " +
			" kelas.id as idKelas, kelas.namaKelas as namaKelas, " +
			" ruangan.id as idRuangan, ruangan.namaRuangan as namaRuangan, " +
			" pegawai.id as idPegawai, pegawai.namaLengkap as namaPegawai, " +
			" pasien.jenisKelamin.jenisKelamin as jenisKelamin, " +
			" pasien.namaPasien as namaPasien, " +
			" pasien.noCm as noCm, alamats.alamatLengkap as alamatLengkap) " +
			" from SignInOperation signInOperation " +
			" left join signInOperation.pasienDaftar antrian " +
			" left join antrian.ruangan ruangan " +
			" left join antrian.kelas as kelas " +
			" left join antrian.pegawai pegawai " +
			" left join antrian.pasienDaftar pasienDaftar " +
			" left join pasienDaftar.pasien pasien " +
			" left join pasien.alamats alamats where antrian.noRec=:noRec")
	List<Map<String, Object>> getSignInByNoRecAntrian(@Param("noRec") String noRec);

 	@Query("select new map(signInOperationDetailQuisioner.noRec as noRec, " +
 			" signInOperationDetailQuisioner.value as value, " +
 			" signInOperationDetailQuisioner.statusEnabled as statusEnabled, " +
 			" signInOperation.noRec as noRecSign, " +
 			" pengobatanKhusus.id as idPengobatanKhusus, " +
 			" pengobatanKhusus.name as namePengobatanKhusus) " +
 			" from SignInOperationDetailQuisioner signInOperationDetailQuisioner " +
 			" left join signInOperationDetailQuisioner.signInOperation signInOperation " +
 			" left join signInOperationDetailQuisioner.pengobatanKhusus pengobatanKhusus " +
 			" where signInOperationDetailQuisioner.statusEnabled in('true') and signInOperation.noRec=:noRec")
 	List<Map<String, Object>> getSignInOperationDetailQuisionerDetailbyNoRecSignIn(@Param("noRec") String noRec);
 	
 	
 	@Query("select new map(signInOperationDetail.noRec as noRec, " +
 			" signInOperation.noRec as noRecSignOperation, " +
 			" konfirmasiSignIn.id as idKonfirmasiSignIn, " +
 			" signInOperationDetail.statusEnabled as statusEnabled," +
 			" konfirmasiSignIn.name as namaKonfirmasiSignIn) " +
 			" from SignInOperationDetail signInOperationDetail " +
 			" left join signInOperationDetail.signInOperation signInOperation " +
 			" left join signInOperationDetail.konfirmasiSignIn konfirmasiSignIn " +
 			" where signInOperationDetail.statusEnabled in('true') and signInOperation.noRec=:noRec")
 	List<Map<String, Object>> getSignInOperationDetailByNoRecSignIn(@Param("noRec") String noRec);
 	
 	@Modifying(clearAutomatically=true)
 	@Query("update AntrianPasienDiPeriksa a set a.statusAntrian='2' where a.noRec=:noRec")
 	public void updateNoAntrianByNoRec(@Param("noRec") String noRec);

	
}
