72 lines
3.0 KiB
Java
72 lines
3.0 KiB
Java
package com.openhis.application.mapper;
|
||
|
||
import com.openhis.application.domain.entity.OrderMain;
|
||
import org.apache.ibatis.annotations.*;
|
||
|
||
import java.util.List;
|
||
|
||
/**
|
||
* 医嘱主表 Mapper
|
||
*
|
||
* 修复 Bug #562:在门诊医生工作站“待写病历”页面,查询待写医嘱列表时未限制返回条数,
|
||
* 导致一次性查询全部历史医嘱,数据量大时响应时间超过 2 秒。
|
||
*
|
||
* 解决方案:
|
||
* 1. 为查询方法增加分页参数(offset、limit),由业务层调用时传入合理的分页值。
|
||
* 2. 在 SQL 中使用索引字段(patient_id、status、create_time)过滤并排序,避免全表扫描。
|
||
* 3. 为常用查询字段在数据库建复合索引(patient_id, status, create_time),
|
||
* 这里在代码层面已明确使用这些字段,以配合数据库索引。
|
||
*
|
||
* 新增:查询任意状态(包括“完诊”)的排队队列列表以及历史查询功能。
|
||
*/
|
||
@Mapper
|
||
public interface OrderMainMapper {
|
||
|
||
@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 patientId 患者 ID
|
||
* @param status 医嘱状态,'0' 表示待写
|
||
* @param offset 分页起始位置
|
||
* @param limit 每页记录数
|
||
* @return 医嘱列表
|
||
*/
|
||
@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);
|
||
|
||
/**
|
||
* 新增:查询指定患者的排队队列(包括所有状态),支持分页。
|
||
*
|
||
* @param patientId 患者 ID
|
||
* @param offset 分页起始位置
|
||
* @param limit 每页记录数
|
||
* @return 医嘱列表(按创建时间升序)
|
||
*/
|
||
@Select("<script>" +
|
||
"SELECT id, patient_id, doctor_id, status, create_time, update_time " +
|
||
"FROM hisdev.order_main " +
|
||
"WHERE patient_id = #{patientId} " +
|
||
"ORDER BY create_time ASC " +
|
||
"LIMIT #{limit} OFFSET #{offset}" +
|
||
"</script>")
|
||
List<OrderMain> selectQueueByPatient(@Param("patientId") Long patientId,
|
||
@Param("offset") int offset,
|
||
@Param("limit") int limit);
|
||
}
|