fix(doctorstation): 解决医嘱删除时的空指针异常和费用项处理问题
- 添加了对EMR详情中的contextJson字段进行空值检查,避免解析空值导致异常 - 优化了医嘱删除时的patientId和encounterId补全逻辑,支持从药品、耗材、诊疗医嘱记录中获取缺失信息 - 修复了删除不同类型医嘱时费用项过滤问题,确保只处理对应类型的费用项目 - 简化了费用项删除逻辑,移除冗余的查询验证步骤,直接执行删除操作 - 增强了日志记录,便于追踪医嘱删除过程中的关键操作和状态变化
This commit is contained in:
@@ -486,11 +486,46 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
// 医嘱分类信息
|
||||
List<AdviceSaveDto> 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<Long> delRequestIdList = deleteList.stream().map(AdviceSaveDto::getRequestId).collect(Collectors.toList());
|
||||
if (!delRequestIdList.isEmpty()) {
|
||||
List<ChargeItem> 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<ChargeItem> 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<ServiceRequest>()
|
||||
@@ -924,6 +957,12 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
||||
List<Long> delRequestIdList = deleteList.stream().map(AdviceSaveDto::getRequestId).collect(Collectors.toList());
|
||||
if (!delRequestIdList.isEmpty()) {
|
||||
List<ChargeItem> 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<ChargeItem> 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<Long> delRequestIdList = deleteList.stream().map(AdviceSaveDto::getRequestId).collect(Collectors.toList());
|
||||
if (!delRequestIdList.isEmpty()) {
|
||||
List<ChargeItem> 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<ServiceRequest>().eq(ServiceRequest::getParentId,
|
||||
adviceSaveDto.getRequestId()));// 删除诊疗套餐对应的子项
|
||||
// 🔧 Bug Fix #219: 删除费用项前查询确认
|
||||
// 🔧 Bug Fix #219: 删除费用项
|
||||
Long requestId = adviceSaveDto.getRequestId();
|
||||
String serviceTable = CommonConstants.TableName.WOR_SERVICE_REQUEST;
|
||||
// 先查询费用项是否存在
|
||||
List<ChargeItem> 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) {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user