liusheng
8 天以前 c111e3eff1191b29d2d2baf2f485a4bf3a2edc00
smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml
@@ -59,6 +59,7 @@
        <result property="medicareType" column="medicare_type"/>
        <result property="carePerson" column="care_person"/>
        <result property="casePersonAge" column="case_person_age"/>
        <result property="reservedPhone" column="reserved_phone"/>
    </resultMap>
@@ -116,6 +117,8 @@
        <result property="tagname" column="tagname"/>
        <result property="leavehospitaldistrictname" column="leavehospitaldistrictname"/>
        <result property="leavehospitaldistrictcode" column="leavehospitaldistrictcode"/>
        <result property="admitdate" column="admitdate"/>
        <result property="reservedPhone" column="reserved_phone"/>
    </resultMap>
    <sql id="selectPatArchiveVo">
@@ -142,6 +145,7 @@
               archivetime,
               archiveby,
               telcode,
               reserved_phone,
               relativetelcode,
               idcardtype,
               orgid,
@@ -197,6 +201,7 @@
            <if test="medicareType != null ">and medicare_type = #{medicareType}</if>
            <if test="carePerson != null ">and care_person = #{carePerson}</if>
            <if test="casePersonAge != null ">and case_person_age = #{casePersonAge}</if>
            <if test="reservedPhone != null ">and reserved_phone = #{reservedPhone}</if>
        </where>
    </select>
@@ -231,11 +236,13 @@
        a.income,
        a.medicare_type,
        a.care_person,
        a.reserved_phone,
        a.case_person_age
        from pat_archive a,pat_archivetag b ,base_tag c
        <where>
            a.del_flag=0 and
            a.id = b.patid and b.tagid = c.tagid
            <if test="reservedPhone != null ">and reserved_phone = #{reservedPhone}</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and idcardno = #{idcardno}</if>
            <if test="telcode != null  and telcode != ''">and telcode = #{telcode}</if>
@@ -301,6 +308,7 @@
            <if test="medicareType != null ">medicare_type,</if>
            <if test="carePerson != null ">care_person,</if>
            <if test="casePersonAge != null ">case_person_age,</if>
            <if test="reservedPhone != null ">reserved_phone,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="patientno != null">#{patientno},</if>
@@ -348,6 +356,7 @@
            <if test="medicareType != null ">#{medicareType},</if>
            <if test="carePerson != null ">#{carePerson},</if>
            <if test="casePersonAge != null ">#{casePersonAge},</if>
            <if test="reservedPhone != null ">#{reservedPhone},</if>
        </trim>
    </insert>
@@ -355,14 +364,14 @@
        insert into
        pat_archive(name,viptype,sex,idcardno,birthdate,place_of_residence,age,age2,sourcefrom,archivetime,archiveby,telcode,relativetelcode,idcardtype,orgid,openid,dduserid,update_by,update_time
        ,create_by,create_time,isupload,upload_time,pattype,nation,birthplace,native_place,patientno,patid_his,sd_flag,age_unit,age_unit2,notrequired_flag,notrequiredreason,care_facilities,case_path,
        degree_of_education,marital_status,income,medicare_type,care_person,case_person_age)
        degree_of_education,marital_status,income,medicare_type,care_person,case_person_age,reserved_phone)
        values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.name},#{item.viptype},#{item.sex},#{item.idcardno},#{item.birthdate},#{item.placeOfResidence},#{item.age},#{item.age2},#{item.sourcefrom},#{item.archivetime},#{item.archiveby}
            ,#{item.telcode},#{item.archiveby},#{item.idcardtype},#{item.orgid},#{item.openid},#{item.dduserid},#{item.updateBy},
            #{item.updateTime},#{item.createBy},#{item.createTime},#{item.isupload},#{item.uploadTime},#{item.pattype},#{item.nation},#{item.birthplace},#{item.nativePlace},#{item.patientno},
            #{item.patidHis},#{item.sdFlag},#{item.ageUnit},#{item.ageUnit2},#{item.notrequiredFlag},#{item.notrequiredreason}
            ,#{item.careFacilities},#{item.casePath},#{item.degreeOfEducation},#{item.maritalStatus},#{item.income},#{item.medicareType},#{item.carePerson},#{item.casePersonAge})
            ,#{item.careFacilities},#{item.casePath},#{item.degreeOfEducation},#{item.maritalStatus},#{item.income},#{item.medicareType},#{item.carePerson},#{item.casePersonAge},#{item.reservedPhone})
        </foreach>
    </insert>
@@ -393,9 +402,9 @@
            <if test="isupload != null">isupload = #{isupload},</if>
            <if test="uploadTime != null">upload_time = #{uploadTime},</if>
            <if test="viptype != null">viptype = #{viptype},</if>
            <if test="viptype != null">patientno = #{patientno},</if>
            <if test="viptype != null">patid_his = #{patidHis},</if>
            <if test="viptype != null">sd_flag = #{sdFlag},</if>
            <if test="patientno != null">patientno = #{patientno},</if>
            <if test="patidHis != null">patid_his = #{patidHis},</if>
            <if test="sdFlag != null">sd_flag = #{sdFlag},</if>
            <if test="ageUnit != null">age_unit = #{ageUnit},</if>
            <if test="ageUnit2 != null">age_unit2 = #{ageUnit2},</if>
            <if test="notrequiredFlag != null ">notrequired_flag = #{notrequiredFlag},</if>
@@ -408,6 +417,7 @@
            <if test="medicareType != null ">medicare_type = #{medicareType},</if>
            <if test="carePerson != null ">care_person = #{carePerson},</if>
            <if test="casePersonAge != null ">case_person_age = #{casePersonAge},</if>
            <if test="reservedPhone != null ">reserved_phone = #{reservedPhone},</if>
        </trim>
        where id = #{id}
    </update>
@@ -465,6 +475,7 @@
        a.upload_time,
        a.viptype,
        a.pattype,
        a.reserved_phone,
        COALESCE((
        SELECT string_agg(d.tagname, ', ')
        FROM pat_archivetag d
@@ -478,12 +489,13 @@
        LEFT JOIN pat_archivetag b ON a.id = b.patid AND b.del_flag = 0
        <where>
            a.del_flag = 0
            <if test="reservedPhone != null ">and a.reserved_phone = #{reservedPhone}</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="tagname != null  and tagname != ''">and b.tagname like concat('%', #{tagname}, '%')</if>
            <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=")">
@@ -538,6 +550,7 @@
        a.create_by,
        a.create_time,
        a.isupload,
        a.reserved_phone,
        a.upload_time,
        a.pattype,
        d.bed_no,
@@ -559,15 +572,15 @@
        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
        ) t ON t.patid = d.patid
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="reservedPhone != null ">and a.reserved_phone = #{reservedPhone}</if>
            <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>
@@ -613,14 +626,15 @@
                </foreach>
            </if>
            <if test="hospitaldistrictcodes != null and hospitaldistrictcodes.size()>0">
            <if test="hospitaldistrictcodes != null and hospitaldistrictcodes.size()>0 and deptcodes == null ">
                AND d.hospitaldistrictcode IN
                <foreach collection="hospitaldistrictcodes" item="hospitaldistrictcode" open="(" separator=","
                         close=")">
                    #{hospitaldistrictcode}
                </foreach>
            </if>
            <if test="deptcodes != null and deptcodes.size() > 0">
            <if test="deptcodes != null and deptcodes.size() > 0 and hospitaldistrictcodes == null">
                AND d.deptcode IN
                <foreach collection="deptcodes" item="deptcode" open="(" separator=","
                         close=")">
@@ -628,11 +642,25 @@
                </foreach>
            </if>
            <if test="hospitaldistrictcodes != null and hospitaldistrictcodes.size()>0 and deptcodes != null ">
                AND (d.hospitaldistrictcode IN
                <foreach collection="hospitaldistrictcodes" item="hospitaldistrictcode" open="(" separator=","
                         close=")">
                    #{hospitaldistrictcode}
                </foreach>
            </if>
            <if test="hospitaldistrictcodes != null and deptcodes != null and deptcodes.size() > 0">
                OR d.deptcode IN
                <foreach collection="deptcodes" item="deptcode" open="(" separator=","
                         close="))">
                    #{deptcode}
                </foreach>
            </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">
@@ -684,8 +712,7 @@
        a.create_time,
        a.isupload,
        a.upload_time,
        d.leavehospitaldistrictcode AS leavehospitaldistrictcode,
        d.leavehospitaldistrictname AS leavehospitaldistrictname,
        a.reserved_phone,
        COALESCE((
        SELECT string_agg(dd.tagname, ', ')
        FROM pat_archivetag dd
@@ -700,7 +727,8 @@
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="reservedPhone != null ">and a.reserved_phone = #{reservedPhone}</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 +756,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">
@@ -783,6 +811,7 @@
        a.create_time,
        a.isupload,
        a.upload_time,
        a.reserved_phone,
        COALESCE((
        SELECT string_agg(dd.tagname, ', ')
        FROM pat_archivetag dd
@@ -797,7 +826,8 @@
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="reservedPhone != null ">and a.reserved_phone = #{reservedPhone}</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 +853,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 +868,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,
@@ -881,96 +909,115 @@
        a.isupload,
        a.upload_time,
        a.pattype,
        a.reserved_phone,
        d.bed_no,
        d.starttime,
        d.endtime,
        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="reservedPhone != null ">and a.reserved_phone = #{reservedPhone}</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="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="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0">
            <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 leaveldeptcodes == null">
                AND d.leavehospitaldistrictcode IN
                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
                         close=")">
                    #{leavehospitaldistrictcode}
                </foreach>
            </if>
            <if test="leaveldeptcodes != null and leaveldeptcodes.size() > 0">
                AND d.leaveldeptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0 and leaveldeptcodes != null and leaveldeptcodes.size() > 0">
                AND (d.leavehospitaldistrictcode IN
                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
                         close=")">
                    #{leavehospitaldistrictcode}
                </foreach>
            </if>
            <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 +1031,7 @@
        d.deptcode,
        d.drcode,
        d.drname,
        d.admitdate,
        a.name,
        a.sex,
        a.nation,
@@ -1008,58 +1056,75 @@
        a.create_by,
        a.create_time,
        a.isupload,
        a.reserved_phone,
        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="reservedPhone != null ">and a.reserved_phone = #{reservedPhone}</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"
@@ -1104,6 +1169,7 @@
        a.create_time,
        a.isupload,
        a.upload_time,
        a.reserved_phone,
        COALESCE((
        SELECT string_agg(dd.tagname, ', ')
        FROM pat_archivetag dd
@@ -1119,7 +1185,8 @@
        <where>
            d.del_flag != 1
            AND a.del_flag != 1
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="reservedPhone != null ">and a.reserved_phone = #{reservedPhone}</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 +1212,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">