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.

182 lines
7.2 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.carbasics.persist.dao.FirstAidDao">
<select id="querySelf" resultType="com.ccsens.carbasics.bean.vo.PatientVo$QueryPatientList">
select a.id as firstAidId, a.name, a.gender, a.age, a.data_status as dataStatus,
a.value_type as demonstrate, a.type as type, r1.answer as record1, r2.answer as record2,
a.project_id as projectId, m.record_user_id as recordUserId, r3.answer as probableCase
from
(select a.* from t_qcp_first_aid a, t_organization_project o where a.hospital_id = o.organization_id and o.project_id = #{param.projectId} and a.rec_status = 0 and o.rec_status = 0 )a
left join t_qcp_first_aid_member m
on a.id = m.first_aid_id and m.rec_status = 0
left join t_qcp_first_aid_record r
on a.id = r.first_aid_id
and r.question_code = 'CYQK-CYSJ' and r.rec_status = 0
left join t_qcp_first_aid_record r1 on a.id = r1.first_aid_id and r1.rec_status = 0
<choose>
<when test="param.firstAidType == 0">and r1.question_code='JBXX-FBSJ'</when>
<when test="param.firstAidType == 1">and r1.question_code='CYQK-LYFS'</when>
</choose>
left join t_qcp_first_aid_record r2 on a.id = r2.first_aid_id and r2.rec_status = 0
<choose>
<when test="param.firstAidType == 0">and r2.question_code='JBXX-DYSJ'</when>
<when test="param.firstAidType == 1">and r2.question_code='CYQK-CYSJ'</when>
</choose>
left join t_qcp_first_aid_record r3 on a.id = r3.first_aid_id and r3.question_code='CJBL-YSBL' and r3.rec_status = 0
where
<choose>
<when test="param.type == 0">
m.create_user_id = #{userId}
</when>
<when test="param.type == 1">
m.record_user_id in (#{userId}, 0)
</when>
</choose>
<choose>
<when test="param.firstAidType == 0"> and (r.id is null or r.answer = '')</when>
<when test="param.firstAidType == 1"> and (r.id is not null and r.answer != '')</when>
<otherwise>and (r.id is null or r.answer = '')</otherwise>
</choose>
<if test="param.name != null and param.name != ''">
and a.name like concat('%', #{param.name}, '%')
</if>
order by a.updated_at desc
</select>
<select id="getIdByProjectId" resultType="com.ccsens.carbasics.bean.po.FirstAid">
SELECT
*
FROM
t_qcp_first_aid
WHERE
rec_status = 0
AND project_id = #{projectId}
LIMIT 1
</select>
<select id="queryPatientListByQuality"
resultType="com.ccsens.carbasics.bean.vo.PatientVo$PatientListByQuality">
SELECT
t.*,
t1.answer AS hospitalNumber,
t2.answer AS arriveHospitalTime,
count( t3.id ) AS times
FROM
(
SELECT
id as firstAidId,
`name`,
gender,
age,
`type`,
nation,
idcard,
data_status AS dataStatus,
updated_at
FROM
t_qcp_first_aid
WHERE
data_status = #{param.dataStatus}
<if test="param.name!=null and param.name!=''">
AND `name` LIKE concat('%',#{param.name},'%')
</if>
<if test="param.idcard!=null and param.idcard!=''">
AND idcard LIKE concat('%',#{param.idcard},'%')
</if>
AND rec_status = 0
AND hospital_id = #{hospitalId}
<foreach collection="templates" item="id" open="AND type in (" close=")" separator=",">
#{id}
</foreach>
) t
LEFT JOIN t_qcp_first_aid_record t1 ON t.firstAidId = t1.first_aid_id
AND t1.question_code = 'JBXX-ZYH'
AND t1.rec_status = 0
LEFT JOIN t_qcp_first_aid_record t2 ON t.firstAidId = t2.first_aid_id
AND t2.question_code = 'JBXX-DYSJ'
AND t2.rec_status = 0
LEFT JOIN t_qcp_first_aid_log t3 ON t.firstAidId = t3.first_aid_id
AND t3.operation_type = 3
AND t3.rec_status = 0
LEFT JOIN t_qcp_first_aid_record t4 ON t.firstAidId = t4.first_aid_id
AND t4.question_code = 'CYQK-CYSJ'
AND t4.rec_status = 0
WHERE
<choose>
<when test="param.queryType == 0">t4.id IS NULL</when>
<otherwise>t4.id IS NOT NULL</otherwise>
</choose>
<if test="param.hospitalNumber!=null and param.hospitalNumber!=''">
AND t1.answer LIKE concat('%',#{param.hospitalNumber},'%')
</if>
<if test="param.startTime!=null and param.startTime!=0">
AND t2.answer + 0 &gt;= #{param.startTime}
</if>
<if test="param.endTime!=null and param.endTime!=0">
AND t2.answer + 0 &lt; #{param.endTime}
</if>
GROUP BY t.firstAidId
ORDER BY t.updated_at DESC
</select>
<select id="queryPatientListBySecretary"
resultType="com.ccsens.carbasics.bean.vo.PatientVo$PatientListByQuality">
SELECT
t.*,
t1.answer AS hospitalNumber,
t2.answer AS arriveHospitalTime,
count( t3.id ) AS times
FROM
(
SELECT
id as firstAidId,
`name`,
gender,
age,
`type`,
nation,
idcard,
data_status AS dataStatus,
updated_at
FROM
t_qcp_first_aid
WHERE
data_status in (1,3,5,6)
<if test="param.name!=null and param.name!=''">
AND `name` LIKE concat('%',#{param.name},'%')
</if>
<if test="param.idcard!=null and param.idcard!=''">
AND idcard LIKE concat('%',#{param.idcard},'%')
</if>
AND rec_status = 0
AND hospital_id in
<foreach collection="hospitalList" open="(" close=")" separator="," item="hospital">
#{hospital.id}
</foreach>
) t
LEFT JOIN t_qcp_first_aid_record t1 ON t.firstAidId = t1.first_aid_id
AND t1.question_code = 'JBXX-ZYH'
AND t1.rec_status = 0
LEFT JOIN t_qcp_first_aid_record t2 ON t.firstAidId = t2.first_aid_id
AND t2.question_code = 'JBXX-DYSJ'
AND t2.rec_status = 0
LEFT JOIN t_qcp_first_aid_log t3 ON t.firstAidId = t3.first_aid_id
AND t3.operation_type = 3
AND t3.rec_status = 0
<trim prefix="WHERE" prefixOverrides="and">
<if test="param.hospitalNumber!=null and param.hospitalNumber!=''">
AND t1.answer LIKE concat('%',#{param.hospitalNumber},'%')
</if>
<if test="param.startTime!=null and param.startTime!=0">
AND t2.answer + 0 &gt;= #{param.startTime}
</if>
<if test="param.endTime!=null and param.endTime!=0">
AND t2.answer + 0 &lt; #{param.endTime}
</if>
</trim>
GROUP BY t.firstAidId
ORDER BY t.updated_at DESC
</select>
</mapper>