package com.jasamedika.medifirst2000.dao;

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

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.JadwalOperasi;

/**
 * @author salmanoe
 * @since Feb 20, 2023
 */
@Repository("jadwalOperasiDao")
public interface JadwalOperasiDao extends JpaRepository<JadwalOperasi, String> {
	@Query("select jo from JadwalOperasi jo " + "inner join jo.antrean apd " + "inner join apd.pasienDaftar pd "
			+ "left join jo.ruangan ru " + "where jo.statusEnabled is true " + "and apd.statusEnabled is true "
			+ "and pd.statusEnabled is true " + "and jo.tglOperasi between :start and :end")
	List<JadwalOperasi> findAllByPeriod(@Param("start") Date start, @Param("end") Date end);

	@Query("select jo from JadwalOperasi jo " + "inner join jo.pasien ps " + "inner join jo.antrean apd "
			+ "inner join apd.pasienDaftar pd " + "left join jo.ruangan ru " + "where jo.statusEnabled is true "
			+ "and ps.statusEnabled is true " + "and apd.statusEnabled is true " + "and pd.statusEnabled is true "
			+ "and ps.noBpjs = :noBpjs")
	List<JadwalOperasi> findAllByPasien(@Param("noBpjs") String noBpjs);
}
