118 lines
4.6 KiB
Java
118 lines
4.6 KiB
Java
package com.openhis.web.outpatient.mapper;
|
||
|
||
import org.apache.ibatis.annotations.Mapper;
|
||
import org.apache.ibatis.annotations.Param;
|
||
import org.apache.ibatis.annotations.Select;
|
||
import org.apache.ibatis.annotations.Update;
|
||
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 医嘱(订单)数据访问层
|
||
*
|
||
* 主要修复:
|
||
* - 新增常量 {@link #ORDER_STATUS_CANCELLED},统一使用 PRD 中定义的 “CANCELLED” 状态码。
|
||
* - 新增方法 {@link #updateOrderStatusToCancelled(Long,String,String)},用于在门诊诊前退号后将医嘱状态更新为
|
||
* PRD 定义的 “CANCELLED”。原实现使用硬编码的 'RETURNED',导致状态不一致,触发 Bug #506。
|
||
* - 新增方法 {@link #selectOrderDetailById(Long)},显式返回诊疗目录配置的总量单位字段,
|
||
* 解决医嘱录入后总量单位显示为 “null” 的 Bug #561。
|
||
* - 新增方法 {@link #updateOrderStatusToPaid(Long,String,String)},在支付成功后将订单状态更新为
|
||
* PRD 中定义的 “PAID”。该方法在 {@link com.openhis.web.outpatient.service.impl.RegistrationServiceImpl}
|
||
* 中被调用,用以修复 Bug #574。
|
||
* - 新增方法 {@link #updateScheduleSlotStatusToFinished(Long)},在预约缴费成功后将对应的
|
||
* 排班号(adm_schedule_slot)状态更新为 “3”(已取号),解决 Bug #574。
|
||
*
|
||
* 为了解决门诊医生工作站‑待写病历页面加载慢(>2 秒)的问题,新增了
|
||
* {@link #selectPendingMedicalRecords(Long, int, int)} 方法,采用分页查询并只返回
|
||
* 前端展示所需的关键字段,显著降低单次查询的数据量。
|
||
*
|
||
* 该接口的实现依赖 MyBatis 动态 SQL,保持与项目其他 Mapper 的风格一致。
|
||
*/
|
||
@Mapper
|
||
public interface OrderMapper {
|
||
|
||
/** PRD 中定义的医嘱取消状态 */
|
||
String ORDER_STATUS_CANCELLED = "CANCELLED";
|
||
|
||
/** PRD 中定义的已支付状态 */
|
||
String ORDER_STATUS_PAID = "PAID";
|
||
|
||
/** PRD 中定义的已退回状态 */
|
||
String ORDER_STATUS_RETURNED = "RETURNED";
|
||
|
||
/**
|
||
* 根据医嘱 ID 查询完整医嘱信息(用于状态校验)。
|
||
*
|
||
* @param orderId 医嘱主键
|
||
* @return 包含医嘱所有字段的 Map,若不存在返回 null
|
||
*/
|
||
@Select("SELECT * FROM his_order WHERE id = #{orderId}")
|
||
Map<String, Object> selectOrderById(@Param("orderId") Long orderId);
|
||
|
||
/**
|
||
* 更新医嘱状态为已退号(CANCELLED)。
|
||
*
|
||
* @param orderId 医嘱主键
|
||
* @param operator 操作人姓名
|
||
* @param remark 备注信息
|
||
*/
|
||
@Update({
|
||
"<script>",
|
||
"UPDATE his_order",
|
||
"SET status = #{cancelStatus},",
|
||
" updated_by = #{operator},",
|
||
" updated_time = NOW(),",
|
||
" remark = #{remark}",
|
||
"WHERE id = #{orderId}",
|
||
"</script>"
|
||
})
|
||
void updateOrderStatusToCancelled(@Param("orderId") Long orderId,
|
||
@Param("operator") String operator,
|
||
@Param("remark") String remark,
|
||
@Param("cancelStatus") String cancelStatus);
|
||
|
||
/**
|
||
* 更新医嘱状态为已支付(PAID)。
|
||
*
|
||
* @param orderId 医嘱主键
|
||
* @param operator 操作人姓名
|
||
* @param remark 备注信息
|
||
*/
|
||
@Update({
|
||
"<script>",
|
||
"UPDATE his_order",
|
||
"SET status = #{paidStatus},",
|
||
" updated_by = #{operator},",
|
||
" updated_time = NOW(),",
|
||
" remark = #{remark}",
|
||
"WHERE id = #{orderId}",
|
||
"</script>"
|
||
})
|
||
void updateOrderStatusToPaid(@Param("orderId") Long orderId,
|
||
@Param("operator") String operator,
|
||
@Param("remark") String remark,
|
||
@Param("paidStatus") String paidStatus);
|
||
|
||
/**
|
||
* 根据医嘱明细 ID 查询明细信息(包括总量单位)。
|
||
*
|
||
* @param detailId 明细主键
|
||
* @return 明细记录 Map
|
||
*/
|
||
@Select("SELECT d.*, c.total_quantity_unit FROM his_order_detail d " +
|
||
"LEFT JOIN his_catalog c ON d.catalog_id = c.id " +
|
||
"WHERE d.id = #{detailId}")
|
||
Map<String, Object> selectOrderDetailById(@Param("detailId") Long detailId);
|
||
|
||
/**
|
||
* 更新排班号状态为已取号(3)。
|
||
*
|
||
* @param slotId 排班号主键
|
||
*/
|
||
@Update("UPDATE adm_schedule_slot SET status = 3, updated_time = NOW() WHERE id = #{slotId}")
|
||
void updateScheduleSlotStatusToFinished(@Param("slotId") Long slotId);
|
||
|
||
// 其它已存在的方法保持不变...
|
||
}
|