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.

248 lines
9.8 KiB

4 years ago
<?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="getUserIdById" resultType="Long">
SELECT
m.user_id
FROM
t_qcp_first_aid a,
t_pro_member m
WHERE
a.project_id = m.project_id
AND a.id = #{aidId}
AND a.rec_status = 0
AND m.rec_status = 0
</select>
<select id="queryQuality" resultType="com.ccsens.carbasics.bean.vo.StatisticalVo$Quality">
select
<choose>
<when test="param.type == 0">
DATE_FORMAT(a.created_at,'%Y-%m') as date,
</when>
<otherwise>
concat(DATE_FORMAT(a.created_at,'%Y-'), week(a.created_at)) as date,
</otherwise>
</choose>
count(a.id) as total,
count(r.id) as rongshuan,
max(r.answer - a.arrive_hospital_time)/60000 as max,
min(r.answer - a.arrive_hospital_time)/60000 as min,
avg(r.answer - a.arrive_hospital_time)/60000 as avg,
count(if(r.answer - a.arrive_hospital_time &lt;= 3600000, 1, null)) as dabiao
from t_qcp_first_aid a left join t_qcp_patient p on a.patient_id = p.id
left join t_qcp_first_aid_record r on a.id = r.first_aid_id and r.question_code = 'JMRSSJ' and r.rec_status = 0
where p.hospital_id = #{hospitalId} and a.rec_status = 0 and p.rec_status = 0
<if test="param.startTime != null and param.startTime != 0">
and unix_timestamp(a.created_at)*1000 &gt;= #{param.startTime}
</if>
<if test="param.endTime != null and param.endTime != 0">
and unix_timestamp(a.created_at)*1000 &lt;= #{param.endTime}
</if>
<choose>
<when test="param.type == 0">
and DATE_FORMAT(a.created_at,'%Y-%m') = FROM_UNIXTIME(r.answer/1000,'%Y-%m')
GROUP BY DATE_FORMAT(a.created_at,'%Y-%m')
</when>
<otherwise>
and concat(DATE_FORMAT(a.created_at,'%Y-'), week(a.created_at)) = concat(DATE_FORMAT(from_unixtime(r.answer/1000),'%Y-'), week(from_unixtime(r.answer/1000)))
GROUP BY DATE_FORMAT(a.created_at,'%Y-%m')
</otherwise>
</choose>
</select>
<select id="getMedian" resultType="java.math.BigDecimal">
SELECT AVG(dd.val) as median_val
FROM (
SELECT d.val, @rownum:=@rownum+1 as `row_number`, @total_rows:=@rownum
FROM
(select r.answer/60000 as val from t_qcp_first_aid a, t_qcp_first_aid_record r
where a.id = r.first_aid_id and r.question_code = 'JMRSSJ'
<choose>
<when test="type == 0">and FROM_UNIXTIME(r.answer/1000,'%Y-%m') = #{date} </when>
<when test="type == 1">and concat(DATE_FORMAT(a.created_at,'%Y-'), week(a.created_at)) = #{date} </when>
<when test="type == 2">and FROM_UNIXTIME(r.answer/1000,'%Y-%m-%d') = #{date} </when>
</choose>
) d,
(SELECT @rownum:=0) r
WHERE d.val is NOT NULL
ORDER BY d.val
) as dd
WHERE dd.row_number IN ( FLOOR((@total_rows+1)/2), FLOOR((@total_rows+2)/2) );
</select>
<select id="queryThrombolyticDay" resultType="java.lang.String">
select distinct FROM_UNIXTIME(r.answer/1000,'%Y-%m-%d') as day
from t_qcp_first_aid a, t_qcp_first_aid_record r, t_qcp_patient p
where a.id = r.first_aid_id and a.patient_id = p.id and p.hospital_id = #{hospitalId}
and r.question_code = 'JMRSSJ' and a.rec_status = 0 and p.rec_status = 0 and r.rec_status = 0
</select>
<select id="getIdByProjectId" resultType="com.ccsens.carbasics.bean.po.FirstAid">
4 years ago
SELECT
*
4 years ago
FROM
t_qcp_first_aid
4 years ago
WHERE
rec_status = 0
AND project_id = #{projectId}
LIMIT 1
</select>
4 years ago
<select id="getPatientName" resultType="java.lang.String">
SELECT
p.NAME
FROM
t_qcp_first_aid a,
t_qcp_patient p
WHERE
a.patient_id = p.id
AND a.id = #{id}
AND a.rec_status = 0
AND p.rec_status = 0
</select>
<select id="selResult" resultType="java.lang.Integer">
select
if(tfa.num is NULL,0,tfa.num) as num
FROM
(SELECT
concat( #{year}, `name` ) AS `name`
FROM
t_statistics_month ) tsm
LEFT JOIN (
SELECT
tfa.da,
count( tfa.da ) AS num
FROM
(
SELECT
FROM_UNIXTIME( a.time / 1000, '%Y-%m' ) AS da
FROM
`t_qcp_first_aid` a LEFT JOIN t_qcp_patient p on a.patient_id = p.id and p.rec_status = 0
WHERE
a.rec_status = 0
AND p.hospital_id = #{hospitalId}
AND FROM_UNIXTIME( time / 1000, '%Y' ) = #{year}
) tfa
GROUP BY
tfa.da
ORDER BY
tfa.da
) tfa on tsm.`name`=tfa.`da`
</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
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}
AND type = #{template}
) t
LEFT JOIN t_qcp_first_aid_record t1 ON t.id = 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.id = 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.id = t3.first_aid_id
AND t3.operation_type = 3
AND t3.rec_status = 0
LEFT JOIN t_qcp_first_aid_record t4 ON t.id = t4.first_aid_id
AND t4.question_code = 'CYQK-CYSJ'
AND t4.rec_status = 0
WHERE
t4.id IS NULL
<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.id
</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,
NAME,
gender,
age,
type,
data_status AS dataStatus
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 in
<foreach collection="hospitalList" open="(" close=")" separator="," item="hospitalId">
#{hospitalId}
</foreach>
AND data_status in (1,3,5,6)
) t
LEFT JOIN t_qcp_first_aid_record t1 ON t.id = 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.id = 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.id = 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.id
</select>
4 years ago
</mapper>