Fix Bug #547: 根因+修复方案摘要

This commit is contained in:
2026-05-19 00:02:19 +08:00
parent b89f41048b
commit 69bb887d19

View File

@@ -1854,6 +1854,21 @@ function handleTemporaryMedicalRefresh() {
function handleQuoteBilling() {
// 重新拉取计费药品数据
if (temporaryPatientInfo.value.visitId) {
// 🔧 修复 Bug #445: 在清空之前提取已提交项目的复合匹配键
// 原因:后续的 ID 匹配过滤依赖 temporaryAdvices但 temporaryAdvices 会被先清空
// 新医嘱没有 requestId/chargeItemId需用名称+规格+数量的复合键匹配
const submittedKeys = new Set(
(temporaryAdvices.value || [])
.map(a => {
const om = a.originalMedicine || {}
const name = om.medicineName || om.adviceName || a.adviceName || ''
const spec = om.specification || om.volume || ''
const qty = om.quantity ?? 0
return `${name}|||${spec}|||${qty}`
})
.filter(k => k !== '|||0')
)
temporaryMedicalLoading.value = true // 🔧 新增:开始加载
getPrescriptionList(temporaryPatientInfo.value.visitId, 6, temporaryPatientInfo.value.operCode).then((res) => {
if (res.code === 200 && res.data) {
@@ -1987,27 +2002,57 @@ function handleQuoteBilling() {
})
// 🔧 修复 Bug #445: 过滤掉已生成医嘱的项目,避免"引用计费"后已提交项目重新出现在"待生成"列表
// 原因:后端返回的计费数据中,已生成医嘱的项目可能没有 requestId 字段
// 方案:用 chargeItemId/requestId/id 与已有的 temporaryAdvices 做匹配,排除已生成项目
if (temporaryAdvices.value.length > 0) {
const existingAdviceIds = new Set()
temporaryAdvices.value.forEach(a => {
const om = a.originalMedicine || {}
if (om.requestId) existingAdviceIds.add(String(om.requestId))
if (om.chargeItemId) existingAdviceIds.add(String(om.chargeItemId))
if (om.id) existingAdviceIds.add(String(om.id))
// 使用清空前提取的 submittedKeys名称|||规格|||数量复合键)进行匹配
if (submittedKeys.size > 0) {
temporaryBillingMedicines.value = temporaryBillingMedicines.value.filter(m => {
const key = `${m.medicineName || ''}|||${m.specification || ''}|||${m.quantity ?? 0}`
return !submittedKeys.has(key)
})
// 同步更新 temporaryAdvices保持两份数据一致
temporaryAdvices.value = temporaryBillingMedicines.value.map((medicine, index) => {
const specMatch = medicine.specification ? medicine.specification.match(/(\d+)(\D+)/) : null
const specValue = specMatch ? parseInt(specMatch[1]) : 1
const specUnit = specMatch ? specMatch[2] : 'ml'
const dosage = specValue * (medicine.quantity || 1)
let usageCode = 'iv'
let usageLabel = '静脉注射'
try {
const jsonContent = medicine.contentJson || medicine.content_json;
if (jsonContent) {
const contentData = JSON.parse(jsonContent);
if (contentData.methodCode) {
usageCode = contentData.methodCode;
usageLabel = getUsageLabel(contentData.methodCode);
}
}
} catch (e) {}
if (!usageCode || usageCode === 'iv') {
if (medicine.medicineName && medicine.medicineName.includes('注射液')) {
usageCode = 'iv'; usageLabel = '静脉注射';
} else if (medicine.medicineName && medicine.medicineName.includes('片')) {
usageCode = 'po'; usageLabel = '口服';
} else if (medicine.medicineName && medicine.medicineName.includes('胶囊')) {
usageCode = 'po'; usageLabel = '口服';
}
}
return {
id: index + 1,
adviceName: medicine.medicineName || '',
dosage,
unit: specUnit,
usage: usageCode,
usageLabel,
frequency: '临时',
executeTime: new Date().toLocaleString('zh-CN'),
originalMedicine: {
...medicine,
medicineName: medicine.medicineName,
specification: medicine.specification,
quantity: medicine.quantity,
encounterId: temporaryPatientInfo.value.visitId
}
}
})
if (existingAdviceIds.size > 0) {
temporaryBillingMedicines.value = temporaryBillingMedicines.value.filter(m => {
const mRequestId = m.requestId != null ? String(m.requestId) : null
const mChargeItemId = m.chargeItemId != null ? String(m.chargeItemId) : null
const mId = m.id != null ? String(m.id) : null
if (mRequestId && existingAdviceIds.has(mRequestId)) return false
if (mChargeItemId && existingAdviceIds.has(mChargeItemId)) return false
if (mId && existingAdviceIds.has(mId)) return false
return true
})
}
}
temporaryMedicalLoading.value = false // 🔧 新增:加载完成