Fix Bug #504: 【住院医生工作站-临床医嘱】护士退回药品医嘱后,医生修改并保存时提示"未匹配到库存信息"
根因分析: 1. SQL查询 getRegRequestBaseInfo 未返回 medication_id/adviceDefinitionId 字段, 退回医嘱的 adviceDefinitionId 为 null,导致库存校验查询无法匹配到库存记录 2. 退回医嘱可能缺少 locationId,严格的 locationId 匹配导致校验失败 修复方案: 1. AdviceManageAppMapper.xml:在三个UNION查询中分别添加 medication_id/device_def_id/activity_id AS advice_definition_id 2. AdviceUtils.checkInventory(): - 过滤 null adviceDefinitionId,避免SQL查询异常 - 所有adviceDefinitionId为null时跳过库存校验 - 退回医嘱单个adviceDefinitionId为null时跳过该校验项 - 添加 locationId 容错匹配(为null时跳过location匹配) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -83,9 +83,14 @@ public class AdviceUtils {
|
|||||||
* @return 提示信息
|
* @return 提示信息
|
||||||
*/
|
*/
|
||||||
public String checkInventory(List<AdviceSaveDto> adviceSaveList) {
|
public String checkInventory(List<AdviceSaveDto> adviceSaveList) {
|
||||||
// 医嘱定义ID集合
|
// 医嘱定义ID集合(过滤null值,避免SQL查询异常)
|
||||||
List<Long> adviceDefinitionIdList
|
List<Long> adviceDefinitionIdList
|
||||||
= adviceSaveList.stream().map(AdviceSaveDto::getAdviceDefinitionId).collect(Collectors.toList());
|
= adviceSaveList.stream().map(AdviceSaveDto::getAdviceDefinitionId)
|
||||||
|
.filter(id -> id != null).collect(Collectors.toList());
|
||||||
|
// 🔧 Bug #504 修复:如果所有adviceDefinitionId都为null,跳过库存校验
|
||||||
|
if (adviceDefinitionIdList.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// 医嘱库存集合
|
// 医嘱库存集合
|
||||||
List<AdviceInventoryDto> adviceInventoryList
|
List<AdviceInventoryDto> adviceInventoryList
|
||||||
= doctorStationAdviceAppMapper.getAdviceInventory(null, adviceDefinitionIdList,
|
= doctorStationAdviceAppMapper.getAdviceInventory(null, adviceDefinitionIdList,
|
||||||
@@ -99,6 +104,10 @@ public class AdviceUtils {
|
|||||||
= this.subtractInventory(adviceInventoryList, adviceDraftInventoryList);
|
= this.subtractInventory(adviceInventoryList, adviceDraftInventoryList);
|
||||||
// 检查库存
|
// 检查库存
|
||||||
for (AdviceSaveDto saveDto : adviceSaveList) {
|
for (AdviceSaveDto saveDto : adviceSaveList) {
|
||||||
|
// 🔧 Bug #504 修复:退回医嘱可能adviceDefinitionId为空,跳过校验
|
||||||
|
if (saveDto.getAdviceDefinitionId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
boolean matched = false;
|
boolean matched = false;
|
||||||
for (AdviceInventoryDto inventoryDto : adviceInventory) {
|
for (AdviceInventoryDto inventoryDto : adviceInventory) {
|
||||||
// 匹配条件:adviceDefinitionId, adviceTableName, locationId, lotNumber 同时相等
|
// 匹配条件:adviceDefinitionId, adviceTableName, locationId, lotNumber 同时相等
|
||||||
@@ -108,10 +117,12 @@ public class AdviceUtils {
|
|||||||
|| saveDto.getLotNumber().equals(inventoryDto.getLotNumber());
|
|| saveDto.getLotNumber().equals(inventoryDto.getLotNumber());
|
||||||
boolean tableNameMatch = StringUtils.isEmpty(saveDto.getAdviceTableName())
|
boolean tableNameMatch = StringUtils.isEmpty(saveDto.getAdviceTableName())
|
||||||
|| inventoryDto.getItemTable().equals(saveDto.getAdviceTableName());
|
|| inventoryDto.getItemTable().equals(saveDto.getAdviceTableName());
|
||||||
// if (saveDto.)
|
// 🔧 Bug #504 修复:退回医嘱可能locationId为空,跳过location匹配
|
||||||
|
boolean locationMatch = saveDto.getLocationId() == null
|
||||||
|
|| inventoryDto.getLocationId().equals(saveDto.getLocationId());
|
||||||
if (inventoryDto.getItemId().equals(saveDto.getAdviceDefinitionId())
|
if (inventoryDto.getItemId().equals(saveDto.getAdviceDefinitionId())
|
||||||
&& tableNameMatch
|
&& tableNameMatch
|
||||||
&& inventoryDto.getLocationId().equals(saveDto.getLocationId()) && lotNumberMatch) {
|
&& locationMatch && lotNumberMatch) {
|
||||||
matched = true;
|
matched = true;
|
||||||
// 检查库存是否充足
|
// 检查库存是否充足
|
||||||
BigDecimal minUnitQuantity = saveDto.getMinUnitQuantity();
|
BigDecimal minUnitQuantity = saveDto.getMinUnitQuantity();
|
||||||
|
|||||||
@@ -216,7 +216,8 @@
|
|||||||
ccd.name AS condition_definition_name,
|
ccd.name AS condition_definition_name,
|
||||||
T1.therapy_enum AS therapyEnum,
|
T1.therapy_enum AS therapyEnum,
|
||||||
T1.sort_number AS sort_number,
|
T1.sort_number AS sort_number,
|
||||||
T1.based_on_id AS based_on_id
|
T1.based_on_id AS based_on_id,
|
||||||
|
T1.medication_id AS advice_definition_id
|
||||||
FROM med_medication_request AS T1
|
FROM med_medication_request AS T1
|
||||||
LEFT JOIN med_medication_definition AS T2 ON T2.ID = T1.medication_id
|
LEFT JOIN med_medication_definition AS T2 ON T2.ID = T1.medication_id
|
||||||
AND T2.delete_flag = '0'
|
AND T2.delete_flag = '0'
|
||||||
@@ -268,7 +269,8 @@
|
|||||||
'' AS condition_definition_name,
|
'' AS condition_definition_name,
|
||||||
2 AS therapyEnum,
|
2 AS therapyEnum,
|
||||||
99 AS sort_number,
|
99 AS sort_number,
|
||||||
T1.based_on_id AS based_on_id
|
T1.based_on_id AS based_on_id,
|
||||||
|
T1.device_def_id AS advice_definition_id
|
||||||
FROM wor_device_request AS T1
|
FROM wor_device_request AS T1
|
||||||
LEFT JOIN adm_device_definition AS T2 ON T2.ID = T1.device_def_id
|
LEFT JOIN adm_device_definition AS T2 ON T2.ID = T1.device_def_id
|
||||||
AND T2.delete_flag = '0'
|
AND T2.delete_flag = '0'
|
||||||
@@ -317,7 +319,8 @@
|
|||||||
'' AS condition_definition_name,
|
'' AS condition_definition_name,
|
||||||
COALESCE(T1.therapy_enum, 2) AS therapyEnum,
|
COALESCE(T1.therapy_enum, 2) AS therapyEnum,
|
||||||
99 AS sort_number,
|
99 AS sort_number,
|
||||||
T1.based_on_id AS based_on_id
|
T1.based_on_id AS based_on_id,
|
||||||
|
T1.activity_id AS advice_definition_id
|
||||||
FROM wor_service_request AS T1
|
FROM wor_service_request AS T1
|
||||||
LEFT JOIN wor_activity_definition AS T2
|
LEFT JOIN wor_activity_definition AS T2
|
||||||
ON T2.ID = T1.activity_id
|
ON T2.ID = T1.activity_id
|
||||||
|
|||||||
Reference in New Issue
Block a user