|
|
@@ -0,0 +1,119 @@
|
|
|
+package com.etotem.cfc.service.attribution;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.etotem.cfc.constant.ConditionalPathogenLowSideRules;
|
|
|
+import com.etotem.cfc.entity.AttributionCaseStrategy;
|
|
|
+import com.etotem.cfc.mapper.AttributionCaseStrategyMapper;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * P3 跨案例聚合服务(T15 跨案例聚合,能力键 {@code guhe.p3.lowSideAggregate})。
|
|
|
+ *
|
|
|
+ * <p>低侧口径并入既有 P3 聚合口径(§三-P3 §T15,2026-11-08 浠艾福平台程序修改计划):
|
|
|
+ * 按「条件致病菌低侧判读」判读口径聚合跨案例归因资产,聚类为「同策略」——
|
|
|
+ * 同条件致病菌低侧(相同 {@code strategyCode})→ 同一应对方案组,
|
|
|
+ * 可检索「同条件致病菌低侧」应对方案。跨案例可按低侧判读口径聚合同策略(T15 验收)。
|
|
|
+ *
|
|
|
+ * <p>判读口径事实锚点为知识库子键「条件致病菌低侧判读补充(人工)」
|
|
|
+ * ({@link ConditionalPathogenLowSideRules#LOW_SIDE_READING_KEY},§2.2 KB)。
|
|
|
+ * 低侧机制全部以「关联非因果」表述({@link AttributionCaseStrategy#getAssociationOnly()} 恒 true),
|
|
|
+ * 不构成健康评估/诊断/干预建议(§五 边界声明);⛔ 不产生「缺 X → 买含 X 菌株产品」桥接。
|
|
|
+ *
|
|
|
+ * <p>本能力属后端内部归因资产层(P3 沉淀与协同),无用户权限维度。
|
|
|
+ *
|
|
|
+ * @author 浠艾福平台程序修改 T15(P3 沉淀与协同层·跨案例聚合)
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class AttributionCaseAggregateService {
|
|
|
+
|
|
|
+ /** 低侧判读分组码(能力键仅按低侧口径聚合) */
|
|
|
+ public static final String READING_LOW = AttributionCaseStrategy.READING_LOW;
|
|
|
+
|
|
|
+ /** 默认策略码(无明确策略时归入低侧观察组) */
|
|
|
+ public static final String DEFAULT_STRATEGY_CODE = AttributionCaseStrategy.DEFAULT_STRATEGY_CODE;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AttributionCaseStrategyMapper attributionCaseStrategyMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按「条件致病菌低侧判读」口径聚合跨案例,聚类为「同策略」(T15 验收)。
|
|
|
+ *
|
|
|
+ * <p>仅聚合 {@code readingLevel=low} 的低侧判读案例(其余判读分组不并入低侧口径);
|
|
|
+ * 同一 {@code strategyCode}(同条件致病菌低侧)归入同一应对方案组。
|
|
|
+ *
|
|
|
+ * @param cases 跨案例判读资产(可含非低侧行,低侧口径自动过滤;null 视为空集)
|
|
|
+ * @return 策略码 → 同策略案例列表 的分组视图(LinkedHashMap 保持插入序)
|
|
|
+ */
|
|
|
+ public Map<String, List<AttributionCaseStrategy>> aggregateLowSideStrategy(
|
|
|
+ List<AttributionCaseStrategy> cases) {
|
|
|
+ Map<String, List<AttributionCaseStrategy>> grouped =
|
|
|
+ new LinkedHashMap<String, List<AttributionCaseStrategy>>();
|
|
|
+ if (cases == null) {
|
|
|
+ return grouped;
|
|
|
+ }
|
|
|
+ for (AttributionCaseStrategy c : cases) {
|
|
|
+ if (c == null || !READING_LOW.equalsIgnoreCase(c.getReadingLevel())) {
|
|
|
+ continue; // 低侧口径:仅聚合低侧判读案例
|
|
|
+ }
|
|
|
+ String key = c.getStrategyCode() == null || c.getStrategyCode().trim().isEmpty()
|
|
|
+ ? DEFAULT_STRATEGY_CODE : c.getStrategyCode();
|
|
|
+ List<AttributionCaseStrategy> bucket = grouped.get(key);
|
|
|
+ if (bucket == null) {
|
|
|
+ bucket = new ArrayList<AttributionCaseStrategy>();
|
|
|
+ grouped.put(key, bucket);
|
|
|
+ }
|
|
|
+ bucket.add(c);
|
|
|
+ }
|
|
|
+ return grouped;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 沉淀一条跨案例低侧判读应对方案(T15 数据层写入)。
|
|
|
+ *
|
|
|
+ * <p>缺省兜底:{@code readingLevel=low}、{@code readingKey=条件致病菌低侧判读补充(人工)}、
|
|
|
+ * {@code associationOnly=true}(低侧机制全部「关联非因果」)。
|
|
|
+ *
|
|
|
+ * @param strategyCase 跨案例低侧判读资产(null 忽略)
|
|
|
+ * @return 影响行数(MyBatis-Plus insert 返回值)
|
|
|
+ */
|
|
|
+ public int recordCase(AttributionCaseStrategy strategyCase) {
|
|
|
+ if (strategyCase == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (strategyCase.getReadingLevel() == null || strategyCase.getReadingLevel().trim().isEmpty()) {
|
|
|
+ strategyCase.setReadingLevel(READING_LOW);
|
|
|
+ }
|
|
|
+ if (strategyCase.getReadingKey() == null || strategyCase.getReadingKey().trim().isEmpty()) {
|
|
|
+ strategyCase.setReadingKey(ConditionalPathogenLowSideRules.LOW_SIDE_READING_KEY);
|
|
|
+ }
|
|
|
+ if (strategyCase.getAssociationOnly() == null) {
|
|
|
+ strategyCase.setAssociationOnly(Boolean.TRUE);
|
|
|
+ }
|
|
|
+ if (strategyCase.getCreatedAt() == null) {
|
|
|
+ strategyCase.setCreatedAt(new Date());
|
|
|
+ }
|
|
|
+ if (strategyCase.getUpdatedAt() == null) {
|
|
|
+ strategyCase.setUpdatedAt(new Date());
|
|
|
+ }
|
|
|
+ return attributionCaseStrategyMapper.insert(strategyCase);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检索全部低侧判读案例(「同条件致病菌低侧」应对方案的跨案例检索入口,T15)。
|
|
|
+ *
|
|
|
+ * @return 低侧判读案例列表(按 id 倒序)
|
|
|
+ */
|
|
|
+ public List<AttributionCaseStrategy> listLowSideCases() {
|
|
|
+ return attributionCaseStrategyMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<AttributionCaseStrategy>()
|
|
|
+ .eq(AttributionCaseStrategy::getReadingLevel, READING_LOW)
|
|
|
+ .orderByDesc(AttributionCaseStrategy::getId));
|
|
|
+ }
|
|
|
+}
|