Files
his/openhis-server-new/openhis-domain/src/main/resources/mapper/clinical/OrderMapper.xml
wangjian963 d6fb0afd2b 506 门诊挂号:门诊诊前退号后,数据库多表状态值变更与 PRD 定义不符
CommonConstants.AppointmentOrderStatus 常量 → OrderStatus 枚举重构
   新增枚举:0=患者取消 / 1=有效 / 2=系统取消 / 3=已完成
   退号流程加乐观锁防并发,slot 状态改回待约,退号日志独立事务 修复 XML 中 Integer 比较用字符串的问题
Bug #411 — 诊室过滤栏从科室下拉框改为诊室按钮组
2026-05-12 23:35:03 +08:00

309 lines
14 KiB
XML
Executable File

<?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.clinical.mapper.OrderMapper">
<resultMap type="com.openhis.clinical.domain.Order" id="OrderResult">
<id property="id" column="id"/>
<result property="orderNo" column="order_no"/>
<result property="patientId" column="patient_id"/>
<result property="patientName" column="patient_name"/>
<result property="medicalCard" column="medical_card"/>
<result property="phone" column="phone"/>
<result property="gender" column="gender"/>
<result property="scheduleId" column="schedule_id"/>
<result property="slotId" column="slot_id"/>
<result property="departmentId" column="department_id"/>
<result property="departmentName" column="department_name"/>
<result property="doctorId" column="doctor_id"/>
<result property="doctorName" column="doctor_name"/>
<result property="regType" column="reg_type"/>
<result property="fee" column="fee"/>
<result property="appointmentDate" column="appointment_date"/>
<result property="appointmentTime" column="appointment_time"/>
<result property="cancelTime" column="cancel_time"/>
<result property="cancelReason" column="cancel_reason"/>
<result property="status" column="status"/>
<result property="payStatus" column="pay_status"/>
<result property="version" column="version"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="selectOrderList" resultMap="OrderResult">
select * from order_main
<where>
<if test="orderNo != null and orderNo != ''">
and order_no = #{orderNo}
</if>
<if test="patientId != null">
and patient_id = #{patientId}
</if>
<if test="patientName != null and patientName != ''">
and patient_name like #{patientName}
</if>
<if test="medicalCard != null and medicalCard != ''">
and medical_card = #{medicalCard}
</if>
<if test="phone != null and phone != ''">
and phone = #{phone}
</if>
<if test="scheduleId != null">
and schedule_id = #{scheduleId}
</if>
<if test="slotId != null">
and slot_id = #{slotId}
</if>
<if test="departmentId != null">
and department_id = #{departmentId}
</if>
<if test="doctorId != null">
and doctor_id = #{doctorId}
</if>
<if test="status != null">
and status = #{status}
</if>
<if test="payStatus != null">
and pay_status = #{payStatus}
</if>
<if test="appointmentDate != null">
and appointment_date = #{appointmentDate}
</if>
</where>
</select>
<select id="selectOrderPage" resultMap="OrderResult">
select * from order_main
<where>
<if test="order.orderNo != null and order.orderNo != ''">
and order_no = #{order.orderNo}
</if>
<if test="order.patientId != null">
and patient_id = #{order.patientId}
</if>
<if test="order.patientName != null and order.patientName != ''">
and patient_name like #{order.patientName}
</if>
<if test="order.medicalCard != null and order.medicalCard != ''">
and medical_card = #{order.medicalCard}
</if>
<if test="order.phone != null and order.phone != ''">
and phone = #{order.phone}
</if>
<if test="order.scheduleId != null">
and schedule_id = #{order.scheduleId}
</if>
<if test="order.slotId != null">
and slot_id = #{order.slotId}
</if>
<if test="order.departmentId != null">
and department_id = #{order.departmentId}
</if>
<if test="order.doctorId != null">
and doctor_id = #{order.doctorId}
</if>
<if test="order.status != null">
and status = #{order.status}
</if>
<if test="order.payStatus != null">
and pay_status = #{order.payStatus}
</if>
<if test="order.appointmentDate != null">
and appointment_date = #{order.appointmentDate}
</if>
</where>
</select>
<!-- status=1: 只查有效订单(0=患者取消 1=有效 2=系统取消 3=已完成) -->
<select id="selectOrderById" resultMap="OrderResult">
select * from order_main where id = #{id}
and status = 1
order by create_time desc
</select>
<!-- status=1: 只查有效订单 -->
<select id="selectOrderBySlotId" resultMap="OrderResult">
select * from order_main where slot_id = #{slotId} and status = 1
</select>
<insert id="insertOrder" parameterType="com.openhis.clinical.domain.Order" useGeneratedKeys="true" keyProperty="id">
insert into order_main
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="orderNo != null and orderNo != ''">order_no,</if>
<if test="patientId != null">patient_id,</if>
<if test="patientName != null and patientName != ''">patient_name,</if>
<if test="medicalCard != null and medicalCard != ''">medical_card,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="gender != null">gender,</if>
<if test="scheduleId != null">schedule_id,</if>
<if test="slotId != null">slot_id,</if>
<if test="departmentId != null">department_id,</if>
<if test="departmentName != null and departmentName != ''">department_name,</if>
<if test="doctorId != null">doctor_id,</if>
<if test="doctorName != null and doctorName != ''">doctor_name,</if>
<if test="regType != null and regType != ''">reg_type,</if>
<if test="fee != null">fee,</if>
<if test="appointmentDate != null">appointment_date,</if>
<if test="appointmentTime != null">appointment_time,</if>
<if test="cancelTime != null">cancel_time,</if>
<if test="cancelReason != null and cancelReason != ''">cancel_reason,</if>
<if test="status != null">status,</if>
<if test="payStatus != null">pay_status,</if>
<if test="version != null">version,</if>
<if test="tenantId != null">tenant_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderNo != null and orderNo != ''">#{orderNo},</if>
<if test="patientId != null">#{patientId},</if>
<if test="patientName != null and patientName != ''">#{patientName},</if>
<if test="medicalCard != null and medicalCard != ''">#{medicalCard},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="gender != null">#{gender},</if>
<if test="scheduleId != null">#{scheduleId},</if>
<if test="slotId != null">#{slotId},</if>
<if test="departmentId != null">#{departmentId},</if>
<if test="departmentName != null and departmentName != ''">#{departmentName},</if>
<if test="doctorId != null">#{doctorId},</if>
<if test="doctorName != null and doctorName != ''">#{doctorName},</if>
<if test="regType != null and regType != ''">#{regType},</if>
<if test="fee != null">#{fee},</if>
<if test="appointmentDate != null">#{appointmentDate},</if>
<if test="appointmentTime != null">#{appointmentTime},</if>
<if test="cancelTime != null">#{cancelTime},</if>
<if test="cancelReason != null and cancelReason != ''">#{cancelReason},</if>
<if test="status != null">#{status},</if>
<if test="payStatus != null">#{payStatus},</if>
<if test="version != null">#{version},</if>
<if test="tenantId != null">#{tenantId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateOrder" parameterType="com.openhis.clinical.domain.Order">
update order_main
<trim prefix="set" suffixOverrides=",">
<if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
<if test="patientId != null">patient_id = #{patientId},</if>
<if test="patientName != null and patientName != ''">patient_name = #{patientName},</if>
<if test="medicalCard != null and medicalCard != ''">medical_card = #{medicalCard},</if>
<if test="phone != null and phone != ''">phone = #{phone},</if>
<if test="gender != null">gender = #{gender},</if>
<if test="scheduleId != null">schedule_id = #{scheduleId},</if>
<if test="slotId != null">slot_id = #{slotId},</if>
<if test="departmentId != null">department_id = #{departmentId},</if>
<if test="departmentName != null and departmentName != ''">department_name = #{departmentName},</if>
<if test="doctorId != null">doctor_id = #{doctorId},</if>
<if test="doctorName != null and doctorName != ''">doctor_name = #{doctorName},</if>
<if test="regType != null and regType != ''">reg_type = #{regType},</if>
<if test="fee != null">fee = #{fee},</if>
<if test="appointmentDate != null">appointment_date = #{appointmentDate},</if>
<if test="appointmentTime != null">appointment_time = #{appointmentTime},</if>
<if test="cancelTime != null">cancel_time = #{cancelTime},</if>
<if test="cancelReason != null and cancelReason != ''">cancel_reason = #{cancelReason},</if>
<if test="status != null">status = #{status},</if>
<if test="payStatus != null">pay_status = #{payStatus},</if>
<if test="version != null">version = #{version},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<select id="countPatientDeptOrdersInPeriod" resultType="int">
select count(*)
from order_main
<where>
and patient_id = #{patientId}
<choose>
<when test="departmentId != null">
and department_id = #{departmentId}
</when>
<when test="departmentName != null and departmentName != ''">
and trim(department_name) = trim(#{departmentName})
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
and appointment_time &gt;= #{startTime}
and appointment_time &lt; #{endTime}
<if test="statuses != null and statuses.size() &gt; 0">
and status in
<foreach item="s" collection="statuses" open="(" separator="," close=")">
#{s}
</foreach>
</if>
</where>
</select>
<update id="updateOrderStatusById">
update order_main set status = #{status} where id = #{id}
</update>
<!-- status=0: 患者取消 (OrderStatus.PATIENT_CANCELLED) -->
<update id="updateOrderCancelInfoById">
update order_main set status = 0, cancel_time = #{cancelTime}, cancel_reason = #{cancelReason} where id = #{id}
</update>
<update id="updatePayStatus">
update order_main
set pay_status = #{payStatus}, pay_time = #{payTime}, update_time = NOW()
where id = #{orderId}
</update>
<delete id="deleteOrderById">
delete from order_main where id = #{id}
</delete>
<delete id="deleteOrderByIds">
delete from order_main where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="countOrders" resultType="int">
select count(*) from order_main
<where>
<if test="params.orderNo != null and params.orderNo != ''">
and order_no = #{params.orderNo}
</if>
<if test="params.patientId != null">
and patient_id = #{params.patientId}
</if>
<if test="params.scheduleId != null">
and schedule_id = #{params.scheduleId}
</if>
<if test="params.slotId != null">
and slot_id = #{params.slotId}
</if>
<if test="params.departmentId != null">
and department_id = #{params.departmentId}
</if>
<if test="params.doctorId != null">
and doctor_id = #{params.doctorId}
</if>
<if test="params.status != null">
and status = #{params.status}
</if>
<if test="params.payStatus != null">
and pay_status = #{params.payStatus}
</if>
<if test="params.appointmentDate != null">
and appointment_date = #{params.appointmentDate}
</if>
</where>
</select>
</mapper>