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 DoctorHisCodeRepository extends JpaRepository<DoctorHisCode, Integer> {

    @Query(value = "select * from doctor_his_code where doctor_id = ? and hospital_id = ? and deleted = 0 limit 1",nativeQuery = true)
    DoctorHisCode getDoctorHisCode(int doctorId, int hospitalId);

    /**
     * 根据医院ID和his编号得到相关信息
     * @param hospitalId
     * @param hisCode
     * @return
     */
    @Query(value = "select * from doctor_his_code where hospital_id = ? and his_code = ? and deleted = 0 limit 1",nativeQuery = true)
    DoctorHisCode getDoctorByHisCode(int hospitalId, String hisCode);

    @Query(value = "select * from doctor_his_code where doctor_id = ? and deleted = 0;", nativeQuery = true)
    List<DoctorHisCode> getListByDoctorId(int doctorId);

    @Query(value = "select * from doctor_his_code where hospital_id = ? and deleted = 0;", nativeQuery = true)
    List<DoctorHisCode> getListByHospitalId(int hospitalId);

    @Query(value = "select * from doctor_his_code where hospital_id = ? and doctor_id = ? and deleted = 0 limit 1;", nativeQuery = true)
    DoctorHisCode findByDoctorId(int hospitalId, int doctorId);

    @Query(value = "select * from doctor_his_code where hospital_id = ? and his_code = ? and deleted = 0",nativeQuery = true)
    List<DoctorHisCode> getAllDoctorByHisCode(int hospitalId, String hisCode);
}
