@ -14,64 +14,81 @@
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
<if test= "dto.startTime != null" >
AND create_time > = #{dto.startTime}
</if>
<if test= "dto.endTime != null" >
AND create_time < = #{dto.endTime}
</if>
</where>
</select>
<select id= "queryAgeStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$PatientVo$AgeVo" >
SELECT
IFNULL(SUM(CASE WHEN age BETWEEN 0 AND 40 THEN 1 ELSE 0 END), 0) as num1,
IFNULL( SUM(CASE WHEN age BETWEEN 41 AND 50 THEN 1 ELSE 0 END), 0) as num2,
IFNULL( SUM(CASE WHEN age BETWEEN 51 AND 60 THEN 1 ELSE 0 END), 0) as num3,
IFNULL( SUM(CASE WHEN age BETWEEN 61 AND 70 THEN 1 ELSE 0 END), 0) as num4,
IFNULL( SUM(CASE WHEN age BETWEEN 71 AND 80 THEN 1 ELSE 0 END), 0) as num5,
IFNULL(SUM(CASE WHEN age > 80 THEN 1 ELSE 0 END), 0) as num6
SUM(CASE WHEN age BETWEEN 0 AND 40 THEN 1 ELSE 0 END) AS num1,
SUM(CASE WHEN age BETWEEN 41 AND 50 THEN 1 ELSE 0 END) AS num2,
SUM(CASE WHEN age BETWEEN 51 AND 60 THEN 1 ELSE 0 END) AS num3,
SUM(CASE WHEN age BETWEEN 61 AND 70 THEN 1 ELSE 0 END) AS num4,
SUM(CASE WHEN age BETWEEN 71 AND 80 THEN 1 ELSE 0 END) AS num5,
SUM(CASE WHEN age > 80 THEN 1 ELSE 0 END) AS num6
FROM
pms_treatment
<where >
del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</where>
(
SELECT
TIMESTAMPDIFF(YEAR, birth_date, now()) AS age
FROM
pms_patient
WHERE
del_flag = 0 and
birth_date IS NOT NULL
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
<if test= "dto.startTime != null" >
AND create_time > = #{dto.startTime}
</if>
<if test= "dto.endTime != null" >
AND create_time < = #{dto.endTime}
</if>
) AS age_data;
</select>
<select id= "queryJwbzStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$PatientVo$JwbzVo" >
SELECT
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"高血压"') THEN 1 ELSE 0 END) AS gxy, -- 高血压
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"脑血管病"') THEN 1 ELSE 0 END) AS nxgb, -- 脑血管病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"恶性肿瘤"') THEN 1 ELSE 0 END) AS exzl, -- 恶性肿瘤
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"冠心病"') THEN 1 ELSE 0 END) AS gxb, -- 冠心病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"精神疾病"') THEN 1 ELSE 0 END) AS jsjb, -- 精神疾病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"胃和十二指肠溃疡"') THEN 1 ELSE 0 END) AS whsezcky, -- 胃和十二指肠溃疡
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"肥胖症"') THEN 1 ELSE 0 END) AS fpz, -- 肥胖症
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"骨质疏松症"' ) THEN 1 ELSE 0 END) AS gzssz, -- 骨质疏松症
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"遗传性、先天性疾病"') THEN 1 ELSE 0 END) AS ycxXtxjb, -- 遗传性、先天性疾病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"糖尿病"' ) THEN 1 ELSE 0 END) AS tnb, -- 糖尿病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"慢性肺系疾病"' ) THEN 1 ELSE 0 END) AS mxfxjb, -- 慢性肺系疾病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"高脂血症"' ) THEN 1 ELSE 0 END) AS gzxz, -- 高脂血症
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"肝脏疾病"' ) THEN 1 ELSE 0 END) AS gzjb, -- 肝脏疾病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"过敏性疾病"' ) THEN 1 ELSE 0 END) AS gmxjb, -- 过敏性疾病
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"关节炎"' ) THEN 1 ELSE 0 END) AS gjy, -- 关节炎
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"痛风"' ) THEN 1 ELSE 0 END) AS tf, -- 痛风
SUM(CASE WHEN JSON_CONTAINS(current_illness_history, '"肾炎、肾病"' ) THEN 1 ELSE 0 END) AS sySb, -- 肾炎、肾病
SUM(CASE WHEN FIND_IN_SET ('高血压' ,current_illness_history ) THEN 1 ELSE 0 END) AS gxy, -- 高血压
SUM(CASE WHEN FIND_IN_SET ('脑血管病' ,current_illness_history ) THEN 1 ELSE 0 END) AS nxgb, -- 脑血管病
SUM(CASE WHEN FIND_IN_SET ('恶性肿瘤' ,current_illness_history ) THEN 1 ELSE 0 END) AS exzl, -- 恶性肿瘤
SUM(CASE WHEN FIND_IN_SET ('冠心病' ,current_illness_history ) THEN 1 ELSE 0 END) AS gxb, -- 冠心病
SUM(CASE WHEN FIND_IN_SET ('精神疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS jsjb, -- 精神疾病
SUM(CASE WHEN FIND_IN_SET ('胃和十二指肠溃疡' ,current_illness_history ) THEN 1 ELSE 0 END) AS whsezcky, --
SUM(CASE WHEN FIND_IN_SET ('肥胖症' ,current_illness_history ) THEN 1 ELSE 0 END) AS fpz, -- 肥胖症
SUM(CASE WHEN FIND_IN_SET ('骨质疏松症' ,current_illness_history ) THEN 1 ELSE 0 END) AS gzssz, -- 骨质疏松症
SUM(CASE WHEN FIND_IN_SET ('遗传性、先天性疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS ycxXtxjb, --
SUM(CASE WHEN FIND_IN_SET ('糖尿病' ,current_illness_history ) THEN 1 ELSE 0 END) AS tnb, -- 糖尿病
SUM(CASE WHEN FIND_IN_SET ('慢性肺系疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS mxfxjb, -- 慢性肺系疾病
SUM(CASE WHEN FIND_IN_SET ('高脂血症' ,current_illness_history ) THEN 1 ELSE 0 END) AS gzxz, -- 高脂血症
SUM(CASE WHEN FIND_IN_SET ('肝脏疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS gzjb, -- 肝脏疾病
SUM(CASE WHEN FIND_IN_SET ('过敏性疾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS gmxjb, -- 过敏性疾病
SUM(CASE WHEN FIND_IN_SET ('关节炎' ,current_illness_history ) THEN 1 ELSE 0 END) AS gjy, -- 关节炎
SUM(CASE WHEN FIND_IN_SET ('痛风' ,current_illness_history ) THEN 1 ELSE 0 END) AS tf, -- 痛风
SUM(CASE WHEN FIND_IN_SET ('肾炎、肾病' ,current_illness_history ) THEN 1 ELSE 0 END) AS sySb, -- 肾炎、肾病
SUM(CASE WHEN
JSON_CONTAINS(current_illness_history, '"高血压"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"脑血管病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"恶性肿瘤"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"冠心病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"精神疾病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"胃和十二指肠溃疡"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"肥胖症"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"骨质疏松症"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"遗传性、先天性疾病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"糖尿病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"慢性肺系疾病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"高脂血症"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"肝脏疾病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"过敏性疾病"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"关节炎"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"痛风"' ) = 0 AND
JSON_CONTAINS(current_illness_history, '"肾炎、肾病"' ) = 0
FIND_IN_SET('高血压' , current_illness_history ) = 0 AND
FIND_IN_SET('脑血管病' , current_illness_history ) = 0 AND
FIND_IN_SET('恶性肿瘤' , current_illness_history ) = 0 AND
FIND_IN_SET('冠心病' , current_illness_history ) = 0 AND
FIND_IN_SET('精神疾病' , current_illness_history ) = 0 AND
FIND_IN_SET('胃和十二指肠溃疡' , current_illness_history ) = 0 AND
FIND_IN_SET('肥胖症' , current_illness_history ) = 0 AND
FIND_IN_SET('骨质疏松症' , current_illness_history ) = 0 AND
FIND_IN_SET('遗传性、先天性疾病' , current_illness_history ) = 0 AND
FIND_IN_SET('糖尿病' , current_illness_history ) = 0 AND
FIND_IN_SET('慢性肺系疾病' , current_illness_history ) = 0 AND
FIND_IN_SET('高脂血症' , current_illness_history ) = 0 AND
FIND_IN_SET('肝脏疾病' , current_illness_history ) = 0 AND
FIND_IN_SET('过敏性疾病' , current_illness_history ) = 0 AND
FIND_IN_SET('关节炎' , current_illness_history ) = 0 AND
FIND_IN_SET('痛风' , current_illness_history ) = 0 AND
FIND_IN_SET('肾炎、肾病' , current_illness_history ) = 0
THEN 1 ELSE 0 END) AS other -- 其他
FROM
pms_patient
@ -91,8 +108,30 @@
</resultMap>
<select id= "queryZyzdStatistics" resultType= "java.lang.String" >
SELECT answer FROM pms_treatment_record WHERE question_code = 'JBXX_ZYZD' and del_flag = 0
SELECT r.answer FROM pms_treatment_record r left join pms_treatment t on r.treatment_id = t.id
WHERE
r.question_code = 'JBXX_ZYZD'
and r.del_flag = 0
and t.del_flag = 0
<if test= "tenantId != null" >
AND t.tenant_id = #{tenantId}
</if>
</select>
<select id= "queryTxStatistics" resultType= "java.lang.String" >
SELECT answer
FROM pms_treatment_record r
left join
pms_treatment t
on r.treatment_id = t.id
WHERE r.question_code = 'PG_RTCF_TXLX'
and t.del_flag = 0
and r.del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "queryTotalPatient" resultType= "java.lang.Integer" >
SELECT
COUNT(1)
@ -150,6 +189,9 @@
WHERE
question_code = 'PG_TZBS_ZYTZ'
AND r.del_flag = 0 and t.del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "queryZllxtjStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$ZlTypeVo$Zllxtj" >
@ -163,6 +205,9 @@
question_code = 'ZLFA_ZLLX'
AND t.del_flag = 0
AND t.del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "queryFpzStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$ZlTypeVo$BzfffbVo$Fpz" >
@ -173,10 +218,16 @@
COUNT( CASE WHEN question_code = 'ZLFA_ZJ' THEN 1 END ) AS zjlf,
COUNT( CASE WHEN question_code = 'ZLFA_ZL' THEN 1 END ) AS ywzl
FROM
pms_treatment_record
pms_treatment t
left join
pms_treatment_record r on t.id = r.treatment_id
WHERE
question_code IN ( 'ZLFA_XWXLGY', 'ZLFA_YDGY', 'ZLFA_LCYYZL', 'ZLFA_ZJ', 'ZLFA_ZL' )
AND del_flag = 0
AND r.del_flag = 0
and t.del_flag = 0
<if test= "tenantId != null" >
AND t.tenant_id = #{tenantId}
</if>
</select>
@ -194,6 +245,9 @@
question_code = 'ZLFA_ZLXG'
AND t.del_flag = 0
and r.del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "queryZlfyStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$ZlTypeVo$ZlfyVo" >
@ -210,7 +264,10 @@
question_code = 'ZLFA_ZTFY'
AND t.del_flag = 0
and r.del_flag = 0
AND answer REGEXP '^[0-9]+$';
AND answer REGEXP '^[0-9]+$'
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "querySftjStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$SftjVo" >
@ -233,8 +290,8 @@
queue_id as queueId,
q.name as queueName,
COUNT(*) AS num, -- 总记录数
SUM(CASE WHEN t.status = 0 AND followup_time IS NULL AND end_time > NOW() THEN 1 ELSE 0 END) AS dsf, -- 待随访
SUM(CASE WHEN t.status = 0 AND followup_time IS NULL AND end _time BETWEEN DATE_SUB(NOW(), INTERVAL 2 DAY) AND DATE_ADD(NOW(), INTERVAL 2 DAY) THEN 1 ELSE 0 END) AS ljsf, -- 临近随访
SUM(CASE WHEN t.status = 0 THEN 1 ELSE 0 END) AS dsf, -- 待随访
SUM(CASE WHEN t.status = 0 AND followup_time IS NULL AND start _time BETWEEN DATE_SUB(NOW(), INTERVAL 2 DAY) AND DATE_ADD(NOW(), INTERVAL 2 DAY) THEN 1 ELSE 0 END) AS ljsf, -- 临近随访
SUM(CASE WHEN (t.status = 0 AND followup_time IS NULL AND end_time < NOW()) OR (t.status = 1 AND followup_time > end_time) THEN 1 ELSE 0 END) AS cqsf, -- 超期随访
SUM(CASE WHEN t.status = 1 AND followup_time < = end_time THEN 1 ELSE 0 END) AS zc -- 正常随访
FROM
@ -242,7 +299,11 @@
left join fms_followup_queue q on t.queue_id = q.id
WHERE
t.del_flag = 0
<if test= "tenantId != null" >
AND t.tenant_id = #{tenantId}
</if>
group by queue_id
</select>
<select id= "queryTtfbStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$TreamentVo$TtfbVo" >
@ -259,6 +320,9 @@
WHERE
question_code = 'PG_TT_TAPS_DF'
AND t.del_flag = 0 and r.del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "querySmfbStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$TreamentVo$SmfbVo" >
@ -270,9 +334,12 @@
FROM pms_treatment t
left join
pms_treatment_record r on t.id = r.treatment_id
WHERE question_code = 'PG_SM_PHQ_ 9_DF'
WHERE question_code = 'PG_SM_PHQ- 9_DF'
AND t.del_flag = 0
and r.del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "queryJlfbStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$TreamentVo$JlfbVo" >
@ -283,9 +350,12 @@
FROM pms_treatment t
left join
pms_treatment_record r on t.id = r.treatment_id
WHERE question_code = 'PG_JL_HAMD_ 24_DF'
WHERE question_code = 'PG_JL_HAMD- 24_DF'
AND t.del_flag = 0
and r.del_flag = 0
<if test= "tenantId != null" >
AND tenant_id = #{tenantId}
</if>
</select>
<select id= "querySmzStatistics" resultType= "com.acupuncture.system.domain.vo.StatisticsVo$ZlTypeVo$BzfffbVo$Smz" >
@ -294,10 +364,14 @@
COUNT( CASE WHEN question_code = 'ZLFA_XLTS' THEN 1 END ) AS ydgy,
COUNT( CASE WHEN question_code = 'ZLFA_ZJ' THEN 1 END ) AS lcyyzl,
COUNT( CASE WHEN question_code = 'ZLFA_YW' THEN 1 END ) AS zjlf
FROM
pms_treatment_record
FROM pms_treatment t
left join
pms_treatment_record r on t.id = r.treatment_id
WHERE
question_code IN ( 'ZLFA_XWXLGY', 'ZLFA_YDGY', 'ZLFA_LCYYZL', 'ZLFA_ZJ', 'ZLFA_ZL' )
AND del_flag = 0
AND r.del_flag = 0
<if test= "tenantId != null" >
AND t.tenant_id = #{tenantId}
</if>
</select>
</mapper>