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

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

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

public interface InspectionReportRepository extends JpaRepository<InspectionReport, Integer> {
    @Query(value = "select * from inspection_report where report_id = ? and deleted = 0 limit 1;", nativeQuery = true)
    InspectionReport getByReportId(String reportId);

    @Query(value = "select * from inspection_report where report_id = ? and hospital_id = ? and deleted = 0 limit 1;", nativeQuery = true)
    InspectionReport getByReportIdAndHospitalId(String reportId, int hospitalId);

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

    @Query(value = "select * from inspection_report where his_patient_id = ? and deleted = 0 order by report_date desc", nativeQuery = true)
    List<InspectionReport> getListByHisPatientId(String hisPatientId);

    @Query(value = "select * from inspection_report where his_patient_id = ? and status = 1 and deleted = 0 order by report_date desc", nativeQuery = true)
    List<InspectionReport> getInspectionReportList(String hisPatientId);

    @Query(value = "select * from inspection_report where clinic_seq = ? and deleted = 0 order by report_date desc", nativeQuery = true)
    List<InspectionReport> getListByHisClinicSeq(String clinicSeq);

    @Query(value = "select * from inspection_report where his_patient_id = ? and clinic_seq = ? and hospital_id = ? and status = 1 and deleted = 0 order by report_date desc;", nativeQuery = true)
    List<InspectionReport> getListTaihe(String hisPatientId, String clinicSeq, int hospitalId);

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

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

    @Query(value = "select * from inspection_report where his_patient_id = ? and hospital_id = ? and status = 1 and deleted = 0 order by report_date desc", nativeQuery = true)
    List<InspectionReport> getInspectionReportList(String hisPatientId, int hospitalId);

    @Query(value = "select * from inspection_report where his_patient_id = ? and status = 1 and deleted = 0 and report_date > ? order by report_date desc", nativeQuery = true)
    List<InspectionReport> getInspectionReportList(String hisPatientId, Date date);

    @Query(value = "select * from inspection_report where his_patient_id = ? and hospital_id = ? and status = 1 and deleted = 0 and report_date > ? order by report_date desc", nativeQuery = true)
    List<InspectionReport> getInspectionReportList(String hisPatientId, int hospitalId, Date date);
}
