<?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.ydzyy.mapper.YdZyyPacsViewMapper">


    <sql id="View_Paperless_DDL">
        select
        b.serialno as REMARK,
        ISNULL(a.register_num,'') as REGISTER_NUM,
        ISNULL(a.hst_num,'') as NP_NO,
        a.study_id as ACCNO,
        CONVERT(VARCHAR(10),a.crt_time,120) as CREATETIMESTR,
        b.report_doc as REPORTDOC,
        a.modality + '检查报告单' as REPORTNAME,
        a.name as NAME,
        b.aduit_time as ADUITTIME,
        '\\10.10.100.97\新图像存储\报告打印图像预览\' + CONVERT(char(4), YEAR(CASE WHEN studytime IS NULL
        THEN preengagetime ELSE studytime END)) + '年' + RTRIM(CONVERT(char(2), MONTH(CASE WHEN studytime IS NULL
        THEN preengagetime ELSE studytime END))) + '月' + RTRIM(CONVERT(char(2), DAY(CASE WHEN studytime IS NULL
        THEN preengagetime ELSE studytime END))) + '日\' + a.name + '_' + a.modality + '_' + LTRIM(STR(a.serialno))
        + '.jpg' as FILEPATH,
        a.statuschgtime as STATUSCHGTIME,
        a.send_date as SENDDATE,
        a.id_card as IDCARD
        FROM pacsdb..rcv_patient a WITH(NOLOCK)
        JOIN pacsdb..diagnose_report b WITH(NOLOCK) on a.serialno = b.serialno
        LEFT join pacsdb..sick_type c on a.sick_type=c.sick_id
        WHERE a.preengagetime >= '2022-10-01 00:00:00'
        AND a.proc_status >='50'
        AND b.userlevel = pacsproc.dbo.fnGetMaxLevelSerialno(a.serialno)
        AND charindex('体检',c.sick_name) <![CDATA[<]]> 1
    </sql>

    <select id="pacsViews" resultType="com.docus.server.ydzyy.entity.YdZyyPacsView">
        select
            REMARK,
            REGISTER_NUM,
            NP_NO,
            ACCNO,
            CREATETIMESTR,
            REPORTDOC,
            REPORTNAME,
            NAME,
            ADUITTIME,
            FILEPATH,
            STATUSCHGTIME,
            SENDDATE,
            IDCARD
        from dbo.View_Paperless
        where (ADUITTIME is not null and ADUITTIME != '')
        <if test="condition.changeTimeStart != null and condition.changeTimeStart != ''">
            and STATUSCHGTIME >= #{condition.changeTimeStart}
        </if>
        <if test="condition.changeTimeEnd != null and condition.changeTimeEnd != ''">
            and STATUSCHGTIME <![CDATA[<=]]> #{condition.changeTimeEnd}
        </if>
        <if test="condition.sendDateStart != null and condition.sendDateStart != ''">
            and SENDDATE >= #{condition.sendDateStart}
        </if>
        <if test="condition.sendDateEnd != null and condition.sendDateEnd != ''">
            and SENDDATE <![CDATA[<=]]> #{condition.sendDateEnd}
        </if>
        <if test="condition.inpNo != null and condition.inpNo != ''">
            and NP_NO = #{condition.inpNo}
        </if>
        <if test="condition.idCard != null and condition.idCard != ''">
            and IDCARD = #{condition.idCard}
        </if>
        <if test="condition.remark != null and condition.remark != ''">
            and REMARK=#{condition.remark}
        </if>
        order by CREATETIMESTR asc
    </select>


    <select id="longTimePacsViews" resultType="com.docus.server.ydzyy.entity.YdZyyPacsView">
        select
        REMARK,
        REGISTER_NUM,
        NP_NO,
        ACCNO,
        CREATETIMESTR,
        REPORTDOC,
        REPORTNAME,
        NAME,
        ADUITTIME,
        FILEPATH,
        STATUSCHGTIME,
        SENDDATE,
        IDCARD
        from ( <include refid="View_Paperless_DDL"></include> ) viewdata
        where (ADUITTIME is not null and ADUITTIME != '')
        <if test="condition.changeTimeStart != null and condition.changeTimeStart != ''">
            and STATUSCHGTIME >= #{condition.changeTimeStart}
        </if>
        <if test="condition.changeTimeEnd != null and condition.changeTimeEnd != ''">
            and STATUSCHGTIME <![CDATA[<=]]> #{condition.changeTimeEnd}
        </if>
        <if test="condition.sendDateStart != null and condition.sendDateStart != ''">
            and SENDDATE >= #{condition.sendDateStart}
        </if>
        <if test="condition.sendDateEnd != null and condition.sendDateEnd != ''">
            and SENDDATE <![CDATA[<=]]> #{condition.sendDateEnd}
        </if>
        <if test="condition.inpNo != null and condition.inpNo != ''">
            and NP_NO = #{condition.inpNo}
        </if>
        <if test="condition.idCard != null and condition.idCard != ''">
            and IDCARD = #{condition.idCard}
        </if>
        <if test="condition.remark != null and condition.remark != ''">
            and REMARK=#{condition.remark}
        </if>
        order by CREATETIMESTR asc
    </select>
</mapper>
