<?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.ruoyi.web.work.mapper.RequestMapper">

    <select id="selectList" resultType="com.ruoyi.web.work.domain.Request">
        select * from tb_obr_request
        <where>
            <if test="orcId != null "> and orc_id = #{orcId}</if>
            <if test="medTechProCode != null and medTechProCode != ''"> and med_tech_pro_code = #{medTechProCode}</if>
            <if test="medTechProName != null and medTechProName != ''"> and med_tech_pro_name like concat('%', #{medTechProName}, '%')</if>
            <if test="reportClass != null and reportClass != ''"> and report_class = #{reportClass}</if>
            <if test="reportCompleteTime != null "> and report_complete_time = #{reportCompleteTime}</if>
            <if test="signs != null and signs != ''"> and signs = #{signs}</if>
            <if test="sampleReceivedDate != null "> and sample_received_date = #{sampleReceivedDate}</if>
            <if test="checkpoint != null and checkpoint != ''"> and checkpoint = #{checkpoint}</if>
            <if test="executeDepartmentCode != null and executeDepartmentCode != ''"> and execute_department_code = #{executeDepartmentCode}</if>
            <if test="executeDepartmentName != null and executeDepartmentName != ''"> and execute_department_name like concat('%', #{executeDepartmentName}, '%')</if>
            <if test="isFlag != null and isFlag != ''"> and is_flag = #{isFlag}</if>
            <if test="reviewDoctorCode != null and reviewDoctorCode != ''"> and review_doctor_code = #{reviewDoctorCode}</if>
            <if test="reviewDoctorName != null and reviewDoctorName != ''"> and review_doctor_name like concat('%', #{reviewDoctorName}, '%')</if>
            <if test="reportDate != null "> and report_date = #{reportDate}</if>
            <if test="reportNo != null and reportNo != ''"> and report_no = #{reportNo}</if>
        </where>
    </select>

    <select id="getRequestByCard" resultType="com.ruoyi.web.work.domain.Request">
        select * from tb_obr_request where card_id=#{card}
    </select>

    <select id="getAllRequestByPatId" resultType="com.ruoyi.web.work.domain.Request">
        SELECT * from tb_obr_request
        where tb_obr_request.orc_id in
              (SELECT tb_orc_report.id from tb_orc_report where tb_orc_report.pat_id=#{patId})

    </select>

    <!--小程序检测报告列表-->
    <select id="getRequestListByPatId" resultType="com.ruoyi.web.work.domain.Request">
        SELECT
        *
        FROM
            tb_obr_request obr
            LEFT JOIN tb_orc_report orc ON obr.orc_id = orc.id
            LEFT JOIN tb_visit vi ON orc.visit_id = vi.id
        WHERE
            orc.pat_id = #{patId}
        <if test="startTime != null and endTime != null">
            AND vi.admission_time BETWEEN #{startTime} AND #{endTime}
        </if>
    </select>

    <select id="selectOrcReportByOrcId" resultType="com.ruoyi.web.work.domain.Request">
        SELECT * from tb_obr_request
        where orc_id = #{orcId}
    </select>

</mapper>
