diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java index ecb0d9090..a3cc93add 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java @@ -55,26 +55,99 @@ public interface OrderMapper { * * @param orderId 医嘱主键 * @param status 目标状态,建议使用常量 {@link #ORDER_STATUS_CANCELLED}、{@link #ORDER_STATUS_PAID} 等 - * @param operator 操作人姓名 + * @param operator 操作人用户名 + * @return 受影响的行数 */ - @Update("UPDATE his_order SET status = #{status}, updated_by = #{operator}, updated_time = NOW() " + + @Update("UPDATE his_order " + + "SET status = #{status}, updated_by = #{operator}, updated_at = now() " + "WHERE id = #{orderId}") int updateOrderStatus(@Param("orderId") Long orderId, @Param("status") String status, @Param("operator") String operator); /** - * 根据医嘱 ID 查询医嘱明细,包括诊疗目录配置的总量单位(total_quantity_unit)。 - * 该方法专门用于门诊医生站‑医嘱录入后展示总量单位,防止出现 null。 - * 修复 Bug #561:通过 LEFT JOIN 显式关联诊疗目录表,映射 usage_unit 为 total_quantity_unit。 + * 门诊诊前退号后,将医嘱状态更新为 PRD 定义的 “CANCELLED”。 + * + * @param orderId 医嘱主键 + * @param status 传入 {@link #ORDER_STATUS_CANCELLED} + * @param operator 操作人 + * @return 受影响的行数 + */ + @Update("UPDATE his_order " + + "SET status = #{status}, updated_by = #{operator}, updated_at = now() " + + "WHERE id = #{orderId}") + int updateOrderStatusToCancelled(@Param("orderId") Long orderId, + @Param("status") String status, + @Param("operator") String operator); + + /** + * 支付成功后,将医嘱状态更新为 PRD 定义的 “PAID”。 + * + * @param orderId 医嘱主键 + * @param status 传入 {@link #ORDER_STATUS_PAID} + * @param operator 操作人 + * @return 受影响的行数 + */ + @Update("UPDATE his_order " + + "SET status = #{status}, updated_by = #{operator}, updated_at = now() " + + "WHERE id = #{orderId}") + int updateOrderStatusToPaid(@Param("orderId") Long orderId, + @Param("status") String status, + @Param("operator") String operator); + + /** + * 退回状态更新(保留原有实现供其他业务使用)。 + * + * @param orderId 医嘱主键 + * @param status 传入 {@link #ORDER_STATUS_RETURNED} + * @param operator 操作人 + * @return 受影响的行数 + */ + @Update("UPDATE his_order " + + "SET status = #{status}, updated_by = #{operator}, updated_at = now() " + + "WHERE id = #{orderId}") + int updateOrderStatusToReturned(@Param("orderId") Long orderId, + @Param("status") String status, + @Param("operator") String operator); + + /** + * 查询医嘱明细并返回配置的总量单位(用于前端展示)。 * * @param orderId 医嘱主键 - * @return 包含医嘱明细及 total_quantity_unit 的 Map,若不存在返回 null + * @return 包含单位字段的明细信息 */ - @Select("SELECT o.id, o.patient_id, o.item_id, o.total_quantity, o.status, " + - "c.usage_unit AS total_quantity_unit " + - "FROM his_order o " + - "LEFT JOIN his_treatment_catalog c ON o.item_id = c.id " + - "WHERE o.id = #{orderId}") - Map selectOrderDetailWithUnit(@Param("orderId") Long orderId); + @Select("SELECT od.*, dc.unit_name " + + "FROM his_order_detail od " + + "LEFT JOIN his_drug_catalog dc ON od.drug_id = dc.id " + + "WHERE od.order_id = #{orderId}") + List> selectOrderDetailWithUnit(@Param("orderId") Long orderId); + + /** + * 将对应排班号状态更新为已取号(状态码 3)。 + * + * @param scheduleSlotId 排班号主键 + * @return 受影响的行数 + */ + @Update("UPDATE adm_schedule_slot SET status = 3, updated_at = now() WHERE id = #{scheduleSlotId}") + int updateScheduleSlotStatusToFinished(@Param("scheduleSlotId") Long scheduleSlotId); + + /** + * 分页查询待写病历的医嘱(仅返回前端需要的字段)。 + * + * @param doctorId 医生主键 + * @param offset 分页起始位置 + * @param limit 每页记录数 + * @return 医嘱列表 + */ + @Select("") + List> selectPendingMedicalRecords(@Param("doctorId") Long doctorId, + @Param("offset") int offset, + @Param("limit") int limit); }