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

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

import java.util.List;

public interface TreatmentReportRepository extends JpaRepository<TreatmentReport, Integer> {

    @Query(value = "select * from treatment_report where order_id = ? and deleted = 0 limit 1;", nativeQuery = true)
    TreatmentReport getReportByOrderId(int orderId);

    /**
     * 一个用户里面有50条远程会诊报告已经可以满足相当长一段时间之内的需求
     *
     * @param userId
     * @return
     */
    @Query(value = "select * from treatment_report where user_id = ? and deleted = 0 order by id desc limit ?;", nativeQuery = true)
    List<TreatmentReport> getTreatmentReportListByUserId(int userId, int count);

    /**
     * 一个用户里面有50条远程会诊报告已经可以满足相当长一段时间之内的需求
     *
     * @param userId
     * @return
     */
    @Query(value = "select count(1) from treatment_report where user_id = ? and deleted = 0;", nativeQuery = true)
    int getTreatmentReportCountByUserId(int userId);
}
