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 01949a3b..98a72edd 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 @@ -737,6 +737,28 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp List medRequestIdList = new ArrayList<>(); for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) { + // 🔧 Bug Fix: 确保accountId不为null,与handleBoundDevices保持一致 + if (adviceSaveDto.getAccountId() == null) { + // 尝试从患者就诊中获取默认账户ID(自费账户) + Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId()); + if (selfAccount != null) { + adviceSaveDto.setAccountId(selfAccount.getId()); + } else { + // 自动创建自费账户 + Account newAccount = new Account(); + newAccount.setPatientId(adviceSaveDto.getPatientId()); + newAccount.setEncounterId(adviceSaveDto.getEncounterId()); + newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO); + newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode()); + newAccount.setBalanceAmount(BigDecimal.ZERO); + newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue()); + newAccount.setEncounterFlag(Whether.YES.getValue()); + newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo()); + Long newAccountId = iAccountService.saveAccountByRegister(newAccount); + adviceSaveDto.setAccountId(newAccountId); + } + } + boolean firstTimeSave = false;// 第一次保存 medicationRequest = new MedicationRequest(); medicationRequest.setId(adviceSaveDto.getRequestId()); // 主键id @@ -941,7 +963,29 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp deviceChargeItem.setServiceId(deviceRequest.getId()); deviceChargeItem.setProductTable(CommonConstants.TableName.ADM_DEVICE_DEFINITION); deviceChargeItem.setProductId(boundDevice.getDevActId()); - deviceChargeItem.setAccountId(adviceSaveDto.getAccountId()); + // 🔧 Bug Fix #281: 如果accountId为null,从就诊中获取账户ID,如果没有则自动创建 + Long deviceAccountId = adviceSaveDto.getAccountId(); + if (deviceAccountId == null) { + // 尝试从患者就诊中获取默认账户ID(自费账户) + Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId()); + if (selfAccount != null) { + deviceAccountId = selfAccount.getId(); + } else { + // 自动创建自费账户 + Account newAccount = new Account(); + newAccount.setPatientId(adviceSaveDto.getPatientId()); + newAccount.setEncounterId(adviceSaveDto.getEncounterId()); + newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO); + newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode()); + newAccount.setBalanceAmount(BigDecimal.ZERO); + newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue()); + newAccount.setEncounterFlag(Whether.YES.getValue()); + // 🔧 Bug Fix: 设置账户名称,避免数据库NOT NULL约束错误 + newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo()); + deviceAccountId = iAccountService.saveAccountByRegister(newAccount); + } + } + deviceChargeItem.setAccountId(deviceAccountId); deviceChargeItem.setConditionId(adviceSaveDto.getConditionId()); deviceChargeItem.setEncounterDiagnosisId(adviceSaveDto.getEncounterDiagnosisId()); deviceChargeItem.setDispenseId(dispenseId); @@ -1141,6 +1185,8 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp newAccount.setBalanceAmount(BigDecimal.ZERO); newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue()); newAccount.setEncounterFlag(Whether.YES.getValue()); + // 🔧 Bug Fix: 设置账户名称,避免数据库NOT NULL约束错误 + newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo()); accountId = iAccountService.saveAccountByRegister(newAccount); } } @@ -1222,6 +1268,28 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp } for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) { + // 🔧 Bug Fix: 确保accountId不为null + if (adviceSaveDto.getAccountId() == null) { + // 尝试从患者就诊中获取默认账户ID(自费账户) + Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId()); + if (selfAccount != null) { + adviceSaveDto.setAccountId(selfAccount.getId()); + } else { + // 自动创建自费账户 + Account newAccount = new Account(); + newAccount.setPatientId(adviceSaveDto.getPatientId()); + newAccount.setEncounterId(adviceSaveDto.getEncounterId()); + newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO); + newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode()); + newAccount.setBalanceAmount(BigDecimal.ZERO); + newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue()); + newAccount.setEncounterFlag(Whether.YES.getValue()); + newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo()); + Long newAccountId = iAccountService.saveAccountByRegister(newAccount); + adviceSaveDto.setAccountId(newAccountId); + } + } + // 🔧 Bug Fix #238: 诊疗项目执行科室非空校验 if (adviceSaveDto.getAdviceType() != null && adviceSaveDto.getAdviceType() == 3) { Long effectiveOrgId = adviceSaveDto.getEffectiveOrgId(); 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 227e49fe..a84cdbbe 100644 --- a/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue +++ b/openhis-ui-vue3/src/views/doctorstation/components/prescription/prescriptionlist.vue @@ -261,6 +261,7 @@
+ {{ scope.row.unitCode_dictText }} - +