| | |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.checktype.CheckTypeDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.appointment.AppointmentMapper; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.checktype.CheckTypeMapper; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.devrent.DevRentMapper; |
| | | import cn.lihu.jh.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.lihu.jh.module.ecg.enums.DevRentStateEnum; |
| | | import cn.lihu.jh.module.system.api.oauth2.OAuth2TokenApi; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | |
| | | @Resource |
| | | private DevRentMapper devRentMapper; |
| | | |
| | | /** |
| | | * 用于「设备领用/装机」取数时过滤出 {@code need_dev_ready = 1} 的检查项目 |
| | | * (见 {@link #filterNeedDevReady})。 |
| | | */ |
| | | @Resource |
| | | private CheckTypeMapper checkTypeMapper; |
| | | |
| | | ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); |
| | | |
| | |
| | | * queue 表不存这些字段,但医生端列表接口需要展示,所以查询后按 applyNo 回查预约单填充: |
| | | * 多耐药、性别、出生日期、登记时间、开单医师、开单日期。 |
| | | */ |
| | | private void fillAppointmentInfo(List<QueueDO> queueDOList) { |
| | | @Override |
| | | public void fillAppointmentInfo(List<QueueDO> queueDOList) { |
| | | if (CollectionUtils.isEmpty(queueDOList)) { |
| | | return; |
| | | } |
| | |
| | | return; |
| | | } |
| | | queueDO.setTolerance(appointment.getTolerance()); |
| | | // 需求2:床边标记(HIS zdy.ISCB)。queue 表已有该列, |
| | | // 但对「22_* 脚本执行前就已入队」的行,靠这里回查补填,保证屏幕/页面能看到。 |
| | | if (queueDO.getIsBedside() == null) { |
| | | queueDO.setIsBedside(appointment.getIsBedside()); |
| | | } |
| | | queueDO.setPatGender(appointment.getPatGender()); |
| | | queueDO.setPatBirthday(appointment.getPatBirthday()); |
| | | queueDO.setRegisterDate(appointment.getRegisterDate()); |
| | | queueDO.setDoctor(appointment.getDoctor()); |
| | | queueDO.setDoctorTime(appointment.getDoctorTime()); |
| | | // 需求1:补平铺的患者信息来源字段(病历区/床号/电话/来源/就诊卡号等) |
| | | queueDO.setPatSrc(appointment.getPatSrc()); |
| | | queueDO.setPatMobile(appointment.getPatMobile()); |
| | | queueDO.setPatPhone(appointment.getPatPhone()); |
| | | queueDO.setPatWardDesc(appointment.getPatWardDesc()); |
| | | queueDO.setPatBedNo(appointment.getPatBedNo()); |
| | | queueDO.setMedicalCard(appointment.getMedicalCard()); |
| | | queueDO.setDoctorAdviceNo(appointment.getDoctorAdviceNo()); |
| | | queueDO.setOutpatientNo(appointment.getOutpatientNo()); |
| | | queueDO.setPatIdentityId(appointment.getPatIdentityId()); |
| | | }); |
| | | } |
| | | |
| | |
| | | patientStatisticVO.setReadyNum(item.getTotalInStatus()); |
| | | } else if (QueueStatusEnum.FINISH.getStatus() == item.getStatus()) { |
| | | patientStatisticVO.setFinishedNum(item.getTotalInStatus()); |
| | | } else if (QueueStatusEnum.PASSED.getStatus() == item.getStatus()) { |
| | | patientStatisticVO.setPassedNum(item.getTotalInStatus()); |
| | | } else if (QueueStatusEnum.PASSED.getStatus() == item.getStatus() |
| | | || QueueStatusEnum.PASSED_WAITING.getStatus() == item.getStatus()) { |
| | | // 【需求4 口径统一】过号 = 已过号(5) + 已过号-排队(3)。 |
| | | // 原先只算 5,而列表与屏幕都含 3,导致"过号"数字比实际少。 |
| | | int cur = patientStatisticVO.getPassedNum() == null ? 0 : patientStatisticVO.getPassedNum(); |
| | | patientStatisticVO.setPassedNum(cur + item.getTotalInStatus()); |
| | | } |
| | | }); |
| | | |
| | | // 统计 该工位类型的【排队中】人员数量 |
| | | // 【Q7 确认】此处刻意统计**全项目**(该工位所含检查类型)的"排队中"总数, |
| | | // 语义为"全院还有多少人等着做这类检查",与"本工位一眼可见的候诊人数"互补。 |
| | | // 且已补 deleted=0 / book_date=今日(见 QueueMapper.checkTypeAndStatusStatistic)。 |
| | | RoomDO roomDO = getRoomDO(roomId, bedNo); |
| | | Integer[] checkTypes = roomDO.getCheckTypes(); |
| | | int queuingNum = 0; |
| | | // 【防御】checkTypes 为空时不能拼 `book_check_type in ()`(MySQL 语法错误)。 |
| | | // 实测该场景会让统计接口 500,进而导致医生端顶部统计整块报错。 |
| | | if (checkTypes != null && checkTypes.length > 0) { |
| | | List<Integer> statusList = new ArrayList<>(); |
| | | statusList.add(QueueStatusEnum.WAITING.getStatus()); |
| | | Integer num = queueMapper.checkTypeAndStatusStatistic(checkTypes, statusList); |
| | | patientStatisticVO.setQueuingNum(num); |
| | | queuingNum = num == null ? 0 : num; |
| | | } else { |
| | | log.warn("[getPatientStatistic][工位未配置检查类型,排队中按 0 计] roomId={} bedNo={}", roomId, bedNo); |
| | | } |
| | | patientStatisticVO.setQueuingNum(queuingNum); |
| | | |
| | | return patientStatisticVO; |
| | | } |
| | |
| | | bedQueueStatisticDOList.forEach(item -> { |
| | | if (QueueStatusEnum.READY.getStatus() == item.getStatus()) { |
| | | patientStatisticVO.setReadyNum(item.getTotalInStatus()); |
| | | } else if (QueueStatusEnum.PASSED.getStatus() == item.getStatus()) { |
| | | patientStatisticVO.setPassedNum(item.getTotalInStatus()); |
| | | } else if (QueueStatusEnum.PASSED.getStatus() == item.getStatus() |
| | | || QueueStatusEnum.PASSED_WAITING.getStatus() == item.getStatus()) { |
| | | // 【需求4 口径统一】过号 = 已过号(5) + 已过号-排队(3)。 |
| | | // |
| | | // 与 getPatientStatistic 保持同一口径。原实现只判 PASSED(5), |
| | | // 而领用界面的列表/屏幕都含 status=3,导致「过号」数字比实际少 |
| | | // —— 这正是用户反馈的「统计与实际不符」。 |
| | | // |
| | | // 另:原实现用 setPassedNum(item.getTotalInStatus())(**覆盖**而非累加), |
| | | // 因 SQL 是 group by status,status=3 与 status=5 是两行, |
| | | // 覆盖会只保留最后一行 → 改为累加。 |
| | | int cur = patientStatisticVO.getPassedNum() == null ? 0 : patientStatisticVO.getPassedNum(); |
| | | patientStatisticVO.setPassedNum(cur + item.getTotalInStatus()); |
| | | } |
| | | }); |
| | | |
| | |
| | | // 统计 该工位类型的【排队中】人员数量 |
| | | RoomDO roomDO = getRoomDO(roomId, bedNo); |
| | | Integer[] checkTypes = roomDO.getCheckTypes(); |
| | | Integer num = 0; |
| | | // 【防御】checkTypes 为空时不能拼 `book_check_type in ()`(MySQL 语法错误), |
| | | // 实测该场景会让统计接口 500、医生端顶部统计整块报错。与 getPatientStatistic 保持一致。 |
| | | if (checkTypes != null && checkTypes.length > 0) { |
| | | List<Integer> statusList = new ArrayList<>(); |
| | | statusList.add(QueueStatusEnum.WAITING.getStatus()); |
| | | Integer num = queueMapper.checkTypeAndStatusStatistic(checkTypes, statusList); |
| | | patientStatisticVO.setQueuingNum(num); |
| | | num = queueMapper.checkTypeAndStatusStatistic(checkTypes, statusList); |
| | | } else { |
| | | log.warn("[getBedDevReadyStatistic][工位未配置检查类型,排队中按 0 计] roomId={} bedNo={}", roomId, bedNo); |
| | | } |
| | | patientStatisticVO.setQueuingNum(num == null ? 0 : num); |
| | | |
| | | return patientStatisticVO; |
| | | } |
| | |
| | | |
| | | startHurryUpOneBed(roomId, bedNo); |
| | | return updateNum; |
| | | } |
| | | |
| | | // ==================== 需求2:撤销「叫号 / 检查完成」 ==================== |
| | | |
| | | /** |
| | | * 撤销「检查完成」:把本工位今日的指定患者从 已就诊(40) 退回 **候诊中(20)**。 |
| | | * <p> |
| | | * <b>Q9 确认</b>:撤销后回到**候诊区**(而非"就诊中"),便于医生重新叫号。 |
| | | * <p> |
| | | * 收尾必须调 {@link #startHurryUpOneBed}:它会重新计算该工位的 |
| | | * {@code readyPatNum} 并刷新分流队列优先级。若不同步内存计数, |
| | | * {@code hurryupOneCheckType} 会抛出 {@code exceed max queue number}。 |
| | | * |
| | | * @return 受影响行数(0 表示没找到该患者今日的已完成记录) |
| | | */ |
| | | @Override |
| | | public Integer undoFinishPatient(Long roomId, String bedNo, String patId, Integer checkType) { |
| | | Integer updateNum = queueMapper.undoFinishPatient(roomId, bedNo, patId, checkType, |
| | | QueueStatusEnum.FINISH.getStatus(), QueueStatusEnum.READY.getStatus()); |
| | | if (null != updateNum && updateNum > 0) { |
| | | startHurryUpOneBed(roomId, bedNo); |
| | | } |
| | | return updateNum; |
| | | } |
| | | |
| | | /** |
| | | * 撤销「误点叫号」:把本工位当前 就诊中(30) 的患者退回 **候诊中(20)**。 |
| | | * |
| | | * @return 受影响行数(0 表示当前没有就诊中的患者) |
| | | */ |
| | | @Override |
| | | public Integer undoCallPatient(Long roomId, String bedNo) { |
| | | Integer updateNum = queueMapper.undoCallPatient(roomId, bedNo, |
| | | QueueStatusEnum.ONSTAGE.getStatus(), QueueStatusEnum.READY.getStatus()); |
| | | if (null != updateNum && updateNum > 0) { |
| | | startHurryUpOneBed(roomId, bedNo); |
| | | } |
| | | return updateNum; |
| | | } |
| | | |
| | | @Override |
| | | public QueueDO getBedLastFinishedQueueItem(Long roomId, String bedNo) { |
| | | return queueMapper.getBedLastFinishedQueueItem(roomId, bedNo, QueueStatusEnum.FINISH.getStatus()); |
| | | } |
| | | |
| | | // ==================== 需求3:停止候诊开关 ==================== |
| | | |
| | | @Override |
| | | public ErrorCode setStopReady(Long roomId, String bedNo, boolean stop) { |
| | | // 走单线程执行器,与 bedDoctorPause/Resume 保持一致的串行化处理, |
| | | // 避免与分流队列的并发修改冲突。 |
| | | Future<ErrorCode> future = singleThreadExecutor.submit( |
| | | () -> queueServiceTxFunctions.setStopReady(roomId, bedNo, stop)); |
| | | try { |
| | | return future.get(); |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | log.error("[setStopReady] 被中断 roomId={} bedNo={}", roomId, bedNo, e); |
| | | } catch (ExecutionException e) { |
| | | log.error("[setStopReady] 执行异常 roomId={} bedNo={}", roomId, bedNo, e); |
| | | } |
| | | return ECG_INNER_ERROR; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean getStopReady(Long roomId, String bedNo) { |
| | | return queueServiceTxFunctions.getStopReady(roomId, bedNo); |
| | | } |
| | | |
| | | @Override |
| | |
| | | queueStatusList.add(QueueStatusEnum.READY.getStatus()); |
| | | queueStatusList.add(QueueStatusEnum.ONSTAGE.getStatus()); |
| | | queueStatusList.add(QueueStatusEnum.PASSED.getStatus()); |
| | | // 【需求4 口径统一】补上 PASSED_WAITING(3)「已过号-排队」。 |
| | | // 原先列表只含 5,而大屏/诊间屏查询含 3,导致同一患者在不同界面出现与否不一致; |
| | | // 统计侧也将 3 计入"过号"(见 getPatientStatistic / getBedDevReadyStatistic)。 |
| | | queueStatusList.add(QueueStatusEnum.PASSED_WAITING.getStatus()); |
| | | queueStatusList.add(QueueStatusEnum.AFFINITY.getStatus()); |
| | | List<QueueDO> queueDOList = getBedQueueByStatus(roomId, bedNo, queueStatusList); |
| | | |
| | |
| | | queueStatusList.add(QueueStatusEnum.INSTALLING.getStatus()); |
| | | queueDOList.addAll(0, getBedQueueByStatus(roomId, bedNo, queueStatusList)); // 当前工位的 |
| | | |
| | | // ====================================================================== |
| | | // 【修复】只保留「需要设备领用」的检查项目。 |
| | | // |
| | | // 背景:上面两处查询的条件是 `room_id = ? AND status IN (...)` |
| | | // (getRoomQueueByStatus 甚至**不含 bed_no**),**完全不看 book_check_type**。 |
| | | // 而自动分流(preemptWaitingPatientWithBedCheckTypes)是**按工位 checkTypes 过滤**的, |
| | | // 所以只有"人工把患者拉进来"这条路径会漏 —— 表现为 |
| | | // 「设备领用」页错误出现常规心电图(100)、平板运动心电(400)等**不需领用设备**的患者。 |
| | | // |
| | | // 判定依据用配置 `check_type.need_dev_ready`: |
| | | // 1 = 需要设备领用(如 动态心电 200、动态血压 300) |
| | | // 0 = 不需要(常规心电图、平板运动心电 …) |
| | | // |
| | | // 放在服务层而不是改 SQL:一次查询得到集合后在内存过滤,逻辑集中、易读, |
| | | // 且不需要为多数据源/动态表名额外调整 SQL。本诊室待安装患者量级很小(几十行)。 |
| | | // ====================================================================== |
| | | queueDOList = filterNeedDevReady(queueDOList); |
| | | |
| | | // 注意:下面用 lambda,捕获的变量必须是 effectively final; |
| | | // 故这里另起一个 final 变量,而不是复用上面的 queueDOList(它已被重新赋值)。 |
| | | final List<QueueDO> installQueueList = queueDOList; |
| | | |
| | | //把 [亲和的] 挪到主项后面 |
| | | List<QueueDO> affinityReceivedList = new ArrayList<>(); |
| | | ListIterator<QueueDO> iterator = queueDOList.listIterator(); |
| | | ListIterator<QueueDO> iterator = installQueueList.listIterator(); |
| | | while (iterator.hasNext()) { |
| | | QueueDO item = iterator.next(); |
| | | if (item.getStatus() == QueueStatusEnum.AFFINITY_INSTALL.getStatus()) { |
| | |
| | | } |
| | | } |
| | | affinityReceivedList.forEach(affinityReceivedItem -> { |
| | | for (int i = queueDOList.size() - 1; i >= 0; i--) { |
| | | if (affinityReceivedItem.getSeqNum() == queueDOList.get(i).getSeqNum()) { |
| | | queueDOList.add(i + 1, affinityReceivedItem); |
| | | for (int i = installQueueList.size() - 1; i >= 0; i--) { |
| | | if (affinityReceivedItem.getSeqNum() == installQueueList.get(i).getSeqNum()) { |
| | | installQueueList.add(i + 1, affinityReceivedItem); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | |
| | | return installQueueList; |
| | | } |
| | | |
| | | /** |
| | | * 只保留「需要设备领用」({@code check_type.need_dev_ready = 1})的检查项目的患者。 |
| | | * |
| | | * <p>用于「设备领用 / 装机」取数:这些工位只应处理需要领用设备的检查项目, |
| | | * 否则会出现常规心电图等患者混入设备流程。 |
| | | * |
| | | * <p>配置异常(查不到检查项目)时**返回原列表**,宁可多显示也不要把患者"藏起来"。 |
| | | */ |
| | | private List<QueueDO> filterNeedDevReady(List<QueueDO> queueDOList) { |
| | | if (null == queueDOList || queueDOList.isEmpty()) { |
| | | return queueDOList; |
| | | } |
| | | List<CheckTypeDO> needDevList = checkTypeMapper.selectList( |
| | | new LambdaQueryWrapperX<CheckTypeDO>().eq(CheckTypeDO::getNeedDevReady, 1)); |
| | | if (null == needDevList || needDevList.isEmpty()) { |
| | | log.warn("[filterNeedDevReady] 未配置任何[需要设备领用]的检查项目,跳过过滤以免患者全部不可见"); |
| | | return queueDOList; |
| | | } |
| | | Set<Integer> needDevCheckTypes = new HashSet<>(); |
| | | needDevList.forEach(ct -> { |
| | | if (null != ct.getValue()) { |
| | | needDevCheckTypes.add(ct.getValue()); |
| | | } |
| | | }); |
| | | |
| | | List<QueueDO> filtered = new ArrayList<>(); |
| | | for (QueueDO item : queueDOList) { |
| | | if (needDevCheckTypes.contains(item.getBookCheckType())) { |
| | | filtered.add(item); |
| | | } else { |
| | | log.info("[filterNeedDevReady] 过滤掉不需要设备领用的患者. patId={} 检查项目={} 状态={}", |
| | | item.getPatId(), item.getBookCheckType(), item.getStatus()); |
| | | } |
| | | } |
| | | return filtered; |
| | | } |
| | | |
| | | private RoomDO getRoomDO(Long roomId, String bedNo) { |
| | | RoomDO roomDO = mapRoomBed.get(Utils.formatRoomBed(roomId, bedNo)); |