From c2b1d7d9d9ae4099467f593b63e9bc3b1ef410fe Mon Sep 17 00:00:00 2001 From: chenqi Date: Tue, 24 Mar 2026 13:27:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(doctorstation):=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=8C=BB=E5=98=B1=E5=88=A0=E9=99=A4=E6=97=B6=E7=9A=84=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8=E5=92=8C=E8=B4=B9=E7=94=A8?= =?UTF-8?q?=E9=A1=B9=E5=A4=84=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了对EMR详情中的contextJson字段进行空值检查,避免解析空值导致异常 - 优化了医嘱删除时的patientId和encounterId补全逻辑,支持从药品、耗材、诊疗医嘱记录中获取缺失信息 - 修复了删除不同类型医嘱时费用项过滤问题,确保只处理对应类型的费用项目 - 简化了费用项删除逻辑,移除冗余的查询验证步骤,直接执行删除操作 - 增强了日志记录,便于追踪医嘱删除过程中的关键操作和状态变化 --- .../DoctorStationAdviceAppServiceImpl.java | 105 +++++++++++------- .../prescription/prescriptionlist.vue | 4 +- 2 files changed, 70 insertions(+), 39 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java index 10feadbd..3774d8ba 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java @@ -486,11 +486,46 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp // 医嘱分类信息 List adviceSaveList = adviceSaveParam.getAdviceSaveList(); - // 🔧 Bug Fix: 校验并补全patientId(如果为null,从encounter查询获取) + // 🔧 Bug Fix: 校验并补全patientId和encounterId(如果为null,尝试从医嘱记录获取) for (AdviceSaveDto adviceSaveDto : adviceSaveList) { + // 对于删除操作,如果encounterId为null,尝试从医嘱记录获取 + if (adviceSaveDto.getEncounterId() == null && DbOpType.DELETE.getCode().equals(adviceSaveDto.getDbOpType())) { + // 尝试从各类医嘱记录中获取encounterId + Long requestId = adviceSaveDto.getRequestId(); + if (requestId != null) { + // 尝试从药品医嘱获取 + MedicationRequest medRequest = iMedicationRequestService.getById(requestId); + if (medRequest != null && medRequest.getEncounterId() != null) { + adviceSaveDto.setEncounterId(medRequest.getEncounterId()); + adviceSaveDto.setPatientId(medRequest.getPatientId()); + log.info("BugFix: 删除药品医嘱时自动补全encounterId和patientId: requestId={}, encounterId={}, patientId={}", + requestId, medRequest.getEncounterId(), medRequest.getPatientId()); + } else { + // 尝试从耗材医嘱获取 + DeviceRequest devRequest = iDeviceRequestService.getById(requestId); + if (devRequest != null && devRequest.getEncounterId() != null) { + adviceSaveDto.setEncounterId(devRequest.getEncounterId()); + adviceSaveDto.setPatientId(devRequest.getPatientId()); + log.info("BugFix: 删除耗材医嘱时自动补全encounterId和patientId: requestId={}, encounterId={}, patientId={}", + requestId, devRequest.getEncounterId(), devRequest.getPatientId()); + } else { + // 尝试从诊疗医嘱获取 + ServiceRequest srvRequest = iServiceRequestService.getById(requestId); + if (srvRequest != null && srvRequest.getEncounterId() != null) { + adviceSaveDto.setEncounterId(srvRequest.getEncounterId()); + adviceSaveDto.setPatientId(srvRequest.getPatientId()); + log.info("BugFix: 删除诊疗医嘱时自动补全encounterId和patientId: requestId={}, encounterId={}, patientId={}", + requestId, srvRequest.getEncounterId(), srvRequest.getPatientId()); + } + } + } + } + } + // 首先检查encounterId是否为null if (adviceSaveDto.getEncounterId() == null) { - log.error("encounterId为null,无法保存医嘱"); + log.error("encounterId为null,无法保存医嘱, dbOpType={}, requestId={}, adviceType={}", + adviceSaveDto.getDbOpType(), adviceSaveDto.getRequestId(), adviceSaveDto.getAdviceType()); return R.fail(null, "就诊信息不完整,请重新选择患者后再试"); } @@ -634,6 +669,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp List delRequestIdList = deleteList.stream().map(AdviceSaveDto::getRequestId).collect(Collectors.toList()); if (!delRequestIdList.isEmpty()) { List chargeItemList = iChargeItemService.getChargeItemInfoByReqId(delRequestIdList); + // 🔧 BugFix#219: 过滤只保留药品类型的费用项 + if (chargeItemList != null && !chargeItemList.isEmpty()) { + chargeItemList = chargeItemList.stream() + .filter(ci -> CommonConstants.TableName.MED_MEDICATION_REQUEST.equals(ci.getServiceTable())) + .collect(Collectors.toList()); + } if (chargeItemList != null && !chargeItemList.isEmpty()) { for (ChargeItem ci : chargeItemList) { if (ChargeItemStatus.BILLED.getValue().equals(ci.getStatusEnum())) { @@ -646,20 +687,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp iMedicationRequestService.removeById(adviceSaveDto.getRequestId()); // 删除已经产生的药品发放信息 iMedicationDispenseService.deleteMedicationDispense(adviceSaveDto.getRequestId()); - // 🔧 Bug Fix #219: 删除费用项前查询确认 + // 🔧 Bug Fix #219: 删除费用项 Long requestId = adviceSaveDto.getRequestId(); String serviceTable = CommonConstants.TableName.MED_MEDICATION_REQUEST; - // 先查询费用项是否存在 - List existingChargeItems = iChargeItemService.getChargeItemInfoByReqId(Arrays.asList(requestId)); - if (existingChargeItems == null || existingChargeItems.isEmpty()) { - log.warn("BugFix#219: 删除药品医嘱时未找到费用项, requestId={}, serviceTable={}", requestId, serviceTable); - } else { - log.info("BugFix#219: 找到 {} 个费用项, 准备删除, requestId={}, serviceTable={}", - existingChargeItems.size(), requestId, serviceTable); - // 删除费用项 - iChargeItemService.deleteByServiceTableAndId(serviceTable, requestId); - log.info("BugFix#219: 费用项删除完成, requestId={}", requestId); - } + // 直接删除费用项 + iChargeItemService.deleteByServiceTableAndId(serviceTable, requestId); + log.info("BugFix#219: 药品医嘱删除完成, requestId={}, serviceTable={}", requestId, serviceTable); // 删除基于这个药品生成的需要执行的诊疗请求 iServiceRequestService.remove( new LambdaQueryWrapper() @@ -924,6 +957,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp List delRequestIdList = deleteList.stream().map(AdviceSaveDto::getRequestId).collect(Collectors.toList()); if (!delRequestIdList.isEmpty()) { List chargeItemList = iChargeItemService.getChargeItemInfoByReqId(delRequestIdList); + // 🔧 BugFix#219: 过滤只保留耗材类型的费用项 + if (chargeItemList != null && !chargeItemList.isEmpty()) { + chargeItemList = chargeItemList.stream() + .filter(ci -> CommonConstants.TableName.WOR_DEVICE_REQUEST.equals(ci.getServiceTable())) + .collect(Collectors.toList()); + } if (chargeItemList != null && !chargeItemList.isEmpty()) { for (ChargeItem ci : chargeItemList) { if (ChargeItemStatus.BILLED.getValue().equals(ci.getStatusEnum())) { @@ -936,20 +975,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp iDeviceRequestService.removeById(adviceSaveDto.getRequestId()); // 删除已经产生的耗材发放信息 iDeviceDispenseService.deleteDeviceDispense(adviceSaveDto.getRequestId()); - // 🔧 Bug Fix #219: 删除费用项前查询确认 + // 🔧 Bug Fix #219: 删除费用项 Long requestId = adviceSaveDto.getRequestId(); String serviceTable = CommonConstants.TableName.WOR_DEVICE_REQUEST; - // 先查询费用项是否存在 - List existingChargeItems = iChargeItemService.getChargeItemInfoByReqId(Arrays.asList(requestId)); - if (existingChargeItems == null || existingChargeItems.isEmpty()) { - log.warn("BugFix#219: 删除耗材医嘱时未找到费用项, requestId={}, serviceTable={}", requestId, serviceTable); - } else { - log.info("BugFix#219: 找到 {} 个费用项, 准备删除, requestId={}, serviceTable={}", - existingChargeItems.size(), requestId, serviceTable); - // 删除费用项 - iChargeItemService.deleteByServiceTableAndId(serviceTable, requestId); - log.info("BugFix#219: 费用项删除完成, requestId={}", requestId); - } + // 直接删除费用项(使用serviceTable和serviceId作为条件) + iChargeItemService.deleteByServiceTableAndId(serviceTable, requestId); + log.info("BugFix#219: 耗材医嘱删除完成, requestId={}, serviceTable={}", requestId, serviceTable); } for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) { @@ -1087,6 +1118,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp List delRequestIdList = deleteList.stream().map(AdviceSaveDto::getRequestId).collect(Collectors.toList()); if (!delRequestIdList.isEmpty()) { List chargeItemList = iChargeItemService.getChargeItemInfoByReqId(delRequestIdList); + // 🔧 BugFix#219: 过滤只保留诊疗类型的费用项 + if (chargeItemList != null && !chargeItemList.isEmpty()) { + chargeItemList = chargeItemList.stream() + .filter(ci -> CommonConstants.TableName.WOR_SERVICE_REQUEST.equals(ci.getServiceTable())) + .collect(Collectors.toList()); + } if (chargeItemList != null && !chargeItemList.isEmpty()) { for (ChargeItem ci : chargeItemList) { if (ChargeItemStatus.BILLED.getValue().equals(ci.getStatusEnum())) { @@ -1100,20 +1137,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp iServiceRequestService.remove( new LambdaQueryWrapper().eq(ServiceRequest::getParentId, adviceSaveDto.getRequestId()));// 删除诊疗套餐对应的子项 - // 🔧 Bug Fix #219: 删除费用项前查询确认 + // 🔧 Bug Fix #219: 删除费用项 Long requestId = adviceSaveDto.getRequestId(); String serviceTable = CommonConstants.TableName.WOR_SERVICE_REQUEST; - // 先查询费用项是否存在 - List existingChargeItems = iChargeItemService.getChargeItemInfoByReqId(Arrays.asList(requestId)); - if (existingChargeItems == null || existingChargeItems.isEmpty()) { - log.warn("BugFix#219: 删除诊疗医嘱时未找到费用项, requestId={}, serviceTable={}", requestId, serviceTable); - } else { - log.info("BugFix#219: 找到 {} 个费用项, 准备删除, requestId={}, serviceTable={}", - existingChargeItems.size(), requestId, serviceTable); - // 删除费用项 - iChargeItemService.deleteByServiceTableAndId(serviceTable, requestId); - log.info("BugFix#219: 费用项删除完成, requestId={}", requestId); - } + // 直接删除费用项 + iChargeItemService.deleteByServiceTableAndId(serviceTable, requestId); + log.info("BugFix#219: 诊疗医嘱删除完成, requestId={}, serviceTable={}", requestId, serviceTable); } for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) { diff --git a/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue b/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue index 3222adfa..47784003 100644 --- a/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue +++ b/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue @@ -2340,11 +2340,13 @@ function handleEmrTreatment() { } }); getEmrDetail(props.patientInfo.encounterId).then((res) => { + // 🔧 BugFix#219: 添加空值检查 + const contextJson = res.data?.contextJson ? JSON.parse(res.data.contextJson) : {}; saveEmr({ patientId: props.patientInfo.patientId, encounterId: props.patientInfo.encounterId, contextJson: { - ...JSON.parse(res.data.contextJson), + ...contextJson, treatment: treatment, }, });