Browse Source

分诊推理逻辑修改

zhaops 5 năm trước cách đây
mục cha
commit
70fd4ee4c6

+ 1 - 0
triage-service/src/main/java/com/diagbot/client/bean/FeatureRate.java

@@ -14,6 +14,7 @@ import java.util.List;
 public class FeatureRate {
     private String featureName;
     private String extraProperty;
+    private String desc;
     private String rate;
     private List<HospitalDeptDTO> hospitalDepts;
 }

+ 97 - 28
triage-service/src/main/java/com/diagbot/facade/AIFacade.java

@@ -2,6 +2,7 @@ package com.diagbot.facade;
 
 import com.diagbot.client.AiptServiceClient;
 import com.diagbot.client.TranServiceClient;
+import com.diagbot.client.bean.Feature;
 import com.diagbot.client.bean.FeatureRate;
 import com.diagbot.client.bean.ResponseData;
 import com.diagbot.client.bean.SearchData;
@@ -10,11 +11,14 @@ import com.diagbot.dto.HospitalDeptDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
+import com.diagbot.util.EntityUtil;
+import com.diagbot.util.FastJsonUtils;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.RespDTOUtil;
 import com.diagbot.util.StringUtil;
 import com.diagbot.vo.AIVO;
 import com.diagbot.vo.HospitalDeptVO;
+import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -22,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -78,45 +83,109 @@ public class AIFacade {
             case "7":
                 List<FeatureRate> items = new ArrayList<>();
                 if (ListUtil.isNotEmpty(res.data.getDis())) {
-                    Double rate;
-                    Map<String, Double> map = new HashMap<>();
+                    Map<String, List<FeatureRate>> disFeatureMap = new LinkedHashMap<>();
+                    //诊断分类
                     for (FeatureRate featureRate : res.data.getDis()) {
-                        if (featureRate.getRate() != null && Double.valueOf(featureRate.getRate()) > 0.1d) {
-                            if (StringUtil.isNotBlank(featureRate.getExtraProperty())) {
-                                if (null != map.get(featureRate.getExtraProperty())) {
-                                    rate = map.get(featureRate.getExtraProperty())
-                                            + Double.valueOf(featureRate.getRate());
-                                    map.replace(featureRate.getExtraProperty(), rate);
-                                } else {
-                                    map.put(featureRate.getExtraProperty(), Double.valueOf(featureRate.getRate()));
-                                }
+                        if (StringUtil.isBlank(featureRate.getDesc())) {
+                            featureRate.setDesc("{\"可能诊断\":\"\"}");
+                        }
+                        Map<String, Object> descMap = FastJsonUtils.getJsonToMap(featureRate.getDesc());
+                        for (String disClass : descMap.keySet()) {
+                            List<FeatureRate> featureRateList = Lists.newLinkedList();
+                            if (disFeatureMap.get(disClass) != null) {
+                                featureRateList = disFeatureMap.get(disClass);
                             }
+                            featureRateList.add(featureRate);
+                            disFeatureMap.put(disClass, featureRateList);
                         }
                     }
 
-                    List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(map.entrySet());
-                    Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
-                        //降序排序
-                        public int compare(Map.Entry<String, Double> o1,
-                                           Map.Entry<String, Double> o2) {
-                            return o2.getValue().compareTo(o1.getValue());
-                        }
-                    });
                     FeatureRate item;
-                    for (Map.Entry<String, Double> entry : list) {
-                        if (items.size() < 2) {
+                    if (disFeatureMap.get("确诊") != null) {
+                        List<FeatureRate> featureRateList = disFeatureMap.get("确诊");
+                        featureRateList = featureRateList.stream().filter(i -> i.getExtraProperty() != null).collect(Collectors.toList());
+                        if (ListUtil.isNotEmpty(featureRateList)) {
+                            Map<String, List<FeatureRate>> disMap = EntityUtil.makeEntityListMap(featureRateList, "extraProperty");
+                            List<Map.Entry<String, List<FeatureRate>>> list = new ArrayList<Map.Entry<String, List<FeatureRate>>>(disMap.entrySet());
+                            Collections.sort(list, new Comparator<Map.Entry<String, List<FeatureRate>>>() {
+                                //降序排序
+                                public int compare(Map.Entry<String, List<FeatureRate>> o1,
+                                                   Map.Entry<String, List<FeatureRate>> o2) {
+                                    return Integer.compare(o2.getValue().size(), o1.getValue().size());
+                                }
+                            });
+                            for (Map.Entry<String, List<FeatureRate>> entry : list) {
+                                if (items.size() < 1) {
+                                    item = new FeatureRate();
+                                    item.setExtraProperty(entry.getKey());
+                                    items.add(item);
+                                }
+                            }
+                        }
+                    }
+                    if (disFeatureMap.get("拟诊") != null && ListUtil.isEmpty(items)) {
+                        List<FeatureRate> featureRateList = disFeatureMap.get("拟诊");
+                        featureRateList = featureRateList.stream().filter(i -> i.getExtraProperty() != null).collect(Collectors.toList());
+                        if (ListUtil.isNotEmpty(featureRateList)) {
+                            Map<String, List<FeatureRate>> disMap = EntityUtil.makeEntityListMap(featureRateList, "extraProperty");
+                            List<Map.Entry<String, List<FeatureRate>>> list = new ArrayList<Map.Entry<String, List<FeatureRate>>>(disMap.entrySet());
+                            Collections.sort(list, new Comparator<Map.Entry<String, List<FeatureRate>>>() {
+                                //降序排序
+                                public int compare(Map.Entry<String, List<FeatureRate>> o1,
+                                                   Map.Entry<String, List<FeatureRate>> o2) {
+                                    return Integer.compare(o2.getValue().size(), o1.getValue().size());
+                                }
+                            });
+                            for (Map.Entry<String, List<FeatureRate>> entry : list) {
+                                if (items.size() < 2) {
+                                    item = new FeatureRate();
+                                    item.setExtraProperty(entry.getKey());
+                                    items.add(item);
+                                }
+                            }
+                        }
+                    }
+                    if (disFeatureMap.get("可能诊断") != null && ListUtil.isEmpty(items)) {
+                        Double rate;
+                        Map<String, Double> map = new HashMap<>();
+                        List<FeatureRate> featureRateList = disFeatureMap.get("可能诊断");
+                        featureRateList = featureRateList.stream().filter(i -> i.getExtraProperty() != null).filter(i -> i.getRate() != null).collect(Collectors.toList());
+                        for (FeatureRate featureRate : featureRateList) {
+                            if (featureRate.getRate() != null && Double.valueOf(featureRate.getRate()) > 0.1d) {
+                                if (StringUtil.isNotBlank(featureRate.getExtraProperty())) {
+                                    if (null != map.get(featureRate.getExtraProperty())) {
+                                        rate = map.get(featureRate.getExtraProperty())
+                                                + Double.valueOf(featureRate.getRate());
+                                        map.replace(featureRate.getExtraProperty(), rate);
+                                    } else {
+                                        map.put(featureRate.getExtraProperty(), Double.valueOf(featureRate.getRate()));
+                                    }
+                                }
+                            }
+                        }
+                        List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(map.entrySet());
+                        Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
+                            //降序排序
+                            public int compare(Map.Entry<String, Double> o1,
+                                               Map.Entry<String, Double> o2) {
+                                return o2.getValue().compareTo(o1.getValue());
+                            }
+                        });
+                        for (Map.Entry<String, Double> entry : list) {
+                            if (items.size() < 2) {
+                                item = new FeatureRate();
+                                item.setExtraProperty(entry.getKey());
+                                items.add(item);
+                            }
+                        }
+                        if (ListUtil.isEmpty(items)) {
                             item = new FeatureRate();
-                            item.setExtraProperty(entry.getKey());
+                            item.setExtraProperty(res.data.getDis().get(0).getExtraProperty());
                             items.add(item);
                         }
                     }
-                    if (ListUtil.isEmpty(items)) {
-                        item = new FeatureRate();
-                        item.setExtraProperty(res.data.getDis().get(0).getExtraProperty());
-                        items.add(item);
-                    }
                 }
-                if(StringUtil.isNotBlank(aivo.getHospitalCode())){
+                if (StringUtil.isNotBlank(aivo.getHospitalCode())) {
                     //获取对接科室
                     if (ListUtil.isNotEmpty(items)) {
                         HospitalDeptVO hospitalDeptVO = new HospitalDeptVO();