<?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.synclis.mapper.LisViewMapper">

    <select id="getZyDataFromView" resultType="com.docus.server.synclis.entity.LisView">
        SELECT
            patient_id AS  patientId,
            lab_num AS labNum,
            name,
            hst_num AS  hstNum,
            req_num AS reqNum,
            req_date AS reqDate,
            audit_time AS auditTime,
            CheckName AS checkName,
            PatSource AS patSource,
            IDCARD AS idCard
        FROM dbo.v_LISReport_YDZYView
        WHERE  PatSource = '住院'
            AND hst_num = #{inpatientNo}
            AND Audit_time != ''
            AND Audit_time IS NOT NULL
            AND Audit_time >= '2022-10-01'
            AND req_date >= #{admissDate}
            AND req_date &lt;= #{disDate}
        ORDER BY audit_time DESC
    </select>
    <select id="getMzDataFromView" resultType="com.docus.server.synclis.entity.LisView">
        SELECT
            patient_id AS  patientId,
            lab_num AS labNum,
            name,
            hst_num AS  hstNum,
            req_num AS reqNum,
            req_date AS reqDate,
            audit_time AS auditTime,
            CheckName AS checkName,
            PatSource AS patSource,
            IDCARD AS idCard
        FROM hylisproc.dbo.v_LISReport_YDZYView
        WHERE  PatSource IN ('门诊','急诊')
            AND IDCARD =#{idCard}
            AND IDCARD != ''
            AND IDCARD IS NOT NULL
            AND Audit_time != ''
            AND Audit_time IS NOT NULL
            AND Audit_time >= '2022-10-01'
            AND req_date >=  #{startDate}
            AND req_date &lt;= #{endDate}
        ORDER BY audit_time DESC
    </select>
    <select id="getFullZyData" resultType="com.docus.server.synclis.entity.LisView">
        SELECT
            patient_id AS  patientId,
            lab_num AS labNum,
            name,
            hst_num AS  hstNum,
            req_num AS reqNum,
            req_date AS reqDate,
            audit_time AS auditTime,
            CheckName AS checkName,
            PatSource AS patSource,
            IDCARD AS idCard
        FROM
            (
                SELECT
                       a.patient_id,
                       a.lab_num,b.name,
                       a.hst_num,
                       ISNULL(a.req_num,'') AS req_num,
                       a.req_date,
                       CONVERT(VARCHAR(19),a.audit_time,120) AS audit_time,
                       dbo.fnGetChkTypeNameByLabNum(a.lab_num) AS CheckName,
                       ISNULL(c.name,'') AS PatSource,
                       ISNULL(b.id_card,'') as IDCARD
                FROM hylisdb..patient_register a WITH(NOLOCK)
 	                JOIN hylisdb..patient_baseinfo b WITH(NOLOCK) ON a.patient_id=b.patient_id
                    JOIN hylisdb..ill_type c ON a.send_type=c.type_id
                WHERE
                    a.hst_num = #{inpatientNo}
                    AND c.name = '住院'
                    AND a.req_date >= #{admissDate}
                    AND a.req_date &lt;= #{disDate}
                    AND a.proc_flag = '8'
            ) temp
        WHERE
            Audit_time != ''
            AND Audit_time IS NOT NULL
            AND Audit_time >= '2022-10-01'
            ORDER BY audit_time DESC
    </select>
    <select id="getFullMzData" resultType="com.docus.server.synclis.entity.LisView">
        SELECT
            patient_id AS  patientId,
            lab_num AS labNum,
            name,
            hst_num AS  hstNum,
            req_num AS reqNum,
            req_date AS reqDate,
            audit_time AS auditTime,
            CheckName AS checkName,
            PatSource AS patSource,
            IDCARD AS idCard
        FROM
            (
                SELECT
                    a.patient_id,
                    a.lab_num,b.name,
                    a.hst_num,
                    ISNULL(a.req_num,'') AS req_num,
                    a.req_date,
                    CONVERT(VARCHAR(19),a.audit_time,120) AS audit_time,
                    dbo.fnGetChkTypeNameByLabNum(a.lab_num) AS CheckName,
                    ISNULL(c.name,'') AS PatSource,
                    ISNULL(b.id_card,'') as IDCARD
                FROM hylisdb..patient_register a WITH(NOLOCK)
 	                JOIN hylisdb..patient_baseinfo b WITH(NOLOCK) ON a.patient_id=b.patient_id
                    JOIN hylisdb..ill_type c ON a.send_type=c.type_id
                WHERE
                    b.id_card = #{idCard}
                  AND c.name IN ('门诊','急诊')
                  AND a.req_date >= #{startDate}
                  AND a.req_date &lt;= #{endDate}
                  AND a.proc_flag = '8'
            ) temp
        WHERE
            Audit_time != ''
            AND Audit_time IS NOT NULL
            AND Audit_time >= '2022-10-01'
        ORDER BY audit_time DESC
    </select>
</mapper>
