package thyyxxk.webserver.dao.his.chronicDisease;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.chronicDisease.CrmVisitRecord;
import thyyxxk.webserver.entity.chronicDisease.CrmVisitRecordVo;

@Mapper
public interface CrmVisitRecordDao extends BaseMapper<CrmVisitRecord> {

    @Select(" select top 1 name, case when sex = 1 then '男' when sex = 2 then '女' else '未知' end sex," +
            " age,birth_day,social_no, patient_id as hisMzNo, times " +
            " from mz_patient_mi " +
            " where patient_id = #{keyCode} or social_no = #{keyCode} ")
    CrmVisitRecordVo selectCrmEmrPatientVoByMzCode(@Param("keyCode") String keyCode);

    @Select(" select top 1 name, case when sex = 1 then '男' when sex = 2 then '女' else '未知' end sex, " +
            " birth_date as birth_day, social_no, inpatient_no as hisZyNo, mz_no as hisMzNo " +
            " from a_patient_mi " +
            " where inpatient_no = #{keyCode} or social_no = #{keyCode} ")
    CrmVisitRecordVo selectCrmEmrPatientVoByZyCode(@Param("keyCode") String keyCode);

    @Select(" select top 1 inpatient_no from a_patient_mi where mz_no=  #{patientId} ")
    String selectPatNo(String patientId);

    @Select(" select max(visit_times) as times from crm_visit_record where p_id = #{pId} ")
    Integer selectCrmEmrPatientMaxById(@Param("pId") String pId);

}
