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

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

public interface InspectionDetailRepository extends JpaRepository<InspectionDetail, Integer> {
    @Query(value = "select count(0) from inspection_detail where report_id = ? and deleted = 0;", nativeQuery = true)
    int count(String reportId);

    @Query(value = "select count(0) from inspection_detail where report_id = ? and user_id = ? and deleted = 0;", nativeQuery = true)
    int getDetailCount(String reportId, int userId);

    @Query(value = "select * from inspection_detail where report_id = ? and deleted = 0 order by create_time asc limit 1;", nativeQuery = true)
    InspectionDetail getByReportId(String reportId);

    @Query(value = "select count(0) from inspection_detail where report_id = ? and his_patient_id = ? and hospital_id = ? and deleted = 0;", nativeQuery = true)
    int getCountTaihe(String reportId, String hisPatientId, int hospitalId);

    @Query(value = "select count(0) from inspection_detail where report_id = ? and his_patient_id = ? and hospital_id = 1 and deleted = 0;", nativeQuery = true)
    int getCountNfyy(String reportId, String hisPatientId);

    @Query(value = "select * from inspection_detail where report_id = ? and hospital_id = ? and deleted = 0 order by create_time limit 1;", nativeQuery = true)
    InspectionDetail getByReportIdAndHospitalId(String reportId, int hospitalId);
}
