<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.docus.server.archivemysql.mapper.TBasicMapper">
    <sql id="basicInfoColumns">
        patient_id as patientId,
            admiss_times as admissTimes,
            inpatient_no as inpatientNo,
            admiss_id as admissId,
            admiss_date as admissDate,
            dis_date as disDate,
            admiss_dept_name as admissDeptName,
            dis_dept_name as disDeptName ,
            jzh,
            name,
            emp_id as empId
    </sql>
    <insert id="insert">
        INSERT INTO docus_archivefile.task_makeup_onview (id, inpatient_no, admiss_times, patient_id,
                                                          dis_date, collect_sys_type, name, report_last_modify)
         VALUES(#{taskMakeup.id},  #{taskMakeup.inpatientNo}, #{taskMakeup.admissTimes}, #{taskMakeup.patientId},
                #{taskMakeup.disDate}, #{taskMakeup.collectSysType}, #{taskMakeup.name}, #{taskMakeup.reportLastModify})
    </insert>
    <update id="update">
        UPDATE docus_archivefile.task_makeup_onview
        SET inpatient_no = #{taskMakeup.inpatientNo}, admiss_times = #{taskMakeup.admissTimes}, patient_id = #{taskMakeup.patientId},
            dis_date = #{taskMakeup.disDate}, collect_sys_type = #{taskMakeup.collectSysType}, name = #{taskMakeup.name}, report_last_modify = #{taskMakeup.reportLastModify}
        WHERE id = #{taskMakeup.id}
    </update>
    <select id="findTbasicByJzhs" resultType="com.docus.server.archivemysql.entity.TBasic">
        select
        <include refid="basicInfoColumns"></include>
        from
        docus_medicalrecord.t_basic
        where
        jzh in
        <foreach collection="jzhList" item="jzh" separator="," open="(" close=")">
            #{jzh}
        </foreach>
    </select>
    <select id="findTbasicByInpatientNo" resultType="com.docus.server.archivemysql.entity.TBasic">
        select
        <include refid="basicInfoColumns"></include>
        from
        docus_medicalrecord.t_basic
        where inpatient_no=#{inpatientNo} and file_source = 1
    </select>
    <select id="findTaskMakeup" resultType="com.docus.server.archivemysql.entity.TaskMakeupOnView">
        SELECT id, inpatient_no, admiss_times, patient_id, dis_date, collect_sys_type, name, report_last_modify
        FROM docus_archivefile.task_makeup_onview
        WHERE inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} and collect_sys_type=#{collectSys}
    </select>
</mapper>
