liusheng
3 天以前 7a4465ad9ffccaa6d8d9e4545c6d9fce0344ac45
smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml
@@ -280,11 +280,26 @@
                #{leavehospitaldistrictcode}
            </foreach>
        </if>
        <if test="hospitaldistrictcodeList != null and hospitaldistrictcodeList.size()>0">
            AND b.hospitaldistrictcode IN
            <foreach collection="hospitaldistrictcodeList" item="hospitaldistrictcode" open="(" separator=","
                     close=")">
                #{hospitaldistrictcode}
            </foreach>
        </if>
        <if test="leaveldeptcodes != null and leaveldeptcodes.size()>0">
            AND b.leaveldeptcode IN
            <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                     close=")">
                #{leaveldeptcode}
            </foreach>
        </if>
        <if test="deptcodeList != null and deptcodeList.size()>0">
            AND b.deptcode IN
            <foreach collection="deptcodeList" item="deptcode" open="(" separator=","
                     close=")">
                #{deptcode}
            </foreach>
        </if>
        GROUP BY
@@ -854,163 +869,70 @@
    <select id="selectPatMedInhospCount" parameterType="com.smartor.domain.PatMedReq"
            resultType="com.smartor.domain.PatMedRes">
        SELECT SUM( rs ) AS rs,
        SUM( rc ) AS rc,
        SUM( scsf ) AS scsf,
        SUM( zcsf ) AS zcsf,
        SUM( zbsf ) AS zbsf
        SELECT SUM(rc) AS rc,
        SUM(rs) AS rs,
        SUM(scsf) AS scsf,
        SUM(zcsf) AS zcsf,
        SUM(zbsf) AS zbsf
        FROM (
        <!-- 出院人次-->
        <!-- 出院人次:去掉 date_format 包装,使日期字段索引生效 -->
        SELECT
        COUNT(1) AS rc,
        0 AS rs,
        0 AS scsf,
        0 AS zcsf,
        0 AS zbsf
        FROM
        pat_med_inhosp
        JOIN
        pat_archive ON pat_archive.id = pat_med_inhosp.patid
        where 1=1
        and pat_med_inhosp.del_flag=0
        FROM pat_med_inhosp
        JOIN pat_archive ON pat_archive.id = pat_med_inhosp.patid
        WHERE pat_med_inhosp.del_flag = 0
        <if test="orgid != null and orgid != ''">
            and pat_med_inhosp.orgid = #{orgid}
            AND pat_med_inhosp.orgid = #{orgid}
        </if>
        AND pat_archive.idcardno IS NOT NULL
        <if test="zy != null">
            and pat_med_inhosp.inhospstate=0
            and date_format(pat_med_inhosp.starttime,'%y%m%d') &gt;= date_format(#{startDate},'%y%m%d')
            and date_format(pat_med_inhosp.starttime,'%y%m%d') &lt;= date_format(#{endDate},'%y%m%d')
            <if test="deptcodeList != null   and deptcodeList.size() > 0">
                and pat_med_inhosp.deptcode in
            AND pat_med_inhosp.inhospstate = 0
            AND pat_med_inhosp.starttime &gt;= #{startDate}
            AND pat_med_inhosp.starttime &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
            <if test="deptcodeList != null and deptcodeList.size() > 0">
                AND pat_med_inhosp.deptcode IN
                <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                    #{deptcode}
                </foreach>
            </if>
        </if>
        <if test="cy != null">
            and pat_med_inhosp.inhospstate=1
            and date_format(pat_med_inhosp.endtime,'%y%m%d') &gt;= date_format(#{startDate},'%y%m%d')
            and date_format(pat_med_inhosp.endtime,'%y%m%d') &lt;= date_format(#{endDate},'%y%m%d')
            <if test="deptcodeList != null   and deptcodeList.size() > 0">
                and pat_med_inhosp.leaveldeptcode in
            AND pat_med_inhosp.inhospstate = 1
            AND pat_med_inhosp.endtime &gt;= #{startDate}
            AND pat_med_inhosp.endtime &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
            <if test="deptcodeList != null and deptcodeList.size() > 0">
                AND pat_med_inhosp.leaveldeptcode IN
                <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                    #{deptcode}
                </foreach>
            </if>
        </if>
        <!-- 随访服务人数 -->
        union all
        select
        UNION ALL
        <!-- 随访服务/首次/再次/专病随访:合并为单次扫描,用条件聚合代替4个 UNION ALL -->
        SELECT
        0 AS rc,
        count(1) AS rs,
        0 AS scsf,
        0 AS zcsf,
        0 AS zbsf
        FROM
        service_subtask
        where 1=1
        and del_flag = 0
        and service_type=2
        COUNT(1) AS rs,
        SUM(CASE WHEN service_type = 2 AND visit_count = 1 THEN 1 ELSE 0 END) AS scsf,
        SUM(CASE WHEN service_type = 2 AND visit_count > 1 THEN 1 ELSE 0 END) AS zcsf,
        SUM(CASE WHEN service_type = 13 THEN 1 ELSE 0 END) AS zbsf
        FROM service_subtask
        WHERE del_flag = 0
        AND service_type IN (2, 13)
        <if test="orgid != null and orgid != ''">
            and orgid = #{orgid}
            AND orgid = #{orgid}
        </if>
        <if test="startDate != null">
            AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
            AND visit_time &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            AND date_format( visit_time, '%y%m%d' ) &lt;= date_format(#{endDate},'%y%m%d')
            AND visit_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
        </if>
        <if test="deptcodeList != null   and deptcodeList.size() > 0">
            and deptcode in
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        <!-- 首次随访人数 -->
        union all
        select
        0 AS rc,
        0 AS rs,
        count(1) AS scsf,
        0 AS zcsf,
        0 AS zbsf
        FROM
        service_subtask
        where 1=1
        and del_flag = 0
        and service_type=2
        and visit_count is not null
        and visit_count = 1
        <if test="orgid != null and orgid != ''">
            and orgid = #{orgid}
        </if>
        <if test="startDate != null">
            AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
        </if>
        <if test="endDate != null">
            AND date_format( visit_time, '%y%m%d' ) &lt;= date_format(#{endDate},'%y%m%d')
        </if>
        <if test="deptcodeList != null   and deptcodeList.size() > 0">
            and deptcode in
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        <!-- 再次随访人数 -->
        union all
        select
        0 AS rc,
        0 AS rs,
        0 AS scsf,
        count(1) AS zcsf,
        0 AS zbsf
        FROM
        service_subtask
        where 1=1
        and del_flag = 0
        and service_type=2
        and visit_count is not null
        and visit_count > 1
        <if test="orgid != null and orgid != ''">
            and orgid = #{orgid}
        </if>
        <if test="startDate != null">
            AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
        </if>
        <if test="endDate != null">
            AND date_format( visit_time, '%y%m%d' ) &lt;= date_format(#{endDate},'%y%m%d')
        </if>
        <if test="deptcodeList != null   and deptcodeList.size() > 0">
            and deptcode in
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        <!-- 专病随访人数 -->
        union all
        select
        0 AS rc,
        0 AS rs,
        0 AS scsf,
        0 AS zcsf,
        count(1) AS zbsf
        FROM
        service_subtask
        where 1=1
        and del_flag = 0
        and service_type=13
        <if test="orgid != null and orgid != ''">
            and orgid = #{orgid}
        </if>
        <if test="startDate != null">
            AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
        </if>
        <if test="endDate != null">
            AND date_format( visit_time, '%y%m%d' ) &lt;= date_format(#{endDate},'%y%m%d')
        </if>
        <if test="deptcodeList != null   and deptcodeList.size() > 0">
            and deptcode in
        <if test="deptcodeList != null and deptcodeList.size() > 0">
            AND deptcode IN
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>