|
@@ -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);
|
|
|
}
|
|
|
}
|