| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * 查询患者随访信息 |
| | | * 省立同德满意度数据统计(按题目统计选项数量/占比,并给出该题的综合得分) |
| | | * <p> |
| | | * 综合满意度 = Σ(选项分值 × 项数) / Σ项数 / 本题最高分值 × 100%, |
| | | * 分值取 1、0.8、0.6、0.4、0.2 五档(很满意、满意、一般、不满意、很不满意); |
| | | * 「不适用」、0 分、空值等既不进分子也不进分母。 |
| | | */ |
| | | @ApiOperation("省立同德满意度数据统计") |
| | | @AddOrgId(field = "orgid", paramIndex = 0, campusField = "campusid") |
| | | @PostMapping("/sltdMydTotalByScore") |
| | | public Map<String, Object> sltdMydTotalByScore(@RequestBody SltdMydTotalVO sltdMydTotalVO) { |
| | | List<ServiceSubtaskRes> serviceSubtaskResList = null; |
| | |
| | | serviceSubtaskEntity.setDeptOrDistrict(sltdMydTotalVO.getDeptOrDistrict()); |
| | | serviceSubtaskEntity.setLeavehospitaldistrictcodes(sltdMydTotalVO.getLeavehospitaldistrictcodes()); |
| | | serviceSubtaskEntity.setLeaveldeptcodes(sltdMydTotalVO.getLeaveldeptcodes()); |
| | | //机构/院区由 @AddOrgId 注入,落到查询条件上,避免跨机构取数 |
| | | serviceSubtaskEntity.setOrgid(sltdMydTotalVO.getOrgid()); |
| | | serviceSubtaskEntity.setCampusid(sltdMydTotalVO.getCampusid()); |
| | | if (serviceSubtaskEntity != null) { |
| | | List<ServiceSubtask> serviceSubtasks = serviceSubtaskService.getServiceSubtasks(serviceSubtaskEntity); |
| | | List<ServiceSubtaskRes> serviceSubtaskRes = DtoConversionUtils.sourceToTarget(serviceSubtasks, ServiceSubtaskRes.class); |
| | |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskResList)) { |
| | | List<ServiceSubtaskDetailRatioExport> detailList = serviceSubtaskService.getDetailRatio(sltdMydTotalVO, serviceSubtaskResList); |
| | | |
| | | if (detailList == null) { |
| | | //serviceType 组合不在支持范围内(如同时含随访 2 和满意度 6/14),给明确提示而不是悄悄返回空数组 |
| | | return error("当前 serviceType 组合暂不支持统计问题占比,请分开查询(仅支持随访 2 或满意度 6/14)"); |
| | | } |
| | | if (CollectionUtils.isNotEmpty(detailList)) { |
| | | Map<String, List<ServiceSubtaskDetailRatioExport>> groupedMap = detailList.stream().collect(Collectors.groupingBy(ServiceSubtaskDetailRatioExport::getQuestiontext)); |
| | | |
| | |
| | | QuestionResultDTO questionResultDTO = new QuestionResultDTO(); |
| | | questionResultDTO.setQeustionText(questionText); |
| | | questionResultDTO.setSubtaskDetailRatioExportList(exportList); |
| | | BigDecimal allCount = new BigDecimal("0"); |
| | | BigDecimal allScore = new BigDecimal("0.00"); |
| | | |
| | | for (ServiceSubtaskDetailRatioExport ssdre : exportList) { |
| | | if (StringUtils.isNotEmpty(ssdre.getCount())) |
| | | allCount.add(BigDecimal.valueOf(Long.valueOf(ssdre.getCount()))); |
| | | allScore.add(BigDecimal.valueOf(Double.valueOf(ssdre.getScore()))); |
| | | } |
| | | |
| | | if (allCount.compareTo(BigDecimal.ZERO) > 0) |
| | | questionResultDTO.setAvgScore(allScore.divide(allCount, 2).toString()); |
| | | //综合得分:Σ(分值×项数) / Σ项数 / 本题最高分值 × 100%,不适用/0分/空值不进分子也不进分母 |
| | | questionResultDTO.setAvgScore(calcMydScore(exportList)); |
| | | result.add(questionResultDTO); |
| | | }); |
| | | } |
| | |
| | | return success(serviceSubtaskService.mzMydScoreRank(mzMydScoreRankVO)); |
| | | } |
| | | |
| | | /** |
| | | * 多选题的问题类型 |
| | | */ |
| | | private static final String VALUE_TYPE_MULTIPLE = "2"; |
| | | |
| | | /** |
| | | * 计算一道题的满意度综合得分(百分制,保留两位小数) |
| | | * <p> |
| | | * 综合满意度 = Σ(选项分值 × 项数) / Σ项数 / 本题最高分值 × 100% |
| | | * 等价于 Σ(很满意×1 + 满意×0.8 + 一般×0.6 + 不满意×0.4 + 很不满意×0.2) / Σ(五档项数) × 100%。 |
| | | * 用本题最高分值归一化,兼容明细分值存 0-1 权重(1、0.8…)和存 5 分制(5、4…)两种口径。 |
| | | * |
| | | * @param exportList 同一道题目的选项统计明细 |
| | | * @return 百分制综合得分,无有效项数时返回 "0.00" |
| | | */ |
| | | private String calcMydScore(List<ServiceSubtaskDetailRatioExport> exportList) { |
| | | if (CollectionUtils.isEmpty(exportList)) return "0.00"; |
| | | |
| | | BigDecimal scoreSum = BigDecimal.ZERO; //分子:Σ(选项分值 × 项数) |
| | | BigDecimal countSum = BigDecimal.ZERO; //分母:Σ项数 |
| | | BigDecimal maxScore = null; //本题最高分值,用于归一化 |
| | | |
| | | for (ServiceSubtaskDetailRatioExport detail : exportList) { |
| | | //多选题一行是多个选项的分值之和,分母只算 1 项,会把得分算高,不计入综合得分 |
| | | if (VALUE_TYPE_MULTIPLE.equals(detail.getValueType())) continue; |
| | | //「不适用」不在公式的五档里,不计入综合得分 |
| | | if (isNotApplicable(detail)) continue; |
| | | |
| | | BigDecimal score = parseDecimal(detail.getScore()); |
| | | BigDecimal count = parseDecimal(detail.getCount()); |
| | | if (score == null || count == null) continue; |
| | | //0 分(未答/空答)、空数量:既不进分子也不进分母 |
| | | if (score.signum() <= 0 || count.signum() <= 0) continue; |
| | | |
| | | if (maxScore == null || score.compareTo(maxScore) > 0) maxScore = score; |
| | | scoreSum = scoreSum.add(score.multiply(count)); |
| | | countSum = countSum.add(count); |
| | | } |
| | | |
| | | if (maxScore == null || countSum.signum() <= 0) return "0.00"; |
| | | |
| | | return scoreSum.divide(countSum, 6, RoundingMode.HALF_UP) |
| | | .divide(maxScore, 6, RoundingMode.HALF_UP) |
| | | .multiply(BigDecimal.valueOf(100)) |
| | | .setScale(2, RoundingMode.HALF_UP) |
| | | .toPlainString(); |
| | | } |
| | | |
| | | /** |
| | | * 是否「不适用」选项 |
| | | */ |
| | | private boolean isNotApplicable(ServiceSubtaskDetailRatioExport detail) { |
| | | return containsNotApplicable(detail.getOptionresult()) || containsNotApplicable(detail.getTargetvalue()); |
| | | } |
| | | |
| | | private boolean containsNotApplicable(String optionText) { |
| | | if (StringUtils.isEmpty(optionText)) return false; |
| | | String text = optionText.trim(); |
| | | return text.contains("不适用") || text.contains("未答") || text.contains("拒答"); |
| | | } |
| | | |
| | | /** |
| | | * 字符串转 BigDecimal,空值/非法值返回 null |
| | | */ |
| | | private BigDecimal parseDecimal(String value) { |
| | | if (StringUtils.isEmpty(value)) return null; |
| | | try { |
| | | return new BigDecimal(value.trim()); |
| | | } catch (NumberFormatException e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | } |