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

147 lines
6.5 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
FROM op_schedule os
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
LEFT JOIN cli_surgery cs ON os.patient_id = cs.patient_id
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
<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.scheduleDate != null">
AND os.schedule_date = #{dto.scheduleDate}
</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
FROM op_schedule os
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
LEFT JOIN cli_surgery cs ON os.patient_id = cs.patient_id
LEFT JOIN adm_organization o ON cs.org_id = o.id
LEFT JOIN doc_request_form drf ON drf.prescription_no=cs.surgery_no
WHERE os.schedule_id = #{scheduleId}
</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
FROM op_schedule os
LEFT JOIN adm_patient ap ON os.patient_id = ap.id
LEFT JOIN cli_surgery cs ON os.patient_id = cs.patient_id
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
<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.scheduleDate != null"> AND os.schedule_date = #{dto.scheduleDate}</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 >= #{startTime}
AND end_time &lt; #{endTime}
</select>
</mapper>