Files
his/openhis-server-new/openhis-application/src/main/resources/mapper/clinicalmanage/SurgicalScheduleAppMapper.xml

205 lines
9.0 KiB
XML

<?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.openhis.web.clinicalmanage.mapper.SurgicalScheduleAppMapper">
<!-- 分页查询手术安排-->
<select id="getSurgerySchedulePage" resultType="com.openhis.web.clinicalmanage.dto.OpScheduleDto">
SELECT
os.schedule_id,
os.tenant_id,
st.tenant_name AS orgName,
os.apply_id,
os.patient_id,
os.visit_id,
os.oper_code,
os.oper_name,
os.surgery_nature,
os.anes_method,
os.schedule_date,
os.sequence_no,
os.room_code,
os.table_no,
su.nick_name AS createByName,
os.create_time,
os.update_time,
ap.name AS patient_name,
CASE ap.gender_enum WHEN 0 THEN '男' WHEN 1 THEN '女' ELSE '未知' END AS gender,
EXTRACT(YEAR FROM AGE(ap.birth_date)) AS age,
cs.apply_dept_id,
cs.apply_dept_name,
cs.org_id,
o.name AS org_name,
cs.main_surgeon_name AS surgeon_name,
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifierNo
FROM op_schedule os
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
LEFT JOIN cli_surgery cs ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
LEFT JOIN adm_organization o ON cs.org_id = o.id
LEFT JOIN sys_tenant st ON st.id = os.tenant_id
LEFT JOIN sys_user su ON su.user_id = os.creator_id
LEFT JOIN (
SELECT patient_id, identifier_no
FROM (
SELECT patient_id, identifier_no,
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
FROM adm_patient_identifier
WHERE delete_flag = '0'
AND identifier_no IS NOT NULL
AND identifier_no != ''
) t
WHERE rn = 1
) pi ON os.patient_id = pi.patient_id
<where>
<if test="dto.tenantId != null">
AND os.tenant_id = #{dto.tenantId}
</if>
<if test="dto.patientName != null and dto.patientName != ''">
AND ap.name LIKE CONCAT('%', #{dto.patientName}, '%')
</if>
<if test="dto.applyDeptId != null and dto.applyDeptId != ''">
AND cs.apply_dept_id = #{dto.applyDeptId}
</if>
<if test="dto.scheduleDateStart != null">
AND DATE(os.schedule_date) &gt;= #{dto.scheduleDateStart}
</if>
<if test="dto.scheduleDateEnd != null">
AND DATE(os.schedule_date) &lt;= #{dto.scheduleDateEnd}
</if>
<if test="dto.operCode != null and dto.operCode != ''">
AND os.oper_code LIKE CONCAT('%', #{dto.operCode}, '%')
</if>
AND os.delete_flag = '0'
</where>
ORDER BY os.create_time DESC
</select>
<!-- 根据ID查询手术安排详情-->
<select id="getSurgeryScheduleDetail" resultType="com.openhis.web.clinicalmanage.dto.OpScheduleDto">
SELECT
os.*,
os.oper_code AS surgeryNo,
ap.name AS patient_name,
CASE ap.gender_enum WHEN 0 THEN '男' WHEN 1 THEN '女' ELSE '未知' END AS gender,
EXTRACT(YEAR FROM AGE(ap.birth_date)) AS age,
cs.apply_dept_id,
cs.apply_dept_name,
cs.org_id,
o.name AS org_name,
cs.main_surgeon_name AS surgeon_name,
cs.apply_doctor_name AS apply_doctor_name,
drf.create_time AS apply_time,
os.surgery_nature AS surgeryType,
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifierNo
FROM op_schedule os
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
LEFT JOIN cli_surgery cs ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
LEFT JOIN adm_organization o ON cs.org_id = o.id
LEFT JOIN doc_request_form drf ON drf.prescription_no=cs.surgery_no
LEFT JOIN (
SELECT patient_id, identifier_no
FROM (
SELECT patient_id, identifier_no,
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
FROM adm_patient_identifier
WHERE delete_flag = '0'
AND identifier_no IS NOT NULL
AND identifier_no != ''
) t
WHERE rn = 1
) pi ON os.patient_id = pi.patient_id
WHERE os.schedule_id = #{scheduleId}
LIMIT 1
</select>
<!-- 新增手术安排-->
<insert id="addSurgerySchedule" useGeneratedKeys="true" keyProperty="scheduleId">
insert into op_schedule(patient_id, doctor_id, schedule_time, schedule_status, create_time, update_time)
values(#{patientId}, #{doctorId}, #{scheduleTime}, #{scheduleStatus}, #{createTime}, #{updateTime})
</insert>
<!-- 修改手术安排-->
<update id="updateSurgerySchedule">
update op_schedule set patient_id = #{patientId}, doctor_id = #{doctorId}, schedule_time = #{scheduleTime},
schedule_status = #{scheduleStatus}, create_time = #{createTime}, update_time = #{updateTime}
where schedule_id = #{scheduleId}
</update>
<!-- 查询所有符合条件的手术安排列表(用于导出) -->
<select id="getSurgeryScheduleList" resultType="com.openhis.web.clinicalmanage.dto.OpScheduleDto">
SELECT
os.schedule_id,
os.tenant_id,
st.tenant_name AS orgName,
os.apply_id,
os.patient_id,
os.visit_id,
os.oper_code,
os.oper_name,
os.surgery_nature,
os.anes_method,
os.schedule_date,
os.sequence_no,
os.room_code,
os.table_no,
su.nick_name AS createByName,
os.create_time,
os.update_time,
ap.name AS patient_name,
CASE ap.gender_enum WHEN 0 THEN '男' WHEN 1 THEN '女' ELSE '未知' END AS gender,
EXTRACT(YEAR FROM AGE(ap.birth_date)) AS age,
cs.apply_dept_id,
cs.apply_dept_name,
cs.org_id,
o.name AS org_name,
cs.main_surgeon_name AS surgeon_name,
COALESCE(pi.identifier_no, ap.bus_no, '') AS identifierNo
FROM op_schedule os
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
LEFT JOIN cli_surgery cs ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
LEFT JOIN adm_organization o ON cs.org_id = o.id
LEFT JOIN sys_tenant st ON st.id = os.tenant_id
LEFT JOIN sys_user su ON su.user_id = os.creator_id
LEFT JOIN (
SELECT patient_id, identifier_no
FROM (
SELECT patient_id, identifier_no,
ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY create_time ASC) AS rn
FROM adm_patient_identifier
WHERE delete_flag = '0'
AND identifier_no IS NOT NULL
AND identifier_no != ''
) t
WHERE rn = 1
) pi ON os.patient_id = pi.patient_id
<where>
AND os.delete_flag = '0'
<if test="dto.patientId != null"> AND os.patient_id = #{dto.patientId}</if>
<if test="dto.visitId != null"> AND os.visit_id = #{dto.visitId}</if>
<if test="dto.applyId != null"> AND os.apply_id = #{dto.applyId}</if>
<if test="dto.operCode != null and dto.operCode != ''"> AND os.oper_code = #{dto.operCode}</if>
<if test="dto.operName != null and dto.operName != ''"> AND os.oper_name LIKE CONCAT('%', #{dto.operName}, '%')</if>
<if test="dto.scheduleDateStart != null"> AND DATE(os.schedule_date) &gt;= #{dto.scheduleDateStart}</if>
<if test="dto.scheduleDateEnd != null"> AND DATE(os.schedule_date) &lt;= #{dto.scheduleDateEnd}</if>
<if test="dto.orgId != null and dto.orgId != ''"> AND cs.org_id = #{dto.orgId}</if>
<if test="dto.applyDeptId != null and dto.applyDeptId != ''"> AND cs.apply_dept_id = #{dto.applyDeptId}</if>
<if test="dto.patientName != null and dto.patientName != ''"> AND ap.name LIKE CONCAT('%', #{dto.patientName}, '%')</if>
</where>
ORDER BY os.create_time DESC
</select>
<!-- 查询时间段内该手术室是否被占用-->
<select id="isScheduleConflict" resultType="java.lang.Boolean">
SELECT COUNT(*) > 0 FROM op_schedule
WHERE room_code = #{surgeryRoomId}
AND entry_time &lt;= #{endTime}
AND end_time >= #{startTime}
AND delete_flag = '0'
</select>
<!-- 检查是否存在重复的手术安排 -->
<select id="existsDuplicateSchedule" resultType="java.lang.Boolean">
SELECT COUNT(*) > 0 FROM op_schedule
WHERE patient_id = #{patientId}
AND oper_code = #{operCode}
AND oper_name = #{operName}
AND delete_flag = '0'
</select>
</mapper>