Files
his/MD/bugs/BUG_763_ANALYSIS.md

91 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Bug #763 诸葛亮分析报告
> **文档类型**: Bug分析
> **分析时间**: 2026-06-12 16:18:00
> **分析模型**: mimo-v2.5 (LLM深度分析)
---
## 基本信息
- **Bug #**: 763
- **标题**: [住院护士站-医嘱校对]医生工作站已签发的临时医嘱在护士站“医嘱校对”中无法查询
- **模块**: 病区护士工作站
- **提出人**: 陈显精
---
This confirms `effectiveDoseEnd` is only set in outpatient prescriptions, NOT in inpatient order signing. Now I have the complete root cause.
---
### 一、Bug 理解
护士在"医嘱校对"界面选择患者并点击查询时,医生已签发的临时医嘱(药品类,如注射用头孢)无法显示,列表为空。期望行为:已签发的临时医嘱应出现在"未校对"列表中,供护士校对。
### 二、根因分析
**根因Bug #665 修复引入的 `deadline` 过滤条件未处理 `NULL` 值。**
完整数据链路追踪:
1. **医生签发临时医嘱**`AdviceManageAppServiceImpl.handMedication()``tempMedicationRequest.setStatusEnum(ACTIVE=2)` → 调用 `saveOrUpdate()` → 写入 `med_medication_request`
2. **关键遗漏**`effectiveDoseEnd`(服药结束时间)在整个签发流程中**从未被设置**`setEffectiveDoseEnd` 仅在门诊处方 `DoctorStationElepPrescriptionServiceImpl` 中调用,住院医嘱路径不涉及),因此数据库中 `effective_dose_end = NULL`
3. **护士站查询** → 前端 `prescriptionList.vue` 默认发送 `deadline = "2026-06-12 23:59:59"` → 后端 `AdviceProcessAppServiceImpl.getInpatientAdvicePage()` 拼接条件:
```java
queryWrapper.le("end_time", deadlineTime); // Bug #665 引入
```
生成 SQL`end_time <= '2026-06-12 23:59:59'`
4. **NULL 比较失败**PostgreSQL 中 `NULL <= anything` 结果为 `NULL`(等价于 `FALSE`WHERE 子句排除该行 → 查询结果为空
**涉及文件:**
- `AdviceProcessAppServiceImpl.java`(第 235-243 行)— deadline 条件拼接
- `AdviceProcessAppMapper.xml` — UNION 查询,`T1.effective_dose_end AS end_time`
### 三、修复方案
**修改文件**`healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/inhospitalnursestation/appservice/impl/AdviceProcessAppServiceImpl.java`
**修改内容**:将 deadline 过滤条件从 `le` 改为 NULL 安全的写法:
```java
// 修改前Bug #665 代码):
if (deadline != null && !deadline.isEmpty()) {
try {
LocalDateTime deadlineTime = LocalDateTime.parse(deadline,
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
queryWrapper.le("end_time", deadlineTime);
} catch (DateTimeParseException e) {
// 忽略无效的日期格式
}
}
// 修改后:
if (deadline != null && !deadline.isEmpty()) {
try {
LocalDateTime deadlineTime = LocalDateTime.parse(deadline,
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
queryWrapper.and(w -> w.le("end_time", deadlineTime).or().isNull("end_time"));
} catch (DateTimeParseException e) {
// 忽略无效的日期格式
}
}
```
**原理**`end_time <= deadline OR end_time IS NULL`,确保 `effective_dose_end` 为 NULL 的新签发医嘱也能被查询到。
**验证**
1. `mvn clean compile -DskipTests` → 编译通过
2. 签发临时医嘱 → 护士站查询 → 应能查到
3. 长期医嘱、有截止时间的医嘱 → deadline 筛选仍然生效
### 四、路由决策
**FIXER**: guanyu
**REASON**: 修复范围仅涉及后端 Java Service 层一处 SQL 条件修改,属于纯后端逻辑修复,由后端开发关羽执行。
---
## 路由决策
- **修复 Agent**: guanyu
- **原因**: LLM 分析决策