Explorar o código

Merge branch 'master' into dev/word

zhoutg %!s(int64=4) %!d(string=hai) anos
pai
achega
f664ebfb8b

+ 72 - 21
src/main/java/com/diagbot/aggregate/PushDisAggregate.java

@@ -1,6 +1,5 @@
 package com.diagbot.aggregate;
 
-import com.diagbot.biz.push.entity.Lis;
 import com.diagbot.facade.NeoFacade;
 import com.diagbot.util.ListUtil;
 import com.diagbot.vo.NeoPushVO;
@@ -26,17 +25,22 @@ public class PushDisAggregate {
     private NeoFacade neoFacade;
     @DataProvider("pushAll")
     public List<String> getDis(
-            @InvokeParameter("allDis") List<String> allDis,
             @InvokeParameter("pushVo") NeoPushVO pushVO,
-            @InvokeParameter("lis") List<Lis> lises,
-            @DataConsumer("pushDisBySymptomOrVital") List<String> disBySv,
-            @DataConsumer("pushDisByLis") List<String> disByLis,
-            @DataConsumer("pushDisByPr") List<String> disByPr
+            @DataConsumer("pushDisBySymptom_main") List<String> disBySm,
+            @DataConsumer("pushDisBySymptom_other") List<String> disBySo,
+            @DataConsumer("pushDisByVital") List<String> disByVital,
+            @DataConsumer("pushDisByLis_nospecial") List<String> disByLis
     ){
         List<String> allPushDis = new ArrayList<>();
-        addDis(allPushDis,disBySv);
-        addDis(allPushDis,disByLis);
-        addDis(allPushDis,disByPr);
+        if(ListUtil.isNotEmpty(disBySm)){
+            disBySo.retainAll(disBySm);
+            disByVital.retainAll(disBySm);
+            disByLis.retainAll(disBySm);
+            allPushDis.addAll(disBySm);
+            allPushDis.addAll(disBySo);
+            allPushDis.addAll(disByVital);
+            allPushDis.addAll(disByLis);
+        }
         return allPushDis;
     }
 
@@ -46,22 +50,69 @@ public class PushDisAggregate {
         }
     }
 
-    @DataProvider("pushDisBySymptomOrVital")
-    public List<String> pushDisBySym(@InvokeParameter("pushVo") NeoPushVO pushVO,@InvokeParameter("allDis") List<String> allDis) {
-        neoFacade.pushDisBySymptomOrVital(pushVO,allDis);
-        return allDis;
+    /**
+     * 主症状推送诊断
+     * @param pushVO
+     * @return
+     */
+    @DataProvider("pushDisBySymptom_main")
+    public List<String> pushDisBySm(@InvokeParameter("pushVo") NeoPushVO pushVO) {
+        List<String> pushDisBySm = neoFacade.pushDisBySymptom_main(pushVO);
+        return pushDisBySm;
+    }
+
+    /**
+     * 其他症状推送诊断
+     * @param pushVO
+     * @return
+     */
+    @DataProvider("pushDisBySymptom_other")
+    public List<String> pushDisBySo(@InvokeParameter("pushVo") NeoPushVO pushVO) {
+        List<String> pushDisBySm = neoFacade.getDisBySymptom_other(pushVO);
+        return pushDisBySm;
     }
 
-    @DataProvider("pushDisByLis")
-    public List<String> pushDisByL(@InvokeParameter("allDis") List<String> allDis,@InvokeParameter("lis") List<Lis> lises) {
-        neoFacade.pushDisByLis(allDis,lises);
-        return allDis;
+    /**
+     * 化验特异性诊断
+     * @param pushVO
+     * @return
+     */
+    @DataProvider("pushDisBySpecialLis")
+    public List<String> pushDisBySl(@InvokeParameter("pushVo") NeoPushVO pushVO) {
+        List<String> pushDisBySm = neoFacade.pushDisBySpecialLis(pushVO);
+        return pushDisBySm;
     }
 
-    @DataProvider("pushDisByPr")
-    public List<String> pushDisByPacsRes(@InvokeParameter("pushVo") NeoPushVO pushVO,@InvokeParameter("allDis") List<String> allDis) {
-        neoFacade.pushDisByPacs(pushVO,allDis);
-        return allDis;
+    /**
+     * 辅检特异性诊断
+     * @param pushVO
+     * @return
+     */
+    @DataProvider("pushDisByPacs")
+    public List<String> pushDisByPs(@InvokeParameter("pushVo") NeoPushVO pushVO) {
+        List<String> pushDisBySm = neoFacade.pushDisByPacs(pushVO);
+        return pushDisBySm;
     }
 
+    /**
+     * 体征推送诊断
+     * @param pushVO
+     * @return
+     */
+    @DataProvider("pushDisByVital")
+    public List<String> pushDisByVl(@InvokeParameter("pushVo") NeoPushVO pushVO) {
+        List<String> pushDisBySm = neoFacade.getDisByVital(pushVO);
+        return pushDisBySm;
+    }
+
+    /**
+     * 非特异性化验推送诊断
+     * @param pushVO
+     * @return
+     */
+    @DataProvider("pushDisByLis_nospecial")
+    public List<String> pushDisByLisNo(@InvokeParameter("pushVo") NeoPushVO pushVO) {
+        List<String> pushDisBySm = neoFacade.getDisByLis_other(pushVO);
+        return pushDisBySm;
+    }
 }

+ 3 - 0
src/main/java/com/diagbot/config/CacheDeleteInit.java

@@ -35,6 +35,9 @@ public class CacheDeleteInit implements CommandLineRunner {
         cacheFacade.getSymptomCache();
         log.info("CDSS-CORE服务启动加载图谱症状缓存成功!");
 
+        cacheFacade.getVitalCache();
+        log.info("CDSS-CORE服务启动加载图谱体征缓存成功!");
+
         cacheFacade.loadDiseaseTypeCache();
         log.info("CDSS-CORE服务启动加载疾病属性(性别、年龄、发病率)缓存成功!");
 

+ 1 - 0
src/main/java/com/diagbot/enums/RedisEnum.java

@@ -14,6 +14,7 @@ public enum RedisEnum implements KeyedNamed {
     drugType(1, "drugType:"),
     symptomVitalType(3, "symptomVitalType:"),
     symptomNumType(4, "symptomNumType:"),
+    vitalType(5, "vitalType:"),
     diseaseType(2, "diseaseType:");
 
     @Setter

+ 12 - 1
src/main/java/com/diagbot/facade/CacheFacade.java

@@ -78,7 +78,7 @@ public class CacheFacade {
     }
 
     /**
-     * 加载图谱中的症状、体征缓存
+     * 加载图谱中的症状缓存
      *
      * @return
      */
@@ -88,6 +88,17 @@ public class CacheFacade {
 
     }
 
+    /**
+     * 加载图谱中的体征缓存
+     *
+     * @return
+     */
+    public void getVitalCache() {
+        redisUtil.deleteByPrex(RedisEnum.vitalType.getName());
+        neoFacade.vitalCache();
+
+    }
+
     /**
      * 加载图谱中的疾病对应的症状个数
      *

+ 8 - 0
src/main/java/com/diagbot/facade/CommonFacade.java

@@ -31,6 +31,7 @@ import com.diagbot.vo.neoPushEntity.LisPushVo;
 import com.diagbot.vo.neoPushEntity.PacsPushVo;
 import com.diagbot.vo.neoPushEntity.PresentPushVo;
 import com.diagbot.vo.neoPushEntity.Symptom;
+import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -340,9 +341,12 @@ public class CommonFacade {
             List<String> collect = depts.stream().map(x -> x.getUniqueName()).collect(Collectors.toList());
             pushVO.setDept(collect);
         }
+        List<String> chiefSymptom = Lists.newArrayList();
+        List<String> presentSymptom = Lists.newArrayList();
         if (chiefLabel != null) {
             ChiefPushVo chiefPushVo = new ChiefPushVo();
             if (ListUtil.isNotEmpty(chiefLabel.getClinicals())) {
+                chiefSymptom = chiefLabel.getClinicals().stream().filter(x -> x.getNegative() == null).map(z -> z.getStandName()).collect(Collectors.toList());
                 List<Symptom> cjiefClinicals = chiefLabel.getClinicals().stream().filter(x -> x.getNegative() == null).map(z ->
                 {
                     String name_sy = z.getBodyPart() == null? z.getStandName() : z.getBodyPart().getName()+z.getStandName();
@@ -374,6 +378,7 @@ public class CommonFacade {
         if (presentLabel != null) {
             PresentPushVo presentPushVo = new PresentPushVo();
             if (ListUtil.isNotEmpty(presentLabel.getClinicals())) {
+                presentSymptom = presentLabel.getClinicals().stream().filter(x -> x.getNegative() == null).map(z -> z.getStandName()).collect(Collectors.toList());
                 List<Symptom> presentClinicals = presentLabel.getClinicals().stream()
                         .filter(x -> x.getNegative() == null).map(z ->
                         {
@@ -406,6 +411,9 @@ public class CommonFacade {
             }
             pushVO.setPresentPushVo(presentPushVo);
         }
+        presentSymptom.removeAll(chiefSymptom);
+        chiefSymptom.addAll(presentSymptom);
+        pushVO.setSymptoms(chiefSymptom);
         if (ListUtil.isNotEmpty(lis)) {
             LisPushVo lisPushVo = new LisPushVo();
             lisPushVo.setLises(lis);

+ 192 - 79
src/main/java/com/diagbot/facade/NeoFacade.java

@@ -29,6 +29,7 @@ import com.diagbot.vo.neoPushEntity.*;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import io.github.lvyahui8.spring.facade.DataFacade;
+import org.apache.commons.collections.MapUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -176,6 +177,18 @@ public class NeoFacade {
         }
     }
 
+    public void vitalCache() {
+        List<String> diseaseProperty = nodeRepository.getVitalClass();
+        if (ListUtil.isNotEmpty(diseaseProperty)) {
+            Map map = diseaseProperty.stream().collect(Collectors.toMap(
+                    k -> RedisEnum.vitalType.getName() + k,
+                    v -> v,
+                    (v1, v2) -> (v2)
+            ));
+            redisTemplate.opsForValue().multiSet(map);
+        }
+    }
+
     public void symptomNumCache() {
         List<SymptomNumOfDiS> diseaseProperty = nodeRepository.getSymptomNum();
         if (ListUtil.isNotEmpty(diseaseProperty)) {
@@ -285,88 +298,109 @@ public class NeoFacade {
      * @return
      */
     public List<String> getPush(NeoPushVO pushVO) {
+        List<String> pushDis = Lists.newArrayList();
+        List<String> pushSpeDis = Lists.newArrayList();
+        //年龄
         Double age = pushVO.getAgeNum();
+        //性别
         Integer sex = pushVO.getSex();
-        List<String> depts = pushVO.getDept();
-        List<String> presentDiags = Lists.newArrayList();
-        PresentPushVo presentPushVo = pushVO.getPresentPushVo();
-        ChiefPushVo chiefPushVo = pushVO.getChiefPushVo();
-        if (presentPushVo != null) {
-            List<Diag> diags = presentPushVo.getDiags();
-            if (ListUtil.isNotEmpty(diags)) {
-                presentDiags = diags.stream().map(x -> x.getName()).collect(Collectors.toList());
-            }
-        }
-        if (chiefPushVo != null) {
-            List<Diag> diags = chiefPushVo.getDiags();
-            if (ListUtil.isNotEmpty(diags)) {
-                List<String> collect = diags.stream().map(x -> x.getName()).collect(Collectors.toList());
-                presentDiags.retainAll(collect);
-                presentDiags.addAll(collect);
-            }
-        }
+        //主诉中第一个时间
         List<PD> pds = pushVO.getChiefPushVo().getPds();
         PD pd = null;
         if (ListUtil.isNotEmpty(pds)) {
             pd = pds.get(0);
         }
-        List<String> pushDis = new ArrayList<>();
-        List<String> allDis = Lists.newArrayList();
-        //如果化验有特异性就直接推送疾病
-        List<Lis> lises = null;
-        LisPushVo lisPushVo = pushVO.getLisPushVo();
-        if (lisPushVo != null) {
-            lises = lisPushVo.getLises();
-        }
-
-        pushDis = pushDisBySpecialLis(depts,age, sex, pd, lises, presentDiags);
-        if (ListUtil.isNotEmpty(pushDis)) {
-            return pushDis;
-        }
-
-
-        /*// 症状、体征推送出的疾病
-        pushDisBySymptomOrVital(pushVO, allDis);
-        //化验推出的疾病
-        pushDisByLis(allDis, lises);
-        //辅检推出的疾病
-        pushDisByPacs(pushVO, allDis);*/
+        //科室
+        List<String> depts = pushVO.getDept();
+        //初步诊断
+        List<String> disByDiag = getDisByDiag(pushVO);
+        //现病史拟诊
+        List<String> presentDiags = getDisByPresent(pushVO);
+        //主诉中提取的诊断
+        List<String> chiefDiags = getDiseaseByChief(pushVO);
+        //化验特异性诊断
+        List<String> pushDisByLis = pushDisBySpecialLis(pushVO);
+        //辅检特异性诊断
+        List<String> pushDisByPacs = pushDisByPacs(pushVO);
 
+        List<String> allDis = Lists.newArrayList();
         try {
             Map<String, Object> invokeParams = new HashMap<>();
-            invokeParams.put("allDis", allDis);
             invokeParams.put("pushVo", pushVO);
-            invokeParams.put("lis", lises);
             allDis = DataFacade.get("pushAll", invokeParams, List.class);
         } catch (Exception e) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "并行推送疾病出错" + e.getMessage());
         }
 
         filterAndSort(pushDis, allDis, sex, age, pd,depts);
-        pushDis = addDiagFromPresent(pushDis, presentDiags);
+        //特异值推送的诊断添加到症状推送诊断的头部
+        pushDisByPacs.removeAll(pushDisByLis);
+        pushDisByLis.addAll(pushDisByPacs);
+        filterAndSort(pushSpeDis,pushDisByLis, sex, age, pd,depts);
+        pushDis.removeAll(pushSpeDis);
+        pushSpeDis.addAll(pushDis);
+
+        //初步诊断、现病史拟诊、主诉诊断添加头部
+        chiefDiags.removeAll(presentDiags);
+        presentDiags.addAll(chiefDiags);
+        presentDiags.removeAll(disByDiag);
+        disByDiag.addAll(presentDiags);
+
+        pushSpeDis.removeAll(disByDiag);
+        disByDiag.addAll(pushSpeDis);
+
+        return disByDiag;
+    }
+
+    private List<String> getDiseaseByChief(NeoPushVO pushVO) {
+        List<String> chiefDiags = Lists.newArrayList();
+        ChiefPushVo chiefPushVo = pushVO.getChiefPushVo();
+        if (chiefPushVo != null) {
+            List<Diag> diags = chiefPushVo.getDiags();
+            if (ListUtil.isNotEmpty(diags)) {
+                chiefDiags = diags.stream().map(x -> x.getName()).collect(Collectors.toList());
+            }
+        }
+        return chiefDiags;
+    }
+
+    private List<String> getDisByPresent(NeoPushVO pushVO) {
+        List<String> presentDiags = Lists.newArrayList();
+        PresentPushVo presentPushVo = pushVO.getPresentPushVo();
+        if (presentPushVo != null) {
+            List<Diag> diags = presentPushVo.getDiags();
+            if (ListUtil.isNotEmpty(diags)) {
+                presentDiags = diags.stream().map(x -> x.getName()).collect(Collectors.toList());
+            }
+        }
+        return presentDiags;
+    }
 
-        return pushDis;
+    private List<String> getDisByDiag(NeoPushVO pushVO) {
+        List<String> diags = Lists.newArrayList();
+        if (pushVO.getDiagVo() != null && ListUtil.isNotEmpty(pushVO.getDiagVo().getDiags())) {
+            diags = pushVO.getDiagVo().getDiags().stream().map(x -> x.getName()).collect(Collectors.toList());
+        }
+        return diags;
     }
 
     /**
      * 化验特异性推送疾病
-     *
-     * @param age
-     * @param sex
-     * @param
-     * @param lises
+     * @param pushVO
      * @return
      */
-    public List<String> pushDisBySpecialLis(List<String> depts, Double age, Integer sex, PD pd, List<Lis> lises, List<String> presentDiags) {
+    public List<String> pushDisBySpecialLis(NeoPushVO pushVO) {
+        List<Lis> lises = null;
+        LisPushVo lisPushVo = pushVO.getLisPushVo();
+        if (lisPushVo != null) {
+            lises = lisPushVo.getLises();
+        }
         List<String> neoPushDTOS = new ArrayList<>();
         if (ListUtil.isNotEmpty(lises)) {
-            List<String> lis_dis = lises.parallelStream()
+            neoPushDTOS = lises.parallelStream()
                     .map(x -> nodeRepository.getDisByLis_Special(x.getName(), x.getUniqueName() + x.getResult()))
                     .flatMap(List::stream).collect(Collectors.toList());
-            if (ListUtil.isNotEmpty(lis_dis)) {
-                filterAndSort(neoPushDTOS, lis_dis, sex, age, pd, depts);
-                neoPushDTOS = addDiagFromPresent(neoPushDTOS, presentDiags);
-            }
+
         }
         return neoPushDTOS;
     }
@@ -411,33 +445,79 @@ public class NeoFacade {
      * 辅检推送疾病
      *
      * @param pushVO
-     * @param allDis
      */
-    public void pushDisByPacs(NeoPushVO pushVO, List<String> allDis) {
+    public List<String> pushDisByPacs(NeoPushVO pushVO) {
+        List<String> allDis_byPacsResult = Lists.newArrayList();
         PacsPushVo pacsPushVo = pushVO.getPacsPushVo();
         if (pacsPushVo != null) {
             List<Item> pacs = pacsPushVo.getPacs();
             if (ListUtil.isNotEmpty(pacs)) {
                 List<String> pacsNames = pacs.stream().map(x -> x.getUniqueName()).collect(Collectors.toList());
-                List<String> allDis_byPacsResult = getDisByPacsResult(pacsNames);
-                allDis.addAll(allDis_byPacsResult);
+                allDis_byPacsResult = pacsResultRepository.getDisByPacsResults(pacsNames);;
+            }
+        }
+        return allDis_byPacsResult;
+    }
+
+    /**
+     * 根据主症状推送诊断
+     * @param pushVO
+     * @return
+     */
+    public List<String> pushDisBySymptom_main(NeoPushVO pushVO) {
+        List<String> disBySymptom_main = Lists.newArrayList();
+        List<String> symptoms = getSymptoms(pushVO);
+        if(ListUtil.isNotEmpty(symptoms)){
+            String s_m = symptoms.get(0);
+            disBySymptom_main = nodeRepository.getDisBySymptom_main(s_m);
+            if(ListUtil.isEmpty(disBySymptom_main) && ListUtil.isNotEmpty(pushVO.getSymptoms())){
+                String s_second = pushVO.getSymptoms().get(0);
+                disBySymptom_main = nodeRepository.getDisBySymptom_main(s_second);
+            }
+        }
+        return disBySymptom_main;
+    }
+
+    public List<String> getSymptoms(NeoPushVO pushVO){
+        List<String> symptom_chief = Lists.newArrayList();
+        List<String> symptom_present = Lists.newArrayList();
+        ChiefPushVo chiefPushVo = pushVO.getChiefPushVo();
+        PresentPushVo presentPushVo = pushVO.getPresentPushVo();
+        if(chiefPushVo != null){
+            List<Symptom> symptoms = chiefPushVo.getSymptoms();
+            if(ListUtil.isNotEmpty(symptoms)){
+                symptom_chief = symptoms.stream().map(x -> x.getName()).collect(Collectors.toList());
             }
         }
+        if(presentPushVo != null){
+            List<Symptom> symptoms = presentPushVo.getSymptoms();
+            if(ListUtil.isNotEmpty(symptoms)){
+                symptom_present = symptoms.stream().map(x -> x.getName()).collect(Collectors.toList());
+            }
+        }
+        symptom_present.removeAll(symptom_chief);
+        symptom_chief.addAll(symptom_present);
+        return symptom_chief;
     }
 
     /**
      * 化验推送疾病
      *
-     * @param allDis
-     * @param lises
+     * @param pushVO
      */
-    public void pushDisByLis(List<String> allDis, List<Lis> lises) {
+    public List<String> pushDisByLis(NeoPushVO pushVO) {
+        List<String> lis_dis = Lists.newArrayList();
+        List<Lis> lises = null;
+        LisPushVo lisPushVo = pushVO.getLisPushVo();
+        if (lisPushVo != null) {
+            lises = lisPushVo.getLises();
+        }
         if (ListUtil.isNotEmpty(lises)) {
-            List<String> lis_dis = lises.parallelStream()
+            lis_dis = lises.parallelStream()
                     .map(x -> nodeRepository.getDisByLis(x.getName(), x.getUniqueName() + x.getResult()))
                     .flatMap(List::stream).collect(Collectors.toList());
-            allDis.addAll(lis_dis);
         }
+        return lis_dis;
     }
 
     /**
@@ -469,6 +549,43 @@ public class NeoFacade {
         allDis.addAll(allDis_bySymptom);
     }
 
+    public List<String> getDisBySymptom_other(NeoPushVO pushVO){
+        List<String> disBySymptoms_1 = Lists.newArrayList();
+        List<String> symptoms = getSymptoms(pushVO);
+        if(ListUtil.isNotEmpty(symptoms) && symptoms.size() > 2){
+            symptoms = symptoms.size() >= 5?symptoms.subList(1,5):symptoms;
+            List<String> sv = redisUtil.getSv(symptoms,RedisEnum.symptomVitalType.getName());
+            disBySymptoms_1 = symptomRepository.getDisBySymptoms_1(sv);
+        }
+        return disBySymptoms_1;
+    }
+
+    public List<String> getDisByVital(NeoPushVO pushVO){
+        List<String> disByVital = Lists.newArrayList();
+        List<String> symptoms = getSymptoms(pushVO);
+        if(ListUtil.isNotEmpty(symptoms)){
+            List<String> sv = redisUtil.getSv(symptoms,RedisEnum.vitalType.getName());
+            disByVital = symptomRepository.getDisByVital(sv);
+        }
+        return disByVital;
+    }
+
+    public List<String> getDisByLis_other(NeoPushVO pushVO){
+        List<Lis> lises = null;
+        LisPushVo lisPushVo = pushVO.getLisPushVo();
+        if (lisPushVo != null) {
+            lises = lisPushVo.getLises();
+        }
+        List<String> neoPushDTOS = new ArrayList<>();
+        if (ListUtil.isNotEmpty(lises)) {
+            neoPushDTOS = lises.parallelStream()
+                    .map(x -> nodeRepository.getDisByLis_Other(x.getName(), x.getUniqueName() + x.getResult()))
+                    .flatMap(List::stream).collect(Collectors.toList());
+
+        }
+        return neoPushDTOS;
+    }
+
     public void filterAndSort(List<String> dises, List<String> allDis, int gender_code, double age, PD pd, List<String> depts) {
         //推送出的所有疾病进行性别和年龄的过滤
         List<Map<String, String>> diseases = null;
@@ -479,52 +596,48 @@ public class NeoFacade {
             allDis = diseases.stream().filter(x -> NeoUtil.matchBasic(x, gender_code, age) && NeoUtil.matchPds(x.get("name"), pd)
             && NeoUtil.matchDept(x,depts)).map(x -> x.get("name")).collect(Collectors.toList());
 //            diseases.forEach(x -> dis_fbl.put(x.get("name"), Double.parseDouble(x.get("fbl"))));
-            List<Map<String, String>> symptomNumOfDis = redisUtil.getSymptomNumOfDis(allDis);
+            /*List<Map<String, String>> symptomNumOfDis = redisUtil.getSymptomNumOfDis(allDis);
             if(ListUtil.isNotEmpty(symptomNumOfDis)){
                 symptomNumOfDis.forEach(x -> {
                     String name = x.get("name");
                     Integer num = Integer.parseInt(x.get("num"));
                     dis_symptom_num.put(name,num);
                 });
-            }
+            }*/
         }
 
         Map<Long, List<String>> numberDiseasesMap = disCountSort(allDis);
-        //根据发病率排序
+        if(MapUtils.isNotEmpty(numberDiseasesMap)){
+            for(Map.Entry<Long, List<String>> ds:numberDiseasesMap.entrySet()){
+                dises.addAll(ds.getValue());
+            }
+        }
+        /*//根据发病率排序
         //        Map<String, Double> disdistributionCache = self.getDisdistributionCache();
         Map<Long, Map<String, Double>> disPack = new LinkedHashMap<>();
         numberDiseasesMap.forEach((x, y) -> {
             Map<String, Double> collect = y.stream()
-//                    .collect(Collectors.toMap(v -> v, v -> dis_fbl.get(v), (e1, e2) -> e2));
                     .collect(Collectors.toMap(v -> v, v -> Double.valueOf(dis_symptom_num.get(v)), (e1, e2) -> e2));
             disPack.put(x, collect);
         });
         disPack.forEach((x, y) -> {
             //倒序排序
-            /*Map<String, Double> collect = y.entrySet().stream()
+            *//*Map<String, Double> collect = y.entrySet().stream()
                     .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
-                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));*/
+                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));*//*
             //正序排序
             Map<String, Double> collect = y.entrySet().stream()
                     .sorted(Map.Entry.comparingByValue())
                     .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
             disPack.put(x, collect);
             collect.forEach((k, n) -> {
-                /*NeoPushDTO neoPushDTO = new NeoPushDTO();
-                PushBaseDTO pushBaseDTO = new PushBaseDTO();
-                pushBaseDTO.setName(k);
-                neoPushDTO.setDisease(pushBaseDTO);
-                neoPushDTOS.add(neoPushDTO);*/
                 dises.add(k);
             });
-        });
+        });*/
     }
 
     public List<String> getDisBySymptom(List<String> symptoms) {
-        List<String> sv = redisUtil.getSv(symptoms);
-//        List<String> symptomCache = getSymptomCache();
-//        //取交集
-//        symptoms.retainAll(symptomCache);
+        List<String> sv = redisUtil.getSv(symptoms,RedisEnum.symptomVitalType.getName());
         List<String> allDis_bySymptom = pushDisBySymptom(symptomRepository, sv);
         return allDis_bySymptom;
     }

+ 21 - 2
src/main/java/com/diagbot/process/PushProcess.java

@@ -39,7 +39,26 @@ public class PushProcess {
         //生成push入参,供图谱调用
         NeoPushVO pushVO = commonFacade.generatePushInput(wordCrfDTO);
         Map<String, List<PushBaseDTO>> dis = new HashMap<>();
-        //如果下的诊断有数据就反推
+        List<String> push = neoFacade.getPush(pushVO);
+        if (ListUtil.isNotEmpty(push)) {
+            //先把所有疾病推出来
+            if (ruleTypeList.contains("7")) {
+                List<PushBaseDTO> diseeases =  push.stream().map(x -> {
+                    PushBaseDTO pushBaseDTO = new PushBaseDTO();
+                    pushBaseDTO.setName(x);
+                    return pushBaseDTO;
+                }).collect(Collectors.toList());
+                diseeases = diseeases.subList(0, diseeases.size() >= length ? length : diseeases.size());
+                dis.put(DiseaseTypeEnum.possibleDis.getName(), diseeases);
+                pushDTO.setDis(dis);
+            }
+            //把第一个推送出来的诊断set到diagOrder中,再反推
+            setPushVo(pushVO, push);
+            //调用反推
+            reversePushPackage(length, pushDTO, ruleTypeList, typeWords, pushVO, dis);
+        }
+        return pushDTO;
+        /*//如果下的诊断有数据就反推
         if (pushVO.getDiagVo() != null && ListUtil.isNotEmpty(pushVO.getDiagVo().getDiags())) {
             reversePushPackage(length, pushDTO, ruleTypeList, typeWords, pushVO, dis);
         } else {
@@ -64,7 +83,7 @@ public class PushProcess {
                 reversePushPackage(length, pushDTO, ruleTypeList, typeWords, pushVO, dis);
             }
         }
-        return pushDTO;
+        return pushDTO;*/
     }
 
     private void setPushVo(NeoPushVO pushVO, List<String> push) {

+ 12 - 1
src/main/java/com/diagbot/repository/BaseNodeRepository.java

@@ -48,9 +48,12 @@ public interface BaseNodeRepository extends Neo4jRepository<BaseNode, Long> {
             " RETURN DISTINCT(m.name)+'::'+c.name")
     List<String> getMedJiePouClass();
 
-    @Query("match(s) where any(label in labels(s) where label in ['症状','体征']) return distinct s.name")
+    @Query("match(d:症状) return distinct d.name")
     List<String> getSymptomClass();
 
+    @Query("match(d:体征) return distinct d.name")
+    List<String> getVitalClass();
+
     //化验查疾病
     @Query("match(d:医保疾病名称)-[r1]->(l:化验套餐名称{name:{lisBig}})-[r:化验套餐名称相关化验细项及结果]->(lr:化验细项及结果{name:{subres}}),(d)-[r2]->(lr) return d.name")
     List<String> getDisByLis(@Param("lisBig") String lisBig,@Param("subres") String subres);
@@ -59,6 +62,10 @@ public interface BaseNodeRepository extends Neo4jRepository<BaseNode, Long> {
     @Query("match(d:医保疾病名称)-[r1]->(l:化验套餐名称{name:{lisBig}})-[r:化验套餐名称相关化验细项及结果]->(lr:化验细项及结果{name:{subres}}),(d)-[r2]->(lr) where lr.special='是' return d.name")
     List<String> getDisByLis_Special(@Param("lisBig") String lisBig,@Param("subres") String subres);
 
+    //化验查疾病(无特异性)
+    @Query("match(d:医保疾病名称)-[r1]->(l:化验套餐名称{name:{lisBig}})-[r:化验套餐名称相关化验细项及结果]->(lr:化验细项及结果{name:{subres}}),(d)-[r2]->(lr) where not exists(lr.special) return d.name")
+    List<String> getDisByLis_Other(@Param("lisBig") String lisBig,@Param("subres") String subres);
+
     @Query("match(d:医保疾病名称)-[r:医保疾病名称相关性别]->(h) return DISTINCT d.name+'&'+h.name")
     List<String> getDisSexClass();
 
@@ -118,5 +125,9 @@ public interface BaseNodeRepository extends Neo4jRepository<BaseNode, Long> {
     @Query("match(d:医保疾病名称)-[r:医保疾病名称相关症状]->(s:症状) return d.name as disease,count(s) as num")
     List<SymptomNumOfDiS> getSymptomNum();
 
+    //主症状推送疾病
+    @Query("match(d:医保疾病名称)-[r:医保疾病名称相关典型症状]->(s:症状) where s.name={py} return d.name")
+    List<String> getDisBySymptom_main(@Param("py") String py);
+
 
 }

+ 25 - 9
src/main/java/com/diagbot/repository/PacsCriticalNode.java

@@ -20,31 +20,47 @@ public class PacsCriticalNode {
 		Integer agemin, agemax;
 
 		List<CriticalNeoDTO> criticallist = new ArrayList<>();
-		CriticalNeoDTO criticalNeoDTO;
+		CriticalNeoDTO criticalNeoDTO = new CriticalNeoDTO();
 
 		Integer gender = criticalNeoVO.getSex();
 		Double age = criticalNeoVO.getAge();
 		List<Item> pacsres = criticalNeoVO.getPacsLabel().getRes();
 
 		try {
-			for (Item item : pacsres) {
+			List<String> rules = new ArrayList<>();
+			List<String> removelt = new ArrayList<>();
 
+			for (Item item : pacsres) {
 				String name = item.getUniqueName();
-
 				if (StringUtil.isNotBlank(name)) {
 					List<PacsCritical> pacslist = pacsCriticalRepository.findByResult(name);
 
 					for (PacsCritical pacscri : pacslist) {
-						criticalNeoDTO = new CriticalNeoDTO();
-						result = pacscri.getVal();
-						criticalNeoDTO.setName(result);
-						criticalNeoDTO.setStandname(result);
-						criticalNeoDTO.setType(Constants.fujian);
+						rules.add(pacscri.getVal());
+					}
+				}
+			}
 
-						criticallist.add(criticalNeoDTO);
+			// 结果留下最完整的记录,移除完全包含的内容,
+			// 例如:右下叶后基底段支气管异物,支气管异物,气管异物,只留下“右下叶后基底段支气管异物”
+			for (String x : rules) {
+				for (String y : rules) {
+					if (!y.equals(x) && y.contains(x)) {
+						removelt.add(x);
 					}
 				}
 			}
+			for (String rule : rules) {
+				if (!removelt.contains(rule)) {
+					criticalNeoDTO = new CriticalNeoDTO();
+					criticalNeoDTO.setName(rule);
+					criticalNeoDTO.setStandname(rule);
+					criticalNeoDTO.setType(Constants.fujian);
+
+					criticallist.add(criticalNeoDTO);
+				}
+			}
+
 		} catch (Exception ex) {
 			ex.printStackTrace();
 		}

+ 4 - 3
src/main/java/com/diagbot/repository/SymptomNameRepository.java

@@ -36,11 +36,12 @@ public interface SymptomNameRepository extends Neo4jRepository<Symptom, Long> {
 //    @Query("match(d:医保疾病名称)-[r]->(s) where any(label in labels(s) WHERE label in ['症状', '体征']) and s.name in {py} return d.name")
     List<String> getDisBySymptoms(@Param("py")List<String> symptoms);
 
-    @Query("match(d:医保疾病名称)-[r{典型:1}]->(s:症状) where  s.name in {py} return d.name\n" +
-            "union all\n" +
-            "match(d:医保疾病名称)-[r{典型:1}]->(s:体征) where  s.name in {py} return d.name")
+    @Query("match(d:医保疾病名称)-[r:医保疾病名称相关伴随症状]->(s:症状) where s.name in {py} return d.name")
     List<String> getDisBySymptoms_1(@Param("py")List<String> symptoms);
 
+    @Query("match(d:医保疾病名称)-[r:医保疾病名称相关体征]->(s:体征) where s.name in {py} return d.name")
+    List<String> getDisByVital(@Param("py")List<String> vitals);
+
     @Query("MATCH (n:症状) return distinct(n.name) as name LIMIT {size}")
     List<String> getSymptomNames(@Param("size") Integer size);
 }

+ 39 - 0
src/main/java/com/diagbot/util/BeanMapUtils.java

@@ -0,0 +1,39 @@
+package com.diagbot.util;
+
+import org.springframework.cglib.beans.BeanMap;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @program: simple_tools
+ * @description: BeanMapUtils
+ * @author: ChenWenLong
+ * @create: 2019-12-29 14:14
+ **/
+public class BeanMapUtils {
+
+    /**
+     * 将对象属性转化为map结合
+     */
+    public static <T> Map<String, Object> beanToMap(T bean) {
+        Map<String, Object> map = new HashMap<>();
+        if (bean != null) {
+            BeanMap beanMap = BeanMap.create(bean);
+            for (Object key : beanMap.keySet()) {
+                map.put(key+"", beanMap.get(key));
+            }
+        }
+        return map;
+    }
+
+    /**
+     * 将map集合中的数据转化为指定对象的同名属性中
+     */
+    public static <T> T mapToBean(Map<String, Object> map,Class<T> clazz) throws Exception {
+        T bean = clazz.newInstance();
+        BeanMap beanMap = BeanMap.create(bean);
+        beanMap.putAll(map);
+        return bean;
+    }
+}

+ 46 - 0
src/main/java/com/diagbot/util/GenericNode.java

@@ -0,0 +1,46 @@
+package com.diagbot.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class GenericNode<T> {
+
+    public List<Map<String, Object>> fillNodeTree(List<?> nodelist) {
+        List<Map<String, Object>> baseNodes = new ArrayList<>();
+        Map<String, Object> node;
+
+        for (Object nd : nodelist) {
+            node = BeanMapUtils.beanToMap(nd);
+
+            baseNodes.add(node);
+        }
+
+        return baseNodes;
+    }
+
+
+    public static List<Map<String, Object>> removeRelation(List<Map<String, Object>> nodes) {
+        List<String> rmkeys = new ArrayList<>();
+        try {
+            for (String key : nodes.get(0).keySet()) {
+                if (nodes.get(0).get(key) instanceof Set) {
+                    rmkeys.add(key);
+                }
+            }
+
+            for (Map<String, Object> node : nodes) {
+                for (String key : rmkeys) {
+                    node.remove(key);
+                }
+            }
+        }
+        catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        finally {
+            return nodes;
+        }
+    }
+}

+ 2 - 2
src/main/java/com/diagbot/util/RedisUtil.java

@@ -114,8 +114,8 @@ public class RedisUtil {
         return list;
     }
 
-    public List<String> getSv(List<String> keys) {
-        keys = keys.stream().map(x ->RedisEnum.symptomVitalType.getName()+x).collect(Collectors.toList());
+    public List<String> getSv(List<String> keys,String type) {
+        keys = keys.stream().map(x ->type+x).collect(Collectors.toList());
         List<String> list = redisTemplate.opsForValue().multiGet(keys);
         return list;
     }

+ 1 - 0
src/main/java/com/diagbot/vo/NeoPushVO.java

@@ -29,5 +29,6 @@ public class NeoPushVO {
     private PastPushVo pastPushVo;//既往史
     private LisPushVo lisPushVo;//化验
     private PacsPushVo pacsPushVo;//辅检
+    private List<String> symptoms;//不带部位的症状
 
 }

+ 1 - 0
src/main/java/com/diagbot/web/CacheController.java

@@ -36,6 +36,7 @@ public class CacheController {
         cacheFacade.loadDrugTypeCache();
         cacheFacade.loadDiseaseTypeCache();
         cacheFacade.getSymptomCache();
+        cacheFacade.getVitalCache();
         cacheFacade.getSymptomNumCache();
         return RespDTO.onSuc(true);
     }