|
@@ -1,12 +1,14 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.diagbot.client.TreatServiceClient;
|
|
|
+import com.diagbot.client.bean.GdbResponse;
|
|
|
import com.diagbot.client.bean.Medicition;
|
|
|
import com.diagbot.client.bean.MedicitionClass;
|
|
|
import com.diagbot.client.bean.Response;
|
|
|
-import com.diagbot.client.bean.ResponseTreatData;
|
|
|
-import com.diagbot.client.bean.SearchData;
|
|
|
+import com.diagbot.client.bean.TreatInput;
|
|
|
import com.diagbot.dto.TreatmentDTO;
|
|
|
import com.diagbot.entity.IntroduceDetail;
|
|
|
import com.diagbot.entity.IntroduceMap;
|
|
@@ -14,14 +16,16 @@ import com.diagbot.entity.QuestionInfo;
|
|
|
import com.diagbot.enums.IntroducePositionEnum;
|
|
|
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.StringUtil;
|
|
|
import com.diagbot.vo.TreatmentVO;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import feign.QueryMap;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -42,95 +46,141 @@ public class TreatmentFacade {
|
|
|
@Autowired
|
|
|
IntroduceMapFacade introduceMapFacade;
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取治疗方案
|
|
|
+ *
|
|
|
+ * @param treatmentVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public TreatmentDTO getTreatment(TreatmentVO treatmentVO) {
|
|
|
TreatmentDTO treatmentDTO = new TreatmentDTO();
|
|
|
Map<String, Object> retMap = new LinkedHashMap<>();
|
|
|
|
|
|
- SearchData searchData = new SearchData();
|
|
|
- searchData.setSymptom(treatmentVO.getSymptom());
|
|
|
- searchData.setVital(treatmentVO.getVital());
|
|
|
- searchData.setLis(treatmentVO.getLis());
|
|
|
- searchData.setPacs(treatmentVO.getPacs());
|
|
|
- searchData.setOther(treatmentVO.getOther());
|
|
|
- searchData.setDiag(treatmentVO.getDiag());
|
|
|
+ TreatInput treatInput = new TreatInput();
|
|
|
+ treatInput.setDisease(treatmentVO.getDiag());
|
|
|
+ treatInput.setFilds(treatmentVO.getSymptom());
|
|
|
|
|
|
Long diseaseId = treatmentVO.getDiseaseId();
|
|
|
QuestionInfo disease = questionFacade.getById(diseaseId);
|
|
|
+ if (!disease.getTagName().equals(treatmentVO.getDiag())) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "诊断名称和id不匹配");
|
|
|
+ }
|
|
|
//一般治疗
|
|
|
- QueryWrapper<IntroduceDetail> introduceDetailQueryWrapper = new QueryWrapper<>();
|
|
|
- String sql = "select introduce_id from icss_introduce_map where question_id=" + diseaseId + " and type=" + QuestionTypeEnum.Disease.getKey();
|
|
|
- introduceDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .apply("find_in_set({0},'position')", IntroducePositionEnum.CommonTreatment.getKey())
|
|
|
- .inSql("introduce_id", sql)
|
|
|
- .orderByAsc("introduce_id", "order_no");
|
|
|
- List<IntroduceDetail> commonTreatmentDetailList = introduceDetailFacade.list(introduceDetailQueryWrapper);
|
|
|
- retMap.put("commonTreatment", commonTreatmentDetailList);
|
|
|
+ List<IntroduceDetail> commonTreatmentDetailList = getIntroduceDetailList(diseaseId, IntroducePositionEnum.CommonTreatment.getKey());
|
|
|
+ retMap.put("commonTreatment", commonTreatmentDetailList.size() > 0 ? commonTreatmentDetailList.get(0).getContent() : "");
|
|
|
|
|
|
//手术治疗
|
|
|
- introduceDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .apply("find_in_set({0},'position')", IntroducePositionEnum.SurgeryTreatment.getKey())
|
|
|
- .inSql("introduce_id", sql)
|
|
|
- .orderByAsc("introduce_id", "order_no");
|
|
|
- List<IntroduceDetail> surgeryTreatmentDetailList = introduceDetailFacade.list(introduceDetailQueryWrapper);
|
|
|
- retMap.put("surgeryTreatment", surgeryTreatmentDetailList);
|
|
|
+ List<IntroduceDetail> surgeryTreatmentDetailList = getIntroduceDetailList(diseaseId, IntroducePositionEnum.SurgeryTreatment.getKey());
|
|
|
+ retMap.put("surgeryTreatment", surgeryTreatmentDetailList.size() > 0 ? surgeryTreatmentDetailList.get(0).getContent() : "");
|
|
|
|
|
|
//获取知识图谱治疗方案
|
|
|
- Response<ResponseTreatData> responseTreatData = treatServiceClient.treatPageData(searchData);
|
|
|
- Map<String, Map<String, List<MedicitionClass>>> resultMap = responseTreatData.getData().getResult();
|
|
|
- List<MedicitionClass> medicitionClassList = resultMap.get("des").get("treatment");
|
|
|
+ Response<GdbResponse> responseTreatData = treatServiceClient.treatPageData(treatInput);
|
|
|
+ Map<String, String> resultMap = responseTreatData.getData().getResult();
|
|
|
+ if (resultMap.size() == 0) {
|
|
|
+ treatmentDTO.setMap(retMap);
|
|
|
+ return treatmentDTO;
|
|
|
+ }
|
|
|
+ String resultDes = resultMap.get("des");
|
|
|
+ if (StringUtil.isBlank(resultDes)) {
|
|
|
+ treatmentDTO.setMap(retMap);
|
|
|
+ return treatmentDTO;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(resultDes);
|
|
|
+ JSONArray treatJsonArray = jsonObject.getJSONArray("treatment");
|
|
|
+ if (treatJsonArray.size() == 0) {
|
|
|
+ treatmentDTO.setMap(retMap);
|
|
|
+ return treatmentDTO;
|
|
|
+ }
|
|
|
+ List<MedicitionClass> drugsList = JSONObject.parseArray(treatJsonArray.toJSONString(), MedicitionClass.class);
|
|
|
|
|
|
- List<String> classNameList = medicitionClassList.stream().map(medicitionClass -> medicitionClass.getClassName()).collect(Collectors.toList());
|
|
|
- QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
|
|
|
- questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).in("tagName", classNameList)
|
|
|
- .eq("sub_type", 0)
|
|
|
- .eq("type", QuestionTypeEnum.DrugClass.getKey());
|
|
|
- List<QuestionInfo> drugClassList = questionFacade.list(questionInfoQueryWrapper);
|
|
|
+ List<String> classNameList = drugsList.stream().map(drugs -> drugs.getDrugsName()).collect(Collectors.toList());
|
|
|
+ List<QuestionInfo> drugClassList = getTopQuestionList(classNameList, QuestionTypeEnum.DrugClass.getKey());
|
|
|
Map<String, QuestionInfo> drugClassMap = EntityUtil.makeEntityMap(drugClassList, "tagName");
|
|
|
List<Long> drugClassIds = drugClassList.stream().map(drugClass -> drugClass.getId()).collect(Collectors.toList());
|
|
|
- QueryWrapper<IntroduceMap> introduceMapQueryWrapper = new QueryWrapper<>();
|
|
|
- introduceDetailQueryWrapper.in("question_id", drugClassIds)
|
|
|
- .eq("type", QuestionTypeEnum.DrugClass.getKey())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- List<IntroduceMap> introduceMapList = introduceMapFacade.list(introduceMapQueryWrapper);
|
|
|
+ List<IntroduceMap> introduceMapList = getIntroduceMapList(drugClassIds, QuestionTypeEnum.DrugClass.getKey());
|
|
|
Map<Long, IntroduceMap> introduceMapMap = EntityUtil.makeEntityMap(introduceMapList, "questionId");
|
|
|
|
|
|
- for (MedicitionClass medicitionClass : medicitionClassList) {
|
|
|
- QuestionInfo drugClass = drugClassMap.get(medicitionClass.getClassName());
|
|
|
+ for (MedicitionClass medicitionClass : drugsList) {
|
|
|
+ QuestionInfo drugClass = drugClassMap.get(medicitionClass.getDrugsName());
|
|
|
if (drugClass != null) {
|
|
|
medicitionClass.setId(drugClass.getId());
|
|
|
if (introduceMapMap.get(drugClass.getId()) != null) {
|
|
|
- medicitionClass.setShowInfo(true);
|
|
|
+ medicitionClass.setShowInfo("1");
|
|
|
}
|
|
|
}
|
|
|
- List<Medicition> medicitionList = medicitionClass.getMedicitionList();
|
|
|
+ LinkedList<Medicition> medicitionList = medicitionClass.getMedicitionsList();
|
|
|
List<String> drugNameList = medicitionList.stream().map(medicition -> medicition.getMedicitionName()).collect(Collectors.toList());
|
|
|
- QueryWrapper<QuestionInfo> drugListQueryWrapper = new QueryWrapper<>();
|
|
|
- drugListQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).in("tagName", drugNameList)
|
|
|
- .eq("sub_type", 0)
|
|
|
- .eq("type", QuestionTypeEnum.Drug.getKey());
|
|
|
- List<QuestionInfo> drugList = questionFacade.list(drugListQueryWrapper);
|
|
|
+ List<QuestionInfo> drugList = getTopQuestionList(drugNameList, QuestionTypeEnum.Drug.getKey());
|
|
|
Map<String, QuestionInfo> drugMap = EntityUtil.makeEntityMap(drugList, "tagName");
|
|
|
List<Long> drugIds = drugList.stream().map(drug -> drug.getId()).collect(Collectors.toList());
|
|
|
- QueryWrapper<IntroduceMap> introduceDrugQueryWrapper = new QueryWrapper<>();
|
|
|
- introduceDrugQueryWrapper.in("question_id", drugIds)
|
|
|
- .eq("type", QuestionTypeEnum.Drug.getKey())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- List<IntroduceMap> drugIntroduceMapList = introduceMapFacade.list(introduceDrugQueryWrapper);
|
|
|
+ List<IntroduceMap> drugIntroduceMapList = getIntroduceMapList(drugIds, QuestionTypeEnum.Drug.getKey());
|
|
|
Map<Long, IntroduceMap> drugIntroduceMapMap = EntityUtil.makeEntityMap(drugIntroduceMapList, "questionId");
|
|
|
for (Medicition medicition : medicitionList) {
|
|
|
QuestionInfo drug = drugMap.get(medicition.getMedicitionName());
|
|
|
if (drug != null) {
|
|
|
medicition.setId(drug.getId());
|
|
|
if (drugIntroduceMapMap.get(drug.getId()) != null) {
|
|
|
- medicition.setShowInfo(true);
|
|
|
+ medicition.setShowInfo("1");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- medicitionClass.setMedicitionList(medicitionList);
|
|
|
+ medicitionClass.setMedicitionsList(medicitionList);
|
|
|
}
|
|
|
|
|
|
- retMap.put("treatment", medicitionClassList);
|
|
|
+ retMap.put("treatment", drugsList);
|
|
|
treatmentDTO.setMap(retMap);
|
|
|
return treatmentDTO;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据展示位置获取提示信息明细列表
|
|
|
+ *
|
|
|
+ * @param diseaseId
|
|
|
+ * @param position
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<IntroduceDetail> getIntroduceDetailList(Long diseaseId, Integer position) {
|
|
|
+ QueryWrapper<IntroduceDetail> introduceDetailQueryWrapper = new QueryWrapper<>();
|
|
|
+ String sql = "select introduce_id from icss_introduce_map where question_id=" + diseaseId + " and type=" + QuestionTypeEnum.Disease.getKey();
|
|
|
+ introduceDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .apply("find_in_set({0},position)", position)
|
|
|
+ .inSql("introduce_id", sql)
|
|
|
+ .orderByAsc("introduce_id", "order_no");
|
|
|
+ List<IntroduceDetail> introduceDetailList = introduceDetailFacade.list(introduceDetailQueryWrapper);
|
|
|
+ return introduceDetailList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取顶级标签
|
|
|
+ *
|
|
|
+ * @param tagNameList
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<QuestionInfo> getTopQuestionList(List<String> tagNameList, Integer type) {
|
|
|
+ QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("tag_name", tagNameList)
|
|
|
+ .eq("sub_type", 0)
|
|
|
+ .eq("type", type);
|
|
|
+ List<QuestionInfo> questionInfoList = questionFacade.list(questionInfoQueryWrapper);
|
|
|
+ return questionInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取标签提示信息映射
|
|
|
+ *
|
|
|
+ * @param questionIdList
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<IntroduceMap> getIntroduceMapList(List<Long> questionIdList, Integer type) {
|
|
|
+ QueryWrapper<IntroduceMap> introduceMapQueryWrapper = new QueryWrapper<>();
|
|
|
+ introduceMapQueryWrapper.in("question_id", questionIdList)
|
|
|
+ .eq("type", type)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ List<IntroduceMap> introduceMapList = introduceMapFacade.list(introduceMapQueryWrapper);
|
|
|
+ return introduceMapList;
|
|
|
+ }
|
|
|
}
|