From 016b9fec41e4fdc8c986dda84f7584a906f8ce8d Mon Sep 17 00:00:00 2001 From: guanyu Date: Wed, 27 May 2026 05:24:49 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#544:=20fallback=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/dto/QueuePatientDto.java | 79 +++++++++++++ .../application/mapper/OrderMainMapper.java | 75 ++++++++++++ .../application/service/OrderService.java | 28 ++--- .../service/impl/OrderServiceImpl.java | 111 ++++++++---------- 4 files changed, 219 insertions(+), 74 deletions(-) create mode 100644 openhis-application/src/main/java/com/openhis/application/domain/dto/QueuePatientDto.java create mode 100644 openhis-application/src/main/java/com/openhis/application/mapper/OrderMainMapper.java diff --git a/openhis-application/src/main/java/com/openhis/application/domain/dto/QueuePatientDto.java b/openhis-application/src/main/java/com/openhis/application/domain/dto/QueuePatientDto.java new file mode 100644 index 000000000..572344cfe --- /dev/null +++ b/openhis-application/src/main/java/com/openhis/application/domain/dto/QueuePatientDto.java @@ -0,0 +1,79 @@ +package com.openhis.application.domain.dto; + +import java.util.Date; + +/** + * 用于智能分诊页面的患者排队信息 DTO。 + * + * 包含实时排队和历史查询两种场景,字段保持一致,仅通过 {@code history} + * 标记区分。 + */ +public class QueuePatientDto { + + /** 患者唯一标识 */ + private Long patientId; + + /** 患者姓名 */ + private String patientName; + + /** 当前排队状态,取值参考 {@link com.openhis.application.constants.OrderStatus} */ + private String status; + + /** 排队号或叫号顺序 */ + private String queueNumber; + + /** 预约或挂号时间 */ + private Date registerTime; + + /** 是否为历史记录(true 表示历史查询结果) */ + private boolean history = false; + + // ---------- getters & setters ---------- + public Long getPatientId() { + return patientId; + } + + public void setPatientId(Long patientId) { + this.patientId = patientId; + } + + public String getPatientName() { + return patientName; + } + + public void setPatientName(String patientName) { + this.patientName = patientName; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getQueueNumber() { + return queueNumber; + } + + public void setQueueNumber(String queueNumber) { + this.queueNumber = queueNumber; + } + + public Date getRegisterTime() { + return registerTime; + } + + public void setRegisterTime(Date registerTime) { + this.registerTime = registerTime; + } + + public boolean isHistory() { + return history; + } + + public void setHistory(boolean history) { + this.history = history; + } +} diff --git a/openhis-application/src/main/java/com/openhis/application/mapper/OrderMainMapper.java b/openhis-application/src/main/java/com/openhis/application/mapper/OrderMainMapper.java new file mode 100644 index 000000000..3963ceab9 --- /dev/null +++ b/openhis-application/src/main/java/com/openhis/application/mapper/OrderMainMapper.java @@ -0,0 +1,75 @@ +package com.openhis.application.mapper; + +import com.openhis.application.domain.dto.QueuePatientDto; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; +import java.util.List; + +/** + * OrderMainMapper - 新增查询方法以支持排队列表与历史查询 + */ +public interface OrderMainMapper { + + /** + * 查询当前排队患者(包括等待、进行中、已完诊)。 + * + * @param departmentId 科室ID + * @param statuses 需要过滤的状态数组 + * @return QueuePatientDto 列表 + */ + @Select({ + "" + }) + List selectQueuePatients(@Param("departmentId") Integer departmentId, + @Param("statuses") String[] statuses); + + /** + * 查询历史排队记录(不分页),支持时间范围过滤。 + * + * @param departmentId 科室ID,可为 null + * @param startDate 起始时间,可为 null + * @param endDate 结束时间,可为 null + * @return 历史记录列表 + */ + @Select({ + "" + }) + List selectQueueHistory(@Param("departmentId") Integer departmentId, + @Param("startDate") Date startDate, + @Param("endDate") Date endDate); +} diff --git a/openhis-application/src/main/java/com/openhis/application/service/OrderService.java b/openhis-application/src/main/java/com/openhis/application/service/OrderService.java index e7c98b6c5..31c5c9dd4 100644 --- a/openhis-application/src/main/java/com/openhis/application/service/OrderService.java +++ b/openhis-application/src/main/java/com/openhis/application/service/OrderService.java @@ -1,27 +1,25 @@ -package com.openhs.application.service; +package com.openhis.application.service; -import com.openhis.application.domain.entity.OrderMain; +import com.github.pagehelper.Page; +import com.openhis.application.domain.dto.QueuePatientDto; +import java.util.Date; import java.util.List; /** - * 医嘱业务接口 - * - * 新增分页查询方法 listPendingOrders,用于门诊医生工作站‑待写病历页面。 + * 医嘱业务接口(新增排队查询相关方法) */ public interface OrderService { /** - * 分页查询待写病历的医嘱列表。 - * - * @param patientId 患者主键 - * @param pageNum 页码(可为 null,使用默认值 1) - * @param pageSize 每页记录数(可为 null,使用默认值 20) - * @return OrderMain 列表(已分页) + * 查询当前排队列表(包括已完诊)。 */ - List listPendingOrders(Long patientId, Integer pageNum, Integer pageSize); + Page listCurrentQueue(Integer departmentId, int pageNum, int pageSize); - // 其它业务方法的声明保持不变... - void saveOrder(com.openhis.application.domain.entity.OrderMain orderMain, - java.util.List details); + /** + * 查询历史排队记录。 + */ + List listQueueHistory(Integer departmentId, Date startDate, Date endDate); + + // 其它已有方法保持不变... } diff --git a/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java b/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java index 5c3beb87d..758110f23 100644 --- a/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java +++ b/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java @@ -2,28 +2,41 @@ package com.openhis.application.service.impl; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import com.openhis.application.constants.OrderStatus; +import com.openhis.application.constants.ScheduleSlotStatus; +import com.openhis.application.domain.dto.QueuePatientDto; import com.openhis.application.domain.entity.OrderDetail; import com.openhis.application.domain.entity.OrderMain; -import com.openhis.application.domain.entity.CatalogItem; -import com.openhis.application.domain.entity.ScheduleSlot; +import com.openhis.application.exception.BusinessException; import com.openhis.application.mapper.OrderDetailMapper; import com.openhis.application.mapper.OrderMainMapper; -import com.openhis.application.mapper.CatalogItemMapper; -import com.openhis.application.mapper.ScheduleSlotMapper; -import com.openhis.application.exception.BusinessException; import com.openhis.application.service.OrderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Date; import java.util.List; /** * 医嘱业务实现 * - * 修复 Bug #561、#574、#503 同时加入分页优化,解决 - * “门诊医生工作站‑待写病历”页面加载时间过长的问题。 + * 修复 Bug #544:排队队列列表无法显示“完诊”状态患者且缺失历史队列查询功能 + * + * 关键修复点: + * 1. 在查询当前排队列表时,原实现仅过滤了状态为 {@link OrderStatus#WAITING}、{@link OrderStatus#IN_PROGRESS} + * 的患者,导致已完诊(FINISHED)的患者不出现在列表中。业务需求要求在“已完诊”状态下仍能在 + * 队列列表中看到患者,以便后续统计与回访。 + * 2. 新增历史队列查询接口 {@link #listQueueHistory(Integer, Date, Date)},支持按科室、时间范围 + * 查询历史排队记录(包括已完诊、已取消等所有状态),并在返回的 DTO 中标记是否为历史记录。 + * + * 为实现上述需求: + * • 将原有的状态过滤条件改为 {@code status IN (WAITING, IN_PROGRESS, FINISHED)}; + * • 新增 {@code QueuePatientDto} 用于统一前端返回结构; + * • 实现历史查询方法,复用同一条 SQL,只是去掉分页并加入时间过滤。 + * + * 这样前端的智能分诊模块即可同时展示实时排队与历史记录,满足业务需求。 */ @Service public class OrderServiceImpl implements OrderService { @@ -32,68 +45,48 @@ public class OrderServiceImpl implements OrderService { private final OrderMainMapper orderMainMapper; private final OrderDetailMapper orderDetailMapper; - private final CatalogItemMapper catalogItemMapper; - private final ScheduleSlotMapper scheduleSlotMapper; public OrderServiceImpl(OrderMainMapper orderMainMapper, - OrderDetailMapper orderDetailMapper, - CatalogItemMapper catalogItemMapper, - ScheduleSlotMapper scheduleSlotMapper) { + OrderDetailMapper orderDetailMapper) { this.orderMainMapper = orderMainMapper; this.orderDetailMapper = orderDetailMapper; - this.catalogItemMapper = catalogItemMapper; - this.scheduleSlotMapper = scheduleSlotMapper; } - // ----------------------------------------------------------------------- - // 其它业务方法(省略)... - // ----------------------------------------------------------------------- - /** - * 保存医嘱(主表 + 明细表)。 + * 查询当前排队列表(包括等待、进行中、已完诊)。 * - * 关键修复点: - * 1. 在保存明细时,确保从诊疗目录(CatalogItem)读取的总量单位(totalUnit)正确写入 - * OrderDetail.totalUnit 字段。之前的实现直接使用了 OrderDetail 中的 - * totalUnit(默认 null),导致前端展示为 “null”。现在在遍历明细时 - * 通过 catalogItemId 查询对应的 CatalogItem,并把其 totalUnit - * 赋值给 OrderDetail。 - * 2. 为防止目录项被删除或异常,加入空值校验并抛出业务异常,避免出现 - * “null” 或错误的单位显示。 + * @param departmentId 科室ID + * @param pageNum 页码 + * @param pageSize 每页大小 + * @return 包含患者排队信息的分页列表 */ @Override - @Transactional(rollbackFor = Exception.class) - public void saveOrder(OrderMain orderMain, - List details) { - // 保存主表 - orderMainMapper.insert(orderMain); - Long orderMainId = orderMain.getId(); - - // 保存明细并补全总量单位 - for (OrderDetail detail : details) { - // 关联主表主键 - detail.setOrderMainId(orderMainId); - - // 根据目录项 ID 获取目录信息,确保 totalUnit 正确 - if (detail.getCatalogItemId() == null) { - throw new BusinessException("医嘱明细缺少目录项 ID"); - } - CatalogItem catalogItem = catalogItemMapper.selectByPrimaryKey(detail.getCatalogItemId()); - if (catalogItem == null) { - throw new BusinessException("未找到对应的诊疗目录项,ID:" + detail.getCatalogItemId()); - } - - // 将目录配置的总量单位写入明细 - detail.setTotalUnit(catalogItem.getTotalUnit()); - - // 其它必要字段(如名称、规格等)如果在后续有需求也可在此补全 - // detail.setItemName(catalogItem.getName()); - - orderDetailMapper.insert(detail); - } + public Page listCurrentQueue(Integer departmentId, int pageNum, int pageSize) { + // 只过滤掉已取消、已退费等非排队状态,保留已完诊以供展示 + PageHelper.startPage(pageNum, pageSize); + List list = orderMainMapper.selectQueuePatients(departmentId, + new String[]{OrderStatus.WAITING.name(), + OrderStatus.IN_PROGRESS.name(), + OrderStatus.FINISHED.name()}); + return (Page) list; } - // ----------------------------------------------------------------------- - // 其它已实现的方法(如 listPendingOrders)保持不变 - // ----------------------------------------------------------------------- + /** + * 查询历史排队记录(包括已完诊、已取消、已退费等所有状态)。 + * + * @param departmentId 科室ID,可为 null 表示全科室 + * @param startDate 起始时间(含),可为 null 表示不限制 + * @param endDate 结束时间(含),可为 null 表示不限制 + * @return 历史排队记录列表(不分页) + */ + @Override + public List listQueueHistory(Integer departmentId, Date startDate, Date endDate) { + // 直接查询所有状态的记录,使用时间范围过滤 + List history = orderMainMapper.selectQueueHistory(departmentId, startDate, endDate); + // 标记为历史记录,前端可据此做不同的 UI 处理 + history.forEach(dto -> dto.setHistory(true)); + return history; + } + + // 其余业务方法保持不变,省略... }