| | |
| | | private static final String AGAIN_LOCK_KEY_PREFIX = "smartor:again:lock:"; |
| | | private static final long AGAIN_LOCK_SECONDS = 30L; |
| | | |
| | | /** 缙云县人民医院机构编码 */ |
| | | private static final String JINYUN_PEOPLES_HOSPITAL_ORGID = "47246116333112211A1001"; |
| | | |
| | | /** |
| | | * 查询单一任务(随访) |
| | | * |
| | |
| | | } |
| | | |
| | | /** |
| | | * 兼容「科室/病区」字段重命名前的旧入参。 |
| | | * |
| | | * <p>2026-11 起:{@code deptcode/deptname} = 在院科室,{@code leaveldeptcode/leaveldeptname} = 离院科室。 |
| | | * 但前端/旧调用方({@code /serviceSubtask/addSubTask})仍可能把科室放在 {@code deptcode/deptname} 里。 |
| | | * 若不归位,子任务会落到「在院维度」,列表按离院科室筛选时查不到(本次线上 2654501/2663019 即此问题)。 |
| | | * |
| | | * <p>规则: |
| | | * <ul> |
| | | * <li>只对非延续护理({@code service_type != '99'})生效;99 允许使用在院维度;</li> |
| | | * <li>离院科室为空且 {@code deptcode} 有值时,把 {@code deptcode/deptname} 迁到离院维度;</li> |
| | | * <li>清空在院维度,避免同一份科室同时命中两组筛选(与 {@code toSubtaskFromTaskVO} 的口径一致)。</li> |
| | | * </ul> |
| | | */ |
| | | private void alignLeaveDeptFromLegacyDept(ServiceSubtask serviceSubtask) { |
| | | if (serviceSubtask == null || "99".equals(serviceSubtask.getServiceType())) { |
| | | return; |
| | | } |
| | | if (StringUtils.isEmpty(serviceSubtask.getLeaveldeptcode()) |
| | | && StringUtils.isNotEmpty(serviceSubtask.getDeptcode())) { |
| | | serviceSubtask.setLeaveldeptcode(serviceSubtask.getDeptcode()); |
| | | } |
| | | if (StringUtils.isEmpty(serviceSubtask.getLeaveldeptname()) |
| | | && StringUtils.isNotEmpty(serviceSubtask.getDeptname())) { |
| | | serviceSubtask.setLeaveldeptname(serviceSubtask.getDeptname()); |
| | | } |
| | | // 手工新增入口没有「在院维度」的可靠来源;任务配置里的科室不是患者本人的在院科室。 |
| | | serviceSubtask.setDeptcode(null); |
| | | serviceSubtask.setDeptname(null); |
| | | serviceSubtask.setHospitaldistrictcode(null); |
| | | serviceSubtask.setHospitaldistrictname(null); |
| | | } |
| | | |
| | | /** |
| | | * 新增单一任务(随访) |
| | | * |
| | | * @param serviceSubtask 单一任务(随访) |
| | |
| | | */ |
| | | @Override |
| | | public Map<String, Object> insertServiceSubtask(ServiceSubtask serviceSubtask) { |
| | | // 兼容 2026-11 字段重命名前的旧入参:/addSubTask 仍可能把科室放在 deptcode/deptname 里 |
| | | alignLeaveDeptFromLegacyDept(serviceSubtask); |
| | | List<ServiceSubtask> serviceSubtasks = null; |
| | | //先查询一下该患者是否已经创建根据serviceType,sendstate,inhospid,patid,orgid |
| | | //这样判断主要是为了想让新华医院的外部导入患者创建任务,也能用这个接口 |
| | |
| | | log.info("getSfStatistics的入参为:{}", serviceSubtaskCountReq); |
| | | String drcode = "drcode"; |
| | | //缙云人民 根据经管医生分组 |
| | | if (serviceSubtaskCountReq.getOrgid().equals("47246116333112211A1001")) { |
| | | boolean jinyunHospital = JINYUN_PEOPLES_HOSPITAL_ORGID.equals(serviceSubtaskCountReq.getOrgid()); |
| | | if (jinyunHospital) { |
| | | drcode = "management_doctor_code"; |
| | | } |
| | | String groupKey = drcode; |
| | |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | groupKey = drcode; |
| | | } else { |
| | | groupKey = "deptcode"; |
| | | // 2026-11 字段重命名后:deptcode 是在院科室(历史数据为空), |
| | | // 出院科室已改名为 leaveldeptcode,分组必须用后者, |
| | | // 否则 getSfStatisticsGroupKey 会返回 NULL,拼成 IN (NULL) 导致整表查空。 |
| | | groupKey = "leaveldeptcode"; |
| | | } |
| | | } else if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 3) { |
| | | // 病种统计:按任务ID分组,每个任务即一个病种随访任务 |
| | |
| | | Map<String, List<ServiceSubtask>> collect = new HashMap<>(); |
| | | serviceSubtaskCountReq.setGroupKey(groupKey); |
| | | List<String> groupKeyList = serviceSubtaskMapper.getSfStatisticsGroupKey(serviceSubtaskCountReq); |
| | | /* |
| | | * 分组键可能为 NULL(历史数据、或重命名后尚未回填的在院维度列), |
| | | * 直接拼进 SQL 会变成 `AND IFNULL(列,'Unknown') IN (NULL)`,恒不成立,整张统计表为空。 |
| | | * 这里统一成 'Unknown',与聚合 SQL 的 IFNULL(列,'Unknown') 口径对齐。 |
| | | */ |
| | | if (groupKeyList != null) { |
| | | groupKeyList = groupKeyList.stream() |
| | | .map(key -> key == null ? "Unknown" : key) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | serviceSubtaskCountReq.setGroupKeyList(groupKeyList); |
| | | List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq); |
| | | switch (groupKey) { |
| | |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getManagementDoctorCode()).orElse("Unknown"))); |
| | | break; |
| | | case "deptcode": |
| | | case "leaveldeptcode": |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeaveldeptcode()).orElse("Unknown"))); |
| | | break; |
| | | case "leavehospitaldistrictcode": |
| | |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown"))); |
| | | break; |
| | | } |
| | | //获取及时率统计合集 |
| | | Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect); |
| | | /* |
| | | * 缙云县人民医院的“及时率”口径是“及时随访人次 / 应随访人次”, |
| | | * 必须和同一批统计行里的 timelyFollowUp / followUpNeeded 保持一致。 |
| | | * 不能再走 selectTimelyRateBatch:该 SQL 在未传应随访时间范围时还会追加 |
| | | * visit_time < NOW(),只按出院时间统计时会把未到期任务排除在分母外, |
| | | * 导致页面上的及时率和“及时随访人次/应随访人次”对不上。 |
| | | */ |
| | | Map<String, Map<String, Object>> jsRates = jinyunHospital |
| | | ? Collections.emptyMap() |
| | | : getSsRateForSfStatistics(serviceSubtaskCountReq, collect); |
| | | for (String collectKey : collect.keySet()) { |
| | | List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey); |
| | | if (CollectionUtils.isEmpty(serviceSubtaskList)) { |
| | |
| | | if ("taskid".equals(groupKey)) { |
| | | applyTaskGroupInfo(statistic, serviceSubtaskList); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(jsRates)) { |
| | | if (jinyunHospital) { |
| | | statistic.setRate(calculateJinyunTimelyRate(statistic)); |
| | | } else if (ObjectUtils.isNotEmpty(jsRates)) { |
| | | Map<String, Object> jsRateMap = jsRates.get(collectKey); |
| | | BigDecimal jsRate = new BigDecimal("0"); |
| | | if (ObjectUtils.isNotEmpty(jsRateMap) && ObjectUtils.isNotEmpty(jsRateMap.get("rate"))) { |
| | |
| | | */ |
| | | private long nvlLong(Long value) { |
| | | return value == null ? 0L : value; |
| | | } |
| | | |
| | | /** |
| | | * 缙云县人民医院及时率:及时随访人次 / 应随访人次。 |
| | | * <p> |
| | | * 两者都取自同一条统计结果,保证页面上的及时率与这两列可以互相验算。 |
| | | * 应随访人次为 0 时返回 0,前端按 0.00% 展示。 |
| | | */ |
| | | private double calculateJinyunTimelyRate(ServiceSubtaskStatistic statistic) { |
| | | long followUpNeeded = nvlLong(statistic.getFollowUpNeeded()); |
| | | if (followUpNeeded <= 0) { |
| | | return 0D; |
| | | } |
| | | long timelyFollowUp = nvlLong(statistic.getTimelyFollowUp()); |
| | | return BigDecimal.valueOf(timelyFollowUp) |
| | | .divide(BigDecimal.valueOf(followUpNeeded), 4, RoundingMode.HALF_UP) |
| | | .doubleValue(); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 再次随访附加统计:待随访、已发送、人工电话超时及回院复诊复查(suggest=6)。 |
| | | * 再次随访附加统计:待随访、已发送、人工电话超时及回院复诊复查(suggest=7)。 |
| | | */ |
| | | private void applyAgainFollowUpExtraStatistics(ServiceSubtaskStatistic statistic, ServiceSubtask serviceSubtask) { |
| | | if (serviceSubtask.getVisitCount() == null || serviceSubtask.getVisitCount() <= 1) { |
| | |
| | | return; |
| | | } |
| | | Long sendstate = serviceSubtask.getSendstate(); |
| | | // 回院复诊复查:再次随访中按处理意见 suggest=6 统计 |
| | | if (StringUtils.equals("6", StringUtils.trim(serviceSubtask.getSuggest()))) { |
| | | statistic.setSuggest6CountAgain(statistic.getSuggest6CountAgain() + 1L); |
| | | // 回院复诊复查:再次随访中按处理意见 suggest=7 统计 |
| | | if (StringUtils.equals("7", StringUtils.trim(serviceSubtask.getSuggest()))) { |
| | | statistic.setSuggest7CountAgain(statistic.getSuggest7CountAgain() + 1L); |
| | | } |
| | | if (sendstate.equals(3L)) { |
| | | statistic.setSentAgain(statistic.getSentAgain() + 1L); |
| | |
| | | * pendingFollowUpSentAgainInfo - visitCount > 1 && sendstate in (3,7) |
| | | * sentInfo - visitCount = 1 && sendstate = 3 |
| | | * sentAgainInfo - visitCount > 1 && sendstate = 3 |
| | | * suggest6CountAgainInfo - visitCount > 1 && suggest = 6 |
| | | * suggest7CountAgainInfo - visitCount > 1 && suggest = 7 |
| | | * filterCountList - taskSituation = 6 && sendstate = 4 |
| | | * |
| | | */ |
| | |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setExcep("1"); |
| | | break; |
| | | case "suggest6CountAgainInfo": |
| | | // 再次随访回院复诊复查:visitCount > 1 且 suggest = 6 |
| | | case "suggest7CountAgainInfo": |
| | | // 再次随访回院复诊复查:visitCount > 1 且 suggest = 7 |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setSuggest("6"); |
| | | serviceSubtaskCountReq.setSuggest("7"); |
| | | break; |
| | | case "taskSituation1Info": |
| | | serviceSubtaskCountReq.setTaskSituation(1); |
| | |
| | | total.setSentAgain(0L); |
| | | total.setFollowUpSuccessAgain(0L); |
| | | total.setFollowUpFailAgain(0L); |
| | | total.setSuggest6CountAgain(0L); |
| | | total.setSuggest7CountAgain(0L); |
| | | total.setManualAgain(0L); |
| | | total.setSmsAgain(0L); |
| | | total.setWeChatAgain(0L); |
| | |
| | | total.setSentAgain(total.getSentAgain() + (stat.getSentAgain() != null ? stat.getSentAgain() : 0L)); |
| | | total.setFollowUpSuccessAgain(total.getFollowUpSuccessAgain() + (stat.getFollowUpSuccessAgain() != null ? stat.getFollowUpSuccessAgain() : 0L)); |
| | | total.setFollowUpFailAgain(total.getFollowUpFailAgain() + (stat.getFollowUpFailAgain() != null ? stat.getFollowUpFailAgain() : 0L)); |
| | | total.setSuggest6CountAgain(total.getSuggest6CountAgain() + (stat.getSuggest6CountAgain() != null ? stat.getSuggest6CountAgain() : 0L)); |
| | | total.setSuggest7CountAgain(total.getSuggest7CountAgain() + (stat.getSuggest7CountAgain() != null ? stat.getSuggest7CountAgain() : 0L)); |
| | | total.setManualAgain(total.getManualAgain() + (stat.getManualAgain() != null ? stat.getManualAgain() : 0L)); |
| | | total.setSmsAgain(total.getSmsAgain() + (stat.getSmsAgain() != null ? stat.getSmsAgain() : 0L)); |
| | | total.setWeChatAgain(total.getWeChatAgain() + (stat.getWeChatAgain() != null ? stat.getWeChatAgain() : 0L)); |