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

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

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

public interface MriSubscribeRepository extends JpaRepository<MriSubscribe, Integer>, JpaSpecificationExecutor<MriSubscribe> {

    @Query(value = "select * from mri_subscribe where patient_mobile = ? and subscribe_time = ? and (status is null or status = 0) and deleted = 0 limit 1", nativeQuery = true)
    MriSubscribe findFirstByPatientMobileAndSubscribeTime(String patientMobile, Date subscribeTime);

    // 已取消的预约也计算未就诊次数
    @Query(value = "select * from mri_subscribe where patient_mobile = ? and deleted = 0 and break_promise = 1", nativeQuery = true)
    List<MriSubscribe> findByPatientMobileForBreakPromise(String patientMobile);

    @Query(value = "select * from mri_subscribe where subscribe_time = ? and (status is null or status = 0) and deleted = 0 ", nativeQuery = true)
    List<MriSubscribe> findBySubscribeTime(Date subscribeTime);
}