<?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.lyms.platform.permission.dao.master.PatientMarkHospitalMapper">
<resultMap id="PatientMarkHospitalResultMap" type="com.lyms.platform.permission.model.PatientMarkHospital">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="patient_id" property="patientId" jdbcType="VARCHAR"/>
<result column="pid" property="pid" jdbcType="VARCHAR"/>
<result column="back_status" property="backStatus" jdbcType="INTEGER"/>
<result column="back_result" property="backResult" jdbcType="INTEGER"/>
<result column="back_doctor" property="backDoctor" jdbcType="VARCHAR"/>
<result column="back_date" property="backDate" jdbcType="TIMESTAMP"/>
<result column="back_make_date" property="backMakeDate" jdbcType="TIMESTAMP"/>
<result column="back_remark" property="backRemark" jdbcType="VARCHAR"/>
<result column="back_failure" property="backFailure" jdbcType="INTEGER"/>
<result column="in_hospit_status" property="inHospitStatus" jdbcType="INTEGER"/>
<result column="in_hospit_result" property="inHospitResult" jdbcType="INTEGER"/>
<result column="in_hospit_doctor" property="inHospitDoctor" jdbcType="VARCHAR"/>
<result column="in_hospit_date" property="inHospitDate" jdbcType="TIMESTAMP"/>
<result column="in_hospit_make_date" property="inHospitMakeDate" jdbcType="TIMESTAMP"/>
<result column="in_hospit_remark" property="inHospitRemark" jdbcType="VARCHAR"/>
<result column="in_hospit_failure" property="inHospitFailure" jdbcType="INTEGER"/>
<result column="make_in_hospit_date" property="makeInHospitDate" jdbcType="TIMESTAMP"/>
<result column="make_date" property="makeDate" jdbcType="TIMESTAMP"/>
<result column="make_doctor" property="makeDoctor" jdbcType="VARCHAR"/>
<result column="make_remark" property="makeRemark" jdbcType="VARCHAR"/>
<result column="hospital_id" property="hospitalId" jdbcType="VARCHAR"/>
<result column="hospit_status" property="hospitStatus" jdbcType="INTEGER"/>
<result column="hospit_date" property="hospitDate" jdbcType="TIMESTAMP"/>
<result column="hospit_type" property="hospitType" jdbcType="INTEGER"/>
</resultMap>
<insert id="addPatientMarkHospital" parameterType="com.lyms.platform.permission.model.PatientMarkHospital">
insert into patient_mark_hospital (id,patient_id,pid,back_status,back_result,back_doctor,back_date,back_make_date,back_remark,back_failure,in_hospit_status,in_hospit_result,in_hospit_doctor,in_hospit_date,in_hospit_make_date,in_hospit_remark,in_hospit_failure,make_in_hospit_date,make_date,make_doctor,make_remark,hospital_id,hospit_status,hospit_date,hospit_type) values (#{id},#{patientId},#{pid},#{backStatus},#{backResult},#{backDoctor},#{backDate},#{backMakeDate},#{backRemark},#{backFailure},#{inHospitStatus},#{inHospitResult},#{inHospitDoctor},#{inHospitDate},#{inHospitMakeDate},#{inHospitRemark},#{inHospitFailure},#{makeInHospitDate},#{makeDate},#{makeDoctor},#{makeRemark},#{hospitalId},#{hospitStatus},#{hospitDate},#{hospitType})
</insert>
<update id="updatePatientMarkHospital" parameterType="com.lyms.platform.permission.model.PatientMarkHospital">
update patient_mark_hospital
<set>
<if test="patientId != null and patientId != ''">
patient_id = #{patientId,jdbcType=VARCHAR},
</if>
<if test="pid != null and pid != ''">
pid = #{pid,jdbcType=VARCHAR},
</if>
<if test="backStatus != null and backStatus >= 0">
back_status = #{backStatus,jdbcType=INTEGER},
</if>
<if test="backResult != null and backResult >= 0">
back_result = #{backResult,jdbcType=INTEGER},
</if>
<if test="backDoctor != null and backDoctor != ''">
back_doctor = #{backDoctor,jdbcType=VARCHAR},
</if>
<if test="backDate != null">
back_date = #{backDate,jdbcType=TIMESTAMP},
</if>
<if test="backMakeDate != null">
back_make_date = #{backMakeDate,jdbcType=TIMESTAMP},
</if>
<if test="backRemark != null and backRemark != ''">
back_remark = #{backRemark,jdbcType=VARCHAR},
</if>
<if test="backFailure != null and backFailure >= 0">
back_failure = #{backFailure,jdbcType=INTEGER},
</if>
<if test="inHospitStatus != null and inHospitStatus >= 0">
in_hospit_status = #{inHospitStatus,jdbcType=INTEGER},
</if>
<if test="inHospitResult != null and inHospitResult >= 0">
in_hospit_result = #{inHospitResult,jdbcType=INTEGER},
</if>
<if test="inHospitDoctor != null and inHospitDoctor != ''">
in_hospit_doctor = #{inHospitDoctor,jdbcType=VARCHAR},
</if>
<if test="inHospitDate != null">
in_hospit_date = #{inHospitDate,jdbcType=TIMESTAMP},
</if>
<if test="inHospitMakeDate != null">
in_hospit_make_date = #{inHospitMakeDate,jdbcType=TIMESTAMP},
</if>
<if test="inHospitRemark != null and inHospitRemark != ''">
in_hospit_remark = #{inHospitRemark,jdbcType=VARCHAR},
</if>
<if test="inHospitFailure != null and inHospitFailure >= 0">
in_hospit_failure = #{inHospitFailure,jdbcType=INTEGER},
</if>
<if test="makeInHospitDate != null">
make_in_hospit_date = #{makeInHospitDate,jdbcType=TIMESTAMP},
</if>
<if test="makeDate != null">
make_date = #{makeDate,jdbcType=TIMESTAMP},
</if>
<if test="makeDoctor != null and makeDoctor != ''">
make_doctor = #{makeDoctor,jdbcType=VARCHAR},
</if>
<if test="makeRemark != null and makeRemark != ''">
make_remark = #{makeRemark,jdbcType=VARCHAR},
</if>
<if test="hospitalId != null and hospitalId != ''">
hospital_id = #{hospitalId,jdbcType=VARCHAR},
</if>
<if test="hospitStatus != null and hospitStatus >= 0">
hospit_status = #{hospitStatus,jdbcType=INTEGER},
</if>
<if test="hospitDate != null">
hospit_date = #{hospitDate,jdbcType=TIMESTAMP},
</if>
<if test="hospitType != null">
hospit_type = #{hospitType,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<delete id="deletePatientMarkHospital" parameterType="java.lang.String">
delete from patient_mark_hospital where id = #{id,jdbcType=VARCHAR}
</delete>
<select id="getPatientMarkHospital" resultMap="PatientMarkHospitalResultMap" parameterType="java.lang.String">
select id,patient_id,pid,back_status,back_result,back_doctor,back_date,back_make_date,back_remark,back_failure,in_hospit_status,in_hospit_result,in_hospit_doctor,in_hospit_date,in_hospit_make_date,in_hospit_remark,in_hospit_failure,make_in_hospit_date,make_date,make_doctor,make_remark,hospital_id,hospit_status,hospit_date,hospit_type
from patient_mark_hospital where id = #{id,jdbcType=VARCHAR}
</select>
<sql id="orderAndLimit">
<if test="sort != null and sort != '' ">
order by ${sort}
<if test="need != null">
limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
</if>
</if>
</sql>
<sql id="PatientMarkHospitalCondition">
<where>
1 = 1
<if test="id != null and id != ''">
and id = #{id,jdbcType=VARCHAR}
</if>
<if test="patientId != null and patientId != ''">
and patient_id = #{patientId,jdbcType=VARCHAR}
</if>
<if test="patientIds!=null">
and patient_id in (
<foreach item="patientId" collection="patientIds" separator=",">
#{patientId}
</foreach>
)
</if>
<if test="pid != null and pid != ''">
and pid = #{pid,jdbcType=VARCHAR}
</if>
<if test="backStatus != null and backStatus >= 0">
and back_status = #{backStatus,jdbcType=INTEGER}
</if>
<if test="backResult != null and backResult >= 0">
and back_result = #{backResult,jdbcType=INTEGER}
</if>
<if test="backDoctor != null and backDoctor != ''">
and back_doctor = #{backDoctor,jdbcType=VARCHAR}
</if>
<if test="backDate != null">
and back_date = #{backDate,jdbcType=TIMESTAMP}
</if>
<if test="backStartDate != null">
AND
<![CDATA[
DATEDIFF(#{backStartDate},back_date)<=0
]]>
</if>
<if test="backEndDate != null">
AND
<![CDATA[
DATEDIFF(#{backEndDate},back_date)>=0
]]>
</if>
<if test="backMakeDate != null">
and back_make_date = #{backMakeDate,jdbcType=TIMESTAMP}
</if>
<if test="backRemark != null and backRemark != ''">
and back_remark = #{backRemark,jdbcType=VARCHAR}
</if>
<if test="backFailure != null and backFailure >= 0">
and back_failure = #{backFailure,jdbcType=INTEGER}
</if>
<if test="inHospitStatus != null and inHospitStatus >= 0">
and in_hospit_status = #{inHospitStatus,jdbcType=INTEGER}
</if>
<if test="inHospitResult != null and inHospitResult >= 0">
and in_hospit_result = #{inHospitResult,jdbcType=INTEGER}
</if>
<if test="inHospitDoctor != null and inHospitDoctor != ''">
and in_hospit_doctor = #{inHospitDoctor,jdbcType=VARCHAR}
</if>
<if test="inHospitDate != null">
and in_hospit_date = #{inHospitDate,jdbcType=TIMESTAMP}
</if>
<if test="inHospitStartDate != null">
AND
<![CDATA[
DATEDIFF(#{inHospitStartDate},in_hospit_date)<=0
]]>
</if>
<if test="inHospitEndDate != null">
AND
<![CDATA[
DATEDIFF(#{inHospitEndDate},in_hospit_date)>=0
]]>
</if>
<if test="inHospitMakeDate != null">
and in_hospit_make_date = #{inHospitMakeDate,jdbcType=TIMESTAMP}
</if>
<if test="inHospitRemark != null and inHospitRemark != ''">
and in_hospit_remark = #{inHospitRemark,jdbcType=VARCHAR}
</if>
<if test="inHospitFailure != null and inHospitFailure >= 0">
and in_hospit_failure = #{inHospitFailure,jdbcType=INTEGER}
</if>
<if test="makeInHospitDate != null">
and make_in_hospit_date = #{makeInHospitDate,jdbcType=TIMESTAMP}
</if>
<if test="makeDate != null">
and make_date = #{makeDate,jdbcType=TIMESTAMP}
</if>
<if test="makeStartDate != null">
AND
<![CDATA[
DATEDIFF(#{makeStartDate},make_date)<=0
]]>
</if>
<if test="makeEndDate != null">
AND
<![CDATA[
DATEDIFF(#{makeEndDate},make_date)>=0
]]>
</if>
<if test="makeDoctor != null and makeDoctor != ''">
and make_doctor = #{makeDoctor,jdbcType=VARCHAR}
</if>
<if test="makeRemark != null and makeRemark != ''">
and make_remark = #{makeRemark,jdbcType=VARCHAR}
</if>
<if test="hospitalId != null and hospitalId != ''">
and hospital_id = #{hospitalId,jdbcType=VARCHAR}
</if>
<if test="hospitStatus != null and hospitStatus >= 0">
and hospit_status = #{hospitStatus,jdbcType=INTEGER}
</if>
<if test="hospitDate != null">
and hospit_date = #{hospitDate,jdbcType=TIMESTAMP}
</if>
<if test="hospitStartDate != null">
AND
<![CDATA[
DATEDIFF(#{hospitStartDate},hospit_date)<=0
]]>
</if>
<if test="hospitEndDate != null">
AND
<![CDATA[
DATEDIFF(#{hospitEndDate},hospit_date)>=0
]]>
</if>
<if test="hospitType != null">
and hospit_type = #{hospitType,jdbcType=INTEGER}
</if>
<if test="sql != null">
${sql}
</if>
</where>
</sql>
<select id="reportPatMarkHospByMakeDoctor" resultType="com.lyms.platform.permission.model.ReportMakeHosptail"
parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">
select count(*) num,make_doctor as doctorId from patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
GROUP BY make_doctor;
</select>
<select id="reportPatMarkHospByBackDoctor" resultType="com.lyms.platform.permission.model.ReportMakeHosptail"
parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">
SELECT
back_doctor as doctorId,
count(*) AS num,
sum(
CASE back_result
WHEN 1 THEN
1
ELSE
0
END
) AS succNum,
sum(
CASE back_result
WHEN 2 THEN
1
ELSE
0
END
) AS errNum
FROM
patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
and back_doctor is not null
GROUP BY back_doctor;
</select>
<!--<select id="reportPatMarkHospByInDoctor" resultType="com.lyms.platform.permission.model.ReportMakeHosptail"-->
<!--parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">-->
<!--SELECT-->
<!--in_hospit_doctor as doctorId,-->
<!--count(*) AS num,-->
<!--sum(-->
<!--CASE in_hospit_result-->
<!--WHEN 1 THEN-->
<!--1-->
<!--ELSE-->
<!--0-->
<!--END-->
<!--) AS succNum,-->
<!--sum(-->
<!--CASE in_hospit_result-->
<!--WHEN 2 THEN-->
<!--1-->
<!--ELSE-->
<!--0-->
<!--END-->
<!--) AS errNum from-->
<!--patient_mark_hospital-->
<!--<include refid="PatientMarkHospitalCondition"/>-->
<!--and in_hospit_doctor is not null-->
<!--GROUP BY in_hospit_doctor;-->
<!--</select>-->
<select id="reportPatMarkHospByInDoctor" resultType="com.lyms.platform.permission.model.ReportMakeHosptail"
parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">
SELECT
in_hospit_doctor as doctorId,
count(*) AS num,
sum(
CASE in_hospit_result
WHEN 1 THEN
1
ELSE
0
END
) AS succNum,
sum(
CASE in_hospit_result
WHEN 2 THEN
1
ELSE
0
END
) AS errNum from
patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
and in_hospit_doctor is not null
GROUP BY in_hospit_doctor;
</select>
<select id="reportRealityByInDoctor" resultType="com.lyms.platform.permission.model.ReportMakeHosptail"
parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">
SELECT
in_hospit_doctor AS doctorId,
count(*) num,
sum(
CASE hospit_status
WHEN 2 THEN
1
ELSE
0
END
) AS succNum
FROM
patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
and in_hospit_result = 1
GROUP BY
in_hospit_doctor;
</select>
<select id="reportFailure" resultType="com.lyms.platform.permission.model.ReportFailureHosptail"
parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">
SELECT
'回院提醒' as type,
count(*) num,
sum(
CASE back_failure
WHEN 1 and back_result = 2 THEN
1
ELSE
0
END
) AS noPhoneNum,
sum(
CASE back_failure
WHEN 2 and back_result = 2 THEN
1
ELSE
0
END
) AS otherHospNum,
sum(
CASE back_failure
WHEN 3 and back_result = 2 THEN
1
ELSE
0
END
) AS indeterNum,
sum(
CASE back_failure
WHEN 4 and back_result = 2 THEN
1
ELSE
0
END
) AS otherNum
FROM
patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
and back_status = 2
UNION
SELECT
'住院提醒' as type,
count(*) num,
sum(
CASE in_hospit_failure
WHEN 1 and in_hospit_result = 2 THEN
1
ELSE
0
END
) AS 电话无人接听,
sum(
CASE in_hospit_failure
WHEN 2 and in_hospit_result = 2 THEN
1
ELSE
0
END
) AS 他院已办理住院,
sum(
CASE in_hospit_failure
WHEN 3 and in_hospit_result = 2 THEN
1
ELSE
0
END
) AS 暂时未确定,
sum(
CASE in_hospit_failure
WHEN 4 and in_hospit_result = 2 THEN
1
ELSE
0
END
) AS 其他
FROM
patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
and in_hospit_status = 2
</select>
<select id="queryPatientMarkHospital" resultMap="PatientMarkHospitalResultMap"
parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">
select
id,patient_id,pid,back_status,back_result,back_doctor,back_date,back_make_date,back_remark,back_failure,in_hospit_status,in_hospit_result,in_hospit_doctor,in_hospit_date,in_hospit_make_date,in_hospit_remark,in_hospit_failure,make_in_hospit_date,make_date,make_doctor,make_remark,hospital_id,hospit_status,hospit_date,hospit_type
from patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
<include refid="orderAndLimit"/>
</select>
<select id="queryPatientMarkHospitalCount" resultType="int"
parameterType="com.lyms.platform.permission.model.PatientMarkHospitalQuery">
select count(1) from patient_mark_hospital
<include refid="PatientMarkHospitalCondition"/>
</select>
</mapper>