package com.jasamedika.medifirst2000.dao;

import java.util.Date;
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.IkiDanRemunerasi;

@Repository("IkiDanRemunerasiDao")
public interface IkiDanRemunerasiDao extends PagingAndSortingRepository<IkiDanRemunerasi, String> {

	// Pegawai
	@Query("select NEW Map (" + "a.id as id, " + "a.namaLengkap as namaLengkap) " + "from Pegawai a")
	List<Map<String, Object>> getPegawaiRemunerasi();

	// grade_nilai_jabatan
	@Query("select NEW Map (  " + "jabatanInternal.namaJabatan as namaJabatan,  "
			+ "kelompokJabatan.id as kelompokJabatanId,  " + "nilaiKelompokJabatan.id as nilaiKelompokJabatan,  "
			+ "nilaiKelompokJabatan.gradeDesc as grade,  " + "pegawai.nipPns as nipPns,  "
			+ "pegawai.nipPns as nipPns,  " + "pegawai.namaLengkap as namaLengkap,  "
			+ "pegawai.nilaiJabatan as nilaiJabatan,  " + "golongan.id as idGolongan,  "
			+ "golongan.golonganPegawai as golongan,  " + "unitKerja.name as unitKerja,  "
			+ "unitKerja.id as idUnitKerja, " + "subUnitKerja.id as idSubUnitKerja, "
			+ "subUnitKerja.name as subUnitKerja, " + "pegawai.id as idPegawai)   "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join pegawai.detailKelompokJabatan nilaiKelompokJabatan "
			+ "left join mapPegawai.jabatan jabatanInternal "
			+ "left join nilaiKelompokJabatan.kelompokJabatan kelompokJabatan "
			+ "left join pegawai.golonganPegawai golongan " + "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and pegawai.id=:id")
	Map<String, Object> getEvaluasiJabatan(@Param("id") Integer id);

	// gaji_Total
	@Query("select NEW Map (" + "b.id as id, " + "a.hargaSatuan as hargaSatuan, " + "a.isByDay as isByDay, "
			+ "a.isByWeek as isByWeek, " + "a.isByMonth as isByMonth, " + "a.isByYear as isByYear, "
			+ "a.hargaSatuan as hargaSatuan) " + "from PegawaiSKGaji a " + "left join a.komponenHarga b "
			+ "left join a.pegawai c " + "where c.id=:id")
	List<Map<String, Object>> getTotalGaji(@Param("id") Integer id);

	// PIR_dan_IKU
	@Query("select NEW Map (" + "a.pir as pir, " + "a.iku as iku) " + "from SettingPirSdm a " + "where a.id=1")
	Map<String, Object> getPirDanIku();

	// IKI
	@Query("select NEW Map ( coalesce (a.iki,0)as iki , " + "a.totalIKI as totalIKI) "
			+ "from NilaiIndexKinerjaIndividu a " + "left join a.pegawai b " + "where b.id=:id and periode =:periode")
	Map<String, Object> getTotalIndexKinerjaIndividu(@Param("id") Integer id, @Param("periode") String periode);

	@Query("select NEW Map (" + "a.minimal as minimal," + "a.maximal as maximal) " + "from RangeKmk a "
			+ "left join a.kelompokJabatan b " + "left join b.kelompokJabatan c " + "where b.id =:id")
	Map<String, Object> getRangeKmk(@Param("id") Integer id);

	@Query("select NEW Map (" + "count(a.loc_code) as count) " + "from Habsen a "
			+ "where to_char(a.tr_date, 'yyyy')=:tahun and " + "to_char(a.tr_date, 'mm')=:bulan and "
			+ "trim(a.empl_code)=:nip")
	Map<String, Object> getAbsen(@Param("tahun") String tahun, @Param("bulan") String bulan, @Param("nip") String nip);

	// getIndekskehadiran
	@Query("select pegawaiHistoriRekap.totalNilaiIndex " + "from PegawaiHistoriRekap pegawaiHistoriRekap "
			+ "left join pegawaiHistoriRekap.pegawai pegawai " + " where pegawaiHistoriRekap.periode = :tanggal  "
			+ "and pegawai.id = :idPegawai")
	Double getIndeksKehadiran(@Param("tanggal") String tanggal, @Param("idPegawai") Integer idPegawai);

	@Query(" select setting.nilaiField as nilaiField " + " from SettingDataFixed setting"
			+ " where setting.namaField = 'KdKategoryPegawai'")
	public List<String> findIdKategoriPegawai();

	@Query(" select setting.nilaiField as nilaiField " + " from SettingDataFixed setting"
			+ " where setting.namaField = 'IdPetugasPelaksana'")
	public List<String> findIdJeniPetugasPelaksana();

	@Query(" select pegawai.id as idPegawai " + "from Pegawai pegawai "
			+ "left join pegawai.kategoryPegawai kategoryPegawai " + " left join pegawai.statusPegawai statusPegawai "
			+ "where kategoryPegawai.id =:kategoryPegawaiId and statusPegawai.id =2")
	public List<Integer> findDetailKategoriPegawai(@Param("kategoryPegawaiId") Integer kategoryPegawaiId);

	@Query(" select new map (ikiDanRemunerasi.indekKehadiran as iki, " + "ikiDanRemunerasi.remunerasi as remun) "
			+ "from IkiDanRemunerasi ikiDanRemunerasi " + "left join ikiDanRemunerasi.pegawai pegawai "
			+ "where pegawai.id = :idPegawai and ikiDanRemunerasi.periode = :periode")
	public Map<String, Object> findRemun(@Param("idPegawai") Integer idPegawai, @Param("periode") String periode);

	@Query(" select new map (settingPirSdm.iku as iku, " + "settingPirSdm.pir as pir, " + "settingPirSdm.id as id, "
			+ "to_char(settingPirSdm.tglAwal, 'yyyy') as tglAwal, " + "settingPirSdm.tglAkhir as tglAkhir) "
			+ "from SettingPirSdm settingPirSdm " + "where to_char(settingPirSdm.tglAwal, 'yyyy-MM-dd') = :tglAwal "
			+ "and to_char(settingPirSdm.tglAkhir, 'yyyy-MM-dd') =  :tglAkhir")
	public Map<String, Object> findPirDanIku(@Param("tglAwal") String tglAwal, @Param("tglAkhir") String tglAkhir);

	@Query(" select coalesce(pegawaiSKPajak.persenPajak,0) " + " from PegawaiSKPajak pegawaiSKPajak "
			+ " left join pegawaiSKPajak.golonganPegawai golongan " + " where golongan.id =:idGolongan")
	public Double findPersentasiPajak(@Param("idGolongan") Integer idGolongan);

	@Query(" select ikiDanRemunerasi.remunerasi " + "from IkiDanRemunerasi ikiDanRemunerasi "
			+ " left join ikiDanRemunerasi.pegawai pegawai " + "left join ikiDanRemunerasi.strukHistory strukHistori "
			+ "where strukHistori.tglHistori between :start and :end " + "and pegawai.id = :idPegawai")
	public Double findRemunerasi(@Param("start") Date start, @Param("end") Date end,
			@Param("idPegawai") Integer idPegawai);

	// Target_pelayanan_jam_kerja
	@Query("select distinct new Map(ppp.ObjectJenisPetugasPeId as jenisPetugasId," + "pg.id as pegawaiId,"
			+ "pp.noRec as noRec,pp.tglPelayanan as tglPelayanan,coalesce(pp.hargaDiscount,0) as hargaDiskon,pp.jumlah as jumlahTindakan,"
			+ "su.id as idKelompokKerja,su.name as kelompokKerja,"
			+ "pr.id as idTindakan,pr.namaProduk as namaTindakan," + "djp.id as djpId,"
			+ "ru.departemenId as idDepartemen,ru.id as idRuangan," + "pd.diskonPegawai as statusDiskon) "
			+ "from PelayananPasienPetugas ppp, MapRuanganToProduk mrtp, MapPegawaiJabatanToUnitKerja mpju, PegawaiJadwalKerja pjk "
			+ "left join ppp.pelayananPasien pp " + "left join ppp.kdpegawai pg " + "left join pp.produk pr "
			+ "left join pp.pasienDaftar apd " + "left join pr.detailJenisProduk djp "
			+ "left join apd.pasienDaftar pd " + "left join apd.ruangan ru " + "left join mpju.subUnitKerjaPegawai su "
			+ "left join mpju.jabatan jb " + "left join pjk.shift sk " + "left join pjk.tanggal kl "
			+ "where mrtp.produkId = pr.id " + "and mrtp.ruanganId = apd.ruanganId "
			+ "and ppp.ObjectPegawaiId = mpju.pegawaiId " + "and mpju.pegawaiId = pg.id "
			+ "and pjk.pegawaiId = ppp.ObjectPegawaiId " + "and pjk.pegawaiId = mpju.pegawaiId "
			+ "and pjk.pegawaiId = pg.id " + "and pg.kategoryPegawaiId in (:listKategoriRemun) "
			+ "and pg.kedudukanId not in (:listInactiveId) " + "and mpju.unitKerjaPegawaiId in (:listKsmId) "
			+ "and jb.levelJabatan = 5 " + "and mpju.statusEnabled is true " + "and pg.statusEnabled is true "
			+ "and su.statusEnabled is true " + "and pd.statusEnabled is true " + "and sk.statusEnabled is true "
			+ "and pp.tglPelayanan between :tglAwal and :tglAkhir "
			+ "and cast(pp.tglPelayanan as date) = cast(kl.tanggal as date) "
			+ "and (pd.kelompokPasienId in (:listBpjsId) " + "or (pd.kelompokPasienId not in (:listBpjsId) "
			+ "and ((to_char(pp.tglPelayanan,'dy') in ('mon','tue','wed','thu') "
			+ "and to_char(pp.tglPelayanan,'HH24:MI:ss') between '07:00:00' and (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '14:00:00' else '15:30:00' end)) "
			+ "or (to_char(pp.tglPelayanan,'dy') in ('fri') "
			+ "and to_char(pp.tglPelayanan,'HH24:MI:ss') between '07:00:00' and (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '15:30:00' else '16:00:00' end))) "
			+ "and sk.id not in (:listNonjadwalId))) " + "and pg.jenisPegawaiId = :jenisPegawaiId "
			+ "and djp.jenisProdukId not in (:listNontindakanId) " + "and pr.id <> :karcisId "
			+ "order by su.name, pr.id")
	public List<Map<String, Object>> getDataLayananJamKerja(@Param("tglAwal") Date tglAwal,
			@Param("tglAkhir") Date tglAkhir, @Param("psbbAwal") Date psbbAwal, @Param("psbbAkhir") Date psbbAkhir,
			@Param("listNonjadwalId") List<Integer> listIdNonjadwal, @Param("jenisPegawaiId") Integer idJenisPegawai,
			@Param("listDepartemenId") List<Integer> listIdDepartemen,
			@Param("listKategoriRemun") List<Integer> listKategoriRemun,
			@Param("listInactiveId") List<Integer> listIdInactive, @Param("listKsmId") List<Integer> listIdKsm,
			@Param("listNontindakanId") List<Integer> listIdNontindakan, @Param("listBpjsId") List<Integer> listIdBpjs,
			@Param("karcisId") Integer idKarcis);

	// Target_pelayanan_luar_jam_kerja
	@Query("select distinct new Map(ppp.ObjectJenisPetugasPeId as jenisPetugasId,"
			+ "pp.noRec as noRec,pp.tglPelayanan as tglPelayanan,coalesce(pp.hargaDiscount,0) as hargaDiskon,pp.jumlah as jumlahTindakan,"
			+ "pg.id as pegawaiId,pg.namaLengkap as namaLengkap," + "jb.id as jabatanId,jb.namaJabatan as namaJabatan,"
			+ "pr.id as idTindakan,pr.namaProduk as namaTindakan," + "djp.id as djpId,"
			+ "ru.departemenId as idDepartemen,ru.id as idRuangan," + "pd.diskonPegawai as statusDiskon) "
			+ "from PelayananPasienPetugas ppp, MapRuanganToProduk mrtp, MapPegawaiJabatanToUnitKerja mpju, PegawaiJadwalKerja pjk "
			+ "left join ppp.pelayananPasien pp " + "left join ppp.kdpegawai pg " + "left join mpju.jabatan jb "
			+ "left join pp.produk pr " + "left join pp.pasienDaftar apd " + "left join pr.detailJenisProduk djp "
			+ "left join apd.pasienDaftar pd " + "left join apd.ruangan ru " + "left join pjk.shift sk "
			+ "left join pjk.tanggal kl " + "where mrtp.produkId = pr.id " + "and mrtp.ruanganId = apd.ruanganId "
			+ "and ppp.ObjectPegawaiId = mpju.pegawaiId " + "and mpju.pegawaiId = pg.id "
			+ "and pjk.pegawaiId = ppp.ObjectPegawaiId " + "and pjk.pegawaiId = pg.id "
			+ "and mpju.unitKerjaPegawaiId in (:listKsmId) " + "and mpju.statusEnabled is true "
			+ "and pg.statusEnabled is true " + "and jb.statusEnabled is true " + "and pd.statusEnabled is true "
			+ "and sk.statusEnabled is true " + "and pp.tglPelayanan between :tglAwal and :tglAkhir "
			+ "and cast(pp.tglPelayanan as date) = cast(kl.tanggal as date) "
			+ "and (pd.kelompokPasienId not in (:listBpjsId) "
			+ "and ((to_char(pp.tglPelayanan,'dy') in ('mon','tue','wed','thu') "
			+ "and (to_char(pp.tglPelayanan,'HH24:MI:ss') between (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '14:00:01' else '15:30:01' end) and '23:59:59' "
			+ "or to_char(pp.tglPelayanan,'HH24:MI:ss') between '00:00:00' and '07:00:00') "
			+ "and sk.id not in (:listNonjadwalId)) " + "or (to_char(pp.tglPelayanan,'dy') in ('fri') "
			+ "and (to_char(pp.tglPelayanan,'HH24:MI:ss') between (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '15:30:01' else '16:00:01'end) and '23:59:59' "
			+ "or to_char(pp.tglPelayanan,'HH24:MI:ss') between '00:00:00' and '07:00:00') "
			+ "and sk.id not in (:listNonjadwalId)) " + "or to_char(pp.tglPelayanan,'dy') in ('sat','sun') "
			+ "or sk.id in (:listNonjadwalId))) " + "and pg.jenisPegawaiId = :jenisPegawaiId "
			+ "and pg.kedudukanId not in (:listInactiveId) " + "and jb.kelompokJabatanId in (3,4) "
			+ "and djp.jenisProdukId not in (:listNontindakanId) " + "and pr.id <> :karcisId "
			+ "order by pg.namaLengkap, pr.id")
	public List<Map<String, Object>> getDataLayananLuarJamKerja(@Param("tglAwal") Date tglAwal,
			@Param("tglAkhir") Date tglAkhir, @Param("psbbAwal") Date psbbAwal, @Param("psbbAkhir") Date psbbAkhir,
			@Param("listNonjadwalId") List<Integer> listIdNonjadwal, @Param("jenisPegawaiId") Integer idJenisPegawai,
			@Param("listInactiveId") List<Integer> listIdInactive,
			@Param("listDepartemenId") List<Integer> listIdDepartemen, @Param("listKsmId") List<Integer> listIdKsm,
			@Param("listNontindakanId") List<Integer> listIdNontindakan, @Param("listBpjsId") List<Integer> listIdBpjs,
			@Param("karcisId") Integer idKarcis);

	// Kinerja_jam_kerja_dokter
	String kinerjaJamKerjaDokter = "select distinct new Map(ppp.ObjectJenisPetugasPeId as jenisPetugasId,coalesce(ppp.asaId,2) as asaId,"
			+ "pg.id as pegawaiId," + "pr.id as produkId,pr.namaProduk as namaProduk,"
			+ "djp.id as detailJenisProdukId,"
			+ "pp.noRec as noRec,pp.tglPelayanan as tglPelayanan,pp.jumlah as jumlah,coalesce(pp.hargaDiscount,0) as hargaDiskon,"
			+ "ru.departemenId as departemenId,ru.id as ruanganId," + "pd.diskonPegawai as statusDiskon) "
			+ "from PelayananPasienPetugas ppp, MapRuanganToProduk mrtp, PegawaiJadwalKerja pjk "
			+ "left join ppp.pelayananPasien pp " + "left join ppp.kdpegawai pg " + "left join pp.produk pr "
			+ "left join pp.pasienDaftar apd " + "left join pr.detailJenisProduk djp "
			+ "left join apd.pasienDaftar pd " + "left join apd.ruangan ru " + "left join pjk.shift sk "
			+ "left join pjk.tanggal kl " + "where mrtp.produkId = pr.id " + "and mrtp.ruanganId = apd.ruanganId "
			+ "and pjk.pegawaiId = ppp.ObjectPegawaiId " + "and pjk.pegawaiId = pg.id "
			+ "and pg.statusEnabled is true " + "and pd.statusEnabled is true " + "and sk.statusEnabled is true "
			+ "and to_char(pp.tglPelayanan,'yyyy-MM') = :bulan "
			+ "and cast(pp.tglPelayanan as date) = cast(kl.tanggal as date) "
			+ "and (pd.kelompokPasienId in (:listBpjsId) " + "or (pd.kelompokPasienId not in (:listBpjsId) "
			+ "and ((to_char(pp.tglPelayanan,'dy') in ('mon','tue','wed','thu') "
			+ "and to_char(pp.tglPelayanan,'HH24:MI:ss') between '07:00:00' and (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '14:00:00' else '15:30:00' end)) "
			+ "or (to_char(pp.tglPelayanan,'dy') in ('fri') "
			+ "and to_char(pp.tglPelayanan,'HH24:MI:ss') between '07:00:00' and (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '15:30:00' else '16:00:00' end))) "
			+ "and sk.id not in (:listNonjadwalId))) " + "and pg.jenisPegawaiId = :jenisPegawaiId "
			+ "and djp.jenisProdukId not in (:listNontindakanId) " + "and pr.id <> :karcisId "
			+ "and pg.id in (:listPegawaiId) ";

	String paramListDetailJenisProdukId = "and (djp.id in (:listDetailJenisProdukId) "
			+ "or (djp.id not in (:listDetailJenisProdukId) " + "and pr.id in (:listProdukIgdId) "
			+ "and pg.id in (:listDokterUmumId) " + "and ru.departemenId = :IgdId)) ";

	String sortingKinerjaJamKerjaDokter = "order by pr.namaProduk, pp.tglPelayanan";

	@Query(kinerjaJamKerjaDokter + paramListDetailJenisProdukId + sortingKinerjaJamKerjaDokter)
	public List<Map<String, Object>> getDataLogbookJamKerjaDokter(@Param("bulan") String bulan,
			@Param("psbbAwal") Date psbbAwal, @Param("psbbAkhir") Date psbbAkhir,
			@Param("listNonjadwalId") List<Integer> listIdNonjadwal, @Param("jenisPegawaiId") Integer idJenisPegawai,
			@Param("listPegawaiId") List<Integer> listIdPegawai,
			@Param("listDepartemenId") List<Integer> listIdDepartemen,
			@Param("listDetailJenisProdukId") List<Integer> listIdDetailJenisProduk,
			@Param("listProdukIgdId") List<Integer> listIdProdukIgd,
			@Param("listDokterUmumId") List<Integer> listIdDokterUmum, @Param("IgdId") Integer idIgd,
			@Param("listNontindakanId") List<Integer> listIdNontindakan, @Param("listBpjsId") List<Integer> listIdBpjs,
			@Param("karcisId") Integer idKarcis);

	@Query(kinerjaJamKerjaDokter + sortingKinerjaJamKerjaDokter)
	public List<Map<String, Object>> getDataLogbookJamKerjaDokter(@Param("bulan") String bulan,
			@Param("psbbAwal") Date psbbAwal, @Param("psbbAkhir") Date psbbAkhir,
			@Param("listNonjadwalId") List<Integer> listIdNonjadwal, @Param("jenisPegawaiId") Integer idJenisPegawai,
			@Param("listPegawaiId") List<Integer> listIdPegawai,
			@Param("listDepartemenId") List<Integer> listIdDepartemen,
			@Param("listNontindakanId") List<Integer> listIdNontindakan, @Param("listBpjsId") List<Integer> listIdBpjs,
			@Param("karcisId") Integer idKarcis);

	// Logbook_kinerja_luar_jam_kerja_dokter
	@Query("select distinct new Map(ppp.ObjectJenisPetugasPeId as jenisPetugasId,coalesce(ppp.asaId,2) as asaId,"
			+ "pr.id as produkId,pr.namaProduk as namaProduk,pg.id as pegawaiId,"
			+ "pp.noRec as noRec,pp.tglPelayanan as tglPelayanan,pp.jumlah as jumlah,coalesce(pp.hargaDiscount,0) as hargaDiskon,"
			+ "ru.departemenId as departemenId,ru.id as ruanganId," + "pd.diskonPegawai as statusDiskon) "
			+ "from PelayananPasienPetugas ppp, MapRuanganToProduk mrtp, PegawaiJadwalKerja pjk "
			+ "left join ppp.pelayananPasien pp " + "left join ppp.kdpegawai pg " + "left join pp.produk pr "
			+ "left join pp.pasienDaftar apd " + "left join pr.detailJenisProduk djp "
			+ "left join apd.pasienDaftar pd " + "left join apd.ruangan ru " + "left join pjk.shift sk "
			+ "left join pjk.tanggal kl " + "where mrtp.produkId = pr.id " + "and mrtp.ruanganId = apd.ruanganId "
			+ "and pjk.pegawaiId = ppp.ObjectPegawaiId " + "and pjk.pegawaiId = pg.id "
			+ "and pg.statusEnabled is true " + "and pd.statusEnabled is true " + "and sk.statusEnabled is true "
			+ "and to_char(pp.tglPelayanan,'yyyy-MM') = :bulan "
			+ "and cast(pp.tglPelayanan as date) = cast(kl.tanggal as date) "
			+ "and (pd.kelompokPasienId not in (:listBpjsId) "
			+ "and ((to_char(pp.tglPelayanan,'dy') in ('mon','tue','wed','thu') "
			+ "and (to_char(pp.tglPelayanan,'HH24:MI:ss') between (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '14:00:01' else '15:30:01' end) and '23:59:59' "
			+ "or to_char(pp.tglPelayanan,'HH24:MI:ss') between '00:00:00' and '07:00:00') "
			+ "and sk.id not in (:listNonjadwalId)) " + "or (to_char(pp.tglPelayanan,'dy') in ('fri') "
			+ "and (to_char(pp.tglPelayanan,'HH24:MI:ss') between (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '15:30:01' else '16:00:01'end) and '23:59:59' "
			+ "or to_char(pp.tglPelayanan,'HH24:MI:ss') between '00:00:00' and '07:00:00') "
			+ "and sk.id not in (:listNonjadwalId)) " + "or to_char(pp.tglPelayanan,'dy') in ('sat','sun') "
			+ "or sk.id in (:listNonjadwalId))) " + "and pg.jenisPegawaiId = :jenisPegawaiId "
			+ "and (djp.id in (:listDetailJenisProdukId) "
			+ "or (djp.id not in (:listDetailJenisProdukId) and pr.id in (:listProdukIgdId) and pg.id in (:listDokterUmumId) and ru.departemenId = :IgdId)) "
			+ "and djp.jenisProdukId not in (:listNontindakanId) " + "and pr.id <> :karcisId "
			+ "and pg.id = :pegawaiId " + "order by pr.namaProduk, pp.tglPelayanan")
	public List<Map<String, Object>> getDataLogbookLuarJamKerjaDokter(@Param("bulan") String bulan,
			@Param("psbbAwal") Date psbbAwal, @Param("psbbAkhir") Date psbbAkhir,
			@Param("listNonjadwalId") List<Integer> listIdNonjadwal, @Param("jenisPegawaiId") Integer idJenisPegawai,
			@Param("pegawaiId") Integer idPegawai, @Param("listDepartemenId") List<Integer> listIdDepartemen,
			@Param("listDetailJenisProdukId") List<Integer> listIdDetailJenisProduk,
			@Param("listProdukIgdId") List<Integer> listIdProdukIgd,
			@Param("listDokterUmumId") List<Integer> listIdDokterUmum, @Param("IgdId") Integer idIgd,
			@Param("listNontindakanId") List<Integer> listIdNontindakan, @Param("listBpjsId") List<Integer> listIdBpjs,
			@Param("karcisId") Integer idKarcis);

	// Detail_logbook_kinerja_jam_kerja_dokter
	@Query("select distinct new Map(jpp.id as jenisPetugasId,jpp.jenisPetugasPe as jenisPetugas,"
			+ "pr.id as produkId,pr.namaProduk as namaProduk," + "coalesce(ppp.asaId,2) as asaId,"
			+ "pp.noRec as noRec,pp.tglPelayanan as tglPelayanan,to_char(pp.tglPelayanan,'dd-MM-yyyy HH24:MI:ss') as tglPelayananFormatted,pp.jumlah as jumlah,"
			+ "coalesce(pp.hargaDiscount,0) as hargaDiskon,"
			+ "ru.departemenId as departemenId,ru.id as ruanganId,ru.namaRuangan as namaRuangan,"
			+ "pd.noRegistrasi as noRegistrasi,pd.diskonPegawai as statusDiskon,"
			+ "ps.namaPasien as namaPasien,ps.noCm as noCm," + "kp.kelompokPasien as kelompokPasien) "
			+ "from PelayananPasienPetugas ppp, MapRuanganToProduk mrtp, PegawaiJadwalKerja pjk "
			+ "left join ppp.pelayananPasien pp " + "left join ppp.kdpegawai pg "
			+ "left join ppp.kdjenispetugaspe jpp " + "left join pp.produk pr " + "left join pp.pasienDaftar apd "
			+ "left join pr.detailJenisProduk djp " + "left join apd.pasienDaftar pd " + "left join apd.ruangan ru "
			+ "left join pd.pasien ps " + "left join pd.kelompokPasien kp " + "left join pjk.shift sk "
			+ "left join pjk.tanggal kl " + "where mrtp.produkId = pr.id " + "and mrtp.ruanganId = apd.ruanganId "
			+ "and pjk.pegawaiId = ppp.ObjectPegawaiId " + "and pjk.pegawaiId = pg.id "
			+ "and pg.statusEnabled is true " + "and pd.statusEnabled is true " + "and pr.id = :produkId "
			+ "and to_char(pp.tglPelayanan,'yyyy-MM-dd') = :tglPelayanan "
			+ "and cast(pp.tglPelayanan as date) = cast(kl.tanggal as date) "
			+ "and (pd.kelompokPasienId in (:listBpjsId) " + "or (pd.kelompokPasienId not in (:listBpjsId) "
			+ "and ((to_char(pp.tglPelayanan,'dy') in ('mon','tue','wed','thu') "
			+ "and to_char(pp.tglPelayanan,'HH24:MI:ss') between '07:00:00' and (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '14:00:00' else '15:30:00' end)) "
			+ "or (to_char(pp.tglPelayanan,'dy') in ('fri') "
			+ "and to_char(pp.tglPelayanan,'HH24:MI:ss') between '07:00:00' and (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '15:30:00' else '16:00:00' end))) "
			+ "and sk.id not in (:listNonjadwalId))) " + "and pg.jenisPegawaiId = :jenisPegawaiId "
			+ "and (djp.id in (:listDetailJenisProdukId) "
			+ "or (djp.id not in (:listDetailJenisProdukId) and pr.id in (:listProdukIgdId) and pg.id in (:listDokterUmumId) and ru.departemenId = :IgdId)) "
			+ "and djp.jenisProdukId not in (:listNontindakanId) " + "and pr.id <> :karcisId "
			+ "and pg.id = :pegawaiId " + "order by pr.namaProduk, pp.tglPelayanan")
	public List<Map<String, Object>> findDetailPasienLogbookJamKerjaDokter(@Param("produkId") Integer idProduk,
			@Param("tglPelayanan") String tglPelayanan, @Param("psbbAwal") Date psbbAwal,
			@Param("psbbAkhir") Date psbbAkhir, @Param("listNonjadwalId") List<Integer> listIdNonjadwal,
			@Param("jenisPegawaiId") Integer idJenisPegawai, @Param("pegawaiId") Integer idPegawai,
			@Param("listDepartemenId") List<Integer> listIdDepartemen,
			@Param("listDetailJenisProdukId") List<Integer> listIdDetailJenisProduk,
			@Param("listProdukIgdId") List<Integer> listIdProdukIgd,
			@Param("listDokterUmumId") List<Integer> listIdDokterUmum, @Param("IgdId") Integer idIgd,
			@Param("listNontindakanId") List<Integer> listIdNontindakan, @Param("listBpjsId") List<Integer> listIdBpjs,
			@Param("karcisId") Integer idKarcis);

	// Detail_logbook_kinerja_luar_jam_kerja_dokter
	@Query("select distinct new Map(jpp.id as jenisPetugasId,jpp.jenisPetugasPe as jenisPetugas,"
			+ "pr.id as produkId,pr.namaProduk as namaProduk,"
			+ "pp.noRec as noRec,pp.tglPelayanan as tglPelayanan,to_char(pp.tglPelayanan,'dd-MM-yyyy HH24:MI:ss') as tglPelayananFormatted,pp.jumlah as jumlah,"
			+ "coalesce(pp.hargaDiscount,0) as hargaDiskon,"
			+ "ru.departemenId as departemenId,ru.id as ruanganId,ru.namaRuangan as namaRuangan,"
			+ "pd.noRegistrasi as noRegistrasi,pd.diskonPegawai as statusDiskon,"
			+ "ps.namaPasien as namaPasien,ps.noCm as noCm," + "kp.kelompokPasien as kelompokPasien) "
			+ "from PelayananPasienPetugas ppp, MapRuanganToProduk mrtp, PegawaiJadwalKerja pjk "
			+ "left join ppp.pelayananPasien pp " + "left join ppp.kdpegawai pg "
			+ "left join ppp.kdjenispetugaspe jpp " + "left join pp.produk pr " + "left join pp.pasienDaftar apd "
			+ "left join pr.detailJenisProduk djp " + "left join apd.pasienDaftar pd " + "left join apd.ruangan ru "
			+ "left join pd.pasien ps " + "left join pd.kelompokPasien kp " + "left join pjk.shift sk "
			+ "left join pjk.tanggal kl " + "where mrtp.produkId = pr.id " + "and mrtp.ruanganId = apd.ruanganId "
			+ "and pjk.pegawaiId = ppp.ObjectPegawaiId " + "and pjk.pegawaiId = pg.id "
			+ "and pg.statusEnabled is true " + "and pd.statusEnabled is true " + "and pr.id = :produkId "
			+ "and to_char(pp.tglPelayanan,'yyyy-MM-dd') = :tglPelayanan "
			+ "and cast(pp.tglPelayanan as date) = cast(kl.tanggal as date) "
			+ "and (pd.kelompokPasienId not in (:listBpjsId) "
			+ "and ((to_char(pp.tglPelayanan,'dy') in ('mon','tue','wed','thu') "
			+ "and (to_char(pp.tglPelayanan,'HH24:MI:ss') between (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '14:00:01' else '15:30:01' end) and '23:59:59' "
			+ "or to_char(pp.tglPelayanan,'HH24:MI:ss') between '00:00:00' and '07:00:00') "
			+ "and sk.id not in (:listNonjadwalId)) " + "or (to_char(pp.tglPelayanan,'dy') in ('fri') "
			+ "and (to_char(pp.tglPelayanan,'HH24:MI:ss') between (case when pp.tglPelayanan between cast(:psbbAwal as timestamp) and cast(:psbbAkhir as timestamp) "
			+ "and ru.departemenId in (:listDepartemenId) then '15:30:01' else '16:00:01'end) and '23:59:59' "
			+ "or to_char(pp.tglPelayanan,'HH24:MI:ss') between '00:00:00' and '07:00:00') "
			+ "and sk.id not in (:listNonjadwalId)) " + "or to_char(pp.tglPelayanan,'dy') in ('sat','sun') "
			+ "or sk.id in (:listNonjadwalId))) " + "and pg.jenisPegawaiId = :jenisPegawaiId "
			+ "and (djp.id in (:listDetailJenisProdukId) "
			+ "or (djp.id not in (:listDetailJenisProdukId) and pr.id in (:listProdukIgdId) and pg.id in (:listDokterUmumId) and ru.departemenId = :IgdId)) "
			+ "and djp.jenisProdukId not in (:listNontindakanId) " + "and pr.id <> :karcisId "
			+ "and pg.id = :pegawaiId " + "order by pr.namaProduk, pp.tglPelayanan")
	public List<Map<String, Object>> findDetailPasienLogbookLuarJamKerjaDokter(@Param("produkId") Integer idProduk,
			@Param("tglPelayanan") String tglPelayanan, @Param("psbbAwal") Date psbbAwal,
			@Param("psbbAkhir") Date psbbAkhir, @Param("listNonjadwalId") List<Integer> listIdNonjadwal,
			@Param("jenisPegawaiId") Integer idJenisPegawai, @Param("pegawaiId") Integer idPegawai,
			@Param("listDepartemenId") List<Integer> listIdDepartemen,
			@Param("listDetailJenisProdukId") List<Integer> listIdDetailJenisProduk,
			@Param("listProdukIgdId") List<Integer> listIdProdukIgd,
			@Param("listDokterUmumId") List<Integer> listIdDokterUmum, @Param("IgdId") Integer idIgd,
			@Param("listNontindakanId") List<Integer> listIdNontindakan, @Param("listBpjsId") List<Integer> listIdBpjs,
			@Param("karcisId") Integer idKarcis);
}