<?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.diagbot.mapper.BehospitalInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.BehospitalInfo">
        <id column="behospital_code" property="behospitalCode"/>
        <result column="hospital_id" property="hospitalId"/>
        <result column="name" property="name"/>
        <result column="sex" property="sex"/>
        <result column="birthday" property="birthday"/>
        <result column="file_code" property="fileCode"/>
        <result column="qc_type_id" property="qcTypeId"/>
        <result column="ward_code" property="wardCode"/>
        <result column="ward_name" property="wardName"/>
        <result column="beh_dept_id" property="behDeptId"/>
        <result column="beh_dept_name" property="behDeptName"/>
        <result column="bed_code" property="bedCode"/>
        <result column="bed_name" property="bedName"/>
        <result column="insurance_name" property="insuranceName"/>
        <result column="job_type" property="jobType"/>
        <result column="behospital_date" property="behospitalDate"/>
        <result column="leave_hospital_date" property="leaveHospitalDate"/>
        <result column="diagnose_icd" property="diagnoseIcd"/>
        <result column="diagnose" property="diagnose"/>
        <result column="beh_doctor_id" property="behDoctorId"/>
        <result column="beh_doctor_name" property="behDoctorName"/>
        <result column="doctor_id" property="doctorId"/>
        <result column="doctor_name" property="doctorName"/>
        <result column="director_doctor_id" property="directorDoctorId"/>
        <result column="director_doctor_name" property="directorDoctorName"/>
        <result column="is_placefile" property="isPlacefile"/>
        <result column="placefile_date" property="placefileDate"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="modifier" property="modifier"/>
        <result column="linkman" property="linkman"/>
    </resultMap>

    <select id="getPage" resultType="com.diagbot.dto.BehospitalInfoDTO">
        SELECT * FROM (
        select   t.*,
        CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type AS ch_type,
        h.check_type AS mr_type,
        g.check_name AS ch_name,
        h.check_name AS mr_name,
        g.check_time AS ch_time,
        h.check_time AS mr_time
        from (
        select a.*, ifnull(b.level,'未评分') as `level`, b.grade_type, b.score_res, b.gmt_create as
        grade_time,IF(c.age is null, null,CONCAT( ifnull(c.age,'') ,ifnull(c.age_unit,'') ))as age,e.score_res as score_bn from med_behospital_info a
        LEFT JOIN med_qcresult_info b
        on a.behospital_code = b.behospital_code and b.is_deleted = 'N'
        left join med_home_page c
        on a.behospital_code = c.behospital_code and c.is_deleted = 'N'
        LEFT JOIN med_qcresult_cases e
        on  a.behospital_code = e.behospital_code
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type in(0,2) ) g
        ON t.behospital_code = g.behospital_code
        AND t.hospital_id = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON t.behospital_code = h.behospital_code
        AND t.hospital_id = h.hospital_id
        where t.is_deleted = 'N'
        <if test="diagnose != null and diagnose != ''">
            AND t.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="deptName != null and deptName != ''">
            and t.beh_dept_name= #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and CONCAT(
            IFNULL(t.doctor_name,''),IFNULL(t.beh_doctor_name,''),IFNULL(t.director_doctor_name,''))
            like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="name != null and name != ''">
            and t.name like CONCAT('%',#{name},'%')
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            and (t.doctor_id = #{doctorCode}
            or t.beh_doctor_id = #{doctorCode}
            or t.director_doctor_id = #{doctorCode})
        </if>
        <if test="fileCode != null and fileCode != ''">
            and t.file_code like CONCAT('%',#{fileCode},'%')
        </if>
        <if test="hospitalId != null">
            and t.hospital_id = #{hospitalId}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and t.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and t.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and t.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and t.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and t.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and t.level = #{level}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and t.is_placefile = #{isPlacefile}
        </if>
        and t.qc_type_id != 0) p
        where p.is_deleted="N"
        <if test="checkStatus != null ">
            and p.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND p.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND p.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND p.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and p.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and p.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and p.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and p.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>

    <select id="getQualityCaseSorce" resultType="com.diagbot.dto.CaseScoreDTO">
     SELECT  c.cases_id as casesId,c.cases_entry_id as casesEntryId,c.behospital_code as behospitalCode,c.score,c.cases_score as casesScore,c.msg,c.is_reject as isReject
        FROM  med_qcresult_detail c,med_behospital_info e
        where c.is_deleted = 'N'AND e.is_deleted = 'N'
        AND c.behospital_code = e.behospital_code
        AND c.hospital_id = e.hospital_id
        and c.hospital_id = #{hospitalId}
        <if test="deptName != null and deptName != ''">
            and e.beh_dept_name= #{deptName}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and e.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and e.is_placefile = #{isPlacefile}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and e.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and e.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and e.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and e.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        GROUP BY c.behospital_code,c.cases_id,c.cases_entry_id
        order by c.behospital_code
    </select>

    <select id="getQualityCaseSorceByDept" resultType="com.diagbot.dto.CaseScoreDTO">
        SELECT c.cases_id as casesId,c.cases_entry_id as casesEntryId,c.behospital_code as behospitalCode,c.score,c.cases_score as casesScore,c.msg,c.is_reject as isReject
        FROM  med_qcresult_detail c,sys_user_dept d,med_behospital_info e
        where  c.is_deleted = 'N' AND d.is_deleted = 'N' AND e.is_deleted = 'N'
        AND c.behospital_code = e.behospital_code
        ON d.hospital_id = e.hospital_id
        AND e.beh_dept_id = d.dept_id
        AND c.hospital_id = e.hospital_id
        and c.hospital_id = #{hospitalId}
        <if test="deptName != null and deptName != ''">
            and e.beh_dept_name= #{deptName}
        </if>
        <if test="userId != null and userId != ''">
            and d.user_id = #{userId}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and e.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and e.is_placefile = #{isPlacefile}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and e.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and e.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and e.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and e.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        GROUP BY c.behospital_code,c.cases_id,c.cases_entry_id
        order by c.behospital_code
    </select>

    <select id="getQualityControl" resultType="com.diagbot.dto.QualityControlDTO">
        SELECT * FROM (
        select
        distinct
        t.name AS NAME,
        t.behospital_code AS behospitalCode,
        t.doctor_name AS doctorName,
        t.beh_dept_name AS deptName,
        t.beh_dept_id AS deptId,
        t.leave_hospital_date AS leaveHospitalDate,
        t.level,
        t.age,
        t.score_res as totalScore,
        t.is_deleted,
        g.check_name AS chName,
        h.check_name AS mrName
        from (
        select a.*,
         ifnull(b.level,'未评分') as level,
          b.grade_type,
          IF(c.age is null, null,CONCAT( ifnull(c.age,'') ,ifnull(c.age_unit,'') ))as age,
          b.score_res
        from med_behospital_info a
        LEFT JOIN med_qcresult_info b
        on a.behospital_code = b.behospital_code and b.is_deleted = 'N'
        left join med_home_page c
        on a.behospital_code = c.behospital_code and c.is_deleted = 'N'
        ) t
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type = 0 ) g
        ON t.behospital_code = g.behospital_code
        AND t.hospital_id = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON t.behospital_code = h.behospital_code
        AND t.hospital_id = h.hospital_id
        where t.is_deleted = 'N'
        <if test="diagnose != null and diagnose != ''">
            AND t.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="deptName != null and deptName != ''">
            and t.beh_dept_name= #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and CONCAT(
            IFNULL(t.doctor_name,''),IFNULL(t.beh_doctor_name,''),IFNULL(t.director_doctor_name,''))
            like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="name != null and name != ''">
            and t.name like CONCAT('%',#{name},'%')
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            and (t.doctor_id = #{doctorCode}
            or t.beh_doctor_id = #{doctorCode}
            or t.director_doctor_id = #{doctorCode})
        </if>
        <if test="fileCode != null and fileCode != ''">
            and t.file_code like CONCAT('%',#{fileCode},'%')
        </if>
        <if test="hospitalId != null">
            and t.hospital_id = #{hospitalId}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and t.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and t.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and t.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and t.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and t.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and t.level = #{level}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and t.is_placefile = #{isPlacefile}
        </if>
        and t.qc_type_id != 0) p
        where p.is_deleted="N"
        <if test="chName != null and chName !=''">
            AND p.chName like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND p.mrName like CONCAT('%',#{mrName},'%')
        </if>
    </select>

    <select id="qualityControlByDept" resultType="com.diagbot.dto.QualityControlDeptDTO">
        SELECT * FROM (
        select
        distinct
        t.name AS NAME,
        t.behospital_code AS behospitalCode,
        t.doctor_name AS doctorName,
        t.beh_dept_name AS deptName,
        t.beh_dept_id AS deptId,
        t.leave_hospital_date AS leaveHospitalDate,
        t.level,
        t.age,
        t.score_res as totalScore,
        t.is_deleted,
        g.check_name AS chName,
        h.check_name AS mrName
        from (
        select a.*, ifnull(b.level,'未评分') as level, IF(c.age is null, null,CONCAT( ifnull(c.age,''),ifnull(c.age_unit,'') ))as age, b.grade_type,d.user_id, b.score_res, b.gmt_create as
        grade_time from med_behospital_info a
        LEFT JOIN med_qcresult_info b
        on a.behospital_code = b.behospital_code and b.is_deleted = 'N'
        left join med_home_page c
        on a.behospital_code = c.behospital_code and c.is_deleted = 'N'
        LEFT JOIN sys_user_dept d
        ON a.hospital_id = d.hospital_id
        AND a.beh_dept_id = d.dept_id
        ) t
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type = 0 ) g
        ON t.behospital_code = g.behospital_code
        AND t.hospital_id = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON t.behospital_code = h.behospital_code
        AND t.hospital_id = h.hospital_id
        where t.is_deleted = 'N'
        AND t.user_id = #{userId}
        <if test="diagnose != null and diagnose != ''">
            AND t.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="deptName != null and deptName != ''">
            and t.beh_dept_name= #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and CONCAT(
            IFNULL(t.doctor_name,''),IFNULL(t.beh_doctor_name,''),IFNULL(t.director_doctor_name,''))
            like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="name != null and name != ''">
            and t.name like CONCAT('%',#{name},'%')
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            and (t.doctor_id = #{doctorCode}
            or t.beh_doctor_id = #{doctorCode}
            or t.director_doctor_id = #{doctorCode})
        </if>
        <if test="fileCode != null and fileCode != ''">
            and t.file_code like CONCAT('%',#{fileCode},'%')
        </if>
        <if test="hospitalId != null">
            and t.hospital_id = #{hospitalId}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and t.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and t.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and t.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and t.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and t.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and t.level = #{level}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and t.is_placefile = #{isPlacefile}
        </if>
        and t.qc_type_id != 0) p
        where p.is_deleted="N"
        <if test="chName != null and chName !=''">
            AND p.chName like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND p.mrName like CONCAT('%',#{mrName},'%')
        </if>
    </select>
   <!-- <select id="getQualityControl" resultType="com.diagbot.dto.QualityControlDTO">
        SELECT m.* FROM(
        SELECT
        a.name AS NAME,
        a.behospital_code AS behospitalCode,
        a.doctor_name AS doctorName,
        a.beh_dept_name AS deptName,
        a.beh_dept_id AS deptId,
        a.leave_hospital_date AS leaveHospitalDate,
        c.behospital_code,
        c.hospital_id,
        c.admissionNote,
        c.firstCourseNote,
        c.medHomePage,
        c.docAdviceNote,
        c.courseRecord,
        c.operationInfo,
        c.dischargeNote,
        c.admissionNoteScore,
        c.firstCourseNoteScore,
        c. medHomePageScore,
        c.docAdviceNoteScore,
        c.courseRecordScore,
        c.operationInfoScore,
        c.dischargeNoteScore,
        c.otherCase,
        (100.0-c.score_res) AS otherCaseScore,
        IFNULL(b.level,'未评分') AS `level`,
        g.check_name AS ch_name,
        h.check_name AS mr_name
        FROM
        med_behospital_info a LEFT JOIN med_qcresult_info b
        ON a.behospital_code = b.behospital_code AND b.is_deleted = 'N'
        LEFT JOIN  (
        SELECT
        t.behospital_code,
        t.hospital_id,
        t.admissionNote,
        t.firstCourseNote,
        t.medHomePage,
        t.docAdviceNote,
        t.courseRecord,
        t.operationInfo,
        t.dischargeNote,
        t.otherCase,
        t.score_res,
        if(t.admissionNoteScoreOn >= t.admissionNoteTolScore, (t.admissionNoteTolScore +  t.admissionNoteScoreTh),(t.admissionNoteScoreOn +  t.admissionNoteScoreTh)) AS admissionNoteScore,
        if(t.firstCourseNoteScoreOn >= t.firstCourseNoteTolScore, (t.firstCourseNoteTolScore +  t.firstCourseNoteScoreTh),(t.firstCourseNoteScoreOn +  t.firstCourseNoteScoreTh)) AS firstCourseNoteScore,
        if(t.medHomePageScoreOn >= t.medHomePageTolScore, (t.medHomePageTolScore +  t.medHomePageScoreTh),(t.medHomePageScoreOn +  t.medHomePageScoreTh)) AS medHomePageScore,
        if(t.docAdviceNoteScoreOn >= t.docAdviceNoteTolScore, (t.docAdviceNoteTolScore +  t.docAdviceNoteScoreTh),(t.docAdviceNoteScoreOn +  t.docAdviceNoteScoreTh)) AS docAdviceNoteScore,
        if(t.courseRecordScoreOn >= t.courseRecordTolScore, (t.courseRecordTolScore +  t.courseRecordScoreTh),(t.courseRecordScoreOn +  t.courseRecordScoreTh)) AS courseRecordScore,
        if(t.operationInfoScoreOn >= t.operationInfoTolScore, (t.operationInfoTolScore +  t.operationInfoScoreTh),(t.operationInfoScoreOn +  t.operationInfoScoreTh)) AS operationInfoScore,
        if(t.dischargeNoteScoreOn >= t.dischargeNoteTolScore, (t.dischargeNoteTolScore +  t.dischargeNoteScoreTh),(t.dischargeNoteScoreOn +  t.dischargeNoteScoreTh)) AS dischargeNoteScore
        from(
        select
         t1.*,
        t2.admissionNoteTolScore,
        t2.firstCourseNoteTolScore,
        t2.medHomePageTolScore,
        t2.docAdviceNoteTolScore,
        t2.courseRecordTolScore,
        t2.operationInfoTolScore,
        t2.dischargeNoteTolScore,
        t2.score_res FROM (
        SELECT
        t1.behospital_code,
        t1.hospital_id,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 1 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS admissionNote,
        SUM(CASE WHEN  t1.mode_id =1  AND t1.is_reject = 0 THEN t1.score ELSE 0 END) AS admissionNoteScoreOn,
        SUM(CASE WHEN  t1.mode_id =1 THEN t1.score ELSE 0 END) AS admissionNoteScoreTw,
        (SUM(CASE WHEN  t1.mode_id =1 THEN t1.score ELSE 0 END)-SUM(CASE WHEN  t1.mode_id =1  AND t1.is_reject = 0 THEN t1.score ELSE 0 END)) AS admissionNoteScoreTh,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 2 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS firstCourseNote,
        SUM(CASE WHEN  t1.mode_id =2 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)  AS firstCourseNoteScoreOn,
        SUM(CASE WHEN  t1.mode_id =2 THEN t1.score ELSE 0 END)  AS firstCourseNoteScoreTw,
        (SUM(CASE WHEN  t1.mode_id =2 THEN t1.score ELSE 0 END) -SUM(CASE WHEN  t1.mode_id =2 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)) AS firstCourseNoteScoreTh,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 6 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS medHomePage,
        SUM(CASE WHEN  t1.mode_id =6 AND t1.is_reject = 0 THEN t1.score ELSE 0 END) AS medHomePageScoreOn,
        SUM(CASE WHEN  t1.mode_id =6 THEN t1.score ELSE 0 END) AS medHomePageScoreTw,
        (SUM(CASE WHEN  t1.mode_id =6 THEN t1.score ELSE 0 END)-SUM(CASE WHEN  t1.mode_id =6 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)) AS medHomePageScoreTh,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 8 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS docAdviceNote,
        SUM(CASE WHEN  t1.mode_id =8 AND t1.is_reject = 0 THEN t1.score ELSE 0 END) AS docAdviceNoteScoreOn,
        SUM(CASE WHEN  t1.mode_id =8 THEN t1.score ELSE 0 END) AS docAdviceNoteScoreTw,
        (SUM(CASE WHEN  t1.mode_id =8 THEN t1.score ELSE 0 END)-SUM(CASE WHEN  t1.mode_id =8 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)) AS docAdviceNoteScoreTh,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 56 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS courseRecord,
        SUM(CASE WHEN  t1.mode_id =56 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)  AS courseRecordScoreOn,
        SUM(CASE WHEN  t1.mode_id =56 THEN t1.score ELSE 0 END)  AS courseRecordScoreTw,
        (SUM(CASE WHEN  t1.mode_id =56 THEN t1.score ELSE 0 END)-SUM(CASE WHEN  t1.mode_id =56 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)) AS courseRecordScoreTh,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 17 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS operationInfo,
        SUM(CASE WHEN  t1.mode_id =17 AND t1.is_reject = 0 THEN t1.score ELSE 0 END) AS operationInfoScoreOn,
        SUM(CASE WHEN  t1.mode_id =17  THEN t1.score ELSE 0 END) AS operationInfoScoreTw,
        (SUM(CASE WHEN  t1.mode_id =17  THEN t1.score ELSE 0 END)-SUM(CASE WHEN  t1.mode_id =17 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)) AS operationInfoScoreTh,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 5 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS dischargeNote,
        SUM(CASE WHEN  t1.mode_id =5 AND t1.is_reject = 0 THEN t1.score ELSE 0 END)  AS dischargeNoteScoreOn,
        SUM(CASE WHEN  t1.mode_id =5 THEN t1.score ELSE 0 END)  AS dischargeNoteScoreTw,
        (SUM(CASE WHEN  t1.mode_id =5 THEN t1.score ELSE 0 END)-GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id = 5 THEN t1.msg ELSE NULL END SEPARATOR ';' )) AS dischargeNoteScoreTh,
        GROUP_CONCAT(DISTINCT CASE WHEN t1.mode_id != 1 AND t1.mode_id !=  2 AND t1.mode_id !=  6 AND t1.mode_id != 8 AND t1.mode_id != 156 AND t1.mode_id != 17 AND t1.mode_id != 5 THEN t1.msg ELSE NULL END SEPARATOR ';' ) AS otherCase
        FROM (
        SELECT
        c.behospital_code,
        c.hospital_id,
        a.mode_id,
        c.cases_score,
        c.score,
        c.msg,
        c.is_reject,
        c.cases_id
        FROM
        `qc_cases_entry` a,
        qc_mode b,
        med_qcresult_detail c,
        qc_cases_hospital d,
        med_behospital_info e
        WHERE a.is_deleted = 'N' AND b.is_deleted = 'N' AND c.is_deleted = 'N' AND d.is_deleted = 'N'AND e.is_deleted = 'N'
        AND a.id = c.cases_entry_id
        AND a.mode_id = b.id
        AND c.cases_id = d.cases_id
        AND c.hospital_id = d.hospital_id
        AND c.behospital_code = e.behospital_code
        AND c.hospital_id = e.hospital_id
        <if test="hospitalId != null">
            and c.hospital_id = #{hospitalId}
        </if>
        <if test="deptName != null and deptName != ''">
            and e.beh_dept_name= #{deptName}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and e.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and e.is_placefile = #{isPlacefile}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and e.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and e.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and e.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and e.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and e.level = #{level}
        </if>
        <if test="level != null and level != ''">
            and e.level = #{level}
        </if>
        ORDER BY b.order_no, c.grade_type DESC, a.order_no
        )t1 GROUP BY behospital_code)t1
        LEFT JOIN (
        SELECT m1.*, m2.score_res FROM(
        SELECT
        m1.hospital_id,
        m1.behospital_code,
        SUM(CASE WHEN  m1.mode_id =1 THEN m1.cases_score ELSE 0 END) AS admissionNoteTolScore,
        SUM(CASE WHEN  m1.mode_id =2 THEN m1.cases_score ELSE 0 END) AS firstCourseNoteTolScore,
        SUM(CASE WHEN  m1.mode_id =6 THEN m1.cases_score ELSE 0 END) AS medHomePageTolScore,
        SUM(CASE WHEN  m1.mode_id =8 THEN m1.cases_score ELSE 0 END) AS docAdviceNoteTolScore,
        SUM(CASE WHEN  m1.mode_id =56 THEN m1.cases_score ELSE 0 END) AS courseRecordTolScore,
        SUM(CASE WHEN  m1.mode_id =17 THEN m1.cases_score ELSE 0 END) AS operationInfoTolScore,
        SUM(CASE WHEN  m1.mode_id =5 THEN m1.cases_score ELSE 0 END) AS dischargeNoteTolScore
        FROM (
        SELECT
        c.behospital_code,
        a.mode_id,
        c.cases_score,
        c.cases_id,
        c.hospital_id
        FROM
        `qc_cases_entry` a,
        qc_mode b,
        med_qcresult_detail c,
        qc_cases_hospital d,
        med_behospital_info e
        WHERE a.is_deleted = 'N' AND b.is_deleted = 'N' AND c.is_deleted = 'N' AND d.is_deleted = 'N'AND e.is_deleted = 'N'
        AND a.id = c.cases_entry_id
        AND a.mode_id = b.id
        AND c.cases_id = d.cases_id
        AND c.hospital_id = d.hospital_id
        AND c.behospital_code = e.behospital_code
        AND c.hospital_id = e.hospital_id
        <if test="hospitalId != null">
            and c.hospital_id = #{hospitalId}
        </if>
        <if test="deptName != null and deptName != ''">
            and e.beh_dept_name= #{deptName}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and e.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and e.is_placefile = #{isPlacefile}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and e.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and e.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and e.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and e.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and e.level = #{level}
        </if>
        <if test="level != null and level != ''">
            and e.level = #{level}
        </if>
        GROUP BY mode_id
        ORDER BY b.order_no, c.grade_type DESC, a.order_no
        )m1  GROUP BY  behospital_code)m1 LEFT JOIN  med_qcresult_info m2
        ON m2.is_deleted = 'N'
        AND m1.hospital_id = m2.hospital_id
        AND m1.behospital_code = m2.behospital_code
        )t2
        ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code)t)c
        ON a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type = 0 ) g
        ON a.behospital_code = g.behospital_code
        AND a.hospital_id = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON a.behospital_code = h.behospital_code
        AND a.hospital_id = h.hospital_id
        where
        a.is_deleted = 'N'
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name= #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and CONCAT(
            IFNULL(a.doctor_name,''),IFNULL(a.beh_doctor_name,''),IFNULL(a.director_doctor_name,''))
            like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="name != null and name != ''">
            and a.name like CONCAT('%',#{name},'%')
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            and (a.doctor_id = #{doctorCode}
            or a.beh_doctor_id = #{doctorCode}
            or a.director_doctor_id = #{doctorCode})
        </if>
        <if test="fileCode != null and fileCode != ''">
            and a.file_code like CONCAT('%',#{fileCode},'%')
        </if>
        <if test="hospitalId != null">
            and a.hospital_id = #{hospitalId}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and a.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and a.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and a.level = #{level}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        and a.qc_type_id != 0
        <if test="chName != null and chName !=''">
            AND g.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND h.mr_name like CONCAT('%',#{mrName},'%')
        </if>)m

    </select>-->

    <select id="getMsg" resultType="com.diagbot.dto.MsgDTO">
        SELECT a.*, u.linkman
        FROM
        (
        SELECT DISTINCT b.`name` model_name,c.score,c.msg,c.cases_entry_id,c.is_reject,c.id id,c.info, a.cases_id cases_id, d.score cases_score,
        b.id model_id, a.name standard_msg, c.opt_type, c.grade_type,
         c.gmt_create, c.gmt_modified, c.modifier,c.is_deleted,c.explain_info as explainInfo,
        a.type, a.drgs
        FROM
        `qc_cases_entry` a, qc_mode b, med_qcresult_detail c, qc_cases_hospital d
        where a.is_deleted = 'N' and b.is_deleted = 'N' and d.is_deleted = 'N'
        and a.id = c.cases_entry_id and a.mode_id = b.id
        AND c.cases_id = d.cases_id and c.hospital_id = d.hospital_id
        and c.hospital_id = #{hospitalId}
        and c.behospital_code = #{behospitalCode}
        order by b.order_no, c.grade_type desc, a.order_no) a
        LEFT JOIN sys_user u  on u.id = a.modifier  and u.is_deleted = 'N'
    </select>




    <select id="getMsgByEntryCode" resultType="com.diagbot.dto.MsgDTO">
        SELECT b.id model_id,b.`name` model_name,
        d.score,d.msg,d.cases_entry_id,d.is_reject,
        a.cases_id cases_id, a.name standard_msg,a.code
        FROM `qc_cases_entry` a, qc_mode b, qc_cases_entry_hospital d
        where a.is_deleted = 'N' and b.is_deleted = 'N' and d.is_deleted = 'N'
        and a.mode_id = b.id
        and a.id = d.cases_entry_id
        and d.is_used = 1
        and d.hospital_id = #{hospitalId}
        and a.code in
        <foreach collection="codeList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="modeId != null">
            and a.mode_id = #{modeId}
        </if>
        order by b.order_no, a.order_no;
    </select>

    <!--病案管理指标基础sql明细-->
    <select id="getBaseIndex"  parameterType="com.diagbot.vo.MedIndexFilterVO" resultType="java.util.Map">
        select
        f1.firWorkNum,
        f2.secWorkNum,
        f3.thrWorkNum,
        f3.forWorkNum,
        f3.sixWorkNum
        from (
        SELECT count(DISTINCT a.behospital_code)  as firWorkNum
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        AND a.is_placefile = 1
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="startDate != null and startDate != ''">
            <![CDATA[ AND a.leave_hospital_date >= #{lastStartDate}]]>
        </if>
        <if test="endDate != null and endDate != ''">
            <![CDATA[ AND a.leave_hospital_date <= #{lastEndDate}]]>
        </if>)f1,
            ( SELECT count(DISTINCT a.behospital_code) AS secWorkNum
        FROM
        med_outpatient_info a
        WHERE
        a.is_deleted = 'N'
        <if test="startDate != null and startDate != ''">
            <![CDATA[ AND a.visit_date >= #{lastStartDate}]]>
        </if>
        <if test="endDate != null and endDate != ''">
            <![CDATA[ AND a.visit_date <= #{lastEndDate}]]>
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>)f2,(
           select
        count(DISTINCT case when  <![CDATA[m.behospital_date >= #{startDate}]]>  and  <![CDATA[m.behospital_date <= #{endDate}]]>
        and m.is_placefile = 0 then m.behospital_code else null end) as thrWorkNum,
        count(DISTINCT case when  <![CDATA[m.leave_hospital_date >= #{startDate}]]>  and  <![CDATA[m.leave_hospital_date <= #{endDate}]]>  and m.is_placefile = 1 then m.behospital_code else null end) as forWorkNum,
        count(DISTINCT case when  <![CDATA[m.leave_hospital_date >= #{startDate}]]> and <![CDATA[m.leave_hospital_date <= #{endDate}]]> and m.is_placefile = 1 and m.level = '甲' then m.behospital_code else null end) as sixWorkNum
           from(
           SELECT DISTINCT a.*,b.level
            FROM
            med_behospital_info a,
            med_qcresult_info b
            WHERE
            a.is_deleted = 'N'
            AND b.is_deleted = 'N'
            AND a.hospital_id = b.hospital_id
            AND a.behospital_code = b.behospital_code
            <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>)m
            )f3
    </select>

    <!-- 病案管理规则质控缺陷病历总数查询-->
    <select id="getMedManageParams"  parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.MedManageParamsDTO">
        SELECT
        f1.behospitalCode,
        <if test="flagStr != null and flagStr == 1 ">
        f2.rep_name as repName,
        </if>
        <if test="flagStr != null and flagStr == 2">
        f3.da_item_name as daItemName,
        f3.da_status AS daStatus,
        f3.doctor_advice_type as doctorAdviceType,
        </if>
        <if test="flagStr != null and flagStr == 4 ">
            f5.content as content,
            f5.rec_title as recTitle,
        </if>
        f1.hospitalId
        from(
        SELECT DISTINCT
        a.hospital_id as hospitalId,
        a.behospital_code as behospitalCode
        FROM
        med_behospital_info a,
        med_qcresult_info b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND <![CDATA[a.leave_hospital_date >= #{startDate}]]>
        AND  <![CDATA[a.leave_hospital_date <= #{endDate}]]>
        AND  a.is_placefile = 1
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>)f1
        <if test="flagStr != null and flagStr == 1 ">
             join med_lis_info f2
            on  f2.is_deleted = 'N'
            AND f1.hospitalId = f2.hospital_id
            AND f1.behospitalCode = f2.behospital_code
        </if>
        <if test="flagStr != null and flagStr == 2">
            join  med_doctor_advice f3
        on  f3.is_deleted = 'N'
        AND f1.hospitalId = f3.hospital_id
        AND f1.behospitalCode = f3.behospital_code
        </if>
        <if test="flagStr != null and flagStr == 3">
            join  med_qcresult_detail f4
            on  f4.is_deleted = 'N'
            AND f1.hospitalId = f4.hospital_id
            AND f1.behospitalCode = f4.behospital_code
            AND f4.is_reject = 1
        </if>
        <if test="flagStr != null and flagStr == 4">
            join  str_informed_consent f5
            on  f5.is_deleted = 'N'
            AND f1.hospitalId = f5.hospital_id
            AND f1.behospitalCode = f5.behospital_code
        </if>
    </select>


    <!-- 各科室缺陷占比-全院-首页 -->
    <select id="entryByDept" parameterType="com.diagbot.vo.FilterVO"
            resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.beh_dept_id as id,
        a.beh_dept_name as name,
        count(*) AS num
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d
        WHERE
        a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.hospital_id = d.hospital_id
        AND a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ORDER BY
        count(*) DESC
    </select>

    <!-- 质控结果缺陷总数查询-->
    <select id="getTotleResultNum" parameterType="com.diagbot.vo.FilterVO" resultType="int">
        SELECT
        count(*) AS totle
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d
        WHERE
        a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.hospital_id = d.hospital_id
        AND a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
    </select>

    <!--获取病历-->
    <select id="getNoGrade" resultMap="BaseResultMap">
        select * from med_behospital_info a
        where a.is_deleted = 'N'
        and a.qc_type_id != 0
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="filterFlag != null and filterFlag == 0">
            and
            not EXISTS (
            SELECT
            1
            FROM
            med_qcresult_info b
            WHERE
            b.is_deleted = 'N'
            AND a.hospital_id = b.hospital_id
            AND a.behospital_code = b.behospital_code
            )
        </if>
        <if test="leaveDate != null">
            <![CDATA[ and a.leave_hospital_date < #{leaveDate}]]>
        </if>
        <if test="hosptialIdList != null and hosptialIdList.size > 0 ">
            and a.hospital_id in
            <foreach collection="hosptialIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="behospitalCodeList != null and behospitalCodeList.size > 0 ">
            and a.behospital_code in
            <foreach collection="behospitalCodeList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="individuation != null and individuation.contains(1)">
            union
            select * from med_behospital_info b
            where b.is_deleted = 'N'
            and b.qc_type_id != 0
            <if test="isPlacefile != null and isPlacefile != ''">
                and b.is_placefile = #{isPlacefile}
            </if>
            <if test="startLeaveDate != null">
                <![CDATA[ and b.leave_hospital_date >= #{startLeaveDate}]]>
            </if>
            <if test="endLeaveDate != null">
                <![CDATA[ and b.leave_hospital_date <= #{endLeaveDate}]]>
            </if>
            <if test="hosptialIdList != null and hosptialIdList.size > 0 ">
                and b.hospital_id in
                <foreach collection="hosptialIdList" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </if>
    </select>

    <!--质控评分(科室)分页-->
    <select id="getPageByDept" resultType="com.diagbot.dto.BehospitalInfoDTO">
        SELECT * from (
        SELECT
        t.*,
        CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type as ch_type,
        h.check_type AS mr_type,
        g.check_name as ch_name,
        h.check_name as mr_name,
        g.check_time as ch_time,
        h.check_time AS mr_time
        FROM
        ( SELECT
        a.*,
        IFNULL(b.level, '未评分') AS `level`,
        b.grade_type,
        b.score_res,
        e.score_res as score_bn,
        b.gmt_create AS grade_time,
        CONCAT( ifnull(c.age,'') ,ifnull(c.age_unit,'') )as age
        FROM
        med_behospital_info a
        JOIN sys_user_dept d
        ON a.hospital_id = d.hospital_id
        AND a.beh_dept_id = d.dept_id
        LEFT JOIN med_qcresult_info b
        ON a.behospital_code = b.behospital_code
        AND b.is_deleted = 'N'
        LEFT JOIN med_qcresult_cases e
        on  a.behospital_code = e.behospital_code
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        LEFT JOIN med_home_page c
        ON a.behospital_code = c.behospital_code
        AND c.is_deleted = 'N'
        WHERE d.is_deleted = 'N'
        AND d.user_id = #{userId}
        ) t
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type in(0,2) ) g
        ON t.behospital_code = g.behospital_code
        AND t.hospital_id = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON t.behospital_code = h.behospital_code
        AND t.hospital_id = h.hospital_id
        where t.is_deleted = 'N'
        <if test="diagnose != null and diagnose != ''">
            AND t.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="deptName != null and deptName != ''">
            and t.beh_dept_name = #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and CONCAT(
            IFNULL(t.doctor_name,''),IFNULL(t.beh_doctor_name,''),IFNULL(t.director_doctor_name,''))
            like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            and (t.doctor_id = #{doctorCode}
            or t.beh_doctor_id = #{doctorCode}
            or t.director_doctor_id = #{doctorCode})
        </if>
        <if test="name != null and name != ''">
            and t.name like CONCAT('%',#{name},'%')
        </if>
        <if test="fileCode != null and fileCode != ''">
            and t.file_code like CONCAT('%',#{fileCode},'%')
        </if>
        <if test="hospitalId != null">
            and t.hospital_id = #{hospitalId}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and t.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and t.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and t.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and t.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and t.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and t.level = #{level}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and t.is_placefile = #{isPlacefile}
        </if>
        and t.qc_type_id != 0) p
        where p.is_deleted="N"
        <if test="checkStatus != null ">
            and p.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND p.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND p.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND p.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and p.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and p.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and p.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and p.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>

    <!--质控评分(个人)分页-->
    <select id="getPageByPerson" resultType="com.diagbot.dto.BehospitalInfoDTO">
        Select * from (
        select t.*,
        CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type as ch_type,
        h.check_type AS mr_type,
        g.check_name as ch_name,
        h.check_name as mr_name,
        g.check_time as ch_time,
        h.check_time AS mr_time
        from (SELECT
        a.*,
        IFNULL(b.level, '未评分') AS `level`,
        b.grade_type,
        b.score_res,
        e.score_res as score_bn,
        b.gmt_create AS grade_time,
        CONCAT( ifnull(c.age,'') ,ifnull(c.age_unit,'') )as age
        FROM
        med_behospital_info a
        JOIN
        (SELECT
        u.id,
        u.linkman AS linkman,
        uh.hospital_id
        FROM
        sys_user u
        JOIN sys_user_hospital uh
        ON u.id = uh.user_id
        WHERE u.is_deleted = "N"
        AND u.id = #{userId}
        AND uh.hospital_id = #{hospitalId}) u1
        ON a.hospital_id = u1.hospital_id
        LEFT JOIN med_qcresult_info b
        ON a.behospital_code = b.behospital_code
        AND b.is_deleted = 'N'
        LEFT JOIN med_qcresult_cases e
        on  a.behospital_code = e.behospital_code
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        LEFT JOIN med_home_page c
        ON a.behospital_code = c.behospital_code
        AND c.is_deleted = 'N'
        WHERE
        a.is_deleted = 'N'
        and  a.doctor_name = u1.linkman
        or   a.beh_doctor_name = u1.linkman
        or   a.director_doctor_name =  u1.linkman
        ) t
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type in(0,2) ) g
        ON t.behospital_code = g.behospital_code
        AND t.hospital_id = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON t.behospital_code = h.behospital_code
        AND t.hospital_id = h.hospital_id
        WHERE t.is_deleted = 'N'
        <if test="diagnose != null and diagnose != ''">
            AND t.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="deptName != null and deptName != ''">
            and t.beh_dept_name = #{deptName}
        </if>
        <if test="name != null and name != ''">
            and t.name like CONCAT('%',#{name},'%')
        </if>
        <if test="fileCode != null and fileCode != ''">
            and t.file_code like CONCAT('%',#{fileCode},'%')
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and t.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and t.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and t.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and t.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and t.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and t.level = #{level}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and t.is_placefile = #{isPlacefile}
        </if>
        and t.qc_type_id != 0) p
        where p.is_deleted="N"
        <if test="checkStatus != null ">
            and p.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND p.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND p.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND p.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and p.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and p.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and p.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and p.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>

    <!--质控评分(医疗组)分页-->
    <select id="getPageByGroup" resultType="com.diagbot.dto.BehospitalInfoDTO">
        select * from (
        select t.*,
        CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type as ch_type,
        h.check_type AS mr_type,
        g.check_name as ch_name,
        h.check_name as mr_name,
        g.check_time as ch_time,
        h.check_time AS mr_time
        from (
        select a.*, ifnull(b.level,'未评分') as `level`, b.grade_type, b.score_res, b.gmt_create as
        grade_time,CONCAT( ifnull(c.age,'') ,ifnull(c.age_unit,'') )as age, e.score_res as score_bn from med_behospital_info a
        LEFT JOIN med_qcresult_info b
        on a.behospital_code = b.behospital_code and b.is_deleted = 'N'
        LEFT JOIN med_qcresult_cases e
        on  a.behospital_code = e.behospital_code
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        left join med_home_page c
        on a.behospital_code = c.behospital_code and c.is_deleted = 'N'
        ) t
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type in(0,2) ) g
        ON t.behospital_code = g.behospital_code
        AND t.hospital_id = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON t.behospital_code = h.behospital_code
        AND t.hospital_id = h.hospital_id
        WHERE t.is_deleted = 'N'
        and
        t.doctor_id in (
        SELECT doctor_id FROM `bas_doctor_info`
        where is_deleted = 'N' and hospital_id = #{hospitalId} and group_id in (
        select c3.group_id from sys_user c1, sys_user_hospital c2, bas_doctor_info c3
        where c1.is_deleted = 'N' and c2.is_deleted = 'N' and c3.is_deleted = 'N'
        and c1.id = c2.user_id and c2.hospital_id = c3.hospital_id
        and c1.username = c3.doctor_id
        and c2.hospital_id = #{hospitalId}
        and c1.id = #{userId}
        )
        )
        <if test="diagnose != null and diagnose != ''">
            AND t.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="doctorName != null and doctorName != ''">
            and (t.doctor_name like CONCAT('%',#{doctorName},'%')
            or t.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            or t.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="name != null and name != ''">
            and t.name like CONCAT('%',#{name},'%')
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            and (t.doctor_id = #{doctorCode}
            or t.beh_doctor_id = #{doctorCode}
            or t.director_doctor_id = #{doctorCode})
        </if>
        <if test="fileCode != null and fileCode != ''">
            and t.file_code like CONCAT('%',#{fileCode},'%')
        </if>
        <if test="hospitalId != null">
            and t.hospital_id = #{hospitalId}
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            and t.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and t.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and t.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null">
            <![CDATA[ and t.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null">
            <![CDATA[ and t.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="level != null and level != ''">
            and t.level = #{level}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and t.is_placefile = #{isPlacefile}
        </if>
        and t.qc_type_id != 0) p
        where p.is_deleted="N"
        <if test="checkStatus != null ">
            and p.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND p.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND p.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND p.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and p.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and p.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and p.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and p.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>

    <!-- 出院总人数统计-全院-首页 -->
    <select id="leaveHosCount" parameterType="com.diagbot.vo.FilterVO" resultType="int">
        SELECT
        COUNT(*)
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
    </select>

    <!-- 新生儿出院人数统计-全院-首页 -->
    <select id="newBornCount" parameterType="com.diagbot.vo.FilterVO" resultType="int">
        SELECT
        COUNT(*)
        FROM
        med_behospital_info a,
        med_home_page b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND (
        ( IFNULL( b.newborn_day, '' ) != '' AND b.newborn_day != '0' AND b.newborn_day != '-' AND b.newborn_day != '—')
        OR ( IFNULL( b.newborn_month, '' )!= '' AND b.newborn_month != '0' AND b.newborn_month != '-' AND b.newborn_month != '—')
        )
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
    </select>

    <!-- 死亡人数统计-全院-首页 -->
    <select id="deathCount" parameterType="com.diagbot.vo.FilterVO" resultType="int">
        select COUNT(*) from(
        SELECT distinct a.*
        FROM
        med_behospital_info a,
        med_medical_record b,
        med_medical_record_content c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND b.rec_id = c.rec_id
        and b.mode_id = '24'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>)m
    </select>

    <!-- 手术人数统计-全院-首页 -->
    <select id="operationCount" parameterType="com.diagbot.vo.FilterVO" resultType="int">
        SELECT
        COUNT( DISTINCT a.behospital_code )
        FROM
        med_behospital_info a,
        med_medical_record c,
        qc_mode d
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND c.mode_id = d.id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND d.`name` = '手术记录'
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
    </select>

    <!-- 入院人数统计-首页 -->
    <select id="beHosCount" parameterType="com.diagbot.vo.FilterVO"
            resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.beh_dept_id AS id,
        a.beh_dept_name AS NAME,
        COUNT(*) AS num
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
    </select>

    <!-- 出院总人数统计-科室-首页 -->
    <select id="leaveHosCountByDept" parameterType="com.diagbot.vo.FilterVO"
            resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.beh_dept_id AS id,
        a.beh_dept_name AS NAME,
        COUNT(*) AS num
        FROM
        med_behospital_info a,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.beh_dept_id = c.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
    </select>

    <!-- 入院总人数统计-科室-首页 -->
    <select id="admissionHosCountByDept" parameterType="com.diagbot.vo.FilterVO"
            resultType="com.diagbot.dto.AdmissionCountDTO">
        SELECT
        a.beh_dept_id as deptId,
        a.beh_dept_name as deptName,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName,
        COUNT(*) AS num
        FROM
        med_behospital_info a,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.beh_dept_id = c.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name,
        a.doctor_id,
        a.doctor_name
    </select>

    <!-- 新生儿出院人数统计-科室-首页 -->
    <select id="newBornCountByDept" parameterType="com.diagbot.vo.FilterVO"
            resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.beh_dept_id AS id,
        a.beh_dept_name AS NAME,
        COUNT(*) AS num
        FROM
        med_behospital_info a,
        med_home_page b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.beh_dept_id = c.dept_id
        AND (
        ( IFNULL( b.newborn_day, '' ) != '' AND b.newborn_day != '0' AND b.newborn_day != '-'AND b.newborn_day != '—' )
        OR ( IFNULL( b.newborn_month, '' )!= '' AND b.newborn_month != '0' AND b.newborn_month != '-' AND b.newborn_month != '—')
        )
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
    </select>

    <!-- 死亡人数统计-科室-首页 -->
    <select id="deathCountByDept" parameterType="com.diagbot.vo.FilterVO"
            resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.beh_dept_id AS id,
        a.beh_dept_name AS NAME,
        COUNT(*) AS num
        FROM
        med_behospital_info a,
        sys_user_dept c,
        med_medical_record d,
        med_medical_record_content e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.beh_dept_id = c.dept_id
        AND d.rec_id = e.rec_id
        AND d.mode_id = '24'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
    </select>

    <!-- 手术人数统计-科室-首页 -->
    <select id="operationCountByDept" parameterType="com.diagbot.vo.FilterVO"
            resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.beh_dept_id AS id,
        a.beh_dept_name AS NAME,
        COUNT( DISTINCT a.behospital_code ) AS num
        FROM
        med_behospital_info a,
        sys_user_dept c,
        med_medical_record d,
        qc_mode e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.beh_dept_id = c.dept_id
        AND d.mode_id = e.id
        AND e.`name` = '手术记录'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
    </select>

    <!-- 各科室缺陷占比排行（分页） -->
    <select id="resultStatisticsByDeptPage" resultType="com.diagbot.dto.NumDTO">
        SELECT t.*
        FROM
        (SELECT
        t1.beh_dept_name AS NAME,
        t1.num AS num,
        t2.totle AS totleNum,
        round( t1.num / t2.totle, 4 ) AS percent,
        concat( round( t1.num / t2.totle * 100, 2 ), '%' ) AS percentStr
        FROM
        (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        count(*) AS num
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d
        WHERE
        a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.hospital_id = d.hospital_id
        AND a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile != ''">
            and a.is_placefile = #{filterPageVO.isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="filterPageVO.hospitalId != null and filterPageVO.hospitalId != ''">
            AND a.hospital_id = #{filterPageVO.hospitalId}
        </if>
        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 0">
            <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{filterPageVO.startDate}]]>
            </if>
            <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{filterPageVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 1">
            <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{filterPageVO.startDate}]]>
            </if>
            <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{filterPageVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageVO.name != null and filterPageVO.name != ''">
            AND a.beh_dept_name like CONCAT('%', #{filterPageVO.name},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ORDER BY
        count(*) DESC
        ) t1,
        (
        SELECT
        count(*) AS totle
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d
        WHERE
        a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.hospital_id = d.hospital_id
        AND a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile != ''">
            and a.is_placefile = #{filterPageVO.isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="filterPageVO.hospitalId != null and filterPageVO.hospitalId != ''">
            AND a.hospital_id = #{filterPageVO.hospitalId}
        </if>
        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 0">
            <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{filterPageVO.startDate}]]>
            </if>
            <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{filterPageVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 1">
            <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{filterPageVO.startDate}]]>
            </if>
            <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{filterPageVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageVO.name != null and filterPageVO.name != ''">
            AND a.beh_dept_name like CONCAT('%', #{filterPageVO.name},'%')
        </if>
        ) t2
        )t
    </select>

    <!-- 科室缺陷占比（主任医生） -->
    <select id="resultStatisticsByDeptAndDoctorPage" resultType="com.diagbot.dto.DeptNumDTO">
        SELECT
        t.*
        FROM
        (
        SELECT
        t1.NAME,
        t1.num AS num,
        t2.totle AS totleNum,
        round( t1.num / t2.totle, 4 ) AS percent,
        concat( round( t1.num / t2.totle * 100, 2 ), '%' ) AS percentStr
        FROM
        (
        SELECT
        d.msg as name,
        count(*) AS num
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        sys_user_dept e
        WHERE
        a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.hospital_id = d.hospital_id
        AND a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.beh_dept_id = e.dept_id
        <if test="filterPageByDeptVO.isPlacefile != null and filterPageByDeptVO.isPlacefile != ''">
            and a.is_placefile = #{filterPageByDeptVO.isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="filterPageByDeptVO.userId!=null">
            AND e.user_id = #{filterPageByDeptVO.userId}
        </if>
        <if test="filterPageByDeptVO.hospitalId != null and filterPageByDeptVO.hospitalId != ''">
            AND a.hospital_id = #{filterPageByDeptVO.hospitalId}
        </if>
        <if test="filterPageByDeptVO.isPlacefile != null and filterPageByDeptVO.isPlacefile == 0">
            <if test="filterPageByDeptVO.startDate != null and filterPageByDeptVO.startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{filterPageByDeptVO.startDate}]]>
            </if>
            <if test="filterPageByDeptVO.endDate != null and filterPageByDeptVO.endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{filterPageByDeptVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageByDeptVO.isPlacefile != null and filterPageByDeptVO.isPlacefile == 1">
            <if test="filterPageByDeptVO.startDate != null and filterPageByDeptVO.startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{filterPageByDeptVO.startDate}]]>
            </if>
            <if test="filterPageByDeptVO.endDate != null and filterPageByDeptVO.endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{filterPageByDeptVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageByDeptVO.name != null and filterPageByDeptVO.name != ''">
            AND d.msg like CONCAT('%', #{filterPageByDeptVO.name},'%')
        </if>
        <if test="filterPageByDeptVO.doctorName != null and filterPageByDeptVO.doctorName != ''">
            AND a.doctor_name = #{filterPageByDeptVO.doctorName}
        </if>
        <if test="filterPageByDeptVO.deptName != null and filterPageByDeptVO.deptName != ''">
            AND a.beh_dept_name = #{filterPageByDeptVO.deptName}
        </if>
        GROUP BY
        d.msg
        ORDER BY
        count(*) DESC
        ) t1,
        (
        SELECT
        count(*) AS totle
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        sys_user_dept e
        WHERE
        a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = d.behospital_code
        AND a.hospital_id = d.hospital_id
        AND a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.beh_dept_id = e.dept_id
        <if test="filterPageByDeptVO.isPlacefile != null and filterPageByDeptVO.isPlacefile != ''">
            and a.is_placefile = #{filterPageByDeptVO.isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="filterPageByDeptVO.userId!=null">
            AND e.user_id = #{filterPageByDeptVO.userId}
        </if>
        <if test="filterPageByDeptVO.hospitalId != null and filterPageByDeptVO.hospitalId != ''">
            AND a.hospital_id = #{filterPageByDeptVO.hospitalId}
        </if>
        <if test="filterPageByDeptVO.isPlacefile != null and filterPageByDeptVO.isPlacefile == 0">
            <if test="filterPageByDeptVO.startDate != null and filterPageByDeptVO.startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{filterPageByDeptVO.startDate}]]>
            </if>
            <if test="filterPageByDeptVO.endDate != null and filterPageByDeptVO.endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{filterPageByDeptVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageByDeptVO.isPlacefile != null and filterPageByDeptVO.isPlacefile == 1">
            <if test="filterPageByDeptVO.startDate != null and filterPageByDeptVO.startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{filterPageByDeptVO.startDate}]]>
            </if>
            <if test="filterPageByDeptVO.endDate != null and filterPageByDeptVO.endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{filterPageByDeptVO.endDate}]]>
            </if>
        </if>
        <if test="filterPageByDeptVO.name != null and filterPageByDeptVO.name != ''">
            AND d.msg like CONCAT('%', #{filterPageByDeptVO.name},'%')
        </if>
        <if test="filterPageByDeptVO.doctorName != null and filterPageByDeptVO.doctorName != ''">
            AND a.doctor_name = #{filterPageByDeptVO.doctorName}
        </if>
        <if test="filterPageByDeptVO.deptName != null and filterPageByDeptVO.deptName != ''">
            AND a.beh_dept_name = #{filterPageByDeptVO.deptName}
        </if>
        ) t2
        )t
    </select>

    <!-- 各科室缺陷占比（组合）-全院 -->
    <select id="levelStatistics" parameterType="com.diagbot.vo.FilterOrderVO"
            resultType="com.diagbot.dto.LevelStatisticsDTO">
        SELECT
        m1.deptId,
        m1.deptName,
        m1.entryNum,
        m2.sameNum,
        m1.mrNum,
        m2.sameMrNum,
        m1.totleValue,
        m2.sameTotleValue,
        m1.averageValue,
        m2.sameAvgValue,
        m1.firstLevelNum,
        m2.sameFirstLevelNum,
        m1.secondLevelNum,
        m2.sameSecondLevelNum,
        m1.thirdLevelNum,
        m2.sameThirdLevelNum,
        m1.firstLevelPercent,
        m2.sameFirstLevelPercent,
        m1.secondLevelPercent,
        m2.sameSecondLevelPercent,
        m1.thirdLevelPercent,
        m2.sameThirdLevelPercent,
        m1.firstLevelPercentStr,
        m2.sameFirstLevelPercentStr,
        m1.secondLevelPercentStr,
        m2.sameSecondLevelPercentStr,
        m1.thirdLevelPercentStr,
        m2.sameThirdLevelPercentStr
        FROM
        (
        SELECT
        t1.deptId,
        t1.deptName,
        t2.entryNum,
        t1.mrNum,
        t1.totleValue,
        t1.averageValue,
        t1.firstLevelNum,
        t1.secondLevelNum,
        t1.thirdLevelNum,
        t1.firstLevelPercent,
        t1.secondLevelPercent,
        t1.thirdLevelPercent,
        t1.firstLevelPercentStr,
        t1.secondLevelPercentStr,
        t1.thirdLevelPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        count(*) AS mrNum,
        ROUND( sum( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        SUM( c.`level` = '甲' ) AS firstLevelNum,
        SUM( c.`level` = '乙' ) AS secondLevelNum,
        SUM( c.`level` = '丙' ) AS thirdLevelNum,
        ROUND( SUM( c.`level` = '甲' )/ count(*), 4 ) AS firstLevelPercent,
        ROUND( SUM( c.`level` = '乙' )/ count(*), 4 ) AS secondLevelPercent,
        ROUND( SUM( c.`level` = '丙' )/ count(*), 4 ) AS thirdLevelPercent,
        concat( ROUND( SUM( c.`level` = '甲' )/ count(*)* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '乙' )/ count(*)* 100, 2 ), '%' ) AS secondLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '丙' )/ count(*)* 100, 2 ), '%' ) AS thirdLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_info c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t1,
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        count( * ) AS entryNum
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        qc_cases_entry e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t2
        WHERE
        t1.deptId = t2.deptId
        AND t1.deptName = t2.deptName)m1 left join
        ( SELECT
        t1.deptId,
        t1.deptName,
        t2.entryNum as sameNum,
        t1.mrNum as sameMrNum,
        t1.totleValue as  sameTotleValue,
        t1.averageValue as sameAvgValue,
        t1.firstLevelNum as sameFirstLevelNum,
        t1.secondLevelNum as sameSecondLevelNum,
        t1.thirdLevelNum as sameThirdLevelNum,
        t1.firstLevelPercent as sameFirstLevelPercent,
        t1.secondLevelPercent as sameSecondLevelPercent,
        t1.thirdLevelPercent as sameThirdLevelPercent,
        t1.firstLevelPercentStr as sameFirstLevelPercentStr,
        t1.secondLevelPercentStr as sameSecondLevelPercentStr,
        t1.thirdLevelPercentStr as sameThirdLevelPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        count(*) AS mrNum,
        ROUND( sum( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        SUM( c.`level` = '甲' ) AS firstLevelNum,
        SUM( c.`level` = '乙' ) AS secondLevelNum,
        SUM( c.`level` = '丙' ) AS thirdLevelNum,
        ROUND( SUM( c.`level` = '甲' )/ count(*), 4 ) AS firstLevelPercent,
        ROUND( SUM( c.`level` = '乙' )/ count(*), 4 ) AS secondLevelPercent,
        ROUND( SUM( c.`level` = '丙' )/ count(*), 4 ) AS thirdLevelPercent,
        concat( ROUND( SUM( c.`level` = '甲' )/ count(*)* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '乙' )/ count(*)* 100, 2 ), '%' ) AS secondLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '丙' )/ count(*)* 100, 2 ), '%' ) AS thirdLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_info c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.behospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.behospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t1,
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        count( * ) AS entryNum
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        qc_cases_entry e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.behospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.behospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t2
        WHERE
        t1.deptId = t2.deptId
        AND t1.deptName = t2.deptName)m2
        on
        m1.deptId = m2.deptId
        AND m1.deptName = m2.deptName
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>m1.deptId asc</when>
                <when test='asc=="deptName"'>m1.deptName asc</when>
                <when test='asc=="entryNum"'>m1.entryNum asc</when>
                <when test='asc=="sameNum"'>m2.sameNum asc</when>
                <when test='asc=="mrNum"'>m1.mrNum asc</when>
                <when test='asc=="sameMrNum"'>m2.sameMrNum asc</when>
                <when test='asc=="totleValue"'>m1.totleValue asc</when>
                <when test='asc=="averageValue"'>m1.averageValue asc</when>
                <when test='asc=="sameAvgValue"'>m2.sameAvgValue asc</when>
                <when test='asc=="firstLevelNum"'>m1.firstLevelNum asc</when>
                <when test='asc=="sameFirstLevelNum"'>m2.sameFirstLevelNum asc</when>
                <when test='asc=="secondLevelNum"'>m1.secondLevelNum asc</when>
                <when test='asc=="sameSecondLevelNum"'>m2.sameSecondLevelNum asc</when>
                <when test='asc=="thirdLevelNum"'>m1.thirdLevelNum asc</when>
                <when test='asc=="sameThirdLevelNum"'>m2.sameThirdLevelNum asc</when>
                <when test='asc=="firstLevelPercent"'>m1.firstLevelPercent asc</when>
                <when test='asc=="sameFirstLevelPercent"'>m2.sameFirstLevelPercent asc</when>
                <when test='asc=="secondLevelPercent"'>m1.secondLevelPercent asc</when>
                <when test='asc=="sameSecondLevelPercent"'>m2.sameSecondLevelPercent asc</when>
                <when test='asc=="thirdLevelPercent"'>m1.thirdLevelPercent asc</when>
                <when test='asc=="sameThirdLevelPercent"'>m2.sameThirdLevelPercent asc</when>
                <when test='asc=="firstLevelPercentStr"'>m1.firstLevelPercent asc</when>
                <when test='asc=="sameFirstLevelPercentStr"'>m2.sameFirstLevelPercentStr asc</when>
                <when test='asc=="secondLevelPercentStr"'>m1.secondLevelPercent asc</when>
                <when test='asc=="sameSecondLevelPercentStr"'>m2.sameSecondLevelPercentStr asc</when>
                <when test='asc=="thirdLevelPercentStr"'>m1.thirdLevelPercent asc</when>
                <when test='asc=="sameThirdLevelPercentStr"'>m2.sameThirdLevelPercentStr asc</when>
                <otherwise>deptName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>m1.deptId desc</when>
                <when test='desc=="deptName"'>m1.deptName desc</when>
                <when test='desc=="entryNum"'>m1.entryNum desc</when>
                <when test='desc=="sameNum"'>m2.sameNum desc</when>
                <when test='desc=="mrNum"'>m1.mrNum desc</when>
                <when test='desc=="sameMrNum"'>m2.sameMrNum desc</when>
                <when test='desc=="totleValue"'>m1.totleValue desc</when>
                <when test='desc=="averageValue"'>m1.averageValue desc</when>
                <when test='desc=="sameAvgValue"'>m2.sameAvgValue desc</when>
                <when test='desc=="firstLevelNum"'>m1.firstLevelNum desc</when>
                <when test='desc=="sameFirstLevelNum"'>m2.sameFirstLevelNum desc</when>
                <when test='desc=="secondLevelNum"'>m1.secondLevelNum desc</when>
                <when test='desc=="sameSecondLevelNum"'>m2.sameSecondLevelNum desc</when>
                <when test='desc=="thirdLevelNum"'>m1.thirdLevelNum desc</when>
                <when test='desc=="sameThirdLevelNum"'>m2.sameThirdLevelNum desc</when>
                <when test='desc=="firstLevelPercent"'>m1.firstLevelPercent desc</when>
                <when test='desc=="sameFirstLevelPercent"'>m2.sameFirstLevelPercent desc</when>
                <when test='desc=="secondLevelPercent"'>m1.secondLevelPercent desc</when>
                <when test='desc=="sameSecondLevelPercent"'>m2.sameSecondLevelPercent desc</when>
                <when test='desc=="thirdLevelPercent"'>m1.thirdLevelPercent desc</when>
                <when test='desc=="sameThirdLevelPercent"'>m2.sameThirdLevelPercent desc</when>
                <when test='desc=="firstLevelPercentStr"'>m1.firstLevelPercent desc</when>
                <when test='desc=="sameFirstLevelPercentStr"'>m2.sameFirstLevelPercentStr desc</when>
                <when test='desc=="secondLevelPercentStr"'>m1.secondLevelPercent desc</when>
                <when test='desc=="sameSecondLevelPercentStr"'>m2.sameSecondLevelPercentStr desc</when>
                <when test='desc=="thirdLevelPercentStr"'>m1.thirdLevelPercent desc</when>
                <when test='desc=="sameThirdLevelPercentStr"'>m2.sameThirdLevelPercentStr desc</when>
                <otherwise>deptName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 各科室缺陷占比（组合）-全院-根据内外科系统统计-关联上级科室 -->
    <select id="levelStatisticsByDeptClass" parameterType="com.diagbot.vo.FilterOrderVO"
            resultType="com.diagbot.dto.LevelStatisticsTZDTO">
        SELECT
        t1.deptId,
        t1.deptName,
        t1.deptClassId,
        t1.deptClass,
        t2.entryNum,
        t1.mrNum,
        t1.totleValue,
        t1.averageValue,
        t1.firstLevelNum,
        t1.secondLevelNum,
        t1.thirdLevelNum,
        t1.firstLevelPercent,
        t1.secondLevelPercent,
        t1.thirdLevelPercent,
        t1.firstLevelPercentStr,
        t1.secondLevelPercentStr,
        t1.thirdLevelPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        e.dept_id AS deptClassId,
        e.dept_name AS deptClass,
        count( DISTINCT c.id ) AS mrNum,
        ROUND( sum( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( sum( CAST( c.score_res AS DECIMAL ( 18, 2 )) )/ count(*), 2 ) AS averageValue,
        COUNT( DISTINCT CASE WHEN c.`level` = '甲' THEN c.id END ) AS firstLevelNum,
        COUNT( DISTINCT CASE WHEN c.`level` = '乙' THEN c.id END ) AS secondLevelNum,
        COUNT( DISTINCT CASE WHEN c.`level` = '丙' THEN c.id END ) AS thirdLevelNum,
        ROUND( COUNT( DISTINCT CASE WHEN c.`level` = '甲' THEN c.id END )/ count( DISTINCT c.id ), 4
        ) AS firstLevelPercent,
        ROUND( COUNT( DISTINCT CASE WHEN c.`level` = '乙' THEN c.id END )/ count( DISTINCT c.id ), 4
        ) AS secondLevelPercent,
        ROUND( COUNT( DISTINCT CASE WHEN c.`level` = '丙' THEN c.id END )/ count( DISTINCT c.id ), 4
        ) AS thirdLevelPercent,
        concat(
        ROUND( COUNT( DISTINCT CASE WHEN c.`level` = '甲' THEN c.id END )/ count( DISTINCT c.id )*
        100, 2 ),
        '%'
        ) AS firstLevelPercentStr,
        concat(
        ROUND( COUNT( DISTINCT CASE WHEN c.`level` = '乙' THEN c.id END )/ count( DISTINCT c.id )*
        100, 2 ),
        '%'
        ) AS secondLevelPercentStr,
        concat(
        ROUND( COUNT( DISTINCT CASE WHEN c.`level` = '丙' THEN c.id END )/ count( DISTINCT c.id )*
        100, 2 ),
        '%'
        ) AS thirdLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        bas_dept_info d,
        bas_dept_info e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = d.dept_id
        AND d.parent_dept_id = e.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        <if test="deptClass != null and deptClass != ''">
            and e.dept_name = #{deptClass}
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name,
        e.dept_id,
        e.dept_name
        ) t1,
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        g.dept_id AS deptClassId,
        g.dept_name AS deptClass,
        count( * ) AS entryNum
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        qc_cases_entry e,
        bas_dept_info f,
        bas_dept_info g
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND g.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.hospital_id = g.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND a.beh_dept_id = f.dept_id
        AND f.parent_dept_id = g.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        <if test="deptClass != null and deptClass != ''">
            and g.dept_name = #{deptClass}
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name,
        g.dept_id,
        g.dept_name
        ) t2
        WHERE
        t1.deptId = t2.deptId
        AND t1.deptName = t2.deptName
        AND t1.deptClassId = t2.deptClassId
        AND t1.deptClass = t2.deptClass
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>deptId asc</when>
                <when test='asc=="deptName"'>deptName asc</when>
                <when test='asc=="deptClassId"'>deptClassId asc</when>
                <when test='asc=="deptClass"'>deptClass asc</when>
                <when test='asc=="entryNum"'>entryNum asc</when>
                <when test='asc=="mrNum"'>mrNum asc</when>
                <when test='asc=="totleValue"'>totleValue asc</when>
                <when test='asc=="averageValue"'>averageValue asc</when>
                <when test='asc=="firstLevelNum"'>firstLevelNum asc</when>
                <when test='asc=="secondLevelNum"'>secondLevelNum asc</when>
                <when test='asc=="thirdLevelNum"'>thirdLevelNum asc</when>
                <when test='asc=="firstLevelPercent"'>firstLevelPercent asc</when>
                <when test='asc=="secondLevelPercent"'>secondLevelPercent asc</when>
                <when test='asc=="thirdLevelPercent"'>thirdLevelPercent asc</when>
                <when test='asc=="firstLevelPercentStr"'>firstLevelPercent asc</when>
                <when test='asc=="secondLevelPercentStr"'>secondLevelPercent asc</when>
                <when test='asc=="thirdLevelPercentStr"'>thirdLevelPercent asc</when>
                <otherwise>deptName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>deptId desc</when>
                <when test='desc=="deptName"'>deptName desc</when>
                <when test='desc=="deptClassId"'>deptClassId desc</when>
                <when test='desc=="deptClass"'>deptClass desc</when>
                <when test='desc=="entryNum"'>entryNum desc</when>
                <when test='desc=="mrNum"'>mrNum desc</when>
                <when test='desc=="totleValue"'>totleValue desc</when>
                <when test='desc=="averageValue"'>averageValue desc</when>
                <when test='desc=="firstLevelNum"'>firstLevelNum desc</when>
                <when test='desc=="secondLevelNum"'>secondLevelNum desc</when>
                <when test='desc=="thirdLevelNum"'>thirdLevelNum desc</when>
                <when test='desc=="firstLevelPercent"'>firstLevelPercent desc</when>
                <when test='desc=="secondLevelPercent"'>secondLevelPercent desc</when>
                <when test='desc=="thirdLevelPercent"'>thirdLevelPercent desc</when>
                <when test='desc=="firstLevelPercentStr"'>firstLevelPercent desc</when>
                <when test='desc=="secondLevelPercentStr"'>secondLevelPercent desc</when>
                <when test='desc=="thirdLevelPercentStr"'>thirdLevelPercent desc</when>
                <otherwise>deptName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 各科室缺陷占比（组合）-全院-根据内外科系统统计（台州） -->
    <select id="levelStatisticsByDeptClass_TZ" parameterType="com.diagbot.vo.FilterOrderVO" resultType="com.diagbot.dto.LevelStatisticsTZDTO">
        select
        m1.deptId,
        m1.deptName,
        m1.deptClassId,
        m1.deptClass,
        m1.entryNum,
        m2.sameNum,
        m1.mrNum,
        m2.sameMrNum,
        m1.totleValue,
        m2.sameTotleValue,
        m1.averageValue,
        m2.sameAvgValue,
        m1.firstLevelNum,
        m2.sameFirstLevelNum,
        m1.secondLevelNum,
        m2.sameSecondLevelNum,
        m1.thirdLevelNum,
        m2.sameThirdLevelNum,
        m1.firstLevelPercent,
        m2.sameFirstLevelPercent,
        m1.secondLevelPercent,
        m2.sameSecondLevelPercent,
        m1.thirdLevelPercent,
        m2.sameThirdLevelPercent,
        m1.firstLevelPercentStr,
        m2.sameFirstLevelPercentStr,
        m1.secondLevelPercentStr,
        m2.sameSecondLevelPercentStr,
        m1.thirdLevelPercentStr,
        m2.sameThirdLevelPercentStr
        from (
        SELECT
        t1.deptId,
        t1.deptName,
        t1.deptClassId,
        t1.deptClass,
        t2.entryNum,
        t1.mrNum,
        t1.totleValue,
        t1.averageValue,
        t1.firstLevelNum,
        t1.secondLevelNum,
        t1.thirdLevelNum,
        t1.firstLevelPercent,
        t1.secondLevelPercent,
        t1.thirdLevelPercent,
        t1.firstLevelPercentStr,
        t1.secondLevelPercentStr,
        t1.thirdLevelPercentStr
        FROM
        (
        SELECT
        tt1.deptId,
        tt1.deptName,
        e.dept_id AS deptClassId,
        e.dept_name AS deptClass,
        count(*) AS mrNum,
        ROUND( sum( CAST( tt1.score AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST( tt1.score AS DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        sum( tt1.`level` = '甲' ) AS firstLevelNum,
        sum( tt1.`level` = '乙' ) AS secondLevelNum,
        sum( tt1.`level` = '丙' ) AS thirdLevelNum,
        ROUND( sum( tt1.`level` = '甲' )/ count( * ), 4 ) AS firstLevelPercent,
        ROUND( sum( tt1.`level` = '乙' )/ count( * ), 4 ) AS secondLevelPercent,
        ROUND( sum( tt1.`level` = '丙' )/ count( * ), 4 ) AS thirdLevelPercent,
        concat( ROUND( sum( tt1.`level` = '甲' )/ count( * )* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( sum( tt1.`level` = '乙' )/ count( * )* 100, 2 ), '%' ) AS secondLevelPercentStr,
        concat( ROUND( sum( tt1.`level` = '丙' )/ count( * )* 100, 2 ), '%' ) AS thirdLevelPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        d.parent_dept_id AS parentDeptId,
        a.hospital_id AS hospitalId,
        a.behospital_code AS behospitalCode,
        c.score_res AS score,
        c.LEVEL
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        bas_dept_info d
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = d.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) tt1
        LEFT JOIN bas_dept_info e ON tt1.parentDeptId = e.dept_id
        AND e.is_deleted = 'N'
        AND tt1.hospitalId = e.hospital_id
        <if test="deptClass != null and deptClass != ''">
            WHERE e.dept_name = #{deptClass}
        </if>
        GROUP BY
        tt1.deptId,
        tt1.deptName,
        e.dept_id,
        e.dept_name
        ) t1,
        (
        SELECT
        tt2.deptId,
        tt2.deptName,
        g.dept_id AS deptClassId,
        g.dept_name AS deptClass,
        count( * ) AS entryNum
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        f.parent_dept_id AS parentDeptId,
        a.hospital_id AS hospitalId,
        a.behospital_code AS behospitalCode
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        qc_cases_entry e,
        bas_dept_info f
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND a.beh_dept_id = f.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) tt2
        LEFT JOIN bas_dept_info g ON tt2.parentDeptId = g.dept_id
        AND g.is_deleted = 'N'
        AND tt2.hospitalId = g.hospital_id
        <if test="deptClass != null and deptClass != ''">
            WHERE g.dept_name = #{deptClass}
        </if>
        GROUP BY
        tt2.deptId,
        tt2.deptName,
        g.dept_id,
        g.dept_name
        ) t2
        WHERE
        t1.deptId = t2.deptId
        AND t1.deptName = t2.deptName)m1 left join
        ( SELECT
        t1.deptId,
        t1.deptName,
        t1.deptClassId,
        t1.deptClass,
        t2.entryNum as sameNum,
        t1.mrNum as sameMrNum,
        t1.totleValue as sameTotleValue,
        t1.averageValue as sameAvgValue,
        t1.firstLevelNum as sameFirstLevelNum,
        t1.secondLevelNum as sameSecondLevelNum,
        t1.thirdLevelNum as sameThirdLevelNum,
        t1.firstLevelPercent as sameFirstLevelPercent,
        t1.secondLevelPercent as sameSecondLevelPercent,
        t1.thirdLevelPercent as sameThirdLevelPercent,
        t1.firstLevelPercentStr as sameFirstLevelPercentStr,
        t1.secondLevelPercentStr as sameSecondLevelPercentStr,
        t1.thirdLevelPercentStr as sameThirdLevelPercentStr
        FROM
        (
        SELECT
        tt1.deptId,
        tt1.deptName,
        e.dept_id AS deptClassId,
        e.dept_name AS deptClass,
        count(*) AS mrNum,
        ROUND( sum( CAST( tt1.score AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST( tt1.score AS DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        sum( tt1.`level` = '甲' ) AS firstLevelNum,
        sum( tt1.`level` = '乙' ) AS secondLevelNum,
        sum( tt1.`level` = '丙' ) AS thirdLevelNum,
        ROUND( sum( tt1.`level` = '甲' )/ count( * ), 4 ) AS firstLevelPercent,
        ROUND( sum( tt1.`level` = '乙' )/ count( * ), 4 ) AS secondLevelPercent,
        ROUND( sum( tt1.`level` = '丙' )/ count( * ), 4 ) AS thirdLevelPercent,
        concat( ROUND( sum( tt1.`level` = '甲' )/ count( * )* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( sum( tt1.`level` = '乙' )/ count( * )* 100, 2 ), '%' ) AS secondLevelPercentStr,
        concat( ROUND( sum( tt1.`level` = '丙' )/ count( * )* 100, 2 ), '%' ) AS thirdLevelPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        d.parent_dept_id AS parentDeptId,
        a.hospital_id AS hospitalId,
        a.behospital_code AS behospitalCode,
        c.score_res AS score,
        c.LEVEL
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        bas_dept_info d
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = d.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.behospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.behospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) tt1
        LEFT JOIN bas_dept_info e ON tt1.parentDeptId = e.dept_id
        AND e.is_deleted = 'N'
        AND tt1.hospitalId = e.hospital_id
        <if test="deptClass != null and deptClass != ''">
            WHERE e.dept_name = #{deptClass}
        </if>
        GROUP BY
        tt1.deptId,
        tt1.deptName,
        e.dept_id,
        e.dept_name
        ) t1,
        (
        SELECT
        tt2.deptId,
        tt2.deptName,
        g.dept_id AS deptClassId,
        g.dept_name AS deptClass,
        count( * ) AS entryNum
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        f.parent_dept_id AS parentDeptId,
        a.hospital_id AS hospitalId,
        a.behospital_code AS behospitalCode
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        qc_cases_entry e,
        bas_dept_info f
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND a.beh_dept_id = f.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.behospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.behospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) tt2
        LEFT JOIN bas_dept_info g ON tt2.parentDeptId = g.dept_id
        AND g.is_deleted = 'N'
        AND tt2.hospitalId = g.hospital_id
        <if test="deptClass != null and deptClass != ''">
            WHERE g.dept_name = #{deptClass}
        </if>
        GROUP BY
        tt2.deptId,
        tt2.deptName,
        g.dept_id,
        g.dept_name
        ) t2
        WHERE
        t1.deptId = t2.deptId
        AND t1.deptName = t2.deptName)m2
        on
            m1.deptId = m2.deptId
        and m1.deptName = m2.deptName
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>m1.deptId asc</when>
                <when test='asc=="deptName"'>m1.deptName asc</when>
                <when test='asc=="deptClassId"'>m1.deptClassId asc</when>
                <when test='asc=="deptClass"'>m1.deptClass asc</when>
                <when test='asc=="entryNum"'>m1.entryNum asc</when>
                <when test='asc=="sameNum"'>m2.sameNum asc</when>
                <when test='asc=="mrNum"'>m1.mrNum asc</when>
                <when test='asc=="sameMrNum"'>m2.sameMrNum asc</when>
                <when test='asc=="totleValue"'>m1.totleValue asc</when>
                <when test='asc=="averageValue"'>m1.averageValue asc</when>
                <when test='asc=="sameAvgValue"'>m2.sameAvgValue asc</when>
                <when test='asc=="firstLevelNum"'>m1.firstLevelNum asc</when>
                <when test='asc=="sameFirstLevelNum"'>m2.sameFirstLevelNum asc</when>
                <when test='asc=="secondLevelNum"'>m1.secondLevelNum asc</when>
                <when test='asc=="sameSecondLevelNum"'>m2.sameSecondLevelNum asc</when>
                <when test='asc=="thirdLevelNum"'>m1.thirdLevelNum asc</when>
                <when test='asc=="sameThirdLevelNum"'>m2.sameThirdLevelNum asc</when>
                <when test='asc=="firstLevelPercent"'>m1.firstLevelPercent asc</when>
                <when test='asc=="sameFirstLevelPercent"'>m2.sameFirstLevelPercent asc</when>
                <when test='asc=="secondLevelPercent"'>m1.secondLevelPercent asc</when>
                <when test='asc=="sameSecondLevelPercent"'>m2.sameSecondLevelPercent asc</when>
                <when test='asc=="thirdLevelPercent"'>m1.thirdLevelPercent asc</when>
                <when test='asc=="sameThirdLevelPercent"'>m2.sameThirdLevelPercent asc</when>
                <when test='asc=="firstLevelPercentStr"'>m1.firstLevelPercent asc</when>
                <when test='asc=="sameFirstLevelPercentStr"'>m2.sameFirstLevelPercentStr asc</when>
                <when test='asc=="secondLevelPercentStr"'>m1.secondLevelPercent asc</when>
                <when test='asc=="sameSecondLevelPercentStr"'>m2.sameSecondLevelPercentStr asc</when>
                <when test='asc=="thirdLevelPercentStr"'>m1.thirdLevelPercent asc</when>
                <when test='asc=="sameThirdLevelPercentStr"'>m2.sameThirdLevelPercentStr asc</when>
                <otherwise>deptName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>m1.deptId desc</when>
                <when test='desc=="deptName"'>m1.deptName desc</when>
                <when test='desc=="deptClassId"'>m1.deptClassId desc</when>
                <when test='desc=="deptClass"'>m1.deptClass desc</when>
                <when test='desc=="entryNum"'>m1.entryNum desc</when>
                <when test='desc=="sameNum"'>m2.sameNum desc</when>
                <when test='desc=="mrNum"'>m1.mrNum desc</when>
                <when test='desc=="sameMrNum"'>m2.sameMrNum desc</when>
                <when test='desc=="totleValue"'>m1.totleValue desc</when>
                <when test='desc=="averageValue"'>m1.averageValue desc</when>
                <when test='desc=="sameAvgValue"'>m2.sameAvgValue desc</when>
                <when test='desc=="firstLevelNum"'>m1.firstLevelNum desc</when>
                <when test='desc=="sameFirstLevelNum"'>m2.sameFirstLevelNum desc</when>
                <when test='desc=="secondLevelNum"'>m1.secondLevelNum desc</when>
                <when test='desc=="sameSecondLevelNum"'>m2.sameSecondLevelNum desc</when>
                <when test='desc=="thirdLevelNum"'>m1.thirdLevelNum desc</when>
                <when test='desc=="sameThirdLevelNum"'>m2.sameThirdLevelNum desc</when>
                <when test='desc=="firstLevelPercent"'>m1.firstLevelPercent desc</when>
                <when test='desc=="sameFirstLevelPercent"'>m2.sameFirstLevelPercent desc</when>
                <when test='desc=="secondLevelPercent"'>m1.secondLevelPercent desc</when>
                <when test='desc=="sameSecondLevelPercent"'>m2.sameSecondLevelPercent desc</when>
                <when test='desc=="thirdLevelPercent"'>m1.thirdLevelPercent desc</when>
                <when test='desc=="sameThirdLevelPercent"'>m2.sameThirdLevelPercent desc</when>
                <when test='desc=="firstLevelPercentStr"'>m1.firstLevelPercent desc</when>
                <when test='desc=="sameFirstLevelPercentStr"'>m2.sameFirstLevelPercentStr desc</when>
                <when test='desc=="secondLevelPercentStr"'>m1.secondLevelPercent desc</when>
                <when test='desc=="sameSecondLevelPercentStr"'>m2.sameSecondLevelPercentStr desc</when>
                <when test='desc=="thirdLevelPercentStr"'>m1.thirdLevelPercent desc</when>
                <when test='desc=="sameThirdLevelPercentStr"'>m2.sameThirdLevelPercentStr desc</when>
                <otherwise>deptName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 病案首页合格率占比 -全院-->
    <select id="homePageLevelStatistics" parameterType="com.diagbot.vo.FilterOrderVO"
            resultType="com.diagbot.dto.HomePageNumDTO">
        SELECT
        t1.deptId,
        t1.deptName,
        t2.entryNum,
        t1.mrNum,
        t1.totleValue,
        t1.averageValue,
        t1.firstLevelNum,
        t1.secondLevelNum,
        t1.firstLevelPercent,
        t1.secondLevelPercent,
        t1.firstLevelPercentStr,
        t1.secondLevelPercentStr,
        t3.emptyNum,
        t3.errorNum,
        t3.entryTotleNum,
        t3.emptyPercent,
        t3.errorPercent,
        t3.emptyPercentStr,
        t3.errorPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        count( * ) AS mrNum,
        ROUND( sum( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        SUM( c.`level` = '合格' ) AS firstLevelNum,
        SUM( c.`level` = '不合格' ) AS secondLevelNum,
        ROUND( SUM( c.`level` = '合格' )/ count( * ), 4 ) AS firstLevelPercent,
        ROUND( SUM( c.`level` = '不合格' )/ count( * ), 4 ) AS secondLevelPercent,
        concat( ROUND( SUM( c.`level` = '合格' )/ count( * )* 100, 2 ),'%' ) AS firstLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '不合格' )/ count( * )* 100, 2 ),'%' ) AS secondLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t1,
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        count( * ) AS entryNum
        FROM
        med_behospital_info a,
        med_qcresult_cases c,
        med_qcresult_detail d,
        qc_cases_entry e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND c.cases_id = d.cases_id
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND d.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t2,(
        SELECT
        h1.deptId,
        h1.deptName,
        h1.emptyNum,
        h1.errorNum,
        h1.mrNum,
        h2.entryNum,
        h1.mrNum * h2.entryNum AS entryTotleNum,
        ROUND( ( h1.mrNum * h2.entryNum  - h1.emptyNum ) / ( h1.mrNum * h2.entryNum ), 4 ) AS emptyPercent,
        ROUND( ( h1.mrNum * h2.entryNum  - h1.errorNum ) / ( h1.mrNum * h2.entryNum ), 4 ) AS errorPercent,
        CONCAT( ROUND( ( h1.mrNum * h2.entryNum - h1.emptyNum ) / ( h1.mrNum * h2.entryNum )* 100, 2 ), '%' ) AS emptyPercentStr,
        CONCAT( ROUND( ( h1.mrNum * h2.entryNum - h1.errorNum ) / ( h1.mrNum * h2.entryNum )* 100, 2 ), '%' ) AS errorPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        sum( d.rule_type = 1 ) AS emptyNum,
        sum( d.rule_type = 2 ) AS errorNum,
        count( DISTINCT a.behospital_code ) AS mrNum
        FROM
        med_behospital_info a,
        med_qcresult_cases b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND b.cases_id = c.cases_id
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND d.cases_id = 243
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and b.level = #{level}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) h1,(
        SELECT
        count(*) AS entryNum
        FROM
        qc_cases_entry
        WHERE
        is_deleted = 'N'
        AND cases_id = 243
        ) h2
        ) t3
        WHERE
        t1.deptId = t2.deptId
        AND t1.deptId = t3.deptId
        AND t1.deptName = t2.deptName
        AND t1.deptName = t3.deptName
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>deptId asc</when>
                <when test='asc=="deptName"'>deptName asc</when>
                <when test='asc=="entryNum"'>entryNum asc</when>
                <when test='asc=="mrNum"'>mrNum asc</when>
                <when test='asc=="totleValue"'>totleValue asc</when>
                <when test='asc=="averageValue"'>averageValue asc</when>
                <when test='asc=="firstLevelNum"'>firstLevelNum asc</when>
                <when test='asc=="secondLevelNum"'>secondLevelNum asc</when>
                <when test='asc=="firstLevelPercent"'>firstLevelPercent asc</when>
                <when test='asc=="secondLevelPercent"'>secondLevelPercent asc</when>
                <when test='asc=="firstLevelPercentStr"'>firstLevelPercent asc</when>
                <when test='asc=="secondLevelPercentStr"'>secondLevelPercent asc</when>
                <when test='asc=="emptyNum"'>emptyNum asc</when>
                <when test='asc=="errorNum"'>errorNum asc</when>
                <when test='asc=="entryTotleNum"'>entryTotleNum asc</when>
                <when test='asc=="emptyPercent"'>emptyPercent asc</when>
                <when test='asc=="errorPercent"'>errorPercent asc</when>
                <when test='asc=="emptyPercentStr"'>emptyPercent asc</when>
                <when test='asc=="errorPercentStr"'>errorPercent asc</when>
                <otherwise>deptName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>deptId desc</when>
                <when test='desc=="deptName"'>deptName desc</when>
                <when test='desc=="entryNum"'>entryNum desc</when>
                <when test='desc=="mrNum"'>mrNum desc</when>
                <when test='desc=="totleValue"'>totleValue desc</when>
                <when test='desc=="averageValue"'>averageValue desc</when>
                <when test='desc=="firstLevelNum"'>firstLevelNum desc</when>
                <when test='desc=="secondLevelNum"'>secondLevelNum desc</when>
                <when test='desc=="firstLevelPercent"'>firstLevelPercent desc</when>
                <when test='desc=="secondLevelPercent"'>secondLevelPercent desc</when>
                <when test='desc=="firstLevelPercentStr"'>firstLevelPercent desc</when>
                <when test='desc=="secondLevelPercentStr"'>secondLevelPercent desc</when>
                <when test='desc=="emptyNum"'>emptyNum desc</when>
                <when test='desc=="errorNum"'>errorNum desc</when>
                <when test='desc=="entryTotleNum"'>entryTotleNum desc</when>
                <when test='desc=="emptyPercent"'>emptyPercent desc</when>
                <when test='desc=="errorPercent"'>errorPercent desc</when>
                <when test='desc=="emptyPercentStr"'>emptyPercent desc</when>
                <when test='desc=="errorPercentStr"'>errorPercent desc</when>
                <otherwise>deptName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 医师病案首页合格率占比 湘雅定制-->
    <select id="homePageLevelStatisticsXY" resultType="com.diagbot.dto.HomePageNumXYDTO">
        SELECT
        tt1.*,
        tt2.entryNum,
        tt2.emptyNum,
        tt2.errorNum,
        tt2.entryTotleNum,
        tt2.emptyPercent,
        tt2.errorPercent,
        tt2.emptyPercentStr,
        tt2.errorPercentStr
        FROM(
        select
        t1.deptId,
        t1.deptName,
        t1.doctorName,
        t1.professor,
        sum(t1.mrNum) as mrNum,
        sum(t1.totleValue)as totleValue,
        ROUND(CAST(sum(t1.totleValue)/sum(t1.mrNum) AS DECIMAL ( 18, 2 )), 2) AS averageValue,
        sum(t1.firstLevelNum)as firstLevelNum,
        sum(t1.secondLevelNum)as secondLevelNum,
        ROUND(sum(t1.firstLevelNum)/sum(t1.mrNum),4) as firstLevelPercent,
        ROUND(sum(t1.secondLevelNum)/sum(t1.mrNum),4) as secondLevelPercent,
        concat( ROUND( sum(t1.firstLevelNum)/sum(t1.mrNum)* 100, 2 ),'%' ) AS firstLevelPercentStr,
        concat( ROUND( sum(t1.secondLevelNum)/sum(t1.mrNum)* 100, 2 ),'%' ) AS secondLevelPercentStr
        from
        (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        case
        when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        b.director_doctor != '' and b.director_doctor is not null
        then b.director_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        (b.director_doctor = '' or b.director_doctor is null) and
        b.behospital_doctor != '' and b.behospital_doctor is not null
        then b.behospital_doctor end as doctorName,
        case
        when b.attending_doctor != '' and b.attending_doctor is not null then '主治医师'
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        b.director_doctor != '' and b.director_doctor is not null
        then '主任医师'
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        (b.director_doctor = '' or b.director_doctor is null) and
        b.behospital_doctor != '' and b.behospital_doctor is not null
        then '住院医师' end as professor,
        count( * ) AS mrNum,
        ROUND( sum( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        count(case when c.`level` = '合格' then 1 end) AS firstLevelNum,
        count(case when c.`level` = '不合格' then 1 end) AS secondLevelNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        <if test="deptId != null and deptId != ''">
            and a.beh_dept_id = #{deptId}
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name,
        b.attending_doctor,
        b.director_doctor,
        b.behospital_doctor
        ) t1
        group by t1.deptId,t1.deptName,t1.doctorName,t1.professor
        )tt1,
        (
        select
        t2.deptId,
        t2.deptName,
        t2.doctorName,
        t2.professor,
        sum(t2.entryNum)as entryNum,
        sum(t2.emptyNum)as emptyNum,
        sum(t2.errorNum)as errorNum,
        sum(t2.mrNum) * t2.entryNumSec AS entryTotleNum,
        ROUND( ( sum(t2.mrNum) * t2.entryNumSec  - sum(t2.emptyNum) ) / ( sum(t2.mrNum) * t2.entryNumSec ), 4 ) AS emptyPercent,
        ROUND( ( sum(t2.mrNum) * t2.entryNumSec  - sum(t2.errorNum) ) / ( sum(t2.mrNum) * t2.entryNumSec ), 4 ) AS errorPercent,
        CONCAT( ROUND( ( sum(t2.mrNum) * t2.entryNumSec - sum(t2.emptyNum) ) / ( sum(t2.mrNum) * t2.entryNumSec )* 100, 2 ), '%' ) AS emptyPercentStr,
        CONCAT( ROUND( ( sum(t2.mrNum) * t2.entryNumSec - sum(t2.errorNum) ) / ( sum(t2.mrNum) * t2.entryNumSec )* 100, 2 ), '%' ) AS errorPercentStr
        from (
        select m1.*,m2.entryNum as entryNumSec from (
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        case
        when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        b.director_doctor != '' and b.director_doctor is not null
        then b.director_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        (b.director_doctor = '' or b.director_doctor is null) and
        b.behospital_doctor != '' and b.behospital_doctor is not null
        then b.behospital_doctor end as doctorName,
        case
        when b.attending_doctor != '' and b.attending_doctor is not null then '主治医师'
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        b.director_doctor != '' and b.director_doctor is not null
        then '主任医师'
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        (b.director_doctor = '' or b.director_doctor is null) and
        b.behospital_doctor != '' and b.behospital_doctor is not null
        then '住院医师' end as professor,
        count( * ) AS entryNum,
        count(case when e.rule_type = 1 then 1 end) AS emptyNum,
        count(case when e.rule_type = 2 then 1 end) AS errorNum,
        count( DISTINCT a.behospital_code ) AS mrNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_cases c,
        med_qcresult_detail d,
        qc_cases_entry e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND c.cases_id = d.cases_id
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND d.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name like CONCAT('%',#{deptName},'%')
        </if>
        <if test="deptId != null and deptId != ''">
            and a.beh_dept_id = #{deptId}
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name,
        b.attending_doctor,
        b.director_doctor,
        b.behospital_doctor
        )m1,(
        SELECT
        count(*) AS entryNum
        FROM
        qc_cases_entry
        WHERE
        is_deleted = 'N'
        AND cases_id = 243
        )m2) t2
        group by t2.deptId,t2.deptName,t2.doctorName,t2.professor
        ) tt2
        WHERE
        tt1.deptId = tt2.deptId
        AND tt1.deptName = tt2.deptName
        AND tt1.doctorName= tt2.doctorName
        AND tt1.professor = tt2.professor
        AND tt1.professor != ''
        and tt1.professor is not null
        <if test="doctorName != null and doctorName != ''">
            and tt1.doctorName like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="professor != null and professor != ''">
            and tt1.professor = #{professor}
        </if>
    </select>


    <!-- 各科室缺陷占比-科室 -->
    <select id="levelStatisticsByDept" parameterType="com.diagbot.vo.FilterOrderByDeptVO"
            resultType="com.diagbot.dto.LevelStsByDeptDTO">
        SELECT
        m1.doctorId,
        m1.doctorName,
        m1.entryNum,
        m2.sameNum,
        m1.mrNum,
        m2.sameMrNum,
        m1.totleValue,
        m2.sameTotleValue,
        m1.averageValue,
        m2.sameAvgValue,
        m1.firstLevelNum,
        m2.sameFirstLevelNum,
        m1.secondLevelNum,
        m2.sameSecondLevelNum,
        m1.thirdLevelNum,
        m2.sameThirdLevelNum,
        m1.firstLevelPercent,
        m2.sameFirstLevelPercent,
        m1.secondLevelPercent,
        m2.sameSecondLevelPercent,
        m1.thirdLevelPercent,
        m2.sameThirdLevelPercent,
        m1.firstLevelPercentStr,
        m2.sameFirstLevelPercentStr,
        m1.secondLevelPercentStr,
        m2.sameSecondLevelPercentStr,
        m1.thirdLevelPercentStr,
        m2.sameThirdLevelPercentStr
        FROM
        (
        SELECT
        t1.doctorId,
        t1.doctorName,
        t2.entryNum,
        t1.mrNum,
        t1.totleValue,
        t1.averageValue,
        t1.firstLevelNum,
        t1.secondLevelNum,
        t1.thirdLevelNum,
        t1.firstLevelPercent,
        t1.secondLevelPercent,
        t1.thirdLevelPercent,
        t1.firstLevelPercentStr,
        t1.secondLevelPercentStr,
        t1.thirdLevelPercentStr
        FROM
        (
        SELECT
        a.doctor_id AS doctorId,
        a.doctor_name AS doctorName,
        count(*) AS mrNum,
        ROUND( sum( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        SUM( c.`level` = '甲' ) AS firstLevelNum,
        SUM( c.`level` = '乙' ) AS secondLevelNum,
        SUM( c.`level` = '丙' ) AS thirdLevelNum,
        ROUND( SUM( c.`level` = '甲' )/ count(*), 4 ) AS firstLevelPercent,
        ROUND( SUM( c.`level` = '乙' )/ count(*), 4 ) AS secondLevelPercent,
        ROUND( SUM( c.`level` = '丙' )/ count(*), 4 ) AS thirdLevelPercent,
        concat( ROUND( SUM( c.`level` = '甲' )/ count(*)* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '乙' )/ count(*)* 100, 2 ), '%' ) AS secondLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '丙' )/ count(*)* 100, 2 ), '%' ) AS thirdLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = e.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="userId!=null and userId !=''">
            AND e.user_id = #{userId}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) t1,
        (
        SELECT
        a.doctor_id AS doctorId,
        a.doctor_name AS doctorName,
        count( * ) AS entryNum
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        qc_cases_entry e,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND a.beh_dept_id = f.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="userId!=null and userId !=''">
            AND f.user_id = #{userId}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) t2
        WHERE
        t1.doctorId = t2.doctorId
        AND t1.doctorName = t2.doctorName
        )m1 left join
        ( SELECT
        t1.doctorId,
        t1.doctorName,
        t2.entryNum as sameNum,
        t1.mrNum as sameMrNum,
        t1.totleValue as  sameTotleValue,
        t1.averageValue as sameAvgValue,
        t1.firstLevelNum as sameFirstLevelNum,
        t1.secondLevelNum as sameSecondLevelNum,
        t1.thirdLevelNum as sameThirdLevelNum,
        t1.firstLevelPercent as sameFirstLevelPercent,
        t1.secondLevelPercent as sameSecondLevelPercent,
        t1.thirdLevelPercent as sameThirdLevelPercent,
        t1.firstLevelPercentStr as sameFirstLevelPercentStr,
        t1.secondLevelPercentStr as sameSecondLevelPercentStr,
        t1.thirdLevelPercentStr as sameThirdLevelPercentStr
        FROM
        (
        SELECT
        a.doctor_id AS doctorId,
        a.doctor_name AS doctorName,
        count(*) AS mrNum,
        ROUND( sum( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST(c.score_res as DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        SUM( c.`level` = '甲' ) AS firstLevelNum,
        SUM( c.`level` = '乙' ) AS secondLevelNum,
        SUM( c.`level` = '丙' ) AS thirdLevelNum,
        ROUND( SUM( c.`level` = '甲' )/ count(*), 4 ) AS firstLevelPercent,
        ROUND( SUM( c.`level` = '乙' )/ count(*), 4 ) AS secondLevelPercent,
        ROUND( SUM( c.`level` = '丙' )/ count(*), 4 ) AS thirdLevelPercent,
        concat( ROUND( SUM( c.`level` = '甲' )/ count(*)* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '乙' )/ count(*)* 100, 2 ), '%' ) AS secondLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '丙' )/ count(*)* 100, 2 ), '%' ) AS thirdLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = e.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.behospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.behospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="userId!=null and userId !=''">
            AND e.user_id = #{userId}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) t1,
        (
        SELECT
        a.doctor_id AS doctorId,
        a.doctor_name AS doctorName,
        count( * ) AS entryNum
        FROM
        med_behospital_info a,
        med_qcresult_info c,
        med_qcresult_detail d,
        qc_cases_entry e,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND a.beh_dept_id = f.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.behospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.behospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="lastStartDate != null and lastStartDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{lastStartDate}]]>
            </if>
            <if test="lastEndDate != null and lastEndDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{lastEndDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name like CONCAT('%',#{doctorName},'%')
        </if>
        <if test="userId!=null and userId !=''">
            AND f.user_id = #{userId}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) t2
        WHERE
        t1.doctorId = t2.doctorId
        AND t1.doctorName = t2.doctorName
        )m2
        on
        m1.doctorId = m2.doctorId
        AND m1.doctorName = m2.doctorName
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="doctorId"'>m1.doctorId asc</when>
                <when test='asc=="doctorName"'>m1.doctorName asc</when>
                <when test='asc=="name"'>m1.doctorName asc</when>
                <when test='asc=="entryNum"'>m1.entryNum asc</when>
                <when test='asc=="sameNum"'>m2.sameNum asc</when>
                <when test='asc=="mrNum"'>m1.mrNum asc</when>
                <when test='asc=="sameMrNum"'>m2.sameMrNum asc</when>
                <when test='asc=="totleValue"'>m1.totleValue asc</when>
                <when test='asc=="averageValue"'>m1.averageValue asc</when>
                <when test='asc=="sameAvgValue"'>m2.sameAvgValue asc</when>
                <when test='asc=="firstLevelNum"'>m1.firstLevelNum asc</when>
                <when test='asc=="sameFirstLevelNum"'>m2.sameFirstLevelNum asc</when>
                <when test='asc=="secondLevelNum"'>m1.secondLevelNum asc</when>
                <when test='asc=="sameSecondLevelNum"'>m2.sameSecondLevelNum asc</when>
                <when test='asc=="thirdLevelNum"'>m1.thirdLevelNum asc</when>
                <when test='asc=="sameThirdLevelNum"'>m2.sameThirdLevelNum asc</when>
                <when test='asc=="firstLevelPercent"'>m1.firstLevelPercent asc</when>
                <when test='asc=="sameFirstLevelPercent"'>m2.sameFirstLevelPercent asc</when>
                <when test='asc=="secondLevelPercent"'>m1.secondLevelPercent asc</when>
                <when test='asc=="sameSecondLevelPercent"'>m2.sameSecondLevelPercent asc</when>
                <when test='asc=="thirdLevelPercent"'>m1.thirdLevelPercent asc</when>
                <when test='asc=="sameThirdLevelPercent"'>m2.sameThirdLevelPercent asc</when>
                <when test='asc=="firstLevelPercentStr"'>m1.firstLevelPercent asc</when>
                <when test='asc=="sameFirstLevelPercentStr"'>m2.sameFirstLevelPercentStr asc</when>
                <when test='asc=="secondLevelPercentStr"'>m1.secondLevelPercent asc</when>
                <when test='asc=="sameSecondLevelPercentStr"'>m2.sameSecondLevelPercentStr asc</when>
                <when test='asc=="thirdLevelPercentStr"'>m1.thirdLevelPercent asc</when>
                <when test='asc=="sameThirdLevelPercentStr"'>m2.sameThirdLevelPercentStr asc</when>
                <otherwise>doctorName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="doctorId"'>m1.doctorId desc</when>
                <when test='desc=="doctorName"'>m1.doctorName desc</when>
                <when test='desc=="entryNum"'>m1.entryNum desc</when>
                <when test='desc=="sameNum"'>m2.sameNum desc</when>
                <when test='desc=="mrNum"'>m1.mrNum desc</when>
                <when test='desc=="sameMrNum"'>m2.sameMrNum desc</when>
                <when test='desc=="totleValue"'>m1.totleValue desc</when>
                <when test='desc=="averageValue"'>m1.averageValue desc</when>
                <when test='desc=="sameAvgValue"'>m2.sameAvgValue desc</when>
                <when test='desc=="firstLevelNum"'>m1.firstLevelNum desc</when>
                <when test='desc=="sameFirstLevelNum"'>m2.sameFirstLevelNum desc</when>
                <when test='desc=="secondLevelNum"'>m1.secondLevelNum desc</when>
                <when test='desc=="sameSecondLevelNum"'>m2.sameSecondLevelNum desc</when>
                <when test='desc=="thirdLevelNum"'>m1.thirdLevelNum desc</when>
                <when test='desc=="sameThirdLevelNum"'>m2.sameThirdLevelNum desc</when>
                <when test='desc=="firstLevelPercent"'>m1.firstLevelPercent desc</when>
                <when test='desc=="sameFirstLevelPercent"'>m2.sameFirstLevelPercent desc</when>
                <when test='desc=="secondLevelPercent"'>m1.secondLevelPercent desc</when>
                <when test='desc=="sameSecondLevelPercent"'>m2.sameSecondLevelPercent desc</when>
                <when test='desc=="thirdLevelPercent"'>m1.thirdLevelPercent desc</when>
                <when test='desc=="sameThirdLevelPercent"'>m2.sameThirdLevelPercent desc</when>
                <when test='desc=="firstLevelPercentStr"'>m1.firstLevelPercent desc</when>
                <when test='desc=="sameFirstLevelPercentStr"'>m2.sameFirstLevelPercentStr desc</when>
                <when test='desc=="secondLevelPercentStr"'>m1.secondLevelPercent desc</when>
                <when test='desc=="sameSecondLevelPercentStr"'>m2.sameSecondLevelPercentStr desc</when>
                <when test='desc=="thirdLevelPercentStr"'>m1.thirdLevelPercent desc</when>
                <when test='desc=="sameThirdLevelPercentStr"'>m2.sameThirdLevelPercentStr desc</when>
                <otherwise>doctorName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 病案首页合格率占比-科室 -->
    <select id="homePageLevelStatisticsByDept" parameterType="com.diagbot.vo.FilterOrderByDeptVO"
            resultType="com.diagbot.dto.HomePageByDeptDTO">
        SELECT
        t1.doctorId,
        t1.doctorName,
        t2.entryNum,
        t1.mrNum,
        t1.totleValue,
        t1.averageValue,
        t1.firstLevelNum,
        t1.secondLevelNum,
        t1.firstLevelPercent,
        t1.secondLevelPercent,
        t1.firstLevelPercentStr,
        t1.secondLevelPercentStr,
        t3.emptyNum,
        t3.errorNum,
        t3.entryTotleNum,
        t3.emptyPercent,
        t3.errorPercent,
        t3.emptyPercentStr,
        t3.errorPercentStr
        FROM
        (
        SELECT
        a.doctor_id  AS doctorId,
        a.doctor_name  AS doctorName,
        count( * ) AS mrNum,
        ROUND( sum( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        sum( c.`level` = '合格' ) AS firstLevelNum,
        sum( c.`level` = '不合格' ) AS secondLevelNum,
        ROUND( sum( c.`level` = '合格' ) / count( * ), 4 ) AS firstLevelPercent,
        ROUND( sum( c.`level` = '不合格' )/ count( * ), 4 ) AS secondLevelPercent,
        concat( ROUND( sum( c.`level` = '合格' ) / count( * )* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( sum( c.`level` = '不合格' )/ count( * )* 100, 2 ), '%' ) AS secondLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_cases c,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND c.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="name != null and name != ''">
            <if test="name == '未知'">
                and (a.doctor_name is null or a.doctor_name='')
            </if>
            <if test="name != '未知'">
                and a.doctor_name like CONCAT('%',#{name},'%')
            </if>
        </if>
        <if test="userId!=null and userId !=''">
            AND f.user_id = #{userId}
        </if>
        <if test="deptName!=null and deptName !=''">
            AND a.beh_dept_name = #{deptName}
        </if>
        <if test="deptId!=null and deptId !=''">
            AND a.beh_dept_id = #{deptId}
        </if>
        <if test="doctorId != null and doctorId != ''">
            AND a.doctor_id  = #{doctorId}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="name != null and name != ''">
            AND a.doctor_name  like CONCAT('%', #{name}, '%')
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) t1,
        (
        SELECT
        a.doctor_id  AS doctorId,
        a.doctor_name AS doctorName,
        count( * ) AS entryNum
        FROM
        med_behospital_info a,
        med_qcresult_cases c,
        med_qcresult_detail d,
        qc_cases_entry e,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND c.cases_id = d.cases_id
        AND d.cases_id = e.cases_id
        AND d.cases_entry_id = e.id
        AND c.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and c.level = #{level}
        </if>
        <if test="name != null and name != ''">
            <if test="name == '未知'">
                and (a.doctor_name is null or a.doctor_name='')
            </if>
            <if test="name != '未知'">
                and a.doctor_name like CONCAT('%',#{name},'%')
            </if>
        </if>
        <if test="userId!=null and userId !=''">
            AND f.user_id = #{userId}
        </if>
        <if test="deptName!=null and deptName !=''">
            AND a.beh_dept_name = #{deptName}
        </if>
        <if test="deptId!=null and deptId !=''">
            AND a.beh_dept_id = #{deptId}
        </if>
        <if test="doctorId != null and doctorId != ''">
            AND a.doctor_id  = #{doctorId}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="name != null and name != ''">
            AND a.doctor_name  like CONCAT('%', #{name}, '%')
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) t2,(
        SELECT
        h1.doctorId,
        h1.doctorName,
        h1.emptyNum,
        h1.errorNum,
        h1.mrNum,
        h2.entryNum,
        h1.mrNum * h2.entryNum AS entryTotleNum,
        ROUND( ( h1.mrNum * h2.entryNum - h1.emptyNum ) / ( h1.mrNum * h2.entryNum ), 4 ) AS emptyPercent,
        ROUND( ( h1.mrNum * h2.entryNum - h1.errorNum ) / ( h1.mrNum * h2.entryNum ), 4 ) AS errorPercent,
        CONCAT( ROUND( ( h1.mrNum * h2.entryNum - h1.emptyNum ) / ( h1.mrNum * h2.entryNum )* 100, 2 ), '%' ) AS emptyPercentStr,
        CONCAT( ROUND( ( h1.mrNum * h2.entryNum - h1.errorNum ) / ( h1.mrNum * h2.entryNum )* 100, 2 ), '%' ) AS errorPercentStr
        FROM
        (
        SELECT
        a.doctor_id AS doctorId,
        a.doctor_name AS doctorName,
        sum( d.rule_type = 1 ) AS emptyNum,
        sum( d.rule_type = 2 ) AS errorNum,
        count( DISTINCT a.behospital_code ) AS mrNum
        FROM
        med_behospital_info a,
        med_qcresult_cases b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND b.cases_id = c.cases_id
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.beh_dept_id = e.dept_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND d.cases_id = 243
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="level != null and level != ''">
            and b.level = #{level}
        </if>
        <if test="name != null and name != ''">
            <if test="name == '未知'">
                and (a.doctor_name is null or a.doctor_name='')
            </if>
            <if test="name != '未知'">
                and a.doctor_name like CONCAT('%',#{name},'%')
            </if>
        </if>
        <if test="userId!=null and userId !=''">
            AND e.user_id = #{userId}
        </if>
        <if test="deptName!=null and deptName !=''">
            AND a.beh_dept_name = #{deptName}
        </if>
        <if test="deptId!=null and deptId !=''">
            AND a.beh_dept_id = #{deptId}
        </if>
        <if test="doctorId != null and doctorId != ''">
            AND a.doctor_id  = #{doctorId}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="name != null and name != ''">
            AND a.doctor_name  like CONCAT('%', #{name}, '%')
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) h1,(
        SELECT
        count(*) AS entryNum
        FROM
        qc_cases_entry
        WHERE
        is_deleted = 'N'
        AND cases_id = 243
        ) h2
        ) t3
        WHERE
        t1.doctorId = t2.doctorId
        AND t1.doctorId = t3.doctorId
        AND t1.doctorName = t2.doctorName
        AND t1.doctorName = t3.doctorName
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="doctorId"'>doctorId asc</when>
                <when test='asc=="doctorName"'>doctorName asc</when>
                <when test='asc=="entryNum"'>entryNum asc</when>
                <when test='asc=="mrNum"'>mrNum asc</when>
                <when test='asc=="totleValue"'>totleValue asc</when>
                <when test='asc=="averageValue"'>averageValue asc</when>
                <when test='asc=="firstLevelNum"'>firstLevelNum asc</when>
                <when test='asc=="secondLevelNum"'>secondLevelNum asc</when>
                <when test='asc=="firstLevelPercent"'>firstLevelPercent asc</when>
                <when test='asc=="secondLevelPercent"'>secondLevelPercent asc</when>
                <when test='asc=="firstLevelPercentStr"'>firstLevelPercent asc</when>
                <when test='asc=="secondLevelPercentStr"'>secondLevelPercent asc</when>
                <when test='asc=="emptyNum"'>emptyNum asc</when>
                <when test='asc=="errorNum"'>errorNum asc</when>
                <when test='asc=="entryTotleNum"'>entryTotleNum asc</when>
                <when test='asc=="emptyPercent"'>emptyPercent asc</when>
                <when test='asc=="errorPercent"'>errorPercent asc</when>
                <when test='asc=="emptyPercentStr"'>emptyPercent asc</when>
                <when test='asc=="errorPercentStr"'>errorPercent asc</when>
                <otherwise>doctorName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="doctorId"'>doctorId desc</when>
                <when test='desc=="doctorName"'>doctorName desc</when>
                <when test='desc=="entryNum"'>entryNum desc</when>
                <when test='desc=="mrNum"'>mrNum desc</when>
                <when test='desc=="totleValue"'>totleValue desc</when>
                <when test='desc=="averageValue"'>averageValue desc</when>
                <when test='desc=="firstLevelNum"'>firstLevelNum desc</when>
                <when test='desc=="secondLevelNum"'>secondLevelNum desc</when>
                <when test='desc=="firstLevelPercent"'>firstLevelPercent desc</when>
                <when test='desc=="secondLevelPercent"'>secondLevelPercent desc</when>
                <when test='desc=="firstLevelPercentStr"'>firstLevelPercent desc</when>
                <when test='desc=="secondLevelPercentStr"'>secondLevelPercent desc</when>
                <when test='desc=="emptyNum"'>emptyNum desc</when>
                <when test='desc=="errorNum"'>errorNum desc</when>
                <when test='desc=="entryTotleNum"'>entryTotleNum desc</when>
                <when test='desc=="emptyPercent"'>emptyPercent desc</when>
                <when test='desc=="errorPercent"'>errorPercent desc</when>
                <when test='desc=="emptyPercentStr"'>emptyPercent desc</when>
                <when test='desc=="errorPercentStr"'>errorPercent desc</when>
                <otherwise>doctorName desc</otherwise>
            </choose>
        </if>
    </select>

    <resultMap id="ExportExcelMapByDept" type="com.diagbot.dto.ExportExcelByDeptDTO">
        <result column="behDeptName" property="behDeptName"/>
        <result column="doctorName" property="doctorName"/>
        <result column="avgScore" property="avgScore"/>
        <collection property="excelBehospitalDTOS"
                    ofType="com.diagbot.dto.ExportExcelBehByDeptDTO">
            <result column="patName" property="patName"/>
            <result column="behospitalCode" property="behospitalCode"/>
            <result column="behospitalDate" property="behospitalDate"/>
            <result column="leaveHospitalDate" property="leaveHospitalDate"/>
            <result column="score" property="score"/>
            <result column="scoreBn" property="scoreBn"/>
            <collection property="exportExcelCaseDTOS" ofType="com.diagbot.dto.ExportExcelCaseDTO">
                <result column="caseName" property="caseName"/>
                <collection property="exportExcelMsgDTOS"
                            ofType="com.diagbot.dto.ExportExcelMsgDTO">
                    <result column="msg" property="msg"/>
                </collection>
            </collection>
        </collection>
    </resultMap>

    <resultMap id="ExportExcelMap" type="com.diagbot.dto.ExportExcelDTO">
        <result column="behDeptName" property="behDeptName"/>
        <result column="avgScore" property="avgScore"/>
        <collection property="excelBehospitalDTOS"
                    ofType="com.diagbot.dto.ExportExcelBehospitalDTO">
            <result column="doctorName" property="doctorName"/>
            <result column="patName" property="patName"/>
            <result column="behospitalCode" property="behospitalCode"/>
            <result column="behospitalDate" property="behospitalDate"/>
            <result column="leaveHospitalDate" property="leaveHospitalDate"/>
            <result column="score" property="score"/>
            <result column="scoreBn" property="scoreBn"/>
            <collection property="exportExcelCaseDTOS" ofType="com.diagbot.dto.ExportExcelCaseDTO">
                <result column="caseName" property="caseName"/>
                <collection property="exportExcelMsgDTOS"
                            ofType="com.diagbot.dto.ExportExcelMsgDTO">
                    <result column="msg" property="msg"/>
                </collection>
            </collection>
        </collection>
    </resultMap>


    <select id="exportExcel" resultMap="ExportExcelMap">
        SELECT DISTINCT
        t1.beh_dept_name AS behDeptName,
        t1.beh_doctor_name AS doctorName,
        t1.`name` AS patName,
        t1.behospital_code AS behospitalCode,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t2.score_res AS score,
        "1" AS avgScore,
        t4.`name` AS caseName,
        t3.msg AS msg
        FROM
        med_behospital_info t1,
        med_qcresult_info t2,
        med_qcresult_detail t3,
        qc_cases t4
        WHERE
        t1.is_deleted = 'N'
        AND t2.is_deleted = 'N'
        AND t3.is_deleted = 'N'
        AND t4.is_deleted = 'N'
        <![CDATA[AND t1.leave_hospital_date >= '2020-03-03 00:00:00']]>
        <![CDATA[AND t1.leave_hospital_date <= '2020-03-03 23:00:00']]>
        AND t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t1.hospital_id = t3.hospital_id
        AND t1.behospital_code = t3.behospital_code
        AND t3.cases_id = t4.id
        ORDER BY
        t1.beh_dept_id ASC,
        t1.leave_hospital_date DESC,
        t1.behospital_code ASC,
        t4.`name` ASC
    </select>


    <!-- 质控评分导出到excel-->
    <select id="exportQcresult" resultMap="ExportExcelMap" parameterType="com.diagbot.vo.ExportQcresultVO">
        SELECT * FROM (
        SELECT tp.*,CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type AS ch_type,
        h.check_type AS mr_type,
        g.check_name AS ch_name,
        h.check_name AS mr_name,
        g.check_time AS ch_time,
        h.check_time AS mr_time
        FROM (
        SELECT
        t1.behDeptId,
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        t1.behospitalCode,
        t1.hospitalId,
        t1.behospitalDate,
        t1.leaveHospitalDate,
        t1.score,
        <if test="radioCheck !=null and radioCheck == 1">
        t1.msg,
        t1.caseName,
        </if>
        t1.scoreBn,
        t2.avgScore
        FROM
        (
        SELECT
        a.doctor_name AS doctorName,
        a.`name` AS patName,
        a.behospital_code AS behospitalCode,
        a.behospital_date AS behospitalDate,
        a.leave_hospital_date AS leaveHospitalDate,
        b.score_res AS score,
        e.score_res as scoreBn,
        <if test="radioCheck !=null and radioCheck == 1">
        c.msg AS msg,
        d.NAME AS caseName,
        </if>
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName,
        a.hospital_id AS hospitalId
        FROM
        med_behospital_info a
        RIGHT JOIN
        med_qcresult_info b
        ON a.hospital_id = b.hospital_id
        AND a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.behospital_code = b.behospital_code
        <if test="radioCheck !=null and radioCheck == 1">
            LEFT JOIN
            med_qcresult_detail c
            ON c.is_deleted = 'N'
            AND b.behospital_code = c.behospital_code
            AND b.hospital_id = c.hospital_id
            LEFT JOIN
            qc_cases d
            on d.is_deleted = 'N'
            AND c.cases_id = d.id
        </if>
        LEFT JOIN med_qcresult_cases e
        on  b.behospital_code = e.behospital_code
        and b.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        WHERE
        1=1
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= DATE(#{leaveHosDateStart})]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < DATE(#{leaveHosDateEnd})]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        ) t1,
        (
        SELECT
        ROUND( AVG( b.score_res ), 2 ) AS avgScore,
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName
        FROM
        med_behospital_info a,
        med_qcresult_info b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= DATE(#{leaveHosDateStart})]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < DATE(#{leaveHosDateEnd})]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t2
        WHERE
        t1.behDeptId = t2.behDeptId
        AND t1.behDeptName = t2.behDeptName
        ORDER BY
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        <if test="radioCheck !=null and radioCheck == 1">
        t1.caseName,
        </if>
        t1.behospitalCode
       )tp
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type = 0 ) g
        ON tp.behospitalCode = g.behospital_code
        AND tp.hospitalId = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON tp.behospitalCode = h.behospital_code
        AND tp.hospitalId = h.hospital_id
        ) tu
        WHERE tu.behospitalCode IS NOT NULL
        <if test="checkStatus != null ">
            and tu.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND tu.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND tu.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND tu.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and tu.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and tu.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and tu.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and tu.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>

    <!-- 科室质控评分导出到excel-->
    <select  id="exportQcresultByDept" resultMap="ExportExcelMap" parameterType="com.diagbot.vo.ExportQcresultVO">
        SELECT * FROM (
        SELECT tp.*,CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type AS ch_type,
        h.check_type AS mr_type,
        g.check_name AS ch_name,
        h.check_name AS mr_name,
        g.check_time AS ch_time,
        h.check_time AS mr_time
        FROM (
        SELECT
        t1.behDeptId,
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        t1.behospitalCode,
        t1.hospitalId,
        t1.behospitalDate,
        t1.leaveHospitalDate,
        t1.score,
        t2.avgScore,
        <if test="radioCheck !=null and radioCheck == 1">
        t1.msg,
        t1.caseName,
        </if>
        e.score_res as scoreBn
        FROM
        (
        SELECT
        a.doctor_name AS doctorName,
        a.`name` AS patName,
        a.behospital_code AS behospitalCode,
        a.hospital_id AS hospital_id,
        a.behospital_date AS behospitalDate,
        a.leave_hospital_date AS leaveHospitalDate,
        b.score_res AS score,
        <if test="radioCheck !=null and radioCheck == 1">
            c.msg AS msg,
            d.NAME AS caseName,
        </if>
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName,
        a.hospital_id AS hospitalId
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases d,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.id
        AND a.beh_dept_id = e.dept_id
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="userId != null ">
            AND e.user_id = #{userId}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= DATE(#{leaveHosDateStart})]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < DATE(#{leaveHosDateEnd})]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        ) t1
        LEFT JOIN med_qcresult_cases e
        on  t1.behospitalCode = e.behospital_code
        and t1.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243,
        (
        SELECT
        ROUND( AVG( b.score_res ), 2 ) AS avgScore,
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.beh_dept_id = c.dept_id
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="userId != null ">
            AND c.user_id = #{userId}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= DATE(#{leaveHosDateStart})]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < DATE(#{leaveHosDateEnd})]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t2
        WHERE
        t1.behDeptId = t2.behDeptId
        AND t1.behDeptName = t2.behDeptName
        ORDER BY
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        <if test="radioCheck !=null and radioCheck == 1">
            t1.caseName,
        </if>
        t1.behospitalCode
        )tp
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type = 0 ) g
        ON tp.behospitalCode = g.behospital_code
        AND tp.hospitalId = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON tp.behospitalCode = h.behospital_code
        AND tp.hospitalId = h.hospital_id
        ) tu
        WHERE tu.behospitalCode IS NOT NULL
        <if test="checkStatus != null ">
            and tu.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND tu.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND tu.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND tu.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and tu.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and tu.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and tu.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and tu.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>
    <!-- 个人质控评分导出到excel-->
    <select  id="exportQcresultByPerson" resultMap="ExportExcelMap" parameterType="com.diagbot.vo.ExportQcresultVO">
        SELECT * FROM (
        SELECT tp.*,CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type AS ch_type,
        h.check_type AS mr_type,
        g.check_name AS ch_name,
        h.check_name AS mr_name,
        g.check_time AS ch_time,
        h.check_time AS mr_time
        FROM (
        SELECT
        t1.behDeptId,
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        t1.behospitalCode,
        t1.hospitalId,
        t1.behospitalDate,
        t1.leaveHospitalDate,
        t1.score,
        t2.avgScore,
        <if test="radioCheck !=null and radioCheck == 1">
            t1.msg,
            t1.caseName,
        </if>
        e.score_res as scoreBn
        FROM
        (
        SELECT
        a.doctor_name AS doctorName,
        a.beh_doctor_name,
        a.director_doctor_name,
        a.`name` AS patName,
        a.behospital_code AS behospitalCode,
        a.behospital_date AS behospitalDate,
        a.leave_hospital_date AS leaveHospitalDate,
        b.score_res AS score,
        <if test="radioCheck !=null and radioCheck == 1">
            c.msg AS msg,
            d.NAME AS caseName,
        </if>
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName,
        a.hospital_id AS hospitalId
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases d,
        sys_user u,
        sys_user_hospital uh
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND u.is_deleted = 'N'
        AND uh.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND u.id = uh.user_id
        AND a.hospital_id = uh.hospital_id
        <if test="userId != null and userId != ''">
            AND u.id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptId != null and deptId != ''">
            AND a.beh_dept_id = #{deptId}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        ) t1 LEFT JOIN med_qcresult_cases e
        on  t1.behospitalCode = e.behospital_code
        and t1.hospitalId = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243,
        (
        SELECT
        ROUND( AVG( b.score_res ), 2 ) AS avgScore,
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        sys_user u,
        sys_user_hospital uh
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND u.is_deleted = 'N'
        AND uh.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND u.id = uh.user_id
        AND a.hospital_id = uh.hospital_id
        and (a.doctor_name = u.linkman
        or  a.beh_doctor_name = u.linkman
        or  a.director_doctor_name = u.linkman)
        <if test="userId != null and userId != ''">
            AND u.id = #{userId}
        </if>
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= #{leaveHosDateStart}]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < #{leaveHosDateEnd}]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptId != null and deptId != ''">
            AND a.beh_dept_id = #{deptId}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        ) t2
        WHERE
        t1.behDeptId = t2.behDeptId
        AND t1.behDeptName = t2.behDeptName
        ORDER BY
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        <if test="radioCheck !=null and radioCheck == 1">
            t1.caseName,
        </if>
        t1.behospitalCode
        )tp
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type = 0 ) g
        ON tp.behospitalCode = g.behospital_code
        AND tp.hospitalId = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON tp.behospitalCode = h.behospital_code
        AND tp.hospitalId = h.hospital_id
        ) tu
        WHERE tu.behospitalCode IS NOT NULL
        <if test="checkStatus != null ">
            and tu.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND tu.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND tu.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND tu.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and tu.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and tu.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and tu.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and tu.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>
    <!-- 医疗组质控评分导出到excel-->
    <select  id="exportQcresultByGroup" resultMap="ExportExcelMap" parameterType="com.diagbot.vo.ExportQcresultVO">
        SELECT * FROM (
        SELECT tp.*,CASE WHEN ISNULL(g.status) THEN 0 ELSE g.status END check_status,
        CASE WHEN ISNULL(h.status) THEN 0 ELSE h.status END mr_status,
        g.check_type AS ch_type,
        h.check_type AS mr_type,
        g.check_name AS ch_name,
        h.check_name AS mr_name,
        g.check_time AS ch_time,
        h.check_time AS mr_time
        FROM (
        SELECT
        t1.behDeptId,
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        t1.behospitalCode,
        t1.hospitalId,
        t1.behospitalDate,
        t1.leaveHospitalDate,
        t1.score,
        t2.avgScore,
        <if test="radioCheck !=null and radioCheck == 1">
            t1.msg,
            t1.caseName,
        </if>
        e.score_res as scoreBn
        FROM
        (
        SELECT
        a.doctor_name AS doctorName,
        a.`name` AS patName,
        a.behospital_code AS behospitalCode,
        a.behospital_date AS behospitalDate,
        a.leave_hospital_date AS leaveHospitalDate,
        b.score_res AS score,
        <if test="radioCheck !=null and radioCheck == 1">
            c.msg AS msg,
            d.NAME AS caseName,
        </if>
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName,
        a.hospital_id AS hospitalId
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.doctor_id in
        (SELECT doctor_id FROM `bas_doctor_info`
        where is_deleted = 'N' and hospital_id = #{hospitalId} and group_id in (
        select c3.group_id from sys_user c1, sys_user_hospital c2, bas_doctor_info c3
        where c1.is_deleted = 'N' and c2.is_deleted = 'N' and c3.is_deleted = 'N'
        and c1.id = c2.user_id and c2.hospital_id = c3.hospital_id
        and c1.username = c3.doctor_id
        and c2.hospital_id = #{hospitalId}
        and c1.id = #{userId}
        ))
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= DATE(#{leaveHosDateStart})]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < DATE(#{leaveHosDateEnd})]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptId != null and deptId != ''">
            AND a.beh_dept_id = #{deptId}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        ) t1 LEFT JOIN med_qcresult_cases e
        on  t1.behospitalCode = e.behospital_code
        and t1.hospitalId = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243,
        (
        SELECT
        ROUND( AVG( b.score_res ), 2 ) AS avgScore,
        a.beh_dept_id AS behDeptId,
        a.beh_dept_name AS behDeptName
        FROM
        med_behospital_info a,
        med_qcresult_info b
        WHERE
        a.is_deleted = 'N'
        AND a.doctor_id in
        (SELECT doctor_id FROM `bas_doctor_info`
        where is_deleted = 'N' and hospital_id = #{hospitalId} and group_id in (
        select c3.group_id from sys_user c1, sys_user_hospital c2, bas_doctor_info c3
        where c1.is_deleted = 'N' and c2.is_deleted = 'N' and c3.is_deleted = 'N'
        and c1.id = c2.user_id and c2.hospital_id = c3.hospital_id
        and c1.username = c3.doctor_id
        and c2.hospital_id = #{hospitalId}
        and c1.id = #{userId}
        ))
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <![CDATA[AND a.qc_type_id <>0 ]]>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="behosDateStart != null">
            <![CDATA[ and a.behospital_date >= #{behosDateStart}]]>
        </if>
        <if test="behosDateEnd != null">
            <![CDATA[ and a.behospital_date < #{behosDateEnd}]]>
        </if>
        <if test="leaveHosDateStart != null ">
            <![CDATA[ and a.leave_hospital_date >= DATE(#{leaveHosDateStart})]]>
        </if>
        <if test="leaveHosDateEnd != null ">
            <![CDATA[AND a.leave_hospital_date < DATE(#{leaveHosDateEnd})]]>
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code like CONCAT('%',#{behospitalCode},'%')
        </if>
        <if test="level != null and level != ''">
            AND b.level = #{level}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND (a.doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.beh_doctor_name like CONCAT('%',#{doctorName},'%')
            OR a.director_doctor_name like CONCAT('%',#{doctorName},'%'))
        </if>
        <if test="doctorCode != null and doctorCode != ''">
            AND (a.doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.beh_doctor_id like CONCAT('%',#{doctorCode},'%')
            OR a.director_doctor_id like CONCAT('%',#{doctorCode},'%'))
        </if>
        <if test="deptId != null and deptId != ''">
            AND a.beh_dept_id = #{deptId}
        </if>
        <if test="name != null and name != ''">
            AND a.name like CONCAT('%',#{name},'%')
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) t2
        WHERE
        t1.behDeptId = t2.behDeptId
        AND t1.behDeptName = t2.behDeptName
        ORDER BY
        t1.behDeptName,
        t1.doctorName,
        t1.patName,
        <if test="radioCheck !=null and radioCheck == 1">
            t1.caseName,
        </if>
        t1.behospitalCode
        )tp
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N' AND check_type = 0 ) g
        ON tp.behospitalCode = g.behospital_code
        AND tp.hospitalId = g.hospital_id
        LEFT JOIN (SELECT * FROM med_check_info WHERE is_deleted = 'N'AND check_type = 1 ) h
        ON tp.behospitalCode = h.behospital_code
        AND tp.hospitalId = h.hospital_id
        ) tu
        WHERE tu.behospitalCode IS NOT NULL
        <if test="checkStatus != null ">
            and tu.check_status = #{checkStatus}
        </if>
        <if test="mrStatus != null ">
            AND tu.mr_status = #{mrStatus}
        </if>
        <if test="chName != null and chName !=''">
            AND tu.ch_name like CONCAT('%',#{chName},'%')
        </if>
        <if test="mrName != null and mrName !=''">
            AND tu.mr_name like CONCAT('%',#{mrName},'%')
        </if>
        <if test="chTimeStart != null">
            <![CDATA[ and tu.ch_time >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null">
            <![CDATA[ and tu.ch_time < #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null">
            <![CDATA[ and tu.mr_time >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null">
            <![CDATA[ and tu.mr_time < #{mrTimeEnd}]]>
        </if>
    </select>

    <!-- 条目缺陷质控评分页（内页）湘雅-->
    <select id="qcResultShortXYPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctorId,
        t1.doctor_name AS doctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,''),ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        f.doctor_id as doctorId,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        case
        when e.attending_doctor != '' and e.attending_doctor is not null then e.attending_doctor
        when (e.attending_doctor = '' or e.attending_doctor is null) and
        e.director_doctor != '' and e.director_doctor is not null
        then e.director_doctor
        when (e.attending_doctor = '' or e.attending_doctor is null) and
        (e.director_doctor = '' or e.director_doctor is null) and
        e.behospital_doctor != '' and e.behospital_doctor is not null
        then e.behospital_doctor end as doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        med_home_page e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = e.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND(case
            when e.attending_doctor != '' and e.attending_doctor is not null then e.attending_doctor
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            e.director_doctor != '' and e.director_doctor is not null
            then e.director_doctor
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            (e.director_doctor = '' or e.director_doctor is null) and
            e.behospital_doctor != '' and e.behospital_doctor is not null
            then e.behospital_doctor end ) LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.professor != null and qcResultShortPageVO.professor != ''">
            AND(case
            when e.attending_doctor != '' and e.attending_doctor is not null then '主治医师'
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            e.director_doctor != '' and e.director_doctor is not null
            then '主任医师'
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            (e.director_doctor = '' or e.director_doctor is null) and
            e.behospital_doctor != '' and e.behospital_doctor is not null
            then '住院医师' end) = #{qcResultShortPageVO.professor}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        LEFT JOIN bas_doctor_info f
        on be.hospital_id = f.hospital_id
        and be.doctor_name = f.name
        AND f.is_deleted = 'N'
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        where 1=1
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND t.doctorId = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 条目缺陷质控评分页（内页)-->
    <select id="qcResultShortPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,''),ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 条目缺陷质控评分页-科室（内页）-->
    <select id="qcResultShortByDeptPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,''),ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = e.dept_id
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND e.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND a.doctor_id = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <update id="updateBatchByKey">
        <foreach collection="list" item="item"  separator=";">
            update med_behospital_info
            <set>
                <if test="item.name != null">
                    name = #{item.name},
                </if>
                <if test="item.sex != null">
                    sex = #{item.sex},
                </if>
                <if test="item.birthday != null">
                    birthday = #{item.birthday},
                </if>
                <if test="item.fileCode != null">
                    file_code = #{item.fileCode},
                </if>
                <if test="item.qcTypeId != null">
                    qc_type_id = #{item.qcTypeId},
                </if>
                <if test="item.wardCode != null">
                    ward_code = #{item.wardCode},
                </if>
                <if test="item.wardName != null">
                    ward_name = #{item.wardName},
                </if>
                <if test="item.behDeptId != null">
                    beh_dept_id = #{item.behDeptId},
                </if>
                <if test="item.behDeptName != null">
                    beh_dept_name = #{item.behDeptName},
                </if>
                <if test="item.bedCode != null">
                    bed_code = #{item.bedCode},
                </if>
                <if test="item.bedName != null">
                    bed_name = #{item.bedName},
                </if>
                <if test="item.insuranceName != null">
                    insurance_name = #{item.insuranceName},
                </if>
                <if test="item.jobType != null">
                    job_type = #{item.jobType},
                </if>
                <if test="item.behospitalDate != null">
                    behospital_date = #{item.behospitalDate},
                </if>
                <if test="item.leaveHospitalDate != null">
                    leave_hospital_date = #{item.leaveHospitalDate},
                </if>
                <if test="item.diagnoseIcd != null">
                    diagnose_icd = #{item.diagnoseIcd},
                </if>
                <if test="item.diagnose != null">
                    diagnose = #{item.diagnose},
                </if>
                <if test="item.behDoctorId != null">
                    beh_doctor_id = #{item.behDoctorId},
                </if>
                <if test="item.behDoctorName != null">
                    beh_doctor_name = #{item.behDoctorName},
                </if>
                <if test="item.doctorId != null">
                    doctor_id = #{item.doctorId},
                </if>
                <if test="item.doctorName != null">
                    doctor_name = #{item.doctorName},
                </if>
                <if test="item.directorDoctorId != null">
                    director_doctor_id = #{item.directorDoctorId},
                </if>
                <if test="item.directorDoctorName != null">
                    director_doctor_name = #{item.directorDoctorName},
                </if>
                <if test="item.placefileDate != null">
                    placefile_date = #{item.placefileDate},
                </if>
                <if test="item.isPlacefile != null">
                    is_placefile = #{item.isPlacefile},
                </if>
                <if test="item.gmtModified != null">
                    gmt_modified = #{item.gmtModified},
                </if>
                <if test="item.modifier != null">
                    modifier = #{item.modifier},
                </if>
            </set>
            where behospital_code = #{item.behospitalCode} and hospital_id = #{item.hospitalId}
        </foreach>
    </update>

    <!-- 关键条目缺陷统计报表-->
    <select id="entryStatistics" parameterType="com.diagbot.vo.EntryStatisticsVO" resultType="com.diagbot.dto.EntryStatisticsDTO">
        SELECT
        deptId,
        deptName,
        consultationMRNum,
        consultationNum,
        2511 AS consultationEntryId,
        '普通会诊未在24小时内完成' AS consultationEntryName,
        ROUND( IFNULL( consultationNum / consultationMRNum, 0 ), 4 ) AS consultationPercent,
        CONCAT( ROUND( IFNULL( consultationNum / consultationMRNum, 0 ) * 100, 2 ), '%' ) AS consultationPercentStr,
        operationMRNum,
        2594 AS operationNameEntryId,
        '首页手术名称与手术记录不一致' AS operationNameEntryName,
        operationNameNum,
        ROUND( IFNULL( operationNameNum / operationMRNum, 0 ), 4 ) AS operationNamePercent,
        CONCAT( ROUND( IFNULL( operationNameNum / operationMRNum, 0 ) * 100, 2 ), '%' ) AS operationNamePercentStr,
        2973 AS operationTimeEntryId,
        '手术日期与手术记录中手术日期不一致' AS operationTimeEntryName,
        operationTimeNum,
        ROUND( IFNULL( operationTimeNum / operationMRNum, 0 ), 4 ) AS operationTimePercent,
        CONCAT( ROUND( IFNULL( operationTimeNum / operationMRNum, 0 ) * 100, 2 ), '%' ) AS operationTimePercentStr,
        2930 AS operation15MinuteEntryId,
        '术后首次病程未即刻完成' AS operation15MinuteEntryName,
        operation15MinuteNum,
        ROUND( IFNULL( operation15MinuteNum / operationMRNum, 0 ), 4 ) AS operation15MinutePercent,
        CONCAT( ROUND( IFNULL( operation15MinuteNum / operationMRNum, 0 ) * 100, 2 ), '%' ) AS operation15MinutePercentStr,
        2419 AS crisisEntryId,
        '危急值记录未在接到危急值报告后6小时内完成' AS crisisEntryName,
        crisisMRNum,
        crisisNum,
        ROUND( IFNULL( crisisNum / crisisMRNum, 0 ), 4 ) AS crisisPercent,
        CONCAT( ROUND( IFNULL( crisisNum / crisisMRNum, 0 ) * 100, 2 ), '%' ) AS crisisPercentStr,
        2495 AS stageSummaryEntryId,
        '无阶段小结' AS stageSummaryEntryName,
        stageSummaryMRNum,
        stageSummaryNum,
        ROUND( IFNULL( stageSummaryNum / stageSummaryMRNum, 0 ), 4 ) AS stageSummaryPercent,
        CONCAT( ROUND( IFNULL( stageSummaryNum / stageSummaryMRNum, 0 ) * 100, 2 ), '%' ) AS stageSummaryPercentStr,
        beHosGT31DaysMRNum
        FROM
        (
        SELECT
        tt.deptId,
        tt.deptName,
        sum( tt.consultationNum ) AS consultationNum,
        sum( tt.consultationMRNum ) AS consultationMRNum,
        sum( tt.operationNameNum ) AS operationNameNum,
        sum( tt.operationTimeNum ) AS operationTimeNum,
        sum( tt.operation15MinuteNum ) AS operation15MinuteNum,
        sum( tt.operationMRNum ) AS operationMRNum,
        sum( tt.crisisNum ) AS crisisNum,
        sum( tt.crisisMRNum ) AS crisisMRNum,
        sum( tt.stageSummaryNum ) AS stageSummaryNum,
        sum( tt.stageSummaryMRNum ) AS stageSummaryMRNum,
        sum( tt.beHosGT31DaysMRNum ) AS beHosGT31DaysMRNum
        FROM
        (
        (
        SELECT
        c.beh_dept_id AS deptId,
        c.beh_dept_name AS deptName,
        sum( d.cases_entry_id = 2511 ) AS consultationNum,
        count( DISTINCT c.behospital_code ) AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id
        FROM
        med_behospital_info a,
        med_medical_record b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND b.mode_id = 30
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) c
        LEFT JOIN med_qcresult_detail d ON d.is_deleted = 'N'
        AND c.hospital_id = d.hospital_id
        AND c.behospital_code = d.behospital_code
        GROUP BY
        c.beh_dept_id,
        c.beh_dept_name
        ) UNION
        (
        SELECT
        d.beh_dept_id AS deptId,
        d.beh_dept_name AS deptName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        sum( e.cases_entry_id = 2594 ) AS operationNameNum,
        sum( e.cases_entry_id = 2973 ) AS operationTimeNum,
        sum( e.cases_entry_id = 2930 ) AS operation15MinuteNum,
        count( DISTINCT d.behospital_code ) AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id
        FROM
        med_behospital_info a,
        med_home_page b,
        med_home_operation_info c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND b.home_page_id = c.home_page_id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) d
        LEFT JOIN med_qcresult_detail e ON e.is_deleted = 'N'
        AND d.hospital_id = e.hospital_id
        AND d.behospital_code = e.behospital_code
        GROUP BY
        d.beh_dept_id,
        d.beh_dept_name
        ) UNION
        (
        SELECT
        c.beh_dept_id AS deptId,
        c.beh_dept_name AS deptName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        sum( d.cases_entry_id = 2419 ) AS crisisNum,
        count( DISTINCT c.behospital_code ) AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id
        FROM
        med_behospital_info a,
        med_crisis_info b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) c
        LEFT JOIN med_qcresult_detail d ON d.is_deleted = 'N'
        AND c.hospital_id = d.hospital_id
        AND c.behospital_code = d.behospital_code
        GROUP BY
        c.beh_dept_id,
        c.beh_dept_name
        ) UNION
        (
        SELECT
        b.beh_dept_id AS deptId,
        b.beh_dept_name AS deptName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        sum( c.cases_entry_id = 2495 ) AS stageSummaryNum,
        count( DISTINCT b.behospital_code ) AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        AND TIMESTAMPDIFF(
        DAY,
        DATE( behospital_date ),
        DATE( leave_hospital_date ))> 30
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) b
        LEFT JOIN med_qcresult_detail c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        GROUP BY
        b.beh_dept_id,
        b.beh_dept_name
        ) UNION
        (
        SELECT
        b.beh_dept_id AS deptId,
        b.beh_dept_name AS deptName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        count(*) AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND TIMESTAMPDIFF(
        DAY,
        DATE( behospital_date ),
        DATE( leave_hospital_date ))> 31
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        ) b
        GROUP BY
        b.beh_dept_id,
        b.beh_dept_name
        )
        ) tt
        GROUP BY
        tt.deptId,
        tt.deptName
        ) t
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>deptId asc</when>
                <when test='asc=="deptName"'>deptName asc</when>
                <when test='asc=="consultationNum"'>consultationNum asc</when>
                <when test='asc=="consultationPercent"'>consultationPercent asc</when>
                <when test='asc=="consultationPercentStr"'>consultationPercent asc</when>
                <when test='asc=="consultationMRNum"'>consultationMRNum asc</when>
                <when test='asc=="operationNameNum"'>operationNameNum asc</when>
                <when test='asc=="operationNamePercent"'>operationNamePercent asc</when>
                <when test='asc=="operationNamePercentStr"'>operationNamePercent asc</when>
                <when test='asc=="operationTimeNum"'>operationTimeNum asc</when>
                <when test='asc=="operationTimePercent"'>operationTimePercent asc</when>
                <when test='asc=="operationTimePercentStr"'>operationTimePercent asc</when>
                <when test='asc=="operation15MinuteNum"'>operation15MinuteNum asc</when>
                <when test='asc=="operation15MinutePercent"'>operation15MinutePercent asc</when>
                <when test='asc=="operation15MinutePercentStr"'>operation15MinutePercent asc</when>
                <when test='asc=="operationMRNum"'>operationMRNum asc</when>
                <when test='asc=="crisisNum"'>crisisNum asc</when>
                <when test='asc=="crisisPercent"'>crisisPercent asc</when>
                <when test='asc=="crisisPercentStr"'>crisisPercent asc</when>
                <when test='asc=="crisisMRNum"'>crisisMRNum asc</when>
                <when test='asc=="stageSummaryNum"'>stageSummaryNum asc</when>
                <when test='asc=="stageSummaryPercent"'>stageSummaryPercent asc</when>
                <when test='asc=="stageSummaryPercentStr"'>stageSummaryPercent asc</when>
                <when test='asc=="stageSummaryMRNum"'>stageSummaryMRNum asc</when>
                <when test='asc=="beHosGT31DaysMRNum"'>beHosGT31DaysMRNum asc</when>
                <otherwise>deptName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>deptId desc</when>
                <when test='desc=="deptName"'>deptName desc</when>
                <when test='desc=="consultationNum"'>consultationNum desc</when>
                <when test='desc=="consultationPercent"'>consultationPercent desc</when>
                <when test='desc=="consultationPercentStr"'>consultationPercent desc</when>
                <when test='desc=="consultationMRNum"'>consultationMRNum desc</when>
                <when test='desc=="operationNameNum"'>operationNameNum desc</when>
                <when test='desc=="operationNamePercent"'>operationNamePercent desc</when>
                <when test='desc=="operationNamePercentStr"'>operationNamePercent desc</when>
                <when test='desc=="operationTimeNum"'>operationTimeNum desc</when>
                <when test='desc=="operationTimePercent"'>operationTimePercent desc</when>
                <when test='desc=="operationTimePercentStr"'>operationTimePercent desc</when>
                <when test='desc=="operation15MinuteNum"'>operation15MinuteNum desc</when>
                <when test='desc=="operation15MinutePercent"'>operation15MinutePercent desc</when>
                <when test='desc=="operation15MinutePercentStr"'>operation15MinutePercent desc</when>
                <when test='desc=="operationMRNum"'>operationMRNum desc</when>
                <when test='desc=="crisisNum"'>crisisNum desc</when>
                <when test='desc=="crisisPercent"'>crisisPercent desc</when>
                <when test='desc=="crisisPercentStr"'>crisisPercent desc</when>
                <when test='desc=="crisisMRNum"'>crisisMRNum desc</when>
                <when test='desc=="stageSummaryNum"'>stageSummaryNum desc</when>
                <when test='desc=="stageSummaryPercent"'>stageSummaryPercent desc</when>
                <when test='desc=="stageSummaryPercentStr"'>stageSummaryPercent desc</when>
                <when test='desc=="stageSummaryMRNum"'>stageSummaryMRNum desc</when>
                <when test='desc=="beHosGT31DaysMRNum"'>beHosGT31DaysMRNum desc</when>
                <otherwise>deptName desc</otherwise>
            </choose>
        </if>
    </select>


    <!-- 关键条目缺陷统计报表-科室-->
    <select id="entryStatisticsByDept" parameterType="com.diagbot.vo.EntryStatisticsVO" resultType="com.diagbot.dto.EntryStasByDeptDTO">
        SELECT
        deptId,
        deptName,
        doctorName,
        consultationMRNum,
        consultationNum,
        2511 AS consultationEntryId,
        '普通会诊未在24小时内完成' AS consultationEntryName,
        ROUND( IFNULL( consultationNum / consultationMRNum, 0 ), 4 ) AS consultationPercent,
        CONCAT( ROUND( IFNULL( consultationNum / consultationMRNum, 0 ) * 100, 2 ), '%' ) AS consultationPercentStr,
        operationMRNum,
        2594 AS operationNameEntryId,
        '首页手术名称与手术记录不一致' AS operationNameEntryName,
        operationNameNum,
        ROUND( IFNULL( operationNameNum / operationMRNum, 0 ), 4 ) AS operationNamePercent,
        CONCAT( ROUND( IFNULL( operationNameNum / operationMRNum, 0 ) * 100, 2 ), '%' ) AS operationNamePercentStr,
        2973 AS operationTimeEntryId,
        '手术日期与手术记录中手术日期不一致' AS operationTimeEntryName,
        operationTimeNum,
        ROUND( IFNULL( operationTimeNum / operationMRNum, 0 ), 4 ) AS operationTimePercent,
        CONCAT( ROUND( IFNULL( operationTimeNum / operationMRNum, 0 ) * 100, 2 ), '%' ) AS operationTimePercentStr,
        2930 AS operation15MinuteEntryId,
        '术后首次病程未即刻完成' AS operation15MinuteEntryName,
        operation15MinuteNum,
        ROUND( IFNULL( operation15MinuteNum / operationMRNum, 0 ), 4 ) AS operation15MinutePercent,
        CONCAT( ROUND( IFNULL( operation15MinuteNum / operationMRNum, 0 ) * 100, 2 ), '%' ) AS operation15MinutePercentStr,
        2419 AS crisisEntryId,
        '危急值记录未在接到危急值报告后6小时内完成' AS crisisEntryName,
        crisisMRNum,
        crisisNum,
        ROUND( IFNULL( crisisNum / crisisMRNum, 0 ), 4 ) AS crisisPercent,
        CONCAT( ROUND( IFNULL( crisisNum / crisisMRNum, 0 ) * 100, 2 ), '%' ) AS crisisPercentStr,
        2495 AS stageSummaryEntryId,
        '无阶段小结' AS stageSummaryEntryName,
        stageSummaryMRNum,
        stageSummaryNum,
        ROUND( IFNULL( stageSummaryNum / stageSummaryMRNum, 0 ), 4 ) AS stageSummaryPercent,
        CONCAT( ROUND( IFNULL( stageSummaryNum / stageSummaryMRNum, 0 ) * 100, 2 ), '%' ) AS stageSummaryPercentStr,
        beHosGT31DaysMRNum
        FROM
        (
        SELECT
        tt.deptId,
        tt.deptName,
        tt.doctorId,
        tt.doctorName,
        sum( tt.consultationNum ) AS consultationNum,
        sum( tt.consultationMRNum ) AS consultationMRNum,
        sum( tt.operationNameNum ) AS operationNameNum,
        sum( tt.operationTimeNum ) AS operationTimeNum,
        sum( tt.operation15MinuteNum ) AS operation15MinuteNum,
        sum( tt.operationMRNum ) AS operationMRNum,
        sum( tt.crisisNum ) AS crisisNum,
        sum( tt.crisisMRNum ) AS crisisMRNum,
        sum( tt.stageSummaryNum ) AS stageSummaryNum,
        sum( tt.stageSummaryMRNum ) AS stageSummaryMRNum,
        sum( tt.beHosGT31DaysMRNum ) AS beHosGT31DaysMRNum
        FROM
        (
        (
        SELECT
        c.beh_dept_id AS deptId,
        c.beh_dept_name AS deptName,
        c.doctorId,
        c.doctorName,
        sum( d.cases_entry_id = 2511 ) AS consultationNum,
        count( DISTINCT c.behospital_code ) AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName
        FROM
        med_behospital_info a,
        med_medical_record b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.beh_dept_id = c.dept_id
        AND b.mode_id = 30
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name = #{deptName}
        </if>
        ) c
        LEFT JOIN med_qcresult_detail d ON d.is_deleted = 'N'
        AND c.hospital_id = d.hospital_id
        AND c.behospital_code = d.behospital_code
        GROUP BY
        c.doctorId,
        c.doctorName
        ) UNION
        (
        SELECT
        d.beh_dept_id AS deptId,
        d.beh_dept_name AS deptName,
        d.doctor_id as doctorId,
        d.doctor_name as doctorName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        sum( e.cases_entry_id = 2594 ) AS operationNameNum,
        sum( e.cases_entry_id = 2973 ) AS operationTimeNum,
        sum( e.cases_entry_id = 2930 ) AS operation15MinuteNum,
        count( DISTINCT d.behospital_code ) AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id,
        a.doctor_id,
        a.doctor_name
        FROM
        med_behospital_info a,
        med_home_page b,
        med_home_operation_info c,
        sys_user_dept d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = b.behospital_code
        AND b.home_page_id = c.home_page_id
        AND a.beh_dept_id = d.dept_id
        <if test="userId!=null">
            AND d.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name = #{deptName}
        </if>
            ) d
        LEFT JOIN med_qcresult_detail e ON e.is_deleted = 'N'
        AND d.hospital_id = e.hospital_id
        AND d.behospital_code = e.behospital_code
        GROUP BY
        d.doctor_id,
        d.doctor_name
        ) UNION
        (
        SELECT
        c.beh_dept_id AS deptId,
        c.beh_dept_name AS deptName,
        c.doctor_id as doctorId,
        c.doctor_name as doctorName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        sum( d.cases_entry_id = 2419 ) AS crisisNum,
        count( DISTINCT c.behospital_code ) AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id,
        a.doctor_id,
        a.doctor_name
        FROM
        med_behospital_info a,
        med_crisis_info b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.beh_dept_id = c.dept_id
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name = #{deptName}
        </if>
        ) c
        LEFT JOIN med_qcresult_detail d ON d.is_deleted = 'N'
        AND c.hospital_id = d.hospital_id
        AND c.behospital_code = d.behospital_code
        GROUP BY
        c.doctor_id,
        c.doctor_name
        ) UNION
        (
        SELECT
        b.beh_dept_id AS deptId,
        b.beh_dept_name AS deptName,
        b.doctor_id as doctorId,
        b.doctor_name as doctorName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        sum( c.cases_entry_id = 2495 ) AS stageSummaryNum,
        count( DISTINCT b.behospital_code ) AS stageSummaryMRNum,
        0 AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id,
        a.doctor_id,
        a.doctor_name
        FROM
        med_behospital_info a,
        sys_user_dept b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.beh_dept_id = b.dept_id
        AND TIMESTAMPDIFF(
        DAY,
        DATE( behospital_date ),
        DATE( leave_hospital_date ))> 30
        <if test="userId!=null">
            AND b.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name = #{deptName}
        </if>
        ) b
        LEFT JOIN med_qcresult_detail c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        GROUP BY
        b.doctor_id,
        b.doctor_name
        ) UNION
        (
        SELECT
        b.beh_dept_id AS deptId,
        b.beh_dept_name AS deptName,
        b.doctor_id as doctorId,
        b.doctor_name as doctorName,
        0 AS consultationNum,
        0 AS consultationMRNum,
        0 AS operationNameNum,
        0 AS operationTimeNum,
        0 AS operation15MinuteNum,
        0 AS operationMRNum,
        0 AS crisisNum,
        0 AS crisisMRNum,
        0 AS stageSummaryNum,
        0 AS stageSummaryMRNum,
        count(*) AS beHosGT31DaysMRNum
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.beh_dept_name,
        a.beh_dept_id,
        a.doctor_id,
        a.doctor_name
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.beh_dept_id = e.dept_id
        AND TIMESTAMPDIFF(
        DAY,
        DATE( behospital_date ),
        DATE( leave_hospital_date ))> 31
        <if test="userId!=null">
            AND e.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name = #{deptName}
        </if>
        ) b
        GROUP BY
        b.doctor_id,
        b.doctor_name
        )
        ) tt
        GROUP BY
        tt.doctorName
        ) t
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>deptId asc</when>
                <when test='asc=="deptName"'>deptName asc</when>
                <when test='asc=="doctorName"'>doctorName asc</when>
                <when test='asc=="consultationNum"'>consultationNum asc</when>
                <when test='asc=="consultationPercent"'>consultationPercent asc</when>
                <when test='asc=="consultationPercentStr"'>consultationPercent asc</when>
                <when test='asc=="consultationMRNum"'>consultationMRNum asc</when>
                <when test='asc=="operationNameNum"'>operationNameNum asc</when>
                <when test='asc=="operationNamePercent"'>operationNamePercent asc</when>
                <when test='asc=="operationNamePercentStr"'>operationNamePercent asc</when>
                <when test='asc=="operationTimeNum"'>operationTimeNum asc</when>
                <when test='asc=="operationTimePercent"'>operationTimePercent asc</when>
                <when test='asc=="operationTimePercentStr"'>operationTimePercent asc</when>
                <when test='asc=="operation15MinuteNum"'>operation15MinuteNum asc</when>
                <when test='asc=="operation15MinutePercent"'>operation15MinutePercent asc</when>
                <when test='asc=="operation15MinutePercentStr"'>operation15MinutePercent asc</when>
                <when test='asc=="operationMRNum"'>operationMRNum asc</when>
                <when test='asc=="crisisNum"'>crisisNum asc</when>
                <when test='asc=="crisisPercent"'>crisisPercent asc</when>
                <when test='asc=="crisisPercentStr"'>crisisPercent asc</when>
                <when test='asc=="crisisMRNum"'>crisisMRNum asc</when>
                <when test='asc=="stageSummaryNum"'>stageSummaryNum asc</when>
                <when test='asc=="stageSummaryPercent"'>stageSummaryPercent asc</when>
                <when test='asc=="stageSummaryPercentStr"'>stageSummaryPercent asc</when>
                <when test='asc=="stageSummaryMRNum"'>stageSummaryMRNum asc</when>
                <when test='asc=="beHosGT31DaysMRNum"'>beHosGT31DaysMRNum asc</when>
                <otherwise>doctorName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>deptId desc</when>
                <when test='desc=="doctorName"'>doctorName desc</when>
                <when test='desc=="deptName"'>deptName desc</when>
                <when test='desc=="consultationNum"'>consultationNum desc</when>
                <when test='desc=="consultationPercent"'>consultationPercent desc</when>
                <when test='desc=="consultationPercentStr"'>consultationPercent desc</when>
                <when test='desc=="consultationMRNum"'>consultationMRNum desc</when>
                <when test='desc=="operationNameNum"'>operationNameNum desc</when>
                <when test='desc=="operationNamePercent"'>operationNamePercent desc</when>
                <when test='desc=="operationNamePercentStr"'>operationNamePercent desc</when>
                <when test='desc=="operationTimeNum"'>operationTimeNum desc</when>
                <when test='desc=="operationTimePercent"'>operationTimePercent desc</when>
                <when test='desc=="operationTimePercentStr"'>operationTimePercent desc</when>
                <when test='desc=="operation15MinuteNum"'>operation15MinuteNum desc</when>
                <when test='desc=="operation15MinutePercent"'>operation15MinutePercent desc</when>
                <when test='desc=="operation15MinutePercentStr"'>operation15MinutePercent desc</when>
                <when test='desc=="operationMRNum"'>operationMRNum desc</when>
                <when test='desc=="crisisNum"'>crisisNum desc</when>
                <when test='desc=="crisisPercent"'>crisisPercent desc</when>
                <when test='desc=="crisisPercentStr"'>crisisPercent desc</when>
                <when test='desc=="crisisMRNum"'>crisisMRNum desc</when>
                <when test='desc=="stageSummaryNum"'>stageSummaryNum desc</when>
                <when test='desc=="stageSummaryPercent"'>stageSummaryPercent desc</when>
                <when test='desc=="stageSummaryPercentStr"'>stageSummaryPercent desc</when>
                <when test='desc=="stageSummaryMRNum"'>stageSummaryMRNum desc</when>
                <when test='desc=="beHosGT31DaysMRNum"'>beHosGT31DaysMRNum desc</when>
                <otherwise>doctorName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 非医嘱离院病人记录-->
    <select id="nonAdviceCount" resultType="int" parameterType="com.diagbot.vo.FilterVO">
        SELECT
        count(*)
        FROM
        med_behospital_info a,
        med_home_page b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND b.leave_hospital_type = '非医嘱离院'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
    </select>

    <!-- 31天内再入院记录-->
    <select id="get31DaysBehospitalCount" resultType="int" parameterType="com.diagbot.vo.FilterVO">
        SELECT
        count(*)
        FROM
        (
        SELECT
        r1.file_code,
        r1.diagnose,
        r1.behospital_code AS behospitalCode,
        r1.behospital_date AS behospitalDate,
        r1.leave_hospital_date AS leaveHospitalDate,
        r2.behospital_code AS lastBehospitalCode,
        r2.behospital_date AS lastBehospitalDate,
        r2.leave_hospital_date AS lastLeaveHospitalDate,
        TIMESTAMPDIFF( DAY, DATE( r2.leave_hospital_date ), DATE( r1.behospital_date ) ) AS diffDays
        FROM
        (
        SELECT
        ( @rownum := @rownum + 1 ) AS rownum,
        t1.file_code,
        t1.diagnose,
        t1.behospital_code,
        t1.behospital_date,
        t1.leave_hospital_date
        FROM
        (
        SELECT
        tt1.file_code,
        tt1.diagnose,
        tt2.behospital_code,
        tt2.behospital_date,
        tt2.leave_hospital_date
        FROM
        (
        SELECT
        a.file_code,
        a.diagnose
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        AND IFNULL( a.diagnose, '' )!= ''
        AND IFNULL( a.file_code, '' )!= ''
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.file_code,
        a.diagnose
        HAVING
        count(*)> 1
        ) tt1,
        med_behospital_info tt2
        WHERE
        tt2.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and tt2.is_placefile = #{isPlacefile}
        </if>
        AND tt2.qc_type_id != 0
        AND tt1.file_code = tt2.file_code
        AND tt1.diagnose = tt2.diagnose
        <if test="hospitalId != null and hospitalId != ''">
            AND tt2.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND tt2.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND tt2.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND tt2.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND tt2.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        ORDER BY
        tt1.file_code,
        tt1.diagnose,
        tt2.behospital_date DESC
        ) t1,
        ( SELECT @rownum := 0 ) r
        ) r1
        LEFT JOIN (
        SELECT
        ( @INDEX := @INDEX + 1 ) AS rownum,
        t2.file_code,
        t2.diagnose,
        t2.behospital_code,
        t2.behospital_date,
        t2.leave_hospital_date
        FROM
        (
        SELECT
        tt1.file_code,
        tt1.diagnose,
        tt2.behospital_code,
        tt2.behospital_date,
        tt2.leave_hospital_date
        FROM
        (
        SELECT
        a.file_code,
        a.diagnose
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        AND IFNULL( a.diagnose, '' )!= ''
        AND IFNULL( a.file_code, '' )!= ''
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.file_code,
        a.diagnose
        HAVING
        count(*)> 1
        ) tt1,
        med_behospital_info tt2
        WHERE
        tt2.is_deleted = 'N'
        <if test="isPlacefile != null and isPlacefile != ''">
            and tt2.is_placefile = #{isPlacefile}
        </if>
        AND tt2.qc_type_id != 0
        AND tt1.file_code = tt2.file_code
        AND tt1.diagnose = tt2.diagnose
        <if test="hospitalId != null and hospitalId != ''">
            AND tt2.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND tt2.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND tt2.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND tt2.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND tt2.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        ORDER BY
        tt1.file_code,
        tt1.diagnose,
        tt2.behospital_date DESC
        ) t2,(
        SELECT
        @INDEX := 0
        ) r
        ) r2 ON r1.file_code = r2.file_code
        AND r1.rownum = r2.rownum - 1
        ) t
        WHERE
        t.diffDays IS NOT NULL
        AND t.diffDays BETWEEN 0
        AND 31
    </select>

    <!-- 病案首页质控病历数统计-全院（首页）-->
    <select id="homePageQcPercent" resultType="com.diagbot.dto.HomePageNumDTO" parameterType="com.diagbot.vo.FilterVO">
        SELECT
        count( * ) AS mrNum,
        ROUND( sum( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
        ROUND( avg( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
        SUM( c.`level` = '合格' ) AS firstLevelNum,
        SUM( c.`level` = '不合格' ) AS secondLevelNum,
        ROUND( SUM( c.`level` = '合格' )/ count( * ), 4 ) AS firstLevelPercent,
        ROUND( SUM( c.`level` = '不合格' )/ count( * ), 4 ) AS secondLevelPercent,
        concat( ROUND( SUM( c.`level` = '合格' )/ count( * )* 100, 2 ), '%' ) AS firstLevelPercentStr,
        concat( ROUND( SUM( c.`level` = '不合格' )/ count( * )* 100, 2 ), '%' ) AS secondLevelPercentStr
        FROM
        med_behospital_info a,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
    </select>

    <!-- 病案首页完整率统计-全院（首页）-->
    <select id="hmEmptyEntryPercent" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.HomePageNumDTO">
        SELECT
        h1.emptyNum,
        h1.mrNum,
        h2.entryNum,
        h1.mrNum * h2.entryNum AS entryTotleNum,
        ROUND( ( h1.mrNum * h2.entryNum - h1.emptyNum ) / ( h1.mrNum * h2.entryNum ), 4 ) AS emptyPercent,
        CONCAT(
        ROUND( ( h1.mrNum * h2.entryNum - h1.emptyNum ) / ( h1.mrNum * h2.entryNum )* 100, 2 ),
        '%'
        ) AS emptyPercentStr
        FROM
        (
        SELECT
        sum( d.rule_type = 1 ) AS emptyNum,
        count( DISTINCT a.behospital_code ) AS mrNum
        FROM
        med_behospital_info a,
        med_qcresult_cases b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND b.cases_id = c.cases_id
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND d.cases_id = 243
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        ) h1,(
        SELECT
        count(*) AS entryNum
        FROM
        qc_cases_entry
        WHERE
        is_deleted = 'N'
        AND cases_id = 243
        ) h2
    </select>
    <!-- 离院病人评分详情页-->
    <select id="getAge" resultType="java.util.Map">
        SELECT
        a.behospital_code as behospitalCode,
        CONCAT( ifnull(a.age,'') ,ifnull(a.age_unit,'') )as age
        FROM
        med_home_page a
        WHERE
        a.is_deleted = 'N'
        AND a.hospital_id = #{hospitalId}
        AND a.behospital_code IN
        <foreach collection="behospitalCodes" open="(" separator="," close=")" item="item">
            '${item}'
        </foreach>
    </select>
    <!-- 离院病人评分详情页-->
    <select id="leaveHosMRPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT
        t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode
        FROM
        (
        SELECT be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (
        SELECT
        b.*,
        ifnull(c.LEVEL,'未评分') as LEVEL ,
        c.grade_type,
        c.score_res,
        c.gmt_create
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        a.file_code
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) b
        LEFT JOIN med_qcresult_info c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        ) tt1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==3">
            ,med_medical_record tt2,
            qc_mode tt3
            WHERE
            tt2.is_deleted = 'N'
            AND tt3.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = tt3.id
            AND tt3.`name` = '手术记录'
        </if>
        ) be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )t1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==2">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND (
            ( IFNULL( t2.newborn_day, '' ) != '' AND t2.newborn_day != '0' AND t2.newborn_day != '-'AND t2.newborn_day != '—' )
            OR ( IFNULL( t2.newborn_month, '' )!= '' AND t2.newborn_month != '0' AND t2.newborn_month != '-'AND t2.newborn_month != '—' )
            )
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==1">
            , med_medical_record b,
            med_medical_record_content c,
            med_home_page t2
            WHERE
            b.is_deleted = 'N'
            and c.is_deleted = 'N'
            and t2.is_deleted = 'N'
            and t1.hospital_id = b.hospital_id
            and t1.hospital_id = c.hospital_id
            and t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = b.behospital_code
            AND t1.behospital_code = t2.behospital_code
            AND b.rec_id = c.rec_id
            and b.mode_id = '24'
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==4">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.leave_hospital_type = '非医嘱离院'
        </if>
        <if test="qcResultShortPageVO.leaveHosType == null or qcResultShortPageVO.leaveHosType == 0 or qcResultShortPageVO.leaveHosType == 3">
            LEFT JOIN med_home_page t2 ON t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
        </if>
        )t
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            and t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.`level` = #{qcResultShortPageVO.level}
        </if>
    </select>

    <!-- 离院病人评分详情页-科室-->
    <select id="leaveHosMRPageByDept" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT
        t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode
        FROM
        (
        SELECT be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (
        SELECT
        b.*,
        ifnull(c.LEVEL,'未评分') as LEVEL ,
        c.grade_type,
        c.score_res,
        c.gmt_create
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        a.file_code
        FROM
        med_behospital_info a,
        sys_user_dept b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.beh_dept_id = b.dept_id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND b.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) b
        LEFT JOIN med_qcresult_info c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        ) tt1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==3">
            ,med_medical_record tt2,
            qc_mode tt3
            WHERE
            tt2.is_deleted = 'N'
            AND tt3.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = tt3.id
            AND tt3.`name` = '手术记录'
        </if>
        ) be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )t1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==2">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND (
            ( IFNULL( t2.newborn_day, '' ) != '' AND t2.newborn_day != '0' AND t2.newborn_day != '-'AND t2.newborn_day != '—' )
            OR ( IFNULL( t2.newborn_month, '' )!= '' AND t2.newborn_month != '0' AND t2.newborn_month != '-'AND t2.newborn_month != '—' )
            )
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==1">
            , med_medical_record b,
            med_medical_record_content c,
            med_home_page t2
            WHERE
            b.is_deleted = 'N'
            and c.is_deleted = 'N'
            and t2.is_deleted = 'N'
            and t1.hospital_id = b.hospital_id
            and t1.hospital_id = c.hospital_id
            and t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = b.behospital_code
            AND t1.behospital_code = t2.behospital_code
            AND b.rec_id = c.rec_id
            and b.mode_id = '24'
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==4">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.leave_hospital_type = '非医嘱离院'
        </if>
        <if test="qcResultShortPageVO.leaveHosType == null or qcResultShortPageVO.leaveHosType == 0 or qcResultShortPageVO.leaveHosType == 3">
            LEFT JOIN med_home_page t2 ON t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
        </if>
        )t
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            and t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.`level` = #{qcResultShortPageVO.level}
        </if>
    </select>

    <!-- 病案首页改善率统计（首页）-->
    <select id="homePageImproveCount" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.HomePageImproveDTO">
        SELECT
        t2.homePageMRNum,
        t1.improveNum,
        round( t1.improveNum / t2.homePageMRNum, 4 ) AS improvePercent,
        Concat( round( t1.improveNum / t2.homePageMRNum * 100, 2 ), '%' ) AS improvePercentStr,
        t1.improveToPassNum,
        round( t1.improveToPassNum / t2.homePageMRNum, 4 ) AS improveToPassPercent,
        Concat( round( t1.improveToPassNum / t2.homePageMRNum * 100, 2 ), '%' ) AS improveToPassPercentStr,
        t1.improveToFullNum,
        round( t1.improveToFullNum / t2.homePageMRNum, 4 ) AS improveToFullPercent,
        Concat( round( t1.improveToFullNum / t2.homePageMRNum * 100, 2 ), '%' ) AS improveToFullPercentStr
        FROM
        (
        SELECT
        <![CDATA[sum( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 ) AS improveToPassNum,]]>
        sum( d.score_res = 20 ) AS improveToFullNum,
        count(*) AS improveNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and m1.is_placefile = #{isPlacefile}
        </if>
        AND m1.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND m1.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND m1.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND m1.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND m1.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND m1.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        AND a.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        ) t1,
        (
        SELECT
        count( DISTINCT a.behospital_code ) AS homePageMRNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.qc_type_id != 0
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        ) t2
    </select>

    <!-- 质控核查统计（内页）-->
    <select id="qcCheckStatistics" parameterType="com.diagbot.vo.FilterOrderVO" resultType="com.diagbot.dto.HomePageImproveDTO">
        SELECT
        t.*
        FROM
        (SELECT
        mr.beh_dept_id AS deptId,
        mr.beh_dept_name AS deptName,
        IFNULL( mr.mrNum, 0 ) AS mrNum,
        ck.checkedNum AS checkedNum,
        ROUND( ck.checkedNum / mr.mrNum, 4 ) AS checkedPercent,
        CONCAT( ROUND( ck.checkedNum / mr.mrNum * 100, 2 ), '%' ) AS checkedPercentStr,
        hmmr_t.homePageMRNum,
        improve_t.improveNum,
        round( improve_t.improveNum / hmmr_t.homePageMRNum, 4 ) AS improvePercent,
        Concat( round( improve_t.improveNum / hmmr_t.homePageMRNum * 100, 2 ), '%' ) AS improvePercentStr,
        improve_t.improveToPassNum,
        round( improve_t.improveToPassNum / hmmr_t.homePageMRNum, 4 ) AS improveToPassPercent,
        Concat( round( improve_t.improveToPassNum / hmmr_t.homePageMRNum * 100, 2 ), '%' ) AS improveToPassPercentStr,
        improve_t.improveToFullNum,
        round( improve_t.improveToFullNum / hmmr_t.homePageMRNum, 4 ) AS improveToFullPercent,
        Concat( round( improve_t.improveToFullNum / hmmr_t.homePageMRNum * 100, 2 ), '%' ) AS improveToFullPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        count(*) AS mrNum
        FROM
        med_behospital_info a,
        med_qcresult_info b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.qc_type_id != 0
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) mr
        LEFT JOIN (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        count(*) AS checkedNum
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_check_info c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.qc_type_id != 0
        AND ifnull(c.`status`,0) = 1
        AND c.check_type in (0,2)
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) ck ON mr.beh_dept_id = ck.beh_dept_id
        AND mr.beh_dept_name = ck.beh_dept_name
        LEFT JOIN (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        count( DISTINCT a.behospital_code ) AS homePageMRNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.qc_type_id != 0
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) hmmr_t ON mr.beh_dept_id = hmmr_t.beh_dept_id
        AND mr.beh_dept_name = hmmr_t.beh_dept_name
        LEFT JOIN (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        <![CDATA[sum( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 ) AS improveToPassNum,]]>
        sum( d.score_res = 20 ) AS improveToFullNum,
        count(*) AS improveNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and m1.is_placefile = #{isPlacefile}
        </if>
        AND m1.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND m1.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND m1.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND m1.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND m1.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND m1.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and m1.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name LIKE CONCAT( '%', #{deptName}, '%' )
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
        ) improve_t ON mr.beh_dept_id = improve_t.beh_dept_id
        AND mr.beh_dept_name = improve_t.beh_dept_name
        ) t
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>deptId asc</when>
                <when test='asc=="deptName"'>deptName asc</when>
                <when test='asc=="mrNum"'>mrNum asc</when>
                <when test='asc=="checkedNum"'>checkedNum asc</when>
                <when test='asc=="checkedPercent"'>checkedPercent asc</when>
                <when test='asc=="checkedPercentStr"'>checkedPercent asc</when>
                <when test='asc=="homePageMRNum"'>homePageMRNum asc</when>
                <when test='asc=="improveNum"'>improveNum asc</when>
                <when test='asc=="improvePercent"'>improvePercent asc</when>
                <when test='asc=="improvePercentStr"'>improvePercent asc</when>
                <when test='asc=="improveToPassNum"'>improveToPassNum asc</when>
                <when test='asc=="improveToPassPercent"'>improveToPassPercent asc</when>
                <when test='asc=="improveToPassPercentStr"'>improveToPassPercent asc</when>
                <when test='asc=="improveToFullNum"'>improveToFullNum asc</when>
                <when test='asc=="improveToFullPercent"'>improveToFullPercent asc</when>
                <when test='asc=="improveToFullPercentStr"'>improveToFullPercent asc</when>
                <otherwise>deptName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>deptId desc</when>
                <when test='desc=="deptName"'>deptName desc</when>
                <when test='desc=="mrNum"'>mrNum desc</when>
                <when test='desc=="checkedNum"'>checkedNum desc</when>
                <when test='desc=="checkedPercent"'>checkedPercent desc</when>
                <when test='desc=="checkedPercentStr"'>checkedPercent desc</when>
                <when test='desc=="homePageMRNum"'>homePageMRNum desc</when>
                <when test='desc=="improveNum"'>improveNum desc</when>
                <when test='desc=="improvePercent"'>improvePercent desc</when>
                <when test='desc=="improvePercentStr"'>improvePercent desc</when>
                <when test='desc=="improveToPassNum"'>improveToPassNum desc</when>
                <when test='desc=="improveToPassPercent"'>improveToPassPercent desc</when>
                <when test='desc=="improveToPassPercentStr"'>improveToPassPercent desc</when>
                <when test='desc=="improveToFullNum"'>improveToFullNum desc</when>
                <when test='desc=="improveToFullPercent"'>improveToFullPercent desc</when>
                <when test='desc=="improveToFullPercentStr"'>improveToFullPercent desc</when>
                <otherwise>deptName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 质控核查统计-科室（内页）-->
    <select id="qcCheckStatisticsByDept" parameterType="com.diagbot.vo.FilterOrderVO" resultType="com.diagbot.dto.ImproveByDeptDTO">
        SELECT
        t.*
        FROM
        (SELECT
        mr.beh_dept_id AS deptId,
        mr.beh_dept_name AS deptName,
        mr.doctorId,
        mr.doctorName,
        IFNULL( mr.mrNum, 0 ) AS mrNum,
        ck.checkedNum AS checkedNum,
        ROUND( ck.checkedNum / mr.mrNum, 4 ) AS checkedPercent,
        CONCAT( ROUND( ck.checkedNum / mr.mrNum * 100, 2 ), '%' ) AS checkedPercentStr,
        hmmr_t.homePageMRNum,
        improve_t.improveNum,
        round( improve_t.improveNum / hmmr_t.homePageMRNum, 4 ) AS improvePercent,
        Concat( round( improve_t.improveNum / hmmr_t.homePageMRNum * 100, 2 ), '%' ) AS improvePercentStr,
        improve_t.improveToPassNum,
        round( improve_t.improveToPassNum / hmmr_t.homePageMRNum, 4 ) AS improveToPassPercent,
        Concat( round( improve_t.improveToPassNum / hmmr_t.homePageMRNum * 100, 2 ), '%' ) AS improveToPassPercentStr,
        improve_t.improveToFullNum,
        round( improve_t.improveToFullNum / hmmr_t.homePageMRNum, 4 ) AS improveToFullPercent,
        Concat( round( improve_t.improveToFullNum / hmmr_t.homePageMRNum * 100, 2 ), '%' ) AS improveToFullPercentStr
        FROM
        (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName,
        count(*) AS mrNum
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.beh_dept_id = c.dept_id
        AND a.behospital_code = b.behospital_code
        AND a.qc_type_id != 0
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name LIKE CONCAT( '%', #{doctorName}, '%' )
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) mr
        LEFT JOIN (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName,
        count(*) AS checkedNum
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_check_info c,
        sys_user_dept d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = d.dept_id
        AND a.qc_type_id != 0
        AND ifnull(c.`status`,0) = 1
        AND c.check_type = 0
        <if test="userId!=null">
            AND d.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name LIKE CONCAT( '%', #{doctorName}, '%' )
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) ck ON mr.doctorId = ck.doctorId
        AND mr.doctorName = ck.doctorName
        LEFT JOIN (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName,
        count( DISTINCT a.behospital_code ) AS homePageMRNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        sys_user_dept d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = d.dept_id
        AND a.qc_type_id != 0
        <if test="userId!=null">
            AND d.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name LIKE CONCAT( '%', #{doctorName}, '%' )
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) hmmr_t ON mr.doctorId = hmmr_t.doctorId
        AND mr.doctorName = hmmr_t.doctorName
        LEFT JOIN (
        SELECT
        a.beh_dept_id,
        a.beh_dept_name,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName,
        <![CDATA[sum( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 ) AS improveToPassNum,]]>
        sum( d.score_res = 20 ) AS improveToFullNum,
        count(*) AS improveNum
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        sys_user_dept f,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        <if test="isPlacefile != null and isPlacefile != ''">
            and m1.is_placefile = #{isPlacefile}
        </if>
        AND m1.qc_type_id != 0
        <if test="hospitalId != null and hospitalId != ''">
            AND m1.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND m1.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND m1.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND m1.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND m1.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            and m1.beh_dept_name = #{deptName}
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND a.beh_dept_id = f.dept_id
        <if test="userId!=null">
            AND f.user_id = #{userId}
        </if>
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="doctorName != null and doctorName != ''">
            and a.doctor_name LIKE CONCAT( '%', #{doctorName}, '%' )
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name
        ) improve_t ON mr.doctorId = improve_t.doctorId
        AND mr.doctorName = improve_t.doctorName
        ) t
        <if test="asc != null and asc !=''">
            order by
            <choose>
                <when test='asc=="deptId"'>deptId asc</when>
                <when test='asc=="deptName"'>deptName asc</when>
                <when test='asc=="doctorName"'>doctorName asc</when>
                <when test='asc=="mrNum"'>mrNum asc</when>
                <when test='asc=="checkedNum"'>checkedNum asc</when>
                <when test='asc=="checkedPercent"'>checkedPercent asc</when>
                <when test='asc=="checkedPercentStr"'>checkedPercent asc</when>
                <when test='asc=="homePageMRNum"'>homePageMRNum asc</when>
                <when test='asc=="improveNum"'>improveNum asc</when>
                <when test='asc=="improvePercent"'>improvePercent asc</when>
                <when test='asc=="improvePercentStr"'>improvePercent asc</when>
                <when test='asc=="improveToPassNum"'>improveToPassNum asc</when>
                <when test='asc=="improveToPassPercent"'>improveToPassPercent asc</when>
                <when test='asc=="improveToPassPercentStr"'>improveToPassPercent asc</when>
                <when test='asc=="improveToFullNum"'>improveToFullNum asc</when>
                <when test='asc=="improveToFullPercent"'>improveToFullPercent asc</when>
                <when test='asc=="improveToFullPercentStr"'>improveToFullPercent asc</when>
                <otherwise>doctorName asc</otherwise>
            </choose>
        </if>
        <if test="desc != null and desc!=''">
            order by
            <choose>
                <when test='desc=="deptId"'>deptId desc</when>
                <when test='desc=="deptName"'>deptName desc</when>
                <when test='desc=="doctorName"'>doctorName desc</when>
                <when test='desc=="mrNum"'>mrNum desc</when>
                <when test='desc=="checkedNum"'>checkedNum desc</when>
                <when test='desc=="checkedPercent"'>checkedPercent desc</when>
                <when test='desc=="checkedPercentStr"'>checkedPercent desc</when>
                <when test='desc=="homePageMRNum"'>homePageMRNum desc</when>
                <when test='desc=="improveNum"'>improveNum desc</when>
                <when test='desc=="improvePercent"'>improvePercent desc</when>
                <when test='desc=="improvePercentStr"'>improvePercent desc</when>
                <when test='desc=="improveToPassNum"'>improveToPassNum desc</when>
                <when test='desc=="improveToPassPercent"'>improveToPassPercent desc</when>
                <when test='desc=="improveToPassPercentStr"'>improveToPassPercent desc</when>
                <when test='desc=="improveToFullNum"'>improveToFullNum desc</when>
                <when test='desc=="improveToFullPercent"'>improveToFullPercent desc</when>
                <when test='desc=="improveToFullPercentStr"'>improveToFullPercent desc</when>
                <otherwise>deptName desc</otherwise>
            </choose>
        </if>
    </select>

    <!-- 离院病人评分详情页导出-->
    <select id="leaveHosMRPageExport" resultMap="ExportExcelMap">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f2.avgScore,
        f1.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        f1.msg,
        f1.caseName,
        </if>
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        qd.msg AS msg,
        qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime,
        t2.age,
        t1.file_code AS fileCode
        FROM
        (
        SELECT be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (
        SELECT
        b.*,
        ifnull(c.LEVEL,'未评分') as LEVEL ,
        c.grade_type,
        c.score_res,
        c.gmt_create
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        a.file_code
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) b
        LEFT JOIN med_qcresult_info c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        ) tt1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==3">
            ,med_medical_record tt2,
            qc_mode tt3
            WHERE
            tt2.is_deleted = 'N'
            AND tt3.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = tt3.id
            AND tt3.`name` = '手术记录'
        </if>
        ) be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )t1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==2">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND (
            ( IFNULL( t2.newborn_day, '' ) != '' AND t2.newborn_day != '0' AND t2.newborn_day != '-' AND t2.newborn_day != '—')
            OR ( IFNULL( t2.newborn_month, '' )!= '' AND t2.newborn_month != '0' AND t2.newborn_month != '-' AND t2.newborn_month != '—')
            )
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==1">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.return_to_type = '死亡'
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==4">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.leave_hospital_type = '非医嘱离院'
        </if>
        <if test="qcResultShortPageVO.leaveHosType == null or qcResultShortPageVO.leaveHosType == 0 or qcResultShortPageVO.leaveHosType == 3">
            LEFT JOIN med_home_page t2 ON t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
        </if>
        )t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            and t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.`level` = #{qcResultShortPageVO.level}
        </if>)f1,(SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime,
        t2.age,
        t1.file_code AS fileCode
        FROM
        (
        SELECT be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (
        SELECT
        b.*,
        ifnull(c.LEVEL,'未评分') as LEVEL ,
        c.grade_type,
        c.score_res,
        c.gmt_create
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        a.file_code
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) b
        LEFT JOIN med_qcresult_info c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        ) tt1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==3">
            ,med_medical_record tt2,
            qc_mode tt3
            WHERE
            tt2.is_deleted = 'N'
            AND tt3.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = tt3.id
            AND tt3.`name` = '手术记录'
        </if>
        ) be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        )t1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==2">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND (
            ( IFNULL( t2.newborn_day, '' ) != '' AND t2.newborn_day != '0' AND t2.newborn_day != '-'AND t2.newborn_day != '—' )
            OR ( IFNULL( t2.newborn_month, '' )!= '' AND t2.newborn_month != '0' AND t2.newborn_month != '-' AND t2.newborn_month != '—')
            )
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==1">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.return_to_type = '死亡'
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==4">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.leave_hospital_type = '非医嘱离院'
        </if>
        <if test="qcResultShortPageVO.leaveHosType == null or qcResultShortPageVO.leaveHosType == 0 or qcResultShortPageVO.leaveHosType == 3">
            LEFT JOIN med_home_page t2 ON t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
        </if>
        )t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            and t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.`level` = #{qcResultShortPageVO.level}
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
    </select>


    <!-- 离院病人评分详情页导出-科室-->
    <select id="leaveHosMRPageExportByDept" resultMap="ExportExcelMapByDept">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f2.avgScore,
        f1.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            f1.msg,
            f1.caseName,
        </if>
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName,
        t.doctorId,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            qd.msg AS msg,
            qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime,
        t2.age,
        t1.file_code AS fileCode
        FROM
        (
        SELECT be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (
        SELECT
        b.*,
        ifnull(c.LEVEL,'未评分') as LEVEL ,
        c.grade_type,
        c.score_res,
        c.gmt_create
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        a.file_code
        FROM
        med_behospital_info a,
        sys_user_dept b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.beh_dept_id = b.dept_id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND b.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) b
        LEFT JOIN med_qcresult_info c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        ) tt1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==3">
            ,med_medical_record tt2,
            qc_mode tt3
            WHERE
            tt2.is_deleted = 'N'
            AND tt3.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = tt3.id
            AND tt3.`name` = '手术记录'
        </if>
        ) be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )t1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==2">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND (
            ( IFNULL( t2.newborn_day, '' ) != '' AND t2.newborn_day != '0' AND t2.newborn_day != '-' AND t2.newborn_day != '—')
            OR ( IFNULL( t2.newborn_month, '' )!= '' AND t2.newborn_month != '0' AND t2.newborn_month != '-' AND t2.newborn_month != '—')
            )
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==1">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.return_to_type = '死亡'
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==4">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.leave_hospital_type = '非医嘱离院'
        </if>
        <if test="qcResultShortPageVO.leaveHosType == null or qcResultShortPageVO.leaveHosType == 0 or qcResultShortPageVO.leaveHosType == 3">
            LEFT JOIN med_home_page t2 ON t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
        </if>
        )t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
            AND t.hospitalId = qd.hospital_id
            AND t.behospitalCode = qd.behospital_code
            LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
            AND qd.cases_id = qc.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            and t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.`level` = #{qcResultShortPageVO.level}
        </if>)f1,(SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime,
        t2.age,
        t1.file_code AS fileCode
        FROM
        (
        SELECT be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (
        SELECT
        b.*,
        ifnull(c.LEVEL,'未评分') as LEVEL ,
        c.grade_type,
        c.score_res,
        c.gmt_create
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        a.file_code
        FROM
        med_behospital_info a,
        sys_user_dept b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.beh_dept_id = b.dept_id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND b.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) b
        LEFT JOIN med_qcresult_info c ON c.is_deleted = 'N'
        AND b.hospital_id = c.hospital_id
        AND b.behospital_code = c.behospital_code
        ) tt1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==3">
            ,med_medical_record tt2,
            qc_mode tt3
            WHERE
            tt2.is_deleted = 'N'
            AND tt3.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = tt3.id
            AND tt3.`name` = '手术记录'
        </if>
        ) be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        )t1
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==2">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND (
            ( IFNULL( t2.newborn_day, '' ) != '' AND t2.newborn_day != '0' AND t2.newborn_day != '-' AND t2.newborn_day != '—')
            OR ( IFNULL( t2.newborn_month, '' )!= '' AND t2.newborn_month != '0' AND t2.newborn_month != '-'AND t2.newborn_month != '—' )
            )
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==1">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.return_to_type = '死亡'
        </if>
        <if test="qcResultShortPageVO.leaveHosType != null and qcResultShortPageVO.leaveHosType ==4">
            ,med_home_page t2
            WHERE
            t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.leave_hospital_type = '非医嘱离院'
        </if>
        <if test="qcResultShortPageVO.leaveHosType == null or qcResultShortPageVO.leaveHosType == 0 or qcResultShortPageVO.leaveHosType == 3">
            LEFT JOIN med_home_page t2 ON t2.is_deleted = 'N'
            AND t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
        </if>
        )t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            and t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.`level` = #{qcResultShortPageVO.level}
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        )f2
        WHERE
        f1.doctorId = f2.doctorId
        AND f1.doctorName = f2.doctorName
    </select>

    <!--缺陷详情质控评分页导出-科室-->
    <select id="qcResultShortByDeptPageExport" resultMap="ExportExcelMapByDept">
        SELECT * from(
        SELECT
        f1.*,
        f2.avgScore
        FROM
        (SELECT
        t.*,
        qi.score_res AS score,
        qd.msg AS msg,
        qc.NAME AS caseName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn AS scoreBn,
        t1.NAME AS patName,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose AS diagnose,
        t1.ward_name AS wardName,
        t1.file_code AS fileCode,
        t1.checkStatus AS checkStatus,
        t1.mrStatus AS mrStatus,
        t1.chName AS chName,
        t1.mrName AS mrName,
        t1.chTime AS chTime,
        t1.mrTime AS mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        e.score_res as scoreBn,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = e.dept_id
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.userId != null and qcResultShortPageVO.userId != ''">
            AND e.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND a.doctor_id = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.casesEntryName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId != ''">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
        AND qd.cases_id = qce.cases_id
        AND qd.cases_entry_id = qce.id
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND qce.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND qce.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = e.dept_id
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND a.doctor_id = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        )f2
        WHERE
        f1.doctorId = f2.doctorId
        AND f1.doctorName = f2.doctorName
        )m
    </select>
    <!-- 条目缺陷评分详情页导出-->
    <select id="qcResultShortPageExport" resultMap="ExportExcelMap">
        SELECT * from(
        SELECT
        f1.*,
        f2.avgScore
        FROM
        (SELECT
        t.*,
        qi.score_res AS score,
        qd.msg AS msg,
        qc.NAME AS caseName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn AS scoreBn,
        t1.NAME AS patName,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose AS diagnose,
        t1.ward_name AS wardName,
        t1.file_code AS fileCode,
        t1.checkStatus AS checkStatus,
        t1.mrStatus AS mrStatus,
        t1.chName AS chName,
        t1.mrName AS mrName,
        t1.chTime AS chTime,
        t1.mrTime AS mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        e.score_res as scoreBn,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name  = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
        AND qd.cases_id = qce.cases_id
        AND qd.cases_entry_id = qce.id
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND qce.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND qce.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name  = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
        )m
    </select>

    <!-- 条目缺陷评分详情页导出湘雅-->
    <select id="qcResultShortXYPageExport" resultMap="ExportExcelMap">
        SELECT * from(
        SELECT
        f1.*,
        f2.avgScore
        FROM
        (SELECT
        t.*,
        qi.score_res AS score,
        qd.msg AS msg,
        qc.NAME AS caseName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn AS scoreBn,
        t1.NAME AS patName,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_name AS doctorName,
        t1.doctorId,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose AS diagnose,
        t1.ward_name AS wardName,
        t1.file_code AS fileCode,
        t1.checkStatus AS checkStatus,
        t1.mrStatus AS mrStatus,
        t1.chName AS chName,
        t1.mrName AS mrName,
        t1.chTime AS chTime,
        t1.mrTime AS mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        e.score_res as scoreBn,
        f.doctor_id as doctorId,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        case
        when e.attending_doctor != '' and e.attending_doctor is not null then e.attending_doctor
        when (e.attending_doctor = '' or e.attending_doctor is null) and
        e.director_doctor != '' and e.director_doctor is not null
        then e.director_doctor
        when (e.attending_doctor = '' or e.attending_doctor is null) and
        (e.director_doctor = '' or e.director_doctor is null) and
        e.behospital_doctor != '' and e.behospital_doctor is not null
        then e.behospital_doctor end as doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        med_home_page e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = e.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name  = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id  = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND(case
            when e.attending_doctor != '' and e.attending_doctor is not null then e.attending_doctor
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            e.director_doctor != '' and e.director_doctor is not null
            then e.director_doctor
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            (e.director_doctor = '' or e.director_doctor is null) and
            e.behospital_doctor != '' and e.behospital_doctor is not null
            then e.behospital_doctor end ) LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.professor != null and qcResultShortPageVO.professor != ''">
            AND(case
            when e.attending_doctor != '' and e.attending_doctor is not null then '主治医师'
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            e.director_doctor != '' and e.director_doctor is not null
            then '主任医师'
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            (e.director_doctor = '' or e.director_doctor is null) and
            e.behospital_doctor != '' and e.behospital_doctor is not null
            then '住院医师' end) = #{qcResultShortPageVO.professor}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        LEFT JOIN bas_doctor_info f
        on be.hospital_id = f.hospital_id
        and be.doctor_name = f.name
        AND f.is_deleted = 'N'
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
        AND qd.cases_id = qce.cases_id
        AND qd.cases_entry_id = qce.id
        where 1=1
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND t.doctorId = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND qce.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND qce.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.doctorId,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT DISTINCT
        tt1.*
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        f.doctor_id as doctorId,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        case
        when e.attending_doctor != '' and e.attending_doctor is not null then e.attending_doctor
        when (e.attending_doctor = '' or e.attending_doctor is null) and
        e.director_doctor != '' and e.director_doctor is not null
        then e.director_doctor
        when (e.attending_doctor = '' or e.attending_doctor is null) and
        (e.director_doctor = '' or e.director_doctor is null) and
        e.behospital_doctor != '' and e.behospital_doctor is not null
        then e.behospital_doctor end as doctor_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        med_home_page e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = e.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name  = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id  = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.casesName != null and qcResultShortPageVO.casesName != ''">
            AND d.cases_name = #{qcResultShortPageVO.casesName}
        </if>
        <if test="qcResultShortPageVO.casesId != null">
            AND d.cases_id = #{qcResultShortPageVO.casesId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND(case
            when e.attending_doctor != '' and e.attending_doctor is not null then e.attending_doctor
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            e.director_doctor != '' and e.director_doctor is not null
            then e.director_doctor
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            (e.director_doctor = '' or e.director_doctor is null) and
            e.behospital_doctor != '' and e.behospital_doctor is not null
            then e.behospital_doctor end ) LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.professor != null and qcResultShortPageVO.professor != ''">
            AND(case
            when e.attending_doctor != '' and e.attending_doctor is not null then '主治医师'
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            e.director_doctor != '' and e.director_doctor is not null
            then '主任医师'
            when (e.attending_doctor = '' or e.attending_doctor is null) and
            (e.director_doctor = '' or e.director_doctor is null) and
            e.behospital_doctor != '' and e.behospital_doctor is not null
            then '住院医师' end) = #{qcResultShortPageVO.professor}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2495">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 30
        </if>
        <if test="qcResultShortPageVO.beHosGT31Days != null and qcResultShortPageVO.beHosGT31Days==1">
            AND TIMESTAMPDIFF(
            DAY,
            DATE( a.behospital_date ),
            DATE( a.leave_hospital_date ))> 31
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN bas_doctor_info f
        on be.hospital_id = f.hospital_id
        and be.doctor_name = f.name
        AND f.is_deleted = 'N'
        )tt1
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2511">
            ,med_medical_record tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
            AND tt2.mode_id = 30
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and qcResultShortPageVO.casesEntryId==2419">
            ,med_crisis_info tt2
            WHERE
            tt2.is_deleted = 'N'
            AND tt1.hospital_id = tt2.hospital_id
            AND tt1.behospital_code = tt2.behospital_code
        </if>
        ) t1
        <if test="qcResultShortPageVO.casesEntryId == null or (qcResultShortPageVO.casesEntryId!=2594  and qcResultShortPageVO.casesEntryId!=2973 and qcResultShortPageVO.casesEntryId!=2930)">
            LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.is_deleted = 'N'
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null and( qcResultShortPageVO.casesEntryId==2594  or qcResultShortPageVO.casesEntryId==2973 or qcResultShortPageVO.casesEntryId==2930)">
            , med_home_page t2
            , med_home_operation_info t3
            WHERE t1.hospital_id = t2.hospital_id
            AND t1.behospital_code = t2.behospital_code
            AND t2.home_page_id = t3.home_page_id
            AND t2.is_deleted = 'N'
            AND t3.is_deleted = 'N'
        </if>
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND t.doctorId = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
        )m
    </select>

    <resultMap id="MedicalCheckMap" type="com.diagbot.dto.MedicalCheckDTO">
        <result column="deptName" property="deptName"/>
        <result column="deptId" property="deptId"/>
        <result column="doctorGroup" property="doctorGroup"/>
        <result column="doctorName" property="doctorName"/>
        <result column="entry_2658_num" property="entry_2658_num"/>
        <result column="entry_2686_num" property="entry_2686_num"/>
        <result column="entry_2657_num" property="entry_2657_num"/>
        <result column="entry_3010_num" property="entry_3010_num"/>
        <result column="entry_2655_num" property="entry_2655_num"/>
        <result column="entry_2654_num" property="entry_2654_num"/>
        <result column="entry_2852_num" property="entry_2852_num"/>
        <result column="entry_2287_num" property="entry_2287_num"/>
        <result column="entry_3025_num" property="entry_3025_num"/>
        <result column="entry_2170_num" property="entry_2170_num"/>
        <result column="entry_2930_num" property="entry_2930_num"/>
        <result column="entry_2900_num" property="entry_2900_num"/>
        <result column="entry_2229_num" property="entry_2229_num"/>
        <result column="entry_2217_num" property="entry_2217_num"/>
        <result column="entry_2218_num" property="entry_2218_num"/>
        <result column="entry_2220_num" property="entry_2220_num"/>
        <result column="entry_2486_num" property="entry_2486_num"/>
        <result column="entry_3063_num" property="entry_3063_num"/>
        <result column="entry_3062_num" property="entry_3062_num"/>
        <result column="entry_2495_num" property="entry_2495_num"/>
    </resultMap>

    <!--    病历稽查表-->
    <select id="getMedicalCheck" resultMap="MedicalCheckMap">
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        a.doctor_name as doctorGroup,
        a.doctor_name as doctorName,
        sum(c.cases_entry_id = 2658) as entry_2658_num,
        sum(c.cases_entry_id = 2686) as entry_2686_num,
        sum(c.cases_entry_id = 2657) as entry_2657_num,
        sum(c.cases_entry_id = 3010) as entry_3010_num,
        sum(c.cases_entry_id = 2655) as entry_2655_num,
        sum(c.cases_entry_id = 2654) as entry_2654_num,
        sum(c.cases_entry_id = 2852) as entry_2852_num,
        sum(c.cases_entry_id = 2287) as entry_2287_num,
        sum(c.cases_entry_id = 3025) as entry_3025_num,
        sum(c.cases_entry_id = 2170) as entry_2170_num,
        sum(c.cases_entry_id = 2930) as entry_2930_num,
        sum(c.cases_entry_id = 2900) as entry_2900_num,
        sum(c.cases_entry_id = 2229) as entry_2229_num,
        sum(c.cases_entry_id = 2217) as entry_2217_num,
        sum(c.cases_entry_id = 2218) as entry_2218_num,
        sum(c.cases_entry_id = 2220) as entry_2220_num,
        sum(c.cases_entry_id = 2486) as entry_2486_num,
        sum(c.cases_entry_id = 3063) as entry_3063_num,
        sum(c.cases_entry_id = 3062) as entry_3062_num,
        sum(c.cases_entry_id = 2495) as entry_2495_num
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        bas_doctor_info e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = e.dept_id
        AND c.cases_entry_id = d.id
        and a.doctor_id=e.doctor_id
        and e.group_id is not NULL
        AND LENGTH(e.group_id)>0
        AND a.qc_type_id != 0
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile != ''">
            and a.is_placefile = #{filterVO.isPlacefile}
        </if>
        <if test="filterVO.hospitalId != null and filterVO.hospitalId != ''">
            AND a.hospital_id = #{filterVO.hospitalId}
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 0">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 1">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.deptName != null and filterVO.deptName != ''">
            AND a.beh_dept_name like CONCAT('%', #{filterVO.deptName}, '%')
        </if>
        GROUP BY
        a.beh_dept_id,
        e.group_id,
        a.doctor_id
    </select>

    <!--    病历稽查表-科室-->
    <select id="getMedicalCheckByDept" resultMap="MedicalCheckMap">
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        a.doctor_name as doctorName,
        a.doctor_name as doctorGroup,
        sum(c.cases_entry_id = 2658) as entry_2658_num,
        sum(c.cases_entry_id = 2686) as entry_2686_num,
        sum(c.cases_entry_id = 2657) as entry_2657_num,
        sum(c.cases_entry_id = 3010) as entry_3010_num,
        sum(c.cases_entry_id = 2655) as entry_2655_num,
        sum(c.cases_entry_id = 2654) as entry_2654_num,
        sum(c.cases_entry_id = 2852) as entry_2852_num,
        sum(c.cases_entry_id = 2287) as entry_2287_num,
        sum(c.cases_entry_id = 3025) as entry_3025_num,
        sum(c.cases_entry_id = 2170) as entry_2170_num,
        sum(c.cases_entry_id = 2930) as entry_2930_num,
        sum(c.cases_entry_id = 2900) as entry_2900_num,
        sum(c.cases_entry_id = 2229) as entry_2229_num,
        sum(c.cases_entry_id = 2217) as entry_2217_num,
        sum(c.cases_entry_id = 2218) as entry_2218_num,
        sum(c.cases_entry_id = 2220) as entry_2220_num,
        sum(c.cases_entry_id = 2486) as entry_2486_num,
        sum(c.cases_entry_id = 3063) as entry_3063_num,
        sum(c.cases_entry_id = 3062) as entry_3062_num,
        sum(c.cases_entry_id = 2495) as entry_2495_num
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        bas_doctor_info e,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND c.cases_entry_id = d.id
        and a.doctor_id=e.doctor_id
        and e.group_id is not NULL
        AND LENGTH(e.group_id)>0
        AND a.qc_type_id != 0
        <if test="filterVO.userId!=null">
            AND f.user_id = #{filterVO.userId}
        </if>
        <if test="filterVO.name != null and filterVO.name != ''">
            AND a.doctor_name  like CONCAT('%', #{filterVO.name}, '%')
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile != ''">
            and a.is_placefile = #{filterVO.isPlacefile}
        </if>
        <if test="filterVO.hospitalId != null and filterVO.hospitalId != ''">
            AND a.hospital_id = #{filterVO.hospitalId}
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 0">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 1">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.deptName != null and filterVO.deptName != ''">
            AND a.beh_dept_name = #{filterVO.deptName}
        </if>
        GROUP BY
        a.beh_dept_id,
        e.group_id,
        a.doctor_name
    </select>

    <!--    病历稽查表最新sql、id&&name-->
    <select id="getMedicalEntryIds" resultType="com.diagbot.dto.MedicalCheckIdNameDTO">
        SELECT
        d.id,
        d.name
        from
        qc_cases_entry d
        where
        1=1
        <if test="casesEntryIds != null and casesEntryIds.size() > 0">
            and d.id in
            <foreach collection="casesEntryIds" open="(" separator="," close=")" item="item">
                '${item}'
            </foreach>
        </if>
    </select>
    <resultMap id="MedicalCheckExcelMap" type="com.diagbot.dto.MedicalCheckExportDTO">
        <result column="deptName" property="deptName"/>
        <collection property="medicalDoctorExportDTOS" javaType="ArrayList"
                    ofType="com.diagbot.dto.MedicalDoctorExportDTO">
            <result column="doctorName" property="doctorName"/>
            <collection property="medicalCheckTitleDTOS" javaType="ArrayList"
                        ofType="com.diagbot.dto.MedicalCheckTitleDTO">
                <result column="RYJLW_24" property="ryjlw_24"/>
                <result column="SCBCJLW_8H" property="scbcjlw_8h"/>
                <result column="ZRSCCFW_72H" property="zrsccfw_72h"/>
                <result column="RYHLJBCW_3D" property="ryhljbcw_3d"/>
                <result column="ZRCFW_2W" property="zrcfw_2w"/>
                <result column="ZZCFW_3W" property="zzcfw_3w"/>
                <result column="QJJLW_6H" property="qjjlw_6h"/>
                <result column="HZJLW_24H" property="hzjlw_24h"/>
                <result column="SQTLXJW" property="sqtlxjw"/>
                <result column="SXJLSW_24H" property="sxjlsw_24h"/>
                <result column="XHSCW_30M" property="xhscw_30m"/>
                <result column="SHZDCFW_24H" property="shzdcfw_24h"/>
                <result column="SHJBCW_3D" property="shjbcw_3d"/>
                <result column="ZKJBCW_3D" property="zkjbcw_3d"/>
                <result column="ZKJLW_24" property="zkjlw_24"/>
                <result column="BWZHJLBCW_MD" property="bwzhjlbcw_md"/>
                <result column="SXHWJL" property="sxhwjl"/>
                <result column="SXPJW_24" property="sxpjw_24"/>
                <result column="WJZWJL" property="wjzwjl"/>
                <result column="WYWWCXJ" property="wywwcxj"/>
            </collection>
        </collection>
    </resultMap>

    <resultMap id="MedicalCheckByDeptMap" type="com.diagbot.dto.MedicalDeptDTO">
        <result column="deptName" property="deptName"/>
        <collection property="medicalDoctorExportDTOS" javaType="ArrayList"
                    ofType="com.diagbot.dto.MedicalDoDeptDTO">
            <result column="doctorGroup" property="doctorGroup"/>
            <collection property="medicalCheckTitleDTOS" javaType="ArrayList"
                        ofType="com.diagbot.dto.MedicalSeeByDeptDTO">
                <result column="doctorName" property="doctorName"/>
                <result column="RYJLW_24" property="ryjlw_24"/>
                <result column="SCBCJLW_8H" property="scbcjlw_8h"/>
                <result column="ZRSCCFW_72H" property="zrsccfw_72h"/>
                <result column="RYHLJBCW_3D" property="ryhljbcw_3d"/>
                <result column="ZRCFW_2W" property="zrcfw_2w"/>
                <result column="ZZCFW_3W" property="zzcfw_3w"/>
                <result column="QJJLW_6H" property="qjjlw_6h"/>
                <result column="HZJLW_24H" property="hzjlw_24h"/>
                <result column="SQTLXJW" property="sqtlxjw"/>
                <result column="SXJLSW_24H" property="sxjlsw_24h"/>
                <result column="XHSCW_30M" property="xhscw_30m"/>
                <result column="SHZDCFW_24H" property="shzdcfw_24h"/>
                <result column="SHJBCW_3D" property="shjbcw_3d"/>
                <result column="ZKJBCW_3D" property="zkjbcw_3d"/>
                <result column="ZKJLW_24" property="zkjlw_24"/>
                <result column="BWZHJLBCW_MD" property="bwzhjlbcw_md"/>
                <result column="SXHWJL" property="sxhwjl"/>
                <result column="SXPJW_24" property="sxpjw_24"/>
                <result column="WJZWJL" property="wjzwjl"/>
                <result column="WYWWCXJ" property="wywwcxj"/>
            </collection>
        </collection>
    </resultMap>

    <!--    病历稽查表最新导出-->
    <select id="getMedicalCheckExport" resultMap="MedicalCheckExcelMap">
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        GROUP_CONCAT( DISTINCT a.doctor_name) as doctorName,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2658 THEN a.behospital_code else null END ) as RYJLW_24,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2686 THEN a.behospital_code else null END ) as SCBCJLW_8H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2657 THEN a.behospital_code else null END ) as ZRSCCFW_72H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3010 THEN a.behospital_code else null END ) as RYHLJBCW_3D,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2655 THEN a.behospital_code else null END ) as ZRCFW_2W,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2654 THEN a.behospital_code else null END ) as ZZCFW_3W,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2852 THEN a.behospital_code else null END ) as QJJLW_6H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2287 THEN a.behospital_code else null END ) as HZJLW_24H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3025 THEN a.behospital_code else null END ) as SQTLXJW,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2170 THEN a.behospital_code else null END ) as SXJLSW_24H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2930 THEN a.behospital_code else null END ) as XHSCW_30M,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2900 THEN a.behospital_code else null END ) as SHZDCFW_24H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2229 THEN a.behospital_code else null END ) as SHJBCW_3D,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2217 THEN a.behospital_code else null END ) as ZKJBCW_3D,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2218 THEN a.behospital_code else null END ) as ZKJLW_24,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2220 THEN a.behospital_code else null END ) as BWZHJLBCW_MD,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2486 THEN a.behospital_code else null END ) as SXHWJL,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3063 THEN a.behospital_code else null END ) as SXPJW_24,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3062 THEN a.behospital_code else null END ) as WJZWJL,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2495 THEN a.behospital_code else null END ) as WYWWCXJ
        -- sum(c.cases_entry_id = 2658) as RYJLW_24,
        -- sum(c.cases_entry_id = 2686) as SCBCJLW_8H,
        -- sum(c.cases_entry_id = 2657) as ZRSCCFW_72H,
        -- sum(c.cases_entry_id = 3010) as RYHLJBCW_3D,
        -- sum(c.cases_entry_id = 2655) as ZRCFW_2W,
        -- sum(c.cases_entry_id = 2654) as ZZCFW_3W,
        -- sum(c.cases_entry_id = 2852) as QJJLW_6H,
        -- sum(c.cases_entry_id = 2287) as HZJLW_24H,
        -- sum(c.cases_entry_id = 3025) as SQTLXJW,
        -- sum(c.cases_entry_id = 2170) as SXJLSW_24H,
        -- sum(c.cases_entry_id = 2930) as XHSCW_30M,
        -- sum(c.cases_entry_id = 2900) as SHZDCFW_24H,
        -- sum(c.cases_entry_id = 2229) as SHJBCW_3D,
        -- sum(c.cases_entry_id = 2217) as ZKJBCW_3D,
        -- sum(c.cases_entry_id = 2218) as ZKJLW_24,
        -- sum(c.cases_entry_id = 2220) as BWZHJLBCW_MD,
        -- sum(c.cases_entry_id = 2486) as SXHWJL,
        -- sum(c.cases_entry_id = 3063) as SXPJW_24,
        -- sum(c.cases_entry_id = 3062) as WJZWJL,
        -- sum(c.cases_entry_id = 2495) as WYWWCXJ
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        bas_doctor_info e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = e.dept_id
        AND c.cases_entry_id = d.id
        and a.doctor_id=e.doctor_id
        and e.group_id is not NULL
        AND LENGTH(e.group_id)>0
        AND a.qc_type_id != 0
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile != ''">
            and a.is_placefile = #{filterVO.isPlacefile}
        </if>
        <if test="filterVO.hospitalId != null and filterVO.hospitalId != ''">
            AND a.hospital_id = #{filterVO.hospitalId}
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 0">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 1">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.deptName != null and filterVO.deptName != ''">
            AND a.beh_dept_name like CONCAT('%', #{filterVO.deptName}, '%')
        </if>
        GROUP BY
        a.beh_dept_id,
        e.group_id
    </select>

    <!--    病历稽查表最新导出-->
    <select id="medicalCheckExportByDept" resultMap="MedicalCheckByDeptMap">
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        a.doctor_name as doctorGroup,
        a.doctor_name as doctorName,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2658 THEN a.behospital_code else null END ) as RYJLW_24,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2686 THEN a.behospital_code else null END ) as SCBCJLW_8H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2657 THEN a.behospital_code else null END ) as ZRSCCFW_72H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3010 THEN a.behospital_code else null END ) as RYHLJBCW_3D,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2655 THEN a.behospital_code else null END ) as ZRCFW_2W,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2654 THEN a.behospital_code else null END ) as ZZCFW_3W,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2852 THEN a.behospital_code else null END ) as QJJLW_6H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2287 THEN a.behospital_code else null END ) as HZJLW_24H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3025 THEN a.behospital_code else null END ) as SQTLXJW,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2170 THEN a.behospital_code else null END ) as SXJLSW_24H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2930 THEN a.behospital_code else null END ) as XHSCW_30M,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2900 THEN a.behospital_code else null END ) as SHZDCFW_24H,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2229 THEN a.behospital_code else null END ) as SHJBCW_3D,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2217 THEN a.behospital_code else null END ) as ZKJBCW_3D,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2218 THEN a.behospital_code else null END ) as ZKJLW_24,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2220 THEN a.behospital_code else null END ) as BWZHJLBCW_MD,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2486 THEN a.behospital_code else null END ) as SXHWJL,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3063 THEN a.behospital_code else null END ) as SXPJW_24,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 3062 THEN a.behospital_code else null END ) as WJZWJL,
        GROUP_CONCAT(DISTINCT case when c.cases_entry_id = 2495 THEN a.behospital_code else null END ) as WYWWCXJ
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        bas_doctor_info e,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND c.cases_entry_id = d.id
        and a.doctor_id=e.doctor_id
        and e.group_id is not NULL
        AND LENGTH(e.group_id)>0
        AND a.qc_type_id != 0
        <if test="filterVO.userId!=null">
            AND f.user_id = #{filterVO.userId}
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile != ''">
            and a.is_placefile = #{filterVO.isPlacefile}
        </if>
        <if test="filterVO.hospitalId != null and filterVO.hospitalId != ''">
            AND a.hospital_id = #{filterVO.hospitalId}
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 0">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.isPlacefile != null and filterVO.isPlacefile == 1">
            <if test="filterVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{filterVO.startDate}]]>
            </if>
            <if test="filterVO.endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
            </if>
        </if>
        <if test="filterVO.name != null and filterVO.name != ''">
            AND a.doctor_name  like CONCAT('%', #{filterVO.name}, '%')
        </if>
        <if test="filterVO.deptName != null and filterVO.deptName != ''">
            AND a.beh_dept_name = #{filterVO.deptName}
        </if>
        GROUP BY
        a.beh_dept_id,
        e.group_id,
        a.doctor_name
    </select>

    <!-- 未整改病历统计-->
    <select id="unModifyMRStatistics" resultType="com.diagbot.dto.UnModifyMRDetailDTO" parameterType="com.diagbot.vo.FilterUnModifyMRVO">
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        d.id AS casesEntryId,
        d.NAME AS casesEntryName,
        count(*) AS casesEntryNum
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name like CONCAT('%', #{deptName}, '%')
        </if>
        <if test="casesEntryIds != null and casesEntryIds.size()>0">
            AND c.cases_entry_id IN
            <foreach collection="casesEntryIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name,
        c.cases_entry_id,
        d.NAME
    </select>

    <!-- 未整改病历统计-科室-->
    <select id="unModifyMRSByDept" resultType="com.diagbot.dto.UnModifyMRDetailDTO" parameterType="com.diagbot.vo.FilterUnModifyMRVO">
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName,
        d.id AS casesEntryId,
        d.NAME AS casesEntryName,
        count(*) AS casesEntryNum
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="userId!=null">
            AND f.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="deptName != null and deptName != ''">
            AND a.beh_dept_name= #{deptName}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name  like CONCAT('%', #{doctorName}, '%')
        </if>
        <if test="casesEntryIds != null and casesEntryIds.size()>0">
            AND c.cases_entry_id IN
            <foreach collection="casesEntryIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY
        a.doctor_id,
        a.doctor_name,
        c.cases_entry_id,
        d.NAME
    </select>


    <!-- 不合格/合格数病历号（内页）科室-->
    <select id="getIsGoodLevelByDept" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        e.score_res as scoreBn,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        sys_user_dept c,
        med_qcresult_cases e
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.beh_dept_id = c.dept_id
        AND a.behospital_code = e.behospital_code
        AND a.qc_type_id != 0
        AND e.cases_id = 243
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="deptName != null and deptName != ''">
            and a.beh_dept_name = #{deptName}
        </if>
        <if test="deptClass != null and deptClass != ''">
            and a.beh_dept_id = #{deptClass}
        </if>
        <if test="deptId != null and deptId != ''">
            and a.beh_dept_id = #{deptId}
        </if>
        <if test="titleName != null and titleName != '' ">
            <if test="titleName == '不合格数'">
                AND e.`level`='不合格'
            </if>
            <if test="titleName == '合格数'">
                AND e.`level`='合格'
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="doctorName != null and doctorName != ''">
            AND a.doctor_name LIKE CONCAT( '%', #{doctorName}, '%' )
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="diagnose != null and diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{diagnose}, '%' )
        </if>
        <if test="behospitalCode != null and behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{behospitalCode}, '%' )
        </if>
        <if test="patName != null and patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{patName}, '%' )
        </if>
        <if test="doctorId != null and doctorId != ''">
            AND a.doctor_id = #{doctorId}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        where
        1=1
        <if test="level != null and level != ''">
            AND b.`level` = #{level}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        where
        1=1
        <if test="checkStatus != null">
            AND t.checkStatus = #{checkStatus}
        </if>
        <if test="mrStatus != null">
            AND t.mrStatus = #{mrStatus}
        </if>
        <if test="chName != null and chName!=''">
            AND t.chName like concat('%', #{chName}, '%')
        </if>
        <if test="mrName != null and mrName!=''">
            AND t.mrName like concat('%', #{mrName}, '%')
        </if>
        <if test="chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{chTimeStart}]]>
        </if>
        <if test="chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{chTimeEnd}]]>
        </if>
        <if test="mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{mrTimeStart}]]>
        </if>
        <if test="mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{mrTimeEnd}]]>
        </if>
    </select>

    <!-- 不合格/合格数病历号（内页）全院-->
    <select id="badLevelPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        e.score_res as scoreBn,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        med_qcresult_cases e
        WHERE
        a.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = e.behospital_code
        AND a.qc_type_id != 0
        AND e.cases_id = 243
        <if test="qcResultPageVO.titleName != null ">
            <if test="qcResultPageVO.titleName == '不合格数'">
                AND e.`level`='不合格'
            </if>
            <if test="qcResultPageVO.titleName == '合格数'">
                AND e.`level`='合格'
            </if>
        </if>
        <if test="qcResultPageVO.isPlacefile != null and qcResultPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultPageVO.isPlacefile}
        </if>
        <if test="qcResultPageVO.hospitalId != null and qcResultPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultPageVO.hospitalId}
        </if>
        <if test="qcResultPageVO.isPlacefile != null and qcResultPageVO.isPlacefile == 0">
            <if test="qcResultPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultPageVO.startDate}]]>
            </if>
            <if test="qcResultPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultPageVO.isPlacefile != null and qcResultPageVO.isPlacefile == 1">
            <if test="qcResultPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultPageVO.startDate}]]>
            </if>
            <if test="qcResultPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultPageVO.diagnose != null and qcResultPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultPageVO.deptName != null and qcResultPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultPageVO.deptName}
        </if>
        <if test="qcResultPageVO.deptId != null and qcResultPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultPageVO.deptId}
        </if>
        <if test="qcResultPageVO.behospitalCode != null and qcResultPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultPageVO.patName != null and qcResultPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultPageVO.patName}, '%' )
        </if>
        <if test="qcResultPageVO.doctorId != null and qcResultPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultPageVO.doctorName != null and qcResultPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultPageVO.doctorName}, '%' ))
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        where
        1=1
        <if test="qcResultPageVO.level != null and qcResultPageVO.level != ''">
            AND b.`level` = #{qcResultPageVO.level}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        where
        1=1
        <if test="qcResultPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultPageVO.checkStatus}
        </if>
        <if test="qcResultPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultPageVO.mrStatus}
        </if>
        <if test="qcResultPageVO.chName != null and qcResultPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultPageVO.chName}, '%')
        </if>
        <if test="qcResultPageVO.mrName != null and qcResultPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultPageVO.mrName}, '%')
        </if>
        <if test="qcResultPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 不合格/合格数病历号XY（内页）全院-->
    <select id="badLevelXYPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.doctorName,
        t1.doctorId,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        f.doctor_id as doctorId,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        e.score_res as scoreBn,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        case
        when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        b.director_doctor != '' and b.director_doctor is not null
        then b.director_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        (b.director_doctor = '' or b.director_doctor is null) and
        b.behospital_doctor != '' and b.behospital_doctor is not null
        then b.behospital_doctor end as doctorName,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_cases e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND e.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = e.behospital_code
        AND a.qc_type_id != 0
        AND e.cases_id = 243
        <if test="qcResultPageVO.titleName != null ">
            <if test="qcResultPageVO.titleName == '不合格数'">
                AND e.`level`='不合格'
            </if>
            <if test="qcResultPageVO.titleName == '合格数'">
                AND e.`level`='合格'
            </if>
        </if>
        <if test="qcResultPageVO.isPlacefile != null and qcResultPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultPageVO.isPlacefile}
        </if>
        <if test="qcResultPageVO.hospitalId != null and qcResultPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultPageVO.hospitalId}
        </if>
        <if test="qcResultPageVO.isPlacefile != null and qcResultPageVO.isPlacefile == 0">
            <if test="qcResultPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultPageVO.startDate}]]>
            </if>
            <if test="qcResultPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultPageVO.isPlacefile != null and qcResultPageVO.isPlacefile == 1">
            <if test="qcResultPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultPageVO.startDate}]]>
            </if>
            <if test="qcResultPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultPageVO.diagnose != null and qcResultPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultPageVO.deptName != null and qcResultPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultPageVO.deptName}
        </if>
        <if test="qcResultPageVO.deptId != null and qcResultPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultPageVO.deptId}
        </if>
        <if test="qcResultPageVO.behospitalCode != null and qcResultPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultPageVO.patName != null and qcResultPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultPageVO.patName}, '%' )
        </if>
        <if test="qcResultPageVO.doctorName != null and qcResultPageVO.doctorName != ''">
            AND (case
            when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            b.director_doctor != '' and b.director_doctor is not null
            then b.director_doctor
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            (b.director_doctor = '' or b.director_doctor is null) and
            b.behospital_doctor != '' and b.behospital_doctor is not null
            then b.behospital_doctor end) LIKE CONCAT( '%', #{qcResultPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultPageVO.professor != null and qcResultPageVO.professor != ''">
            AND (case
            when b.attending_doctor != '' and b.attending_doctor is not null then '主治医师'
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            b.director_doctor != '' and b.director_doctor is not null
            then '主任医师'
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            (b.director_doctor = '' or b.director_doctor is null) and
            b.behospital_doctor != '' and b.behospital_doctor is not null
            then '住院医师' end) = #{qcResultPageVO.professor}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        LEFT JOIN bas_doctor_info f
        on be.hospital_id = f.hospital_id
        and be.doctorName = f.name
        AND f.is_deleted = 'N'
        where
        1=1
        <if test="qcResultPageVO.level != null and qcResultPageVO.level != ''">
            AND b.`level` = #{qcResultPageVO.level}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        where
        1=1
        <if test="qcResultPageVO.doctorId != null and qcResultPageVO.doctorId != ''">
            AND t.doctorId = #{qcResultPageVO.doctorId}
        </if>
        <if test="qcResultPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultPageVO.checkStatus}
        </if>
        <if test="qcResultPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultPageVO.mrStatus}
        </if>
        <if test="qcResultPageVO.chName != null and qcResultPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultPageVO.chName}, '%')
        </if>
        <if test="qcResultPageVO.mrName != null and qcResultPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultPageVO.mrName}, '%')
        </if>
        <if test="qcResultPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultPageVO.mrTimeEnd}]]>
        </if>
    </select>


    <!-- 未整改病历质控评分页（内页）-->
    <select id="unModifyMRPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}

        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 未整改病历质控评分页-科室（内页）-->
    <select id="unModifyMRByDept" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT t.*
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND a.beh_dept_id = f.dept_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND f.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 病案首页不合格/合格数病历详情页导出-->
    <select id="badLevelPagePageExport" resultMap="ExportExcelMap">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        f1.msg,
        f1.caseName,
        </if>
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        qd.msg AS msg,
        qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.score_res as scoreBn,
        c.cases_id,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.qc_type_id != 0
        AND c.cases_id = 243
        <if test="qcResultShortPageVO.titleName != null ">
            <if test="qcResultShortPageVO.titleName == '不合格数'">
                AND c.`level`='不合格'
            </if>
            <if test="qcResultShortPageVO.titleName == '合格数'">
                AND c.`level`='合格'
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        left join qc_cases_entry d
        on  d.is_deleted = 'N'
        AND be.cases_id = d.cases_id
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
        AND qd.cases_id = qce.cases_id
        AND qd.cases_entry_id = qce.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        b.LEVEL,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = 243
        <if test="qcResultShortPageVO.titleName != null ">
            <if test="qcResultShortPageVO.titleName == '不合格数'">
                AND c.`level`='不合格'
            </if>
            <if test="qcResultShortPageVO.titleName == '合格数'">
                AND c.`level`='合格'
            </if>
        </if>
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
    </select>

    <!-- 病案首页不合格/合格数病历详情页XY导出-->
    <select id="badLevelPageXYExport" resultMap="ExportExcelMap">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            f1.msg,
            f1.caseName,
        </if>
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            qd.msg AS msg,
            qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.doctorId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.level,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_name AS doctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.doctorId,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.level,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        f.doctor_id as doctorId,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.score_res as scoreBn,
        c.cases_id,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        case
        when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        b.director_doctor != '' and b.director_doctor is not null
        then b.director_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        (b.director_doctor = '' or b.director_doctor is null) and
        b.behospital_doctor != '' and b.behospital_doctor is not null
        then b.behospital_doctor end as doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.qc_type_id != 0
        AND c.cases_id = 243
        <if test="qcResultShortPageVO.titleName != null ">
            <if test="qcResultShortPageVO.titleName == '不合格数'">
                AND c.`level`='不合格'
            </if>
            <if test="qcResultShortPageVO.titleName == '合格数'">
                AND c.`level`='合格'
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (case
            when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            b.director_doctor != '' and b.director_doctor is not null
            then b.director_doctor
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            (b.director_doctor = '' or b.director_doctor is null) and
            b.behospital_doctor != '' and b.behospital_doctor is not null
            then b.behospital_doctor end) LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.professor != null and qcResultShortPageVO.professor != ''">
            AND (case
            when b.attending_doctor != '' and b.attending_doctor is not null then '主治医师'
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            b.director_doctor != '' and b.director_doctor is not null
            then '主任医师'
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            (b.director_doctor = '' or b.director_doctor is null) and
            b.behospital_doctor != '' and b.behospital_doctor is not null
            then '住院医师' end) = #{qcResultShortPageVO.professor}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        left join qc_cases_entry d
        on  d.is_deleted = 'N'
        AND be.cases_id = d.cases_id
        LEFT JOIN bas_doctor_info f
        on be.hospital_id = f.hospital_id
        and be.doctor_name = f.name
        AND f.is_deleted = 'N'
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
            AND t.hospitalId = qd.hospital_id
            AND t.behospitalCode = qd.behospital_code
            LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
            AND qd.cases_id = qc.id
            LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
            AND qd.cases_id = qce.cases_id
            AND qd.cases_entry_id = qce.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND t.doctorId = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.level = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (SELECT DISTINCT
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.hospital_id as hospitalId,
        t1.behospital_code as behospitalCode,
        t1.`level`,
        t1.checkStatus,
        t1.mrStatus,
        t1.doctorId,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.grade_type,
        b.score_res,
        b.`level`,
        b.gmt_create,
        f.doctor_id as doctorId,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.beh_dept_id,
        a.beh_dept_name,
        a.hospital_id,
        case
        when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        b.director_doctor != '' and b.director_doctor is not null
        then b.director_doctor
        when (b.attending_doctor = '' or b.attending_doctor is null) and
        (b.director_doctor = '' or b.director_doctor is null) and
        b.behospital_doctor != '' and b.behospital_doctor is not null
        then b.behospital_doctor end as doctor_name,
        a.behospital_code
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = 243
                <if test="qcResultShortPageVO.titleName != null ">
                    <if test="qcResultShortPageVO.titleName == '不合格数'">
                        AND c.`level`='不合格'
                    </if>
                    <if test="qcResultShortPageVO.titleName == '合格数'">
                        AND c.`level`='合格'
                    </if>
                </if>
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (case
            when b.attending_doctor != '' and b.attending_doctor is not null then b.attending_doctor
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            b.director_doctor != '' and b.director_doctor is not null
            then b.director_doctor
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            (b.director_doctor = '' or b.director_doctor is null) and
            b.behospital_doctor != '' and b.behospital_doctor is not null
            then b.behospital_doctor end) LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        <if test="qcResultShortPageVO.professor != null and qcResultShortPageVO.professor != ''">
            AND (case
            when b.attending_doctor != '' and b.attending_doctor is not null then '主治医师'
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            b.director_doctor != '' and b.director_doctor is not null
            then '主任医师'
            when (b.attending_doctor = '' or b.attending_doctor is null) and
            (b.director_doctor = '' or b.director_doctor is null) and
            b.behospital_doctor != '' and b.behospital_doctor is not null
            then '住院医师' end) = #{qcResultShortPageVO.professor}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        LEFT JOIN bas_doctor_info f
        on be.hospital_id = f.hospital_id
        and be.doctor_name = f.name
        AND f.is_deleted = 'N'
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND t.doctorId = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND t.level = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
    </select>


    <!-- 病案首页不合格/合格数病历详情页导出-科室-->
    <select id="homePageOrLevelExportByDept" resultMap="ExportExcelMapByDept">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            f1.msg,
            f1.caseName,
        </if>
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName AS doctorName,
        t.doctorId,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            qd.msg AS msg,
            qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.score_res as scoreBn,
        c.cases_id,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        sys_user_dept b,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.beh_dept_id = b.dept_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.qc_type_id != 0
        AND c.cases_id = 243
        <if test="qcResultShortPageVO.userId!=null">
            AND b.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.titleName != null ">
            <if test="qcResultShortPageVO.titleName == '不合格数'">
                AND c.`level`='不合格'
            </if>
            <if test="qcResultShortPageVO.titleName == '合格数'">
                AND c.`level`='合格'
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name LIKE CONCAT( '%', #{qcResultShortPageVO.deptName}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND a.doctor_id = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        left join qc_cases_entry d
        on  d.is_deleted = 'N'
        AND be.cases_id = d.cases_id
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
            AND t.hospitalId = qd.hospital_id
            AND t.behospitalCode = qd.behospital_code
            LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
            AND qd.cases_id = qc.id
            LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
            AND qd.cases_id = qce.cases_id
            AND qd.cases_entry_id = qce.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.doctorId,
        t.doctorName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        b.grade_type,
        b.score_res,
        b.gmt_create,
        b.LEVEL,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name
        FROM
        med_behospital_info a,
        sys_user_dept b,
        med_qcresult_cases c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = c.behospital_code
        AND a.beh_dept_id = b.dept_id
        AND a.qc_type_id != 0
        AND c.cases_id = 243
        <if test="qcResultShortPageVO.titleName != null ">
            <if test="qcResultShortPageVO.titleName == '不合格数'">
                AND c.`level`='不合格'
            </if>
            <if test="qcResultShortPageVO.titleName == '合格数'">
                AND c.`level`='合格'
            </if>
        </if>
        <if test="qcResultShortPageVO.userId!=null">
            AND b.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name LIKE CONCAT( '%', #{qcResultShortPageVO.deptName}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptId != null and qcResultShortPageVO.deptId != ''">
            AND a.beh_dept_id = #{qcResultShortPageVO.deptId}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND a.doctor_id = #{qcResultShortPageVO.doctorId}
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        left join med_qcresult_info b
        on  b.is_deleted = 'N'
        AND be.hospital_id = b.hospital_id
        AND be.behospital_code = b.behospital_code
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        )f2
        WHERE
        f1.doctorId = f2.doctorId
        AND f1.doctorName = f2.doctorName
    </select>

    <!-- 未整改病历缺陷评分详情页导出-->
    <select id="unModifyMRPageExport" resultMap="ExportExcelMap">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        f1.msg,
        f1.caseName,
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        qd.msg AS msg,
        qc.NAME AS caseName,
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
        AND qd.cases_id = qce.cases_id
        AND qd.cases_entry_id = qce.id
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
    </select>

    <!-- 未整改病历缺陷评分详情页导出-科室-->
    <select id="unModifyExportByDept" resultMap="ExportExcelMapByDept">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        f1.msg,
        f1.caseName,
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName,
        t.doctorId,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        qd.msg AS msg,
        qc.NAME AS caseName,
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        e.score_res as scoreBn,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.beh_dept_id = f.dept_id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND f.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        LEFT JOIN qc_cases_entry qce ON qce.is_deleted = 'N'
        AND qd.cases_id = qce.cases_id
        AND qd.cases_entry_id = qce.id
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND qce.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND qce.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        FROM
        (SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (SELECT
        be.*,
        ifnull(mci.status,0) AS checkStatus,
        ifnull(hm_mci.status,0) AS mrStatus,
        mci.check_name as chName,
        hm_mci.check_name as mrName,
        mci.gmt_create as chTime,
        hm_mci.gmt_create as mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        med_qcresult_detail c,
        qc_cases_entry d,
        sys_user_dept f
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND c.cases_id = d.cases_id
        AND c.cases_entry_id = d.id
        AND a.beh_dept_id = f.dept_id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND f.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.casesEntryName != null and qcResultShortPageVO.casesEntryName != ''">
            AND d.NAME = #{qcResultShortPageVO.casesEntryName}
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.casesEntryId != null ">
            AND d.id = #{qcResultShortPageVO.casesEntryId}
        </if>
        <if test="qcResultShortPageVO.isReject != null">
            AND c.is_reject = #{qcResultShortPageVO.isReject}
        </if>
        <if test="qcResultShortPageVO.ruleType != null">
            AND d.rule_type = #{qcResultShortPageVO.ruleType}
        </if>
        )be
        left join med_check_info mci
        on mci.is_deleted = 'N'
        and mci.check_type in(0,2)
        and be.hospital_id = mci.hospital_id
        and be.behospital_code = mci.behospital_code
        left join med_check_info hm_mci
        on hm_mci.is_deleted = 'N'
        and hm_mci.check_type = 1
        and be.hospital_id = hm_mci.hospital_id
        and be.behospital_code = hm_mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.doctorId,
        t.doctorName
        )f2
        WHERE
        f1.doctorId = f2.doctorId
        AND f1.doctorName = f2.doctorName
    </select>


    <!-- 31天再入院详情页-->
    <select id="reHos31DaysPage" resultType="com.diagbot.dto.ReBeHosMergeDTO">
        SELECT
        t.fileCode,
        t.diagnose,
        t.diagnoseName,
        t.NAME,
        t.sex,
        t.hospitalId,
        t.behDeptId,
        t.behDeptName,
        t.behospitalCode,
        t.behospitalDate,
        t.lastDiagnose,
        t.lastDiagnoseName,
        t.leaveHospitalDate,
        t.lastBehDeptId,
        t.lastBehDeptName,
        t.lastBehospitalCode,
        t.lastBehospitalDate,
        t.lastLeaveHospitalDate,
        t.diffDays,
        mqi.score_res AS scoreRes,
        mqi.LEVEL AS LEVEL,
        mqi_last.score_res AS lastScoreRes,
        mqi_last.LEVEL AS lastLevel,
        mhp.total_fee AS totleFee,
        mhp.behospital_day_num AS behospitalDayNum,
        mhp.again_behospital_plan AS againBehospitalPlan,
        IF(mhp.age is null, null,CONCAT( ifnull(mhp.age,'') ,ifnull(mhp.age_unit,'') ))as age,
        mhp_last.again_behospital_plan AS lastAgainBehospitalPlan,
        IF(mhp_last.age is null, null,CONCAT( ifnull(mhp_last.age,'') ,ifnull(mhp_last.age_unit,'') ))as lastAge,
        mhp_last.total_fee AS lastTotleFee,
        mhp_last.behospital_day_num AS lastBehospitalDayNum
        FROM
        (
        SELECT
        be.fileCode,
        be.diagnose,
        be.diagnoseName,
        be.NAME,
        be.sex,
        be.hospitalId,
        be.behDeptId,
        be.behDeptName,
        be.behospitalCode,
        be.behospitalDate,
        be.leaveHospitalDate,
        be.lastDiagnose,
        be.lastDiagnoseName,
        be.lastBehDeptId,
        be.lastBehDeptName,
        be.lastBehospitalCode,
        be.lastBehospitalDate,
        be.lastLeaveHospitalDate,
        be.diffDays
        FROM
        (
        SELECT
        r1.file_code AS fileCode,
        r1.diagnose,
        r1.diagnose_name AS diagnoseName,
        r1.NAME,
        r1.sex,
        r1.hospital_id AS hospitalId,
        r1.beh_dept_id AS behDeptId,
        r1.beh_dept_name AS behDeptName,
        r1.behospital_code AS behospitalCode,
        r1.behospital_date AS behospitalDate,
        r1.leave_hospital_date AS leaveHospitalDate,
        r2.diagnose AS lastDiagnose,
        r2.diagnose_name AS lastDiagnoseName,
        r2.beh_dept_id AS lastBehDeptId,
        r2.beh_dept_name AS lastBehDeptName,
        r2.behospital_code AS lastBehospitalCode,
        r2.behospital_date AS lastBehospitalDate,
        r2.leave_hospital_date AS lastLeaveHospitalDate,
        TIMESTAMPDIFF( DAY, DATE( r2.leave_hospital_date ), DATE( r1.behospital_date ) ) AS diffDays
        FROM
        (
        SELECT
        ( @rownum := @rownum + 1 ) AS rownum,
        t1.file_code,
        t1.behospital_code,
        t1.diagnose,
        t1.diagnose_name,
        t1.NAME,
        t1.sex,
        t1.hospital_id,
        t1.beh_dept_id,
        t1.beh_dept_name,
        t1.behospital_date,
        t1.leave_hospital_date
        FROM(
        select
        tt3.file_code,
        tt3.behospital_code,
        tt3.diagnose,
        tt3.NAME,
        tt3.sex,
        tt3.hospital_id,
        tt3.beh_dept_id,
        tt3.beh_dept_name,
        tt3.behospital_date,
        tt3.leave_hospital_date,
        GROUP_CONCAT(case when tt5.diagnose_name is not null then tt5.diagnose_name else '' end) as diagnose_name
        FROM(
        SELECT
        tt2.file_code,
        tt2.diagnose,
        tt2.NAME,
        tt2.sex,
        tt2.hospital_id,
        tt2.beh_dept_id,
        tt2.beh_dept_name,
        tt2.behospital_code,
        tt2.behospital_date,
        tt2.leave_hospital_date
        FROM
        (
        SELECT
        a.file_code
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and a.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        AND a.qc_type_id != 0
        AND IFNULL( a.diagnose, '' )!= ''
        AND IFNULL( a.file_code, '' )!= ''
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND a.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND a.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND a.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        GROUP BY
        a.file_code
        HAVING
        count(*)> 1
        ) tt1,
        med_behospital_info tt2
        WHERE
        tt2.is_deleted = 'N'
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and tt2.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        AND tt2.qc_type_id != 0
        AND tt1.file_code = tt2.file_code
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND tt2.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND tt2.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND tt2.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND tt2.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND tt2.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        ORDER BY
        tt1.file_code,
        tt2.behospital_date DESC)tt3
        left join med_home_page tt4 on tt4.is_deleted = 'N'
        AND tt3.hospital_id = tt4.hospital_id
        AND tt3.behospital_code = tt4.behospital_code
        LEFT JOIN med_home_diagnose_info tt5 on tt5.is_deleted = 'N'
        AND tt4.hospital_id = tt5.hospital_id
        AND tt4.home_page_id = tt5.home_page_id
        GROUP by tt3.behospital_code
        ORDER BY tt3.file_code,tt3.leave_hospital_date DESC
        ) t1,
        ( SELECT @rownum := 0 ) r
        ) r1
        LEFT JOIN (
        SELECT
        ( @INDEX := @INDEX + 1 ) AS rownum,
        t1.file_code,
        t1.behospital_code,
        t1.diagnose,
        t1.diagnose_name,
        t1.NAME,
        t1.sex,
        t1.hospital_id,
        t1.beh_dept_id,
        t1.beh_dept_name,
        t1.behospital_date,
        t1.leave_hospital_date
        FROM(
        select
        tt3.file_code,
        tt3.behospital_code,
        tt3.diagnose,
        tt3.NAME,
        tt3.sex,
        tt3.hospital_id,
        tt3.beh_dept_id,
        tt3.beh_dept_name,
        tt3.behospital_date,
        tt3.leave_hospital_date,
        GROUP_CONCAT(case when tt5.diagnose_name is not null then tt5.diagnose_name else '' end) as diagnose_name
        FROM(
        SELECT
        tt2.file_code,
        tt2.diagnose,
        tt2.NAME,
        tt2.sex,
        tt2.hospital_id,
        tt2.beh_dept_id,
        tt2.beh_dept_name,
        tt2.behospital_code,
        tt2.behospital_date,
        tt2.leave_hospital_date
        FROM
        (
        SELECT
        a.file_code
        FROM
        med_behospital_info a
        WHERE
        a.is_deleted = 'N'
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and a.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        AND a.qc_type_id != 0
        AND IFNULL( a.diagnose, '' )!= ''
        AND IFNULL( a.file_code, '' )!= ''
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND a.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND a.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND a.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        GROUP BY
        a.file_code
        HAVING
        count(*)> 1
        ) tt1,
        med_behospital_info tt2
        WHERE
        tt2.is_deleted = 'N'
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and tt2.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        AND tt2.qc_type_id != 0
        AND tt1.file_code = tt2.file_code
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND tt2.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND tt2.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND tt2.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND tt2.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND tt2.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        ORDER BY
        tt1.file_code,
        tt2.behospital_date DESC)tt3
        left join med_home_page tt4 on tt4.is_deleted = 'N'
        AND tt3.hospital_id = tt4.hospital_id
        AND tt3.behospital_code = tt4.behospital_code
        LEFT JOIN med_home_diagnose_info tt5 on tt5.is_deleted = 'N'
        AND tt4.hospital_id = tt5.hospital_id
        AND tt4.home_page_id = tt5.home_page_id
        GROUP by tt3.behospital_code
        ORDER BY tt3.file_code,tt3.leave_hospital_date DESC
        ) t1,
        ( SELECT @INDEX := 0 ) r
        ) r2 ON r1.file_code = r2.file_code
        AND r1.rownum = r2.rownum - 1
        ) be
        WHERE
        be.diffDays IS NOT NULL
        AND be.diffDays BETWEEN 0
        AND 31
        ) t
        LEFT JOIN med_qcresult_info mqi ON mqi.is_deleted = 'N'
        AND t.hospitalId = mqi.hospital_id
        AND t.behospitalCode = mqi.behospital_code
        LEFT JOIN med_qcresult_info mqi_last ON mqi_last.is_deleted = 'N'
        AND t.hospitalId = mqi_last.hospital_id
        AND t.lastBehospitalCode = mqi_last.behospital_code
        LEFT JOIN med_home_page mhp ON mhp.is_deleted = 'N'
        AND t.hospitalId = mhp.hospital_id
        AND t.behospitalCode = mhp.behospital_code
        LEFT JOIN med_home_page mhp_last ON mhp_last.is_deleted = 'N'
        AND t.hospitalId = mhp_last.hospital_id
        AND t.lastBehospitalCode = mhp_last.behospital_code
    </select>

    <!-- 31天再入院详情页-科室-->
    <select id="reHos31DaysPageByDept" resultType="com.diagbot.dto.ReBeHosMergeDTO">
        SELECT
        t.fileCode,
        t.diagnose,
        t.diagnoseName,
        t.NAME,
        t.sex,
        t.hospitalId,
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName,
        t.behospitalCode,
        t.behospitalDate,
        t.leaveHospitalDate,
        t.lastDiagnose,
        t.lastDiagnoseName,
        t.lastBehDeptId,
        t.lastBehDeptName,
        t.lastDoctorName,
        t.lastBehospitalCode,
        t.lastBehospitalDate,
        t.lastLeaveHospitalDate,
        t.diffDays,
        mqi.score_res AS scoreRes,
        mqi.LEVEL AS LEVEL,
        mqi_last.score_res AS lastScoreRes,
        mqi_last.LEVEL AS lastLevel,
        mhp.again_behospital_plan AS againBehospitalPlan,
        mhp_last.again_behospital_plan AS lastAgainBehospitalPlan,
        mhp.total_fee AS totleFee,
        mhp.behospital_day_num AS behospitalDayNum,
        mhp_last.total_fee AS lastTotleFee,
        mhp_last.behospital_day_num AS lastBehospitalDayNum
        FROM
        (
        SELECT
        be.fileCode,
        be.diagnose,
        be.diagnoseName,
        be.NAME,
        be.sex,
        be.hospitalId,
        be.behDeptId,
        be.behDeptName,
        be.doctorId,
        be.doctorName,
        be.behospitalCode,
        be.behospitalDate,
        be.leaveHospitalDate,
        be.lastDiagnose,
        be.lastDiagnoseName,
        be.lastBehDeptId,
        be.lastBehDeptName,
        be.lastDoctorId,
        be.lastDoctorName,
        be.lastBehospitalCode,
        be.lastBehospitalDate,
        be.lastLeaveHospitalDate,
        be.diffDays
        FROM
        (
        SELECT
        r1.file_code AS fileCode,
        r1.diagnose,
        r1.diagnose_name AS diagnoseName,
        r1.NAME,
        r1.sex,
        r1.hospital_id AS hospitalId,
        r1.beh_dept_id AS behDeptId,
        r1.beh_dept_name AS behDeptName,
        r1.doctor_id as doctorId,
        r1.doctor_name as doctorName,
        r1.behospital_code AS behospitalCode,
        r1.behospital_date AS behospitalDate,
        r1.leave_hospital_date AS leaveHospitalDate,
        r2.diagnose AS lastDiagnose,
        r2.diagnose_name AS lastDiagnoseName,
        r2.beh_dept_id AS lastBehDeptId,
        r2.beh_dept_name AS lastBehDeptName,
        r2.behospital_code AS lastBehospitalCode,
        r2.behospital_date AS lastBehospitalDate,
        r2.doctor_id as lastDoctorId,
        r2.doctor_name as lastDoctorName,
        r2.leave_hospital_date AS lastLeaveHospitalDate,
        TIMESTAMPDIFF( DAY, DATE( r2.leave_hospital_date ), DATE( r1.behospital_date ) ) AS diffDays
        FROM
        (
        SELECT
        ( @rownum := @rownum + 1 ) AS rownum,
        t1.file_code,
        t1.NAME,
        t1.sex,
        t1.diagnose,
        t1.diagnose_name,
        t1.doctor_id,
        t1.doctor_name,
        t1.hospital_id,
        t1.beh_dept_id,
        t1.beh_dept_name,
        t1.behospital_code,
        t1.behospital_date,
        t1.leave_hospital_date
        FROM
        (
        select
        tt3.file_code,
        tt3.behospital_code,
        tt3.diagnose,
        tt3.NAME,
        tt3.sex,
        tt3.hospital_id,
        tt3.beh_dept_id,
        tt3.beh_dept_name,
        tt3.doctor_id,
        tt3.doctor_name,
        tt3.behospital_date,
        tt3.leave_hospital_date,
        GROUP_CONCAT(case when tt5.diagnose_name is not null then tt5.diagnose_name else '' end) as diagnose_name
        FROM(
        SELECT
        tt1.file_code,
        tt2.diagnose,
        tt2.doctor_id,
        tt2.doctor_name,
        tt2.NAME,
        tt2.sex,
        tt2.hospital_id,
        tt2.beh_dept_id,
        tt2.beh_dept_name,
        tt2.behospital_code,
        tt2.behospital_date,
        tt2.leave_hospital_date
        FROM
        (
        SELECT
        a.file_code
        FROM
        med_behospital_info a,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.beh_dept_id = c.dept_id
        <if test="reBeHosPageVO.deptName != null and reBeHosPageVO.deptName != ''">
            and a.beh_dept_name = #{reBeHosPageVO.deptName}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and a.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        <if test="reBeHosPageVO.userId!=null">
            AND c.user_id = #{reBeHosPageVO.userId}
        </if>
        AND a.qc_type_id != 0
        AND IFNULL( a.diagnose, '' )!= ''
        AND IFNULL( a.file_code, '' )!= ''
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND a.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND a.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND a.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        GROUP BY
        a.file_code
        HAVING
        count(*)> 1
        ) tt1,
        med_behospital_info tt2
        WHERE
        tt2.is_deleted = 'N'
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and tt2.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        AND tt2.qc_type_id != 0
        AND tt1.file_code = tt2.file_code
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND tt2.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND tt2.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND tt2.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND tt2.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND tt2.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        ORDER BY
        tt1.file_code,
        tt2.behospital_date DESC)tt3
        left join med_home_page tt4 on tt4.is_deleted = 'N'
        AND tt3.hospital_id = tt4.hospital_id
        AND tt3.behospital_code = tt4.behospital_code
        LEFT JOIN med_home_diagnose_info tt5 on tt5.is_deleted = 'N'
        AND tt4.hospital_id = tt5.hospital_id
        AND tt4.home_page_id = tt5.home_page_id
        GROUP by tt3.behospital_code
        ORDER BY tt3.file_code,tt3.leave_hospital_date DESC
        ) t1,
        ( SELECT @rownum := 0 ) r
        ) r1
        LEFT JOIN (
        SELECT
        ( @INDEX := @INDEX + 1 ) AS rownum,
        t1.file_code,
        t1.NAME,
        t1.sex,
        t1.diagnose,
        t1.diagnose_name,
        t1.doctor_id,
        t1.doctor_name,
        t1.hospital_id,
        t1.beh_dept_id,
        t1.beh_dept_name,
        t1.behospital_code,
        t1.behospital_date,
        t1.leave_hospital_date
        FROM
        (
        select
        tt3.file_code,
        tt3.behospital_code,
        tt3.diagnose,
        tt3.NAME,
        tt3.sex,
        tt3.hospital_id,
        tt3.beh_dept_id,
        tt3.beh_dept_name,
        tt3.doctor_id,
        tt3.doctor_name,
        tt3.behospital_date,
        tt3.leave_hospital_date,
        GROUP_CONCAT(case when tt5.diagnose_name is not null then tt5.diagnose_name else '' end) as diagnose_name
        FROM(
        SELECT
        tt1.file_code,
        tt2.diagnose,
        tt2.doctor_id,
        tt2.doctor_name,
        tt2.NAME,
        tt2.sex,
        tt2.hospital_id,
        tt2.beh_dept_id,
        tt2.beh_dept_name,
        tt2.behospital_code,
        tt2.behospital_date,
        tt2.leave_hospital_date
        FROM
        (
        SELECT
        a.file_code
        FROM
        med_behospital_info a,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = c.hospital_id
        AND a.beh_dept_id = c.dept_id
        <if test="reBeHosPageVO.deptName != null and reBeHosPageVO.deptName != ''">
            and a.beh_dept_name = #{reBeHosPageVO.deptName}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and a.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        <if test="reBeHosPageVO.userId!=null">
            AND c.user_id = #{reBeHosPageVO.userId}
        </if>
        AND a.qc_type_id != 0
        AND IFNULL( a.diagnose, '' )!= ''
        AND IFNULL( a.file_code, '' )!= ''
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND a.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND a.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND a.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        GROUP BY
        a.file_code
        HAVING
        count(*)> 1
        ) tt1,
        med_behospital_info tt2
        WHERE
        tt2.is_deleted = 'N'
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile != ''">
            and tt2.is_placefile = #{reBeHosPageVO.isPlacefile}
        </if>
        AND tt2.qc_type_id != 0
        AND tt1.file_code = tt2.file_code
        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
            AND tt2.hospital_id = #{reBeHosPageVO.hospitalId}
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 0">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.behospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null ">
                <![CDATA[ AND tt2.behospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.isPlacefile != null and reBeHosPageVO.isPlacefile == 1">
            <if test="reBeHosPageVO.startDate != null ">
                <![CDATA[ AND tt2.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
            </if>
            <if test="reBeHosPageVO.endDate != null">
                <![CDATA[ AND tt2.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
            </if>
        </if>
        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
            AND tt2.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
        </if>
        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
            AND tt2.name like concat('%', #{reBeHosPageVO.name},'%')
        </if>
        ORDER BY
        tt1.file_code,
        tt2.behospital_date DESC)tt3
        left join med_home_page tt4 on tt4.is_deleted = 'N'
        AND tt3.hospital_id = tt4.hospital_id
        AND tt3.behospital_code = tt4.behospital_code
        LEFT JOIN med_home_diagnose_info tt5 on tt5.is_deleted = 'N'
        AND tt4.hospital_id = tt5.hospital_id
        AND tt4.home_page_id = tt5.home_page_id
        GROUP by tt3.behospital_code
        ORDER BY tt3.file_code,tt3.leave_hospital_date DESC
        ) t1,
        ( SELECT @INDEX := 0 ) r
        ) r2 ON r1.file_code = r2.file_code
        AND r1.rownum = r2.rownum - 1
        ) be
        WHERE
        be.diffDays IS NOT NULL
        AND be.diffDays BETWEEN 0
        AND 31
        ) t
        LEFT JOIN med_qcresult_info mqi ON mqi.is_deleted = 'N'
        AND t.hospitalId = mqi.hospital_id
        AND t.behospitalCode = mqi.behospital_code
        LEFT JOIN med_qcresult_info mqi_last ON mqi_last.is_deleted = 'N'
        AND t.hospitalId = mqi_last.hospital_id
        AND t.lastBehospitalCode = mqi_last.behospital_code
        LEFT JOIN med_home_page mhp ON mhp.is_deleted = 'N'
        AND t.hospitalId = mhp.hospital_id
        AND t.behospitalCode = mhp.behospital_code
        LEFT JOIN med_home_page mhp_last ON mhp_last.is_deleted = 'N'
        AND t.hospitalId = mhp_last.hospital_id
        AND t.lastBehospitalCode = mhp_last.behospital_code
    </select>

    <!-- 单条条目缺陷统计-->
    <select id="casesEntryStatisticsById" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.beh_dept_id AS id,
        a.beh_dept_name AS NAME,
        count(*) AS num
        FROM
        med_behospital_info a,
        med_qcresult_detail b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.qc_type_id != 0
        and b.cases_entry_id=2658
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name
    </select>

    <!-- 单条条目缺陷统计-->
    <select id="casesEntryStatisticsByDept" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.AdmissionCountDTO">
        SELECT
        a.beh_dept_id AS deptId,
        a.beh_dept_name AS deptName,
        a.doctor_id as doctorId,
        a.doctor_name as doctorName,
        count(*) AS num
        FROM
        med_behospital_info a,
        med_qcresult_detail b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.beh_dept_id = c.dept_id
        AND a.qc_type_id != 0
        and b.cases_entry_id=2658
        <if test="isPlacefile != null and isPlacefile != ''">
            and a.is_placefile = #{isPlacefile}
        </if>
        <if test="hospitalId != null and hospitalId != ''">
            AND a.hospital_id = #{hospitalId}
        </if>
        <if test="userId!=null">
            AND c.user_id = #{userId}
        </if>
        <if test="isPlacefile != null and isPlacefile == 0">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
            </if>
        </if>
        <if test="isPlacefile != null and isPlacefile == 1">
            <if test="startDate != null and startDate != ''">
                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
            </if>
        </if>
        GROUP BY
        a.beh_dept_id,
        a.beh_dept_name,
        a.doctor_id,
        a.doctor_name
    </select>

    <!-- 病案首页改善率质控评分页（内页）-->
    <select id="hmImproveMRPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT
        t.*
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.chName,
        t1.chTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        mci.check_name AS chName,
        mci.gmt_create AS chTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.LEVEL,
        c.grade_type,
        c.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        c.gmt_create,
        d.score_res as scoreBn
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        AND m1.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and m1.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND m1.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND m1.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null">
                <![CDATA[ AND m1.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND m1.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 2">
            <![CDATA[AND ( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 )]]>
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 3">
            AND d.score_res = 20
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        WHERE
        1 = 1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 病案首页改善率质控评分页（内页）-科室-->
    <select id="hmImproveMRPageByDept" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT
        t.*
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.scoreBn,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        ifnull( hm_mci.STATUS, 0 ) AS mrStatus,
        mci.check_name AS chName,
        hm_mci.check_name AS mrName,
        e.score_res as scoreBn,
        mci.gmt_create AS chTime,
        hm_mci.gmt_create AS mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.LEVEL,
        c.grade_type,
        c.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        c.gmt_create
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        sys_user_dept f,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        AND m1.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and m1.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND m1.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND m1.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null">
                <![CDATA[ AND m1.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND m1.beh_dept_name like CONCAT('%', #{qcResultShortPageVO.deptName}, '%')
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND a.behospital_code = e.behospital_code
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND f.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 2">
            <![CDATA[AND ( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 )]]>
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 3">
            AND d.score_res = 20
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_check_info hm_mci ON hm_mci.is_deleted = 'N'
        AND hm_mci.check_type = 1
        AND be.hospital_id = hm_mci.hospital_id
        AND be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        WHERE
        1 = 1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>


    <!-- 质控核查质控评分页（内页）-->
    <select id="qcCheckMRPage" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT
        t.*
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.chName,
        t1.chTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        mci.check_name AS chName,
        e.score_res as scoreBn,
        mci.gmt_create AS chTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        WHERE
        1 = 1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 质控核查质控评分页-科室（内页）-->
    <select id="qcCheckMRPageByDept" resultType="com.diagbot.dto.QcResultShortDTO">
        SELECT
        t.*
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        CONCAT( ifnull(t2.age,'') ,ifnull(t2.age_unit,'') )as age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        ifnull( hm_mci.STATUS, 0 ) AS mrStatus,
        mci.check_name AS chName,
        e.score_res as scoreBn,
        hm_mci.check_name AS mrName,
        mci.gmt_create AS chTime,
        hm_mci.gmt_create AS mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.beh_dept_id = c.dept_id
        AND a.behospital_code = b.behospital_code
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND c.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND b.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_check_info hm_mci ON hm_mci.is_deleted = 'N'
        AND hm_mci.check_type = 1
        AND be.hospital_id = hm_mci.hospital_id
        AND be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        WHERE
        1 = 1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
    </select>

    <!-- 病案首页改善率质控评分页导出-->
    <select id="hmImproveMRPageExport" resultMap="ExportExcelMap">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        f1.msg,
        f1.caseName,
        </if>
        f1.checkStatus,
        f1.chName,
        f1.chTime
        FROM
        (SELECT
        t.doctorName AS behDoctorName,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        qd.msg AS msg,
        qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.chName,
        t.chTime
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.chName,
        t1.chTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        mci.check_name AS chName,
        mci.gmt_create AS chTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.LEVEL,
        c.grade_type,
        c.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        c.gmt_create,
        d.score_res as scoreBn
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        AND m1.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and m1.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND m1.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND m1.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null">
                <![CDATA[ AND m1.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND m1.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 2">
            <![CDATA[AND ( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 )]]>
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 3">
            AND d.score_res = 20
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.chName,
        t1.chTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        mci.check_name AS chName,
        mci.gmt_create AS chTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.LEVEL,
        c.grade_type,
        c.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        c.gmt_create
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        AND m1.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and m1.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND m1.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND m1.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null">
                <![CDATA[ AND m1.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND m1.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 2">
            <![CDATA[AND ( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 )]]>
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 3">
            AND d.score_res = 20
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
    </select>

    <!-- 病案首页改善率质控评分页导出-->
    <select id="improveMRExportByDept" resultMap="ExportExcelMapByDept">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorId,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.scoreBn,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f2.avgScore,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            f1.msg,
            f1.caseName,
        </if>
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorId,
        t.doctorName,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            qd.msg AS msg,
            qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t1.scoreBn,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        ifnull( hm_mci.STATUS, 0 ) AS mrStatus,
        mci.check_name AS chName,
        e.score_res as scoreBn,
        hm_mci.check_name AS mrName,
        mci.gmt_create AS chTime,
        hm_mci.gmt_create AS mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.LEVEL,
        c.grade_type,
        c.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        c.gmt_create
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        sys_user_dept f,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        AND m1.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and m1.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND m1.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND m1.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null">
                <![CDATA[ AND m1.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND m1.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND f.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 2">
            <![CDATA[AND ( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 )]]>
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 3">
            AND d.score_res = 20
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_check_info hm_mci ON hm_mci.is_deleted = 'N'
        AND hm_mci.check_type = 1
        AND be.hospital_id = hm_mci.hospital_id
        AND be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
            AND t.hospitalId = qd.hospital_id
            AND t.behospitalCode = qd.behospital_code
            LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
            AND qd.cases_id = qc.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        ifnull( hm_mci.STATUS, 0 ) AS mrStatus,
        mci.check_name AS chName,
        hm_mci.check_name AS mrName,
        mci.gmt_create AS chTime,
        hm_mci.gmt_create AS mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        c.LEVEL,
        c.grade_type,
        c.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        c.gmt_create
        FROM
        med_behospital_info a,
        med_home_page b,
        med_qcresult_info c,
        med_qcresult_cases d,
        sys_user_dept f,
        (
        SELECT
        m4.*
        FROM
        med_behospital_info m1,
        med_home_page m2,
        med_qcresult_info m3,
        med_qcresult_cases m4
        WHERE
        m1.is_deleted = 'N'
        AND m2.is_deleted = 'N'
        AND m3.is_deleted = 'Y'
        AND m4.is_deleted = 'Y'
        AND m1.hospital_id = m2.hospital_id
        AND m1.hospital_id = m3.hospital_id
        AND m1.hospital_id = m4.hospital_id
        AND m1.behospital_code = m2.behospital_code
        AND m1.behospital_code = m3.behospital_code
        AND m1.behospital_code = m4.behospital_code
        AND m3.gmt_create = m4.gmt_create
        AND m3.have_home_page = 1
        AND m4.cases_id = 243
        AND m1.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and m1.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND m1.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND m1.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null">
                <![CDATA[ AND m1.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND m1.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND m1.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        GROUP BY
        m1.behospital_code
        ORDER BY
        m1.behospital_code,
        m4.gmt_create
        ) e
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND d.is_deleted = 'N'
        AND f.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = d.hospital_id
        AND a.hospital_id = e.hospital_id
        AND a.hospital_id = f.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.behospital_code = c.behospital_code
        AND a.behospital_code = d.behospital_code
        AND a.behospital_code = e.behospital_code
        AND a.beh_dept_id = f.dept_id
        AND d.cases_id = 243
        AND d.score_res > e.score_res
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND f.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 2">
            <![CDATA[AND ( e.`level` = '不合格' AND d.`level` = '合格' AND d.score_res < 20 )]]>
        </if>
        <if test="qcResultShortPageVO.improveType != null and qcResultShortPageVO.improveType == 3">
            AND d.score_res = 20
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_check_info hm_mci ON hm_mci.is_deleted = 'N'
        AND hm_mci.check_type = 1
        AND be.hospital_id = hm_mci.hospital_id
        AND be.behospital_code = hm_mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.doctorId,
        t.doctorName
        )f2
        WHERE
        f1.doctorId = f2.doctorId
        AND f1.doctorName = f2.doctorName
    </select>

    <!-- 质控核查质控评分页导出-->
    <select id="qcCheckMRPageExport" resultMap="ExportExcelMap">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        f1.msg,
        f1.caseName,
        </if>
        f1.checkStatus,
        f1.chName,
        f1.chTime
        FROM
        (SELECT
        t.doctorName,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        qd.msg AS msg,
        qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.chName,
        t.chTime
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.chName,
        t1.chTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        mci.check_name AS chName,
        e.score_res as scoreBn,
        mci.gmt_create AS chTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}

        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
            LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
            AND t.hospitalId = qd.hospital_id
            AND t.behospitalCode = qd.behospital_code
            LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
            AND qd.cases_id = qc.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.chName,
        t1.chTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        mci.check_name AS chName,
        mci.gmt_create AS chTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}

        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.behDeptId,
        t.behDeptName
        )f2
        WHERE
        f1.behDeptId = f2.behDeptId
        AND f1.behDeptName = f2.behDeptName
    </select>


    <!-- 质控核查质控评分页导出 -科室-->
    <select id="qcCheckMRPageExportByDept" resultMap="ExportExcelMapByDept">
        SELECT
        f1.behDeptId,
        f1.behDeptName,
        f1.doctorName,
        f1.doctorId,
        f1.patName,
        f1.behospitalCode,
        f1.hospitalId,
        f1.behospitalDate,
        f1.leaveHospitalDate,
        f1.score,
        f1.scoreBn,
        f2.avgScore,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        f1.msg,
        f1.caseName,
        </if>
        f1.checkStatus,
        f1.mrStatus,
        f1.chName,
        f1.mrName,
        f1.chTime,
        f1.mrTime
        FROM
        (SELECT
        t.doctorName,
        t.doctorId,
        t.`name` AS patName,
        t.behospitalCode AS behospitalCode,
        t.behospitalDate AS behospitalDate,
        t.leaveHospitalDate AS leaveHospitalDate,
        qi.score_res AS score,
        t.scoreBn,
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        qd.msg AS msg,
        qc.NAME AS caseName,
        </if>
        t.behDeptId,
        t.behDeptName,
        t.hospitalId,
        t.checkStatus,
        t.mrStatus,
        t.chName,
        t.mrName,
        t.chTime,
        t.mrTime
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.scoreBn,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        ifnull( hm_mci.STATUS, 0 ) AS mrStatus,
        mci.check_name AS chName,
        e.score_res as scoreBn,
        hm_mci.check_name AS mrName,
        mci.gmt_create AS chTime,
        hm_mci.gmt_create AS mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.beh_dept_id = c.dept_id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND c.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_check_info hm_mci ON hm_mci.is_deleted = 'N'
        AND hm_mci.check_type = 1
        AND be.hospital_id = hm_mci.hospital_id
        AND be.behospital_code = hm_mci.behospital_code
        LEFT JOIN med_qcresult_cases e
        on  be.behospital_code = e.behospital_code
        and be.hospital_id = e.hospital_id
        AND e.is_deleted = 'N'
        and e.cases_id = 243
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        <if test="qcResultShortPageVO.radioCheck !=null and qcResultShortPageVO.radioCheck == 1">
        LEFT JOIN med_qcresult_detail qd ON qd.is_deleted = 'N'
        AND t.hospitalId = qd.hospital_id
        AND t.behospitalCode = qd.behospital_code
        LEFT JOIN qc_cases qc ON qc.is_deleted = 'N'
        AND qd.cases_id = qc.id
        </if>
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        )f1,
        (SELECT
        ROUND( AVG( qi.score_res ), 2 ) AS avgScore,
        t.behDeptId,
        t.behDeptName,
        t.doctorId,
        t.doctorName
        FROM
        (
        SELECT DISTINCT
        t1.hospital_id AS hospitalId,
        t1.behospital_code AS behospitalCode,
        t1.bed_code AS bedCode,
        t1.LEVEL AS LEVEL,
        t1.grade_type AS gradeType,
        t1.score_res AS scoreRes,
        t1.NAME AS NAME,
        t1.sex AS sex,
        t1.beh_dept_id AS behDeptId,
        t1.beh_dept_name AS behDeptName,
        t1.doctor_id AS doctorId,
        t1.doctor_name AS doctorName,
        t1.beh_doctor_id AS behDoctorId,
        t1.beh_doctor_name AS behDoctorName,
        t1.director_doctor_id AS directorDoctorId,
        t1.director_doctor_name AS directorDoctorName,
        t1.birthday AS birthday,
        t1.behospital_date AS behospitalDate,
        t1.leave_hospital_date AS leaveHospitalDate,
        t1.placefile_date AS placefileDate,
        t1.gmt_create AS gradeTime,
        t1.diagnose,
        t1.ward_name AS wardName,
        t2.age,
        t1.file_code AS fileCode,
        t1.checkStatus,
        t1.mrStatus,
        t1.chName,
        t1.mrName,
        t1.chTime,
        t1.mrTime
        FROM
        (
        SELECT
        be.*,
        ifnull( mci.STATUS, 0 ) AS checkStatus,
        ifnull( hm_mci.STATUS, 0 ) AS mrStatus,
        mci.check_name AS chName,
        hm_mci.check_name AS mrName,
        mci.gmt_create AS chTime,
        hm_mci.gmt_create AS mrTime
        FROM
        (
        SELECT DISTINCT
        a.hospital_id,
        a.behospital_code,
        a.bed_code,
        a.file_code,
        b.LEVEL,
        b.grade_type,
        b.score_res,
        a.NAME,
        a.sex,
        a.beh_dept_id,
        a.beh_dept_name,
        a.birthday,
        a.behospital_date,
        a.leave_hospital_date,
        a.doctor_id,
        a.doctor_name,
        a.beh_doctor_id,
        a.beh_doctor_name,
        a.director_doctor_id,
        a.director_doctor_name,
        a.diagnose,
        a.placefile_date,
        a.ward_name,
        b.gmt_create
        FROM
        med_behospital_info a,
        med_qcresult_info b,
        sys_user_dept c
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.hospital_id = b.hospital_id
        AND a.hospital_id = c.hospital_id
        AND a.behospital_code = b.behospital_code
        AND a.beh_dept_id = c.dept_id
        AND a.qc_type_id != 0
        <if test="qcResultShortPageVO.userId!=null">
            AND c.user_id = #{qcResultShortPageVO.userId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile != ''">
            and a.is_placefile = #{qcResultShortPageVO.isPlacefile}
        </if>
        <if test="qcResultShortPageVO.hospitalId != null and qcResultShortPageVO.hospitalId != ''">
            AND a.hospital_id = #{qcResultShortPageVO.hospitalId}
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 0">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.behospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null ">
                <![CDATA[ AND a.behospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.isPlacefile != null and qcResultShortPageVO.isPlacefile == 1">
            <if test="qcResultShortPageVO.startDate != null ">
                <![CDATA[ AND a.leave_hospital_date >= #{qcResultShortPageVO.startDate}]]>
            </if>
            <if test="qcResultShortPageVO.endDate != null">
                <![CDATA[ AND a.leave_hospital_date <= #{qcResultShortPageVO.endDate}]]>
            </if>
        </if>
        <if test="qcResultShortPageVO.diagnose != null and qcResultShortPageVO.diagnose != ''">
            AND a.diagnose LIKE CONCAT( '%', #{qcResultShortPageVO.diagnose}, '%' )
        </if>
        <if test="qcResultShortPageVO.deptName != null and qcResultShortPageVO.deptName != ''">
            AND a.beh_dept_name = #{qcResultShortPageVO.deptName}
        </if>
        <if test="qcResultShortPageVO.level != null and qcResultShortPageVO.level != ''">
            AND c.`level` = #{qcResultShortPageVO.level}
        </if>
        <if test="qcResultShortPageVO.behospitalCode != null and qcResultShortPageVO.behospitalCode != ''">
            AND a.behospital_code LIKE CONCAT( '%', #{qcResultShortPageVO.behospitalCode}, '%' )
        </if>
        <if test="qcResultShortPageVO.patName != null and qcResultShortPageVO.patName != ''">
            AND a.NAME LIKE CONCAT( '%', #{qcResultShortPageVO.patName}, '%' )
        </if>
        <if test="qcResultShortPageVO.doctorId != null and qcResultShortPageVO.doctorId != ''">
            AND (a.doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.beh_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' )
            OR a.director_doctor_id LIKE CONCAT( '%', #{qcResultShortPageVO.doctorId}, '%' ))
        </if>
        <if test="qcResultShortPageVO.doctorName != null and qcResultShortPageVO.doctorName != ''">
            AND (a.doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.beh_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' )
            OR a.director_doctor_name LIKE CONCAT( '%', #{qcResultShortPageVO.doctorName}, '%' ))
        </if>
        ) be
        LEFT JOIN med_check_info mci ON mci.is_deleted = 'N'
        AND mci.check_type in(0,2)
        AND be.hospital_id = mci.hospital_id
        AND be.behospital_code = mci.behospital_code
        LEFT JOIN med_check_info hm_mci ON hm_mci.is_deleted = 'N'
        AND hm_mci.check_type = 1
        AND be.hospital_id = hm_mci.hospital_id
        AND be.behospital_code = hm_mci.behospital_code
        ) t1
        LEFT JOIN med_home_page t2 ON t1.hospital_id = t2.hospital_id
        AND t1.behospital_code = t2.behospital_code
        AND t2.is_deleted = 'N'
        ) t
        LEFT JOIN med_qcresult_info qi ON qi.is_deleted = 'N'
        AND t.hospitalId = qi.hospital_id
        AND t.behospitalCode = qi.behospital_code
        where 1=1
        <if test="qcResultShortPageVO.checkStatus != null">
            AND t.checkStatus = #{qcResultShortPageVO.checkStatus}
        </if>
        <if test="qcResultShortPageVO.mrStatus != null">
            AND t.mrStatus = #{qcResultShortPageVO.mrStatus}
        </if>
        <if test="qcResultShortPageVO.chName != null and qcResultShortPageVO.chName!=''">
            AND t.chName like concat('%', #{qcResultShortPageVO.chName}, '%')
        </if>
        <if test="qcResultShortPageVO.mrName != null and qcResultShortPageVO.mrName!=''">
            AND t.mrName like concat('%', #{qcResultShortPageVO.mrName}, '%')
        </if>
        <if test="qcResultShortPageVO.chTimeStart != null ">
            <![CDATA[ AND t.chTime >= #{qcResultShortPageVO.chTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.chTimeEnd != null ">
            <![CDATA[ AND t.chTime <= #{qcResultShortPageVO.chTimeEnd}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeStart != null ">
            <![CDATA[ AND t.mrTime >= #{qcResultShortPageVO.mrTimeStart}]]>
        </if>
        <if test="qcResultShortPageVO.mrTimeEnd != null ">
            <![CDATA[ AND t.mrTime <= #{qcResultShortPageVO.mrTimeEnd}]]>
        </if>
        GROUP BY
        t.doctorId,
        t.doctorName
        )f2
        WHERE
        f1.doctorId = f2.doctorId
        AND f1.doctorName = f2.doctorName
    </select>

    <!-- 入院，手术，出院病案情况-->
    <select id="medicalRecordIndicator" parameterType="com.diagbot.vo.FilterVO" resultType="java.util.Map">
        SELECT
        count(
        DISTINCT
        CASE
        WHEN q.type=5 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'operationNote',
        count(
        DISTINCT
        CASE
        WHEN q.type = 4 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'residentAdmitNote',
        count(
        DISTINCT
        CASE
        WHEN q.type = 6 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'dischargeRecord',
        count(
        DISTINCT
        CASE
        WHEN q.type = 7 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'medicalRecord'
        FROM
        (
        SELECT
        a.behospital_code,
        a.cases_entry_id,
        a.hospital_id
        FROM
        (
        SELECT
        a.behospital_code,
        c.cases_entry_id,
        a.hospital_id
        FROM
        (
        SELECT
        a.behospital_code,
        a.hospital_id
        FROM
        med_behospital_info a,
        med_qcresult_info c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.is_placefile = #{filterVO.isPlacefile}
        <if test="filterVO.startDate != null and  filterVO.endDate != null">
            <![CDATA[ and a.leave_hospital_date >= #{filterVO.startDate}]]>
            <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
        </if>
        <![CDATA[ and  a.qc_type_id <>'0' ]]>
        AND a.behospital_code = c.behospital_code
        AND a.hospital_id = #{filterVO.hospitalId}
        AND a.hospital_id = c.hospital_id
        ) a
        LEFT JOIN med_qcresult_detail c ON c.is_deleted = 'N'
        AND a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        ) a
        JOIN qc_cases_entry d ON d.id = a.cases_entry_id
        AND d.is_deleted = 'N'
        ) a
        LEFT JOIN qc_cases_relevance_entry q ON a.cases_entry_id = q.relevance_id
        AND a.hospital_id = q.hospital_id

    </select>

    <!--  时间段出院，住院， 手术费，抗菌药物，手术和病理费等含有人数 -->
    <select id="selectOperationNum" parameterType="com.diagbot.vo.FilterVO" resultType="java.util.Map">
        select
        d.behospital_code behospitalCode,
        b.operation_fee operationFee,
        b.pathology_fee pathologyFee,
        b.antibiosis_fee antibiosisFee
        FROM
        (
        SELECT
        a.behospital_code,
        a.hospital_id,
        a.behospital_date,
        a.leave_hospital_date
        FROM
        med_behospital_info a,
        med_qcresult_info c
        WHERE
            a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.is_placefile = #{filterVO.isPlacefile}
        <if test="filterVO.startDate != null and  filterVO.endDate != null">
            <![CDATA[ and a.leave_hospital_date >= #{filterVO.startDate}]]>
            <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
        </if>
        <![CDATA[ and  a.qc_type_id <>'0' ]]>
        AND a.hospital_id = c.hospital_id
        AND a.hospital_id = #{filterVO.hospitalId}
        and a.behospital_code = c.behospital_code
        ) d
        JOIN med_home_page b ON b.behospital_code = d.behospital_code
        AND d.hospital_id = b.hospital_id
        AND b.is_deleted = 'N'
    </select>
<!--    关于触发规则不符合人数-->
    <select id="triggeringRules" parameterType="com.diagbot.vo.FilterVO" resultType="java.util.Map">
        SELECT
        count(
        DISTINCT
        CASE
        WHEN a.type=5 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'operationNote',
        count(
        DISTINCT
        CASE
        WHEN a.type = 4 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'residentAdmitNote',
        count(
        DISTINCT
        CASE
        WHEN a.type = 6 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'dischargeRecord',
        count(
        DISTINCT
        CASE
        WHEN a.type = 7 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'medicalRecord',
        count(
        DISTINCT
        CASE
        WHEN a.type=8 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'CT',
        count(
        DISTINCT
        CASE
        WHEN a.type = 9 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'MR',
        count(
        DISTINCT
        CASE
        WHEN a.type = 10 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'operationPathologyFee',
        count(
        DISTINCT
        CASE
        WHEN a.type = 11 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'bacterialCulture',
        count(
        DISTINCT
        CASE
        WHEN a.type = 12 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'antibiosis',
        count(
        DISTINCT
        CASE
        WHEN a.type = 13 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'chemotherapyMalignantTumors',
        count(
        DISTINCT
        CASE
        WHEN a.type = 15 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'operationRecordNum',
        count(
        DISTINCT
        CASE
        WHEN a.type = 17 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'bloodNum',
        count(
        DISTINCT
        CASE
        WHEN a.type = 18 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'WardRoundNum',
        count(
        DISTINCT
        CASE
        WHEN a.type = 19 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'rescueNum',
        count(
        DISTINCT
        CASE
        WHEN a.type = 22 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'unreasonedCopyNum',
        count(
        DISTINCT
        CASE
        WHEN a.type = 14 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'tumorRadiationNum',
        count(
        DISTINCT
        CASE
        WHEN a.type = 16 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'implantsNum',
        count(
        DISTINCT
        CASE
        WHEN a.type = 23 THEN
        a.behospital_code
        ELSE
        NULL
        END
        ) AS 'InformedNum'
        FROM
        (
        SELECT
        a.behospital_code,
        a.hospital_id,
        q.type
        FROM
        (
        SELECT
        a.behospital_code,
        a.cases_entry_id,
        a.hospital_id
        FROM
        (
        SELECT
        a.behospital_code,
        c.cases_entry_id,
        a.hospital_id
        FROM
        (
        SELECT
        a.behospital_code,
        a.hospital_id
        FROM
        med_behospital_info a,
        med_qcresult_info c
        WHERE
        a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        AND a.is_placefile = #{filterVO.isPlacefile}
        <if test="filterVO.startDate != null and  filterVO.endDate != null">
            <![CDATA[ and a.leave_hospital_date >= #{filterVO.startDate}]]>
            <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
        </if>
        AND a.behospital_code = c.behospital_code
        AND a.hospital_id = #{filterVO.hospitalId}
        AND a.hospital_id = c.hospital_id
        ) a
        LEFT JOIN med_qcresult_detail c ON c.is_deleted = 'N'
        AND a.behospital_code = c.behospital_code
        AND a.hospital_id = c.hospital_id
        ) a
        JOIN qc_cases_entry d ON d.id = a.cases_entry_id
        AND d.is_deleted = 'N'
        ) a
        JOIN qc_cases_relevance_entry q ON a.cases_entry_id = q.relevance_id
        AND a.hospital_id = q.hospital_id
        ) a
        JOIN med_index_relevance r ON r.behospital_code = a.behospital_code
        AND r.relevance_type = a.type
        AND r.is_deleted = 'N'
        AND a.hospital_id = r.hospital_id
    </select>

<!--    跟病案首页关联的出院病历-->
    <select id="getMedicalRecords" parameterType="com.diagbot.vo.FilterVO" resultType="java.util.Map">
     SELECT
	d.behospital_code,
	d.behospital_date,
	d.leave_hospital_date,
	b.behospital_code AS b_code,
	b.operation_fee,
	b.antibiosis_fee,
	b.pathology_fee
    FROM
	    (
		SELECT
			a.behospital_code,
			a.hospital_id,
			a.behospital_date,
			a.leave_hospital_date
		FROM
			med_behospital_info a,
			med_qcresult_info c
		WHERE
			a.behospital_code = c.behospital_code
		AND a.hospital_id = #{filterVO.hospitalId}
		AND a.is_placefile = #{filterVO.isPlacefile}
		AND a.hospital_id = c.hospital_id
		AND a.is_deleted = 'N'
		AND c.is_deleted = 'N'
        <![CDATA[ and  a.qc_type_id <>'0' ]]>
        <if test="filterVO.startDate != null and  filterVO.endDate != null ">
            <![CDATA[ AND a.leave_hospital_date >= #{filterVO.startDate}]]>
            <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
        </if>
	) d
    LEFT JOIN med_home_page b ON b.behospital_code = d.behospital_code
    AND d.hospital_id = b.hospital_id
    AND b.is_deleted = 'N'
    where ISNULL(b.behospital_code)
    </select>

<!--    首页恶性肿瘤-->
    <select id="malignancy" parameterType="com.diagbot.vo.FilterVO" resultType="java.util.Map">
        select
        a.behospital_code,
        a.hospital_id,
        d.diagnose_name,
        d.diagnose_type,
        d.icd_code
        from(
        SELECT
        d.behospital_code,
        d.hospital_id,
        b.home_page_id
        FROM
        (
        SELECT
        a.behospital_code,
        a.hospital_id,
        a.behospital_date,
        a.leave_hospital_date
        FROM
        med_behospital_info a,
        med_qcresult_info c
        WHERE
        a.behospital_code = c.behospital_code
        AND a.hospital_id =  #{filterVO.hospitalId}
        AND a.is_placefile =  #{filterVO.isPlacefile}
        AND a.hospital_id = c.hospital_id
        AND a.is_deleted = 'N'
        AND c.is_deleted = 'N'
        <![CDATA[ and  a.qc_type_id <>'0' ]]>
        <if test="filterVO.startDate != null and  filterVO.endDate != null ">
            <![CDATA[ AND a.leave_hospital_date >= #{filterVO.startDate}]]>
            <![CDATA[ AND a.leave_hospital_date <= #{filterVO.endDate}]]>
        </if>
        ) d
        JOIN med_home_page b ON b.behospital_code = d.behospital_code
        AND d.hospital_id = b.hospital_id
        AND b.is_deleted = 'N'
        )a join
        med_home_diagnose_info d on a.hospital_id=d.hospital_id
        where a.home_page_id =d.home_page_id
        and d.is_deleted ='N'
        and d.diagnose_name like '%恶性肿瘤%'
        and d.icd_code like 'C%'
    </select>

    <!-- 获取患者年龄信息(通过出生日期和入院日期重新计算) -->
    <select id="getBehospitalInfoAge" resultType="com.diagbot.dto.BehospitalInfoAgeDTO">
        SELECT
        mbi.behospital_code behospitalCode,
        mhp.age,
        TIMESTAMPDIFF(year,ifnull(mhp.birthday,mbi.birthday),mbi.behospital_date) as ageYear,
        TIMESTAMPDIFF(day,ifnull(mhp.birthday,mbi.birthday),mbi.behospital_date) as ageDay
        FROM
        med_behospital_info mbi
        LEFT JOIN med_home_page mhp
        ON mbi.behospital_code=mhp.behospital_code
        AND mbi.hospital_id = mhp.hospital_id AND mhp.is_deleted = 'N'
        WHERE mbi.hospital_id=#{hospitalId} AND mbi.is_deleted = 'N'
        <if test="behospitalCodes !=null and behospitalCodes.size > 0">
            and mbi.behospital_code in
            <foreach collection="behospitalCodes" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>
