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 LaboratoryReportRepository extends JpaRepository<LaboratoryReport, Integer> {
    //    @Query(value = "select count(0) from laboratory_report where clinic_seq = ? and deleted = 0;", nativeQuery = true)
//    int count(String clinicSeq);

    @Query(value = "select count(0) from laboratory_report where inspection_id = ? and user_id = ? and status = 1 and deleted = 0;", nativeQuery = true)
    int count(String inspectionId, int userId);

    @Query(value = "select count(0) from laboratory_report where inspection_id = ? and status = 1 and deleted = 0;", nativeQuery = true)
    int count(String inspectionId);

//    @Query(value = "select * from laboratory_report where report_id = ? and deleted = 0 limit 1;", nativeQuery = true)
//    LaboratoryReport getByReportId(String reportId);

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

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

    @Query(value = "select * from laboratory_report where his_patient_id = ? and status = 1 and deleted = 0 order by inspection_date desc", nativeQuery = true)
    List<LaboratoryReport> getLaboratoryReportList(String hisPatientId);

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

    @Query(value = "select count(0) from laboratory_report where his_patient_id = ? and inspection_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 laboratory_report where his_patient_id = ? and inspection_id = ? and hospital_id = 1 and status = 1 and deleted = 0;", nativeQuery = true)
    int getCountNfyy(String hisPatientId, String reportId);

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

    @Query(value = "select * from laboratory_report where his_patient_id = ? and deleted = 0 and inspection_date >= ? order by inspection_date desc", nativeQuery = true)
    List<LaboratoryReport> getListByHisClinicSeq(String clinicSeq, Date date);

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

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