Fix Bug #480: [住院护士站-医嘱执行] 非耗材类医嘱执行报"耗材库存"错误且全选逻辑联动异常

根因分析:
1. lotNumberMatch 调用传入了所有在科患者的 encounterId(来自 patientInfoList),
   而非仅选中医嘱对应的 encounterId。若其他患者存在 PREPARATION 状态的耗材发放记录
   但无匹配库存,API 返回"发耗材单生成失败,请检查耗材库存"错误
2. handleExecute 缺少 .catch() 处理器,API 调用失败时 UI 状态不一致,
   导致列表刷新后全选联动异常

修复策略:
- lotNumberMatch 仅传入选中医嘱对应的 encounterId(去重过滤),避免无关患者耗材记录干扰
- 新增空选择校验,未选中医嘱时提示用户而非直接调接口
- 为 handleExecute 添加 .catch() 处理器,API 失败时给出友好提示
- lotNumberMatch 增加 .then() 检查返回码,确保 error 被正确捕获

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
关羽
2026-05-14 11:30:57 +08:00
parent 46e972a799
commit 4084f2ffa8

View File

@@ -459,10 +459,15 @@ function handleGetPrescription(skipAutoSelectAll = false) {
// 执行
function handleExecute() {
let list = getSelectRows();
if (list.length === 0) {
proxy.$modal.msgWarning('请选择需要执行的医嘱');
return;
}
let encounterIds = patientInfoList.value.map((i) => i.encounterId).join(',');
list = list.map((item) => {
return {
requestId: item.requestId,
encounterId: item.encounterId,
accountId: item.accountId,
adviceTable: item.adviceTable,
executeTimes: item.executeTimes,
@@ -473,14 +478,23 @@ function handleExecute() {
if (res.code == 200) {
// 仅当选中医嘱中包含诊疗类医嘱(可能绑定耗材)时,才调用耗材批号匹配
// adviceTable 取值为 med_medication_request药品或 wor_service_request诊疗/耗材)
// 原代码用 includes('device') 判断有误,两个表名均不含 "device" 字符串
const hasServiceRequest = list.some((item) =>
String(item.adviceTable || '') === 'wor_service_request',
);
if (hasServiceRequest) {
lotNumberMatch({ encounterIdList: encounterIds }, { skipErrorMsg: true }).catch((error) => {
console.warn('lotNumberMatch failed after adviceExecute:', error);
});
// 仅传入选中医嘱对应的 encounterId避免其他患者的耗材记录干扰
const selectedEncounterIds = [...new Set(list.map((item) => item.encounterId).filter(Boolean))];
if (selectedEncounterIds.length > 0) {
lotNumberMatch({ encounterIdList: selectedEncounterIds }, { skipErrorMsg: true })
.then((matchRes) => {
if (matchRes && matchRes.code !== 200) {
console.warn('lotNumberMatch returned error:', matchRes.msg);
}
})
.catch((error) => {
console.warn('lotNumberMatch failed after adviceExecute:', error);
});
}
}
// 刷新列表(不自动全选,保持用户操作前的选择状态)
handleGetPrescription(true);
@@ -488,6 +502,9 @@ function handleExecute() {
} else {
proxy.$modal.msgError(res.msg || '医嘱执行失败');
}
}).catch((error) => {
console.error('医嘱执行接口调用失败:', error);
proxy.$modal.msgError('医嘱执行失败,请稍后重试');
});
}