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 0cbd3d1e..10feadbd 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 @@ -16,9 +16,11 @@ import com.core.common.utils.SecurityUtils; import com.core.common.utils.StringUtils; import com.core.web.util.TenantOptionUtil; import com.openhis.administration.domain.Account; -import com.openhis.administration.service.IAccountService; import com.openhis.administration.domain.ChargeItem; +import com.openhis.administration.domain.Encounter; +import com.openhis.administration.service.IAccountService; import com.openhis.administration.service.IChargeItemService; +import com.openhis.administration.service.IEncounterService; import com.openhis.common.constant.CommonConstants; import com.openhis.common.constant.PromptMsgConstant; import com.openhis.common.enums.*; @@ -106,6 +108,9 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp @Resource RedisCache redisCache; + @Resource + IEncounterService iEncounterService; + // 缓存 key 前缀 private static final String ADVICE_BASE_INFO_CACHE_PREFIX = "advice:base:info:"; // 缓存过期时间(小时) @@ -480,6 +485,30 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp Long organizationId = adviceSaveParam.getOrganizationId(); // 医嘱分类信息 List adviceSaveList = adviceSaveParam.getAdviceSaveList(); + + // 🔧 Bug Fix: 校验并补全patientId(如果为null,从encounter查询获取) + for (AdviceSaveDto adviceSaveDto : adviceSaveList) { + // 首先检查encounterId是否为null + if (adviceSaveDto.getEncounterId() == null) { + log.error("encounterId为null,无法保存医嘱"); + return R.fail(null, "就诊信息不完整,请重新选择患者后再试"); + } + + // 如果patientId为null,尝试从encounter获取 + if (adviceSaveDto.getPatientId() == null) { + // 从就诊记录中获取patientId + Encounter encounter = iEncounterService.getById(adviceSaveDto.getEncounterId()); + if (encounter != null && encounter.getPatientId() != null) { + adviceSaveDto.setPatientId(encounter.getPatientId()); + log.info("自动补全patientId: encounterId={}, patientId={}", + adviceSaveDto.getEncounterId(), encounter.getPatientId()); + } else { + log.error("无法获取patientId: encounterId={}", adviceSaveDto.getEncounterId()); + return R.fail(null, "无法获取患者信息,请重新选择患者"); + } + } + } + // 药品 List medicineList = adviceSaveList.stream() .filter(e -> ItemType.MEDICINE.getValue().equals(e.getAdviceType())).collect(Collectors.toList()); 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 8b973667..08c9b9ab 100644 --- a/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue +++ b/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue @@ -674,6 +674,7 @@ :controls="false" style="width: 60px" size="small" + @change="calculateTotalPrice(scope.row, scope.$index)" /> {{ scope.row.unitCode_dictText }} @@ -2154,6 +2155,13 @@ function handleSave(prescriptionId) { finalAccountId = null; } + // 🔧 Bug Fix: 校验患者信息完整性 + if (!props.patientInfo || !props.patientInfo.patientId || !props.patientInfo.encounterId) { + console.error('患者信息不完整:', props.patientInfo); + proxy.$modal.msgError('患者信息不完整,请重新选择患者后再试'); + return; + } + saveList.forEach((item) => { item.patientId = props.patientInfo.patientId; item.encounterId = props.patientInfo.encounterId; @@ -2686,6 +2694,13 @@ function handleSaveBatch(prescriptionId) { return; } + // 🔧 Bug Fix: 校验患者信息完整性 + if (!props.patientInfo || !props.patientInfo.patientId || !props.patientInfo.encounterId) { + console.error('患者信息不完整:', props.patientInfo); + proxy.$modal.msgError('患者信息不完整,请重新选择患者后再试'); + return; + } + // --- 【修改开始:优先使用选中行】 --- // 1. 获取表格当前选中的行 @@ -2785,6 +2800,8 @@ function handleSaveBatch(prescriptionId) { return { ...item, + patientId: props.patientInfo.patientId, + encounterId: props.patientInfo.encounterId, adviceType: saveAdviceType, dbOpType: item.requestId ? '2' : '1', isSaved: true,