Fix Bug #504: 【住院医生工作站-临床医嘱】护士退回药品医嘱后,医生修改并保存时提示"未匹配到库存信息"
根因:checkInventory() 仅执行严格匹配(adviceDefinitionId + adviceTableName + locationId + lotNumber), 当退回医嘱设置了 locationId 但该药房恰好没有对应药品的库存记录时,匹配失败直接返回"未匹配到库存信息"。 而 checkExeMedInventory() 已有两步放宽匹配逻辑(先按药房匹配,失败后放宽到所有药房),checkInventory 缺失此逻辑。 修复:在 checkInventory() 中增加两步匹配: 1. 严格匹配(原有逻辑,含 locationId 条件) 2. 若严格匹配未找到且 locationId 非null,放宽 locationId 条件匹配所有药房库存 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -109,45 +109,74 @@ public class AdviceUtils {
|
||||
continue;
|
||||
}
|
||||
boolean matched = false;
|
||||
boolean insufficientInventory = false;
|
||||
|
||||
// 第一步:严格匹配(adviceDefinitionId + adviceTableName + locationId + lotNumber)
|
||||
for (AdviceInventoryDto inventoryDto : adviceInventory) {
|
||||
// 匹配条件:adviceDefinitionId, adviceTableName, locationId, lotNumber 同时相等
|
||||
// 如果选择了具体的批次号,校验库存时需要加上批次号的匹配条件
|
||||
// 🔧 Bug #177 修复:添加容错处理,如果 adviceTableName 为空则跳过该项匹配
|
||||
boolean lotNumberMatch = StringUtils.isEmpty(saveDto.getLotNumber())
|
||||
|| saveDto.getLotNumber().equals(inventoryDto.getLotNumber());
|
||||
boolean tableNameMatch = StringUtils.isEmpty(saveDto.getAdviceTableName())
|
||||
|| inventoryDto.getItemTable().equals(saveDto.getAdviceTableName());
|
||||
// 🔧 Bug #504 修复:退回医嘱可能locationId为空,跳过location匹配
|
||||
boolean locationMatch = saveDto.getLocationId() == null
|
||||
|| inventoryDto.getLocationId().equals(saveDto.getLocationId());
|
||||
if (inventoryDto.getItemId().equals(saveDto.getAdviceDefinitionId())
|
||||
&& tableNameMatch
|
||||
&& locationMatch && lotNumberMatch) {
|
||||
matched = true;
|
||||
// 检查库存是否充足
|
||||
BigDecimal minUnitQuantity = saveDto.getMinUnitQuantity();
|
||||
// 🔧 Bug Fix: 对于耗材类型,如果没有设置minUnitQuantity,则使用quantity作为默认值
|
||||
if (minUnitQuantity == null) {
|
||||
if (CommonConstants.TableName.ADM_DEVICE_DEFINITION.equals(inventoryDto.getItemTable())) {
|
||||
// 耗材只有一个单位,minUnitQuantity等于quantity
|
||||
minUnitQuantity = saveDto.getQuantity();
|
||||
} else {
|
||||
return saveDto.getAdviceName() + "的小单位数量不能为空";
|
||||
}
|
||||
}
|
||||
BigDecimal chineseHerbsDoseQuantity = saveDto.getChineseHerbsDoseQuantity(); // 中药付数
|
||||
// 中草药医嘱的情况
|
||||
BigDecimal chineseHerbsDoseQuantity = saveDto.getChineseHerbsDoseQuantity();
|
||||
if (chineseHerbsDoseQuantity != null && chineseHerbsDoseQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
||||
minUnitQuantity = minUnitQuantity.multiply(chineseHerbsDoseQuantity);
|
||||
}
|
||||
if (minUnitQuantity.compareTo(inventoryDto.getQuantity()) > 0) {
|
||||
return saveDto.getAdviceName() + "在" + inventoryDto.getLocationName() + "库存不足";
|
||||
insufficientInventory = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 第二步:如果严格匹配未找到,放宽location条件匹配所有药房库存
|
||||
if (!matched && saveDto.getLocationId() != null) {
|
||||
for (AdviceInventoryDto inventoryDto : adviceInventory) {
|
||||
boolean lotNumberMatch = StringUtils.isEmpty(saveDto.getLotNumber())
|
||||
|| saveDto.getLotNumber().equals(inventoryDto.getLotNumber());
|
||||
boolean tableNameMatch = StringUtils.isEmpty(saveDto.getAdviceTableName())
|
||||
|| inventoryDto.getItemTable().equals(saveDto.getAdviceTableName());
|
||||
if (inventoryDto.getItemId().equals(saveDto.getAdviceDefinitionId())
|
||||
&& tableNameMatch && lotNumberMatch) {
|
||||
matched = true;
|
||||
BigDecimal minUnitQuantity = saveDto.getMinUnitQuantity();
|
||||
if (minUnitQuantity == null) {
|
||||
if (CommonConstants.TableName.ADM_DEVICE_DEFINITION.equals(inventoryDto.getItemTable())) {
|
||||
minUnitQuantity = saveDto.getQuantity();
|
||||
} else {
|
||||
return saveDto.getAdviceName() + "的小单位数量不能为空";
|
||||
}
|
||||
}
|
||||
BigDecimal chineseHerbsDoseQuantity = saveDto.getChineseHerbsDoseQuantity();
|
||||
if (chineseHerbsDoseQuantity != null && chineseHerbsDoseQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
||||
minUnitQuantity = minUnitQuantity.multiply(chineseHerbsDoseQuantity);
|
||||
}
|
||||
if (minUnitQuantity.compareTo(inventoryDto.getQuantity()) > 0) {
|
||||
insufficientInventory = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有匹配到库存
|
||||
if (!matched) {
|
||||
if (insufficientInventory) {
|
||||
return saveDto.getAdviceName() + "库存不足";
|
||||
}
|
||||
return saveDto.getAdviceName() + "未匹配到库存信息";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user