瀏覽代碼

代码优化

zhoutg 4 年之前
父節點
當前提交
a10687a4a4

+ 7 - 7
src/main/java/com/diagbot/enums/StandConvertEnum.java

@@ -11,13 +11,13 @@ import lombok.Setter;
 
 public enum StandConvertEnum implements KeyedNamed {
 
-    lis(1, "化验"),
-    pacs(2, "辅检"),
-    disease(3, "诊断"),
-    drug(4, "药品"),
-    clinical(5, "临床表现"),
-    operation(6, "手术"),
-    vital(7, "体征");
+    lis(1, "lis"),
+    pacs(2, "pacs"),
+    disease(3, "disease"),
+    drug(4, "drug"),
+    symptom(5, "symptom"),
+    operation(6, "operation"),
+    vital(7, "vital");
 
     @Setter
     private int key;

+ 23 - 0
src/main/java/com/diagbot/facade/CacheFacade.java

@@ -1,6 +1,10 @@
 package com.diagbot.facade;
 
+import com.diagbot.enums.StandConvertEnum;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
 /**
@@ -11,6 +15,10 @@ import org.springframework.stereotype.Component;
 @Component
 public class CacheFacade {
 
+    @Autowired
+    @Qualifier("redisTemplateForSimilar")
+    RedisTemplate redisTemplate;
+
     /**
      * 清除缓存信息
      *
@@ -20,4 +28,19 @@ public class CacheFacade {
     public void clear() {
 
     }
+
+    /**
+     * 清除标准词转换缓存信息
+     *
+     * @return
+     */
+    public void clearStandConvert() {
+        redisTemplate.delete(StandConvertEnum.disease.getName());
+        redisTemplate.delete(StandConvertEnum.drug.getName());
+        redisTemplate.delete(StandConvertEnum.lis.getName());
+        redisTemplate.delete(StandConvertEnum.operation.getName());
+        redisTemplate.delete(StandConvertEnum.pacs.getName());
+        redisTemplate.delete(StandConvertEnum.symptom.getName());
+        redisTemplate.delete(StandConvertEnum.vital.getName());
+    }
 }

+ 2 - 2
src/main/java/com/diagbot/facade/CommonFacade.java

@@ -159,8 +159,8 @@ public class CommonFacade {
         VitalLabel vitalLabel = wordCrfDTO.getVitalLabel();
 
         //症状回填
-        CoreUtil.setPropertyList(chiefLabel.getClinicals(), map.get(StandConvertEnum.clinical.getName()));
-        CoreUtil.setPropertyList(presentLabel.getClinicals(), map.get(StandConvertEnum.clinical.getName()));
+        CoreUtil.setPropertyList(chiefLabel.getClinicals(), map.get(StandConvertEnum.symptom.getName()));
+        CoreUtil.setPropertyList(presentLabel.getClinicals(), map.get(StandConvertEnum.symptom.getName()));
         //诊断回填
         CoreUtil.setPropertyList(diagLabel.getDiags(), map.get(StandConvertEnum.disease.getName()));
         CoreUtil.setPropertyList(wordCrfDTO.getDiagOrder(),"name", "uniqueName", map.get(StandConvertEnum.disease.getName()));

+ 111 - 189
src/main/java/com/diagbot/facade/NeoFacade.java

@@ -3,19 +3,42 @@ package com.diagbot.facade;
 import com.alibaba.fastjson.JSONArray;
 import com.diagbot.client.ChiefPresentSimilarityServiceClient;
 import com.diagbot.client.StandConvertServiceClient;
-import com.diagbot.dto.*;
+import com.diagbot.dto.BillNeoDTO;
+import com.diagbot.dto.CriticalNeoDTO;
+import com.diagbot.dto.HighRiskNeoDTO;
+import com.diagbot.dto.NeoPushDTO;
+import com.diagbot.dto.PushDTO;
+import com.diagbot.dto.StandConvertCrfBatchDTO;
+import com.diagbot.dto.StandConvertCrfDTO;
 import com.diagbot.entity.node.Disease;
 import com.diagbot.entity.node.Medicine_Code;
 import com.diagbot.entity.node.OralMedicine;
 import com.diagbot.enums.StandConvertEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
-import com.diagbot.model.ai.ModelAI;
-import com.diagbot.repository.*;
+import com.diagbot.repository.DiseaseNode;
+import com.diagbot.repository.DiseaseRepository;
+import com.diagbot.repository.LisNode;
+import com.diagbot.repository.LisPackNode;
+import com.diagbot.repository.LisPackRepository;
+import com.diagbot.repository.LisRepository;
+import com.diagbot.repository.MedicineCodeRepository;
+import com.diagbot.repository.MedicineNode;
+import com.diagbot.repository.MedicineRepository;
+import com.diagbot.repository.OperationNode;
+import com.diagbot.repository.OperationRepository;
+import com.diagbot.repository.PACSNode;
+import com.diagbot.repository.PacsRepository;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.RedisUtil;
 import com.diagbot.util.StringUtil;
-import com.diagbot.vo.*;
+import com.diagbot.vo.BillNeoVO;
+import com.diagbot.vo.CriticalNeoVO;
+import com.diagbot.vo.HighRiskNeoVO;
+import com.diagbot.vo.NeoPushVO;
+import com.diagbot.vo.PushNeoVO;
+import com.diagbot.vo.StandConvert;
+import com.diagbot.vo.StandConvertCrfVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Component;
@@ -104,7 +127,7 @@ public class NeoFacade {
         Map<String, List<String>> res = new HashMap<>();
         // 临床表现,诊断,化验,辅检,药品,查体,手术
         // TODO 测试数据
-        res.put(StandConvertEnum.clinical.getName(), Arrays.asList("胸痛","咳嗽"));
+        res.put(StandConvertEnum.symptom.getName(), Arrays.asList("胸痛","咳嗽"));
         res.put(StandConvertEnum.disease.getName(), Arrays.asList("高血压", "糖尿病"));
         return res;
     }
@@ -262,8 +285,6 @@ public class NeoFacade {
         return criticalNeoDTOs;
     }
 
-
-
     /**
      * 处理高危药品数据
      * @param drugs
@@ -289,69 +310,6 @@ public class NeoFacade {
         return highRiskNeoDTOS;
     }
 
-
-    /**
-     * 标准词转换
-     *
-     * @param standConvert
-     *
-     * @return  Map<String, Map<String, String>> -->Map<类型, Map<原始词, 标准词>>
-     */
-    public Map<String, Map<String, String>> standConvert(StandConvert standConvert) {
-        Map<String, Map<String, String>> map = new LinkedHashMap<>();
-        Map<String, List<String>> similarMap = self.getSimilarCache();
-        /* 文本相似度模型 */
-        ModelAI modelAI = new ModelAI();
-
-        // 临床表现数据
-        List<String> list = standConvert.getClinicalList();
-        Map<String, String> clinicalMap = getStandConvertTypeMap(modelAI, list,
-                similarMap.get(StandConvertEnum.clinical.getName()), "chief_present");
-        map.put(StandConvertEnum.clinical.getName(), clinicalMap);
-
-        // 诊断数据
-        List<String> diag_list = standConvert.getDiaglList();
-        Map<String, String> diseaseMap = getStandConvertTypeMap(modelAI, diag_list,
-                similarMap.get(StandConvertEnum.disease.getName()), "diagnose");
-        map.put(StandConvertEnum.disease.getName(), diseaseMap);
-
-        // 手术数据
-        List<String> operation_list = standConvert.getOperationList();
-        Map<String, String> operationMap = getStandConvertTypeMap(modelAI, operation_list,
-                similarMap.get(StandConvertEnum.operation.getName()), "operation");
-        map.put(StandConvertEnum.operation.getName(), operationMap);
-
-        // 辅检数据
-        List<String> pacs_list = standConvert.getPacsList();
-        Map<String, String> pacsMap = getStandConvertTypeMap(modelAI, pacs_list,
-                similarMap.get(StandConvertEnum.pacs.getName()), "pacs");
-        map.put(StandConvertEnum.pacs.getName(), pacsMap);
-
-        return map;
-    }
-
-    /**
-     * 获取指定类型的map数据
-     *
-     * @param modelAI
-     * @param text 文本内容
-     * @param cacheList 模型列表
-     * @param modelName 模块名称
-     * @return
-     */
-    public Map<String, String> getStandConvertTypeMap(ModelAI modelAI, List<String> text, List<String> cacheList, String modelName) {
-        Map<String, String> map = new LinkedHashMap<>();
-        if (ListUtil.isEmpty(cacheList)) {
-            return map;
-        }
-        for (String s : text) {
-            JSONArray jsonArray = modelAI.loadSimilarAI(s, cacheList,
-                    false, modelName, chiefPresentSimilarityServiceClient);
-            putMap(jsonArray, s, map);
-        }
-        return map;
-    }
-
     /**
      * 提取方法
      * @param jsonArray
@@ -381,149 +339,113 @@ public class NeoFacade {
      */
     public Map<String, Map<String, String>> standConvertCrf(StandConvert standConvert) {
         Map<String, Map<String, String>> map = new LinkedHashMap<>();
-        List<String> clinicalList = standConvert.getClinicalList();
-        Map<String, String> clinicalMap = getStandConvertMapBatch(clinicalList, "symptom");
-        map.put(StandConvertEnum.clinical.getName(), clinicalMap);
-
-        List<String> operationList = standConvert.getOperationList();
-        Map<String, String> operationMap = getStandConvertMapBatch(operationList, "operation");
-        map.put(StandConvertEnum.operation.getName(), operationMap);
-
-        List<String> drugList = standConvert.getDrugList();
-        Map<String, String> drugMap = getStandConvertMapBatch(drugList, "drug");
-        map.put(StandConvertEnum.drug.getName(), drugMap);
 
-        List<String> vitalList = standConvert.getVitalList();
-        Map<String, String> vitalMap = getStandConvertMapBatch(vitalList, "vital");
-        map.put(StandConvertEnum.vital.getName(), vitalMap);
-
-        List<String> diseaseList = standConvert.getDiaglList();
-        Map<String, String> diseaseMap = getStandConvertMapBatch(diseaseList, "disease");
-        map.put(StandConvertEnum.disease.getName(), diseaseMap);
-
-        List<String> pacsList = standConvert.getPacsList();
-        Map<String, String> pacsMap = getStandConvertMapBatch(pacsList, "pacs");
-        map.put(StandConvertEnum.pacs.getName(), pacsMap);
+        List<StandConvertCrfVO> standConvertCrfVOList = new ArrayList<>();
+        List<String> clinicalConList = getConvertList(standConvert.getClinicalList(), StandConvertEnum.symptom.getName(), standConvertCrfVOList);
+        List<String> operationConList = getConvertList(standConvert.getOperationList(), StandConvertEnum.operation.getName(), standConvertCrfVOList);
+        List<String> drugConList = getConvertList(standConvert.getDrugList(), StandConvertEnum.drug.getName(), standConvertCrfVOList);
+        List<String> vitallConList = getConvertList(standConvert.getVitalList(), StandConvertEnum.vital.getName(), standConvertCrfVOList);
+        List<String> diseaseConList = getConvertList(standConvert.getDiaglList(), StandConvertEnum.disease.getName(), standConvertCrfVOList);
+        List<String> pacsConList = getConvertList(standConvert.getPacsList(), StandConvertEnum.pacs.getName(), standConvertCrfVOList);
+        List<String> lisConList = getConvertList(standConvert.getLisList(), StandConvertEnum.lis.getName(), standConvertCrfVOList);
+
+        StandConvertCrfBatchDTO standConvertCrfBatchDTO = null;
+        try {
+            standConvertCrfBatchDTO = standConvertServiceClient.similarityBatch(standConvertCrfVOList);
+        } catch (Exception e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标准词转换服务出错!【找毕金良】" + e.getMessage());
+        }
+        Map<String, Map<String, StandConvertCrfDTO>> crfMap = standConvertCrfBatchDTO.getData();
+        getConvertMap(crfMap, StandConvertEnum.symptom.getName(), clinicalConList, standConvert.getClinicalList(), map);
+        getConvertMap(crfMap, StandConvertEnum.operation.getName(), operationConList, standConvert.getOperationList(), map);
+        getConvertMap(crfMap, StandConvertEnum.drug.getName(), drugConList, standConvert.getDrugList(), map);
+        getConvertMap(crfMap, StandConvertEnum.vital.getName(), vitallConList, standConvert.getVitalList(), map);
+        getConvertMap(crfMap, StandConvertEnum.disease.getName(), diseaseConList, standConvert.getDiaglList(), map);
+        getConvertMap(crfMap, StandConvertEnum.pacs.getName(), pacsConList, standConvert.getPacsList(), map);
+        getConvertMap(crfMap, StandConvertEnum.lis.getName(), lisConList, standConvert.getLisList(), map);
 
-        List<String> lisList = standConvert.getLisList();
-        Map<String, String> lisMap = getStandConvertMapBatch(lisList, "lis");
-        map.put(StandConvertEnum.lis.getName(), lisMap);
         return map;
     }
 
-
     /**
-     * 标准词转换
+     * 入参数据处理
      *
-     * @param list 原词
-     * @param type 类型
-     * @return
+     * @param wordList
+     * @param type
+     * @param standConvertCrfVOList
      */
-    public Map<String, String> getStandConvertMap(List<String> list, String type) {
-        long l1 = System.currentTimeMillis();
-        Map<String, String> typeMap = redisUtil.getValueByType(type);
-        Map<String, String> standConvertMap = new LinkedHashMap<>();
-        List<String> notList = new ArrayList<>();
-
-        if (typeMap != null) {
-            for (String s : list) {
-                if (StringUtil.isBlank(typeMap.get(s))) {
-                    notList.add(s);
-                }
-            }
-        } else {
-            typeMap = new LinkedHashMap<>();
-            notList = list;
+    public List<String> getConvertList(List<String> wordList, String type, List<StandConvertCrfVO> standConvertCrfVOList) {
+        List<String> convertList = new ArrayList<>();
+        if (ListUtil.isEmpty(wordList)) {
+            return null;
         }
 
-        if (ListUtil.isNotEmpty(notList)) {
-            for (String s : notList) {
-                StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
-                standConvertCrfVO.setWord_type(type);
-                standConvertCrfVO.setWord(s);
-                StandConvertCrfDTO standConvertCrfDTO = standConvertServiceClient.similarity(standConvertCrfVO);
-                if (ListUtil.isEmpty(standConvertCrfDTO.getStandard_words())) {
-                    standConvertMap.put(s, s);
-                } else {
-                    standConvertMap.put(s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
+        // 从redis获取对应的内容
+        Map<String, String> redisMap = redisUtil.getValueByType(type);
+        if (redisMap == null) {
+            redisMap = new LinkedHashMap<>();
+        }
+        if (ListUtil.isNotEmpty(wordList)) {
+            for (String s : wordList) {
+                if (StringUtil.isBlank(redisMap.get(s))) {
+                    StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
+                    standConvertCrfVO.setWord_type(type);
+                    standConvertCrfVO.setWord(s);
+                    standConvertCrfVOList.add(standConvertCrfVO);
+                    if (!convertList.contains(s)) {
+                        convertList.add(s);
+                    }
                 }
             }
-
-            if (standConvertMap != null && !standConvertMap.isEmpty()) {
-                typeMap.putAll(standConvertMap);
-            }
-            long l2 = System.currentTimeMillis();
-            System.out.println("存放前" + type + ":" + (l2 - l1) / 1000.0);
-            redisUtil.updateValueByType(typeMap, type);
-            long l3 = System.currentTimeMillis();
-            System.out.println("存放" + type + ":" + (l3 - l2) / 1000.0);
         }
-        long l4 = System.currentTimeMillis();
-        System.out.println("共耗时:" + type + ":" + (l4 - l1) / 1000.0);
-        return typeMap;
+        return convertList;
     }
 
-
     /**
-     * 标准词转换
+     * 获取标准词转换map结果,并更新redis
      *
-     * @param list 原词
-     * @param type 类型
-     * @return
+     * @param crfDTO
+     * @param type
+     * @param convertList
+     * @param orginList
+     * @param map
      */
-    public Map<String, String> getStandConvertMapBatch(List<String> list, String type) {
-        // long l1 = System.currentTimeMillis();
-        Map<String, String> typeMap = redisUtil.getValueByType(type);
-        Map<String, String> standConvertMap = new LinkedHashMap<>();
-        List<String> notList = new ArrayList<>();
-
-        if (typeMap != null) {
-            for (String s : list) {
-                if (StringUtil.isBlank(typeMap.get(s))) {
-                    notList.add(s);
-                }
+    public void getConvertMap(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
+                          List<String> orginList, Map<String, Map<String, String>> map) {
+        Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
+        Map<String, String> typeMap = new LinkedHashMap<>();
+        if (ListUtil.isEmpty(convertList) || crfMap == null) {
+            for (String orgS : orginList) {
+                typeMap.put(orgS, orgS);
             }
         } else {
-            typeMap = new LinkedHashMap<>();
-            notList = list;
-        }
-
-        List<StandConvertCrfVO> standConvertCrfVOList = new ArrayList<>();
-        if (ListUtil.isNotEmpty(notList)) {
-            for (String s : notList) {
-                StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
-                standConvertCrfVO.setWord_type(type);
-                standConvertCrfVO.setWord(s);
-                standConvertCrfVOList.add(standConvertCrfVO);
-            }
-            StandConvertCrfBatchDTO standConvertCrfBatchDTO = null;
-            try {
-                 standConvertCrfBatchDTO = standConvertServiceClient.similarityBatch(standConvertCrfVOList);
-            } catch (Exception e) {
-                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "标准词转换服务出错!【找毕金良】" + e.getMessage());
+            // 从redis获取对应的内容
+            Map<String, String> redisMap = null;
+            redisMap = redisUtil.getValueByType(type);
+            if (redisMap == null) {
+                redisMap = new LinkedHashMap<>();
             }
-            if (standConvertCrfBatchDTO != null && standConvertCrfBatchDTO.getStatus()) {
-                Map<String, StandConvertCrfDTO> map1 = standConvertCrfBatchDTO.getData().get(type);
-                for (String s : notList) {
-                    StandConvertCrfDTO standConvertCrfDTO = map1.get(s);
-                    if (standConvertCrfDTO == null || ListUtil.isEmpty(standConvertCrfDTO.getStandard_words())) {
-                        standConvertMap.put(s, s);
-                    } else {
-                        standConvertMap.put(s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
-                    }
+
+            for (String s : convertList) {
+                StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
+                if (standConvertCrfDTO != null) {
+                    redisMap.put(s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
+                } else {
+                    redisMap.put(s, s); // 找不到就认为是标准词
                 }
             }
-            if (standConvertMap != null && !standConvertMap.isEmpty()) {
-                typeMap.putAll(standConvertMap);
+
+            // 更新redis
+            redisUtil.updateValueByType(redisMap, type);
+
+            for (String orgS : orginList) {
+                if (StringUtil.isNotBlank(redisMap.get(orgS))) {
+                    typeMap.put(orgS, redisMap.get(orgS));
+                } else {
+                    typeMap.put(orgS, orgS);
+                }
             }
-            // long l2 = System.currentTimeMillis();
-            // System.out.println("存放前" + type + ":" + (l2 - l1) / 1000.0);
-            redisUtil.updateValueByType(typeMap, type);
-            // long l3 = System.currentTimeMillis();
-            // System.out.println("存放" + type + ":" + (l3 - l2) / 1000.0);
         }
-        // long l4 = System.currentTimeMillis();
-        // System.out.println("共耗时:" + type + ":" + (l4 - l1) / 1000.0);
-        return typeMap;
+        map.put(type, typeMap);
     }
 }

+ 1 - 1
src/main/java/com/diagbot/facade/PushFacade.java

@@ -56,7 +56,7 @@ public class PushFacade {
                 int length = pushVo.getLength();
                 // 症状
                 if (ruleTypeList.contains("1") && ListUtil.isNotEmpty(neoPushDTO.getSymptoms())) {
-                    List<PushBaseDTO> filterSymptoms = neoPushDTO.getSymptoms().stream().filter(x -> !typeWords.get(StandConvertEnum.clinical.getName()).contains(x.getName())).collect(Collectors.toList());
+                    List<PushBaseDTO> filterSymptoms = neoPushDTO.getSymptoms().stream().filter(x -> !typeWords.get(StandConvertEnum.symptom.getName()).contains(x.getName())).collect(Collectors.toList());
                     pushDTO.setSymptom(filterSymptoms.subList(0, filterSymptoms.size() >= length ? length : filterSymptoms.size()));
                 }
                 // 查体

+ 0 - 22
src/main/java/com/diagbot/util/RedisUtil.java

@@ -5,8 +5,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
-import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -21,26 +19,6 @@ public class RedisUtil {
     @Qualifier("redisTemplateForSimilar")
     RedisTemplate redisTemplate;
 
-    /**
-     * 获取指定类型的数据
-     *
-     * @param list
-     * @param type
-     * @return
-     */
-    public Map<String, String> getValueByType(List<String> list, String type) {
-        Map<String, String> res = new LinkedHashMap<>();
-        Map<String, String> map = (Map<String, String>)redisTemplate.opsForValue().get(type);
-        if (map == null) {
-            return res;
-        }
-        for (String str : list) {
-            res.put(str, map.get(str) == null ? "" : map.get(str));
-        }
-        return res;
-    }
-
-
     /**
      * 获取指定类型的数据
      *

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

@@ -24,7 +24,6 @@ import org.springframework.web.bind.annotation.RestController;
 @Api(value = "缓存API", tags = { "缓存API" })
 public class CacheController {
 
-
     @Autowired
     CacheFacade cacheFacade;
 
@@ -36,4 +35,13 @@ public class CacheController {
         cacheFacade.clear();
         return RespDTO.onSuc(true);
     }
+
+    @ApiOperation(value = "清除标准词转换缓存[by:zhoutg]",
+            notes = "")
+    @PostMapping("/clearStandConvert")
+    @SysLogger("clearStandConvert")
+    public RespDTO<Boolean> clearStandConvert() {
+        cacheFacade.clearStandConvert();
+        return RespDTO.onSuc(true);
+    }
 }

+ 1 - 2
src/main/java/com/diagbot/web/TestController.java

@@ -55,8 +55,7 @@ public class TestController {
         return RespDTO.onSuc(testFacade.testStandConvert(standConvertCrfVO));
     }
 
-
-    @ApiOperation(value = "标准词转换API[zhoutg]", notes = "类型,疾病: disease,症状: symptom,手术和操作:operation,药品: drug,实验室检查:lis,辅助检查:pacs, 辅助检查:vital")
+    @ApiOperation(value = "标准词批量转换API[zhoutg]", notes = "类型,疾病: disease,症状: symptom,手术和操作:operation,药品: drug,实验室检查:lis,辅助检查:pacs, 辅助检查:vital")
     @PostMapping("/testStandConvertBatch")
     public RespDTO<StandConvertCrfBatchDTO> testStandConvertBatch(@RequestBody List<StandConvertCrfVO> standConvertCrfVOList) {
         return RespDTO.onSuc(testFacade.testStandConvertBatch(standConvertCrfVOList));