فهرست منبع

Merge branch 'develop' into dev/tcm_20210512

gaodm 4 سال پیش
والد
کامیت
e725d04bb5

+ 7 - 0
pom.xml

@@ -34,6 +34,7 @@
         <logstash.version>5.2</logstash.version>
         <docker-maven-plugin.version>1.2.1</docker-maven-plugin.version>
         <aggregator.version>1.1.3</aggregator.version>
+        <hanlp.version>portable-1.8.1</hanlp.version>
         <docker.image.prefix>192.168.2.236:5000/diagbotcloud</docker.image.prefix>
         <registryUrl>http://192.168.2.236:5000/repository/diagbotcloud/</registryUrl>
     </properties>
@@ -215,6 +216,12 @@
             <artifactId>spring-boot-data-aggregator-starter</artifactId>
             <version>${aggregator.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.hankcs</groupId>
+            <artifactId>hanlp</artifactId>
+            <version>${hanlp.version}</version>
+        </dependency>
     </dependencies>
 
     <!-- 私有仓库 -->

+ 1 - 0
src/main/java/com/diagbot/aggregate/PushNewAggregate.java

@@ -90,6 +90,7 @@ public class PushNewAggregate {
         Map<String, List<PushBaseDTO>> dis = new LinkedHashMap<>();
         pushDTO.setDis(dis);
         long start = System.currentTimeMillis();
+        pushNewVO.setWordCrfDTO(wordCrfDTO);
         try {
             PushNewDTO pushNewDTO = pushNewServiceClient.pushNew(pushNewVO);
             if (pushNewDTO == null || (pushNewDTO != null && pushNewDTO.getStatus().equals(-1))) {

+ 9 - 28
src/main/java/com/diagbot/config/CacheDeleteInit.java

@@ -1,6 +1,7 @@
 package com.diagbot.config;
 
 import com.diagbot.facade.CacheFacade;
+import com.diagbot.facade.ConceptInfoFacade;
 import com.diagbot.facade.NeoFacade;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,9 +23,12 @@ public class CacheDeleteInit implements CommandLineRunner {
     CacheFacade cacheFacade;
     @Autowired
     NeoFacade neoFacade;
+    @Autowired
+    private ConceptInfoFacade conceptInfoFacade;
+
 
     @Override
-    public void run(String... args) throws Exception {
+    public void run(String... args) {
         // 服务启动清除redis缓存
         cacheFacade.clear();
         log.info("CDSS-CORE服务启动清除redis缓存成功!");
@@ -44,37 +48,14 @@ public class CacheDeleteInit implements CommandLineRunner {
         cacheFacade.loadDeptPush();
         log.info("CDSS-CORE服务启动加载科室和推送映射成功!");
 
-        cacheFacade.loadAllBaseDiagnoseCache();
-        log.info("CDSS-CORE服务启动加载诊断依据缓存成功!");
-
         cacheFacade.loadAllRuleCache();
         log.info("CDSS-CORE服务启动加载医学知识库中的所有规则缓存成功!");
 
-//        cacheFacade.getDiseaseCorrespondCache();
-//        log.info("CDSS-CORE服务启动加载疾病对应ICD10缓存成功!");
-//
-//        cacheFacade.getdiseaseFilterCache();
-//        log.info("CDSS-CORE服务启动加载疾病过滤缓存成功!");
+        cacheFacade.loadAllBaseDiagnoseCache();
+        log.info("CDSS-CORE服务启动加载诊断依据缓存成功!");
 
-        //无用的缓存
-        //
-        //        cacheFacade.getSymptomCache();
-        //        log.info("CDSS-CORE服务启动加载图谱症状缓存成功!");
-        //
-        //        cacheFacade.getVitalCache();
-        //        log.info("CDSS-CORE服务启动加载图谱体征缓存成功!");
-        //
-        //        cacheFacade.getSymptomFeatureCache();
-        //        log.info("CDSS-CORE服务启动加载症状特征缓存成功!");
-        //
-        //        cacheFacade.getSymptomMainCache();
-        //        log.info("CDSS-CORE服务启动加载典型症状缓存成功!");
-        //
-        //        cacheFacade.loadDiseaseTypeCache();
-        //        log.info("CDSS-CORE服务启动加载疾病属性(性别、年龄、发病率)缓存成功!");
-        //
-        //        cacheFacade.getSymptomNumCache();
-        //        log.info("CDSS-CORE服务启动加载疾病对应的症状个数缓存成功!");
+        conceptInfoFacade.loadCustomDictionary();
+        log.info("CDSS-CORE服务启动加载NLP分词字典成功!");
 
         log.info("CDSS-CORE初始化完成!");
     }

+ 16 - 0
src/main/java/com/diagbot/dto/CustomDictionaryDTO.java

@@ -0,0 +1,16 @@
+package com.diagbot.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2021/5/25 20:03
+ */
+@Getter
+@Setter
+public class CustomDictionaryDTO {
+    private String name;
+    private String type;
+}

+ 326 - 30
src/main/java/com/diagbot/facade/CommonFacade.java

@@ -3,13 +3,18 @@ package com.diagbot.facade;
 import com.diagbot.biz.push.entity.Item;
 import com.diagbot.biz.push.entity.Lis;
 import com.diagbot.client.CRFServiceClient;
+import com.diagbot.client.StandConvertServiceClient;
 import com.diagbot.dto.BillMsg;
 import com.diagbot.dto.RuleDTO;
 import com.diagbot.dto.RuleExtDTO;
+import com.diagbot.dto.StandConvertCrfBatchDTO;
+import com.diagbot.dto.StandConvertCrfDTO;
 import com.diagbot.dto.WordCrfDTO;
 import com.diagbot.enums.LexiconEnum;
 import com.diagbot.enums.RedisEnum;
 import com.diagbot.enums.StandConvertEnum;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.model.ai.AIAnalyze;
 import com.diagbot.model.entity.BodyPart;
 import com.diagbot.model.entity.Clinical;
@@ -28,11 +33,13 @@ import com.diagbot.util.BeanUtil;
 import com.diagbot.util.CoreUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.RedisUtil;
+import com.diagbot.util.ReflectUtil;
 import com.diagbot.util.StringUtil;
 import com.diagbot.vo.NeoPushVO;
 import com.diagbot.vo.RuleVO;
 import com.diagbot.vo.SearchData;
 import com.diagbot.vo.StandConvert;
+import com.diagbot.vo.StandConvertCrfVO;
 import com.diagbot.vo.neoPushEntity.ChiefPushVo;
 import com.diagbot.vo.neoPushEntity.Diag;
 import com.diagbot.vo.neoPushEntity.DiagVo;
@@ -45,8 +52,9 @@ import com.google.common.collect.Lists;
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
-
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -73,23 +81,35 @@ public class CommonFacade {
     CommonRule commonRule;
     @Autowired
     RedisUtil redisUtil;
+    @Autowired
+    NLPFacade nlpFacade;
+    @Autowired
+    StandConvertServiceClient standConvertServiceClient;
+    @Value("${StandConvert.rate}")
+    String standConvertRate;
 
-    //组装好的label
-    public WordCrfDTO crf_process(SearchData searchData) {
+    /**
+     * 组装好label
+     *
+     * @param searchData
+     * @param participleFlag
+     * @return
+     */
+    public WordCrfDTO crf_process(SearchData searchData, Boolean participleFlag) {
         AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient);
         // 合并既往史:既往史+传染病史+手术外伤史+过敏史+接种史
         String unionPasts = searchData.getPasts();
         if (StringUtil.isNotBlank(searchData.getInfectious())) { // 传染病史
-            unionPasts = unionPasts + "。"  + searchData.getInfectious();
+            unionPasts = unionPasts + "。" + searchData.getInfectious();
         }
         if (StringUtil.isNotBlank(searchData.getSurgical())) { // 手术外伤史
-            unionPasts = unionPasts + "。"  + searchData.getSurgical();
+            unionPasts = unionPasts + "。" + searchData.getSurgical();
         }
         if (StringUtil.isNotBlank(searchData.getAllergy())) { // 过敏史
-            unionPasts = unionPasts + "。"  + searchData.getAllergy();
+            unionPasts = unionPasts + "。" + searchData.getAllergy();
         }
         if (StringUtil.isNotBlank(searchData.getVaccination())) { // 接种史
-            unionPasts = unionPasts + "。"  + searchData.getVaccination();
+            unionPasts = unionPasts + "。" + searchData.getVaccination();
         }
         searchData.setPasts(unionPasts);
 
@@ -173,10 +193,78 @@ public class CommonFacade {
 
         // 现病史中体征内容放入体征标签
         processPresentVital(wordCrfDTO);
+
+        // 加入分词
+        if (participleFlag) {
+            participle(wordCrfDTO);
+        }
         return wordCrfDTO;
     }
 
-    //返回给图谱的词,这些词需要转换成标准词
+    /**
+     * 分词
+     *
+     * @param wordCrfDTO
+     */
+    public void participle(WordCrfDTO wordCrfDTO) {
+        // 主诉症状分词
+        participleByType(wordCrfDTO.getChiefLabel().getClinicals(), String.valueOf(LexiconEnum.Symptom.getKey()));
+        // 现病史症状分词
+        participleByType(wordCrfDTO.getPresentLabel().getClinicals(), String.valueOf(LexiconEnum.Symptom.getKey()));
+    }
+
+    /**
+     * 根据类型分词,通用方法
+     *
+     * @param tList
+     * @param type
+     * @param <T>
+     */
+    public <T> void participleByType(List<T> tList, String type) {
+        List<T> participleList = Lists.newArrayList();
+        if (ListUtil.isNotEmpty(tList)) {
+            for (T t : tList) {
+                String val = ReflectUtil.getProperty(t, "name");
+                List<String> list = nlpFacade.getByType(val, type);
+                if (ListUtil.isNotEmpty(list)) {
+                    for (String s : list) {
+                        if (!s.equals(val)) { // 去除自身
+                            try {
+                                T tNew = (T) tList.get(0).getClass().newInstance(); // 泛型不能直接创建对象
+                                BeanUtil.copyProperties(t, tNew);
+                                ReflectUtil.setProperty(tNew, "name", s);
+                                ReflectUtil.setProperty(tNew, "standName", s);
+                                participleList.add(tNew);
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    }
+                }
+            }
+            if (ListUtil.isNotEmpty(participleList)) {
+                tList.addAll(participleList);
+            }
+        }
+    }
+
+    /**
+     * 同义词转换
+     *
+     * @param wordCrfDTO
+     */
+    public void wordStandConvert(WordCrfDTO wordCrfDTO) {
+        StandConvert standConvert = dataTypeGet(wordCrfDTO);
+        Map<String, Map<String, String>> standConvertMap = standConvertCrf(standConvert);
+        dataTypeSet(wordCrfDTO, standConvertMap);
+    }
+
+    /**
+     * 获取所有需要转标准词的词
+     *
+     * @param wordCrfDTO
+     * @return
+     */
     public StandConvert dataTypeGet(WordCrfDTO wordCrfDTO) {
         StandConvert standConvert = new StandConvert();
 
@@ -277,7 +365,12 @@ public class CommonFacade {
         return standConvert;
     }
 
-    //把图谱返回的标准词set到label中
+    /**
+     * 标准词set到label中
+     *
+     * @param wordCrfDTO
+     * @param map
+     */
     public void dataTypeSet(WordCrfDTO wordCrfDTO, Map<String, Map<String, String>> map) {
         ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
         PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
@@ -321,22 +414,22 @@ public class CommonFacade {
         // 6、结构化药品
         CoreUtil.setPropertyList(wordCrfDTO.getDrug(), "name", "uniqueName", map.get(StandConvertEnum.drug.toString()));
 
-//        // 【化验回填】
-//        // 1、普通化验
-//        CoreUtil.setPropertyList(lis, "detailName", "uniqueName", map.get(StandConvertEnum.lis.toString()));
-//        // 2、开单化验——取套餐
-//        CoreUtil.setPropertyList(wordCrfDTO.getLisOrder(), "name", "uniqueName", map.get(StandConvertEnum.lis.toString()));
-//
-//        // 【辅助项目回填】
-//        // 1、模型解析辅检项目
-//        CoreUtil.setPropertyList(pacsList, "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
-//        // 2、结构化辅检项目
-//        CoreUtil.setPropertyList(wordCrfDTO.getPacs(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
-//        // 3、开单辅检项目
-//        CoreUtil.setPropertyList(wordCrfDTO.getPacsOrder(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
-
-        CoreUtil.setUninameFromDetail(wordCrfDTO.getLis(),"detailName");
-        CoreUtil.setUninameFromDetail(wordCrfDTO.getLisOrder(),"name");
+        //        // 【化验回填】
+        //        // 1、普通化验
+        //        CoreUtil.setPropertyList(lis, "detailName", "uniqueName", map.get(StandConvertEnum.lis.toString()));
+        //        // 2、开单化验——取套餐
+        //        CoreUtil.setPropertyList(wordCrfDTO.getLisOrder(), "name", "uniqueName", map.get(StandConvertEnum.lis.toString()));
+        //
+        //        // 【辅助项目回填】
+        //        // 1、模型解析辅检项目
+        //        CoreUtil.setPropertyList(pacsList, "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
+        //        // 2、结构化辅检项目
+        //        CoreUtil.setPropertyList(wordCrfDTO.getPacs(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
+        //        // 3、开单辅检项目
+        //        CoreUtil.setPropertyList(wordCrfDTO.getPacsOrder(), "name", "uniqueName", map.get(StandConvertEnum.pacs.toString()));
+
+        CoreUtil.setUninameFromDetail(wordCrfDTO.getLis(), "detailName");
+        CoreUtil.setUninameFromDetail(wordCrfDTO.getLisOrder(), "name");
 
         pacsGetAndSet(wordCrfDTO);
 
@@ -363,6 +456,209 @@ public class CommonFacade {
         CoreUtil.setPropertyList(wordCrfDTO.getTransfusionOrder(), "name", "uniqueName", map.get(StandConvertEnum.transfusion.toString()));
     }
 
+    /**
+     * 标准词转换
+     * 类型,疾病: disease,症状: symptom,手术和操作:operation,药品: drug,实验室检查:lis,辅助检查:pacs, 辅助检查:vital"
+     *
+     * @param standConvert
+     * @return Map<String,Map<String,String>> -->Map<类型, Map<原始词, 标准词>>
+     */
+    public Map<String, Map<String, String>> standConvertCrf(StandConvert standConvert) {
+        Map<String, Map<String, String>> map = new LinkedHashMap<>();
+
+        List<StandConvertCrfVO> standConvertCrfVOList = new ArrayList<>();
+        List<String> clinicalConList = getConvertList(standConvert.getClinicalList(), StandConvertEnum.symptom.toString(), standConvertCrfVOList);
+        // List<String> operationConList = getConvertList(standConvert.getOperationList(), StandConvertEnum.operation.toString(), standConvertCrfVOList);
+        List<String> drugConList = getConvertList(standConvert.getDrugList(), StandConvertEnum.drug.toString(), standConvertCrfVOList);
+        List<String> vitallConList = getConvertList(standConvert.getVitalList(), StandConvertEnum.vital.toString(), standConvertCrfVOList);
+        List<String> diseaseConList = getConvertList(standConvert.getDiaglList(), StandConvertEnum.disease.toString(), standConvertCrfVOList);
+        // List<String> pacsConList = getConvertList(standConvert.getPacsList(), StandConvertEnum.pacs.toString(), standConvertCrfVOList);
+        // List<String> lisConList = getConvertList(standConvert.getLisList(), StandConvertEnum.lis.toString(), standConvertCrfVOList);
+        List<String> transfusionConList = getConvertList(standConvert.getTransfusionList(), StandConvertEnum.transfusion.toString(), standConvertCrfVOList);
+
+        StandConvertCrfBatchDTO standConvertCrfBatchDTO = new StandConvertCrfBatchDTO();
+        if (!(ListUtil.isEmpty(clinicalConList)
+                // && ListUtil.isEmpty(operationConList)
+                && ListUtil.isEmpty(drugConList)
+                && ListUtil.isEmpty(vitallConList)
+                && ListUtil.isEmpty(diseaseConList)
+                // && ListUtil.isEmpty(pacsConList)
+                // && ListUtil.isEmpty(lisConList)
+                && ListUtil.isEmpty(transfusionConList))) {
+            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.toString(), clinicalConList, standConvert.getClinicalList(), map);
+        // getConvertMap(crfMap, StandConvertEnum.operation.toString(), operationConList, standConvert.getOperationList(), map);
+        getConvertMap(crfMap, StandConvertEnum.drug.toString(), drugConList, standConvert.getDrugList(), map);
+        getConvertMap(crfMap, StandConvertEnum.vital.toString(), vitallConList, standConvert.getVitalList(), map);
+        getConvertMap(crfMap, StandConvertEnum.disease.toString(), diseaseConList, standConvert.getDiaglList(), map);
+        // getConvertMap(crfMap, StandConvertEnum.pacs.toString(), pacsConList, standConvert.getPacsList(), map);
+        // getConvertMap(crfMap, StandConvertEnum.lis.toString(), lisConList, standConvert.getLisList(), map);
+        getConvertMap(crfMap, StandConvertEnum.transfusion.toString(), transfusionConList, standConvert.getTransfusionList(), map);
+
+        return map;
+    }
+
+    /**
+     * 获取标准词转换map结果,并更新redis
+     *
+     * @param crfDTO
+     * @param type
+     * @param convertList
+     * @param map
+     */
+    public void getConvertMapDisease(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
+                                     List<String> originList, Map<String, Map<String, String>> map) {
+        Map<String, String> typeMap = new LinkedHashMap<>();
+
+        if (ListUtil.isNotEmpty(convertList)) {
+            Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
+            for (String s : convertList) {
+                boolean convertFlag = false;
+                String lastS = s;
+                if (StringUtil.isBlank(s)) {
+                    continue;
+                }
+                if (crfMap != null) {
+                    StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
+                    if (standConvertCrfDTO != null) {
+                        List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
+                        if (ListUtil.isEmpty(list)) {
+                            redisUtil.updateValue(type + "Conv:" + s, "");
+                        } else {
+                            String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
+                            if (StringUtil.isBlank(rateStr)) {
+                                redisUtil.updateValue(type + "Conv:" + s, "");
+                            } else {
+                                BigDecimal rate = new BigDecimal(rateStr);
+                                int flag = rate.compareTo(new BigDecimal(standConvertRate));
+                                if (flag < 0) {
+                                    redisUtil.updateValue(type + "Conv:" + s, "");
+                                } else {
+                                    redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
+                                    lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
+                                    convertFlag = true;
+                                }
+                            }
+                        }
+                    } else {
+                        redisUtil.updateValue(type + "Conv:" + s, "");
+                    }
+                } else {
+                    redisUtil.updateValue(type + "Conv:" + s, "");
+                }
+                if (convertFlag) {
+                    typeMap.put(s, lastS);
+                } else {
+                    typeMap.put(s, "");
+                }
+            }
+        }
+        // 将所有的词放入typeMap中
+        for (String s : originList) {
+            if (!typeMap.containsKey(s)) {
+                String value = redisUtil.get(type + "Conv:" + s);
+                typeMap.put(s, value);
+            }
+        }
+        map.put(type, typeMap);
+    }
+
+    /**
+     * 入参数据处理
+     *
+     * @param wordList
+     * @param type
+     * @param standConvertCrfVOList
+     */
+    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(wordList)) {
+            for (String s : wordList) {
+                String value = redisUtil.get(type + "Conv:" + s);
+                if (value == null) {
+                    StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
+                    standConvertCrfVO.setWord_type(type);
+                    standConvertCrfVO.setWord(s);
+                    standConvertCrfVOList.add(standConvertCrfVO);
+                    if (!convertList.contains(s)) {
+                        convertList.add(s);
+                    }
+                }
+            }
+        }
+        return convertList;
+    }
+
+    /**
+     * 获取标准词转换map结果,并更新redis
+     *
+     * @param crfDTO
+     * @param type
+     * @param convertList
+     * @param map
+     */
+    public void getConvertMap(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
+                              List<String> originList, Map<String, Map<String, String>> map) {
+        Map<String, String> typeMap = new LinkedHashMap<>();
+
+        if (ListUtil.isNotEmpty(convertList)) {
+            Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
+            for (String s : convertList) {
+                String lastS = s;
+                if (StringUtil.isBlank(s)) {
+                    continue;
+                }
+                if (crfMap != null) {
+                    StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
+                    if (standConvertCrfDTO != null) {
+                        List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
+                        if (ListUtil.isEmpty(list)) {
+                            redisUtil.updateValue(type + "Conv:" + s, s);
+                        } else {
+                            String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
+                            if (StringUtil.isBlank(rateStr)) {
+                                redisUtil.updateValue(type + "Conv:" + s, s);
+                            } else {
+                                BigDecimal rate = new BigDecimal(rateStr);
+                                int flag = rate.compareTo(new BigDecimal(standConvertRate));
+                                if (flag < 0) {
+                                    redisUtil.updateValue(type + "Conv:" + s, s);
+                                } else {
+                                    redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
+                                    lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
+                                }
+                            }
+                        }
+                    } else {
+                        redisUtil.updateValue(type + "Conv:" + s, s);
+                    }
+                } else {
+                    redisUtil.updateValue(type + "Conv:" + s, s);
+                }
+                typeMap.put(s, lastS);
+            }
+        }
+        // 将所有的词放入typeMap中
+        for (String s : originList) {
+            if (!typeMap.containsKey(s)) {
+                String value = redisUtil.get(type + "Conv:" + s);
+                typeMap.put(s, value);
+            }
+        }
+        map.put(type, typeMap);
+    }
+
     /**
      * 手术映射(关闭同义词转换)
      *
@@ -444,15 +740,15 @@ public class CommonFacade {
     /**
      * 替换映射内容
      *
-     * @param obj 对象
+     * @param obj          对象
      * @param listProperty 获取List属性名
-     * @param objProperty 对象属性名
-     * @param configMap 映射Map
+     * @param objProperty  对象属性名
+     * @param configMap    映射Map
      */
     public <T> void setListProperty(Object obj, String listProperty, String objProperty, Map<String, Map<String, Long>> configMap) {
         Object tList = CoreUtil.getFieldValue(obj, listProperty);
-        List<T> newList = convertStandName((List)tList, configMap, objProperty);
-        CoreUtil.setFieldValue(obj, listProperty, newList);
+        List<T> newList = convertStandName((List) tList, configMap, objProperty);
+        ReflectUtil.setProperty(obj, listProperty, newList);
     }
 
     /**

+ 12 - 0
src/main/java/com/diagbot/facade/ConceptInfoFacade.java

@@ -1,6 +1,7 @@
 package com.diagbot.facade;
 
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.diagbot.dto.CustomDictionaryDTO;
 import com.diagbot.dto.ReverseDTO;
 import com.diagbot.entity.ConceptInfo;
 import com.diagbot.enums.IsDeleteEnum;
@@ -8,6 +9,7 @@ import com.diagbot.service.impl.ConceptInfoServiceImpl;
 import com.diagbot.util.ListUtil;
 import com.diagbot.vo.ReverseVO;
 import com.google.common.collect.Lists;
+import com.hankcs.hanlp.dictionary.CustomDictionary;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
@@ -49,4 +51,14 @@ public class ConceptInfoFacade extends ConceptInfoServiceImpl {
         }
         return Lists.newArrayList();
     }
+
+    public void loadCustomDictionary(){
+        CustomDictionary.reload();
+        List<CustomDictionaryDTO> words = this.getAllWord();
+        if (ListUtil.isNotEmpty(words)){
+            for (CustomDictionaryDTO dictionaryDTO: words){
+                CustomDictionary.insert(dictionaryDTO.getName().trim().replaceAll(" ",""), dictionaryDTO.getType());
+            }
+        }
+    }
 }

+ 30 - 41
src/main/java/com/diagbot/facade/IndicationFacade.java

@@ -6,15 +6,12 @@ import com.diagbot.dto.WordCrfDTO;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.util.CoreUtil;
-import com.diagbot.util.ListUtil;
 import com.diagbot.util.ParamUtil;
 import com.diagbot.vo.IndicationPushVO;
-import com.diagbot.vo.StandConvert;
 import io.github.lvyahui8.spring.facade.DataFacade;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -40,16 +37,14 @@ public class IndicationFacade {
     @Autowired
     KlRegularConfigFacade klRegularConfigFacade;
 
-    private static final Map<String, List<String>> methodMap;
-
-    static {
-        methodMap = new HashMap<>();
-        methodMap.put("1", Arrays.asList("crf", "stand"));
-        methodMap.put("2", Arrays.asList("crf", "stand"));
-        methodMap.put("3", Arrays.asList("crf", "stand"));
-        methodMap.put("4", Arrays.asList("crf", "stand"));
-    }
-
+    // private static final Map<String, List<String>> methodMap;
+    // static {
+    //     methodMap = new HashMap<>();
+    //     methodMap.put("1", Arrays.asList("crf", "stand"));
+    //     methodMap.put("2", Arrays.asList("crf", "stand"));
+    //     methodMap.put("3", Arrays.asList("crf", "stand"));
+    //     methodMap.put("4", Arrays.asList("crf", "stand"));
+    // }
 
     /**
      * 提示总入口
@@ -64,36 +59,16 @@ public class IndicationFacade {
         List<String> ruleTypeList = Arrays.asList(indicationPushVO.getRuleType().split(","));
         indicationPushVO.setRuleTypeList(ruleTypeList);
 
-        List<String> methodList = new ArrayList<>();
-        for (String ruleType : ruleTypeList) {
-            if (ListUtil.isNotEmpty(methodMap.get(ruleType))) {
-                List<String> methods = methodMap.get(ruleType);
-                for (String method : methods) {
-                    if (!methodList.contains(method)) {
-                        methodList.add(method);
-                    }
-                }
-            }
-        }
-
-        WordCrfDTO wordCrfDTO = new WordCrfDTO();
-        long l1 = System.currentTimeMillis();
+        long start = System.currentTimeMillis();
+        // CRF模型处理
+        WordCrfDTO wordCrfDTO = commonFacade.crf_process(indicationPushVO, false);
+        CoreUtil.getDebugStr(start, "模型处理耗时", debug);
 
-        // 模型处理数据
-        long crfStart = System.currentTimeMillis();
-        if (methodList.contains("crf")) {
-            wordCrfDTO = commonFacade.crf_process(indicationPushVO);
-        }
-        CoreUtil.getDebugStr(crfStart, "模型处理耗时", debug);
-
-        // 标准词转换
+        // 同义词转换
         long standStart = System.currentTimeMillis();
-        if (methodList.contains("stand")) {
-            StandConvert standConvert = commonFacade.dataTypeGet(wordCrfDTO);
-            Map<String, Map<String, String>> standConvertMap = neoFacade.standConvertCrf(standConvert);
-            commonFacade.dataTypeSet(wordCrfDTO, standConvertMap);
-        }
+        commonFacade.wordStandConvert(wordCrfDTO);
         CoreUtil.getDebugStr(standStart, "标准词转换耗时", debug);
+
         //正则匹配开始
         wordCrfDTO = klRegularConfigFacade.getRegularConfigs(wordCrfDTO, indicationPushVO);
         //正则匹配结束
@@ -114,8 +89,22 @@ public class IndicationFacade {
         }
 
         // 输入调试信息
-        CoreUtil.getDebugStr(l1, "本次调用总计耗时", res.getDebug());
+        CoreUtil.getDebugStr(start, "本次调用总计耗时", res.getDebug());
         CoreUtil.getDebugObject("数据", res.getDebug(), wordCrfDTO);
         return res;
     }
+
+    /**
+     * 提示总入口
+     *
+     * @param
+     * @return
+     */
+    public WordCrfDTO getWordCrfDTO(IndicationPushVO indicationPushVO) {
+        // CRF模型处理
+        WordCrfDTO wordCrfDTO = commonFacade.crf_process(indicationPushVO, true);
+        // 同义词转换
+        commonFacade.wordStandConvert(wordCrfDTO);
+        return wordCrfDTO;
+    }
 }

+ 73 - 0
src/main/java/com/diagbot/facade/NLPFacade.java

@@ -0,0 +1,73 @@
+package com.diagbot.facade;
+
+import com.google.common.collect.Lists;
+import com.hankcs.hanlp.HanLP;
+import com.hankcs.hanlp.seg.common.Term;
+import org.springframework.stereotype.Component;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2021/5/25 20:13
+ */
+@Component
+public class NLPFacade {
+
+    public String segment(String text) {
+        return HanLP.segment(text).toString();
+    }
+
+    /**
+     * 返回所有结果
+     *
+     * @param text
+     * @return
+     */
+    public Map<String, List<String>> getMap(String text) {
+        Map<String, List<String>> map = new LinkedHashMap<>();
+        List<Term> termList = HanLP.segment(text);
+        for (Term term : termList) {
+            String word = term.word;
+            String type = term.nature.toString();
+            List<String> splitTypeList = Lists.newArrayList(type.split(","));
+            for (String t : splitTypeList) {
+                if (map.get(t) != null) {
+                    map.get(t).add(word);
+                } else {
+                    List<String> wordList = Lists.newArrayList();
+                    wordList.add(word);
+                    map.put(t, wordList);
+                }
+            }
+        }
+        return map;
+    }
+
+    /**
+     * 根据指定指定返回结果
+     *
+     * @param text
+     * @param filterType
+     * @return
+     */
+    public List<String> getByType(String text, String filterType) {
+        List<String> res = Lists.newArrayList();
+        List<Term> termList = HanLP.segment(text);
+        for (Term term : termList) {
+            String word = term.word;
+            String type = term.nature.toString();
+            List<String> splitTypeList = Lists.newArrayList(type.split(","));
+            for (String splitType : splitTypeList) {
+                if (filterType.equals(splitType)) {
+                    res.add(word);
+                }
+            }
+        }
+        return res;
+    }
+
+}

+ 0 - 216
src/main/java/com/diagbot/facade/NeoFacade.java

@@ -9,17 +9,12 @@ import com.diagbot.dto.DrugTypeCacheDTO;
 import com.diagbot.dto.DrugTypeDTO;
 import com.diagbot.dto.NeoPushDTO;
 import com.diagbot.dto.RuleDTO;
-import com.diagbot.dto.StandConvertCrfBatchDTO;
-import com.diagbot.dto.StandConvertCrfDTO;
 import com.diagbot.entity.KlDiseaseCorresponding;
 import com.diagbot.entity.SymptomFeature;
 import com.diagbot.entity.TranHospitalFilter;
 import com.diagbot.enums.IsDeleteEnum;
 import com.diagbot.enums.PushRelationTypeEnum;
 import com.diagbot.enums.RedisEnum;
-import com.diagbot.enums.StandConvertEnum;
-import com.diagbot.exception.CommonErrorCode;
-import com.diagbot.exception.CommonException;
 import com.diagbot.model.entity.PD;
 import com.diagbot.service.KlDiseaseCorrespondingService;
 import com.diagbot.service.SymptomFeatureService;
@@ -30,8 +25,6 @@ import com.diagbot.util.RedisUtil;
 import com.diagbot.util.StringUtil;
 import com.diagbot.vo.DiseaseItemVO;
 import com.diagbot.vo.NeoPushVO;
-import com.diagbot.vo.StandConvert;
-import com.diagbot.vo.StandConvertCrfVO;
 import com.diagbot.vo.neoPushEntity.ChiefPushVo;
 import com.diagbot.vo.neoPushEntity.Diag;
 import com.diagbot.vo.neoPushEntity.PresentPushVo;
@@ -41,11 +34,9 @@ import com.google.common.collect.Maps;
 import org.apache.commons.collections.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -72,8 +63,6 @@ public class NeoFacade {
     @Autowired
     @Qualifier("redisTemplateForSimilar")
     RedisTemplate redisTemplate;
-    @Value("${StandConvert.rate}")
-    String standConvertRate;
     @Autowired
     SymptomFeatureService symptomFeatureService;
     @Autowired
@@ -489,211 +478,6 @@ public class NeoFacade {
         }
     }
 
-
-    /**
-     * 标准词转换
-     * 类型,疾病: disease,症状: symptom,手术和操作:operation,药品: drug,实验室检查:lis,辅助检查:pacs, 辅助检查:vital"
-     *
-     * @param standConvert
-     * @return Map<String,Map<String,String>> -->Map<类型, Map<原始词, 标准词>>
-     */
-    public Map<String, Map<String, String>> standConvertCrf(StandConvert standConvert) {
-        Map<String, Map<String, String>> map = new LinkedHashMap<>();
-
-        List<StandConvertCrfVO> standConvertCrfVOList = new ArrayList<>();
-        List<String> clinicalConList = getConvertList(standConvert.getClinicalList(), StandConvertEnum.symptom.toString(), standConvertCrfVOList);
-        // List<String> operationConList = getConvertList(standConvert.getOperationList(), StandConvertEnum.operation.toString(), standConvertCrfVOList);
-        List<String> drugConList = getConvertList(standConvert.getDrugList(), StandConvertEnum.drug.toString(), standConvertCrfVOList);
-        List<String> vitallConList = getConvertList(standConvert.getVitalList(), StandConvertEnum.vital.toString(), standConvertCrfVOList);
-        List<String> diseaseConList = getConvertList(standConvert.getDiaglList(), StandConvertEnum.disease.toString(), standConvertCrfVOList);
-        // List<String> pacsConList = getConvertList(standConvert.getPacsList(), StandConvertEnum.pacs.toString(), standConvertCrfVOList);
-        // List<String> lisConList = getConvertList(standConvert.getLisList(), StandConvertEnum.lis.toString(), standConvertCrfVOList);
-        List<String> transfusionConList = getConvertList(standConvert.getTransfusionList(), StandConvertEnum.transfusion.toString(), standConvertCrfVOList);
-
-        StandConvertCrfBatchDTO standConvertCrfBatchDTO = new StandConvertCrfBatchDTO();
-        if (!(ListUtil.isEmpty(clinicalConList)
-                // && ListUtil.isEmpty(operationConList)
-                && ListUtil.isEmpty(drugConList)
-                && ListUtil.isEmpty(vitallConList)
-                && ListUtil.isEmpty(diseaseConList)
-                // && ListUtil.isEmpty(pacsConList)
-                // && ListUtil.isEmpty(lisConList)
-                && ListUtil.isEmpty(transfusionConList))) {
-            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.toString(), clinicalConList, standConvert.getClinicalList(), map);
-        // getConvertMap(crfMap, StandConvertEnum.operation.toString(), operationConList, standConvert.getOperationList(), map);
-        getConvertMap(crfMap, StandConvertEnum.drug.toString(), drugConList, standConvert.getDrugList(), map);
-        getConvertMap(crfMap, StandConvertEnum.vital.toString(), vitallConList, standConvert.getVitalList(), map);
-        getConvertMap(crfMap, StandConvertEnum.disease.toString(), diseaseConList, standConvert.getDiaglList(), map);
-        // getConvertMap(crfMap, StandConvertEnum.pacs.toString(), pacsConList, standConvert.getPacsList(), map);
-        // getConvertMap(crfMap, StandConvertEnum.lis.toString(), lisConList, standConvert.getLisList(), map);
-        getConvertMap(crfMap, StandConvertEnum.transfusion.toString(), transfusionConList, standConvert.getTransfusionList(), map);
-
-        return map;
-    }
-
-    /**
-     * 入参数据处理
-     *
-     * @param wordList
-     * @param type
-     * @param standConvertCrfVOList
-     */
-    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(wordList)) {
-            for (String s : wordList) {
-                String value = redisUtil.get(type + "Conv:" + s);
-                if (value == null) {
-                    StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
-                    standConvertCrfVO.setWord_type(type);
-                    standConvertCrfVO.setWord(s);
-                    standConvertCrfVOList.add(standConvertCrfVO);
-                    if (!convertList.contains(s)) {
-                        convertList.add(s);
-                    }
-                }
-            }
-        }
-        return convertList;
-    }
-
-    /**
-     * 获取标准词转换map结果,并更新redis
-     *
-     * @param crfDTO
-     * @param type
-     * @param convertList
-     * @param map
-     */
-    public void getConvertMap(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
-                              List<String> originList, Map<String, Map<String, String>> map) {
-        Map<String, String> typeMap = new LinkedHashMap<>();
-
-        if (ListUtil.isNotEmpty(convertList)) {
-            Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
-            for (String s : convertList) {
-                String lastS = s;
-                if (StringUtil.isBlank(s)) {
-                    continue;
-                }
-                if (crfMap != null) {
-                    StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
-                    if (standConvertCrfDTO != null) {
-                        List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
-                        if (ListUtil.isEmpty(list)) {
-                            redisUtil.updateValue(type + "Conv:" + s, s);
-                        } else {
-                            String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
-                            if (StringUtil.isBlank(rateStr)) {
-                                redisUtil.updateValue(type + "Conv:" + s, s);
-                            } else {
-                                BigDecimal rate = new BigDecimal(rateStr);
-                                int flag = rate.compareTo(new BigDecimal(standConvertRate));
-                                if (flag < 0) {
-                                    redisUtil.updateValue(type + "Conv:" + s, s);
-                                } else {
-                                    redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
-                                    lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
-                                }
-                            }
-                        }
-                    } else {
-                        redisUtil.updateValue(type + "Conv:" + s, s);
-                    }
-                } else {
-                    redisUtil.updateValue(type + "Conv:" + s, s);
-                }
-                typeMap.put(s, lastS);
-            }
-        }
-        // 将所有的词放入typeMap中
-        for (String s : originList) {
-            if (!typeMap.containsKey(s)) {
-                String value = redisUtil.get(type + "Conv:" + s);
-                typeMap.put(s, value);
-            }
-        }
-        map.put(type, typeMap);
-    }
-
-
-    /**
-     * 获取标准词转换map结果,并更新redis
-     *
-     * @param crfDTO
-     * @param type
-     * @param convertList
-     * @param map
-     */
-    public void getConvertMapDisease(Map<String, Map<String, StandConvertCrfDTO>> crfDTO, String type, List<String> convertList,
-                                     List<String> originList, Map<String, Map<String, String>> map) {
-        Map<String, String> typeMap = new LinkedHashMap<>();
-
-        if (ListUtil.isNotEmpty(convertList)) {
-            Map<String, StandConvertCrfDTO> crfMap = crfDTO.get(type);
-            for (String s : convertList) {
-                boolean convertFlag = false;
-                String lastS = s;
-                if (StringUtil.isBlank(s)) {
-                    continue;
-                }
-                if (crfMap != null) {
-                    StandConvertCrfDTO standConvertCrfDTO = crfMap.get(s);
-                    if (standConvertCrfDTO != null) {
-                        List<Map<String, String>> list = standConvertCrfDTO.getStandard_words();
-                        if (ListUtil.isEmpty(list)) {
-                            redisUtil.updateValue(type + "Conv:" + s, "");
-                        } else {
-                            String rateStr = standConvertCrfDTO.getStandard_words().get(0).get("rate");
-                            if (StringUtil.isBlank(rateStr)) {
-                                redisUtil.updateValue(type + "Conv:" + s, "");
-                            } else {
-                                BigDecimal rate = new BigDecimal(rateStr);
-                                int flag = rate.compareTo(new BigDecimal(standConvertRate));
-                                if (flag < 0) {
-                                    redisUtil.updateValue(type + "Conv:" + s, "");
-                                } else {
-                                    redisUtil.updateValue(type + "Conv:" + s, standConvertCrfDTO.getStandard_words().get(0).get("standard_word"));
-                                    lastS = standConvertCrfDTO.getStandard_words().get(0).get("standard_word");
-                                    convertFlag = true;
-                                }
-                            }
-                        }
-                    } else {
-                        redisUtil.updateValue(type + "Conv:" + s, "");
-                    }
-                } else {
-                    redisUtil.updateValue(type + "Conv:" + s, "");
-                }
-                if (convertFlag) {
-                    typeMap.put(s, lastS);
-                } else {
-                    typeMap.put(s, "");
-                }
-            }
-        }
-        // 将所有的词放入typeMap中
-        for (String s : originList) {
-            if (!typeMap.containsKey(s)) {
-                String value = redisUtil.get(type + "Conv:" + s);
-                typeMap.put(s, value);
-            }
-        }
-        map.put(type, typeMap);
-    }
-
     public void allRuleCache() {
         List<RuleDTO> ruleDTOList = klRuleFacade.getAllRule();
         if (ListUtil.isNotEmpty(ruleDTOList)) {

+ 5 - 10
src/main/java/com/diagbot/facade/PushFacade.java

@@ -21,7 +21,6 @@ import com.diagbot.util.StringUtil;
 import com.diagbot.vo.PushNewVO;
 import com.diagbot.vo.PushPlanVO;
 import com.diagbot.vo.PushVO;
-import com.diagbot.vo.StandConvert;
 import com.google.common.collect.Lists;
 import io.github.lvyahui8.spring.facade.DataFacade;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -146,16 +145,14 @@ public class PushFacade {
         Map<String, Object> debug = new LinkedHashMap<>();
         debug.put("大数据推送地址", pushUrl);
 
-        // 模型处理数据
+        // CRF模型处理
         long start = System.currentTimeMillis();
-        WordCrfDTO wordCrfDTO = commonFacade.crf_process(pushVo);
+        WordCrfDTO wordCrfDTO = commonFacade.crf_process(pushVo, false);
         CoreUtil.getDebugStr(start, "模型处理耗时", debug);
 
-        // 标准词转换
+        // 同义词转换
         long standStart = System.currentTimeMillis();
-        StandConvert standConvert = commonFacade.dataTypeGet(wordCrfDTO);
-        Map<String, Map<String, String>> standConvertMap = neoFacade.standConvertCrf(standConvert);
-        commonFacade.dataTypeSet(wordCrfDTO, standConvertMap);
+        commonFacade.wordStandConvert(wordCrfDTO);
         CoreUtil.getDebugStr(standStart, "标准词转换耗时", debug);
         ParamUtil.dealLis(wordCrfDTO.getLis());
 
@@ -306,9 +303,7 @@ public class PushFacade {
             wordCrfDTO.setOperationName(pushPlanVO.getOperationName());
             // 标准词转换
             long standStart = System.currentTimeMillis();
-            StandConvert standConvert = commonFacade.dataTypeGet(wordCrfDTO);
-            Map<String, Map<String, String>> standConvertMap = neoFacade.standConvertCrf(standConvert);
-            commonFacade.dataTypeSet(wordCrfDTO, standConvertMap);
+            commonFacade.wordStandConvert(wordCrfDTO);
             CoreUtil.getDebugStr(standStart, "标准词转换耗时", debug);
             // 推送随访计划
             long pushStart = System.currentTimeMillis();

+ 4 - 1
src/main/java/com/diagbot/mapper/ConceptInfoMapper.java

@@ -1,6 +1,7 @@
 package com.diagbot.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.diagbot.dto.CustomDictionaryDTO;
 import com.diagbot.dto.ReverseDTO;
 import com.diagbot.entity.ConceptInfo;
 import com.diagbot.vo.ReverseVO;
@@ -17,5 +18,7 @@ import java.util.List;
  */
 public interface ConceptInfoMapper extends BaseMapper<ConceptInfo> {
 
-    public List<ReverseDTO> getReverse(ReverseVO reverseVO);
+    List<ReverseDTO> getReverse(ReverseVO reverseVO);
+
+    List<CustomDictionaryDTO> getAllWord();
 }

+ 4 - 1
src/main/java/com/diagbot/service/ConceptInfoService.java

@@ -1,6 +1,7 @@
 package com.diagbot.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.diagbot.dto.CustomDictionaryDTO;
 import com.diagbot.dto.ReverseDTO;
 import com.diagbot.entity.ConceptInfo;
 import com.diagbot.vo.ReverseVO;
@@ -17,5 +18,7 @@ import java.util.List;
  */
 public interface ConceptInfoService extends IService<ConceptInfo> {
 
-    public List<ReverseDTO> getReverse(ReverseVO reverseVO);
+    List<ReverseDTO> getReverse(ReverseVO reverseVO);
+
+    List<CustomDictionaryDTO> getAllWord();
 }

+ 6 - 0
src/main/java/com/diagbot/service/impl/ConceptInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.diagbot.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.dto.CustomDictionaryDTO;
 import com.diagbot.dto.ReverseDTO;
 import com.diagbot.entity.ConceptInfo;
 import com.diagbot.mapper.ConceptInfoMapper;
@@ -24,4 +25,9 @@ public class ConceptInfoServiceImpl extends ServiceImpl<ConceptInfoMapper, Conce
     public List<ReverseDTO> getReverse(ReverseVO reverseVO) {
         return baseMapper.getReverse(reverseVO);
     }
+
+    @Override
+    public List<CustomDictionaryDTO> getAllWord(){
+        return baseMapper.getAllWord();
+    }
 }

+ 1 - 22
src/main/java/com/diagbot/util/CoreUtil.java

@@ -266,32 +266,11 @@ public class CoreUtil {
             String value = (String)getFieldValue(r, "uniqueName");
             if (StringUtil.isBlank(value)) {
                 String detailName = (String) getFieldValue(r, targetProperty);
-                setFieldValue(r, "uniqueName", detailName);
+                ReflectUtil.setProperty(r, "uniqueName", detailName);
             }
         }
     }
 
-    /**
-     * 对象赋值
-     *
-     * @param object
-     * @param property
-     * @param value
-     */
-    public static void setFieldValue(Object object, String property, Object value){
-        //根据 对象和属性名通过反射 调用上面的方法获取 Field对象
-        Field field = getDeclaredField(object, property) ;
-        //抑制Java对其的检查
-        field.setAccessible(true) ;
-        try {
-            field.set(object, value);
-        } catch (IllegalArgumentException e) {
-            e.printStackTrace();
-        } catch (IllegalAccessException e) {
-            e.printStackTrace();
-        }
-    }
-
     /**
      * 将对象添加到列表中
      *

+ 49 - 11
src/main/java/com/diagbot/util/ReflectUtil.java

@@ -3,6 +3,8 @@ package com.diagbot.util;
 import com.google.common.collect.Lists;
 
 import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 /**
@@ -42,17 +44,6 @@ public class ReflectUtil {
         return res;
     }
 
-    /**
-     * 获取属性对应的值,以list形式返回——重载
-     *
-     * @param list
-     * @param <T>
-     * @return
-     */
-    public static <T> List<String> getPropertyList(List<T> list) {
-        return getPropertyList(list, "name");
-    }
-
     /**
      * 循环向上转型, 获取对象的 DeclaredField
      *
@@ -100,6 +91,53 @@ public class ReflectUtil {
         return null;
     }
 
+    /**
+     * 对象赋值
+     *
+     * @param object
+     * @param property
+     * @param value
+     */
+    public static void setProperty(Object object, String property, Object value) {
+        //根据 对象和属性名通过反射 调用上面的方法获取 Field对象
+        Field field = getDeclaredField(object, property);
+        //抑制Java对其的检查
+        field.setAccessible(true);
+        try {
+            field.set(object, value);
+        } catch (IllegalArgumentException e) {
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 根据指定字段按照字符串排序
+     *
+     * @param tList
+     * @param property
+     * @param <T>
+     */
+    public <T> void sort(List<T> tList, String property) {
+        if (ListUtil.isNotEmpty(tList) && tList.size() > 1) {
+            Collections.sort(tList, new Comparator<T>() {
+                @Override
+                public int compare(T o1, T o2) {
+                    String v1 = getProperty(o1, property);
+                    String v2 = getProperty(o2, property);
+                    if (StringUtil.isBlank(v1)) {
+                        return -1;
+                    }
+                    if (StringUtil.isBlank(v2)) {
+                        return 1;
+                    }
+                    return v1.compareTo(v2);
+                }
+            });
+        }
+    }
+
     public static void main(String[] args) {
 
     }

+ 3 - 1
src/main/java/com/diagbot/vo/PushNewVO.java

@@ -1,5 +1,6 @@
 package com.diagbot.vo;
 
+import com.diagbot.dto.WordCrfDTO;
 import lombok.Data;
 
 /**
@@ -9,10 +10,11 @@ import lombok.Data;
  */
 @Data
 public class PushNewVO {
-    private String hospitalType = "0"; // 模型类型, 0:全科、妇幼、精神,1:精神
+    private String hospitalType = "0";
     private Double age; // 年龄
     private Integer sex; // 性别
     private String chief; // 主诉
     private String present; // 现病史
     private Integer num = 10; // 疾病个数
+    private WordCrfDTO wordCrfDTO = new WordCrfDTO();
 }

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

@@ -3,6 +3,7 @@ package com.diagbot.web;
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.CacheFacade;
+import com.diagbot.facade.ConceptInfoFacade;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -28,6 +29,8 @@ public class CacheController {
 
     @Autowired
     CacheFacade cacheFacade;
+    @Autowired
+    private ConceptInfoFacade conceptInfoFacade;
 
     @ApiOperation(value = "清除启动加载类缓存[by:zhoutg]",
             notes = "")
@@ -137,4 +140,12 @@ public class CacheController {
         return RespDTO.onSuc(true);
     }
 
+    @ApiOperation(value = "重新加载NLP分词字典[by:gaodm]",
+            notes = "")
+    @PostMapping("/reloadCustomDictionary")
+    @SysLogger("reloadCustomDictionary")
+    public RespDTO<Boolean> reloadCustomDictionary() {
+        conceptInfoFacade.loadCustomDictionary();
+        return RespDTO.onSuc(true);
+    }
 }

+ 38 - 0
src/main/java/com/diagbot/web/CrfController.java

@@ -0,0 +1,38 @@
+package com.diagbot.web;
+
+import com.diagbot.dto.RespDTO;
+import com.diagbot.dto.WordCrfDTO;
+import com.diagbot.facade.IndicationFacade;
+import com.diagbot.vo.IndicationPushVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+/**
+ * @Description: crf转换控制层
+ * @author: zhoutg
+ * @time: 2018/8/30 10:12
+ */
+@RestController
+@RequestMapping("/crf")
+@Api(value = "crf转换API", tags = { "crf转换API" })
+@SuppressWarnings("unchecked")
+public class CrfController {
+
+    @Autowired
+    IndicationFacade indicationFacade;
+
+    @ApiOperation(value = "CRF转换[zhoutg]", notes = "ruleType(1:危急值提醒,2:开单合理项,3:高危药品、手术,4:其他提醒)")
+    @PostMapping("/getWordCrfDTO")
+    public RespDTO<WordCrfDTO> getWordCrfDTO(@Valid @RequestBody IndicationPushVO indicationPushVO) {
+        WordCrfDTO wordCrfDTO = indicationFacade.getWordCrfDTO(indicationPushVO);
+        return RespDTO.onSuc(wordCrfDTO);
+    }
+
+}

+ 44 - 0
src/main/java/com/diagbot/web/NLPController.java

@@ -0,0 +1,44 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.NLPFacade;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2021/5/25 20:09
+ */
+@RequestMapping("/nlp")
+@RestController
+@SuppressWarnings("unchecked")
+@Api(value = "NLP API", tags = { "NLP API" })
+public class NLPController {
+    @Autowired
+    private NLPFacade nlpFacade;
+
+    @ApiOperation(value = "NLP分词[by:gaodm]",
+            notes = "")
+    @PostMapping("/segment")
+    @SysLogger("segment")
+    public RespDTO<String> segment(String text){
+        return RespDTO.onSuc(nlpFacade.segment(text));
+    }
+
+    @ApiOperation(value = "NLP分词放入组[by:zhoutg]",
+            notes = "")
+    @PostMapping("/getMap")
+    @SysLogger("getMap")
+    public RespDTO<Map> getMap(String text){
+        return RespDTO.onSuc(nlpFacade.getMap(text));
+    }
+
+}

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

@@ -185,7 +185,7 @@ public class TestController {
 
     @ApiOperation(value = "crf解析测试[zhoutg]", notes = "content:文本内容\n" +
             "modelType:模型类型,主诉、现病史:chief_present,既往史:PastFamily_cx,查体:Present_cx,个人史:PersonalHistory_cx,诊断:Diagnoses_cx")
-    @PostMapping("/testCrf")
+    @PostMapping("/A_testCrf")
     public RespDTO<Object> testCrf(@RequestBody TestCrfVO testCrfVO) {
         return RespDTO.onSuc(testFacade.testCrf(testCrfVO));
     }

+ 17 - 0
src/main/resources/mapper/ConceptInfoMapper.xml

@@ -72,4 +72,21 @@
         t.order_no
     </select>
 
+    <select id="getAllWord" resultType="com.diagbot.dto.CustomDictionaryDTO">
+        SELECT
+            a. NAME,
+            CONCAT_WS(" ",GROUP_CONCAT(a.type_id),1024) AS type
+        FROM
+            kl_library_info a,
+            kl_concept b
+        WHERE
+            a.is_deleted = 'N'
+        AND b.is_deleted = 'N'
+        AND a.id = b.lib_id
+        AND b.`status` = 1
+        AND a.type_id IN (103, 122, 126, 129)
+        GROUP BY
+            a.`name`
+    </select>
+
 </mapper>