|
@@ -2,22 +2,20 @@ package com.diagbot.facade;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.diagbot.client.AiptServiceClient;
|
|
|
+import com.diagbot.dto.FeatureConceptDTO;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
-import com.diagbot.dto.SymptomFeatureDTO;
|
|
|
import com.diagbot.entity.QuestionInfo;
|
|
|
-import com.diagbot.enums.DisTypeEnum;
|
|
|
+import com.diagbot.enums.ConceptTypeEnum;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
-import com.diagbot.enums.QuestionTypeEnum;
|
|
|
-import com.diagbot.exception.CommonErrorCode;
|
|
|
-import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
import com.diagbot.util.RespDTOUtil;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description:
|
|
@@ -30,8 +28,6 @@ public class FeatureFacade {
|
|
|
private AiptServiceClient aiptServiceClient;
|
|
|
@Autowired
|
|
|
private QuestionFacade questionFacade;
|
|
|
- @Autowired
|
|
|
- private DisTypeFacade disTypeFacade;
|
|
|
|
|
|
/**
|
|
|
* 症状关键词提取
|
|
@@ -39,48 +35,34 @@ public class FeatureFacade {
|
|
|
* @param text
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<SymptomFeatureDTO> getSymptomFeature(String text) {
|
|
|
- List<SymptomFeatureDTO> symptomFeatureDTOList = Lists.newLinkedList();
|
|
|
- RespDTO<List<Map<String, Object>>> res = aiptServiceClient.symptomFeaturePageData(text);
|
|
|
+ public List<FeatureConceptDTO> getSymptomFeature(String text) {
|
|
|
+ RespDTO<List<FeatureConceptDTO>> res = aiptServiceClient.symptomFeature(text);
|
|
|
RespDTOUtil.respNGDealCover(res, "AI没有返回结果");
|
|
|
- List<Map<String, Object>> symptomFeatureList = res.data;
|
|
|
- List<String> symptomNameList = Lists.newLinkedList();
|
|
|
- for (Map<String, Object> symptomFeature : symptomFeatureList) {
|
|
|
- if (symptomFeature != null) {
|
|
|
- symptomNameList.add(symptomFeature.get("feature_name").toString());
|
|
|
- }
|
|
|
- }
|
|
|
- if (!ListUtil.isNotEmpty(symptomFeatureList)) {
|
|
|
- throw new CommonException(CommonErrorCode.NOT_EXISTS, "未提取到特征词");
|
|
|
- }
|
|
|
+ List<FeatureConceptDTO> symptomFeatureList = res.data;
|
|
|
+ symptomFeatureList = addQuestionId(symptomFeatureList, ConceptTypeEnum.Symptom.getKey());
|
|
|
+ return symptomFeatureList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 概念关联标签,添加标签id
|
|
|
+ *
|
|
|
+ * @param concepts
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<FeatureConceptDTO> addQuestionId(List<FeatureConceptDTO> concepts, Integer type) {
|
|
|
QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
|
|
|
- questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).
|
|
|
- in("tag_name", symptomNameList).
|
|
|
- and(i -> i.eq("type", QuestionTypeEnum.Symptom.getKey()).or().eq("type", QuestionTypeEnum.Disease.getKey())).
|
|
|
- eq("item_type", 0);
|
|
|
+ List<String> nameList = concepts.stream().map(concept -> concept.getName()).collect(Collectors.toList());
|
|
|
+ questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).in("tag_name", nameList).eq("type", type);
|
|
|
List<QuestionInfo> questionInfoList = questionFacade.list(questionInfoQueryWrapper);
|
|
|
- for (QuestionInfo questionInfo : questionInfoList) {
|
|
|
- SymptomFeatureDTO symptomFeatureDTO = new SymptomFeatureDTO();
|
|
|
- //特征提取出诊断
|
|
|
- if (questionInfo.getType().equals(QuestionTypeEnum.Disease.getKey())) {
|
|
|
- //判断是否有“复诊”关键字
|
|
|
- if (symptomNameList.contains("复诊")) {
|
|
|
- //判断是否为慢病
|
|
|
- Boolean isChronic = disTypeFacade.judgeByDisName(questionInfo.getTagName(), DisTypeEnum.CHRONIC.getKey());
|
|
|
- if (isChronic) {
|
|
|
- symptomFeatureDTO.setDisType(DisTypeEnum.CHRONIC.getKey());
|
|
|
- }
|
|
|
- } else {
|
|
|
- //没有提取到“复诊”这个特征,诊断不处理
|
|
|
- continue;
|
|
|
+ if (ListUtil.isNotEmpty(questionInfoList)) {
|
|
|
+ Map<String, QuestionInfo> questionInfoMap = EntityUtil.makeEntityMap(questionInfoList, "tagName");
|
|
|
+ for (FeatureConceptDTO concept : concepts) {
|
|
|
+ if (questionInfoMap.containsKey(concept.getName())) {
|
|
|
+ concept.setId(questionInfoMap.get(concept.getName()).getId());
|
|
|
}
|
|
|
}
|
|
|
- symptomFeatureDTO.setId(questionInfo.getId());
|
|
|
- symptomFeatureDTO.setTagName(questionInfo.getTagName());
|
|
|
- symptomFeatureDTO.setName(questionInfo.getName());
|
|
|
- symptomFeatureDTO.setType(questionInfo.getType());
|
|
|
- symptomFeatureDTOList.add(symptomFeatureDTO);
|
|
|
}
|
|
|
- return symptomFeatureDTOList;
|
|
|
+ return concepts;
|
|
|
}
|
|
|
}
|