|
|
@@ -3,12 +3,15 @@ package com.etotem.cfc.service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.etotem.cfc.dto.MemberMatchResult;
|
|
|
+import com.etotem.cfc.dto.ParsedAbnormalSpecies;
|
|
|
import com.etotem.cfc.dto.ParsedReportPayload;
|
|
|
+import com.etotem.cfc.dto.ParsedSpeciesLibrary;
|
|
|
import com.etotem.cfc.entity.*;
|
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.GrowthPlanMapper;
|
|
|
import com.etotem.cfc.mapper.HealthDiseaseRiskMapper;
|
|
|
import com.etotem.cfc.mapper.HealthGutFloraMapper;
|
|
|
+import com.etotem.cfc.mapper.HealthSpeciesLibraryMapper;
|
|
|
import com.etotem.cfc.mapper.HealthIndicatorMapper;
|
|
|
import com.etotem.cfc.mapper.IndicatorDefinitionMapper;
|
|
|
import com.etotem.cfc.mapper.IndicatorValueMapper;
|
|
|
@@ -42,6 +45,7 @@ import java.util.Objects;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import com.etotem.cfc.entity.MemberIndicatorCurrent;
|
|
|
import java.util.Set;
|
|
|
import com.etotem.cfc.util.SortUtil;
|
|
|
@@ -66,6 +70,9 @@ public class HealthReportService {
|
|
|
@Resource
|
|
|
private HealthGutFloraMapper healthGutFloraMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private HealthSpeciesLibraryMapper healthSpeciesLibraryMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private HealthDiseaseRiskMapper healthDiseaseRiskMapper;
|
|
|
|
|
|
@@ -874,6 +881,92 @@ public class HealthReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // ======================== 物种功能库 + 异常菌清单(health.report.abnormalSpecies) ========================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常菌清单统一口径(P0-6 口径约束):关联非因果、测评 ≠ 诊断,供前端统一展示。
|
|
|
+ */
|
|
|
+ public static final String ABNORMAL_SPECIES_DISCLAIMER =
|
|
|
+ "本清单为菌群检测结果的关联性提示,不代表医学因果关系,也不构成医疗诊断,请以专业医生意见为准。";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常菌清单(能力键 {@code health.report.abnormalSpecies},P0-6 ▲ 直出)。
|
|
|
+ *
|
|
|
+ * <p>口径:仅收录 {@code health_species_library} 中 {@code direction IS NOT NULL} 的 ▲▼ 条目,
|
|
|
+ * 按 {@code direction} 排序(▲ 超标优先,其次 ▼ 偏低),同级按菌种编号升序,
|
|
|
+ * 让前端可一键展示「你的报告有 N 条 ▲ 超标菌」,无需遍历 payload。</p>
|
|
|
+ */
|
|
|
+ public List<ParsedAbnormalSpecies> listAbnormalSpecies(Long reportId) {
|
|
|
+ if (reportId == null) return Collections.emptyList();
|
|
|
+ List<HealthSpeciesLibrary> rows = healthSpeciesLibraryMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<HealthSpeciesLibrary>()
|
|
|
+ .eq(HealthSpeciesLibrary::getReportId, reportId)
|
|
|
+ .isNotNull(HealthSpeciesLibrary::getDirection)
|
|
|
+ );
|
|
|
+ if (rows.isEmpty()) return Collections.emptyList();
|
|
|
+
|
|
|
+ Comparator<HealthSpeciesLibrary> byDirection =
|
|
|
+ Comparator.comparingInt(HealthReportService::directionRank)
|
|
|
+ .thenComparing(HealthReportService::speciesNoOf);
|
|
|
+ List<ParsedAbnormalSpecies> result = new ArrayList<>();
|
|
|
+ for (HealthSpeciesLibrary row : rows.stream().sorted(byDirection).collect(Collectors.toList())) {
|
|
|
+ ParsedAbnormalSpecies item = new ParsedAbnormalSpecies();
|
|
|
+ item.setSpeciesNo(row.getSpeciesNo());
|
|
|
+ item.setCnName(row.getCnName());
|
|
|
+ item.setLatinName(row.getLatinName());
|
|
|
+ item.setAbundance(row.getAbundance());
|
|
|
+ item.setRefRange(row.getRefRange());
|
|
|
+ item.setDirection(row.getDirection());
|
|
|
+ item.setCategory(row.getFunctionTag());
|
|
|
+ item.setPopulationLevel(row.getPopulationLevel());
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 按 direction 排序权重:▲ 超标优先(0),▼ 偏低次之(1),其余兜底(2)。 */
|
|
|
+ private static int directionRank(HealthSpeciesLibrary row) {
|
|
|
+ if (row == null) return 2;
|
|
|
+ String direction = row.getDirection();
|
|
|
+ if (direction == null) return 2;
|
|
|
+ if (direction.contains("▲")) return 0;
|
|
|
+ if (direction.contains("▼")) return 1;
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 同级 direction 内按菌种编号升序,保证清单顺序稳定。 */
|
|
|
+ private static int speciesNoOf(HealthSpeciesLibrary row) {
|
|
|
+ Integer speciesNo = row.getSpeciesNo();
|
|
|
+ return speciesNo == null ? Integer.MAX_VALUE : speciesNo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存物种功能库明细(解析入库时调用,同一报告先清后写,保持幂等)
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void saveSpeciesLibrary(Long reportId, List<ParsedSpeciesLibrary> speciesList) {
|
|
|
+ if (reportId == null || speciesList == null || speciesList.isEmpty()) return;
|
|
|
+ healthSpeciesLibraryMapper.delete(new LambdaQueryWrapper<HealthSpeciesLibrary>()
|
|
|
+ .eq(HealthSpeciesLibrary::getReportId, reportId));
|
|
|
+ for (ParsedSpeciesLibrary parsed : speciesList) {
|
|
|
+ HealthSpeciesLibrary item = new HealthSpeciesLibrary();
|
|
|
+ item.setReportId(reportId);
|
|
|
+ item.setSpeciesNo(parsed.getSpeciesNo());
|
|
|
+ item.setCnName(parsed.getCnName());
|
|
|
+ item.setLatinName(parsed.getLatinName());
|
|
|
+ item.setFunctionTag(parsed.getFunctionTag());
|
|
|
+ item.setDetectionRate(parsed.getDetectionRate());
|
|
|
+ item.setFunctionDesc(parsed.getFunctionDesc());
|
|
|
+ item.setImproveMethod(parsed.getImproveMethod());
|
|
|
+ item.setAbundance(parsed.getAbundance());
|
|
|
+ item.setRefRange(parsed.getRefRange());
|
|
|
+ item.setStatus(parsed.getStatus());
|
|
|
+ item.setDirection(parsed.getDirection());
|
|
|
+ item.setCreatedAt(new Date());
|
|
|
+ healthSpeciesLibraryMapper.insert(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取身体维度异常指标(身体页面"指标告警"专供)
|
|
|
* 返回:疾病风险(非低风险) + 主要营养评估异常 + 氨基酸评估异常
|