package thyyxxk.webserver.dao.his.outpatient.triage;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.outpatient.triage.EmergencyRegInfo;

public interface EmergencyRegDao extends BaseMapper<EmergencyRegInfo> {

    @Select("select " +
            "rtrim(a.patient_id) as patientId,a.times,level=N'三级', " +
            "rtrim(a.name) as patientName,a.request_day as regTime, " +
            "gender=case when b.sex='1' then N'男' when b.sex='2' then N'女' else N'未知' end, " +
            "rtrim(b.social_no) as idCard,consciousness=N'清醒',rtrim(b.phone_no) as phone, " +
            "rtrim(b.adress) as liveAddress,createTime=getdate() " +
            "from mzy_reqrec a,mz_patient_mi b " +
            "where a.patient_id=#{patientId} and a.times=#{times} " +
            "and a.patient_id=b.patient_id")
    EmergencyRegInfo getRawEntity(String patientId, Integer times);

    @Select("select top 1 rtrim(inpatient_no) from a_patient_mi where social_no=#{idNo}")
    String getInpatientNo(String idNo);
    
    @Select("select rtrim(name) from zd_unit_code where code= " +
            "(select zk_ward from zy_actpatient where inpatient_no=#{patNo})")
    String getDeptName(String patNo);
}
