package thyyxxk.webserver.dao.his.jiekou;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.jiekou.PatientInformation;

import java.util.List;

/**
 * <p>
 * 描述： 对深圳博英接口文档
 * </p>
 *
 * @author xc
 * @date 2021-07-13 08:03
 */
@Mapper
public interface DuiWaiJieKouDao {
    /**
     * 获取 门诊患者的信息
     *
     * @param patientId 门诊号
     * @param execDept  执行科室
     * @return 返回 多条数据
     */
    @Select("select a.patient_id,order_code order_id,a.patient_id inpatient_no,p_name name,birth_date birthday, " +
            "group_name test_name, " +
            "(select RTRIM(name) from zd_unit_code where code = req_ward) open_dpmt, " +
            "(select RTRIM(name) from a_employee_mi where code = req_doctor) open_doc,req_date open_date,receive_flag, " +
            "source = '门诊', rtrim(ic_card_no) card_id, " +
            "case when sex = 1 then '男' when sex = 2 then '女' else '未知' end sex,RTRIM(adress) address,rtrim(social_no) idNumber, " +
            "RTRIM(phone_no) phone,jy_remark LCZD,result_comment JYBS " +
            "from mz_yj_req a left join mz_patient_mi b on (a.patient_id = b.patient_id) " +
            "where exec_dept = #{execDept} and a.patient_id = #{patientId}")
    List<PatientInformation> getMzPatient(@Param("patientId") String patientId,
                                          @Param("execDept") String execDept);

    /**
     * 获取 住院患者的信息
     *
     * @param inpatientNo 住院号
     * @param execDept    执行科室
     * @return 返回信息
     */
    @Select("select a.inpatient_no patient_id,order_code order_id,a.inpatient_no,p_name name, " +
            "case when sex = 1 then '男' when sex = 2 then '女' else '未知' end sex,birth_date birthday, " +
            "home_street address,rtrim(social_no) idNumber,rtrim(home_tel) phone,order_name testName, " +
            "(select rtrim(name)  from zd_unit_code where code = req_ward) open_dpmt, " +
            "bed_no sickbed, " +
            "(select rtrim(name) from a_employee_mi where code = req_doctor) open_doc, " +
            "req_date open_date,receive_flag,source='住院',req_comment JYBS,diag_text LCZD " +
            "from ysh_yj_req a left join a_patient_mi b on (a.inpatient_no = b.inpatient_no) " +
            "where exec_dept = #{execDept} and a.inpatient_no = #{inpatientNo} ")
    List<PatientInformation> getYzPatient(@Param("inpatientNo") String inpatientNo,
                                          @Param("execDept") String execDept);
}
