From 814bfff8b5810fc8b9328dd899dd1df1a671e61f Mon Sep 17 00:00:00 2001 From: liuhongrui Date: Thu, 20 Mar 2025 16:26:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E6=B6=B2=E4=BF=A1=E6=81=AFup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OutpatientInfusionRecordServiceImpl.java | 127 +++++++++++++----- .../dto/OutpatientInfusionRecordDto.java | 4 - .../OutpatientManageMapper.xml | 5 +- 3 files changed, 91 insertions(+), 45 deletions(-) diff --git a/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/appservice/impl/OutpatientInfusionRecordServiceImpl.java b/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/appservice/impl/OutpatientInfusionRecordServiceImpl.java index a8c0dcc4..ce79dc17 100644 --- a/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/appservice/impl/OutpatientInfusionRecordServiceImpl.java +++ b/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/appservice/impl/OutpatientInfusionRecordServiceImpl.java @@ -24,7 +24,6 @@ import com.openhis.administration.service.IPractitionerRoleService; import com.openhis.administration.service.IPractitionerService; import com.openhis.common.constant.CommonConstants; import com.openhis.common.enums.AdministrativeGender; -import com.openhis.common.enums.ClinicalStatus; import com.openhis.common.enums.EventStatus; import com.openhis.common.enums.Whether; import com.openhis.common.utils.EnumUtils; @@ -103,7 +102,10 @@ public class OutpatientInfusionRecordServiceImpl implements IOutpatientInfusionR public List getPatientInfusionRecord( OutpatientInfusionPatientDto outpatientInfusionPatientDto, HttpServletRequest request) { - if (outpatientInfusionPatientDto == null && outpatientInfusionPatientDto.getPatientId() != null) { + // 参数不能为空 + if (outpatientInfusionPatientDto == null) { + return null; + } else if (outpatientInfusionPatientDto.getPatientId() == null) { return null; } @@ -145,6 +147,13 @@ public class OutpatientInfusionRecordServiceImpl implements IOutpatientInfusionR Map> groupedRecords = outpatientInfusionRecordDtoList.stream() .collect(Collectors.groupingBy(OutpatientInfusionRecordDto::getGroupId)); + // 按 serviceId 分组 + Map> serviceRecords = outpatientInfusionRecordDtoList.stream() + .collect(Collectors.groupingBy(OutpatientInfusionRecordDto::getServiceId)); + + // 构造批量插入的 ServiceRequest 列表 + List serviceRequests = new ArrayList<>(); + // 遍历每个分组 for (Map.Entry> entry : groupedRecords.entrySet()) { List groupRecords = entry.getValue(); @@ -158,12 +167,10 @@ public class OutpatientInfusionRecordServiceImpl implements IOutpatientInfusionR return false; } - // 构造批量插入的 ServiceRequest 列表 - List serviceRequests = new ArrayList<>(); for (OutpatientInfusionRecordDto record : groupRecords) { - //判断当前组药品状态不是已领药,有未领药的数据,跳过执行下一组数据 - if(record.getMedicationStatusEnum() != EventStatus.COMPLETED.getValue()){ + // 判断当前组药品状态不是已领药,有未领药的数据,跳过执行下一组数据 + if (!(record.getMedicationStatusEnum() == EventStatus.COMPLETED.getValue())) { // 跳过当前分组的剩余处理,继续下一个分组 break; } @@ -187,41 +194,91 @@ public class OutpatientInfusionRecordServiceImpl implements IOutpatientInfusionR serviceRequests.add(serviceRequest); } } - // 使用 MyBatis-Plus 的 saveBatch 方法批量插入 - if (!serviceRequestService.saveBatch(serviceRequests)) { - return false; // 如果批量插入失败,返回 false - } - // 更新分组中每个记录的状态 - for (OutpatientInfusionRecordDto record : groupRecords) { - String prefixBusNo = record.getBusNo() + "." + record.getGroupId() + "." + record.getMedicationId(); - // 获取执行次数 - Long exeCount = - outpatientManageMapper.countExecuteNumOrGroupNum(record.getServiceId(), prefixBusNo, null, true); - - // 执行完毕后,更新执行服务请求表的状态 - if (exeCount.equals(record.getExecuteNum())) { - if (!updateRecordStatus(record.getServiceId())) { - return false; // 如果更新状态失败,返回 false - } - } - } } - // 所有分组都执行成功 + + // 使用 MyBatis-Plus 的 saveBatch 方法批量插入 + if (!serviceRequestService.saveBatch(serviceRequests)) { + return false; // 如果批量插入失败,返回 false + } + // 批量更新执行状态 + if (!checkServiceRequestIsCompleted(serviceRecords)) { + return false; // 如果批量耿欣失败,返回 false + } + return true; + } /** - * 更新执行状态 + * 检查该条服务申请的所有输液信息都完成 * - * @param serviceId 服务请求ID + * @param serviceRecords 同一个服务请求的输液信息列表 + * @return 更新成功/失败 + */ + public boolean checkServiceRequestIsCompleted(Map> serviceRecords) { + + // 存储更新的serviceId + List serviceIds = new ArrayList<>(); + + // 遍历每个分组 + for (Map.Entry> entry : serviceRecords.entrySet()) { + // 获取当前分组的 serviceId + Long serviceId = entry.getKey(); + // 获取当前分组的记录列表 + List groupRecords = entry.getValue(); + + // 创建一个数组来记录每个记录是否满足条件 + int[] flags = new int[serviceRecords.size()]; + int index = 0; // 用于记录当前索引 + + for (OutpatientInfusionRecordDto record : groupRecords) { + String prefixBusNo = record.getBusNo() + "." + record.getGroupId() + "." + record.getMedicationId(); + // 获取执行次数 + Long exeCount = outpatientManageMapper.countExecuteNumOrGroupNum(serviceId, prefixBusNo, null, true); + + // 判断是否满足条件 + if (exeCount.equals(record.getExecuteNum())) { + flags[index] = 1; // 如果满足条件,设置为 1 + } else { + flags[index] = 0; // 如果不满足条件,设置为 0 + } + index++; + } + + // 使用与运算判断最终结果 + int result = 1; + for (int flag : flags) { + result &= flag; // 与运算 + } + + // 如果最终结果为 1,表示所有记录都满足条件,即当前服务请求的数据全部被执行 + if (result == 1) { + serviceIds.add(serviceId); + } + + } + + return batchUpdateRecordStatus(serviceIds); + } + + /** + * 批量更新执行状态 + * + * @param serviceIds 服务请求ID列表 * @return 修改成功/失败 */ - public boolean updateRecordStatus(Long serviceId) { + public boolean batchUpdateRecordStatus(List serviceIds) { + if (serviceIds == null || serviceIds.isEmpty()) { + return false; // 如果传入的列表为空,直接返回失败 + } + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(ServiceRequest::getId, serviceId).set(ServiceRequest::getStatusEnum, + // 使用 IN 条件匹配多个 serviceId + updateWrapper.in(ServiceRequest::getId, serviceIds).set(ServiceRequest::getStatusEnum, EventStatus.COMPLETED.getValue()); int countUpdate = serviceRequestMapper.update(null, updateWrapper); + // 如果更新的记录数大于 0,返回 true return countUpdate > 0; } @@ -240,7 +297,7 @@ public class OutpatientInfusionRecordServiceImpl implements IOutpatientInfusionR DateUtils.parseDate(outpatientInfusionRecordDto.getOccurrenceEndTime())); int countUpdate = serviceRequestMapper.update(null, updateWrapper); - return countUpdate < 0 ? false : true; + return countUpdate >= 0; } @@ -283,15 +340,11 @@ public class OutpatientInfusionRecordServiceImpl implements IOutpatientInfusionR // 性别 e.setGenderEnum_enumText(EnumUtils.getInfoByValue(AdministrativeGender.class, e.getGenderEnum())); // 药品状态 - e.setClinicalStatusEnum_enumText(EnumUtils.getInfoByValue(EventStatus.class, e.getMedicationStatusEnum())); + e.setMedicationStatusEnum_enumText( + EnumUtils.getInfoByValue(EventStatus.class, e.getMedicationStatusEnum())); // 皮试标志 e.setSkinTestFlag_enumText(EnumUtils.getInfoByValue(Whether.class, e.getSkinTestFlag())); - // 只有皮试药品才显示皮试结果 - if (e.getSkinTestFlag() == Whether.YES.getValue()) { - // 皮试结果 - e.setMedicationStatusEnum_enumText( - EnumUtils.getInfoByValue(ClinicalStatus.class, e.getClinicalStatusEnum())); - } + }); return infusionPerformList; diff --git a/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/dto/OutpatientInfusionRecordDto.java b/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/dto/OutpatientInfusionRecordDto.java index 022b49b1..e9228231 100644 --- a/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/dto/OutpatientInfusionRecordDto.java +++ b/openhis-server/openhis-application/src/main/java/com/openhis/web/outpatientmanage/dto/OutpatientInfusionRecordDto.java @@ -118,10 +118,6 @@ public class OutpatientInfusionRecordDto { private Integer skinTestFlag; private String skinTestFlag_enumText; - /** 皮试结果 */ - private Integer clinicalStatusEnum; - private String clinicalStatusEnum_enumText; - /** 开单时间 */ private Date createTime; diff --git a/openhis-server/openhis-application/src/main/resources/mapper/outpatientmanage/OutpatientManageMapper.xml b/openhis-server/openhis-application/src/main/resources/mapper/outpatientmanage/OutpatientManageMapper.xml index 8c1f76d8..96afe984 100644 --- a/openhis-server/openhis-application/src/main/resources/mapper/outpatientmanage/OutpatientManageMapper.xml +++ b/openhis-server/openhis-application/src/main/resources/mapper/outpatientmanage/OutpatientManageMapper.xml @@ -151,7 +151,7 @@ sr.prescription_no, --处方号 sr.encounter_id, e.bus_no as encounter_bus_no, --就诊号 - TO_CHAR(pt.birth_date, 'YYYY-MM-DD') AS birth_date , --病人生日 + TO_CHAR(pt.birth_date, 'YYYY-MM-DD') AS birth_date, --病人生日 pt.bus_no AS patient_bus_no, --病人ID(前台显示用) sr.patient_id, --病人ID pt.name AS patient_name, --病人姓名 @@ -197,7 +197,6 @@ T1.medication_quantity, T1.medication_status_Enum, T1.group_id, - T1.clinical_status_enum, T1.skin_test_flag, T1.speed, T1.method_code, @@ -234,7 +233,6 @@ WHEN 1 THEN 1 ELSE 0 END AS skin_test_flag ,--皮试标志 - ai.clinical_status_enum, --皮试检查结果 mr.speed, --输液速度 mr.method_code,--用法 mr.dose || ' '|| mr.dose_unit_code AS dose,--单次剂量,剂量单位 @@ -276,7 +274,6 @@ LEFT JOIN med_medication_request mr ON mr.prescription_no = sr.prescription_no LEFT JOIN med_medication m ON m.id = mr.medication_id LEFT JOIN med_medication_definition md ON md.id = m.medication_def_id - LEFT JOIN cli_allergy_intolerance ai ON ai.request_id = sr.id ad.bus_no = 'sy001' -- 输液检查的编号,todo:编号未定,后期修改 AND mr.infusion_flag = 1