浏览代码

湘雅医师病案首页sql逻辑修改

chengyao 3 年之前
父节点
当前提交
1ae772b0ff
共有 2 个文件被更改,包括 99 次插入61 次删除
  1. 1 1
      src/main/java/com/diagbot/dto/HomePageNumXYDTO.java
  2. 98 60
      src/main/resources/mapper/BehospitalInfoMapper.xml

+ 1 - 1
src/main/java/com/diagbot/dto/HomePageNumXYDTO.java

@@ -27,7 +27,7 @@ public class HomePageNumXYDTO {
      * 主管医生职称
      */
     @Excel(name = "医师类别", width = 20, orderNum = "2")
-    private String professor;
+    private String doctorTitle;
 
     /**
      * 主管医生id

+ 98 - 60
src/main/resources/mapper/BehospitalInfoMapper.xml

@@ -3378,45 +3378,53 @@
     <!-- 医师病案首页合格率占比 湘雅定制-->
     <select id="homePageLevelStatisticsXY" resultType="com.diagbot.dto.HomePageNumXYDTO">
         SELECT
-        t4.*,
-        bas.name as doctorName,
-        ifnull(bas.professor,'')as professor
-        FROM (
-        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.doctorId,
-        sum(t1.mrNum),
-        sum(t1.totleValue),
-        sum(t1.averageValue),
-        sum(t1.firstLevelNum),
-        sum(t1.secondLevelNum),
+        t1.doctorName,
+        t1.doctorTitle,
+        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,
-        sum(t2.entryNum),
-        sum(t2.emptyNum),
-        sum(t2.errorNum),
-        sum(t2.mrNum) * t3.entryNum AS entryTotleNum,
-        ROUND( ( sum(t2.mrNum) * t3.entryNum  - sum(t2.emptyNum) ) / ( sum(t2.mrNum) * t3.entryNum ), 4 ) AS emptyPercent,
-        ROUND( ( sum(t2.mrNum) * t3.entryNum  - sum(t2.errorNum) ) / ( sum(t2.mrNum) * t3.entryNum ), 4 ) AS errorPercent,
-        CONCAT( ROUND( ( sum(t2.mrNum) * t3.entryNum - sum(t2.emptyNum) ) / ( sum(t2.mrNum) * t3.entryNum )* 100, 2 ), '%' ) AS emptyPercentStr,
-        CONCAT( ROUND( ( sum(t2.mrNum) * t3.entryNum - sum(t2.errorNum) ) / ( sum(t2.mrNum) * t3.entryNum )* 100, 2 ), '%' ) AS errorPercentStr
-        FROM
+        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 a.doctor_id != '' and a.doctor_id is not null then a.doctor_id
-        when (a.doctor_id = '' or a.doctor_id is null) and
-        a.director_doctor_id != '' and a.director_doctor_id is not null
-        then a.director_doctor_id
-        when (a.doctor_id = '' or a.doctor_id is null) and
-        (a.director_doctor_id = '' or a.director_doctor_id is null) and
-        a.beh_doctor_id != '' and a.beh_doctor_id is not null
-        then a.beh_doctor_id end as doctorId,
+        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 doctorTitle,
         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,
@@ -3424,11 +3432,15 @@
         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 != ''">
@@ -3462,39 +3474,70 @@
         </if>
         GROUP BY
         a.beh_dept_id,
-        a.doctor_id,
-        a.director_doctor_id,
-        a.beh_doctor_id
-        ) t1,
+        a.beh_dept_name,
+        b.attending_doctor,
+        b.director_doctor,
+        b.behospital_doctor
+        ) t1
+        group by t1.deptId,t1.deptName,t1.doctorName
+        )tt1,
         (
+        select
+        t2.deptId,
+        t2.deptName,
+        t2.doctorName,
+        t2.doctorTitle,
+        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 a.doctor_id != '' and a.doctor_id is not null then a.doctor_id
-        when (a.doctor_id = '' or a.doctor_id is null) and
-        a.director_doctor_id != '' and a.director_doctor_id is not null
-        then a.director_doctor_id
-        when (a.doctor_id = '' or a.doctor_id is null) and
-        (a.director_doctor_id = '' or a.director_doctor_id is null) and
-        a.beh_doctor_id != '' and a.beh_doctor_id is not null
-        then a.beh_doctor_id end as doctorId,
+        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 doctorTitle,
         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
@@ -3532,10 +3575,11 @@
         </if>
         GROUP BY
         a.beh_dept_id,
-        a.doctor_id,
-        a.director_doctor_id,
-        a.beh_doctor_id
-        ) t2,(
+        a.beh_dept_name,
+        b.attending_doctor,
+        b.director_doctor,
+        b.behospital_doctor
+        )m1,(
         SELECT
         count(*) AS entryNum
         FROM
@@ -3543,22 +3587,16 @@
         WHERE
         is_deleted = 'N'
         AND cases_id = 243
-        ) t3
+        )m2) t2
+        group by t2.deptId,t2.deptName,t2.doctorName
+        ) tt2
         WHERE
-        t1.deptId = t2.deptId
-        AND t1.deptName = t2.deptName
-        AND t1.doctorId = t2.doctorId
-        group by t1.deptId,t1.doctorId
-        )t4
-        left join bas_doctor_info bas
-        on t4.doctorId = bas.doctor_id
-        and bas.is_deleted = 'N'
-        where
-        t4.doctorId != ''
-        and t4.doctorId is not null
-        <if test="professor != null and professor != ''">
-            and bas.professor = #{professor}
-        </if>
+        tt1.deptId = tt2.deptId
+        AND tt1.deptName = tt2.deptName
+        AND tt1.doctorName= tt2.doctorName
+        AND tt1.doctorTitle = tt2.doctorTitle
+        AND tt1.doctorTitle != ''
+        and tt1.doctorTitle is not null
     </select>