You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
448 lines
20 KiB
448 lines
20 KiB
<?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.ccsens.ht.persist.dao.HtPatientReportDao">
|
|
<resultMap id="BaseResultMap" type="com.ccsens.ht.bean.vo.PatientReportVo$ReprotPatient">
|
|
<id column="id" jdbcType="BIGINT" property="id"/>
|
|
<result column="name" jdbcType="VARCHAR" property="name"/>
|
|
<result column="patient_id" jdbcType="BIGINT" property="patientId"/>
|
|
<result column="patient_age" jdbcType="TINYINT" property="patientAge"/>
|
|
<result column="doctor_id" jdbcType="BIGINT" property="doctorId"/>
|
|
<result column="doctor_name" jdbcType="VARCHAR" property="doctorName"/>
|
|
<result column="serial_number" jdbcType="VARCHAR" property="serialNumber"/>
|
|
<result column="initial_impression" jdbcType="VARCHAR" property="initialImpression"/>
|
|
<result column="clinical_diagnosis" jdbcType="VARCHAR" property="clinicalDiagnosis"/>
|
|
<result column="pasi" jdbcType="TINYINT" property="pasi"/>
|
|
<result column="department" jdbcType="VARCHAR" property="department"/>
|
|
<result column="bed_number" jdbcType="VARCHAR" property="bedNumber"/>
|
|
<result column="report_time" jdbcType="BIGINT" property="reportTime"/>
|
|
<result column="check_time" jdbcType="BIGINT" property="checkTime"/>
|
|
<result column="url" jdbcType="VARCHAR" property="url"/>
|
|
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
|
<result column="patient_name" jdbcType="VARCHAR" property="patientName"/>
|
|
<result column="patient_number" jdbcType="VARCHAR" property="patientNumber"/>
|
|
<result column="hospital_number" jdbcType="VARCHAR" property="hospitalNumber"/>
|
|
<result column="sex" jdbcType="TINYINT" property="sex"/>
|
|
<result column="educational_status" jdbcType="TINYINT" property="educationalStatus"/>
|
|
<result column="educational_status_unit" jdbcType="VARCHAR" property="educationalStatusUnit"/>
|
|
<result column="career" jdbcType="TINYINT" property="career"/>
|
|
<result column="hospital" jdbcType="VARCHAR" property="hospital"/>
|
|
</resultMap>
|
|
<resultMap id="ScoreMap" type="com.ccsens.ht.bean.vo.PatientReportVo$ReportScore">
|
|
<result column="code" jdbcType="VARCHAR" property="code"/>
|
|
<result column="parent_code" jdbcType="VARCHAR" property="parentCode"/>
|
|
<result column="name" jdbcType="VARCHAR" property="name"/>
|
|
<result column="description" jdbcType="VARCHAR" property="description"/>
|
|
<result column="total_score" jdbcType="INTEGER" property="totalScore"/>
|
|
<result column="remark" jdbcType="VARCHAR" property="remark"/>
|
|
<result column="type" jdbcType="TINYINT" property="type"/>
|
|
<result column="score" jdbcType="INTEGER" property="score"/>
|
|
</resultMap>
|
|
<resultMap id="QuestionMap" type="com.ccsens.ht.bean.vo.PatientReportVo$QuestionAndAnswer">
|
|
<id column="id" property="id"/>
|
|
<result column="question" property="question"/>
|
|
<result column="sort" property="sort"/>
|
|
<collection property="optionList" ofType="com.ccsens.ht.bean.vo.PatientReportVo$Option">
|
|
<id column="optionId" property="id"/>
|
|
<result column="name" property="name"/>
|
|
<result column="answer" property="answer"/>
|
|
<result column="chooseStatus" property="chooseStatus"/>
|
|
</collection>
|
|
</resultMap>
|
|
<resultMap id="AnalyseMap" type="com.ccsens.ht.bean.vo.PatientReportVo$Analyse">
|
|
<id column="id" property="id"/>
|
|
<result column="report_time" property="reportTime"/>
|
|
<result column="patientName" property="patientName"/>
|
|
<result column="patient_age" property="patientAge"/>
|
|
<result column="pasi" property="pasi"/>
|
|
<result column="clinical_diagnosis" property="clinicalDiagnosis"/>
|
|
<result column="sex" property="sex"/>
|
|
<result column="educational_status" property="educationalStatus"/>
|
|
<result column="career" property="career"/>
|
|
<collection property="mmseScores" ofType="com.ccsens.ht.bean.vo.PatientReportVo$MMSEScore">
|
|
<id column="mmseCode" property="code"/>
|
|
<result column="mmseScore" property="score"/>
|
|
</collection>
|
|
<collection property="mocaScores" ofType="com.ccsens.ht.bean.vo.PatientReportVo$MoCAScore">
|
|
<id column="mocaSort" property="sort"/>
|
|
<result column="mocaScore" property="score"/>
|
|
</collection>
|
|
<collection property="totalScores" ofType="com.ccsens.ht.bean.vo.PatientReportVo$TotalScore">
|
|
<id column="evaluationCode" property="evaluationCode"/>
|
|
<result column="totalScore" property="totalScore"/>
|
|
</collection>
|
|
</resultMap>
|
|
|
|
<select id="queryReportResult" resultMap="BaseResultMap">
|
|
select r.*, d.name as doctor_name, p.name as patient_name, p.sex, p.educational_status, p.educational_status_unit, p.career, p.hospital_number, p.patient_number
|
|
from t_ht_patient_report r, t_ht_patient p, t_ht_doctor d
|
|
where r.patient_id = p.id and r.doctor_id = d.id and r.id = #{id, jdbcType=BIGINT}
|
|
and r.is_del = 0 and p.is_del = 0 and d.is_del = 0
|
|
</select>
|
|
<select id="queryReportScore" resultMap="ScoreMap">
|
|
select t1.code,t1.name, t1.description, t1.total_score, t1.remark,t1.type,t1.parent_code, sum(t2.score) as score
|
|
from
|
|
(
|
|
select code,name, description, total_score, remark, type, parent_code, sort from (
|
|
select t1.*, if (find_in_set(t1.parent_code, @pcode) > 0, @pcode := concat(@pcode,',',t1.code) ,0 )as ischild
|
|
from
|
|
(select * from t_ht_report where is_show = 1 and is_del = 0
|
|
<if test="rey == 1">
|
|
and `code` != 'Rey' and `code` != 'XFXPD' and parent_code != 'Rey'
|
|
</if>
|
|
<if test="rey == 2">
|
|
AND (`code` = 'Rey' or parent_code = 'Rey')
|
|
</if>
|
|
ORDER BY type, sort) t1 ,
|
|
(select @pcode:=#{report} ) t2
|
|
) t where ischild != '0'
|
|
|
|
) t1
|
|
left join t_ht_question q on t1.code = q.parent_code and q.is_del = 0
|
|
left join t_ht_patient_score t2
|
|
on q.id = t2.question_id and
|
|
(
|
|
(t2.patient_report_id = #{id, jdbcType=BIGINT} and t2.type in (0,2) and t2.is_del = 0) or t2.id is null
|
|
)
|
|
GROUP BY t1.code
|
|
order by t1.type,t1.sort
|
|
</select>
|
|
<select id="queryNpiScore" resultType="java.util.Map">
|
|
select option_name as optionName, sum(score) as score
|
|
from t_ht_patient_score
|
|
where patient_report_id = #{id, jdbcType=BIGINT} and question_parent_code = 'NPI'
|
|
and option_name in ('carer','result') and is_del = 0 group by option_name;
|
|
</select>
|
|
<select id="checkComplete" resultType="com.ccsens.ht.bean.vo.PatientReportVo$Complete">
|
|
select r.id, r.name, p.id as patientId, p.name as patientName, p.idcard as patientIdCard,
|
|
r.create_time as createTime,
|
|
concat('检测到您在', r.create_time, '为患者', p.name,'的检测报告尚未完成,是否继续?') as description ,
|
|
if(r.id = null , 0, 1) as hasUnfinished
|
|
from t_ht_patient_report r, t_ht_patient p, t_ht_doctor d
|
|
where r.patient_id = p.id and r.doctor_id = d.id
|
|
and d.user_id = #{userId, jdbcType=BIGINT} and d.audit_state = 1
|
|
and r.complete_status = 0 and d.is_del = 0 and r.is_del = 0 and p.is_del = 0
|
|
order by r.create_time desc limit 1;
|
|
</select>
|
|
<select id="ignoreComplete">
|
|
update t_ht_patient_report set complete_status = 2 , show_status = 0
|
|
where id = #{id, jdbcType=BIGINT} and complete_status = 0 and is_del = 0 and doctor_id in
|
|
(select doctor_id from t_ht_doctor where user_id = #{userId, jdbcType=BIGINT} and audit_state = 1 and is_del = 0)
|
|
</select>
|
|
<select id="queryReportName" resultType="com.ccsens.ht.bean.vo.PatientReportVo$ReportName">
|
|
select id, name, url, doctor_id as doctorId, 0 as authority from t_ht_patient_report
|
|
<where>
|
|
<if test="doctorId != null">
|
|
and doctor_id = #{doctorId, jdbcType=BIGINT}
|
|
</if>
|
|
<if test="patientId != null">
|
|
and patient_id = #{patientId, jdbcType=BIGINT}
|
|
</if>
|
|
and show_status = 1
|
|
and is_del = 0
|
|
</where>
|
|
order by create_time desc
|
|
</select>
|
|
<select id="queryAllReports" resultType="com.ccsens.ht.bean.vo.PatientReportVo$ReportName">
|
|
select t.* from
|
|
(select r.id, r.name, r.url, r.doctor_id as doctorId, 1 as authority, r.create_time
|
|
<if test="scores != null and scores.size() > 0">
|
|
,
|
|
SUM(CASE report.code WHEN 'moca' THEN s.score ELSE 0 END) as 'moca',
|
|
SUM(CASE report.code WHEN 'mmse' THEN s.score ELSE 0 END) as 'mmse',
|
|
SUM(CASE report.code WHEN 'rey' THEN s.score ELSE 0 END) as 'rey',
|
|
SUM(CASE report.code WHEN 'hama' THEN s.score ELSE 0 END) as 'hama',
|
|
SUM(CASE report.code WHEN 'hamd' THEN s.score ELSE 0 END) as 'hamd',
|
|
SUM(CASE report.code WHEN 'adl' THEN s.score ELSE 0 END) as 'adl',
|
|
SUM(CASE report.code WHEN 'npi' THEN s.score ELSE 0 END) as 'npi'
|
|
</if>
|
|
from t_ht_patient_report r, t_ht_patient p
|
|
<if test="scores != null and scores.size() > 0">
|
|
,
|
|
t_ht_report report,
|
|
t_ht_question q,
|
|
t_ht_patient_score s
|
|
</if>
|
|
where r.patient_id = p.id
|
|
<if test="scores != null and scores.size() > 0">
|
|
AND r.id = s.patient_report_id
|
|
AND report.CODE = q.evaluation_code
|
|
AND q.id = s.question_id
|
|
AND report.type = 2
|
|
AND s.type IN ( 0, 2 )
|
|
</if>
|
|
<if test="patientName != null and patientName != ''">
|
|
and p.name = #{patientName}
|
|
</if>
|
|
<if test="patientSex != null">
|
|
and p.sex = #{patientSex}
|
|
</if>
|
|
<if test="startAge != null">
|
|
and r.patient_age > #{startAge}
|
|
</if>
|
|
<if test="endAge != null">
|
|
and r.patient_age < #{endAge}
|
|
</if>
|
|
<if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">
|
|
and r.clinical_diagnosis = #{clinicalDiagnosis}
|
|
</if>
|
|
<if test="pasi != null and pasi != ''">
|
|
and r.pasi = #{pasi}
|
|
</if>
|
|
<if test="educationalStatus != null and educationalStatus != ''">
|
|
and p.educational_status = #{educationalStatus}
|
|
</if>
|
|
<if test="startEducationalStatusUnit != null">
|
|
and p.educational_status_unit >= #{startEducationalStatusUnit}
|
|
</if>
|
|
<if test="endEducationalStatusUnit != null">
|
|
and p.educational_status_unit <= #{endEducationalStatusUnit}
|
|
</if>
|
|
<if test="startTime != null">
|
|
and r.report_time >= #{startTime}
|
|
</if>
|
|
<if test="endTime != null">
|
|
and r.report_time <= #{endTime}
|
|
</if>
|
|
and r.show_status = 1
|
|
AND r.complete_status = 1
|
|
and r.is_del = 0
|
|
group by r.id
|
|
) t
|
|
where 1=1
|
|
<if test="scores != null and scores.size() > 0">
|
|
<foreach collection="scores" item="score">
|
|
<if test="score.start != null">
|
|
AND ${score.code} >= #{score.start}
|
|
</if>
|
|
<if test="score.end != null">
|
|
AND ${score.code} <= #{score.end}
|
|
</if>
|
|
</foreach>
|
|
</if>
|
|
order by create_time desc
|
|
</select>
|
|
<select id="countByClinicalDiagnosis" resultType="com.ccsens.ht.bean.vo.PatientReportVo$ClinicalDiagnosis">
|
|
select clinical_diagnosis as diagnosis, count(*) as count from t_ht_patient_report
|
|
where is_del = 0 and show_status = 1 group by diagnosis
|
|
</select>
|
|
<select id="countBySexAndAge" resultType="com.ccsens.ht.bean.vo.PatientReportVo$AgeAndSex">
|
|
select r.patient_age div 10 * 10 as ageLevel, p.sex as sex, count(*) as count from t_ht_patient_report r, t_ht_patient p
|
|
where r.patient_id = p.id and r.is_del = 0 and r.show_status = 1 group by ageLevel, sex
|
|
order by ageLevel, sex
|
|
</select>
|
|
<select id="countByDay" resultType="com.ccsens.ht.bean.vo.PatientReportVo$Day">
|
|
select FROM_UNIXTIME(report_time div 1000, '%Y-%m-%d') as dateDay, count(*) as count
|
|
from t_ht_patient_report
|
|
where is_del = 0 and show_status = 1
|
|
<if test="startTime != null">
|
|
and report_time >= #{startTime}
|
|
</if>
|
|
<if test="endTime != null">
|
|
and report_time < #{endTime}
|
|
</if>
|
|
group by dateDay
|
|
</select>
|
|
|
|
<resultMap id="queryReportAnswer" type="com.ccsens.ht.bean.vo.PatientReportVo$ReportDetailAnswer">
|
|
<id column="parentCode" property="parentCode"/>
|
|
<collection property="questionList" ofType="com.ccsens.ht.bean.vo.PatientReportVo$QuestionInfo">
|
|
<id column="questionId" property="questionId"/>
|
|
<result column="questionName" property="questionName"/>
|
|
<result column="type" property="type"/>
|
|
<result column="operateType" property="operateType"/>
|
|
<result column="otherValue" property="otherValue"/>
|
|
<collection property="answers" ofType="com.ccsens.ht.bean.vo.PatientReportVo$Answer">
|
|
<id column="optionName" property="optionName"/>
|
|
<result column="answer" property="answer"/>
|
|
</collection>
|
|
</collection>
|
|
</resultMap>
|
|
<select id="queryReportAnswer" resultMap="queryReportAnswer">
|
|
|
|
SELECT
|
|
a.parentCode,
|
|
a.questionId,
|
|
a.questionName,
|
|
a.type,
|
|
a.operateType,
|
|
a.optionName,
|
|
t.answer,
|
|
r.record_value as otherValue
|
|
FROM
|
|
(
|
|
SELECT
|
|
q.id as questionId,
|
|
q.parent_code,
|
|
r.`name` as parentCode,
|
|
q.question as questionName,
|
|
q.type as type,
|
|
q.operate_type as operateType
|
|
,o.`name` as optionName
|
|
,o.id as optionId
|
|
,o.sort
|
|
FROM
|
|
t_ht_question q
|
|
LEFT JOIN t_ht_report r on q.parent_code = r.`code`
|
|
LEFT JOIN t_ht_question_option o on q.id = o.question_id
|
|
WHERE
|
|
q.evaluation_code = #{evaluationCode}
|
|
and q.is_del = 0
|
|
and r.is_del = 0
|
|
and o.is_del = 0
|
|
GROUP BY q.id ,o.`name`
|
|
) a
|
|
LEFT JOIN
|
|
(
|
|
SELECT * FROM t_ht_patient_question_record WHERE patient_report_id = #{id} and is_del = 0
|
|
)r on r.question_id = a.questionId
|
|
LEFT JOIN
|
|
(
|
|
SELECT
|
|
s.id,
|
|
s.question_id,
|
|
o.id as optionId,
|
|
o.`name` as optionName,
|
|
if(o.type = 'hidden',s.score,o.display) as answer
|
|
FROM
|
|
t_ht_patient_score s
|
|
LEFT JOIN t_ht_question_option o
|
|
on s.option_id = o.id
|
|
WHERE
|
|
s.patient_report_id = #{id}
|
|
and s.is_del = 0
|
|
and o.is_del = 0
|
|
) t
|
|
on a.optionName = t.optionName
|
|
and a.questionId = t.question_id
|
|
ORDER BY a.questionId ,a.sort
|
|
</select>
|
|
<select id="search" resultType="com.ccsens.ht.bean.vo.PatientReportSearchVo$Search">
|
|
<foreach collection="codes" item="item" separator="INTERSECT">
|
|
<if test="item.code != null and item.code != '' and (item.start != null or item.end != null)">
|
|
SELECT
|
|
r.id,
|
|
r.NAME
|
|
FROM
|
|
t_ht_patient_score s,
|
|
t_ht_question q,
|
|
t_ht_patient_report r
|
|
WHERE
|
|
s.question_id = q.id
|
|
AND s.patient_report_id = r.id
|
|
AND s.question_parent_code = #{item.code}
|
|
AND s.type IN ( 0, 2 )
|
|
AND s.is_del = 0
|
|
AND q.is_del = 0
|
|
GROUP BY
|
|
patient_report_id
|
|
HAVING
|
|
<trim suffixOverrides="AND">
|
|
<if test="item.start != null">
|
|
sum( score ) >= #{item.start} AND
|
|
</if>
|
|
<if test="item.end != null">
|
|
sum( score ) <= #{item.end} AND
|
|
</if>
|
|
</trim>
|
|
</if>
|
|
</foreach>
|
|
|
|
</select>
|
|
<select id="queryReportScore2" resultMap="ScoreMap">
|
|
select t1.code,t1.name, t1.description, t1.total_score, t1.remark,t1.type,t1.parent_code, sum(t2.score) as score
|
|
from
|
|
(
|
|
select code,name, description, total_score, remark, type, parent_code, sort from (
|
|
select t1.*, if (find_in_set(t1.parent_code, @pcode) > 0 or t1.code = @pcode, @pcode := concat(@pcode,',',t1.code) ,0 )as ischild
|
|
from
|
|
(select * from t_ht_report where is_show = 1 and is_del = 0
|
|
ORDER BY type, sort) t1 ,
|
|
(select @pcode:=#{code} ) t2
|
|
) t where ischild != '0'
|
|
|
|
) t1
|
|
left join t_ht_question q on t1.code = q.parent_code and q.is_del = 0
|
|
left join t_ht_patient_score t2
|
|
on q.id = t2.question_id and
|
|
(
|
|
(t2.patient_report_id = #{id, jdbcType=BIGINT} and t2.type in (0,2) and t2.is_del = 0) or t2.id is null
|
|
)
|
|
GROUP BY t1.code
|
|
order by t1.type,t1.sort
|
|
</select>
|
|
<select id="queryQuestionAndScore" resultMap="QuestionMap">
|
|
SELECT
|
|
q.id,
|
|
q.question,
|
|
q.sort,
|
|
o.id AS optionId,
|
|
o.NAME,
|
|
IF( s.id IS NULL, 0, 1 ) AS chooseStatus,
|
|
s.answer
|
|
FROM
|
|
( SELECT * FROM t_ht_question WHERE evaluation_code = #{code} AND is_del = 0 ) q
|
|
LEFT JOIN t_ht_question_option o ON q.id = o.question_id
|
|
AND o.is_del = 0
|
|
LEFT JOIN t_ht_patient_score s ON q.id = s.question_id
|
|
AND o.id = s.option_id
|
|
AND s.is_del = 0
|
|
AND s.patient_report_id = #{id}
|
|
ORDER BY
|
|
q.sort,
|
|
o.sort
|
|
</select>
|
|
<select id="queryReportAnalyseScore" resultMap="AnalyseMap">
|
|
select * from
|
|
-- 患者信息
|
|
(select r.id, r.patient_age, r.pasi, r.clinical_diagnosis, p.sex, p.educational_status, p.career, r.report_time, p.name as patientName from t_ht_patient_report r , t_ht_patient p where r.patient_id = p.id and r.id in
|
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
|
#{id}
|
|
</foreach>
|
|
and r.is_del = 0 and p.is_del = 0) report
|
|
left join
|
|
-- MMSE 分数
|
|
(select s.patient_report_id as mmseReportId, t.code as mmseCode, sum(s.score) as mmseScore from
|
|
(
|
|
select if(r.parent_code = 'MMSE', r.code, r.parent_code) as code, q.id from
|
|
(
|
|
select code, parent_code from
|
|
(
|
|
select code, parent_code, if(FIND_IN_SET(parent_code,@pcode), @pcode := concat(@pcode,',',code),'') as pcode from
|
|
t_ht_report,
|
|
(select @pcode := 'MMSE') t
|
|
where is_del = 0
|
|
) r where pcode != ''
|
|
) r, t_ht_question q where (q.parent_code = r.code or q.parent_code = r.parent_code) and q.is_del = 0
|
|
) t left join t_ht_patient_score s
|
|
on t.id = s.question_id and s.is_del = 0 and s.patient_report_id in
|
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
|
#{id}
|
|
</foreach>
|
|
and s.type in (0, 2)
|
|
group by s.patient_report_id, t.code) mmse
|
|
on report.id = mmse.mmseReportId
|
|
left join
|
|
-- MOCA
|
|
(select s.patient_report_id as mocaReportId, q.sort as mocaSort, sum(s.score) as mocaScore from
|
|
(select * from t_ht_question where evaluation_code = 'MOCA' AND is_del = 0) q
|
|
left join t_ht_patient_score s on q.id = s.question_id and s.patient_report_id in
|
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
|
#{id}
|
|
</foreach>
|
|
and s.type in (0, 2)
|
|
and s.is_del = 0
|
|
group by s.patient_report_id,q.sort
|
|
) moca
|
|
on report.id = moca.mocaReportId
|
|
left join
|
|
-- 总成绩
|
|
(select q.evaluation_code as evaluationCode, s.patient_report_id as scoreReportId, sum(s.score) as totalScore from t_ht_question q left join t_ht_patient_score s on q.id = s.question_id and s.is_del = 0 where q.is_del = 0 and s.patient_report_id in
|
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
|
#{id}
|
|
</foreach>
|
|
group by q.evaluation_code, s.patient_report_id) score
|
|
on report.id = score.scoreReportId
|
|
</select>
|
|
|
|
|
|
</mapper>
|