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.
 
 

615 lines
27 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.tcm.persist.dao.PatientDao">
<select id="selConRec" resultType="com.ccsens.tcm.bean.vo.ConRecVo$SelConRecVo">
SELECT
tcr.id,
tcr.start_time AS startTime,
tcr.end_time AS endTime,
place,
`host`,
participants,
tcr.discussion_content AS discussionContent,
tcr.meeting_minutes AS meetingMinutes
FROM
t_conference_records tcr
WHERE
tcr.rec_status=0
<if test="id != null and id!=0 ">
and id = #{param.id}
</if>
<if test="id == null">
<if test="startTime != null ">
and tcr.start_time &gt; #{param.startTime}
</if>
<if test="endTime != null ">
and tcr.end_time &lt; #{param.endTime}
</if>
<if test="place != null and place != ''">
and tcr.place like concat('%',#{place, jdbcType=VARCHAR},'%')
</if>
<if test="host != null and host != ''">
and tcr.host like concat('%',#{host, jdbcType=VARCHAR},'%')
</if>
<if test="discussionContent != null and discussionContent != ''">
and tcr.discussion_content like concat('%',#{discussionContent},'%')
</if>
</if>
</select>
<select id="selPatientMesList" resultType="com.ccsens.tcm.bean.vo.PatientVo$SelPatient">
SELECT
tpi.id,
tpi.hospitalization,
tpi.code,
tpi.inpatient_id AS inpatientId,
tpi.input_status AS inputStatus,
tpi.hospital_id AS hospitalId,
th.name as hosName,
ti.name,
ti.collection_num as collectionNum,
tpi.update_at as updateAt,
tpi.user_id as userId,
d.`name` as doctorName
FROM
t_patient_information tpi left join t_inpatient ti on ti.rec_status IN ( 0, 1 ) and ti.id=tpi.inpatient_id
left join t_hospital th on th.rec_status=0 and th.id=tpi.hospital_id
LEFT JOIN t_doctor d on tpi.user_id = d.user_id and d.rec_status = 0
WHERE
tpi.rec_status = 0
<if test="hospitalId!=null and hospitalId !=0 ">
and tpi.hospital_id=#{hospitalId}
</if>
<if test="hospitalization!=null and hospitalization!=''">
and tpi.hospitalization like concat('%',#{hospitalization},'%')
</if>
<if test="inpatientId !=null and inpatientId!=0">
and tpi.inpatient_id=#{inpatientId}
</if>
<if test="inputStatus !=null">
and tpi.input_status=#{inputStatus}
</if>
<if test="(conditionList!=null and conditionList.size()!=0 ) or (conditionListDate != null and conditionListDate.size() !=0 ) or (reportParams != null and reportParams.size() != 0)">
and tpi.id IN (
SELECT DISTINCT
( t.patient_id )
FROM
(
<trim suffixOverrides="INTERSECT">
<if test="conditionList!=null and conditionList.size()!=0 ">
<foreach collection="conditionList" item="item">
SELECT
tpr.patient_id
FROM
t_patient_record tpr
WHERE
tpr.rec_status = 0
and tpr.contents_type = 0
AND tpr.test_questions_id = #{item.testQuestionsId}
<if test="item.contents!=null and item.contents!=''">
AND tpr.contents LIKE concat('%',#{item.contents},'%')
</if>
INTERSECT
</foreach>
</if>
<if test="conditionListDate != null and conditionListDate.size() !=0 ">
<foreach collection="conditionListDate" item="item1">
SELECT
tpr.patient_id
FROM
t_patient_record tpr
WHERE
tpr.rec_status = 0
and tpr.contents_type = 0
AND tpr.test_questions_id = #{item1.testQuestionsId}
<if test="item1.startTime!=null and item1.startTime!=''">
AND tpr.contents &gt; #{item1.startTime}
</if>
<if test="item1.endTime!=null and item1.endTime!=''">
AND tpr.contents &lt; #{item1.endTime}
</if>
INTERSECT
</foreach>
</if>
<if test="reportParams != null and reportParams.size() != 0">
<foreach collection="reportParams" item="item">
<if test="item.code != null and item.code != '' and (item.start != null or item.end != null)">
SELECT
r.patient_id
FROM
question.t_ht_patient_score s,
question.t_ht_question q,
question.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 ) &gt;= #{item.start} AND
</if>
<if test="item.end != null">
sum( score ) &lt;= #{item.end} AND
</if>
</trim>
INTERSECT
</if>
</foreach>
</if>
</trim>
) t
)
</if>
order by tpi.update_at desc
</select>
<select id="selPatientInformationList" resultType="com.ccsens.tcm.bean.vo.PatientVo$SelPatient">
SELECT
tpi.id,
tpi.hospitalization,
tpi.code,
tpi.inpatient_id AS inpatientId,
tpi.input_status AS inputStatus,
tpi.hospital_id AS hospitalId,
ti.name,
ti.collection_num as collectionNum,
tpi.user_id as userId,
d.`name` as doctorName
FROM
t_patient_information tpi left join t_inpatient ti on ti.rec_status in(0 , 1) and ti.id=tpi.inpatient_id
LEFT JOIN t_doctor d on d.user_id = tpi.user_id and d.rec_status = 0
WHERE
tpi.rec_status =0
<if test="param.id != null and param.id!=0">
and tpi.id=#{param.id}
</if>
<if test="param.id == null">
<if test="param.hospitalization!=null and param.hospitalization!='' ">
and tpi.hospitalization like concat('%', #{param.hospitalization}, '%')
</if>
<if test="param.code != null and param.code != '' ">
and tpi.code like concat('%',#{param.code}, '%')
</if>
<if test="param.inpatientId != null and param.inpatientId != 0 ">
and tpi.inpatient_id= #{param.inpatientId}
</if>
<if test="param.hospitalId != null and param.hospitalId != 0 ">
and tpi.hospital_id= #{param.hospitalId}
</if>
<if test="param.inputStatus != null and param.inputStatus != 0 ">
and tpi.input_status= #{param.inputStatus}
</if>
<if test="param.startTime != null ">
and tpi.created_at &gt;= #{param.startTime}
</if>
<if test="param.endTime != null ">
and tpi.created_at &lt;= #{param.endTime}
</if>
<if test="param.doctorId!=null and param.doctorId!=0 ">
and d.id = #{param.doctorId}
</if>
<choose>
<when test="param.queryAuthority == 0">
and tpi.user_id = #{userId}
</when>
<when test="param.queryAuthority == 1">
<if test="param.hospitalIds != null and param.hospitalIds.size() > 0">
<choose>
<when test="param.hospitalIds.size() == 1">
and tpi.hospital_id=#{param.hospitalIds[0]}
</when>
<otherwise>
and tpi.hospital_id in
<foreach collection="param.hospitalIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</otherwise>
</choose>
</if>
</when>
<when test="param.queryAuthority == 2">
</when>
<otherwise>
and tpi.user_id = #{userId}
</otherwise>
</choose>
</if>
order by tpi.update_at desc
</select>
<select id="countCase" resultType="com.ccsens.tcm.bean.vo.StatisticVo$Shuliang">
select DATE_FORMAT(tpi.update_at,'%Y-%m-%d') as shijian,count(*) as nums from t_patient_information tpi
where tpi.rec_status=0
<if test="param.hospitalId!=null and param.hospitalId!=0 ">
and tpi.hospital_id=#{param.hospitalId}
</if>
<if test="inputStatus!=null and inputStatus.length>0">
and tpi.input_status in
<foreach collection="inputStatus" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
GROUP BY shijian
</select>
<select id="countAnalysis" resultType="com.ccsens.tcm.bean.vo.StatisticVo$SelGroupList">
<if test="testQuestionsId!=null and testQuestionsId!=0">
select tpr.contents as content,ti.name,
count(distinct tpr.patient_id) as nums
from t_patient_information tpi
left join t_patient_record tpr on tpi.id=tpr.patient_id and tpr.rec_status=0 and tpr.contents_type =0
left join t_inpatient ti on ti.id=tpi.inpatient_id and ti.rec_status in (0,1)
where tpi.rec_status=0
<if test="testQuestionsId!=null and testQuestionsId!=0">
and tpr.test_questions_id=#{testQuestionsId}
</if>
</if>
<if test="testQuestionsId==null or testQuestionsId==0">
SELECT
'总人数' as content,
ti.name,
count( * ) AS nums
FROM
t_patient_information tpi
left join t_inpatient ti on ti.id=tpi.inpatient_id and ti.rec_status = 0
WHERE
tpi.rec_status = 0
</if>
and tpi.id in (
SELECT
tpi.id
FROM
t_patient_information tpi left join t_inpatient ti on ti.rec_status=0 and ti.id=tpi.inpatient_id
WHERE
tpi.rec_status = 0
<if test="hospitalId!=null and hospitalId !=0 ">
and tpi.hospital_id=#{hospitalId}
</if>
<if test="hospitalization!=null and hospitalization!=''">
and tpi.hospitalization like concat('%',#{hospitalization},'%')
</if>
<if test="inpatientId !=null and inpatientId!=0">
and tpi.inpatient_id=#{inpatientId}
</if>
<if test="inputStatus !=null">
and tpi.input_status=#{inputStatus}
</if>
<if test="(conditionList!=null and conditionList.size()!=0 ) or (conditionListDate != null and conditionListDate.size() !=0 ) or (reportParams != null and reportParams.size() != 0)">
and tpi.id IN (
SELECT DISTINCT
( t.patient_id )
FROM
(
<trim suffixOverrides="INTERSECT">
<if test="conditionList!=null and conditionList.size()!=0 ">
<foreach collection="conditionList" item="item">
SELECT
tpr.patient_id
FROM
t_patient_record tpr
WHERE
tpr.rec_status = 0
AND tpr.test_questions_id = #{item.testQuestionsId}
and tpr.contents_type =0
<if test="item.contents!=null and item.contents!=''">
AND tpr.contents LIKE concat('%',#{item.contents},'%')
</if>
INTERSECT
</foreach>
</if>
<if test="conditionListDate != null and conditionListDate.size() !=0 ">
<foreach collection="conditionListDate" item="item1">
SELECT
tpr.patient_id
FROM
t_patient_record tpr
WHERE
tpr.rec_status = 0
AND tpr.test_questions_id = #{item1.testQuestionsId}
and tpr.contents_type = 0
<if test="item1.startTime!=null and item1.startTime!=''">
AND tpr.contents &gt; #{item1.startTime}
</if>
<if test="item1.endTime!=null and item1.endTime!=''">
AND tpr.contents &lt; #{item1.endTime}
</if>
INTERSECT
</foreach>
</if>
<if test="reportParams != null and reportParams.size() != 0">
<foreach collection="reportParams" item="item">
<if test="item.code != null and item.code != '' and (item.start != null or item.end != null)">
SELECT
r.patient_id
FROM
question.t_ht_patient_score s,
question.t_ht_question q,
question.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 ) &gt;= #{item.start} AND
</if>
<if test="item.end != null">
sum( score ) &lt;= #{item.end} AND
</if>
</trim>
INTERSECT
</if>
</foreach>
</if>
</trim>
) t
)
</if>
)
<if test="testQuestionsId != null and testQuestionsId!=0">
group by content
</if>
</select>
<select id="statisticsComplete" resultType="com.ccsens.tcm.bean.vo.StatisticVo$StatisticsComplete">
SELECT
(case input_status
when 5 THEN 2
when 6 then 2
else input_status end
) as id,
(case input_status
when 0 THEN '新建'
when 1 then '数据搜集中'
when 2 then '数据搜集完成'
when 5 then '数据搜集完成'
when 6 then '数据搜集完成'
when 3 then '数据搜集超时'
when 4 then '废弃'
END) as name,
count(*) as nums
FROM
t_patient_information
WHERE
rec_status = 0
<if test="hospitalId != null and hospitalId != 0">
and hospital_id = #{hospitalId}
</if>
GROUP BY
(case input_status
when 5 THEN 2
when 6 then 2
else input_status end)
</select>
<select id="completeHospital" resultType="com.ccsens.tcm.bean.vo.StatisticVo$CompleteHospital">
SELECT
t.hospital_id as hospitalId,
t.`name` as hospitalName,
MAX(CASE t.input_status WHEN 0 THEN nums ELSE 0 END ) unfinished,
MAX(CASE t.input_status WHEN 1 THEN nums ELSE 0 END ) underway,
MAX(CASE t.input_status WHEN 2 THEN nums when 5 THEN nums WHEN 6 THEN nums ELSE 0 END ) completed,
MAX(CASE t.input_status WHEN 3 THEN nums ELSE 0 END ) overtime,
MAX(CASE t.input_status WHEN 4 THEN nums ELSE 0 END ) discarded
FROM(
SELECT
i.hospital_id,
h.`name`,
i.input_status,
count(*) as nums
FROM
t_patient_information i
LEFT JOIN t_hospital h on i.hospital_id = h.id
WHERE
i.rec_status = 0
and h.rec_status = 0
GROUP BY
hospital_id,
input_status
) t
GROUP BY
t.hospital_id
</select>
<select id="completeDoctor" resultType="com.ccsens.tcm.bean.vo.StatisticVo$CompleteDoctor">
SELECT
t.user_id as doctorId,
t.`name` as doctorName,
MAX(CASE t.input_status WHEN 0 THEN nums ELSE 0 END ) unfinished,
MAX(CASE t.input_status WHEN 1 THEN nums ELSE 0 END ) underway,
MAX(CASE t.input_status WHEN 2 THEN nums when 5 THEN nums WHEN 6 THEN nums ELSE 0 END ) completed,
MAX(CASE t.input_status WHEN 3 THEN nums ELSE 0 END ) overtime,
MAX(CASE t.input_status WHEN 4 THEN nums ELSE 0 END ) discarded
FROM(
SELECT
i.user_id,
d.`name`,
i.input_status,
count(*) as nums
FROM
t_patient_information i
LEFT JOIN t_doctor d on i.user_id = d.user_id
WHERE
i.rec_status = 0
and d.rec_status = 0
and i.hospital_id = #{hospitalId}
GROUP BY
i.user_id,
i.input_status
) t
GROUP BY
t.user_id
</select>
<select id="selBiologicalSamples" resultType="com.ccsens.tcm.bean.vo.BiologicalSamplesVo$selBiolog">
select th.name,tbs.sample_type as sampleType, tpi.hospitalization, tpi.code as patientCode, tbs.collect_time as collectTime,
tbs.update_at as updateAt,
tbs.user_id as userId,
d.`name` as doctorName
from t_biological_samples tbs
left join t_patient_information tpi on tpi.id=tbs.patient_information_id and tpi.rec_status=0
left join t_hospital th on th.id=tpi.hospital_id and th.rec_status=0
LEFT JOIN t_doctor d on d.user_id = tbs.user_id and d.rec_status = 0
where tbs.rec_status=0
<if test="hospitalId!=null">
and th.id=#{hospitalId}
</if>
<if test="sampleType!=null">
and tbs.sample_type=#{sampleType}
</if>
<if test="hospitalization!=null and hospitalization!=''">
and tpi.hospitalization like concat('%',#{hospitalization},'%')
</if>
<if test="code!=null and code!=''">
and tpi.code like concat('%',#{code},'%')
</if>
<if test="collectTime!=null">
and tbs.collect_time=#{collectTime}
</if>
order by tbs.update_at desc
</select>
<select id="selAllYBS" resultType="com.ccsens.tcm.bean.vo.BiologicalSamplesVo$SelBiologNums">
select th.id,th.name,count(*) as nums from t_biological_samples tbs
left join t_patient_information tpi on tpi.id = tbs.patient_information_id and tpi.rec_status=0
left join t_hospital th on th.id=tpi.hospital_id and th.rec_status=0
where tbs.rec_status=0
group by th.id
</select>
<sql id="adjacentTasksSql">
select
tpr.id,
(
CASE
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 9 AND DATEDIFF( now( ), tpr.contents ) &lt;= 19 ) THEN
DATE_FORMAT( FROM_UNIXTIME( UNIX_TIMESTAMP( tpr.contents ) + 14 * 24 * 60 * 60 ), '%Y-%m-%d' )
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 85 AND DATEDIFF( now( ), tpr.contents ) &lt;= 95 ) THEN
DATE_FORMAT( FROM_UNIXTIME( UNIX_TIMESTAMP( tpr.contents ) + 90 * 24 * 60 * 60 ), '%Y-%m-%d' )
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 175 AND DATEDIFF( now( ), tpr.contents ) &lt;= 185 ) THEN
DATE_FORMAT( FROM_UNIXTIME( UNIX_TIMESTAMP( tpr.contents ) + 180 * 24 * 60 * 60 ), '%Y-%m-%d' )
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 360 AND DATEDIFF( now( ), tpr.contents ) &lt;= 370 ) THEN
DATE_FORMAT( FROM_UNIXTIME( UNIX_TIMESTAMP( tpr.contents ) + 365 * 24 * 60 * 60 ), '%Y-%m-%d' )
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 0 AND DATEDIFF( now( ), tpr.contents ) &lt;= 5 ) THEN
DATE_FORMAT( FROM_UNIXTIME( UNIX_TIMESTAMP( tpr.contents ) + 1 * 24 * 60 * 60 ), '%Y-%m-%d' )
END
) as shijian,tpi.hospitalization, tpi.code, (
CASE
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 9 AND DATEDIFF( now( ), tpr.contents ) &lt;= 19 ) THEN
'14天数据搜集'
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 85 AND DATEDIFF( now( ), tpr.contents ) &lt;= 95 ) THEN
'90天数据搜集'
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 175 AND DATEDIFF( now( ), tpr.contents ) &lt;= 185 ) THEN
'180天随访'
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 360 AND DATEDIFF( now( ), tpr.contents ) &lt;= 370 ) THEN
'360天随访'
WHEN ( DATEDIFF( now( ), tpr.contents ) &gt;= 0 AND DATEDIFF( now( ), tpr.contents ) &lt;= 5 ) THEN
'第一次数据收集'
END
) as task, d.name as doctorName from t_patient_record tpr
left join t_patient_information tpi on tpi.id=tpr.patient_id and tpi.rec_status=0
left join t_doctor d on tpi.user_id = d.user_id and d.rec_status = 0
where tpr.rec_status=0
and tpr.test_questions_id=#{param.testQuestionsId}
and (
( DATEDIFF( now( ), tpr.contents ) &gt;= 9 AND DATEDIFF( now( ), tpr.contents ) &lt;= 19 )
OR ( DATEDIFF( now( ), tpr.contents ) &gt;= 85 AND DATEDIFF( now( ), tpr.contents ) &lt;= 95 )
OR ( DATEDIFF( now( ), tpr.contents ) &gt;= 175 AND DATEDIFF( now( ), tpr.contents ) &lt;= 185 )
OR ( DATEDIFF( now( ), tpr.contents ) &gt;= 360 AND DATEDIFF( now( ), tpr.contents ) &lt;= 370 )
OR ( DATEDIFF( now( ), tpr.contents ) &gt;= 0 AND DATEDIFF( now( ), tpr.contents ) &lt;= 5 )
)
</sql>
<select id="adjacentTasks" resultType="com.ccsens.tcm.bean.vo.StatisticVo$RecentAnalysisVO">
<include refid="adjacentTasksSql"/>
and tpr.user_id=#{userId}
</select>
<select id="hospitalAdjacentTasks" resultType="com.ccsens.tcm.bean.vo.StatisticVo$RecentAnalysisVO">
<include refid="adjacentTasksSql"/>
and tpr.user_id in (
select d.user_id from
(select hospital_id from t_doctor where user_id = #{userId}) h, t_doctor d
where h.hospital_id = d.hospital_id
)
</select>
<resultMap id="selPatientProgress1" type="com.ccsens.tcm.bean.vo.StatisticVo$PatientProgressVo">
<id property="id" column="id" />
<result property="hospitalization" column="hospitalization" />
<result property="code" column="code" />
<collection property="collectTime" ofType="java.lang.Integer">
<result column="collectTime"/>
</collection>
</resultMap>
<select id="selPatientProgress" resultMap="selPatientProgress1">
SELECT
tpi.id,
tpi.hospitalization,
tpi.code,
tpr.collect_time collectTime
FROM
t_patient_record tpr
, t_patient_information tpi
WHERE
tpr.rec_status = 0
and tpi.rec_status = 0
AND tpi.id = tpr.patient_id
AND tpi.input_status IN ( 0, 1, 3 )
AND tpr.user_id = #{userId}
AND tpr.created_at &gt; DATE_SUB( now( ), INTERVAL 1 YEAR )
GROUP BY
tpr.patient_id,tpr.collect_time
</select>
<select id="stringLists" resultType="java.lang.String">
select distinct tpr.contents from t_patient_record tpr
where tpr.rec_status=0
and tpr.test_questions_id=#{testQuestionsId}
</select>
<select id="selByHosAllYBS" resultType="com.ccsens.tcm.bean.vo.BiologicalSamplesVo$selByHosAllYBS" parameterType="java.lang.Long">
SELECT
tbs.sample_type AS sampleType,
(CASE tbs.sample_type
WHEN 0 THEN
'抗血凝10ml'
WHEN 1 THEN '促凝血5ml'
WHEN 2 THEN '晨尿10ml'
WHEN 3 THEN '24小时尿10ml'
end) name,
count( * ) AS nums
FROM
t_biological_samples tbs
, t_patient_information tpi where tpi.rec_status = 0
AND tbs.patient_information_id = tpi.id
AND tpi.hospital_id =#{id}
and
tbs.rec_status = 0
GROUP BY
tbs.sample_type
</select>
<select id="queryByPatient" resultType="com.ccsens.tcm.bean.vo.BiologicalSamplesVo$selBiolog">
select th.name,tbs.sample_type as sampleType, tpi.hospitalization, tpi.code as patientCode, tbs.collect_time as collectTime,
tbs.update_at as updateAt,
tbs.user_id as userId,
d.`name` as doctorName
from t_biological_samples tbs, t_patient_information tpi, t_hospital th, t_doctor d
where
tpi.id=tbs.patient_information_id
and th.id=tpi.hospital_id
and d.user_id = tbs.user_id
and tbs.patient_information_id = #{param.patientId}
and tbs.rec_status=0
and tpi.rec_status=0
and th.rec_status=0
and d.rec_status = 0
order by tbs.update_at desc
</select>
</mapper>