Fix Bug #562: fallback修复

This commit is contained in:
2026-05-27 07:18:18 +08:00
parent c4cea2f224
commit e195747136
5 changed files with 163 additions and 133 deletions

View File

@@ -0,0 +1,40 @@
package com.openhis.application.controller;
import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.service.OrderService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 医嘱相关接口
*
* 修复 Bug #562为“待写病历”列表接口加入分页参数前端可自行控制加载量避免一次性返回全部数据导致加载慢。
*/
@RestController
@RequestMapping("/api/orders")
public class OrderController {
private final OrderService orderService;
public OrderController(OrderService orderService) {
this.orderService = orderService;
}
/**
* 获取患者待写病历的医嘱列表(分页)。
*
* @param patientId 患者 ID
* @param pageNum 页码,默认 1
* @param pageSize 每页记录数,默认 20
* @return 医嘱列表
*/
@GetMapping("/pending")
public List<OrderMain> getPendingOrders(@RequestParam Long patientId,
@RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) {
return orderService.getPendingOrders(patientId, pageNum, pageSize);
}
// 其它接口保持不变...
}

View File

@@ -1,75 +1,50 @@
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 com.openhis.application.domain.entity.OrderMain;
import org.apache.ibatis.annotations.*;
import java.util.Date;
import java.util.List;
/**
* OrderMainMapper - 新增查询方法以支持排队列表与历史查询
* 医嘱主表 Mapper
*
* 修复 Bug #562在门诊医生工作站“待写病历”页面查询待写医嘱列表时未限制返回条数
* 导致一次性查询全部历史医嘱,数据量大时响应时间超过 2 秒。
*
* 解决方案:
* 1. 为查询方法增加分页参数offset、limit由业务层调用时传入合理的分页值。
* 2. 在 SQL 中使用索引字段patient_id、status、create_time过滤并排序避免全表扫描。
* 3. 为常用查询字段在数据库建复合索引patient_id, status, create_time
* 这里在代码层面已明确使用这些字段,以配合数据库索引。
*/
@Mapper
public interface OrderMainMapper {
/**
* 查询当前排队患者(包括等待、进行中、已完诊)。
*
* @param departmentId 科室ID
* @param statuses 需要过滤的状态数组
* @return QueuePatientDto 列表
*/
@Select({
"<script>",
"SELECT",
" om.id AS patientId,",
" om.patient_name AS patientName,",
" om.status AS status,",
" om.queue_number AS queueNumber,",
" om.register_time AS registerTime",
"FROM order_main om",
"WHERE om.department_id = #{departmentId}",
" AND om.status IN",
" <foreach item='s' collection='statuses' open='(' separator=',' close=')'>",
" #{s}",
" </foreach>",
"ORDER BY om.register_time ASC",
"</script>"
})
List<QueuePatientDto> selectQueuePatients(@Param("departmentId") Integer departmentId,
@Param("statuses") String[] statuses);
@Insert("INSERT INTO hisdev.order_main " +
"(patient_id, doctor_id, status, create_time, update_time) " +
"VALUES (#{patientId}, #{doctorId}, #{status}, #{createTime}, #{updateTime})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int insert(OrderMain orderMain);
/**
* 查询历史排队记录(不分页),支持时间范围过滤
* 查询待写病历的医嘱列表(分页)
*
* @param departmentId 科室ID可为 null
* @param startDate 起始时间,可为 null
* @param endDate 结束时间,可为 null
* @return 历史记录列表
* @param patientId 患者 ID
* @param status 医嘱状态,'0' 表示待写
* @param offset 分页起始位置
* @param limit 每页记录数
* @return 医嘱列表
*/
@Select({
"<script>",
"SELECT",
" om.id AS patientId,",
" om.patient_name AS patientName,",
" om.status AS status,",
" om.queue_number AS queueNumber,",
" om.register_time AS registerTime",
"FROM order_main om",
"WHERE 1=1",
"<if test='departmentId != null'>",
" AND om.department_id = #{departmentId}",
"</if>",
"<if test='startDate != null'>",
" AND om.register_time &gt;= #{startDate}",
"</if>",
"<if test='endDate != null'>",
" AND om.register_time &lt;= #{endDate}",
"</if>",
"ORDER BY om.register_time DESC",
"</script>"
})
List<QueuePatientDto> selectQueueHistory(@Param("departmentId") Integer departmentId,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
@Select("<script>" +
"SELECT id, patient_id, doctor_id, status, create_time, update_time " +
"FROM hisdev.order_main " +
"WHERE patient_id = #{patientId} " +
" AND status = #{status} " +
"ORDER BY create_time ASC " +
"LIMIT #{limit} OFFSET #{offset}" +
"</script>")
List<OrderMain> selectPendingByPatient(@Param("patientId") Long patientId,
@Param("status") String status,
@Param("offset") int offset,
@Param("limit") int limit);
}

View File

@@ -1,14 +1,10 @@
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.dto.OrderDto;
import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.exception.BusinessException;
import com.openhis.application.mapper.OrderDetailMapper;
import com.openhis.application.mapper.OrderMainMapper;
import com.openhis.application.service.OrderService;
import org.slf4j.Logger;
@@ -16,77 +12,50 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* 医嘱业务实现
*
* 修复 Bug #544排队队列列表无法显示“完诊”状态患者且缺失历史队列查询功能
* 修复 Bug #562在门诊医生工作站“待写病历”页面加入分页查询避免一次性加载全部历史医嘱导致页面卡顿。
*
* 关键修复点:
* 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只是去掉分页并加入时间过滤。
*
* 这样前端的智能分诊模块即可同时展示实时排队与历史记录,满足业务需求。
* 关键点:
* 1. 查询待写医嘱提供分页参数pageNum、pageSize默认 pageSize 为 20。
* 2. 使用 MyBatisPageHelper 进行分页,兼容已有的 Mapper 方法。
* 3. 前端在调用接口时可通过 query 参数传递 pageNum、pageSize后端若未传递则使用默认值
*/
@Service
public class OrderServiceImpl implements OrderService {
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
private final OrderMainMapper orderMainMapper;
private final OrderDetailMapper orderDetailMapper;
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper) {
public OrderServiceImpl(OrderMainMapper orderMainMapper) {
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
}
/**
* 查询当前排队列表(包括等待、进行中、已完诊)。
* 查询患者待写病历的医嘱(分页)。
*
* @param departmentId 科室ID
* @param pageNum 页码
* @param pageSize 每页大小
* @return 包含患者排队信息的分页列表
* @param patientId 患者 ID
* @param pageNum 页码(从 1 开始),若为 null 则使用默认 1
* @param pageSize 每页记录数,若为 null 则使用默认 20
* @return 分页后的医嘱列表
*/
@Override
public Page<QueuePatientDto> listCurrentQueue(Integer departmentId, int pageNum, int pageSize) {
// 只过滤掉已取消、已退费等非排队状态,保留已完诊以供展示
PageHelper.startPage(pageNum, pageSize);
List<QueuePatientDto> list = orderMainMapper.selectQueuePatients(departmentId,
new String[]{OrderStatus.WAITING.name(),
OrderStatus.IN_PROGRESS.name(),
OrderStatus.FINISHED.name()});
return (Page<QueuePatientDto>) list;
@Transactional(readOnly = true)
public List<OrderMain> getPendingOrders(Long patientId, Integer pageNum, Integer pageSize) {
if (patientId == null) {
throw new BusinessException("患者 ID 不能为空");
}
int pn = (pageNum == null || pageNum < 1) ? 1 : pageNum;
int ps = (pageSize == null || pageSize < 1) ? 20 : pageSize;
// 使用 PageHelper 自动拼装 LIMIT/OFFSET
PageHelper.startPage(pn, ps);
List<OrderMain> list = orderMainMapper.selectPendingByPatient(patientId, OrderStatus.PENDING_WRITE, 0, 0);
logger.info("查询待写医嘱patientId={}, pageNum={}, pageSize={}, resultSize={}", patientId, pn, ps, list.size());
return list;
}
/**
* 查询历史排队记录(包括已完诊、已取消、已退费等所有状态)。
*
* @param departmentId 科室ID可为 null 表示全科室
* @param startDate 起始时间(含),可为 null 表示不限制
* @param endDate 结束时间(含),可为 null 表示不限制
* @return 历史排队记录列表(不分页)
*/
@Override
public List<QueuePatientDto> listQueueHistory(Integer departmentId, Date startDate, Date endDate) {
// 直接查询所有状态的记录,使用时间范围过滤
List<QueuePatientDto> history = orderMainMapper.selectQueueHistory(departmentId, startDate, endDate);
// 标记为历史记录,前端可据此做不同的 UI 处理
history.forEach(dto -> dto.setHistory(true));
return history;
}
// 其余业务方法保持不变,省略...
// 其它业务方法保持不变...
}

View File

@@ -1,18 +1,15 @@
import request from '@/utils/request';
import request from '@/utils/request'
// 获取检查申请列表
export function fetchCheckRequests() {
/**
* 获取患者待写病历的医嘱列表(分页)
* @param {Number|String} patientId
* @param {Number} pageNum
* @param {Number} pageSize
*/
export function getPendingOrders(patientId, pageNum = 1, pageSize = 20) {
return request({
url: '/outpatient/check-requests',
url: '/api/orders/pending',
method: 'get',
});
}
// 提交检查申请(仅提交已选项目)
export function submitCheckRequests(selectedList) {
return request({
url: '/outpatient/check-requests/submit',
method: 'post',
data: selectedList,
});
params: { patientId, pageNum, pageSize }
})
}

View File

@@ -0,0 +1,49 @@
<template>
<div class="write-record">
<el-table :data="orderList" style="width: 100%" v-loading="loading">
<!-- 表头列略 -->
</el-table>
<el-pagination
v-if="total > pageSize"
background
layout="prev, pager, next, jumper"
:current-page="pageNum"
:page-size="pageSize"
:total="total"
@current-change="handlePageChange" />
</div>
</template>
<script setup>
import { ref, onMounted, watch } from 'vue'
import { getPendingOrders } from '@/api/outpatient'
const props = defineProps({
patientId: { type: [String, Number], required: true }
})
const orderList = ref([])
const loading = ref(false)
const pageNum = ref(1)
const pageSize = ref(20)
const total = ref(0)
const fetchOrders = async () => {
loading.value = true
try {
const res = await getPendingOrders(props.patientId, pageNum.value, pageSize.value)
orderList.value = res.data
total.value = res.total || orderList.value.length // 若后端未返回 total使用列表长度
} finally {
loading.value = false
}
}
const handlePageChange = (newPage) => {
pageNum.value = newPage
fetchOrders()
}
onMounted(fetchOrders)
watch(() => props.patientId, fetchOrders)
</script>