package com.ywt.outpatient.domain.entity.center;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface AttendingTreatmentRepository extends JpaRepository<AttendingTreatment, Integer> {

    /**
     * 查看当前患者是否有正在进行的订单
     *
     * @param patientId
     * @return
     */
    @Query(value = "SELECT COUNT(1) FROM attending_treatment WHERE from_doctor_id = ? AND patient_id = ? AND is_deleted = 0  AND attending_status IN (2,6)",nativeQuery = true)
    public int checkPresentAttendingTreatmentOrder(int doctorId, int patientId);


    @Query(value = "select * from attending_treatment where from_doctor_id = ? and patient_id = ? and is_deleted = 0 order by create_time desc limit 1", nativeQuery = true)
    AttendingTreatment getLastAttending(int doctorId, int patientId);

}
