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 MedicalRecordsImageRepository extends JpaRepository<MedicalRecordsImage, Integer> {
    @Query(value = "select * from medical_records_image where patient_id = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getMedicalRecordsImageList(int patientId);

    @Query(value = "select * from medical_records_image where patient_id = ? and doctor_id = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getMedicalRecordsImageList(int patientId, int doctorId);

    @Query(value = "select * from medical_records_image where patient_id = ? and doctor_id = ? and type = 0 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getPatientImageList(int patientId, int doctorId);

    /**
     * 根据病历Id获取图片列表
     * @param recordId
     * @return
     */
    @Query(value = "select * from medical_records_image where medical_records_id = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getListByRecordId(int recordId);

    /**
     * 根据病历Id获取图片列表
     * @param orderId
     * @return
     */
    @Query(value = "select * from medical_records_image where order_id = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getListByOrderId(int orderId);

    /**
     * 获取图片列表
     * @param doctorId
     * @param type
     * @return
     */
    @Query(value = "select * from medical_records_image where user_id = ? and doctor_id = ? and type = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getListByUserIdAndDoctorId(int userId, int doctorId, int type);

    /**
     * 获取图片列表
     * @param patientId
     * @param type
     * @return
     */
    @Query(value = "select * from medical_records_image where patient_id = ? and type = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getList(int patientId, int type);

    /**
     * 获取医生证书图片
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = 4 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorCertificateImageList(int doctorId);

    /**
     * 获取医生待审核的证书图片
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = ? and status = 0 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorPendingCertificateImageList(int doctorId, int type);


    /**
     * 获取医生的证书图片(状态)
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = ? and status = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorCertificateImageList(int doctorId, int type, int status);

    /**
     * 获取医生身份证正反照
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = 5 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorIdNoImgList(int doctorId);

    /**
     * 获取医生待审核身份证正反照
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = 5 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorPendingIdNoImgList(int doctorId);

    /**
     * 获取医师资格证
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = 6 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorQualificationImgList(int doctorId);

    /**
     * 获取医生待审核的医师资格证
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = 6 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorPendingQualificationImgList(int doctorId);

    /**
     * 获取医师专业技术资格证
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = 7 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorProfessionalSkillImgList(int doctorId);

    /**
     * 获取待审核的医师专业技术资格证
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and type = 7 and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getDoctorPendingProfessionalSkillImgList(int doctorId);

    /**
     * 获取不通过的证书图片
     * @param doctorId
     * @return
     */
    @Query(value = "select * from medical_records_image where doctor_id = ? and audit_id = ? and type = ? and deleted = 0 order by create_time desc", nativeQuery = true)
    List<MedicalRecordsImage> getNoPassImageList(int doctorId, int auditId, int type);

}
