| | |
| | | import cn.lihu.jh.module.ecg.feign.FeeConfirmFeignService; |
| | | import cn.lihu.jh.module.ecg.service.queue.QueueServiceTxFunctions; |
| | | import cn.lihu.jh.module.ecg.webservice.WebServiceClient; |
| | | import cn.lihu.jh.module.infra.dal.dataobject.config.ConfigDO; |
| | | import cn.lihu.jh.module.infra.dal.mysql.config.ConfigMapper; |
| | | import cn.lihu.jh.module.infra.service.config.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | |
| | | @Resource |
| | | CheckTypeMapper checkTypeMapper; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Autowired |
| | | private WebServiceClient webServiceClient; |
| | | |
| | | @Value("${spring.profiles.active}") |
| | | private String active; |
| | | |
| | | |
| | | @Override |
| | |
| | | throw exception(DEV_INSTALL_EXCEPTION); |
| | | } |
| | | |
| | | rent_id = devRentDOList.getFirst().getId(); |
| | | rent_id = devRentDOList.get(0).getId(); |
| | | createReqVO.setId(rent_id); |
| | | createReqVO.setState(DevRentStateEnum.ROUTINE_FINISH.getState()); |
| | | updateDevRent(createReqVO); |
| | |
| | | //queueMapper.updateBedQueueStatus(createReqVO.getRoomId(), createReqVO.getBedNo(), |
| | | // QueueStatusEnum.ONSTAGE.getStatus(), QueueStatusEnum.FINISH.getStatus()); |
| | | |
| | | QueueDO firstOnStageQueueItem = queueMapper.getBedFirstQueueItemByStatus(createReqVO.getRoomId(), createReqVO.getBedNo(), QueueStatusEnum.ONSTAGE.getStatus()); |
| | | // QueueStatusEnum.ONSTAGE => QueueStatusEnum.FINISH |
| | | firstOnStageQueueItem.setStatus(QueueStatusEnum.FINISH.getStatus()); // 默认状态 设置 |
| | | queueMapper.updateById(firstOnStageQueueItem); |
| | | // 【缺陷修复】原实现: |
| | | // QueueDO firstOnStageQueueItem = queueMapper.getBedFirstQueueItemByStatus( |
| | | // roomId, bedNo, ONSTAGE); |
| | | // firstOnStageQueueItem.setStatus(FINISH); // ← 取不到时为 null,直接 NPE |
| | | // |
| | | // 两个问题: |
| | | // 1) NPE:该工位当前没有"就诊中(30)"患者时返回 null(例如医生先点了"放弃检查", |
| | | // cancelRoutineOperation 已把该患者置为 40),第 159 行空指针 → 整个事务回滚。 |
| | | // 2) 误伤:只按"工位 + 状态取 seq_num 最小的一条",若期间已叫了下一位患者, |
| | | // 会把**下一位患者**误置为"已就诊(40)"。 |
| | | // |
| | | // 修复策略(按可靠性从高到低): |
| | | // ① 优先按 patId + checkType 精确匹配(前端 submitForm 传的 formData 含这两个字段); |
| | | // ② 退化到"工位 + 状态 + 今日"取 update_time 最新的一条(比 seq_num 最小更贴合当前患者); |
| | | // ③ 仍取不到 → 记警告并**跳过队列更新**,而不是抛 NPE 让整个"检查完成"失败。 |
| | | // 此时设备归还、作业记录等仍会正常保存(数据不丢),仅队列状态未变。 |
| | | QueueDO onStageQueueItem = null; |
| | | |
| | | // 检查项目.亲和性 处理逻辑 |
| | | CheckTypeDO checkTypeDO = queueServiceTxFunctions.getCheckTypeItem(firstOnStageQueueItem.getBookCheckType()); |
| | | if (checkTypeDO.getAffinityCheckTypes().length > 0) { |
| | | procAffinityWhenRoutineFinish(firstOnStageQueueItem.getPatId(), checkTypeDO.getAffinityCheckTypes()); |
| | | // ① 精确定位(用 Spring 的 StringUtils,避免额外依赖; |
| | | // 本模块未引入 commons-lang3,勿用 org.apache.commons.lang3.StringUtils) |
| | | if (org.springframework.util.StringUtils.hasText(createReqVO.getPatId()) |
| | | && null != createReqVO.getCheckType()) { |
| | | onStageQueueItem = queueMapper.getBedQueueItemByPatAndStatus( |
| | | createReqVO.getRoomId(), createReqVO.getBedNo(), |
| | | createReqVO.getPatId(), createReqVO.getCheckType(), |
| | | QueueStatusEnum.ONSTAGE.getStatus()); |
| | | } |
| | | |
| | | // ② 退化:取该工位今日最近更新的一条"就诊中" |
| | | if (null == onStageQueueItem) { |
| | | onStageQueueItem = queueMapper.getBedLatestQueueItemByStatus( |
| | | createReqVO.getRoomId(), createReqVO.getBedNo(), QueueStatusEnum.ONSTAGE.getStatus()); |
| | | if (null != onStageQueueItem) { |
| | | log.warn("[routineFinish] 未按 patId 命中,退化为按工位取最近就诊中患者. " |
| | | + "roomId={} bedNo={} reqPatId={} reqCheckType={} 实际patId={} checkType={}", |
| | | createReqVO.getRoomId(), createReqVO.getBedNo(), createReqVO.getPatId(), |
| | | createReqVO.getCheckType(), onStageQueueItem.getPatId(), |
| | | onStageQueueItem.getBookCheckType()); |
| | | } |
| | | } |
| | | |
| | | // ③ 仍取不到:跳过队列更新,不抛异常(保证"检查完成"本身可用) |
| | | if (null == onStageQueueItem) { |
| | | log.warn("[routineFinish] 该工位无[就诊中]患者,跳过队列状态更新. roomId={} bedNo={} patId={} applyNo={}", |
| | | createReqVO.getRoomId(), createReqVO.getBedNo(), |
| | | createReqVO.getPatId(), createReqVO.getApplyNo()); |
| | | } else { |
| | | // QueueStatusEnum.ONSTAGE => QueueStatusEnum.FINISH |
| | | onStageQueueItem.setStatus(QueueStatusEnum.FINISH.getStatus()); |
| | | queueMapper.updateById(onStageQueueItem); |
| | | |
| | | // 检查项目.亲和性 处理逻辑 |
| | | CheckTypeDO checkTypeDO = queueServiceTxFunctions.getCheckTypeItem(onStageQueueItem.getBookCheckType()); |
| | | if (null != checkTypeDO && null != checkTypeDO.getAffinityCheckTypes() |
| | | && checkTypeDO.getAffinityCheckTypes().length > 0) { |
| | | procAffinityWhenRoutineFinish(onStageQueueItem.getPatId(), checkTypeDO.getAffinityCheckTypes()); |
| | | } |
| | | } |
| | | |
| | | //检查完成后,此时检查登记写成了,需要将这个回写给集成平台(线上环境才回写) |
| | | if (active.equals("prod")) { |
| | | ConfigDO configDO = configService.getConfigByKey("ecg.back.data"); |
| | | if (configDO.getValue().equals("1")) { |
| | | if (createReqVO.getCheckType() != 100 && createReqVO.getCheckType() != 1000 && createReqVO.getCheckType() != 1100 && createReqVO.getCheckType() != 1400 && createReqVO.getCheckType() != 1500) { |
| | | AppointmentDO appointmentDO = appointmentMapper.getByApplyNo(createReqVO.getApplyNo()); |
| | | ApplicationTemplate app = new ApplicationTemplate(); |
| | | String action = "S0405"; |
| | | String message = app.getXML(createReqVO.getApplyNo(), "4", "取消检查", createReqVO.getOperater(), appointmentDO.getPatDeptCode(), appointmentDO.getPatDeptDesc(), appointmentDO.getPatWardCode(), appointmentDO.getPatWardDesc(), appointmentDO.getPatBedNo(), appointmentDO.getEpisodeId(), "" + appointmentDO.getBookSrc(), appointmentDO.getPatId(), appointmentDO.getPatName()); |
| | | String message = app.getXML(createReqVO.getApplyNo(), "3", "检查登记", createReqVO.getOperater(), appointmentDO.getPatDeptCode(), appointmentDO.getPatDeptDesc(), appointmentDO.getPatWardCode(), appointmentDO.getPatWardDesc(), appointmentDO.getPatBedNo(), appointmentDO.getEpisodeId(), "" + appointmentDO.getBookSrc(), appointmentDO.getPatId(), appointmentDO.getPatName()); |
| | | String s = webServiceClient.callJHFWTYRK(action, "", message); |
| | | log.info("routineFinishWebServiceClient的返回值为:{}", s); |
| | | if (s.contains("更新成功")) { |
| | | //需要根据applyNo,将appiontment表里的status改成3 |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "4"); |
| | | // 【诊断日志】同 AppointmentServiceImpl#handleAppointmentStatusUpdate: |
| | | // 打印日期对象类型与值,便于定位 register_date 被写成 00:00:00 的写入方。 |
| | | java.util.Date regNow = new Date(); |
| | | log.info("[devRentCreate][登记时间写入] applyNo={} 日期对象类型={} 值={}", |
| | | createReqVO.getApplyNo(), regNow.getClass().getName(), |
| | | new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(regNow)); |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "3", regNow); |
| | | } |
| | | } else { |
| | | //检查类型是床边的或常规的,需要根据applyNo,将appiontment表里的status改成7 |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "7"); |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "7", null); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //设备领取完成后,此时检查登记写成了,需要将这个回写给集成平台(线上环境才回写) |
| | | if (active.equals("prod")) { |
| | | ConfigDO configDO = configService.getConfigByKey("ecg.back.data"); |
| | | if (configDO.getValue().equals("1")) { |
| | | AppointmentDO appointmentDO = appointmentMapper.getByApplyNo(createReqVO.getApplyNo()); |
| | | ApplicationTemplate app = new ApplicationTemplate(); |
| | | String action = "S0405"; |
| | |
| | | log.info("webservice的返回值为:{}", s); |
| | | if (s.contains("更新成功")) { |
| | | //需要根据applyNo,将appiontment表里的status改成3 |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "3"); |
| | | // 【诊断日志】同上:打印日期对象类型与值 |
| | | java.util.Date regNow2 = new Date(); |
| | | log.info("[devRentOther][登记时间写入] applyNo={} 日期对象类型={} 值={}", |
| | | createReqVO.getApplyNo(), regNow2.getClass().getName(), |
| | | new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(regNow2)); |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "3", regNow2); |
| | | } |
| | | } |
| | | List<Integer> jobTypeList = new ArrayList<Integer>(); |
| | |
| | | throw exception(DEV_INSTALL_EXCEPTION); |
| | | } |
| | | |
| | | rent_id = devRentDOList.getFirst().getId(); |
| | | rent_id = devRentDOList.get(0).getId(); |
| | | createReqVO.setId(rent_id); |
| | | createReqVO.setState(DevRentStateEnum.RECEIVED.getState()); |
| | | updateDevRent(createReqVO); |
| | |
| | | throw exception(DEV_INSTALL_EXCEPTION); |
| | | } |
| | | |
| | | rent_id = devRentDOList.getFirst().getId(); |
| | | rent_id = devRentDOList.get(0).getId(); |
| | | createReqVO.setId(rent_id); |
| | | createReqVO.setState(DevRentStateEnum.INSTALLED.getState()); |
| | | updateDevRent(createReqVO); |
| | |
| | | List<DevRentDO> devRentDOList = devRentMapper.selectByPatAndChecktypeAndState(createReqVO.getPatId(), createReqVO.getCheckType(), DevRentStateEnum.FREE.getState()); |
| | | if (devRentDOList.size() != 1) throw exception(ROUTINE_CHECK_EXIST); |
| | | |
| | | rent_id = devRentDOList.getFirst().getId(); |
| | | rent_id = devRentDOList.get(0).getId(); |
| | | createReqVO.setId(rent_id); |
| | | createReqVO.setState(DevRentStateEnum.ROUTINE_CANCELLED.getState()); |
| | | updateDevRent(createReqVO); |
| | | |
| | | if (active.equals("prod")) { |
| | | ConfigDO configDO = configService.getConfigByKey("ecg.back.data"); |
| | | if (configDO.getValue().equals("1")) { |
| | | if (cancelReqVO.getCheckType() != 100 && cancelReqVO.getCheckType() != 1000 && cancelReqVO.getCheckType() != 1100 && cancelReqVO.getCheckType() != 1400 && cancelReqVO.getCheckType() != 1500) { |
| | | AppointmentDO appointmentDO = appointmentMapper.getByApplyNo(createReqVO.getApplyNo()); |
| | | ApplicationTemplate app = new ApplicationTemplate(); |
| | |
| | | log.info("routineFinishWebServiceClient的返回值为:{}", s); |
| | | if (s.contains("更新成功")) { |
| | | //需要根据applyNo,将appiontment表里的status改成3 |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "4"); |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "4", null); |
| | | } |
| | | } else { |
| | | //检查类型是床边的或常规的,需要根据applyNo,将appiontment表里的status改成7 |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "7"); |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "7", null); |
| | | } |
| | | } |
| | | |
| | |
| | | List<DevRentDO> devRentDOList = devRentMapper.selectByPatAndChecktypeAndState(createReqVO.getPatId(), createReqVO.getCheckType(), DevRentStateEnum.FREE.getState()); |
| | | if (devRentDOList.size() != 1) throw exception(DEV_INSTALL_EXIST); |
| | | |
| | | rent_id = devRentDOList.getFirst().getId(); |
| | | rent_id = devRentDOList.get(0).getId(); |
| | | createReqVO.setId(rent_id); |
| | | createReqVO.setState(DevRentStateEnum.RECEIVED_CANCELLED.getState()); |
| | | updateDevRent(createReqVO); |
| | | |
| | | if (active.equals("prod")) { |
| | | ConfigDO configDO = configService.getConfigByKey("ecg.back.data"); |
| | | if (configDO.getValue().equals("1")) { |
| | | AppointmentDO appointmentDO = appointmentMapper.getByApplyNo(createReqVO.getApplyNo()); |
| | | ApplicationTemplate app = new ApplicationTemplate(); |
| | | String action = "S0405"; |
| | |
| | | log.info("routineFinishWebServiceClient的返回值为:{}", s); |
| | | if (s.contains("更新成功")) { |
| | | //需要根据applyNo,将appiontment表里的status改成3 |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "4"); |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "4", null); |
| | | } |
| | | } |
| | | |
| | |
| | | List<DevRentDO> devRentDOList = devRentMapper.selectByPatAndChecktypeAndState(createReqVO.getPatId(), createReqVO.getCheckType(), DevRentStateEnum.RECEIVED.getState()); |
| | | if (devRentDOList.size() != 1) throw exception(DEV_INSTALL_EXIST); |
| | | |
| | | rent_id = devRentDOList.getFirst().getId(); |
| | | rent_id = devRentDOList.get(0).getId(); |
| | | createReqVO.setId(rent_id); |
| | | createReqVO.setState(DevRentStateEnum.INSTALL_CANCELLED.getState()); |
| | | updateDevRent(createReqVO); |
| | | |
| | | if (active.equals("prod")) { |
| | | ConfigDO configDO = configService.getConfigByKey("ecg.back.data"); |
| | | if (configDO.getValue().equals("1")) { |
| | | AppointmentDO appointmentDO = appointmentMapper.getByApplyNo(createReqVO.getApplyNo()); |
| | | ApplicationTemplate app = new ApplicationTemplate(); |
| | | String action = "S0405"; |
| | |
| | | log.info("routineFinishWebServiceClient的返回值为:{}", s); |
| | | if (s.contains("更新成功")) { |
| | | //需要根据applyNo,将appiontment表里的status改成3 |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "4"); |
| | | appointmentMapper.updateStatusByApplyNo(createReqVO.getApplyNo(), "4", null); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public DevRentDO getDevRent(Long id) { |
| | | return devRentMapper.selectById(id); |
| | | DevRentDO devRentDO = devRentMapper.selectById(id); |
| | | fillPatientInfo(devRentDO); |
| | | return devRentDO; |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<DevRentDO> getDevRentPage(DevRentPageReqVO pageReqVO) { |
| | | pageReqVO.setState(0); |
| | | return devRentMapper.selectPage(pageReqVO); |
| | | PageResult<DevRentDO> pageResult = devRentMapper.selectPage(pageReqVO); |
| | | fillPatientInfo(pageResult.getList()); |
| | | return pageResult; |
| | | } |
| | | |
| | | @Override |
| | |
| | | stateList.add(DevRentStateEnum.INSTALLED.getState()); |
| | | stateList.add(DevRentStateEnum.RECEIVED.getState()); |
| | | searchReqVO.setStateList(stateList); |
| | | return devRentMapper.getRentByState(searchReqVO); |
| | | DevRentDO devRentDO = devRentMapper.getRentByState(searchReqVO); |
| | | fillPatientInfo(devRentDO); |
| | | return devRentDO; |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<Integer> stateList = new ArrayList<>(); |
| | | stateList.add(DevRentStateEnum.FREE.getState()); |
| | | searchReqVO.setStateList(stateList); |
| | | return devRentMapper.getRentByState(searchReqVO); |
| | | DevRentDO devRentDO = devRentMapper.getRentByState(searchReqVO); |
| | | fillPatientInfo(devRentDO); |
| | | return devRentDO; |
| | | } |
| | | |
| | | @Override |
| | |
| | | stateList.add(DevRentStateEnum.RECEIVED.getState()); |
| | | stateList.add(DevRentStateEnum.RECEIVED_CANCELLED.getState()); |
| | | searchReqVO.setStateList(stateList); |
| | | return devRentMapper.getRentByState(searchReqVO); |
| | | DevRentDO devRentDO = devRentMapper.getRentByState(searchReqVO); |
| | | fillPatientInfo(devRentDO); |
| | | return devRentDO; |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<Integer> stateList = new ArrayList<>(); |
| | | stateList.add(DevRentStateEnum.DISMANTLED.getState()); |
| | | searchReqVO.setStateList(stateList); |
| | | return devRentMapper.getRentByState(searchReqVO); |
| | | DevRentDO devRentDO = devRentMapper.getRentByState(searchReqVO); |
| | | fillPatientInfo(devRentDO); |
| | | return devRentDO; |
| | | } |
| | | |
| | | // ==================== 需求1:回填患者信息 18 项 ==================== |
| | | // dev_rent 表只存了 applyNo / patName / patDetails, |
| | | // 其余患者信息(性别、出生日期、病区、床号、电话、来源、就诊卡号、 |
| | | // 登记时间、开单医师、开单日期、多耐药)都在 appointment 表。 |
| | | // |
| | | // 参照 QueueServiceImpl#fillAppointmentInfo 的做法:查询后按 applyNo 回查预约单补齐。 |
| | | // 这样领用/装机/拆机/数据录入/检查记录 5 个界面才能展示完整患者信息。 |
| | | |
| | | /** |
| | | * 回填单个对象的患者信息(对象为 null 或 applyNo 为空时安全跳过)。 |
| | | */ |
| | | private void fillPatientInfo(DevRentDO devRentDO) { |
| | | if (null == devRentDO || !org.springframework.util.StringUtils.hasText(devRentDO.getApplyNo())) { |
| | | return; |
| | | } |
| | | AppointmentDO appointment = appointmentMapper.getByApplyNo(devRentDO.getApplyNo()); |
| | | if (null == appointment) { |
| | | return; |
| | | } |
| | | applyAppointmentToDevRent(devRentDO, appointment); |
| | | } |
| | | |
| | | /** |
| | | * 批量回填(避免 N+1 之外的额外开销由调用方控制;此处逐条回查, |
| | | * 与 QueueServiceImpl#fillAppointmentInfo 保持一致的做法)。 |
| | | */ |
| | | private void fillPatientInfo(List<DevRentDO> devRentDOList) { |
| | | if (null == devRentDOList || devRentDOList.isEmpty()) { |
| | | return; |
| | | } |
| | | devRentDOList.forEach(this::fillPatientInfo); |
| | | } |
| | | |
| | | /** |
| | | * 把预约单中的患者信息复制到 dev_rent 对象。 |
| | | * <p> |
| | | * 注意:只覆盖**为空的**平铺字段?——不,这里直接覆盖: |
| | | * 这些字段均标记为 {@code @TableField(exist=false)},不参与写库, |
| | | * 本次查询返回的就是最新数据,不存在"覆盖掉用户刚录入的值"的风险。 |
| | | */ |
| | | private void applyAppointmentToDevRent(DevRentDO target, AppointmentDO source) { |
| | | target.setPatGender(source.getPatGender()); |
| | | target.setPatBirthday(source.getPatBirthday()); |
| | | target.setRegisterDate(source.getRegisterDate()); |
| | | target.setDoctor(source.getDoctor()); |
| | | target.setDoctorTime(source.getDoctorTime()); |
| | | target.setPatSrc(source.getPatSrc()); |
| | | target.setPatMobile(source.getPatMobile()); |
| | | target.setPatPhone(source.getPatPhone()); |
| | | target.setPatWardDesc(source.getPatWardDesc()); |
| | | target.setPatBedNo(source.getPatBedNo()); |
| | | target.setMedicalCard(source.getMedicalCard()); |
| | | if (target.getDoctorAdviceNo() == null) target.setDoctorAdviceNo(source.getDoctorAdviceNo()); |
| | | target.setOutpatientNo(source.getOutpatientNo()); |
| | | target.setPatIdentityId(source.getPatIdentityId()); |
| | | target.setTolerance(source.getTolerance()); |
| | | } |
| | | |
| | | // 确费处理 |