diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java index 0f930c292..37b1a3cc9 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java @@ -178,15 +178,26 @@ public class AdviceUtils { // 生命提示信息集合 List tipsList = new ArrayList<>(); for (MedicationRequestUseExe medicationRequestUseExe : medUseExeList) { - // 聚合同一位置所有批次的库存总量 + // 第一步:按 performLocation 匹配指定药房的库存 List matchedInventories = adviceInventory.stream() .filter(inventoryDto -> medicationRequestUseExe.getMedicationId().equals(inventoryDto.getItemId()) && CommonConstants.TableName.MED_MEDICATION_DEFINITION.equals(inventoryDto.getItemTable()) - && medicationRequestUseExe.getPerformLocation().equals(inventoryDto.getLocationId()) + && (medicationRequestUseExe.getPerformLocation() == null + || medicationRequestUseExe.getPerformLocation().equals(inventoryDto.getLocationId())) // 如果选择了具体的批次号,校验库存时需要加上批次号的匹配条件 && (StringUtils.isEmpty(medicationRequestUseExe.getLotNumber()) || medicationRequestUseExe.getLotNumber().equals(inventoryDto.getLotNumber()))) .collect(Collectors.toList()); + // 第二步:如果指定药房没有匹配到库存,则放宽条件查询所有药房的库存 + if (matchedInventories.isEmpty()) { + matchedInventories = adviceInventory.stream() + .filter(inventoryDto -> medicationRequestUseExe.getMedicationId().equals(inventoryDto.getItemId()) + && CommonConstants.TableName.MED_MEDICATION_DEFINITION.equals(inventoryDto.getItemTable()) + // 如果选择了具体的批次号,校验库存时需要加上批次号的匹配条件 + && (StringUtils.isEmpty(medicationRequestUseExe.getLotNumber()) + || medicationRequestUseExe.getLotNumber().equals(inventoryDto.getLotNumber()))) + .collect(Collectors.toList()); + } // 匹配到库存信息 if (!matchedInventories.isEmpty()) { // 聚合所有批次的可用库存