liusheng
4 天以前 38e0cad3107b0a43e9afac4e5e55cf769e84d01c
smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml
@@ -116,6 +116,7 @@
        <result property="tagname" column="tagname"/>
        <result property="leavehospitaldistrictname" column="leavehospitaldistrictname"/>
        <result property="leavehospitaldistrictcode" column="leavehospitaldistrictcode"/>
        <result property="admitdate" column="admitdate"/>
    </resultMap>
    <sql id="selectPatArchiveVo">
@@ -483,7 +484,7 @@
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="notrequiredFlag != null  and notrequiredFlag != ''">and a.notrequired_flag = #{notrequiredFlag}
            </if>
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="patid != null  and patid != ''">and a.id = #{patid}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode like concat('%', #{telcode}, '%')</if>
            <if test="tagIds != null  and tagIds != ''">and b.tagid in
                <foreach collection="tagIds" item="tagId" open="(" separator="," close=")">
@@ -567,7 +568,7 @@
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="tagname != null  and tagname != ''">and t.tagname like concat('%', #{tagname}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="pid != null  and pid != ''">and a.id = #{id}</if>
            <if test="patid != null  and patid != ''">and a.id = #{patid}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode like concat('%', #{telcode}, '%')</if>
            <if test="notrequiredFlag != null  and notrequiredFlag != ''">and a.notrequired_flag = #{notrequiredFlag}
            </if>
@@ -629,10 +630,10 @@
            </if>
            <if test="pids != null">
            <if test="patids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                <foreach collection="patid" item="patid" open="(" separator="," close=")">
                    #{patid}
                </foreach>
            </if>
            <if test="isFilter == true">
@@ -700,7 +701,7 @@
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="patid != null  and patid != ''">and a.id = #{patid}</if>
            <if test="tagname != null  and tagname != ''">and t.tagname like concat('%', #{tagname}, '%')</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
@@ -728,10 +729,10 @@
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="pids != null">
            <if test="patids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                <foreach collection="patids" item="patid" open="(" separator="," close=")">
                    #{patid}
                </foreach>
            </if>
            <if test="isFilter == true">
@@ -797,7 +798,7 @@
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="patid != null  and patid != ''">and a.id = #{patid}</if>
            <if test="tagname != null  and tagname != ''">and t.tagname like concat('%', #{tagname}, '%')</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
@@ -823,10 +824,10 @@
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="pids != null">
            <if test="patids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                <foreach collection="patids" item="patid" open="(" separator="," close=")">
                    #{patid}
                </foreach>
            </if>
            <if test="isFilter == true">
@@ -838,9 +839,7 @@
    <select id="selectPatArchiveInfoByInhospQC" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveOthreInfoResult">
        select * from (
        select
        DISTINCT ON (a.id)
        SELECT DISTINCT ON (a.id)
        a.idcardno,
        a.id,
        a.age_unit,
@@ -887,59 +886,45 @@
        d.nurse_name,
        d.nurse_id,
        d.out_way_id,
        d.leavehospitaldistrictname AS leavehospitaldistrictname,
        d.leavehospitaldistrictcode AS leavehospitaldistrictcode,
        d.leavehospitaldistrictname,
        d.leavehospitaldistrictcode,
        COALESCE((
        SELECT string_agg(dd.tagname, ', ')
        FROM pat_archivetag dd
        WHERE dd.patid = a.id
        AND dd.del_flag = 0
        WHERE dd.patid = a.id AND dd.del_flag = 0
        ), '') AS tag
        FROM
        pat_med_inhosp d
        JOIN pat_archive a ON a.id = d.patid
        LEFT JOIN ( SELECT patid, GROUP_CONCAT( tagname ) AS tagname FROM pat_archivetag where del_flag=0 GROUP BY patid
        ) t ON t.patid =
        d.patid
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="tagname != null  and tagname != ''">and t.tagname like concat('%', #{tagname}, '%')</if>
            <if test="pid != null  and pid != ''">and a.id = #{id}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode like concat('%', #{telcode}, '%')</if>
            <if test="notrequiredFlag != null  and notrequiredFlag != ''">and a.notrequired_flag = #{notrequiredFlag}
            <if test="name != null  and name != ''">AND a.name LIKE concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">AND a.idcardno = #{idcardno}</if>
            <if test="tagname != null  and tagname != ''">
                AND EXISTS (
                SELECT 1 FROM pat_archivetag dd
                WHERE dd.patid = a.id AND dd.del_flag = 0 AND dd.tagname LIKE concat('%', #{tagname}, '%')
                )
            </if>
            <if test="hospitalname != null and hospitalname != ''">
                AND d.hospitalname = #{hospitalname}
            <if test="patid != null  and patid != ''">AND a.id = #{patid}</if>
            <if test="telcode != null  and telcode != ''">AND a.telcode LIKE concat('%', #{telcode}, '%')</if>
            <if test="notrequiredFlag != null and notrequiredFlag != ''">AND a.notrequired_flag = #{notrequiredFlag}
            </if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">
                AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')
            <if test="hospitalname != null and hospitalname != ''">AND d.hospitalname = #{hospitalname}</if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">AND d.hospitaldistrictname LIKE
                concat('%',#{hospitaldistrictname}, '%')
            </if>
            <if test="leaveicd10code != null and leaveicd10code != ''">
                AND d.leaveicd10code LIKE concat('%',#{leaveicd10code}, '%')
            <if test="leaveicd10code != null and leaveicd10code != ''">AND d.leaveicd10code LIKE
                concat('%',#{leaveicd10code}, '%')
            </if>
            <if test="endtime != null">
                AND d.endtime = #{endtime}
            </if>
            <if test="cry != null and cry == 0 ">and d.endtime is null</if>
            <if test="cry != null and cry == 1 ">and d.endtime is not null</if>
            <if test="visitno != null and visitno != ''">
                AND d.inhospno = #{visitno}
            </if>
            <if test="deptname != null and deptname != ''">
                and d.deptname LIKE concat('%', #{deptname}, '%')
            </if>
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="diagname != null and diagname != ''">
                AND d.diagname LIKE concat('%',#{diagname}, '%')
            </if>
            <if test="deptname != null and deptname != ''">
                AND d.deptname LIKE concat('%',#{deptname}, '%')
            </if>
            <if test="endtime != null">AND d.endtime = #{endtime}</if>
            <if test="cry != null and cry == 0 ">AND d.endtime IS NULL</if>
            <if test="cry != null and cry == 1 ">AND d.endtime IS NOT NULL</if>
            <if test="visitno != null and visitno != ''">AND d.inhospno = #{visitno}</if>
            <if test="deptname != null and deptname != ''">AND d.deptname LIKE concat('%', #{deptname}, '%')</if>
            <if test="drname != null and drname != ''">AND d.drname LIKE concat('%',#{drname}, '%')</if>
            <if test="diagname != null and diagname != ''">AND d.diagname LIKE concat('%',#{diagname}, '%')</if>
            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0">
                AND d.leavehospitaldistrictcode IN
                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
@@ -947,30 +932,54 @@
                    #{leavehospitaldistrictcode}
                </foreach>
            </if>
            <if test="leaveldeptcodes != null and leaveldeptcodes.size() > 0">
                AND d.leaveldeptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                         close=")">
            <if test="leaveldeptcodes != null and leaveldeptcodes.size() > 0 and leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0">
                OR d.leaveldeptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," close=")">
                    #{leaveldeptcode}
                </foreach>
            </if>
            <if test="pids != null">
            <if test="leaveldeptcodes != null and leaveldeptcodes.size() > 0 and leavehospitaldistrictcodes == null">
                AND d.leaveldeptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," close=")">
                    #{leaveldeptcode}
                </foreach>
            </if>
            <if test="hospitaldistrictcodes != null and hospitaldistrictcodes.size()>0">
                AND d.hospitaldistrictcode IN
                <foreach collection="hospitaldistrictcodes" item="hospitaldistrictcode" open="(" separator=","
                         close=")">
                    #{hospitaldistrictcode}
                </foreach>
            </if>
            <if test="deptcodes != null and deptcodes.size() > 0">
                AND d.deptcode IN
                <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
                    #{deptcode}
                </foreach>
            </if>
            <if test="patids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                <foreach collection="patids" item="patid" open="(" separator="," close=")">
                    #{patid}
                </foreach>
            </if>
            <if test="isFilter == true">
                AND NOT exists ( SELECT 1 FROM pat_filterlist f where d.patid=f.patid)
                AND NOT EXISTS (SELECT 1 FROM pat_filterlist f WHERE d.patid = f.patid)
            </if>
        </where>
        order by a.id,a.update_time desc ) order by endtime desc
        ORDER BY a.id, a.update_time DESC
    </select>
    <select id="selectPatArchiveInfoByOuthospQC" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveOthreInfoResult">
        select
        DISTINCT ON (a.id)
        WITH recent_tag AS (
        SELECT patid, string_agg(tagname, ', ') AS tagname
        FROM pat_archivetag
        WHERE del_flag = 0
        GROUP BY patid
        ),
        filtered AS (
        SELECT
        a.idcardno,
        a.id,
        a.age_unit,
@@ -984,6 +993,7 @@
        d.deptcode,
        d.drcode,
        d.drname,
        d.admitdate,
        a.name,
        a.sex,
        a.nation,
@@ -1009,57 +1019,72 @@
        a.create_time,
        a.isupload,
        a.upload_time,
        COALESCE((
        SELECT string_agg(dd.tagname, ', ')
        FROM pat_archivetag dd
        WHERE dd.patid = a.id
        AND dd.del_flag = 0
        ), '') AS tag,
        ROW_NUMBER() OVER (PARTITION BY A.idcardno ORDER BY A.update_time DESC) AS rn,
        rt.tagname,
        ROW_NUMBER() OVER (PARTITION BY a.idcardno ORDER BY a.update_time DESC) AS rn,
        a.pattype
        from pat_med_outhosp d JOIN pat_archive a ON a.id = d.patid
        LEFT JOIN ( SELECT patid, GROUP_CONCAT( tagname ) AS tagname FROM pat_archivetag where del_flag=0 GROUP BY patid
        ) t ON t.patid =
        d.patid
        FROM pat_med_outhosp d
        JOIN pat_archive a ON a.id = d.patid
        LEFT JOIN recent_tag rt ON rt.patid = a.id
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="tagname != null  and tagname != ''">and t.tagname like concat('%', #{tagname}, '%')</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode like concat('%', #{telcode}, '%')</if>
            AND d.admitdate >= CURRENT_DATE - INTERVAL '90 days' <!-- 强烈推荐加时间限制 -->
            <if test="patid != null and patid != ''">AND a.id = #{patid}</if>
            <if test="tagname != null and tagname != ''">AND rt.tagname LIKE concat('%', #{tagname}, '%')</if>
            <if test="name != null and name != ''">AND a.name LIKE concat('%', #{name}, '%')</if>
            <if test="idcardno != null and idcardno != ''">AND a.idcardno = #{idcardno}</if>
            <if test="telcode != null and telcode != ''">AND a.telcode LIKE concat('%', #{telcode}, '%')</if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">
                AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')
                AND d.hospitaldistrictname LIKE concat('%', #{hospitaldistrictname}, '%')
            </if>
            <if test="notrequiredFlag != null  and notrequiredFlag != ''">and a.notrequired_flag = #{notrequiredFlag}
            <if test="notrequiredFlag != null and notrequiredFlag != ''">
                AND a.notrequired_flag = #{notrequiredFlag}
            </if>
            <if test="diagname != null and diagname != ''">
                AND d.diagname LIKE concat('%',#{diagname}, '%')
            </if>
            <if test="hospitalname != null and hospitalname != ''">
                AND d.hospitalname = #{hospitalname}
            </if>
            <if test="visitno != null and visitno != ''">
                AND d.outhospno = #{visitno}
            </if>
            <if test="deptname != null and deptname != ''">
                and d.deptname LIKE concat('%', #{deptname}, '%')
            </if>
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="pids != null">
            <if test="diagname != null and diagname != ''">AND d.diagname LIKE concat('%', #{diagname}, '%')</if>
            <if test="deptcode != null and deptcode != ''">AND d.deptcode = #{deptcode}</if>
            <if test="visitno != null and visitno != ''">AND d.outhospno = #{visitno}</if>
            <if test="deptname != null and deptname != ''">AND d.deptname LIKE concat('%', #{deptname}, '%')</if>
            <if test="drname != null and drname != ''">AND d.drname LIKE concat('%', #{drname}, '%')</if>
            <if test="patids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                <foreach collection="patids" item="patid" open="(" separator="," close=")">
                    #{patid}
                </foreach>
            </if>
            <if test="isFilter == true">
                AND NOT exists ( SELECT 1 FROM pat_filterlist f where d.patid=f.patid)
                AND NOT EXISTS (
                SELECT 1 FROM pat_filterlist f WHERE d.patid = f.patid
                )
            </if>
        </where>
        order by a.id, a.update_time desc
        )
        SELECT *
        FROM filtered
        WHERE rn = 1
        <if test="pageNumMZ != null and pageSizeMZ != null">
            LIMIT #{pageSizeMZ} OFFSET (#{pageNumMZ} - 1) * #{pageSizeMZ}
        </if>
    </select>
    <select id="selectPatArchiveInfoByOuthospQCCount" parameterType="com.smartor.domain.PatArchiveReq"
            resultType="long">
        WITH recent_tag AS (SELECT patid, string_agg(tagname, ', ') AS tagname
                            FROM pat_archivetag
                            WHERE del_flag = 0
                            GROUP BY patid),
             filtered AS (
                 SELECT ROW_NUMBER() OVER ( PARTITION BY A.idcardno ORDER BY A.update_time DESC ) AS rn
                 FROM pat_med_outhosp d
                          JOIN pat_archive A ON A.ID = d.patid
                          LEFT JOIN recent_tag rt ON rt.patid = A.ID
                 WHERE d.del_flag != 1
            AND A.del_flag != 1
            AND d.admitdate >= CURRENT_DATE - INTERVAL '90 days'
            )
        SELECT COUNT(*)
        FROM filtered
        WHERE rn = 1;
    </select>
    <select id="selectPatArchiveInfoByPhysicalQC" parameterType="com.smartor.domain.PatArchiveReq"
@@ -1119,7 +1144,7 @@
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="patid != null  and patid != ''">and a.id = #{patid}</if>
            <if test="tagname != null  and tagname != ''">and t.tagname like concat('%', #{tagname}, '%')</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
@@ -1145,10 +1170,10 @@
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="pids != null">
            <if test="patids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                <foreach collection="patids" item="patid" open="(" separator="," close=")">
                    #{patid}
                </foreach>
            </if>
            <if test="isFilter == true">