package com.jasamedika.medifirst2000.dao;

import java.util.List;

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

/**
 * @author salmanoe
 * @since Oct 21, 2021
 */
@Repository("cpptDao")
public interface CatatanPerkembanganPasienTerintegrasiDao
		extends PagingAndSortingRepository<CatatanPerkembanganPasienTerintegrasi, String> {

	/**
	 * Daftar harian entri SOAP pertama oleh dokter di dalam CPPT
	 */
	@Query(nativeQuery = true, value = "select distinct on (cppt.pegawaifk,to_char(cppt.tglinput,'yyyy-MM-dd')) cppt.* "
			+ "from (select cp.* from cppt_t cp "
			+ "inner join antrianpasiendiperiksa_t apd on cp.noregistrasifk = apd.norec "
			+ "where cp.statusenabled is true " + "and cp.flag_ = 1 "
			+ "and to_char(cp.tglinput,'yyyy-MM-dd') between :startDate and :endDate "
			+ "and cp.pegawaifk in (:listPegawaiId) " + "order by cp.pegawaifk, cp.tglinput) as cppt "
			+ "order by cppt.pegawaifk, to_char(cppt.tglinput,'yyyy-MM-dd')")
	List<CatatanPerkembanganPasienTerintegrasi> findPresensiCPPT(@Param("listPegawaiId") List<Integer> listIdPegawai,
			@Param("startDate") String startDate, @Param("endDate") String endDate);

}
