<?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.sict.data.mapper.DataPlatMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.sict.data.model.DataPlat"> <id column="id" property="id"/> <result column="name" property="name"/> </resultMap> <!-- 通用查询结果列 --> <sql id="Base_Column_List"> id, `name` </sql> <!-- 获取各医联体下筛查人数排行榜 --> <select id="getHospScreeningRank" resultType="com.sict.data.dto.HospScreeningDTO"> SELECT hospNum, hospName, count( * ) hospScreeningTotal, count( screeningStatus = 1 OR NULL ) hospApplyScreeningTotal FROM ( SELECT p.id patientId, p.`name` patientName, rel5.number hospNum, rel5.`name` hospName, CASE rel1.igg WHEN 1 THEN '阳性' WHEN 0 THEN '阴性' ELSE '' END iggDetection, CASE rel2.grade WHEN 1 THEN '低风险' WHEN 2 THEN '中风险' WHEN 3 THEN '高风险' ELSE '' END riskLevel, CASE rel3.is_inspect WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE '否' END isGastroscopy, rel3.inspect_way gastroscopyWay, CASE rel3.capsule WHEN 1 THEN '异常' WHEN 2 THEN '未见异常' ELSE '' END gastroscopyResult, rel3.precise_way gastroscopyDetailWay, CASE rel3.diagnose_result WHEN 1 THEN '异常' WHEN 2 THEN '未见明显异常' ELSE '' END gastroscopyDetailResult, rel3.diagnose_info gastroscopyDetailInfo, CASE rel4.continue_flup WHEN 1 THEN '继续随访' WHEN 0 THEN '停止随访' ELSE '' END isContinueFlup, rel4.content_type planFlupContent, rel1.`status` screeningStatus FROM tb_patient p RIGHT JOIN ( SELECT patient_id, igg, step, `status` FROM tb_lab_inspect WHERE `status` NOT IN ( 0, 5 ) ) rel1 ON rel1.patient_id = p.id RIGHT JOIN ( SELECT patient_id, step, score, grade, `status` FROM tb_risk_assess WHERE `status` NOT IN ( 0, 5 ) ) rel2 ON rel2.patient_id = p.id AND rel2.step = rel1.step AND rel2.`status` = rel1.`status` LEFT JOIN ( SELECT patient_id, step, is_inspect, inspect_way, capsule, precise_way, diagnose_result, diagnose_info, `status` FROM tb_gastro_inspect WHERE `status` NOT IN ( 0, 5 ) ) rel3 ON rel3.patient_id = p.id AND rel3.step = rel2.step AND rel3.`status` = rel2.`status` LEFT JOIN ( SELECT patient_id, step, continue_flup, content_type, `status` FROM tb_flup_plan WHERE `status` NOT IN ( 0, 5 ) ) rel4 ON rel4.patient_id = p.id AND rel4.step = rel3.step AND rel4.`status` = rel3.`status` INNER JOIN ( SELECT number, `name` FROM tb_hosp ) rel5 ON rel5.number = p.hosp_number ) rel GROUP BY hospName ORDER BY hospScreeningTotal DESC </select> <!-- 获取各省份血检人次统计结果 --> <select id="getProvinceSerumStatistics" resultType="com.sict.data.dto.ProvinceSerumDTO"> SELECT provinceName, sum( serumTestPlan + serumTestActual ) serumTestTotal, sum( serumTestPlan ) serumTestPlan, sum( serumTestActual ) serumTestActual, sum( iggPositive ) iggPositive, sum( earlyCancer ) earlyCancer FROM ( ( SELECT provinceName, count( * ) serumTestPlan, count( NULL ) serumTestActual, count( NULL ) iggPositive, count( NULL ) earlyCancer FROM ( SELECT p.id patientId, rel3.area provinceName, rel1.step planFlupStep, CASE rel1.continue_flup WHEN 1 THEN '继续随访' WHEN 0 THEN '停止随访' ELSE '' END isContinueFlup, rel1.content_type planFlupContent, rel1.`status` planFlupAuditStatus FROM tb_patient p RIGHT JOIN ( SELECT patient_id, step, continue_flup, content_type, `status` FROM tb_flup_plan WHERE continue_flup = 1 AND content_type LIKE '%b%' ) rel1 ON rel1.patient_id = p.id INNER JOIN ( SELECT `name`, number FROM tb_hosp ) rel2 ON rel2.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel3 ON rel3.`name` = rel2.`name` ) rel GROUP BY provinceName ) UNION ( SELECT provinceName, count( NULL ) serumTestPlan, count( * ) serumTestActual, count( iggDetection = '阳性' OR NULL ) iggPositive, count( NULL ) earlyCancer FROM ( SELECT p.id patientId, rel3.area provinceName, rel1.step labInspectStep, rel1.g17 G17, rel1.pg1 PG1, rel1.pg2 PG2, CASE rel1.igg WHEN 1 THEN '阳性' WHEN 0 THEN '阴性' ELSE '' END iggDetection, rel1.`status` labInspectStatus FROM tb_patient AS p RIGHT JOIN ( SELECT patient_id, step, g17, pg1, pg2, igg, `status` FROM tb_lab_inspect ) rel1 ON rel1.patient_id = p.id INNER JOIN ( SELECT `name`, number FROM tb_hosp ) rel2 ON rel2.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel3 ON rel3.`name` = rel2.`name` WHERE rel1.`status` NOT IN ( 0, 5 ) ) rel GROUP BY provinceName ) UNION ( SELECT provinceName, count( NULL ) serumTestPlan, count( NULL ) serumTestActual, count( NULL ) iggPositive, count( gastroscopyDetailInfo LIKE '%"b":1%' OR NULL ) + count( gastroscopyDetailInfo LIKE '%"g":1%' OR NULL ) earlyCancer FROM ( SELECT p.id patientId, rel3.area provinceName, rel1.step gastroscopyStep, rel1.is_inspect isGastroscopy, rel1.inspect_way gastroscopyWay, rel1.capsule gastroscopyResult, rel1.precise_way gastroscopyDetailWay, rel1.diagnose_result gastroscopyDetailResult, rel1.diagnose_info gastroscopyDetailInfo, rel1.`status` gastroscopyAuditStatus FROM tb_patient p RIGHT JOIN ( SELECT patient_id, step, is_inspect, inspect_way, capsule, precise_way, diagnose_result, diagnose_info, `status` FROM tb_gastro_inspect WHERE is_inspect = 1 AND `status` NOT IN ( 0, 5 ) AND diagnose_result = 1 ) rel1 ON rel1.patient_id = p.id INNER JOIN ( SELECT `name`, number FROM tb_hosp ) rel2 ON rel2.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel3 ON rel3.`name` = rel2.`name` ) rel GROUP BY provinceName ) ) rel GROUP BY provinceName </select> <!-- 获取各省份胃镜检查人次统计结果 --> <select id="getProvinceGastroscopyStatistics" resultType="com.sict.data.dto.ProvinceGastroscopyDTO"> SELECT provinceName, sum( gastroscopyPlan + gastroscopyActual ) gastroscopyTotal, sum( gastroscopyPlan ) gastroscopyPlan, sum( gastroscopyActual ) gastroscopyActual, sum( gastroscopyDetail ) gastroscopyDetail, sum( earlyCancer ) earlyCancer FROM ( ( SELECT provinceName, count( * ) gastroscopyPlan, count( NULL ) gastroscopyActual, count( NULL ) gastroscopyDetail, count( NULL ) earlyCancer FROM ( SELECT p.id patientId, rel3.area provinceName, rel1.step planFlupStep, CASE rel1.continue_flup WHEN 1 THEN '继续随访' WHEN 0 THEN '停止随访' ELSE '' END isContinueFlup, rel1.content_type planFlupContent FROM tb_patient p RIGHT JOIN ( SELECT patient_id, step, continue_flup, content_type FROM tb_flup_plan WHERE continue_flup = 1 AND content_type LIKE '%a%' ) rel1 ON rel1.patient_id = p.id INNER JOIN ( SELECT `name`, number FROM tb_hosp ) rel2 ON rel2.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel3 ON rel3.`name` = rel2.`name` ) rel GROUP BY provinceName ) UNION ( SELECT provinceName, count( NULL ) gastroscopyPlan, count( * ) gastroscopyActual, count( gastroscopyDetailWay <> '[]' OR NULL ) gastroscopyDetail, count( gastroscopyDetailDetail LIKE '%"b":1%' OR NULL ) + count( gastroscopyDetailDetail LIKE '%"g":1%' OR NULL ) earlyCancer FROM ( SELECT p.id patientId, rel3.area provinceName, rel1.step gastroscopyStep, CASE rel1.is_inspect WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE '' END isGastroscopy, rel1.inspect_way gastroscopyWay, CASE rel1.capsule WHEN 1 THEN '异常' WHEN 2 THEN '未见异常' ELSE '' END gastroscopyResult, rel1.precise_way gastroscopyDetailWay, CASE WHEN rel1.diagnose_result = 1 THEN '异常' WHEN rel1.diagnose_result = 2 THEN '未见明显异常' ELSE '' END gastroscopyDetailResult, rel1.diagnose_info gastroscopyDetailDetail, rel1.STATUS gastroscopyAuditStatus FROM tb_patient p RIGHT JOIN ( SELECT patient_id, step, inspect_way, precise_way, capsule, diagnose_result, diagnose_info, is_inspect, `status` FROM tb_gastro_inspect WHERE is_inspect = 1 AND `status` NOT IN ( 0, 5 ) ) rel1 ON rel1.patient_id = p.id INNER JOIN ( SELECT `name`, number FROM tb_hosp ) rel2 ON rel2.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel3 ON rel3.`name` = rel2.`name` ) rel GROUP BY provinceName ) ) rel GROUP BY provinceName </select> <!-- 获取各省份筛查人次统计结果 --> <select id="getProvinceScreeningStatistics" resultType="com.sict.data.dto.ProvinceScreeningDTO"> SELECT provinceName, count( * ) provinceScreeningTotal, count( screeningStatus = 1 OR NULL ) provinceApplyScreeningTotal, count( hospaudditStatus = 0 OR NULL ) hospApply FROM ( SELECT p.id patientId, p.`name` patientName, rel6.area provinceName, CASE rel1.igg WHEN 1 THEN '阳性' WHEN 0 THEN '阴性' ELSE '' END iggDetection, CASE rel2.grade WHEN 1 THEN '低风险' WHEN 2 THEN '中风险' WHEN 3 THEN '高风险' ELSE '' END riskLevel, CASE rel3.is_inspect WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE '否' END isGastroscopy, rel3.inspect_way gastroscopyWay, CASE rel3.capsule WHEN 1 THEN '异常' WHEN 2 THEN '未见异常' ELSE '' END gastroscopyResult, rel3.precise_way gastroscopyDetailWay, CASE rel3.diagnose_result WHEN 1 THEN '异常' WHEN 2 THEN '未见明显异常' ELSE '' END gastroscopyDetailResult, rel3.diagnose_info gastroscopyDetailInfo, CASE rel4.continue_flup WHEN 1 THEN '继续随访' WHEN 0 THEN '停止随访' ELSE '' END isContinueFlup, rel4.content_type planFlupContent, rel1.`status` screeningStatus, rel7.is_auddit hospAudditStatus FROM tb_patient p RIGHT JOIN ( SELECT patient_id, igg, step, `status` FROM tb_lab_inspect WHERE `status` NOT IN ( 0, 5 ) ) rel1 ON rel1.patient_id = p.id LEFT JOIN ( SELECT patient_id, step, score, grade, `status` FROM tb_risk_assess WHERE `status` NOT IN ( 0, 5 ) ) rel2 ON rel2.patient_id = p.id AND rel2.step = rel1.step AND rel2.`status` = rel1.`status` LEFT JOIN ( SELECT patient_id, step, is_inspect, inspect_way, capsule, precise_way, diagnose_result, diagnose_info, `status` FROM tb_gastro_inspect WHERE `status` NOT IN ( 0, 5 ) ) rel3 ON rel3.patient_id = p.id AND rel3.step = rel2.step AND rel3.`status` = rel2.`status` LEFT JOIN ( SELECT patient_id, step, continue_flup, content_type, `status` FROM tb_flup_plan WHERE `status` NOT IN ( 0, 5 ) ) rel4 ON rel4.patient_id = p.id AND rel4.step = rel3.step AND rel4.`status` = rel3.`status` INNER JOIN ( SELECT number, `name` FROM tb_hosp ) rel5 ON rel5.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel6 ON rel6.`name` = rel5.`name` LEFT JOIN ( SELECT hosp_number, is_auddit FROM tmp_tb_hosp_apply ) rel7 ON rel7.hosp_number = rel5.number ) rel GROUP BY provinceName </select> <!-- 获取省份胃镜精查最终诊断异常统计结果 --> <select id="getProvinceGastroscopyResult" resultType="com.sict.data.dto.ProvinceGastroscopyResultDTO"> SELECT provinceName, ( count( gastroDetailInfo LIKE '%"a":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"b":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"c":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"d":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"e":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"f":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"g":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"h":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"i":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"j":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"k":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"l":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"m":1%' OR NULL ) + count( gastroDetailInfo LIKE '%"n":%' OR NULL ) ) total, count( gastroDetailInfo LIKE '%"a":1%' OR NULL ) AS esophagusTumor, count( gastroDetailInfo LIKE '%"b":1%' OR NULL ) AS earlyEsophagealCancer, count( gastroDetailInfo LIKE '%"c":1%' OR NULL ) AS progressEsophagealCancer, count( gastroDetailInfo LIKE '%"d":1%' OR NULL ) AS barretEsophagus, count( gastroDetailInfo LIKE '%"e":1%' OR NULL ) AS refluxEsophagitis, count( gastroDetailInfo LIKE '%"f":1%' OR NULL ) AS gastricMucosaTumor, count( gastroDetailInfo LIKE '%"g":1%' OR NULL ) AS earlyGastricCancer, count( gastroDetailInfo LIKE '%"h":1%' OR NULL ) AS progressGastricCancer, count( gastroDetailInfo LIKE '%"i":1%' OR NULL ) AS atrophicGastritis, count( gastroDetailInfo LIKE '%"j":1%' OR NULL ) AS stomachUlcer, count( gastroDetailInfo LIKE '%"k":1%' OR NULL ) AS gastricPolyp, count( gastroDetailInfo LIKE '%"l":1%' OR NULL ) AS nonAtrophicGastritis, count( gastroDetailInfo LIKE '%"m":1%' OR NULL ) AS duodenalUlcer, count( gastroDetailInfo LIKE '%"n":%' OR NULL ) AS others, count( gastroDetailInfo LIKE '%"type_a":"a"%' OR gastroDetailInfo LIKE '%"type_f":"a"%' OR NULL ) AS highEsophagusTumor FROM ( SELECT p.id patientId, rel3.area provinceName, rel1.step gastroStep, rel1.is_inspect isGastro, rel1.inspect_way gastroWay, rel1.capsule gastroResult, rel1.precise_way gastroDetailWay, rel1.diagnose_result gastroDetailResult, rel1.diagnose_info gastroDetailInfo, rel1.`status` auditStatus FROM tb_patient p RIGHT JOIN ( SELECT patient_id, step, is_inspect, inspect_way, capsule, precise_way, diagnose_result, diagnose_info, `status` FROM tb_gastro_inspect WHERE is_inspect = 1 AND `status` NOT IN ( 0, 5 ) AND diagnose_result = 1 ) rel1 ON rel1.patient_id = p.id INNER JOIN ( SELECT `name`, number FROM tb_hosp ) rel2 ON rel2.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel3 ON rel3.`name` = rel2.`name` ) rel GROUP BY provinceName </select> <!-- 获取患病风险等级评估统计 --> <select id="getRiskAssessStatistics" resultType="com.sict.data.dto.RiskAssessDTO"> SELECT count( riskLevel = '高风险' OR NULL ) highRisk, count( riskLevel = '中风险' OR NULL) mediumRisk, count( riskLevel = '低风险' OR NULL) lowRisk FROM ( SELECT p.id patientId, rel3.area provinceName, rel1.score riskScore, CASE rel1.grade WHEN 1 THEN '低风险' WHEN 2 THEN '中风险' WHEN 3 THEN '高风险' ELSE '' END riskLevel FROM tb_patient p RIGHT JOIN ( SELECT patient_id, igg, step, `status` FROM tb_lab_inspect WHERE `status` NOT IN ( 0, 5 ) ) rel4 ON rel4.patient_id = p.id LEFT JOIN ( SELECT patient_id, score, grade, step, `status` FROM tb_risk_assess ) rel1 ON rel1.patient_id = p.id AND rel1.step=rel4.step AND rel1.`status` = rel4.`status` INNER JOIN ( SELECT `name`, number FROM tb_hosp ) rel2 ON rel2.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel3 ON rel3.`name` = rel2.`name` ) rel </select> <!-- 获取胃镜精查统计结果 --> <select id="getGastroscopyDetailStatistics" resultType="com.sict.data.dto.GastroscopyDetailDTO"> SELECT count( * ) total, count( gastroscopyResult = '异常' OR NULL ) actual FROM ( SELECT p.id patientId, p.`name` patientName, rel6.area provinceName, CASE rel1.igg WHEN 1 THEN '阳性' WHEN 0 THEN '阴性' ELSE '' END iggDetection, CASE rel2.grade WHEN 1 THEN '低风险' WHEN 2 THEN '中风险' WHEN 3 THEN '高风险' ELSE '' END riskLevel, CASE rel3.is_inspect WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE '否' END isGastroscopy, rel3.inspect_way gastroscopyWay, CASE rel3.capsule WHEN 1 THEN '异常' WHEN 2 THEN '未见异常' ELSE '' END gastroscopyResult, rel3.precise_way gastroscopyDetailWay, CASE rel3.diagnose_result WHEN 1 THEN '异常' WHEN 2 THEN '未见明显异常' ELSE '' END gastroscopyDetailResult, rel3.diagnose_info gastroscopyDetailInfo, rel1.`status` screeningStatus FROM tb_patient p RIGHT JOIN ( SELECT patient_id, igg, step, `status` FROM tb_lab_inspect WHERE `status` NOT IN ( 0, 5 ) ) rel1 ON rel1.patient_id = p.id LEFT JOIN ( SELECT patient_id, step, score, grade, `status` FROM tb_risk_assess ) rel2 ON rel2.patient_id = p.id AND rel2.step = rel1.step AND rel2.`status` = rel1.`status` LEFT JOIN ( SELECT patient_id, step, is_inspect, inspect_way, capsule, precise_way, diagnose_result, diagnose_info, `status` FROM tb_gastro_inspect ) rel3 ON rel3.patient_id = p.id AND rel3.step = rel2.step AND rel3.`status` = rel2.`status` INNER JOIN ( SELECT number, `name` FROM tb_hosp ) rel5 ON rel5.number = p.hosp_number LEFT JOIN ( SELECT area, `name` FROM tmp_tb_hosp_area ) rel6 ON rel6.`name` = rel5.`name` WHERE rel2.grade = 2 OR rel2.grade = 3 ) rel </select> <!-- 获取医院相关统计(申请数、认证数) --> <select id="getHospStatistics" resultType="com.sict.data.dto.HospStatisticsDTO"> SELECT count( is_auddit = 1 OR NULL ) certifiedHosp, count( is_auddit = 0 OR NULL ) applyHosp FROM tmp_tb_hosp_apply </select> </mapper>