<?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.supervision.mapper.ProcessMapper">

    <resultMap id="BaseResultMap" type="com.supervision.model.Process">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="patientId" column="patient_id" jdbcType="VARCHAR"/>
        <result property="medicalRecId" column="medical_rec_id" jdbcType="VARCHAR"/>
        <result property="userId" column="user_id" jdbcType="VARCHAR"/>
        <result property="graphId" column="graph_id" jdbcType="VARCHAR"/>
        <result property="processNo" column="process_no" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="processType" column="process_type" jdbcType="INTEGER"/>
        <result property="finishAskTime" column="finish_ask_time" jdbcType="TIMESTAMP"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
        <result property="evaluateLevel" column="evaluate_level" jdbcType="INTEGER"/>
        <result property="evaluateRemark" column="evaluate_remark" jdbcType="VARCHAR"/>
        <result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateUserId" column="update_user_id" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,process_no,patient_id,user_id,status,process_type,
          finish_ask_time,graph_id,delete_flag,
        create_user_id,create_time,update_user_id,update_time
    </sql>


    <sql id="queryUserDiagnoseProcessListSql">
        select pro.id as processId,
        pro.user_id as userId,
        pro.status as status,
        pro.update_time as time,
        mre.id as medicalRecId,
        mre.patient_self_desc as patientSelfDesc,
        mre.patient_id as patientId,
        mre.patient_name as name,
        mre.patient_head_pic as patientHeadPic,
        mre.patient_age as age,
        mre.patient_gender as gender,
        pat.resource_id as resourceId
        from vp_process pro
        left join vp_medical_rec mre on pro.medical_rec_id = mre.id
        left join vp_patient pat on mre.patient_id = pat.id
        where
        pro.user_id = #{diagnoseProcess.userId}
        <if test="diagnoseProcess.patientSelfDesc != null and diagnoseProcess.patientSelfDesc != ''">
            AND mre.patient_self_desc like concat("%",#{diagnoseProcess.patientSelfDesc}, "%")
        </if>
        <if test="diagnoseProcess.deleteFlag != null ">
            AND pro.delete_flag = #{diagnoseProcess.deleteFlag}
        </if>
        ORDER BY pro.update_time desc
    </sql>

    <select id="queryDiagnoseProcessPageList" resultType="com.supervision.vo.result.DiagnoseProcessResVo">
        <include refid="queryUserDiagnoseProcessListSql"></include>
    </select>

    <select id="queryProcessRecordPage" resultType="com.supervision.vo.result.ProcessRecordVO">
        select t1.id as processId,
        t2.id as medicalId,
        t1.process_no as processNo,
        t2.no as medicalRecNo,
        t1.user_id as userId,
        t3.name as studentName,
        t2.disease_id as diseaseId,
        t1.status as status,
        cast(t4.contain_disease_ids as CHAR ) as containDiseaseIdJsonStr
        from vp_process t1
        left join vp_medical_rec t2 on t1.medical_rec_id = t2.id
        left join vp_user t3 on t1.user_id = t3.id
        left join vp_disease t4 on t1.disease_id = t4.id
        where 1 = 1
        <if test="studentName != null and studentName != ''">
            and t3.name like concat("%",#{studentName}, "%")
        </if>
        <if test="medicalRecNo != null and medicalRecNo != ''">
            and t2.no like concat("%",#{medicalRecNo}, "%")
        </if>
        <if test="diseaseList != null and diseaseList.size() > 0">
            and t4.id in
            <foreach item="diseaseId" collection="diseaseList" open="(" separator="," close=")">
                #{diseaseId}
            </foreach>
        </if>

    </select>
</mapper>