Browse Source

Merge remote-tracking branch 'origin/master'

MarkHuang 4 years ago
parent
commit
4b02349552

+ 4 - 211
src/main/java/com/diagbot/facade/PushFacade.java

@@ -1,21 +1,11 @@
 package com.diagbot.facade;
 
-import com.diagbot.biz.push.entity.Item;
-import com.diagbot.dto.*;
-import com.diagbot.enums.DiseaseTypeEnum;
-import com.diagbot.enums.MedicalAdviceEnum;
-import com.diagbot.enums.StandConvertEnum;
+import com.diagbot.dto.PushDTO;
 import com.diagbot.process.PushProcess;
-import com.diagbot.util.ListUtil;
-import com.diagbot.vo.*;
-import com.diagbot.vo.neoPushEntity.Diag;
-import com.diagbot.vo.neoPushEntity.DiagVo;
+import com.diagbot.vo.PushVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.*;
-import java.util.stream.Collectors;
-
 /**
  * @Description: 推送facade
  * @author: zhoutg
@@ -24,213 +14,16 @@ import java.util.stream.Collectors;
 @Component
 public class PushFacade {
 
-    @Autowired
-    NeoFacade neoFacade;
-    @Autowired
-    CommonFacade commonFacade;
     @Autowired
     PushProcess pushProcess;
-
     /**
      * 推送业务
      * @param
      * @return
      */
     public PushDTO pushFac(PushVO pushVo) {
-        int length = pushVo.getLength();
-        PushDTO pushDTO = new PushDTO();
-        // 模型处理数据
-        WordCrfDTO wordCrfDTO = commonFacade.crf_process(pushVo);
-
-        // 标准词转换
-        StandConvert standConvert = commonFacade.dataTypeGet(wordCrfDTO);
-        Map<String, Map<String, String>> standConvertMap = neoFacade.standConvertCrf(standConvert);
-        commonFacade.dataTypeSet(wordCrfDTO, standConvertMap);
-        List<String> ruleTypeList = Arrays.asList(pushVo.getFeatureType().split(","));
-        Map<String, List<String>> typeWords = typeWords(standConvertMap);
-        //生成push入参,供图谱调用
-        NeoPushVO pushVO = commonFacade.generatePushInput(wordCrfDTO);
-        Map<String, List<PushBaseDTO>> dis = new HashMap<>();
-        //如果下的诊断有数据就反推
-        if(pushVO.getDiagVo() != null && pushVO.getDiagVo().getDiags().size() > 0){
-            reversePushPackage(length, pushDTO, ruleTypeList, typeWords, pushVO,dis,wordCrfDTO.getDiag());
-        }else {
-            //正推
-            List<NeoPushDTO> push = neoFacade.getPush(pushVO);
-            if(ListUtil.isNotEmpty(push) && push.size() >0){
-                //先把所有疾病推出来
-                if(ruleTypeList.contains("7")){
-                    List<PushBaseDTO> diseeases = push.stream().filter(x -> x.getDisease() != null).map(x -> x.getDisease()).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,wordCrfDTO.getDiag());
-            }
-        }
-
-        return pushDTO;
-    }
-
-    private void setPushVo(NeoPushVO pushVO, List<NeoPushDTO> push) {
-        String firstDisease = push.get(0).getDisease().getName();
-        List<Diag> diags = new ArrayList<>();
-        Diag diag = new Diag();
-        diag.setName(firstDisease);
-        diags.add(diag);
-        DiagVo diagVo = new DiagVo();
-        diagVo.setDiags(diags);
-        pushVO.setDiagVo(diagVo);
-    }
-
-    private void reversePushPackage(int length, PushDTO pushDTO, List<String> ruleTypeList, Map<String, List<String>> typeWords, NeoPushVO pushVO, Map<String, List<PushBaseDTO>> dis, List<Item> diags) {
-        List<NeoPushDTO> reversePush = neoFacade.getReversePush(pushVO);
-        if(ListUtil.isNotEmpty(reversePush)){
-            // 症状
-            if (ruleTypeList.contains("1")) {
-                List<String> symptoms = new ArrayList<>();
-                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getSymptoms())).forEach(x -> {
-                    List<String> symptomList = x.getSymptoms().stream().map(y -> y.getName()).collect(Collectors.toList());
-                    symptoms.removeAll(symptomList);
-                    symptoms.addAll(symptomList);
-                });
-                if (symptoms.size() > 0) {
-                    List<PushBaseDTO> filtervitals = getPackagePushBaseDTO(typeWords, symptoms, StandConvertEnum.symptom);
-                    pushDTO.setSymptom(filtervitals.subList(0, filtervitals.size() >= length ? length : filtervitals.size()));
-                }
-            }
-            // 查体
-            if (ruleTypeList.contains("4")) {
-                List<String> vitals = new ArrayList<>();
-                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getVitals())).forEach(x -> {
-                    List<String> vitalList = x.getVitals().stream().map(y -> y.getName()).collect(Collectors.toList());
-                    vitals.removeAll(vitalList);
-                    vitals.addAll(vitalList);
-                });
-                if (vitals.size() > 0) {
-                    List<PushBaseDTO> filtervitals = getPackagePushBaseDTO(typeWords, vitals, StandConvertEnum.vital);
-                    pushDTO.setVital(filtervitals.subList(0, filtervitals.size() >= length ? length : filtervitals.size()));
-                }
-            }
-            // 化验
-            if (ruleTypeList.contains("5")) {
-                List<String> lises = new ArrayList<>();
-                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getLis())).forEach(x -> {
-                    List<String> lisList = x.getLis().stream().map(y -> y.getName()).collect(Collectors.toList());
-                    lises.removeAll(lisList);
-                    lises.addAll(lisList);
-                });
-                if (lises.size() > 0) {
-                    List<PushBaseDTO> filterlis = getPackagePushBaseDTO(typeWords, lises, StandConvertEnum.lis);
-                    pushDTO.setLis(filterlis.subList(0, filterlis.size() >= length ? length : filterlis.size()));
-                }
-            }
-            // 辅检
-            if (ruleTypeList.contains("6")) {
-                List<String> pacses = new ArrayList<>();
-                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getPacs())).forEach(x -> {
-                    List<String> pacsList = x.getPacs().stream().map(y -> y.getName()).collect(Collectors.toList());
-                    pacses.removeAll(pacsList);
-                    pacses.addAll(pacsList);
-                });
-                if (pacses.size() > 0) {
-                    List<PushBaseDTO> filterpacs = getPackagePushBaseDTO(typeWords, pacses, StandConvertEnum.pacs);
-                    pushDTO.setPacs(filterpacs.subList(0, filterpacs.size() >= length ? length : filterpacs.size()));
-                }
-            }
-            // 药品
-            if (ruleTypeList.contains("8")) {
-                List<String> drugs = new ArrayList<>();
-                reversePush.stream().filter(x ->x.getTreat() != null && ListUtil.isNotEmpty(x.getTreat().get(MedicalAdviceEnum.drug.getName())))
-                        .forEach(x -> {
-                            List<String> drugList = x.getTreat().get(MedicalAdviceEnum.drug.getName()).stream().map(y -> y.getName()).collect(Collectors.toList());
-                            drugs.removeAll(drugList);
-                            drugs.addAll(drugList);
-                });
-                if (drugs.size() > 0) {
-                    List<PushBaseDTO> filterdrugs = getPackagePushBaseDTO(typeWords, drugs, StandConvertEnum.drug);
-                    pushDTO.setMedicines(filterdrugs.subList(0, filterdrugs.size() >= length ? length : filterdrugs.size()));
-                }
-            }
-            // 手术
-            if (ruleTypeList.contains("9")) {
-                List<String> operations = new ArrayList<>();
-                reversePush.stream().filter(x ->x.getTreat() != null && ListUtil.isNotEmpty(x.getTreat().get(MedicalAdviceEnum.operation.getName())))
-                        .forEach(x -> {
-                            List<String> operationList = x.getTreat().get(MedicalAdviceEnum.operation.getName()).stream().map(y -> y.getName()).collect(Collectors.toList());
-                            operations.removeAll(operationList);
-                            operations.addAll(operationList);
-                        });
-                if (operations.size() > 0) {
-                    List<PushBaseDTO> filteroperations = getPackagePushBaseDTO(typeWords, operations, StandConvertEnum.operation);
-                    pushDTO.setOperations(filteroperations.subList(0, filteroperations.size() >= length ? length : filteroperations.size()));
-                }
-            }
-            //反推,推鉴别诊断
-            if (ruleTypeList.contains("7")) {
-                List<String> differentDis = new ArrayList<>();
-                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getDifferentialDis())).forEach(x -> {
-                    List<String> differentList = x.getDifferentialDis().stream().map(y -> y.getName()).collect(Collectors.toList());
-                    differentDis.removeAll(differentList);
-                    differentDis.addAll(differentList);
-                });
-                if (differentDis.size() > 0) {
-                    List<PushBaseDTO> filterpacs = getPackagePushBaseDTO(typeWords, differentDis, StandConvertEnum.disease);
-                    List<PushBaseDTO> pushDiffBaseDTOS = filterpacs.subList(0, filterpacs.size() >= length ? length : filterpacs.size());
-                    dis.put(DiseaseTypeEnum.identify.getName(),pushDiffBaseDTOS);
-                    pushDTO.setDis(dis);
-                }
-            }
-            if (ruleTypeList.contains("10") && ListUtil.isNotEmpty(diags)) {
-                List<TreatDTO> collect = diags.stream().map(x -> {
-                    TreatDTO treatDTO = new TreatDTO();
-                    treatDTO.setName(x.getName());
-                    treatDTO.setUniqueName(x.getUniqueName());
-                    return treatDTO;
-                }).collect(Collectors.toList());
-                pushDTO.setGeneraTreat(collect);
-            }
-        }
-//            return pushDTO;
+        PushDTO process = pushProcess.process(pushVo);
+        return process;
     }
 
-    private List<PushBaseDTO> getPackagePushBaseDTO(Map<String, List<String>> typeWords, List<String> symptoms, StandConvertEnum symptom) {
-
-        List<PushBaseDTO> symptomPush = symptoms.stream().map(x -> {
-            PushBaseDTO pushBaseDTO = new PushBaseDTO();
-            pushBaseDTO.setName(x);
-            return pushBaseDTO;
-        }).collect(Collectors.toList());
-        return symptomPush.stream().filter(x -> !typeWords.get(symptom.getName()).contains(x.getName())).collect(Collectors.toList());
-    }
-
-    public BillNeoVO fillBillNeo(IndicationPushVO indicationPushVO) {
-        BillNeoVO billNeoVO = new BillNeoVO();
-
-        List<Item> items = indicationPushVO.getDrug();
-        for (Item item : items) {
-            billNeoVO.getDrugList().put(item.getName(), item.getUniqueName());
-        }
-
-        return billNeoVO;
-    }
-
-    public Map<String,List<String>> typeWords( Map<String, Map<String, String>> standConvertMap){
-        Map<String,List<String>> typeWordsMap = new HashMap<>();
-        for (Map.Entry<String, Map<String, String>> s:standConvertMap.entrySet()) {
-            List<String> words = new ArrayList<>();
-            String type = s.getKey();
-            Map<String, String> value = s.getValue();
-            value.forEach((name,standName)->{
-                words.add(name);
-                words.add(standName);
-            });
-            typeWordsMap.put(type,new ArrayList<>(new HashSet<>(words)));
-        }
-
-        return typeWordsMap;
-    }
 }

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

@@ -1,8 +1,24 @@
 package com.diagbot.process;
 
-import com.diagbot.dto.WordCrfDTO;
+import com.diagbot.biz.push.entity.Item;
+import com.diagbot.dto.*;
+import com.diagbot.enums.DiseaseTypeEnum;
+import com.diagbot.enums.MedicalAdviceEnum;
+import com.diagbot.enums.StandConvertEnum;
+import com.diagbot.facade.CommonFacade;
+import com.diagbot.facade.NeoFacade;
+import com.diagbot.util.ListUtil;
+import com.diagbot.vo.NeoPushVO;
+import com.diagbot.vo.PushVO;
+import com.diagbot.vo.StandConvert;
+import com.diagbot.vo.neoPushEntity.Diag;
+import com.diagbot.vo.neoPushEntity.DiagVo;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.*;
+import java.util.stream.Collectors;
+
 /**
  * @author kwz
  * @date 2020/8/17
@@ -10,8 +26,193 @@ import org.springframework.stereotype.Component;
  */
 @Component
 public class PushProcess {
-    public void process(WordCrfDTO wordCrfDTO) {
+    @Autowired
+    NeoFacade neoFacade;
+    @Autowired
+    CommonFacade commonFacade;
+    public PushDTO process(PushVO pushVo) {
+        int length = pushVo.getLength();
+        PushDTO pushDTO = new PushDTO();
+        // 模型处理数据
+        WordCrfDTO wordCrfDTO = commonFacade.crf_process(pushVo);
+        // 标准词转换
+        StandConvert standConvert = commonFacade.dataTypeGet(wordCrfDTO);
+        Map<String, Map<String, String>> standConvertMap = neoFacade.standConvertCrf(standConvert);
+        commonFacade.dataTypeSet(wordCrfDTO, standConvertMap);
+        List<String> ruleTypeList = Arrays.asList(pushVo.getFeatureType().split(","));
+        Map<String, List<String>> typeWords = typeWords(standConvertMap);
+        //生成push入参,供图谱调用
+        NeoPushVO pushVO = commonFacade.generatePushInput(wordCrfDTO);
+        Map<String, List<PushBaseDTO>> dis = new HashMap<>();
+        //如果下的诊断有数据就反推
+        if(pushVO.getDiagVo() != null && pushVO.getDiagVo().getDiags().size() > 0){
+            reversePushPackage(length, pushDTO, ruleTypeList, typeWords, pushVO,dis,wordCrfDTO.getDiag());
+        }else {
+            //正推
+            List<NeoPushDTO> push = neoFacade.getPush(pushVO);
+            if(ListUtil.isNotEmpty(push) && push.size() >0){
+                //先把所有疾病推出来
+                if(ruleTypeList.contains("7")){
+                    List<PushBaseDTO> diseeases = push.stream().filter(x -> x.getDisease() != null).map(x -> x.getDisease()).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,wordCrfDTO.getDiag());
+            }
+        }
+        return pushDTO;
+    }
+
+    private void setPushVo(NeoPushVO pushVO, List<NeoPushDTO> push) {
+        String firstDisease = push.get(0).getDisease().getName();
+        List<Diag> diags = new ArrayList<>();
+        Diag diag = new Diag();
+        diag.setName(firstDisease);
+        diags.add(diag);
+        DiagVo diagVo = new DiagVo();
+        diagVo.setDiags(diags);
+        pushVO.setDiagVo(diagVo);
+    }
+
+    public Map<String,List<String>> typeWords( Map<String, Map<String, String>> standConvertMap){
+        Map<String,List<String>> typeWordsMap = new HashMap<>();
+        for (Map.Entry<String, Map<String, String>> s:standConvertMap.entrySet()) {
+            List<String> words = new ArrayList<>();
+            String type = s.getKey();
+            Map<String, String> value = s.getValue();
+            value.forEach((name,standName)->{
+                words.add(name);
+                words.add(standName);
+            });
+            typeWordsMap.put(type,new ArrayList<>(new HashSet<>(words)));
+        }
+
+        return typeWordsMap;
+    }
+
+    private void reversePushPackage(int length, PushDTO pushDTO, List<String> ruleTypeList, Map<String, List<String>> typeWords, NeoPushVO pushVO, Map<String, List<PushBaseDTO>> dis, List<Item> diags) {
+        List<NeoPushDTO> reversePush = neoFacade.getReversePush(pushVO);
+        if(ListUtil.isNotEmpty(reversePush)){
+            // 症状
+            if (ruleTypeList.contains("1")) {
+                List<String> symptoms = new ArrayList<>();
+                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getSymptoms())).forEach(x -> {
+                    List<String> symptomList = x.getSymptoms().stream().map(y -> y.getName()).collect(Collectors.toList());
+                    symptoms.removeAll(symptomList);
+                    symptoms.addAll(symptomList);
+                });
+                if (symptoms.size() > 0) {
+                    List<PushBaseDTO> filtervitals = getPackagePushBaseDTO(typeWords, symptoms, StandConvertEnum.symptom);
+                    pushDTO.setSymptom(filtervitals.subList(0, filtervitals.size() >= length ? length : filtervitals.size()));
+                }
+            }
+            // 查体
+            if (ruleTypeList.contains("4")) {
+                List<String> vitals = new ArrayList<>();
+                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getVitals())).forEach(x -> {
+                    List<String> vitalList = x.getVitals().stream().map(y -> y.getName()).collect(Collectors.toList());
+                    vitals.removeAll(vitalList);
+                    vitals.addAll(vitalList);
+                });
+                if (vitals.size() > 0) {
+                    List<PushBaseDTO> filtervitals = getPackagePushBaseDTO(typeWords, vitals, StandConvertEnum.vital);
+                    pushDTO.setVital(filtervitals.subList(0, filtervitals.size() >= length ? length : filtervitals.size()));
+                }
+            }
+            // 化验
+            if (ruleTypeList.contains("5")) {
+                List<String> lises = new ArrayList<>();
+                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getLis())).forEach(x -> {
+                    List<String> lisList = x.getLis().stream().map(y -> y.getName()).collect(Collectors.toList());
+                    lises.removeAll(lisList);
+                    lises.addAll(lisList);
+                });
+                if (lises.size() > 0) {
+                    List<PushBaseDTO> filterlis = getPackagePushBaseDTO(typeWords, lises, StandConvertEnum.lis);
+                    pushDTO.setLis(filterlis.subList(0, filterlis.size() >= length ? length : filterlis.size()));
+                }
+            }
+            // 辅检
+            if (ruleTypeList.contains("6")) {
+                List<String> pacses = new ArrayList<>();
+                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getPacs())).forEach(x -> {
+                    List<String> pacsList = x.getPacs().stream().map(y -> y.getName()).collect(Collectors.toList());
+                    pacses.removeAll(pacsList);
+                    pacses.addAll(pacsList);
+                });
+                if (pacses.size() > 0) {
+                    List<PushBaseDTO> filterpacs = getPackagePushBaseDTO(typeWords, pacses, StandConvertEnum.pacs);
+                    pushDTO.setPacs(filterpacs.subList(0, filterpacs.size() >= length ? length : filterpacs.size()));
+                }
+            }
+            // 药品
+            if (ruleTypeList.contains("8")) {
+                List<String> drugs = new ArrayList<>();
+                reversePush.stream().filter(x ->x.getTreat() != null && ListUtil.isNotEmpty(x.getTreat().get(MedicalAdviceEnum.drug.getName())))
+                        .forEach(x -> {
+                            List<String> drugList = x.getTreat().get(MedicalAdviceEnum.drug.getName()).stream().map(y -> y.getName()).collect(Collectors.toList());
+                            drugs.removeAll(drugList);
+                            drugs.addAll(drugList);
+                        });
+                if (drugs.size() > 0) {
+                    List<PushBaseDTO> filterdrugs = getPackagePushBaseDTO(typeWords, drugs, StandConvertEnum.drug);
+                    pushDTO.setMedicines(filterdrugs.subList(0, filterdrugs.size() >= length ? length : filterdrugs.size()));
+                }
+            }
+            // 手术
+            if (ruleTypeList.contains("9")) {
+                List<String> operations = new ArrayList<>();
+                reversePush.stream().filter(x ->x.getTreat() != null && ListUtil.isNotEmpty(x.getTreat().get(MedicalAdviceEnum.operation.getName())))
+                        .forEach(x -> {
+                            List<String> operationList = x.getTreat().get(MedicalAdviceEnum.operation.getName()).stream().map(y -> y.getName()).collect(Collectors.toList());
+                            operations.removeAll(operationList);
+                            operations.addAll(operationList);
+                        });
+                if (operations.size() > 0) {
+                    List<PushBaseDTO> filteroperations = getPackagePushBaseDTO(typeWords, operations, StandConvertEnum.operation);
+                    pushDTO.setOperations(filteroperations.subList(0, filteroperations.size() >= length ? length : filteroperations.size()));
+                }
+            }
+            //反推,推鉴别诊断
+            if (ruleTypeList.contains("7")) {
+                List<String> differentDis = new ArrayList<>();
+                reversePush.stream().filter(x -> ListUtil.isNotEmpty(x.getDifferentialDis())).forEach(x -> {
+                    List<String> differentList = x.getDifferentialDis().stream().map(y -> y.getName()).collect(Collectors.toList());
+                    differentDis.removeAll(differentList);
+                    differentDis.addAll(differentList);
+                });
+                if (differentDis.size() > 0) {
+                    List<PushBaseDTO> filterpacs = getPackagePushBaseDTO(typeWords, differentDis, StandConvertEnum.disease);
+                    List<PushBaseDTO> pushDiffBaseDTOS = filterpacs.subList(0, filterpacs.size() >= length ? length : filterpacs.size());
+                    dis.put(DiseaseTypeEnum.identify.getName(),pushDiffBaseDTOS);
+                    pushDTO.setDis(dis);
+                }
+            }
+            if (ruleTypeList.contains("10") && ListUtil.isNotEmpty(diags)) {
+                List<TreatDTO> collect = diags.stream().map(x -> {
+                    TreatDTO treatDTO = new TreatDTO();
+                    treatDTO.setName(x.getName());
+                    treatDTO.setUniqueName(x.getUniqueName());
+                    return treatDTO;
+                }).collect(Collectors.toList());
+                pushDTO.setGeneraTreat(collect);
+            }
+        }
+//            return pushDTO;
+    }
+
+    private List<PushBaseDTO> getPackagePushBaseDTO(Map<String, List<String>> typeWords, List<String> symptoms, StandConvertEnum symptom) {
 
+        List<PushBaseDTO> symptomPush = symptoms.stream().map(x -> {
+            PushBaseDTO pushBaseDTO = new PushBaseDTO();
+            pushBaseDTO.setName(x);
+            return pushBaseDTO;
+        }).collect(Collectors.toList());
+        return symptomPush.stream().filter(x -> !typeWords.get(symptom.getName()).contains(x.getName())).collect(Collectors.toList());
     }
 }