From 63e28ab153c9ad28ea6087408edaf6af24e8d1ca Mon Sep 17 00:00:00 2001 From: zhaoyun Date: Thu, 28 May 2026 15:55:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(#597):=20remark=E5=AD=97=E6=AE=B5=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=90=8E=E4=B8=A2=E5=A4=B1=E4=BF=AE=E5=A4=8D=E2=80=94?= =?UTF-8?q?=E2=80=94=E8=8D=AF=E5=93=81/=E8=80=97=E6=9D=90=E5=8C=BB?= =?UTF-8?q?=E5=98=B1=E7=9A=84=E5=A4=87=E6=B3=A8=E5=86=99=E5=85=A5contentJs?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: - MedicationRequest/DeviceRequest 实体无 remark 字段/列 - handMedication()/handDevice() 未保存 remark - 查询 Mapper 通过子查 wor_service_request 取 remark,但药品/耗材无对应记录 修复: - Mapper:药品/耗材的 remark 来源改为从 content_json::jsonb ->> 'remark' 提取 - Service:在 handMedication()/handDevice() 中将 remark 合并到 contentJson - 覆盖住院(AdviceManageAppServiceImpl)和门诊(DoctorStationAdviceAppServiceImpl) - 不新增数据库列,不改实体结构 --- .../DoctorStationAdviceAppServiceImpl.java | 32 +++++++++++++++ .../impl/AdviceManageAppServiceImpl.java | 40 +++++++++++++++++++ .../DoctorStationAdviceAppMapper.xml | 6 +-- .../AdviceManageAppMapper.xml | 4 +- 4 files changed, 77 insertions(+), 5 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 e09f2c29b..225d47c8c 100755 --- 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 @@ -48,6 +48,9 @@ import com.openhis.web.personalization.dto.ActivityDeviceDto; import com.openhis.workflow.domain.ActivityDefinition; import com.openhis.workflow.domain.DeviceRequest; import com.openhis.workflow.domain.InventoryItem; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.openhis.workflow.domain.ServiceRequest; import com.openhis.workflow.service.*; import lombok.extern.slf4j.Slf4j; @@ -946,6 +949,27 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp /** * 处理药品 */ + + /** + * 将 remark 合并到 contentJson 中,确保 Mapper 能从 content_json 提取 remark + */ + private String injectRemarkIntoContentJson(String contentJson, String remark) { + if (remark == null || remark.isEmpty() || contentJson == null || contentJson.isEmpty()) { + return contentJson; + } + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode node = mapper.readTree(contentJson); + if (node instanceof ObjectNode) { + ((ObjectNode) node).put("remark", remark); + return mapper.writeValueAsString(node); + } + } catch (Exception e) { + log.warn("Failed to inject remark into contentJson: {}", e.getMessage()); + } + return contentJson; + } + private List handMedication(List medicineList, Date curDate, String adviceOpType, Long organizationId, String signCode) { // 当前登录账号的科室id @@ -1162,6 +1186,10 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp if (medicationRequest.getId() == null) { firstTimeSave = true; } + // 确保 contentJson 包含 remark + if (adviceSaveDto.getRemark() != null && !adviceSaveDto.getRemark().isEmpty()) { + medicationRequest.setContentJson(injectRemarkIntoContentJson(medicationRequest.getContentJson(), adviceSaveDto.getRemark())); + } iMedicationRequestService.saveOrUpdate(medicationRequest); if (firstTimeSave) { medRequestIdList.add(medicationRequest.getId().toString()); @@ -1622,6 +1650,10 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp deviceRequest.setConditionId(adviceSaveDto.getConditionId()); // 诊断id deviceRequest.setEncounterDiagnosisId(adviceSaveDto.getEncounterDiagnosisId()); // 就诊诊断id + // 确保 contentJson 包含 remark + if (adviceSaveDto.getRemark() != null && !adviceSaveDto.getRemark().isEmpty()) { + deviceRequest.setContentJson(injectRemarkIntoContentJson(deviceRequest.getContentJson(), adviceSaveDto.getRemark())); + } iDeviceRequestService.saveOrUpdate(deviceRequest); if (is_save) { // 处理耗材发放 diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/AdviceManageAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/AdviceManageAppServiceImpl.java index 1412ebd71..362f12331 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/AdviceManageAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/appservice/impl/AdviceManageAppServiceImpl.java @@ -30,6 +30,9 @@ import com.openhis.web.regdoctorstation.dto.*; import com.openhis.web.regdoctorstation.mapper.AdviceManageAppMapper; import com.openhis.web.regdoctorstation.utils.RegPrescriptionUtils; import com.openhis.workflow.domain.DeviceRequest; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.openhis.workflow.domain.ServiceRequest; import com.openhis.workflow.service.IActivityDefinitionService; import com.openhis.workflow.domain.ActivityDefinition; @@ -351,6 +354,27 @@ public class AdviceManageAppServiceImpl implements IAdviceManageAppService { /** * 处理药品 */ + + /** + * 将 remark 合并到 contentJson 中,确保 Mapper 能从 content_json 提取 remark + */ + private String injectRemarkIntoContentJson(String contentJson, String remark) { + if (remark == null || remark.isEmpty() || contentJson == null || contentJson.isEmpty()) { + return contentJson; + } + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode node = mapper.readTree(contentJson); + if (node instanceof ObjectNode) { + ((ObjectNode) node).put("remark", remark); + return mapper.writeValueAsString(node); + } + } catch (Exception e) { + log.warn("Failed to inject remark into contentJson: {}", e.getMessage()); + } + return contentJson; + } + private List handMedication(List medicineList, Date startTime, Date authoredTime, Date curDate, String adviceOpType, Long organizationId, String signCode) { // 当前登录账号的科室id @@ -449,6 +473,10 @@ public class AdviceManageAppServiceImpl implements IAdviceManageAppService { if (longMedicationRequest.getId() == null) { firstTimeSave = true; } + // 确保 contentJson 包含 remark + if (regAdviceSaveDto.getRemark() != null && !regAdviceSaveDto.getRemark().isEmpty()) { + longMedicationRequest.setContentJson(injectRemarkIntoContentJson(longMedicationRequest.getContentJson(), regAdviceSaveDto.getRemark())); + } iMedicationRequestService.saveOrUpdate(longMedicationRequest); if (firstTimeSave) { medRequestIdList.add(longMedicationRequest.getId().toString()); @@ -536,6 +564,10 @@ public class AdviceManageAppServiceImpl implements IAdviceManageAppService { if (tempMedicationRequest.getId() == null) { firstTimeSave = true; } + // 确保 contentJson 包含 remark + if (regAdviceSaveDto.getRemark() != null && !regAdviceSaveDto.getRemark().isEmpty()) { + tempMedicationRequest.setContentJson(injectRemarkIntoContentJson(tempMedicationRequest.getContentJson(), regAdviceSaveDto.getRemark())); + } iMedicationRequestService.saveOrUpdate(tempMedicationRequest); if (firstTimeSave) { medRequestIdList.add(tempMedicationRequest.getId().toString()); @@ -823,6 +855,10 @@ public class AdviceManageAppServiceImpl implements IAdviceManageAppService { deviceRequest.setConditionId(regAdviceSaveDto.getConditionId()); // 诊断id deviceRequest.setEncounterDiagnosisId(regAdviceSaveDto.getEncounterDiagnosisId()); // 就诊诊断id } + // 确保 contentJson 包含 remark + if (regAdviceSaveDto.getRemark() != null && !regAdviceSaveDto.getRemark().isEmpty()) { + deviceRequest.setContentJson(injectRemarkIntoContentJson(deviceRequest.getContentJson(), regAdviceSaveDto.getRemark())); + } iDeviceRequestService.saveOrUpdate(deviceRequest); } @@ -862,6 +898,10 @@ public class AdviceManageAppServiceImpl implements IAdviceManageAppService { deviceRequest.setConditionId(regAdviceSaveDto.getConditionId()); // 诊断id deviceRequest.setEncounterDiagnosisId(regAdviceSaveDto.getEncounterDiagnosisId()); // 就诊诊断id } + // 确保 contentJson 包含 remark + if (regAdviceSaveDto.getRemark() != null && !regAdviceSaveDto.getRemark().isEmpty()) { + deviceRequest.setContentJson(injectRemarkIntoContentJson(deviceRequest.getContentJson(), regAdviceSaveDto.getRemark())); + } iDeviceRequestService.saveOrUpdate(deviceRequest); // 保存时,保存耗材费用项 diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/doctorstation/DoctorStationAdviceAppMapper.xml b/openhis-server-new/openhis-application/src/main/resources/mapper/doctorstation/DoctorStationAdviceAppMapper.xml index e95852482..12f135132 100755 --- a/openhis-server-new/openhis-application/src/main/resources/mapper/doctorstation/DoctorStationAdviceAppMapper.xml +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/doctorstation/DoctorStationAdviceAppMapper.xml @@ -516,7 +516,7 @@ T1.patient_id AS patient_id, 'med_medication_definition' AS advice_table_name, T1.medication_id AS advice_definition_id - , (SELECT remark FROM wor_service_request WHERE based_on_id = T1.id AND based_on_table = #{MED_MEDICATION_REQUEST} AND delete_flag = '0' LIMIT 1) AS remark + , T1.content_json::jsonb ->> 'remark' AS remark FROM med_medication_request AS T1 LEFT JOIN med_medication_definition AS T2 ON T2.ID = T1.medication_id AND T2.delete_flag = '0' @@ -578,7 +578,7 @@ T1.patient_id AS patient_id, 'med_medication_definition' AS advice_table_name, T3.ID AS advice_definition_id - , (SELECT remark FROM wor_service_request WHERE based_on_id = T2.id AND based_on_table = #{MED_MEDICATION_REQUEST} AND delete_flag = '0' LIMIT 1) AS remark + , T1.content_json::jsonb ->> 'remark' AS remark FROM adm_charge_item AS T1 INNER JOIN med_medication_request AS T2 ON T2.ID = T1.service_id AND T2.delete_flag = '0' LEFT JOIN med_medication_definition AS T3 ON T3.ID = T2.medication_id AND T3.delete_flag = '0' @@ -694,7 +694,7 @@ T1.patient_id AS patient_id, 'adm_device_definition' AS advice_table_name, T1.device_def_id AS advice_definition_id - , (SELECT remark FROM wor_service_request WHERE based_on_id = T1.id AND based_on_table = #{WOR_DEVICE_REQUEST} AND delete_flag = '0' LIMIT 1) AS remark + , T1.content_json::jsonb ->> 'remark' AS remark FROM wor_device_request AS T1 LEFT JOIN adm_device_definition AS T2 ON T2.ID = T1.device_def_id AND T2.delete_flag = '0' diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml index 4a8bf8e28..aa1c15631 100755 --- a/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/AdviceManageAppMapper.xml @@ -218,7 +218,7 @@ T1.sort_number AS sort_number, T1.based_on_id AS based_on_id, T1.medication_id AS advice_definition_id, - (SELECT remark FROM wor_service_request WHERE based_on_id = T1.id AND based_on_table = #{MED_MEDICATION_REQUEST} AND delete_flag = '0' LIMIT 1) AS remark + T1.content_json::jsonb ->> 'remark' AS remark FROM med_medication_request AS T1 LEFT JOIN med_medication_definition AS T2 ON T2.ID = T1.medication_id AND T2.delete_flag = '0' @@ -272,7 +272,7 @@ 99 AS sort_number, T1.based_on_id AS based_on_id, T1.device_def_id AS advice_definition_id, - (SELECT remark FROM wor_service_request WHERE based_on_id = T1.id AND based_on_table = #{WOR_DEVICE_REQUEST} AND delete_flag = '0' LIMIT 1) AS remark + T1.content_json::jsonb ->> 'remark' AS remark FROM wor_device_request AS T1 LEFT JOIN adm_device_definition AS T2 ON T2.ID = T1.device_def_id AND T2.delete_flag = '0'