package com.jasamedika.medifirst2000.dao;

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

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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.Jabatan;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.vo.PegawaiVO;

/**
 * Repository class for Pegawai
 * 
 * @author Askur
 */
@Repository("PegawaiDao")
public interface PegawaiDao extends PagingAndSortingRepository<Pegawai, Integer>, JpaSpecificationExecutor<Pegawai> {

	@Query("select new map (pegawai.id as id, pegawai.namaLengkap as namaLengkap) "
			+ "from Pegawai pegawai where pegawai.id = :pegawaiId and pegawai.statusEnabled is true")
	public Map<String, Object> getPegawaiByPegawaiId(@Param("pegawaiId") Integer pegawaiId);

	@Query("select new Map (p.namaLengkap as namaLengkap,p.nip as nip) from Pegawai p where p.id=:id")
	public Map<String, Object> dataPegawaiByNoRec(@Param("id") Integer id);

	@Query("select new Map(model.id as id,model.namaLengkap as namaLengkap,model.ruanganId as ruanganId) "
			+ "from Pegawai model where model.id=:id and model.statusEnabled is true")
	public Map<String, Object> getPegawaiByIdCustom(@Param("id") Integer id);

	@Query("select new Map(pg.namaLengkap as namaLengkap," + "pg.idFinger as idFinger,"
			+ "pg.jenisPegawaiId as jenisPegawaiId," + "pg.shiftKerjaId as shiftKerjaId) " + "from Pegawai pg "
			+ "where pg.id = :pegawaiId")
	public Map<String, Object> getPegawaiCapaianKuantitas(@Param("pegawaiId") Integer idPegawai);

	@Query("select new map (coalesce(pegawai.nipPns,'') as nip, " + "coalesce(pegawai.namaLengkap,'') as namaLengkap, "
			+ "coalesce(agama.agama,'') as agama, " + "coalesce(subUnitKerja.name,'') as subUnitKerja, "
			+ "coalesce(unitKerja.name,'') as unitKerja, "
			+ "coalesce(jabatanInternal.namaJabatan,'') as namaJabatanInternal, "
			+ "coalesce(kedudukan.name,'') as kedudukan, "
			+ "coalesce(kategoriPegawai.kategoryPegawai,'') as kategoriPegawai) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join pegawai.golonganPegawai golongan "
			+ "left join pegawai.agama agama " + "left join pegawai.detailKategoryPegawai detailKategoryPegawai "
			+ "left join pegawai.dokumen dokumen " + "left join pegawai.eselon eselon "
			+ "left join pegawai.golonganDarah golonganDarah "
			+ "left join pegawai.jabatanFungsional jabatanFungsional " + "left join mapPegawai.jabatan jabatanInternal "
			+ "left join pegawai.jabatanLamar jabatanLamar " + "left join pegawai.jabatanStruktural jabatanStruktural "
			+ "left join pegawai.jenisKelamin jenisKelamin " + "left join pegawai.jenisPegawai jenisPegawai "
			+ "left join pegawai.jenisPegawaiLamar jenisPegawaiLamar "
			+ "left join pegawai.kategoryPegawai kategoriPegawai " + "left join pegawai.kedudukan kedudukan "
			+ "left join pegawai.kualifikasiJurusan kualifikasiJurusan " + "left join pegawai.negara negara "
			+ "left join pegawai.pangkat pangkat " + "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.penghasilanTidakKenaPajak penghasilanTidakKenaPajak "
			+ "left join pegawai.range range " + "left join pegawai.ruangan ruangan "
			+ "left join pegawai.satuanKerja satuanKerja " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join pegawai.statusKawin statusKawin " + "left join pegawai.statusPegawai statusPegawai "
			+ "left join pegawai.statusPerkawinanPegawai statusPerkawinanPegawai " + "left join pegawai.suku suku "
			+ "left join pegawai.titlePasien titlePasien " + "left join pegawai.typePegawai typePegawai "
			+ "where mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and kategoriPegawai.id = :kategoryPegawaiId " + "order by pegawai.nama")
	public List<Map<String, Object>> generatePegawaiByKategory(@Param("kategoryPegawaiId") Integer kategoryPegawaiId);

	@Query("select coalesce(p.nip,p.nipPns) as nip, " + "p.namaLengkap as namaLengkap, " + "a.agama as agama, "
			+ "suk.namaExternal as subUnitKerja, " + "uk.namaExternal as UnitKerja, "
			+ "ji.namaJabatan as namaJabatanInternal, " + "k.namaExternal as kedudukan, "
			+ "kp.kategoryPegawai as kategoriPegawai " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai p " + "inner join p.kategoryPegawai kp " + "left join p.agama a "
			+ "left join mapPegawai.subUnitKerjaPegawai suk " + "left join mapPegawai.unitKerjaPegawai uk "
			+ "left join mapPegawai.jabatan ji " + "left join p.kedudukan k " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and p.statusEnabled is true " + "order by p.nama")
	public List<Object[]> generatePegawai();

	@Query("select NEW com.jasamedika.medifirst2000.entities.Pegawai(p.namaLengkap, p.namaPanggilan, p.nikIntern, p.nipPns, p.noIdentitas,p.npwp,p.id) "
			+ "from SettingDataFixed s,JenisPegawai j,Pegawai p where  p.statusEnabled is true and j.kdJenisPegawai=s.nilaiField and j.id=p.jenisPegawaiId "
			+ "and j.id= (Select cast(s.nilaiField as int) from  SettingDataFixed s where s.namaField='KdJenisPegawaiDokter') and p.statusPegawai.kdStatusPegawai=2 "
			+ "group by p.id")
	public List<Pegawai> getAllDokter();

	@Query("select NEW com.jasamedika.medifirst2000.entities.Pegawai(p.namaLengkap, p.namaPanggilan, p.nikIntern, p.nipPns, p.noIdentitas,p.npwp,p.id) "
			+ "from SettingDataFixed s,JenisPegawai j,Pegawai p where p.namaLengkap like %:nama% and  j.kdJenisPegawai=s.nilaiField and j.id=p.jenisPegawaiId "
			+ "and j.id= (Select cast(s.nilaiField as int) from  SettingDataFixed s where s.namaField='KdJenisPegawaiDokter') group by p.id")
	public List<Pegawai> getAllDokter(@Param("nama") String nama);

	@Query("select p from SettingDataFixed s,JenisPegawai j,Pegawai p where  j.kdJenisPegawai=s.nilaiField and j.id=p.jenisPegawaiId and j.id= "
			+ "(Select cast(s.nilaiField as int) from  SettingDataFixed s where s.namaField='KdJenisPegawaiDokter' and :kodeRuangan=:kodeRuangan and :tanggal=:tanggal) "
			+ "and p.statusPegawai.kdStatusPegawai=2 group by p.id")
	public List<Pegawai> getAllDokterByRuanganAndTanggal(@Param("kodeRuangan") String kodeRuangan,
			@Param("tanggal") Date tanggal);

	@Query("select model from Pegawai model where model.namaLengkap=:nama")
	public List<Pegawai> findPasienByNama(@Param("nama") String nama);

	@Query("select model from Pegawai model where model.statusEnabled is true and model.id=:nik")
	public List<Pegawai> findPasienByNik(@Param("nik") String nik);

	@Query("select model from Pegawai model where model.statusEnabled is true and model.id=:key")
	public Pegawai findById(@Param("key") Integer key);

	@Query("select model from Pegawai model where model.id=:id")
	public Pegawai getPegawaiById(@Param("id") Integer id);

	@Query("select count(model.id) " + "from LoginUser loginUser " + "inner join loginUser.pegawai model "
			+ "where model.id = :id " + "and loginUser.statusEnabled is true " + "and model.statusEnabled is true")
	public Integer countPegawaiWithUsername(@Param("id") Integer id);

	@Query("select NEW Map(model.GolonganId as golonganId, " + "model.agamaId as agamaId, " + "model.alamat as alamat, "
			+ "model.bankRekeningAtasNama as bankRekeningAtasNama, " + "model.bankRekeningNama as bankRekeningNama, "
			+ "model.bankRekeningNomor as bankRekeningNomor, "
			+ "model.detailKategoryPegawaiId as detailKategoryPegawaiId, " + "model.dokumenId as dokumenId, "
			+ "model.email as email, " + "model.emailAlternatif as emailAlternatif, " + "model.eselonId as eselonId, "
			+ "model.gelarBelakang as gelarBelakang, " + "model.gelarDepan as gelarDepan, "
			+ "model.golonganDarahId as golonganDarahId, " + "model.golonganPegawaiId as golonganPegawaiId, "
			+ "model.id as id, " + "model.idFinger as idFinger, " + "model.jabatanFungsionalId as jabatanFungsionalId, "
			+ "mapPeg.jabatanId as jabatanInternalId, " + "model.jabatanLamarId as jabatanLamarId, "
			+ "model.jabatanStrukturalId as jabatanStrukturalId, " + "model.jenisKelaminId as jenisKelaminId, "
			+ "model.jenisPegawaiId as jenisPegawaiId, " + "model.jenisPegawaiLamarId as jenisPegawaiLamarId, "
			+ "model.kategoryPegawaiId as kategoryPegawaiId, " + "model.kdProfile as kdProfile, "
			+ "model.kedudukanId as kedudukanId, " + "model.kodeBank as kodeBank, "
			+ "model.kodeExternal as kodeExternal, " + "model.kodeGapokId as kodeGapokId, "
			+ "model.kodePos as kodePos," + "model.kualifikasiJurusanId as kualifikasiJurusanId, "
			+ "model.nama as nama, " + "model.namaExternal as namaExternal, " + "model.namaKeluarga as namaKeluarga, "
			+ "model.namaLengkap as namaLengkap, " + "model.namaPanggilan as namaPanggilan, "
			+ "model.namaRekening as namaRekening, " + "model.negaraId as negaraId, " + "model.nikIntern as nikIntern, "
			+ "model.nilaiJabatan as nilaiJabatan, " + "model.nip as nip, " + "model.nipPns as nipPns, "
			+ "model.noBPJS as noBPJS, " + "model.noCm as noCm, " + "model.noHandphone as noHandphone, "
			+ "model.noIdentitas as noIdentitas, " + "model.noRec as noRec, " + "model.noSip as noSip, "
			+ "model.noStr as noStr, " + "model.noStruk_TTujuanLastId as noStruk_TTujuanLastId, "
			+ "model.noTlp as noTlp, " + "model.nomorRekening as nomorRekening, " + "model.npwp as npwp, "
			+ "model.pangkatId as pangkatId, " + "model.pendidikanId as pendidikanId, "
			+ "model.penghasilanTidakKenaPajakId as penghasilanTidakKenaPajakId, " + "model.pensiun as pensiun, "
			+ "model.periodePengajarId as periodePengajarId, " + "model.photoDiri as photoDiri, "
			+ "model.qPegawai as qPegawai, " + "model.qtyAnak as qtyAnak, " + "model.qtyTanggungan as qtyTanggungan, "
			+ "model.qtyTotalJiwa as qtyTotalJiwa, " + "model.rangeId as rangeId, " + "model.rekananId as rekananId, "
			+ "model.reportDisplay as reportDisplay, " + "model.ruanganId as ruanganId, "
			+ "model.satuanKerjaId as satuanKerjaId, " + "model.sewaRumah as sewaRumah, "
			+ "model.shiftKerjaId as shiftKerjaId, " + "model.statusEnabled as statusEnabled, "
			+ "model.statusKawinId as statusKawinId, " + "model.statusPegawaiId as statusPegawaiId, "
			+ "model.statusPerkawinanPegawaiId as statusPerkawinanPegawaiId, " + "model.statusRhesus as statusRhesus, "
			+ "model.sukuId as sukuId, " + "model.tanggalMeninggal as tanggalMeninggal, "
			+ "model.tempatLahir as tempatLahir, " + "model.tglBerakhirSip as tglBerakhirSip, "
			+ "model.tglBerakhirStr as tglBerakhirStr, " + "model.tglLahir as tglLahir, "
			+ "model.tglMasuk as tglMasuk, " + "model.tglPensiun as tglPensiun, "
			+ "model.tglTerbitSip as tglTerbitSip, " + "model.tglTerbitStr as tglTerbitStr, "
			+ "model.tglkeluar as tglkeluar, " + "model.titlePasienId as titlePasienId, "
			+ "model.totalNilaiScore as totalNilaiScore, " + "model.tunjanganFungsional as tunjanganFungsional, "
			+ "model.tunjanganPapua as tunjanganPapua, " + "model.tunjanganUmum as tunjanganUmum, "
			+ "model.typePegawaiId as typePegawaiId, " + "mapPeg.unitKerjaPegawaiId as unitKerjaId, "
			+ "model.wilayahTerperinci as wilayahTerperinci, " + "loginUser.namaUser as namaUser) "
			+ "from LoginUser loginUser, " + "MapPegawaiJabatanToUnitKerja mapPeg "
			+ "inner join loginUser.pegawai model " + "where model.id = :id " + "and mapPeg.pegawaiId = model.id "
			+ "and loginUser.statusEnabled is true " + "and mapPeg.isPrimary is true "
			+ "and mapPeg.statusEnabled is true " + "and model.statusEnabled is true "
			+ "and loginUser.namaUser = lower(regexp_replace(model.nama, ' ', '.'))")
	public Map<String, Object> getPegawaiWithNamaUserById(@Param("id") Integer id);

	@Query("select NEW Map(model.GolonganId as golonganId, " + "model.agamaId as agamaId, " + "model.alamat as alamat, "
			+ "model.bankRekeningAtasNama as bankRekeningAtasNama, " + "model.bankRekeningNama as bankRekeningNama, "
			+ "model.bankRekeningNomor as bankRekeningNomor, "
			+ "model.detailKategoryPegawaiId as detailKategoryPegawaiId, " + "model.dokumenId as dokumenId, "
			+ "model.email as email, " + "model.emailAlternatif as emailAlternatif, " + "model.eselonId as eselonId, "
			+ "model.gelarBelakang as gelarBelakang, " + "model.gelarDepan as gelarDepan, "
			+ "model.golonganDarahId as golonganDarahId, " + "model.golonganPegawaiId as golonganPegawaiId, "
			+ "model.id as id, " + "model.idFinger as idFinger, " + "model.jabatanFungsionalId as jabatanFungsionalId, "
			+ "mapPegawai.jabatanId as jabatanInternalId, " + "model.jabatanLamarId as jabatanLamarId, "
			+ "model.jabatanStrukturalId as jabatanStrukturalId, " + "model.jenisKelaminId as jenisKelaminId, "
			+ "model.jenisPegawaiId as jenisPegawaiId, " + "model.jenisPegawaiLamarId as jenisPegawaiLamarId, "
			+ "model.kategoryPegawaiId as kategoryPegawaiId, " + "model.kdProfile as kdProfile, "
			+ "model.kedudukanId as kedudukanId, " + "model.kodeBank as kodeBank, "
			+ "model.kodeExternal as kodeExternal, " + "model.kodeGapokId as kodeGapokId, "
			+ "model.kodePos as kodePos," + "model.kualifikasiJurusanId as kualifikasiJurusanId, "
			+ "model.nama as nama, " + "model.namaExternal as namaExternal, " + "model.namaKeluarga as namaKeluarga, "
			+ "model.namaLengkap as namaLengkap, " + "model.namaPanggilan as namaPanggilan, "
			+ "model.namaRekening as namaRekening, " + "model.negaraId as negaraId, " + "model.nikIntern as nikIntern, "
			+ "model.nilaiJabatan as nilaiJabatan, " + "model.nip as nip, " + "model.nipPns as nipPns, "
			+ "model.noBPJS as noBPJS, " + "model.noCm as noCm, " + "model.noHandphone as noHandphone, "
			+ "model.noIdentitas as noIdentitas, " + "model.noRec as noRec, " + "model.noSip as noSip, "
			+ "model.noStr as noStr, " + "model.noStruk_TTujuanLastId as noStruk_TTujuanLastId, "
			+ "model.noTlp as noTlp, " + "model.nomorRekening as nomorRekening, " + "model.npwp as npwp, "
			+ "model.pangkatId as pangkatId, " + "model.pendidikanId as pendidikanId, "
			+ "model.penghasilanTidakKenaPajakId as penghasilanTidakKenaPajakId, " + "model.pensiun as pensiun, "
			+ "model.periodePengajarId as periodePengajarId, " + "model.photoDiri as photoDiri, "
			+ "model.qPegawai as qPegawai, " + "model.qtyAnak as qtyAnak, " + "model.qtyTanggungan as qtyTanggungan, "
			+ "model.qtyTotalJiwa as qtyTotalJiwa, " + "model.rangeId as rangeId, " + "model.rekananId as rekananId, "
			+ "model.reportDisplay as reportDisplay, " + "model.ruanganId as ruanganId, "
			+ "model.satuanKerjaId as satuanKerjaId, " + "model.sewaRumah as sewaRumah, "
			+ "model.shiftKerjaId as shiftKerjaId, " + "model.statusEnabled as statusEnabled, "
			+ "model.statusKawinId as statusKawinId, " + "model.statusPegawaiId as statusPegawaiId, "
			+ "model.statusPerkawinanPegawaiId as statusPerkawinanPegawaiId, " + "model.statusRhesus as statusRhesus, "
			+ "model.sukuId as sukuId, " + "model.tanggalMeninggal as tanggalMeninggal, "
			+ "model.tempatLahir as tempatLahir, " + "model.tglBerakhirSip as tglBerakhirSip, "
			+ "model.tglBerakhirStr as tglBerakhirStr, " + "model.tglLahir as tglLahir, "
			+ "model.tglMasuk as tglMasuk, " + "model.tglPensiun as tglPensiun, "
			+ "model.tglTerbitSip as tglTerbitSip, " + "model.tglTerbitStr as tglTerbitStr, "
			+ "model.tglkeluar as tglkeluar, " + "model.titlePasienId as titlePasienId, "
			+ "model.totalNilaiScore as totalNilaiScore, " + "model.tunjanganFungsional as tunjanganFungsional, "
			+ "model.tunjanganPapua as tunjanganPapua, " + "model.tunjanganUmum as tunjanganUmum, "
			+ "model.typePegawaiId as typePegawaiId, " + "mapPegawai.subUnitKerjaPegawaiId as unitKerjaId, "
			+ "model.wilayahTerperinci as wilayahTerperinci, " + "loginUser.namaUser as namaUser) "
			+ "from LoginUser loginUser, MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "inner join loginUser.pegawai model " + "where mapPegawai.pegawaiId = model.id "
			+ "and mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and loginUser.statusEnabled is true " + "and model.statusEnabled is true " + "and model.id = :id")
	public Map<String, Object> getPegawaiWithNamaUserByIdCustom(@Param("id") Integer id);

	@Query("select model from Pegawai model where model.statusEnabled is true and model.statusPegawai.kdStatusPegawai=2")
	public List<Pegawai> findAllPegawai();

	@Query("select NEW com.jasamedika.medifirst2000.entities.Pegawai(p.namaLengkap, p.namaPanggilan, p.nikIntern, p.nipPns, p.noIdentitas,p.npwp,p.id) "
			+ "from SettingDataFixed s,JenisPegawai j,Pegawai p where  j.kdJenisPegawai=s.nilaiField and j.id=p.jenisPegawaiId and j.id= (Select cast(s.nilaiField as int) "
			+ "from  SettingDataFixed s where s.namaField='KdJenisPegawaiDokter') and p.qPegawai=:kdPegawai group by p.id")
	public Pegawai findByKdPegawaiDokter(@Param("kdPegawai") short kdPegawai);

	@Query("select NEW com.jasamedika.medifirst2000.entities.Pegawai(p.namaLengkap, p.namaPanggilan, p.nikIntern, p.nipPns, p.noIdentitas,p.npwp,p.id,p.qPegawai) "
			+ "from SettingDataFixed s,JenisPegawai j,Pegawai p where  j.kdJenisPegawai=s.nilaiField and j.id=p.jenisPegawaiId and j.id= (Select cast(s.nilaiField as int) "
			+ "from  SettingDataFixed s where s.namaField='KdJenisPegawaiDokter') and p.statusEnabled is true and  p.statusPegawai.kdStatusPegawai=2 group by p.id "
			+ "order by p.namaLengkap")
	public List<Pegawai> getDokters();

	@Query("select p from Pegawai p where p.statusEnabled is true and p.jabatanFungsionalId=:jabatanFungsionalId")
	public List<Pegawai> findByJabatanFungsional(@Param("jabatanFungsionalId") Integer jabatanFungsionalId);

	@Query("select p from Pegawai p join fetch p.jenisPegawai where p.statusEnabled is true and p.jenisPegawai.id=:getSettingDataFixed and p.namaLengkap like :key")
	public List<Pegawai> findByJenisPetugas(@Param("getSettingDataFixed") Integer getSettingDataFixed,
			@Param("key") String key);

	@Query("select p from Pegawai p where p.statusEnabled is true and p.satuanKerjaId=:satuanKerjaId")
	public List<Pegawai> findBySatuanKerja(@Param("satuanKerjaId") Integer satuanKerjaId);

	@Query("select NEW com.jasamedika.medifirst2000.entities.Pegawai(p.id, p.namaLengkap) from Pegawai p where p.statusEnabled is true and p.satuanKerjaId=:satuanKerjaId")
	public List<Pegawai> findBySatuanKerja2(@Param("satuanKerjaId") Integer satuanKerjaId);

	// supir ambulance - sarpras
	@Query("select NEW Map(p.id as idPegawai,p.namaLengkap as namaPegawai) from Pegawai p,Jabatan jb "
			+ "where p.statusEnabled is true and jb.id=p.jabatanFungsionalId and jb.namaJabatan like '%Pengemudi%'")
	public List<PegawaiVO> getSupirAmbulance();

	// supir kendaraan dinas - sarpras
	@Query("select NEW Map(p.id as idPegawai,p.namaLengkap as namaPegawai) from Pegawai p,Jabatan jb "
			+ "where p.statusEnabled is true and jb.id=p.jabatanFungsionalId and jb.namaJabatan like '%Pengemudi%'")
	public List<PegawaiVO> getSupirKendaraanDinas();

	@Query("select NEW Map(p.id as idPegawai,p.namaLengkap as namaPegawai,mapPegawai.jabatan.id as idJabatanInternal, mapPegawai.jabatan.namaJabatan as namaJabatan) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai p "
			+ "where mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and p.statusEnabled is true " + "and p.ruangan.id=:ruangan")
	public List<Map<String, Object>> findByRuanganKerja(@Param("ruangan") Integer ruangan);

	@Query("select NEW Map(p.id as idPegawai," + "p.namaLengkap as namaPegawai,"
			+ "jabatanInternal.id as idJabatanInternal," + "jabatanInternal.namaJabatan as namaJabatan) "
			+ "from MapPegawaiJabatanToUnitKerja mappeg " + "left join mappeg.pegawai p "
			+ "left join mappeg.jabatan jabatanInternal " + "left join mappeg.subUnitKerjaPegawai subUnitKerja "
			+ "where p.statusEnabled is true " + "and mappeg.isPrimary is true " + "and mappeg.statusEnabled is true "
			+ "and subUnitKerja.id = :subUnitKerja " + "order by p.nama asc")
	public List<Map<String, Object>> findByUnitKerja(@Param("subUnitKerja") Integer subUnitKerja);

	@Query("select distinct NEW Map(p.id as idPegawai," + "p.namaLengkap as namaPegawai) "
			+ "from MapPegawaiJabatanToUnitKerja mappeg " + "left join mappeg.pegawai p "
			+ "left join mappeg.subUnitKerjaPegawai subUnitKerja " + "where p.statusEnabled is true "
			+ "and mappeg.statusEnabled is true " + "and subUnitKerja.id = :subUnitKerja " + "order by namaPegawai asc")
	public List<Map<String, Object>> findSimpleByUnitKerja(@Param("subUnitKerja") Integer subUnitKerja);

	@Query("select NEW Map(p.id as idPegawai," + "p.namaLengkap as namaPegawai,"
			+ "jabatanInternal.id as idJabatanInternal," + "jabatanInternal.namaJabatan as namaJabatan) "
			+ "from MapPegawaiJabatanToUnitKerja mappeg " + "left join mappeg.pegawai p "
			+ "left join mappeg.jabatan jabatanInternal " + "left join mappeg.subUnitKerjaPegawai subUnitKerja "
			+ "where p.statusEnabled is true " + "and mappeg.isPrimary is true " + "and mappeg.statusEnabled is true "
			+ "and subUnitKerja.id = :subUnitKerja " + "and p.id = :idPegawai")
	public List<Map<String, Object>> findByUnitKerja(@Param("subUnitKerja") Integer subUnitKerja,
			@Param("idPegawai") Integer idPegawai);

	@Query("select p.jabatanStruktural from Pegawai p where p.id=:id")
	public Jabatan findJabatanByIdPegawai(@Param("id") Integer id);

	@Query("select peg from MapPegawaiJabatanToUnitKerja mappeg left join mappeg.pegawai peg where mappeg.pegawaiId=:idPegawai "
			+ "and mappeg.jabatanId=:idJabatan and mappeg.statusEnabled is true")
	public Pegawai findPegawaiByIdJabatanInternal(@Param("idPegawai") Integer idPegawai,
			@Param("idJabatan") Integer idJabatan);

	@Query("select mapPegawai.jabatan from MapPegawaiJabatanToUnitKerja mapPegawai left join mapPegawai.pegawai p "
			+ "where mapPegawai.isPrimary is true and mapPegawai.statusEnabled is true and p.id=:id")
	public Jabatan findJabatanInternalByIdPegawai(@Param("id") Integer id);

	@Query("select j " + "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai p "
			+ "left join mapPegawai.jabatan j " + "where mapPegawai.statusEnabled is true "
			+ "and p.statusEnabled is true " + "and j.statusEnabled is true " + "and p.id=:id " + "and j.id=:idJabatan")
	public Jabatan findJabatanInternalByIdPegawai(@Param("id") Integer id, @Param("idJabatan") Integer idJabatan);

	@Query("select p from Pegawai p where p.statusEnabled is true ")
	public List<Pegawai> find();

	@Query("select p.idFinger from Pegawai p where p.id = :idPegawai")
	public String getidFinger(@Param("idPegawai") Integer idPegawai);

	public Pegawai findByIdFinger(String idFinger);

	@Query("select new Map ( pegawai.namaLengkap as nama, pegawai.id as idPegawai,jabatan.id as idJabatanInternal) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai left join mapPegawai.pegawai pegawai left join mapPegawai.jabatan jabatan "
			+ "where mapPegawai.isPrimary is true and mapPegawai.statusEnabled is true and pegawai.statusEnabled is true")
	public List<Map<String, Object>> dataAllPegawai();

	@Query("select new Map (" + "a.id as id, " + "a.namaLengkap as namaLengkap, " + "b.jenisPegawai as jenisPegawai) "
			+ "from Pegawai a " + "left join a.jenisPegawai b " + "where b.id in (select d.id "
			+ "from MapJenisPetugasPToJenisPegawai c " + "left join c.jenisPegawai d " + "left join c.jenisPetugasPe e "
			+ "where a.statusEnabled is true and e.id=:id)")
	public List<Map<String, Object>> getPegawaiByPelaksana(@Param("id") Integer id);

	@Query("select new map (pegawai.id as idPegawai, " + "pegawai.nama as nama, "
			+ "pegawai.namaLengkap as namaLengkap, " + " pegawai.tglLahir as tglLahir, "
			+ "  kelompokJabatan.detailKelompokJabatan as kelompokJabatan, " + " pegawai.tglMasuk as tglMasuk, "
			+ " pegawai.tglkeluar as tglKeluar, " + " pegawai.bankRekeningAtasNama as bankRekeningAtasNama, "
			+ " pegawai.bankRekeningNama as bankRekeningNama, " + " pegawai.bankRekeningNomor as bankRekeningNomor, "
			+ " pegawai.namaRekening as namaRekening, " + " pegawai.npwp as npwp, " + " pegawai.alamat as alamat, "
			+ " pegawai.kodePos as kodePos, " + " pegawai.nilaiJabatan as nilaiJabatan, " + " pegawai.grade as grade, "
			+ "pegawai.noSip as noSip, " + "pegawai.tglTerbitSip as tglTerbitSip,"
			+ "pegawai.tglBerakhirSip as tglBerakhirSip," + "pegawai.noStr as noStr, "
			+ "pegawai.tglTerbitStr as tglTerbitStr, " + "pegawai.tglBerakhirStr as tglBerakhirStr,"
			+ "pegawai.gelarDepan as gelarDepan, " + " pegawai.gelarBelakang as gelarBelakang, "
			+ " pegawai.tempatLahir as tempatLahir," + "golongan.golonganPegawai as namaGolongan, "
			+ "agama.agama as agama, " + "detailKategoryPegawai.detailKategoryPegawai as detailKategoryPegawai, "
			+ "dokumen.namaJudulDokumen as namaJudulDokumen, " + "eselon.eselon as eselon, "
			+ "golonganDarah.golonganDarah as golonganDarah, " + "jabatanFungsional.namaJabatan as namaJabatan, "
			+ "jabatanLamar.namaJabatan as jabatanLamar, " + "jabatanStruktural.namaJabatan as jabatanStruktural, "
			+ "jenisKelamin.jenisKelamin as jenisKelamin, " + "jenisPegawai.jenisPegawai as jenisPegawai, "
			+ "jenisPegawaiLamar.jenisPegawai as jenisPegawaiLamar, "
			+ "kategoriPegawai.kategoryPegawai as kategoriPegawai, " + "kedudukan.name as kedudukan, "
			+ "kualifikasiJurusan.kualifikasiJurusan as kualifikasiJurusan, " + "negara.namaNegara as namaNegara,  "
			+ "pangkat.namaPangkat as namaPangkat, " + "pendidikan.namaPendidikan as namaPendidikan, "
			+ "penghasilanTidakKenaPajak.deskripsi as penghasilanTidakKenaPajak, " + "range.namaRange as namaRange, "
			+ "pegawai.nipPns as nipPns, " + "pegawai.nip as nip, " + "pegawai.nikIntern as nikIntern, "
			+ "pegawai.tanggalMeninggal as tanggalMeninggal, " + "pegawai.idFinger as idFinger, "
			+ "ruangan.id as idRuangan, " + "ruangan.namaRuangan as namaRuangan, "
			+ "satuanKerja.satuanKerja as satuanKerja, " + "shiftKerja.name as shiftKerja, "
			+ "shiftKerja.id as idKelompokShiftKerja," + "statusKawin.statusPerkawinan as statusKawin, "
			+ "statusPegawai.statusPegawai as statusPegawai, "
			+ "statusPerkawinanPegawai.statusPerkawinan as statusPerkawinanPegawai, " + "suku.suku as suku, "
			+ "titlePasien.namaTitle as titlePasien, " + "typePegawai.typePegawai as typePegawai) "
			+ "from Pegawai pegawai " + "left join pegawai.golonganPegawai golongan "
			+ "left join pegawai.detailKategoryPegawai detailKategoryPegawai " + "left join pegawai.agama agama "
			+ "left join pegawai.detailKelompokJabatan kelompokJabatan " + "left join pegawai.dokumen dokumen "
			+ "left join pegawai.eselon eselon " + "left join pegawai.golonganDarah golonganDarah "
			+ "left join pegawai.jabatanFungsional jabatanFungsional " + "left join pegawai.jabatanLamar jabatanLamar "
			+ "left join pegawai.jabatanStruktural jabatanStruktural " + "left join pegawai.jenisKelamin jenisKelamin "
			+ "left join pegawai.jenisPegawai jenisPegawai " + "left join pegawai.jenisPegawaiLamar jenisPegawaiLamar "
			+ "left join pegawai.kategoryPegawai kategoriPegawai " + "left join pegawai.kedudukan kedudukan "
			+ "left join pegawai.kualifikasiJurusan kualifikasiJurusan " + "left join pegawai.negara negara "
			+ "left join pegawai.pangkat pangkat " + "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.penghasilanTidakKenaPajak penghasilanTidakKenaPajak "
			+ "left join pegawai.range range " + "left join pegawai.ruangan ruangan "
			+ "left join pegawai.satuanKerja satuanKerja " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join pegawai.statusKawin statusKawin " + "left join pegawai.statusPegawai statusPegawai "
			+ "left join pegawai.statusPerkawinanPegawai statusPerkawinanPegawai " + "left join pegawai.suku suku "
			+ "left join pegawai.titlePasien titlePasien " + "left join pegawai.typePegawai typePegawai "
			+ "where pegawai.statusEnabled is true " + "and pegawai.kategoryPegawaiId in :listKategoryPegawaiId "
			+ "and kedudukan.id not in :listKedudukan " + "order by pegawai.nama")
	public List<Map<String, Object>> findAllPegawaiNoPaging(
			@Param("listKategoryPegawaiId") List<Integer> listKategoryPegawaiId,
			@Param("listKedudukan") List<Integer> listKedudukan);

	@Query("select new map (pegawai.id as idPegawai," + "pegawai.nama as nama," + "pegawai.namaLengkap as namaLengkap,"
			+ "pegawai.tglLahir as tglLahir," + "pegawai.qtyAnak as qtyAnak,"
			+ "pegawai.qtyTanggungan as qtyTanggungan," + "pegawai.qtyTotalJiwa as qtyTotalJiwa,"
			+ "kelompokJabatan.detailKelompokJabatan as kelompokJabatan," + "pegawai.tglMasuk as tglMasuk,"
			+ "pegawai.tglkeluar as tglKeluar," + "pegawai.kodeBank as kodeBank,"
			+ "pegawai.bankRekeningAtasNama as bankRekeningAtasNama," + "pegawai.bankRekeningNama as bankRekeningNama,"
			+ "pegawai.bankRekeningNomor as bankRekeningNomor," + "pegawai.kodeGapokId as idKodeGapok,"
			+ "pegawai.email as email," + "pegawai.emailAlternatif as emailAlternatif," + "pegawai.noTlp as noTlp,"
			+ "pegawai.noHandphone as noHandphone," + "pegawai.npwp as npwp," + "pegawai.noBPJS as noBPJS,"
			+ "pegawai.noCm as noCm," + "pegawai.alamat as alamat," + "pegawai.kodePos as kodePos,"
			+ "pegawai.nilaiJabatan as nilaiJabatan," + "levelTingkat.id as idLevelTingkat,"
			+ "levelTingkat.levelTingkat as levelTingkat," + "pegawai.grade as grade," + "pegawai.noSip as noSip,"
			+ "pegawai.tglTerbitSip as tglTerbitSip," + "pegawai.tglBerakhirSip as tglBerakhirSip,"
			+ "pegawai.noStr as noStr," + "pegawai.tglTerbitStr as tglTerbitStr,"
			+ "pegawai.tglBerakhirStr as tglBerakhirStr," + "pegawai.gelarDepan as gelarDepan,"
			+ "pegawai.gelarBelakang as gelarBelakang," + "pegawai.tempatLahir as tempatLahir,"
			+ "golongan.golonganPegawai as namaGolongan," + "agama.agama as agama,"
			+ "detailKategoryPegawai.detailKategoryPegawai as detailKategoryPegawai,"
			+ "dokumen.namaJudulDokumen as namaJudulDokumen," + "eselon.eselon as eselon,"
			+ "golonganDarah.golonganDarah as golonganDarah," + "pegawai.statusRhesus as rhesusGolonganDarah,"
			+ "jabatanFungsional.namaJabatan as namaJabatan," + "jabatanLamar.namaJabatan as jabatanLamar,"
			+ "jabatanStruktural.namaJabatan as jabatanStruktural," + "jenisKelamin.jenisKelamin as jenisKelamin,"
			+ "jenisPegawai.jenisPegawai as jenisPegawai," + "jenisPegawaiLamar.jenisPegawai as jenisPegawaiLamar,"
			+ "kategoriPegawai.kategoryPegawai as kategoriPegawai," + "kedudukan.id as kedudukanId,"
			+ "kedudukan.name as kedudukan," + "kualifikasiJurusan.kualifikasiJurusan as kualifikasiJurusan,"
			+ "negara.namaNegara as namaNegara," + "pangkat.namaPangkat as namaPangkat,"
			+ "pendidikan.namaPendidikan as namaPendidikan,"
			+ "penghasilanTidakKenaPajak.deskripsi as penghasilanTidakKenaPajak,"
			+ "pegawai.totalNilaiScore as totalNilaiScore," + "pegawai.tunjanganFungsional as tunjanganFungsional,"
			+ "pegawai.tunjanganPapua as tunjanganPapua," + "pegawai.tunjanganUmum as tunjanganUmum,"
			+ "pegawai.noIdentitas as noIdentitas," + "pegawai.nipPns as nipPns," + "pegawai.nip as nip,"
			+ "pegawai.nikIntern as nikIntern," + "pegawai.tanggalMeninggal as tanggalMeninggal,"
			+ "pegawai.pensiun as usiaPensiun," + "pegawai.tglPensiun as tglPensiun," + "pegawai.idFinger as idFinger,"
			+ "ruangan.id as idRuangan," + "ruangan.namaRuangan as namaRuangan," + "rekanan.id as idRuangan,"
			+ "rekanan.namaRekanan as namaRekanan," + "satuanKerja.satuanKerja as satuanKerja,"
			+ "shiftKerja.name as shiftKerja," + "shiftKerja.id as idKelompokShiftKerja,"
			+ "statusKawin.statusPerkawinan as statusKawin," + "statusPegawai.statusPegawai as statusPegawai,"
			+ "statusPerkawinanPegawai.statusPerkawinan as statusPerkawinanPegawai," + "suku.suku as suku,"
			+ "typePegawai.typePegawai as typePegawai," + "pegawai.statusEnabled as statusEnabled)"
			+ "from Pegawai pegawai " + "left join pegawai.detailKategoryPegawai detailKategoryPegawai "
			+ "left join pegawai.agama agama " + "left join pegawai.detailKelompokJabatan kelompokJabatan "
			+ "left join pegawai.dokumen dokumen " + "left join pegawai.eselon eselon "
			+ "left join pegawai.golonganDarah golonganDarah "
			+ "left join pegawai.jabatanFungsional jabatanFungsional " + "left join pegawai.jabatanLamar jabatanLamar "
			+ "left join pegawai.jabatanStruktural jabatanStruktural " + "left join pegawai.jenisKelamin jenisKelamin "
			+ "left join pegawai.jenisPegawai jenisPegawai " + "left join pegawai.jenisPegawaiLamar jenisPegawaiLamar "
			+ "left join pegawai.kategoryPegawai kategoriPegawai " + "left join pegawai.kedudukan kedudukan "
			+ "left join pegawai.kualifikasiJurusan kualifikasiJurusan "
			+ "left join pegawai.levelTingkat levelTingkat " + "left join pegawai.negara negara "
			+ "left join pegawai.pangkat pangkat " + "left join pangkat.kdGolonganPegawai golongan "
			+ "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.penghasilanTidakKenaPajak penghasilanTidakKenaPajak "
			+ "left join pegawai.ruangan ruangan " + "left join pegawai.satuanKerja satuanKerja "
			+ "left join pegawai.rekanan rekanan " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join pegawai.statusKawin statusKawin " + "left join pegawai.statusPegawai statusPegawai "
			+ "left join pegawai.statusPerkawinanPegawai statusPerkawinanPegawai " + "left join pegawai.suku suku "
			+ "left join pegawai.typePegawai typePegawai " + "where pegawai.statusEnabled is true "
			+ "and pegawai.kategoryPegawaiId = :idKategoryPegawai " + // PNS
			"and kedudukan.id not in :listKedudukan " + "order by pegawai.nama")
	public List<Map<String, Object>> findAllPegawaiByKategory(@Param("listKedudukan") List<Integer> listKedudukan,
			@Param("idKategoryPegawai") Integer idKategoryPegawai);

	@Query("select new map (jabatanInternal.namaJabatan as jabatanInternal, "
			+ "jabatanInternal.id as idJabatanInternal, " + "unitKerja.id as idUnitKerja, "
			+ "unitKerja.name as unitKerja, " + "subUnitKerja.id as idSubUnitKerja, "
			+ "subUnitKerja.name as subUnitKerja, " + "atasanLangsung.namaLengkap as atasanLangsung, "
			+ "pejabatPenilai.namaLengkap as pejabatPenilai, "
			+ "mapPegawai.atasanLangsungDireksi as atasanLangsungUntukPejabatDireksi, "
			+ "mapPegawai.pejabatPenilaiDireksi as pejabatPenilaiUntukPejabatDireksi) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join mapPegawai.jabatan jabatanInternal "
			+ "left join mapPegawai.atasanLangsung atasanLangsung "
			+ "left join mapPegawai.pejabatPenilai pejabatPenilai " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and pegawai.statusEnabled is true "
			+ "and pegawai.id = :idPegawai")
	public Map<String, Object> getMapJabatanUnitSubAllPegawai(@Param("idPegawai") Integer idPegawai);

	@Query("select new Map(pegawai.id as idPegawai, " + "loginuser.namaUser as namaUser) " + "from LoginUser loginuser "
			+ "left join loginuser.pegawai pegawai " + "where loginuser.statusEnabled is true "
			+ "and pegawai.statusEnabled is true " + "and pegawai.id = :idPegawai " + "order by pegawai.id")
	public List<Map<String, Object>> getUsernameByIdPegawai(@Param("idPegawai") Integer idPegawai);

	@Query("select new map (pegawai.id as idPegawai, " + "pegawai.nama as nama, "
			+ "pegawai.namaLengkap as namaLengkap, " + " pegawai.tglLahir as tglLahir, "
			+ "  kelompokJabatan.detailKelompokJabatan as kelompokJabatan, " + " pegawai.tglMasuk as tglMasuk, "
			+ " pegawai.tglkeluar as tglKeluar, " + " pegawai.bankRekeningAtasNama as bankRekeningAtasNama, "
			+ " pegawai.bankRekeningNama as bankRekeningNama, " + " pegawai.bankRekeningNomor as bankRekeningNomor, "
			+ " pegawai.namaRekening as namaRekening, " + " pegawai.npwp as npwp, " + " pegawai.alamat as alamat, "
			+ " pegawai.kodePos as kodePos, " + " pegawai.nilaiJabatan as nilaiJabatan, " + " pegawai.grade as grade, "
			+ "pegawai.gelarDepan as gelarDepan, " + " pegawai.gelarBelakang as gelarBelakang, "
			+ " pegawai.tempatLahir as tempatLahir," + "golongan.golonganPegawai as namaGolongan, "
			+ "agama.agama as agama, " + "detailKategoryPegawai.detailKategoryPegawai as detailKategoryPegawai, "
			+ "dokumen.namaJudulDokumen as namaJudulDokumen, " + "eselon.eselon as eselon, "
			+ "golonganDarah.golonganDarah as golonganDarah, " + "jabatanFungsional.namaJabatan as namaJabatan, "
			+ "jabatanInternal.namaJabatan as jabatanInternal, " + "jabatanInternal.id as idJabatanInternal,"
			+ "jabatanLamar.namaJabatan as jabatanLamar, " + "jabatanStruktural.namaJabatan as jabatanStruktural, "
			+ "jenisKelamin.jenisKelamin as jenisKelamin, " + "jenisPegawai.jenisPegawai as jenisPegawai, "
			+ "jenisPegawaiLamar.jenisPegawai as jenisPegawaiLamar, "
			+ "kategoriPegawai.kategoryPegawai as kategoriPegawai, " + "kedudukan.name as kedudukan, "
			+ "kualifikasiJurusan.kualifikasiJurusan as kualifikasiJurusan, " + "negara.namaNegara as namaNegara,  "
			+ "pangkat.namaPangkat as namaPangkat, " + "pendidikan.namaPendidikan as namaPendidikan, "
			+ "penghasilanTidakKenaPajak.deskripsi as penghasilanTidakKenaPajak, " + "range.namaRange as namaRange, "
			+ "pegawai.nipPns as nipPns, " + "pegawai.nip as nip, " + "unitKerja.id as idUnitKerja, "
			+ "unitKerja.name as unitKerja, " + "subUnitKerja.id as idSubUnitKerja, "
			+ "subUnitKerja.name as subUnitKerja, " + "pegawai.nikIntern as nikIntern, "
			+ "pegawai.tanggalMeninggal as tanggalMeninggal, " + "pegawai.idFinger as idFinger, "
			+ "ruangan.id as idRuangan, " + "ruangan.namaRuangan as namaRuangan, "
			+ "satuanKerja.satuanKerja as satuanKerja, " + "shiftKerja.name as shiftKerja, "
			+ "shiftKerja.id as idKelompokShiftKerja," + "statusKawin.statusPerkawinan as statusKawin, "
			+ "statusPegawai.statusPegawai as statusPegawai, "
			+ "statusPerkawinanPegawai.statusPerkawinan as statusPerkawinanPegawai, " + "suku.suku as suku, "
			+ "titlePasien.namaTitle as titlePasien, " + "typePegawai.typePegawai as typePegawai) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join pegawai.golonganPegawai golongan "
			+ "left join pegawai.detailKategoryPegawai detailKategoryPegawai " + "left join pegawai.agama agama "
			+ "left join pegawai.detailKelompokJabatan kelompokJabatan " + "left join pegawai.dokumen dokumen "
			+ "left join pegawai.eselon eselon " + "left join pegawai.golonganDarah golonganDarah "
			+ "left join pegawai.jabatanFungsional jabatanFungsional " + "left join mapPegawai.jabatan jabatanInternal "
			+ "left join pegawai.jabatanLamar jabatanLamar " + "left join pegawai.jabatanStruktural jabatanStruktural "
			+ "left join pegawai.jenisKelamin jenisKelamin " + "left join pegawai.jenisPegawai jenisPegawai "
			+ "left join pegawai.jenisPegawaiLamar jenisPegawaiLamar "
			+ "left join pegawai.kategoryPegawai kategoriPegawai " + "left join pegawai.kedudukan kedudukan "
			+ "left join pegawai.kualifikasiJurusan kualifikasiJurusan " + "left join pegawai.negara negara "
			+ "left join pegawai.pangkat pangkat " + "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.penghasilanTidakKenaPajak penghasilanTidakKenaPajak "
			+ "left join pegawai.range range " + "left join pegawai.ruangan ruangan "
			+ "left join pegawai.satuanKerja satuanKerja " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join pegawai.statusKawin statusKawin " + "left join pegawai.statusPegawai statusPegawai "
			+ "left join pegawai.statusPerkawinanPegawai statusPerkawinanPegawai " + "left join pegawai.suku suku "
			+ "left join pegawai.titlePasien titlePasien " + "left join pegawai.typePegawai typePegawai "
			+ "where mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and pegawai.statusEnabled is true " + "and pegawai.kategoryPegawaiId not in :listKategoryPegawaiId "
			+ "and kedudukan.id not in :listKedudukan " + "order by pegawai.nama")
	public List<Map<String, Object>> findAllPegawaiLainLain(
			@Param("listKategoryPegawaiId") List<Integer> listKategoryPegawaiId,
			@Param("listKedudukan") List<Integer> listKedudukan);

	@Query("select new Map(p.nipPns as nip, p.namaLengkap as namaPegawai , p.tglLahir as tglLahir, p.tempatLahir as tempatLahir, "
			+ "j.kdJabatan as idJabatan,j.namaJabatan as namaJabatan, "
			+ "g.id as idGolongan,g.golonganPegawai as namaGolongan , "
			+ " sk.statusPerkawinan as idStatusKawin, sk.statusPerkawinan as statusPerkawinan, "
			+ "a.agama as namaAgama, a.kdAgama as idAgama , "
			+ " s.kdSatuanKerja as idSatuanKerja,s.satuanKerja as satuanKerja , "
			+ " js.kdJabatan as idJabatanStruktural,js.namaJabatan as namaJabatanStruktural, "
			+ " jf.kdJabatan as idJabatanFungsional,jf.namaJabatan as namaJabatanFungsional "
			+ ") from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai p "
			+ "left join mapPegawai.jabatan j " + "left join p.golonganPegawai g " + "left join p.statusKawin sk "
			+ "left join p.agama a " + "left join p.satuanKerja s " + "left join p.jabatanStruktural js "
			+ "left join p.jabatanFungsional jf " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and p.statusEnabled is true "
			+ "and p.namaLengkap like :namaPegawai " + "order by p.namaLengkap")
	public List<Map<String, Object>> findAllPegawaiNoPagingSearch(@Param("namaPegawai") String namaPegawai);

	@Query("select p.id from Pegawai p where p.statusEnabled is true")
	public List<Integer> findAllIdPegawai();

	@Query("select p.id from Pegawai p " + "left join p.statusPegawai statusPegawai "
			+ "left join p.kategoryPegawai kategori " + "where p.statusEnabled is true and statusPegawai.id = 2 "
			+ "and kategori.id != 11 ")
	public List<Integer> findPegawaiStatusAktifAndKaryawan();

	@Query("select kategori.id " + "from Pegawai p " + "left join p.statusPegawai statusPegawai "
			+ "left join p.kategoryPegawai kategori " + "where p.statusEnabled is true " + "and p.id = :idPegawai")
	public Integer getStatusKategoryPegawai(@Param("idPegawai") Integer idPegawai);

	@Query("select p from Pegawai p " + "left join p.statusPegawai statusPegawai "
			+ "left join p.shiftKerja shiftKerja " + "where p.statusEnabled is true "
			+ "and to_char(p.tglMasuk,'yyyy-MM-dd') <= :tahun " + "and shiftKerja.id= :idKelompokShift ")
	public List<Pegawai> findPegawaiStatusAktif(@Param("idKelompokShift") Integer idKelompokShift,
			@Param("tahun") String tahun);

	String strQryJabatanCetak = "select new map (pegawai.id as idPegawai, " + "pegawai.namaLengkap as nama, "
			+ "golongan.id as idGolongan,golongan.golonganPegawai as namaGolongan, " + "pegawai.noTlp as noTlp, "
			+ "pegawai.noHandphone as noHandphone, " + "agama.agama as agama, " + "pegawai.alamat as alamat, "
			+ "detailKategoryPegawai.detailKategoryPegawai as detailKategoryPegawai, "
			+ "dokumen.namaJudulDokumen as namaJudulDokumen, " + "eselon.eselon as eselon, "
			+ "golonganDarah.golonganDarah as golonganDarah, " + "jabatanFungsional.namaJabatan as namaJabatan, "
			+ "jabatanInternal.namaJabatan as jabatanInternal, " + "jabatanInternal.id as idJabatanInternal,"
			+ "pegawai.nomorRekening as nomorRekening, " + "jabatanLamar.namaJabatan as jabatanLamar, "
			+ "jabatanStruktural.namaJabatan as jabatanStruktural, " + "jenisKelamin.jenisKelamin as jenisKelamin, "
			+ "jenisPegawai.jenisPegawai as jenisPegawai, " + "jenisPegawaiLamar.jenisPegawai as jenisPegawaiLamar, "
			+ "kategoriPegawai.kategoryPegawai as kategoriPegawai, " + "kedudukan.name as kedudukan, "
			+ "kualifikasiJurusan.kualifikasiJurusan as kualifikasiJurusan, " + "negara.namaNegara as namaNegara,  "
			+ "shiftKerja.factorRate as factorRate, " + "pangkat.namaPangkat as namaPangkat, "
			+ "pendidikan.namaPendidikan as namaPendidikan, "
			+ "penghasilanTidakKenaPajak.deskripsi as penghasilanTidakKenaPajak, " + "range.namaRange as namaRange, "
			+ "pegawai.nipPns as nipPns, " + "pegawai.nip as nip, " + "pegawai.nikIntern as nikIntern, "
			+ "pegawai.tglMasuk as tglMasuk, " + "pegawai.idFinger as idFinger, " + "ruangan.id as idRuangan, "
			+ "ruangan.namaRuangan as namaRuangan, " + "unitKerja.id as idUnitKerja, " + "unitKerja.name as unitKerja, "
			+ "subUnitKerja.id as idSubUnitKerja, " + "subUnitKerja.name as subUnitKerja, "
			+ "satuanKerja.satuanKerja as satuanKerja, " + "shiftKerja.name as shiftKerja, "
			+ "shiftKerja.id as idKelompokShiftKerja," + "statusKawin.statusPerkawinan as statusKawin, "
			+ "statusPegawai.statusPegawai as statusPegawai, "
			+ "statusPerkawinanPegawai.statusPerkawinan as statusPerkawinanPegawai, " + "suku.suku as suku, "
			+ "departemen.namaDepartemen as departemen, " + "titlePasien.namaTitle as titlePasien, "
			+ "typePegawai.typePegawai as typePegawai) " + "from MapPegawaiJabatanToUnitKerja mappegawai "
			+ "left join mappegawai.pegawai pegawai " + "left join pegawai.golonganPegawai golongan "
			+ "left join pegawai.agama agama " + "left join pegawai.detailKategoryPegawai detailKategoryPegawai "
			+ "left join pegawai.dokumen dokumen " + "left join pegawai.eselon eselon "
			+ "left join pegawai.golonganDarah golonganDarah "
			+ "left join pegawai.jabatanFungsional jabatanFungsional " + "left join mappegawai.jabatan jabatanInternal "
			+ "left join pegawai.jabatanLamar jabatanLamar " + "left join pegawai.jabatanStruktural jabatanStruktural "
			+ "left join pegawai.jenisKelamin jenisKelamin " + "left join pegawai.jenisPegawai jenisPegawai "
			+ "left join pegawai.jenisPegawaiLamar jenisPegawaiLamar "
			+ "left join pegawai.kategoryPegawai kategoriPegawai " + "left join pegawai.kedudukan kedudukan "
			+ "left join pegawai.kualifikasiJurusan kualifikasiJurusan " + "left join pegawai.negara negara "
			+ "left join pegawai.pangkat pangkat " + "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.penghasilanTidakKenaPajak penghasilanTidakKenaPajak "
			+ "left join pegawai.range range " + "left join pegawai.ruangan ruangan "
			+ "left join mappegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mappegawai.unitKerjaPegawai unitKerja " + "left join pegawai.satuanKerja satuanKerja "
			+ "left join pegawai.shiftKerja shiftKerja " + "left join pegawai.statusKawin statusKawin "
			+ "left join pegawai.statusPegawai statusPegawai "
			+ "left join pegawai.statusPerkawinanPegawai statusPerkawinanPegawai " + "left join pegawai.suku suku "
			+ "left join pegawai.titlePasien titlePasien " + "left join ruangan.departemen departemen "
			+ "left join pegawai.typePegawai typePegawai " + "where pegawai.statusEnabled is true "
			+ "and mappegawai.statusEnabled is true ";

	String cdtJabatanCetak = "and mappegawai.jabatanId =:jabatanId and pegawai.id =:pegawaiId";

	String cdtJabatanUtamaCetak = "and mappegawai.isPrimary is true and pegawai.id =:pegawaiId";

	@Query(strQryJabatanCetak + cdtJabatanUtamaCetak)
	public Map<String, Object> findPegawaiById(@Param("pegawaiId") Integer idPegawai);

	@Query(strQryJabatanCetak + cdtJabatanCetak)
	public Map<String, Object> findPegawaiById(@Param("pegawaiId") Integer idPegawai,
			@Param("jabatanId") Integer idJabatan);

	// GET ALL DOKTER BY RUANGAN KERJA
	@Query("select NEW Map(p.id as idPegawai,p.namaLengkap as namaPegawai,m.jabatan.id as idJabatanInternal, m.jabatan.namaJabatan as namaJabatan) "
			+ "from MapPegawaiJabatanToUnitKerja m " + "left join m.pegawai p " + "where p.statusEnabled is true "
			+ "and m.isPrimary is true " + "and m.statusEnabled is true " + "and p.jenisPegawai.id=1 "
			+ "and p.ruangan.id=:ruangan")
	public List<Map<String, Object>> findDokterByRuanganKerja(@Param("ruangan") Integer ruangan);

	// GET ALL PEGAWAI BY RUANGAN KERJA EXCEPT DOKTER
	@Query("select NEW Map(p.id as idPegawai,p.namaLengkap as namaPegawai,mapPegawai.jabatan.id as idJabatanInternal, mapPegawai.jabatan.namaJabatan as namaJabatan) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai p "
			+ "where mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and p.statusEnabled is true " + "and p.ruangan.id=:ruangan " + "and p.jenisPegawai.id not in(1)")
	public List<Map<String, Object>> findPegawaiExceptDokterByRuanganKerja(@Param("ruangan") Integer ruangan);

	@Query("select new com.jasamedika.medifirst2000.entities.Pegawai(p.id, p.namaLengkap, p.nipPns) from Pegawai p where p.nipPns=:nipPns")
	public Pegawai findOneByNipPns(@Param("nipPns") String nipPns);

	@Query("select NEW Map(p.id as pegawaiId," + "p.namaLengkap as namaPegawai," + "p.nipPns as nipPegawai,"
			+ "p.tglLahir as tglLahir" + ") " + "from Pegawai p " + "left join p.statusPegawai statuspegawai "
			+ "where p.statusEnabled is true and statuspegawai.id=2")
	public List<Map<String, Object>> findAllPegawais();

	// GET HARI LIBUR
	@Query("select new map(model2.tanggal as tanggal, model1.namaExternal as namaHariLibur,model2.namaHari as namaHari) from MapKalenderToHariLibur model1 "
			+ "right join model1.tanggal model2 where model2.tahunKalender = :tahun and model2.bulanKeDlmTahun= :bulan")
	public List<Map<String, Object>> findHariLiburPegawaiNonShift(@Param("tahun") Integer tahun,
			@Param("bulan") Integer bulan);

	@Query("select NEW com.jasamedika.medifirst2000.entities.Pegawai (model.id, model.namaLengkap) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai model "
			+ "where mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and model.statusEnabled is true " + "and model.statusPegawai.kdStatusPegawai=2 "
			+ "and mapPegawai.unitKerjaPegawaiId= :idRuangan")
	public List<Pegawai> findAllPegawaiAktifByRuangan(@Param("idRuangan") Integer idRuangan);

	@Query("select new map (pegawai.id as idPegawai, " + "pegawai.namaLengkap as nama, "
			+ "golongan.golonganPegawai as namaGolongan, " + "agama.agama as agama, "
			+ "detailKategoryPegawai.detailKategoryPegawai as detailKategoryPegawai, "
			+ "dokumen.namaJudulDokumen as namaJudulDokumen, " + "eselon.eselon as eselon, "
			+ "golonganDarah.golonganDarah as golonganDarah, " + "jabatanFungsional.namaJabatan as namaJabatan, "
			+ "jabatanInternal.namaJabatan as jabatanInternal, " + "jabatanInternal.id as idJabatanInternal,"
			+ "pegawai.nomorRekening as nomorRekening, " + "jabatanLamar.namaJabatan as jabatanLamar, "
			+ "jabatanStruktural.namaJabatan as jabatanStruktural, " + "jenisKelamin.jenisKelamin as jenisKelamin, "
			+ "jenisPegawai.jenisPegawai as jenisPegawai, " + "jenisPegawaiLamar.jenisPegawai as jenisPegawaiLamar, "
			+ "kategoriPegawai.kategoryPegawai as kategoriPegawai, " + "kedudukan.name as kedudukan, "
			+ "kualifikasiJurusan.kualifikasiJurusan as kualifikasiJurusan, " + "negara.namaNegara as namaNegara,  "
			+ "shiftKerja.factorRate as factorRate, " + "pangkat.namaPangkat as namaPangkat, "
			+ "pendidikan.namaPendidikan as namaPendidikan, "
			+ "penghasilanTidakKenaPajak.deskripsi as penghasilanTidakKenaPajak, " + "range.namaRange as namaRange, "
			+ "pegawai.nipPns as nipPns, " + "pegawai.nip as nip, " + "pegawai.nikIntern as nikIntern, "
			+ "pegawai.idFinger as idFinger, " + "ruangan.id as idRuangan, " + "ruangan.namaRuangan as namaRuangan, "
			+ "satuanKerja.satuanKerja as satuanKerja, " + "shiftKerja.name as shiftKerja, "
			+ "shiftKerja.id as idKelompokShiftKerja," + "statusKawin.statusPerkawinan as statusKawin, "
			+ "statusPegawai.statusPegawai as statusPegawai, "
			+ "statusPerkawinanPegawai.statusPerkawinan as statusPerkawinanPegawai, " + "suku.suku as suku, "
			+ "titlePasien.namaTitle as titlePasien, " + "typePegawai.typePegawai as typePegawai) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join pegawai.golonganPegawai golongan " + "left join pegawai.agama agama "
			+ "left join pegawai.detailKategoryPegawai detailKategoryPegawai " + "left join pegawai.dokumen dokumen "
			+ "left join pegawai.eselon eselon " + "left join pegawai.golonganDarah golonganDarah "
			+ "left join pegawai.jabatanFungsional jabatanFungsional " + "left join mapPegawai.jabatan jabatanInternal "
			+ "left join pegawai.jabatanLamar jabatanLamar " + "left join pegawai.jabatanStruktural jabatanStruktural "
			+ "left join pegawai.jenisKelamin jenisKelamin " + "left join pegawai.jenisPegawai jenisPegawai "
			+ "left join pegawai.jenisPegawaiLamar jenisPegawaiLamar "
			+ "left join pegawai.kategoryPegawai kategoriPegawai " + "left join pegawai.kedudukan kedudukan "
			+ "left join pegawai.kualifikasiJurusan kualifikasiJurusan " + "left join pegawai.negara negara "
			+ "left join pegawai.pangkat pangkat " + "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.penghasilanTidakKenaPajak penghasilanTidakKenaPajak "
			+ "left join pegawai.range range " + "left join pegawai.ruangan ruangan "
			+ "left join pegawai.satuanKerja satuanKerja " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join pegawai.statusKawin statusKawin " + "left join pegawai.statusPegawai statusPegawai "
			+ "left join pegawai.statusPerkawinanPegawai statusPerkawinanPegawai " + "left join pegawai.suku suku "
			+ "left join pegawai.titlePasien titlePasien " + "left join pegawai.typePegawai typePegawai "
			+ "where mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and jabatanFungsional.id =:idJabatan")
	public Map<String, Object> findPegawaiByIdabatan(@Param("idJabatan") Integer idJabatan);

	@Query("select  NEW  Pegawai(p.id, p.namaLengkap) from Pegawai p where p.id = :idPegawai")
	Pegawai findPegawaiHukorById(@Param("idPegawai") Integer idPegawai);

	@Query("select  NEW  Map(p.id as idPegawai, p.namaLengkap as namaLengkap, p.tglMasuk as tglMasuk, p.alamat as alamat ,jabatanInternal.namaJabatan as namaJabatan , "
			+ "golonganPegawai.golonganPegawai as grade) " + " from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai p " + "left join mapPegawai.jabatan jabatanInternal "
			+ "left join p.golonganPegawai as golonganPegawai " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and p.id = :idPegawai")
	Map<String, Object> findPegawaiForMobileById(@Param("idPegawai") Integer idPegawai);

	@Query("select  ruangan.id " + " from Pegawai p " + " left join p.ruangan ruangan " + " where p.id = :idPegawai")
	Integer findIdRuanganByIdPegawai(@Param("idPegawai") Integer idPegawai);

	@Query("select  jabatan.id " + " from MappingPegawaiToJabatanManajerial mapping "
			+ " left join mapping.jabatan jabatan " + " left join mapping.pegawai pegawai "
			+ " where pegawai.statusEnabled is true and pegawai.id = :idPegawai")
	List<Integer> findIdJabatanManajerialByIdPegawai(@Param("idPegawai") Integer idPegawai);

	@Query("select new map ( kelompokJabatan.usiaPensiun as usiaPensiun,  "
			+ " kelompokJabatan.id as idKelompokJabatan ) " + "from Jabatan jabatanFungsional "
			+ "left join jabatanFungsional.kelompokJabatan kelompokJabatan "
			+ "where jabatanFungsional.id = :idJabatanFungsional")
	Map<String, Object> findIdUsiaPensiunByIdJabatanFungsional(
			@Param("idJabatanFungsional") Integer idJabatanFungsional);

	@Query("select pegawai.id " + "from Pegawai pegawai " + "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.jabatanFungsional jabatanFungsional "
			+ "left join jabatanFungsional.kelompokJabatan kelompokJabatan "
			+ "where pendidikan.id = :idPendidikan and kelompokJabatan.id = :idKelJabatan and  pegawai.id = :idPegawai")
	Integer findPerawatSarjana(@Param("idPegawai") Integer idPegawai, @Param("idKelJabatan") Integer idKelJabatan,
			@Param("idPendidikan") Integer idPendidikan);

	@Query("select new map (p.id as id, " + "p.namaLengkap as namaLengkap, " + "p.tglPensiun as tglpensiun, "
			+ "p.tglLahir as tglLahir, " + "p.nipPns as nip, " + "golongan.golonganPegawai as golongan, "
			+ "pendidikan.namaPendidikan as pendidikan," + "subUnitKerja.name as subUnitKerja, "
			+ "unitKerja.name as unitKerja) " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai p " + "left join p.golonganPegawai golongan "
			+ "left join p.pendidikan pendidikan " + "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true "
			+ "and to_char(p.tglPensiun, 'yyyy-MM') between :startPeriode and :endPeriode "
			+ "order by tglpensiun, namalengkap")
	List<Map<String, Object>> findPegawaiPensiun(@Param("startPeriode") String startPeriode,
			@Param("endPeriode") String endPeriode);

	@Query("select new map (p.id as id, " + "p.tglBerakhirSip as tglBerakhirSip, "
			+ "p.tglBerakhirStr as tglBerakhirStr, " + "to_char(p.tglBerakhirSip,'dd-MM-yyyy') as tglBerakhirSip2, "
			+ "to_char(p.tglBerakhirStr,'dd-MM-yyyy') as tglBerakhirStr2, " + "p.noSip as noSip, "
			+ "p.noStr as noStr, " + "p.nipPns as nipPns, " + "p.namaLengkap as namaLengkap,  "
			+ "subUnitKerja.name as subUnitKerja,  " + "unitKerja.name as unitKerja)  "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai p "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and p.statusEnabled is true " + "and tglBerakhirStr <= :date "
			+ "order by tglBerakhirStr, namaLengkap")
	List<Map<String, Object>> findStrExpired(@Param("date") Date date);

	@Query("select new map (p.id as id, " + "p.tglBerakhirSip as tglBerakhirSip, "
			+ "p.tglBerakhirStr as tglBerakhirStr, " + "to_char(p.tglBerakhirSip,'dd-MM-yyyy') as tglBerakhirSip2, "
			+ "to_char(p.tglBerakhirStr,'dd-MM-yyyy') as tglBerakhirStr2, " + "p.noSip as noSip, "
			+ "p.noStr as noStr, " + "p.nipPns as nipPns, " + "p.namaLengkap as namaLengkap,  "
			+ "subUnitKerja.name as subUnitKerja,  " + "unitKerja.name as unitKerja)  "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai p "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and p.statusEnabled is true " + "and tglBerakhirSip <= :date "
			+ "order by tglBerakhirSip, namaLengkap")
	List<Map<String, Object>> findSipExpired(@Param("date") Date date);

	@Query("select new map (p.id as id, " + "p.tglBerakhirSip as tglBerakhirSip, "
			+ "to_char(p.tglBerakhirSip,'dd-MM-yyyy') as tglBerakhirSip2, " + "p.noSip as noSip, "
			+ "p.nipPns as nipPns, " + "p.namaLengkap as namaLengkap,  " + "subUnitKerja.name as subUnitKerja,  "
			+ "unitKerja.name as unitKerja)  " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai p " + "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and p.statusEnabled is true " + "and p.id = :id "
			+ "and tglBerakhirSip <= :date " + "order by tglBerakhirSip, namaLengkap")
	Map<String, Object> findSipExpiredByPegawai(@Param("date") Date date, @Param("id") Integer id);

	@Query("select new map (p.id as id, " + "p.tglBerakhirStr as tglBerakhirStr, "
			+ "to_char(p.tglBerakhirStr,'dd-MM-yyyy') as tglBerakhirStr2, " + "p.noStr as noStr, "
			+ "p.nipPns as nipPns, " + "p.namaLengkap as namaLengkap,  " + "subUnitKerja.name as subUnitKerja,  "
			+ "unitKerja.name as unitKerja)  " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai p " + "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and p.statusEnabled is true " + "and p.id = :id "
			+ "and tglBerakhirStr <= :date " + "order by tglBerakhirStr, namaLengkap")
	Map<String, Object> findStrExpiredByPegawai(@Param("date") Date date, @Param("id") Integer id);

	@Query("select new map (unitKerja.name as unitKerja, count(pegawai.id) as value )"
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and pegawai.statusEnabled is true "
			+ "group by unitKerja.name")
	List<Map<String, Object>> countByUnitKerja();

	@Query("select new map (kelompokJabatan.detailKelompokJabatan as kelompokJabatan, count(pegawai.id) as value ) "
			+ "from Pegawai pegawai " + "join pegawai.detailKelompokJabatan kelompokJabatan "
			+ "where pegawai.statusEnabled is true " + "group by kelompokJabatan.detailKelompokJabatan")
	List<Map<String, Object>> countByKelompokJabatan();

	@Query("select new map ( statusPegawai.kategoryPegawai as kategoryPegawai, count(pegawai.id) as value) "
			+ "from Pegawai pegawai " + "join pegawai.kategoryPegawai statusPegawai "
			+ "where pegawai.statusEnabled is true " + "group by statusPegawai.kategoryPegawai")
	List<Map<String, Object>> countByStatusPegawai();

	@Query("select new map ( jenisKelamin.jenisKelamin as jenisKelamin, count(pegawai.id) as value) "
			+ "from Pegawai pegawai " + "join pegawai.jenisKelamin jenisKelamin "
			+ "where pegawai.statusEnabled is true " + "group by  jenisKelamin.jenisKelamin")
	List<Map<String, Object>> countByJenisKelamin();

	String queryListPegawai = "select new map (pegawai.id as idPegawai, " + "pegawai.nama as nama, "
			+ "pegawai.namaLengkap as namaLengkap, " + " pegawai.tglLahir as tglLahir, "
			+ "pegawai.gelarDepan as gelarDepan, " + " pegawai.gelarBelakang as gelarBelakang, "
			+ " pegawai.tempatLahir as tempatLahir," + "golongan.golonganPegawai as namaGolongan, "
			+ "agama.agama as agama, " + "detailKategoryPegawai.detailKategoryPegawai as detailKategoryPegawai, "
			+ "dokumen.namaJudulDokumen as namaJudulDokumen, " + "eselon.eselon as eselon, "
			+ "golonganDarah.golonganDarah as golonganDarah, " + "jabatanFungsional.namaJabatan as namaJabatan, "
			+ "jabatanLamar.namaJabatan as jabatanLamar, " + "jabatanStruktural.namaJabatan as jabatanStruktural, "
			+ "jenisKelamin.jenisKelamin as jenisKelamin, " + "jenisPegawai.jenisPegawai as jenisPegawai, "
			+ "jenisPegawaiLamar.jenisPegawai as jenisPegawaiLamar, "
			+ "kategoriPegawai.kategoryPegawai as kategoriPegawai, " + "kedudukan.name as kedudukan, "
			+ "kualifikasiJurusan.kualifikasiJurusan as kualifikasiJurusan, " + "negara.namaNegara as namaNegara,  "
			+ "pangkat.namaPangkat as namaPangkat, " + "pendidikan.namaPendidikan as namaPendidikan, "
			+ "penghasilanTidakKenaPajak.deskripsi as penghasilanTidakKenaPajak, " + "range.namaRange as namaRange, "
			+ "pegawai.nipPns as nipPns, " + "pegawai.tanggalMeninggal as tanggalMeninggal, " + "pegawai.nip as nip, "
			+ "pegawai.nikIntern as nikIntern, " + "pegawai.idFinger as idFinger, " + "pegawai.tglMasuk as tglMasuk, "
			+ "pegawai.tglkeluar as tglkeluar, " + "ruangan.id as idRuangan, " + "ruangan.namaRuangan as namaRuangan, "
			+ "satuanKerja.satuanKerja as satuanKerja, " + "shiftKerja.name as shiftKerja, "
			+ "shiftKerja.id as idKelompokShiftKerja," + "statusKawin.statusPerkawinan as statusKawin, "
			+ "statusPegawai.statusPegawai as statusPegawai, "
			+ "statusPerkawinanPegawai.statusPerkawinan as statusPerkawinanPegawai, " + "suku.suku as suku, "
			+ "titlePasien.namaTitle as titlePasien, " + "typePegawai.typePegawai as typePegawai,"
			+ "pegawai.statusEnabled as statusEnabled) " + "from Pegawai pegawai "
			+ "left join pegawai.golonganPegawai golongan " + "left join pegawai.agama agama "
			+ "left join pegawai.detailKategoryPegawai detailKategoryPegawai " + "left join pegawai.dokumen dokumen "
			+ "left join pegawai.eselon eselon " + "left join pegawai.golonganDarah golonganDarah "
			+ "left join pegawai.jabatanFungsional jabatanFungsional " + "left join pegawai.jabatanLamar jabatanLamar "
			+ "left join pegawai.jabatanStruktural jabatanStruktural " + "left join pegawai.jenisKelamin jenisKelamin "
			+ "left join pegawai.jenisPegawai jenisPegawai " + "left join pegawai.jenisPegawaiLamar jenisPegawaiLamar "
			+ "left join pegawai.kategoryPegawai kategoriPegawai " + "left join pegawai.kedudukan kedudukan "
			+ "left join pegawai.kualifikasiJurusan kualifikasiJurusan " + "left join pegawai.negara negara "
			+ "left join pegawai.pangkat pangkat " + "left join pegawai.pendidikan pendidikan "
			+ "left join pegawai.penghasilanTidakKenaPajak penghasilanTidakKenaPajak "
			+ "left join pegawai.range range " + "left join pegawai.ruangan ruangan "
			+ "left join pegawai.satuanKerja satuanKerja " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join pegawai.statusKawin statusKawin " + "left join pegawai.statusPegawai statusPegawai "
			+ "left join pegawai.statusPerkawinanPegawai statusPerkawinanPegawai " + "left join pegawai.suku suku "
			+ "left join pegawai.titlePasien titlePasien " + "left join pegawai.typePegawai typePegawai ";

	@Query(queryListPegawai
			+ "where kedudukan.id in (:listKedudukan) and kategoriPegawai.id not in (:listNonSdm) order by pegawai.nama  ")
	public List<Map<String, Object>> findPegawaiMeninggalPindahPensiunNoPaging(
			@Param("listKedudukan") List<Integer> listKedudukan, @Param("listNonSdm") List<Integer> listNonSdm);

	@Query(queryListPegawai
			+ "where kedudukan.id in (:listKedudukan) and kategoriPegawai.id in (:listNonSdm) order by pegawai.nama  ")
	public List<Map<String, Object>> findPegawaiMeninggalPindahPensiunNonSdm(
			@Param("listKedudukan") List<Integer> listKedudukan, @Param("listNonSdm") List<Integer> listNonSdm);

	@Query(queryListPegawai
			+ "where kategoriPegawai.id in (:listStatus) and pegawai.statusEnabled is true order by pegawai.nama  ")
	public List<Map<String, Object>> findPegawaiOutSourcingNoPaging(@Param("listStatus") List<Integer> listKedudukan);

	@Query("select new map (pegawai.id as idPegawai, pegawai.namaLengkap as namaLengkap, " + "pegawai.nama as nama) "
			+ "from Pegawai pegawai  " + "left join pegawai.kedudukan kedudukan "
			+ "where (pegawai.statusEnabled is false and kedudukan.id in (:listKedudukan) and (pegawai.tanggalMeninggal >=:date or pegawai.tglPensiun >=:date "
			+ "or pegawai.tglkeluar >=:date )) " + "or pegawai.statusEnabled is true " + "order by pegawai.nama ")
	public List<Map<String, Object>> findAllPegawaiIncludeMeninggalPindahPensiunNoPaging(
			@Param("listKedudukan") List<Integer> listKedudukan, @Param("date") Date date);

	@Query("select new map(peg.id as id, peg.namaLengkap as nama) " + "from MapPegawaiJabatanToUnitKerja mappeg "
			+ "left join mappeg.pegawai peg " + "left join mappeg.jabatan jab "
			+ "where jab.namaJabatan like 'Kepala Ruang%' " + "and mappeg.isPrimary is true "
			+ "and mappeg.statusEnabled is true")
	public List<Map<String, Object>> findAllPegawaiKepalaRuangan();

	@Query("select new Map(pegawai.id as idPegawai, " + "pegawai.namaLengkap as namaPegawai, "
			+ "pegawai.nipPns as nipPegawai, " + "jabatan.namaJabatan as namaJabatan) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "inner join mapPegawai.pegawai pegawai "
			+ "inner join mapPegawai.jabatan jabatan " + "where mapPegawai.jabatan.namaJabatan like %:namaJabatan%")
	public Map<String, Object> getKepalaPegawai(@Param("namaJabatan") String namaJabatan);

	@Query("select pg.id from MapPegawaiJabatanToUnitKerja mj " + "inner join mj.pegawai pg "
			+ "inner join mj.jabatan jb " + "where mj.unitKerjaPegawaiId = jb.unitKerjaId "
			+ "and mj.statusEnabled is true and pg.statusEnabled is true and jb.statusEnabled is true "
			+ "and mj.unitKerjaPegawaiId = :idUnitKerja " + "and (jb.levelJabatan in (3,4) "
			+ "or (mj.subUnitKerjaPegawaiId = :idSubUnitKerja and jb.levelJabatan = 5))")
	public List<Integer> getPegawaiSDMforCred(@Param("idUnitKerja") Integer idUnitKerja,
			@Param("idSubUnitKerja") Integer idSubUnitKerja);

	@Query("select pegawai.id " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "inner join mapPegawai.pegawai pegawai " + "where mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and pegawai.statusEnabled is true "
			+ "and mapPegawai.unitKerjaPegawaiId = 24")
	public List<Integer> getPegawaiSDM();

	@Query("select new map(pegawai.nipPns as nip, " + "pegawai.namaLengkap as nama, "
			+ "jabatanInternal.namaJabatan as jabatanInternal, " + "ruangan.namaRuangan as namaRuangan, "
			+ "unitKerja.name as unitKerja, " + "pegawai.idFinger as idFinger) "
			+ "from Pegawai pegawai, MapPegawaiJabatanToUnitKerja mapPegawai " + "left join pegawai.ruangan ruangan "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join mapPegawai.jabatan jabatanInternal "
			+ "where pegawai.id = mapPegawai.pegawaiId " + "and mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and pegawai.idFinger = :idFinger "
			+ "and pegawai.statusEnabled is true " + "order by pegawai.nama asc")
	public Map<String, Object> getPegawaiToMonitoringAbsen(@Param("idFinger") String idFinger);

	@Query("select new map(pegawai.nipPns as nip, " + "pegawai.namaLengkap as nama, "
			+ "jabatanInternal.namaJabatan as jabatanInternal, " + "ruangan.namaRuangan as namaRuangan, "
			+ "unitKerja.name as unitKerja, " + "pegawai.idFinger as idFinger) "
			+ "from Pegawai pegawai, MapPegawaiJabatanToUnitKerja mapPegawai " + "left join pegawai.ruangan ruangan "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join mapPegawai.jabatan jabatanInternal "
			+ "where pegawai.id = mapPegawai.pegawaiId " + "and mapPegawai.statusEnabled is true "
			+ "and pegawai.statusEnabled is true " + "and mapPegawai.isPrimary is true "
			+ "and pegawai.id = :idPegawai " + "order by pegawai.nama asc")
	public Map<String, Object> getPegawaiToMonitoringAbsen(@Param("idPegawai") Integer idPegawai);

	@Query("select p.id " + "from MapPegawaiJabatanToUnitKerja mappeg " + "inner join mappeg.pegawai p "
			+ "inner join mappeg.subUnitKerjaPegawai subUnitKerja " + "where mappeg.statusEnabled is true "
			+ "and p.statusEnabled is true " + "and mappeg.isPrimary is true " + "and mappeg.statusEnabled is true "
			+ "and p.shiftKerjaId in (1,2) " + "and subUnitKerja.id = :subUnitKerja " + "order by p.id asc")
	public List<Integer> getPegawaiNonshiftBySubunitKerja(@Param("subUnitKerja") Integer subUnitKerja);

	@Query("select p.id " + "from MapPegawaiJabatanToUnitKerja mappeg " + "inner join mappeg.pegawai p "
			+ "inner join mappeg.subUnitKerjaPegawai subUnitKerja " + "where mappeg.statusEnabled is true "
			+ "and p.statusEnabled is true " + "and mappeg.isPrimary is true " + "and mappeg.statusEnabled is true "
			+ "and p.shiftKerjaId in (1,2) " + "order by p.id asc")
	public List<Integer> getPegawaiNonshift();

	@Query("select peg.id from Pegawai peg where peg.statusEnabled is true and peg.jenisPegawaiId=1 and peg.ruanganId=:idRuangan")
	public int[] getDokterByRuanganId(@Param("idRuangan") int idRuangan);

	@Query("select distinct pgw.id " + "from MapPegawaiJabatanToUnitKerja mpj " + "inner join mpj.pegawai pgw "
			+ "where mpj.statusEnabled is true " + "and pgw.statusEnabled is true " + "and pgw.jenisPegawaiId = 1 "
			+ "and mpj.subUnitKerjaPegawaiId = :subunitKerjaId")
	public List<Integer> getDokterByKelompokKerja(@Param("subunitKerjaId") Integer idSubunitKerja);

	@Query("select peg.id from Pegawai peg where peg.statusEnabled is true and peg.kategoryPegawaiId in (:listKategoryPegawaiId)")
	public List<Integer> getPegawaiByKategoryPegawai(
			@Param("listKategoryPegawaiId") List<Integer> listKategoryPegawaiId);

	@Query("select mapp.pegawaiId from MapPegawaiJabatanToUnitKerja mapp "
			+ "where mapp.statusEnabled is true and mapp.unitKerjaPegawaiId = :idUnitKerja "
			+ "and mapp.pegawaiId is not null")
	public List<Integer> getPegawaiByIdUnitKerja(@Param("idUnitKerja") Integer idUnitKerja);

	@Query("select pg.shiftKerjaId from Pegawai pg where pg.statusEnabled is true and pg.id = :idPegawai")
	public Integer getKelompokShiftByIdPegawai(@Param("idPegawai") Integer idPegawai);

	@Query("select new Map(jab.id as id, jab.namaJabatan as namaJabatan) "
			+ "from Pegawai peg left join peg.jabatanFungsional jab " + "where peg.statusEnabled is true "
			+ "and jab.statusEnabled is true " + "and peg.id = :idPegawai")
	public Map<String, Object> getJabatanFungsionalByPegawai(@Param("idPegawai") Integer idPegawai);

	@Query("select new Map (ese.id as idEselon,ese.eselon as eselon) " + "from MapPegawaiJabatanToUnitKerja mapp "
			+ "left join mapp.jabatan jab " + "left join jab.eselon ese "
			+ "where mapp.statusEnabled is true and jab.statusEnabled is true and ese.statusEnabled is true "
			+ "and jab.jenisJabatanId = 5 and lower(jab.namaJabatan) not like lower('Plh%') and mapp.pegawaiId = :idPegawai")
	public Map<String, Object> getEselonStruktural(@Param("idPegawai") Integer idPegawai);

	@Query("select p.id " + "from Pegawai p," + "JenisPegawai j," + "SettingDataFixed s "
			+ "where p.statusEnabled is true " + "and p.jenisPegawaiId = j.id "
			+ "and p.jenisPegawaiId = cast(s.nilaiField as int) " + "and j.id = cast(s.nilaiField as int) "
			+ "and s.namaField='KdJenisPegawaiDokter' " + "and p.statusPegawai.id = 2")
	public List<Integer> getPegawaiKedokteran();

	@Query("select new Map(pegawai.alamat as alamat, " + "pegawai.agamaId as agamaId, "
			+ "pegawai.bankRekeningAtasNama as bankRekeningAtasNama, "
			+ "pegawai.bankRekeningNama as bankRekeningNama, " + "pegawai.bankRekeningNomor as bankRekeningNomor, "
			+ "pegawai.detailKelompokJabatanId as detailKelompokJabatanId, " + "pegawai.email as email, "
			+ "pegawai.emailAlternatif as emailAlternatif, " + "pegawai.eselonId as eselonId, "
			+ "pegawai.gelarBelakang as gelarBelakang, " + "pegawai.gelarDepan as gelarDepan, "
			+ "pegawai.grade as grade, " + "pegawai.golonganDarahId as golonganDarahId, " + "pegawai.id as id, "
			+ "pegawai.idFinger as idFinger, " + "pegawai.isMenanggung as isMenanggung, "
			+ "pegawai.jabatanFungsionalId as jabatanFungsionalId, "
			+ "pegawai.jabatanInternalId as jabatanInternalId, " + "pegawai.jabatanLamarId as jabatanLamarId, "
			+ "pegawai.jabatanStrukturalId as jabatanStrukturalId, " + "pegawai.jenisKelaminId as jenisKelaminId, "
			+ "pegawai.jenisPegawaiId as jenisPegawaiId, " + "pegawai.kodePos as kodePos, "
			+ "pegawai.kategoryPegawaiId as kategoryPegawaiId, " + "pegawai.kedudukanId as kedudukanId, "
			+ "pegawai.nama as nama, " + "pegawai.namaLengkap as namaLengkap, " + "pegawai.nikIntern as nikIntern, "
			+ "pegawai.nilaiJabatan as nilaiJabatan, " + "pegawai.nip as nip, " + "pegawai.nipPns as nipPns, "
			+ "pegawai.noBPJS as noBPJS, " + "pegawai.noHandphone as noHandphone, "
			+ "pegawai.noIdentitas as noIdentitas, " + "pegawai.noSip as noSip, " + "pegawai.noStr as noStr, "
			+ "pegawai.noTlp as noTlp, " + "pegawai.npwp as npwp, " + "pegawai.negaraId as negaraId, "
			+ "pegawai.pensiun as pensiun, " + "pegawai.pangkatId as pangkatId, " + "pegawai.ruanganId as ruanganId, "
			+ "pegawai.rekananId as rekananId," + "pegawai.statusRhesus as statusRhesus, "
			+ "pegawai.shiftKerjaId as shiftKerjaId, " + "pegawai.statusKawinId as statusKawinId, "
			+ "pegawai.sukuId as sukuId, " + "pegawai.tempatLahir as tempatLahir, "
			+ "pegawai.tglBerakhirSip as tglBerakhirSip, " + "pegawai.tglBerakhirStr as tglBerakhirStr, "
			+ "pegawai.tglLahir as tglLahir, " + "pegawai.tglMasuk as tglMasuk, " + "pegawai.tglkeluar as tglkeluar, "
			+ "pegawai.tglPensiun as tglPensiun, " + "pegawai.tglTerbitSip as tglTerbitSip, "
			+ "pegawai.tglTerbitStr as tglTerbitStr, " + "pegawai.typePegawaiId as typePegawaiId) "
			+ "from Pegawai pegawai where pegawai.id = :idPegawai")
	public Map<String, Object> getPegawaiDetailById(@Param("idPegawai") Integer idPegawai);

	@Query("select new Map(pegawai.alamat as alamat, " + "pegawai.agamaId as agamaId, " + "pegawai.email as email, "
			+ "pegawai.emailAlternatif as emailAlternatif, " + "pegawai.gelarBelakang as gelarBelakang, "
			+ "pegawai.gelarDepan as gelarDepan, " + "pegawai.golonganDarahId as golonganDarahId, "
			+ "pegawai.id as id, " + "pegawai.jenisKelaminId as jenisKelaminId, "
			+ "pegawai.jenisPegawaiId as jenisPegawaiId, " + "pegawai.kodePos as kodePos, "
			+ "pegawai.kategoryPegawaiId as kategoryPegawaiId, " + "pegawai.kedudukanId as kedudukanId, "
			+ "pegawai.kualifikasiJurusanId as kualifikasiJurusanId, " + "pegawai.nama as nama, "
			+ "pegawai.namaLengkap as namaLengkap, " + "pegawai.nikIntern as nikIntern, " + "pegawai.nip as nip, "
			+ "pegawai.nipPns as nipPns, " + "pegawai.noHandphone as noHandphone, "
			+ "pegawai.noIdentitas as noIdentitas, " + "pegawai.noSip as noSip, " + "pegawai.noStr as noStr, "
			+ "pegawai.noTlp as noTlp, " + "pegawai.negaraId as negaraId, "
			+ "pegawai.pegawaiPembimbingId as pegawaiPembimbingId, " + "pegawai.pendidikanId as pendidikanId, "
			+ "pegawai.statusRhesus as statusRhesus, " + "pegawai.statusKawinId as statusKawinId, "
			+ "pegawai.sukuId as sukuId, " + "pegawai.tempatLahir as tempatLahir, "
			+ "pegawai.tglBerakhirSip as tglBerakhirSip, " + "pegawai.tglBerakhirStr as tglBerakhirStr, "
			+ "pegawai.tglLahir as tglLahir, " + "pegawai.tglMasuk as tglMasuk, " + "pegawai.tglkeluar as tglkeluar, "
			+ "pegawai.tglTerbitSip as tglTerbitSip, " + "pegawai.tglTerbitStr as tglTerbitStr)"
			+ "from Pegawai pegawai where pegawai.id = :idPegawai")
	public Map<String, Object> getPesertaDidikDetailById(@Param("idPegawai") Integer idPegawai);

	@Query("select new Map(dokter.id as id, dokter.namaLengkap as namaLengkap) "
			+ "from PelayananPasienPetugas pelayananPasienPetugas "
			+ "left join pelayananPasienPetugas.pelayananPasien pelayananPasien "
			+ "left join pelayananPasienPetugas.kdjenispetugaspe jenisPetugas "
			+ "left join pelayananPasienPetugas.kdpegawai dokter " + "left join pelayananPasien.pasienDaftar antrian "
			+ "left join antrian.ruangan ruangan " + "left join ruangan.departemen departemen "
			+ "where (pelayananPasienPetugas.statusEnabled is null or pelayananPasienPetugas.statusEnabled is true) "
			+ "and (pelayananPasien.statusEnabled is null or pelayananPasien.statusEnabled is true) "
			+ "and (antrian.statusEnabled is null or antrian.statusEnabled is true) "
			+ "and jenisPetugas.statusEnabled is true " + "and dokter.statusEnabled is true "
			+ "and ruangan.statusEnabled is true " + "and departemen.statusEnabled is true "
			+ "and departemen.id = :idDepartemen " + "and jenisPetugas.id <> :idPetugasPelaksana "
			+ "and to_char(pelayananPasien.tglPelayanan,'yyyy-MM') = :month " + "order by dokter.namaLengkap")
	public List<Map<String, Object>> getListPegawaiPendapatanDepartemen(@Param("idDepartemen") Integer idDepartemen,
			@Param("idPetugasPelaksana") int idPetugasPelaksana, @Param("month") String month);

	@Query("select new Map(dokter.id as id, dokter.namaLengkap as namaLengkap) "
			+ "from PelayananPasienPetugas pelayananPasienPetugas "
			+ "left join pelayananPasienPetugas.pelayananPasien pelayananPasien "
			+ "left join pelayananPasienPetugas.kdjenispetugaspe jenisPetugas "
			+ "left join pelayananPasienPetugas.kdpegawai dokter " + "left join pelayananPasien.pasienDaftar antrian "
			+ "left join antrian.ruangan ruangan " + "left join ruangan.departemen departemen "
			+ "where (pelayananPasienPetugas.statusEnabled is null or pelayananPasienPetugas.statusEnabled is true) "
			+ "and (pelayananPasien.statusEnabled is null or pelayananPasien.statusEnabled is true) "
			+ "and (antrian.statusEnabled is null or antrian.statusEnabled is true) "
			+ "and jenisPetugas.statusEnabled is true " + "and dokter.statusEnabled is true "
			+ "and ruangan.statusEnabled is true " + "and departemen.statusEnabled is true "
			+ "and departemen.id = :idDepartemen " + "and ruangan.id = :idRuangan "
			+ "and jenisPetugas.id <> :idPetugasPelaksana "
			+ "and to_char(pelayananPasien.tglPelayanan,'yyyy-MM') = :month " + "order by dokter.namaLengkap")
	public List<Map<String, Object>> getListPegawaiPendapatanRuangan(@Param("idDepartemen") Integer idDepartemen,
			@Param("idRuangan") Integer idRuangan, @Param("idPetugasPelaksana") int idPetugasPelaksana,
			@Param("month") String month);

	@Query("select new Map(dokter.id as id, dokter.namaLengkap as namaLengkap) "
			+ "from PelayananPasienPetugas pelayananPasienPetugas "
			+ "left join pelayananPasienPetugas.pelayananPasien pelayananPasien "
			+ "left join pelayananPasienPetugas.kdjenispetugaspe jenisPetugas "
			+ "left join pelayananPasienPetugas.kdpegawai dokter " + "left join pelayananPasien.pasienDaftar antrian "
			+ "left join antrian.ruangan ruangan " + "left join ruangan.departemen departemen "
			+ "where (pelayananPasienPetugas.statusEnabled is null or pelayananPasienPetugas.statusEnabled is true) "
			+ "and (pelayananPasien.statusEnabled is null or pelayananPasien.statusEnabled is true) "
			+ "and (antrian.statusEnabled is null or antrian.statusEnabled is true) "
			+ "and jenisPetugas.statusEnabled is true " + "and dokter.statusEnabled is true "
			+ "and ruangan.statusEnabled is true " + "and departemen.statusEnabled is true "
			+ "and pelayananPasienPetugas.ObjectPegawaiId in (:listIdPegawai) "
			+ "and jenisPetugas.id <> :idPetugasPelaksana "
			+ "and to_char(pelayananPasien.tglPelayanan,'yyyy-MM') = :month " + "order by dokter.namaLengkap")
	public List<Map<String, Object>> getListPegawaiPendapatanUnitKerja(
			@Param("listIdPegawai") List<Integer> listIdPegawai, @Param("idPetugasPelaksana") int idPetugasPelaksana,
			@Param("month") String month);

	@Query("select new Map(peg.id as idPegawai, peg.kategoryPegawaiId as idKategoryPegawai) " + "from Pegawai peg "
			+ "where peg.statusEnabled is true " + "and to_char(peg.tglkeluar, 'yyyy-MM-dd') <= :currentDate "
			+ "and peg.id = :idPegawai")
	public Map<String, Object> getPegawaiKeluarHariIni(@Param("currentDate") String currentDate,
			@Param("idPegawai") Integer idPegawai);

	@Query("select distinct peg.id " + "from MapPegawaiJabatanToUnitKerja mapp left join mapp.pegawai peg "
			+ "where mapp.statusEnabled is true and peg.statusEnabled is true "
			+ "and mapp.unitKerjaPegawaiId in (:listIdKsm)")
	public List<Integer> getListPegawaiByGrupUnitKerja(@Param("listIdKsm") List<Integer> listIdKsm);

	@Query("select new Map(pg.id as id,pg.shiftKerjaId as shiftKerjaId) from Pegawai pg where pg.statusEnabled is true and pg.id in (:listIdPegawai)")
	public List<Map<String, Object>> getListKelompokShiftKerja(@Param("listIdPegawai") List<Integer> listIdPegawai);

	@Query("select distinct new Map (pg.id as id,pg.namaLengkap as namaLengkap," + "pg.tglMasuk as tglMasuk,"
			+ "pg.jenisPegawaiId as jenisPegawaiId) " + "from Pegawai pg " + "where pg.statusEnabled is true "
			+ "and pg.kategoryPegawaiId in (:listKategoryPegawaiId) " + "order by pg.namaLengkap")
	public List<Map<String, Object>> findPegawaiByListKategori(
			@Param("listKategoryPegawaiId") List<Integer> listIdKategoriPegawai);

	@Query("select new Map(pg.id as pegawaiId,pg.namaLengkap as namaLengkap) "
			+ "from Pegawai pg where pg.statusEnabled is true and pg.id in (:listPegawaiId) "
			+ "order by pg.namaLengkap")
	public List<Map<String, Object>> findPegawaiByListId(@Param("listPegawaiId") List<Integer> listIdPegawai);

	@Query("select new Map(pg.id as id,pg.namaLengkap as namaLengkap) " + "from Pegawai pg "
			+ "where pg.statusEnabled is true " + "and pg.idFinger = :fingerId " + "and pg.idFinger <> ''")
	public List<Map<String, Object>> checkExistingFingerId(@Param("fingerId") String idFinger);

	@Query("select new Map(pg.id as id,pg.namaLengkap as namaLengkap) " + "from Pegawai pg "
			+ "where pg.statusEnabled is true " + "and trim(pg.idFinger) = :fingerId " + "and trim(pg.idFinger) <> '' "
			+ "and pg.id <> :pegawaiId")
	public List<Map<String, Object>> checkExistingFingerId(@Param("fingerId") String idFinger,
			@Param("pegawaiId") Integer idPegawai);

	@Query("select new Map(pg.id as id,pg.namaLengkap as namaLengkap,pg.jenisKelaminId as jenisKelaminId) "
			+ "from Pegawai pg " + "where pg.statusEnabled is true " + "and to_char(pg.tglLahir,'MM-dd') = :tglLahir "
			+ "and pg.kedudukanId not in (3,4,5,6,24,25,26,28,29) " + "order by pg.namaLengkap")
	public List<Map<String, Object>> findByBirthDate(@Param("tglLahir") String tglLahir);

	@Query("select new Map(pg.id as id, pg.namaLengkap as namaLengkap) " + "from Pegawai pg "
			+ "where pg.statusEnabled is true " + "and pg.jenisPegawaiId = 1 " + "and pg.namaLengkap like '%dr%' "
			+ "order by pg.namaLengkap")
	public List<Map<String, Object>> findAllDokter();

}
