|
@@ -0,0 +1,191 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.diagbot.client.CRFServiceClient;
|
|
|
+import com.diagbot.dto.StandConvertCrfBatchDTO;
|
|
|
+import com.diagbot.dto.StandConvertCrfDTO;
|
|
|
+import com.diagbot.dto.WordCrfDTO;
|
|
|
+import com.diagbot.entity.TestwordInfo;
|
|
|
+import com.diagbot.entity.TestwordRes;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.model.ai.AIAnalyze;
|
|
|
+import com.diagbot.service.TestwordInfoService;
|
|
|
+import com.diagbot.service.TestwordResService;
|
|
|
+import com.diagbot.service.impl.TestwordInfoServiceImpl;
|
|
|
+import com.diagbot.util.CoreUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.vo.SearchData;
|
|
|
+import com.diagbot.vo.StandConvertCrfVO;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhoutg
|
|
|
+ * @time: 2020/7/29 15:03
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class TestwordInfoFacade extends TestwordInfoServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CRFServiceClient crfServiceClient;
|
|
|
+ @Autowired
|
|
|
+ TestwordResFacade testwordResFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("testwordResServiceImpl")
|
|
|
+ TestwordResService testwordResService;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("testwordInfoServiceImpl")
|
|
|
+ TestwordInfoService testwordInfoService;
|
|
|
+ @Autowired
|
|
|
+ TestFacade testFacade;
|
|
|
+
|
|
|
+ public Map getWord() {
|
|
|
+ Map<String, String> res = new LinkedHashMap<>();
|
|
|
+ Long start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ AIAnalyze aiAnalyze = new AIAnalyze(crfServiceClient);
|
|
|
+ List<String> symptomStand = new ArrayList<>();
|
|
|
+
|
|
|
+ //模型处理数据
|
|
|
+ WordCrfDTO wordCrfDTO = new WordCrfDTO();
|
|
|
+ List<TestwordInfo> testwordInfoList = this.page(new Page<>(1, 100), new QueryWrapper<TestwordInfo>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("is_deal", 0)
|
|
|
+ .orderByAsc("id")).getRecords();
|
|
|
+
|
|
|
+ while (ListUtil.isNotEmpty(testwordInfoList)) {
|
|
|
+ Set<String> symptomList = new LinkedHashSet<>();
|
|
|
+ Set<String> diseaseList = new LinkedHashSet<>();
|
|
|
+ Set<String> drugList = new LinkedHashSet<>();
|
|
|
+ Set<String> operateList = new LinkedHashSet<>();
|
|
|
+ Set<String> lisList = new LinkedHashSet<>();
|
|
|
+ Set<String> pacsList = new LinkedHashSet<>();
|
|
|
+ for (TestwordInfo bean : testwordInfoList) {
|
|
|
+ String text = bean.getText();
|
|
|
+ String type = bean.getType();
|
|
|
+ if ("主诉".equals(type) || "现病史".equals(type)) {
|
|
|
+ SearchData searchData = new SearchData();
|
|
|
+ searchData.setChief(text);
|
|
|
+ aiAnalyze.aiProcess(searchData, wordCrfDTO);
|
|
|
+ CoreUtil.addSet(symptomList, CoreUtil.getName(wordCrfDTO.getChiefLabel().getClinicals()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (symptomList != null && symptomList.size() > 0) {
|
|
|
+ List<TestwordRes> testwordResList = testwordResFacade.list(new QueryWrapper<TestwordRes>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("word", symptomList)
|
|
|
+ .eq("type", "症状")
|
|
|
+ );
|
|
|
+ // 剔除已存在
|
|
|
+ removeWord(symptomList, testwordResList);
|
|
|
+ // 剔除标准
|
|
|
+ symptomList.removeAll(symptomStand);
|
|
|
+ List<TestwordRes> insertSypmotom = stringConvertRes(symptomList, "症状");
|
|
|
+ // 保存
|
|
|
+ if (ListUtil.isNotEmpty(insertSypmotom)) {
|
|
|
+ testwordResService.saveBatch(insertSypmotom);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (TestwordInfo testwordInfo : testwordInfoList) {
|
|
|
+ testwordInfo.setIsDeal(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ testwordInfoService.saveOrUpdateBatch(testwordInfoList);
|
|
|
+
|
|
|
+ testwordInfoList = this.page(new Page<>(1, 100), new QueryWrapper<TestwordInfo>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("is_deal", 0)
|
|
|
+ .orderByAsc("id")).getRecords();
|
|
|
+ }
|
|
|
+
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ res.put("执行时间", (end - start) / 1000.0 + "秒");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<TestwordRes> stringConvertRes(Set<String> stringList, String type) {
|
|
|
+ List<TestwordRes> res = new ArrayList<>();
|
|
|
+ for (String s : stringList) {
|
|
|
+ TestwordRes testwordRes = new TestwordRes();
|
|
|
+ testwordRes.setWord(s);
|
|
|
+ testwordRes.setType(type);
|
|
|
+ res.add(testwordRes);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void removeWord(Set<String> stringList, List<TestwordRes> testwordResList) {
|
|
|
+ if (ListUtil.isEmpty(testwordResList)) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ Set<String> setList = testwordResList.stream().map(r -> r.getWord()).collect(Collectors.toSet());
|
|
|
+ stringList.removeAll(setList);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void wordConvert() {
|
|
|
+ List<TestwordRes> testwordInfoList = testwordResService.page(new Page<>(1, 20), new QueryWrapper<TestwordRes>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("is_deal", 0)
|
|
|
+ .orderByAsc("id")).getRecords();
|
|
|
+
|
|
|
+ while(ListUtil.isNotEmpty(testwordInfoList)) {
|
|
|
+ List<StandConvertCrfVO> convertCrfVOList = new ArrayList<>();
|
|
|
+ for (TestwordRes testwordRes : testwordInfoList) {
|
|
|
+ StandConvertCrfVO standConvertCrfVO = new StandConvertCrfVO();
|
|
|
+ standConvertCrfVO.setWord(testwordRes.getWord());
|
|
|
+ switch (testwordRes.getType()) {
|
|
|
+ case "症状":
|
|
|
+ standConvertCrfVO.setWord_type("symptom");
|
|
|
+ standConvertCrfVO.setNumber(3);
|
|
|
+ convertCrfVOList.add(standConvertCrfVO);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ StandConvertCrfBatchDTO standConvertCrfBatchDTO = testFacade.testStandConvertBatch(convertCrfVOList);
|
|
|
+ for (TestwordRes testwordRes : testwordInfoList) {
|
|
|
+ Set<String> symptomType = new LinkedHashSet<>();
|
|
|
+ switch (testwordRes.getType()) {
|
|
|
+ case "症状":
|
|
|
+ Map<String, StandConvertCrfDTO> convertCrfDTOMap = standConvertCrfBatchDTO.getData().get("symptom");
|
|
|
+ if (convertCrfDTOMap != null && convertCrfDTOMap.get(testwordRes.getWord()) != null) {
|
|
|
+ List<Map<String,String>> listMap = convertCrfDTOMap.get(testwordRes.getWord()).getStandard_words();
|
|
|
+ int size = 0;
|
|
|
+ for (Map<String,String> map : listMap) {
|
|
|
+ if (size < 3 && StringUtil.isNotBlank(map.get("standard_word"))) {
|
|
|
+ symptomType.add(map.get("standard_word"));
|
|
|
+ }
|
|
|
+ size++;
|
|
|
+ }
|
|
|
+ testwordRes.setConvertWord(StringUtils.join(symptomType, ";"));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ testwordRes.setIsDeal(1);
|
|
|
+ }
|
|
|
+ testwordResService.saveOrUpdateBatch(testwordInfoList);
|
|
|
+
|
|
|
+ testwordInfoList = testwordResService.page(new Page<>(1, 20), new QueryWrapper<TestwordRes>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("is_deal", 0)
|
|
|
+ .orderByAsc("id")).getRecords();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|