|
@@ -20,66 +20,107 @@
|
|
|
</resultMap>
|
|
</resultMap>
|
|
|
<select id="selectPatientList" resultMap="PatientAndClinicResult">
|
|
<select id="selectPatientList" resultMap="PatientAndClinicResult">
|
|
|
SELECT
|
|
SELECT
|
|
|
- count(1) as count_result,
|
|
|
|
|
|
|
+ tmp2.c as count_result,
|
|
|
bp.id AS patient_id,
|
|
bp.id AS patient_id,
|
|
|
bp.patient_code,
|
|
bp.patient_code,
|
|
|
bp.current_clinic_id,
|
|
bp.current_clinic_id,
|
|
|
- bcr.patient_name,
|
|
|
|
|
- bcr.patient_age,
|
|
|
|
|
- bcr.patient_gender,
|
|
|
|
|
- bcr.image_url,
|
|
|
|
|
|
|
+ tmp1.patient_name,
|
|
|
|
|
+ tmp1.patient_age,
|
|
|
|
|
+ tmp1.patient_gender,
|
|
|
|
|
+ tmp1.clinic_start_time,
|
|
|
|
|
+ tmp1.id as current_clinic_id,
|
|
|
|
|
+ tmp1.image_url,
|
|
|
bp.create_time,
|
|
bp.create_time,
|
|
|
bp.update_time,
|
|
bp.update_time,
|
|
|
bp.create_by,
|
|
bp.create_by,
|
|
|
bp.update_by
|
|
bp.update_by
|
|
|
FROM
|
|
FROM
|
|
|
biz_patient bp
|
|
biz_patient bp
|
|
|
- JOIN biz_clinic_room bcr ON bp.ID = bcr.patient_id
|
|
|
|
|
- JOIN biz_clinic_room_doctor_user bcrmu ON bcr.ID = bcrmu.clinic_room_id
|
|
|
|
|
|
|
+ JOIN (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ bcr1.*
|
|
|
|
|
+ FROM
|
|
|
|
|
+ biz_clinic_room bcr1
|
|
|
|
|
+ JOIN
|
|
|
|
|
+ biz_clinic_room_doctor_user bcrmu
|
|
|
|
|
+ ON bcr1.ID = bcrmu.clinic_room_id
|
|
|
|
|
+ <!-- 子查询:获取每个patient_id的最大clinic_start_time-->
|
|
|
|
|
+ JOIN (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ bcr_sub.patient_id,
|
|
|
|
|
+ MAX(bcr_sub.clinic_start_time) AS max_clinic_time
|
|
|
|
|
+ FROM
|
|
|
|
|
+ biz_clinic_room bcr_sub
|
|
|
|
|
+ JOIN
|
|
|
|
|
+ biz_clinic_room_doctor_user bcrmu_sub
|
|
|
|
|
+ ON bcr_sub.ID = bcrmu_sub.clinic_room_id
|
|
|
|
|
+ <where>
|
|
|
|
|
+ <if test="query.currentUserId != null and query.currentUserId != ''">
|
|
|
|
|
+ AND bcrmu_sub.user_id = #{query.currentUserId,jdbcType=VARCHAR}
|
|
|
|
|
+ </if>
|
|
|
|
|
+ </where>
|
|
|
|
|
+ GROUP BY
|
|
|
|
|
+ bcr_sub.patient_id
|
|
|
|
|
+ ) AS sub
|
|
|
|
|
+ ON
|
|
|
|
|
+ bcr1.patient_id = sub.patient_id
|
|
|
|
|
+ AND bcr1.clinic_start_time = sub.max_clinic_time
|
|
|
<where>
|
|
<where>
|
|
|
- and bcr.deleted = 0
|
|
|
|
|
- and bp.deleted = 0
|
|
|
|
|
|
|
+ <if test="query.currentUserId != null and query.currentUserId != ''">
|
|
|
|
|
+ AND bcrmu.user_id = #{query.currentUserId,jdbcType=VARCHAR}
|
|
|
|
|
+ </if>
|
|
|
|
|
+ </where>
|
|
|
|
|
+ ) AS tmp1
|
|
|
|
|
+ ON
|
|
|
|
|
+ tmp1.patient_id = bp.id
|
|
|
|
|
+ LEFT JOIN (
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ bcr1.patient_id AS patient_id,
|
|
|
|
|
+ count(1) AS c
|
|
|
|
|
+ FROM
|
|
|
|
|
+ biz_clinic_room bcr1
|
|
|
|
|
+ JOIN
|
|
|
|
|
+ biz_clinic_room_doctor_user bcrmu
|
|
|
|
|
+ ON bcr1.ID = bcrmu.clinic_room_id
|
|
|
|
|
+ <where>
|
|
|
|
|
+ <if test="query.currentUserId != null and query.currentUserId != ''">
|
|
|
|
|
+ AND bcrmu.user_id = #{query.currentUserId,jdbcType=VARCHAR}
|
|
|
|
|
+ </if>
|
|
|
|
|
+ </where>
|
|
|
|
|
+ GROUP BY
|
|
|
|
|
+ bcr1.patient_id
|
|
|
|
|
+ ) AS tmp2
|
|
|
|
|
+ ON
|
|
|
|
|
+ tmp2.patient_id = bp.id
|
|
|
|
|
+ <where>
|
|
|
|
|
+ and bcr.deleted = 0 and bp.deleted = 0 and tmp2.c >0
|
|
|
<if test="query.queryCondition != null and query.queryCondition != ''">
|
|
<if test="query.queryCondition != null and query.queryCondition != ''">
|
|
|
and (
|
|
and (
|
|
|
bp.patient_code LIKE concat('%',#{query.queryCondition,jdbcType=VARCHAR},'%')
|
|
bp.patient_code LIKE concat('%',#{query.queryCondition,jdbcType=VARCHAR},'%')
|
|
|
- or bcr.patient_name like concat('%',#{query.queryCondition,jdbcType=VARCHAR},'%')
|
|
|
|
|
|
|
+ or tmp1.patient_name like concat('%',#{query.queryCondition,jdbcType=VARCHAR},'%')
|
|
|
)
|
|
)
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.ageRange != null and query.ageRange.size() > 0">
|
|
<if test="query.ageRange != null and query.ageRange.size() > 0">
|
|
|
- AND bcr.patient_age >= #{query.ageRange[0]}
|
|
|
|
|
|
|
+ AND tmp1.patient_age >= #{query.ageRange[0]}
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.ageRange != null and query.ageRange.size() > 1">
|
|
<if test="query.ageRange != null and query.ageRange.size() > 1">
|
|
|
- AND bcr.patient_age <= #{query.ageRange[1]}
|
|
|
|
|
|
|
+ AND tmp1.patient_age <= #{query.ageRange[1]}
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.gender != null and query.gender != ''">
|
|
<if test="query.gender != null and query.gender != ''">
|
|
|
- AND bcr.patient_gender = #{query.gender,jdbcType=VARCHAR}
|
|
|
|
|
|
|
+ AND tmp1.patient_gender = #{query.gender,jdbcType=VARCHAR}
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.deptId != null and query.deptId != ''">
|
|
<if test="query.deptId != null and query.deptId != ''">
|
|
|
- AND bcr.dept_id = #{query.deptId,jdbcType=VARCHAR}
|
|
|
|
|
- </if>
|
|
|
|
|
- <if test="query.currentUserId != null and query.currentUserId != ''">
|
|
|
|
|
- AND bcrmu.user_id = #{query.currentUserId,jdbcType=VARCHAR}
|
|
|
|
|
|
|
+ AND tmp1.dept_id = #{query.deptId,jdbcType=VARCHAR}
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.queryTime != null and query.queryTime.size() > 0">
|
|
<if test="query.queryTime != null and query.queryTime.size() > 0">
|
|
|
- AND clinic_start_time >= #{query.queryTime[0]}
|
|
|
|
|
|
|
+ AND tmp1.clinic_start_time >= #{query.queryTime[0]}
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.queryTime != null and query.queryTime.size() > 1">
|
|
<if test="query.queryTime != null and query.queryTime.size() > 1">
|
|
|
- AND clinic_start_time <= #{query.queryTime[1]}
|
|
|
|
|
|
|
+ AND tmp1.clinic_start_time <= #{query.queryTime[1]}
|
|
|
</if>
|
|
</if>
|
|
|
</where>
|
|
</where>
|
|
|
- GROUP BY
|
|
|
|
|
- bp.id,
|
|
|
|
|
- bp.patient_code,
|
|
|
|
|
- bp.current_clinic_id,
|
|
|
|
|
- bcr.patient_name,
|
|
|
|
|
- bcr.patient_age,
|
|
|
|
|
- bcr.patient_gender,
|
|
|
|
|
- bp.create_time,
|
|
|
|
|
- bp.update_time,
|
|
|
|
|
- bp.create_by,
|
|
|
|
|
- bp.update_by,
|
|
|
|
|
- bcr.image_url
|
|
|
|
|
</select>
|
|
</select>
|
|
|
|
|
+
|
|
|
<select id="selectPatientByConditionList" resultType="cn.tr.module.smart.web.vo.WebBizPatientVO">
|
|
<select id="selectPatientByConditionList" resultType="cn.tr.module.smart.web.vo.WebBizPatientVO">
|
|
|
SELECT
|
|
SELECT
|
|
|
bp.id,
|
|
bp.id,
|
|
@@ -117,7 +158,7 @@
|
|
|
and bcrmu.user_id = #{query.userId,jdbcType=VARCHAR}
|
|
and bcrmu.user_id = #{query.userId,jdbcType=VARCHAR}
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.bindDevice != null and query.bindDevice == true">
|
|
<if test="query.bindDevice != null and query.bindDevice == true">
|
|
|
- and bic.device_id is not null
|
|
|
|
|
|
|
+ and bic.device_id is not null
|
|
|
</if>
|
|
</if>
|
|
|
<if test="query.bindDevice != null and query.bindDevice == false">
|
|
<if test="query.bindDevice != null and query.bindDevice == false">
|
|
|
and bic.device_id is null
|
|
and bic.device_id is null
|