浏览代码

治疗方案

Zhaops 6 年之前
父节点
当前提交
34750d3328

+ 7 - 0
icss-service/pom.xml

@@ -137,6 +137,13 @@
             <artifactId>druid-spring-boot-starter</artifactId>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.46</version>
+        </dependency>
+
         <!-- springboot整合mybatis(核心就这一个) -->
         <!-- 注意顺序,这个一定要放在最下面 -->
         <dependency>

+ 3 - 3
icss-service/src/main/java/com/diagbot/client/TreatServiceClient.java

@@ -1,8 +1,8 @@
 package com.diagbot.client;
 
+import com.diagbot.client.bean.GdbResponse;
 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.client.hystrix.TreatServiceHystrix;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -16,5 +16,5 @@ import org.springframework.web.bind.annotation.RequestBody;
 @FeignClient(name = "Treat", url = "${treat.server.address}", fallback = TreatServiceHystrix.class)
 public interface TreatServiceClient {
     @PostMapping(value = "/web/graphdb/treat")
-    Response<ResponseTreatData> treatPageData(@RequestBody SearchData searchData);
+    Response<GdbResponse> treatPageData(@RequestBody TreatInput treatInput);
 }

+ 18 - 0
icss-service/src/main/java/com/diagbot/client/bean/GdbResponse.java

@@ -0,0 +1,18 @@
+package com.diagbot.client.bean;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 图形数据库数据返回结构
+ * Created by Mark Huang on 2018/10/26.
+ */
+@Getter
+@Setter
+public class GdbResponse {
+    private String status = "";
+    private Map<String, String> Result = new HashMap<>();
+}

+ 8 - 2
icss-service/src/main/java/com/diagbot/client/bean/Medicition.java

@@ -13,8 +13,14 @@ import lombok.Setter;
 public class Medicition {
     private Long id;
     private String medicitionName;
+    /**
+     * 1-显示,0-隐藏
+     */
     private String isShow;
     private String forbidden;
-    private Boolean showInfo;
+    /**
+     * 1-有提示信息,0-没有提示信息
+     */
+    private String showInfo = "0";
     private String rate;
-}
+}

+ 7 - 4
icss-service/src/main/java/com/diagbot/client/bean/MedicitionClass.java

@@ -3,7 +3,7 @@ package com.diagbot.client.bean;
 import lombok.Getter;
 import lombok.Setter;
 
-import java.util.List;
+import java.util.LinkedList;
 
 /**
  * @Description:
@@ -14,7 +14,10 @@ import java.util.List;
 @Setter
 public class MedicitionClass {
     private Long id;
-    private String className;
-    private Boolean showInfo;
-    private List<Medicition> medicitionList;
+    /**
+     * 1-有提示信息,0-没有提示信息
+     */
+    private String showInfo = "0";
+    private String drugsName;//药类名
+    private LinkedList<Medicition> medicitionsList;
 }

+ 16 - 0
icss-service/src/main/java/com/diagbot/client/bean/TreatInput.java

@@ -0,0 +1,16 @@
+package com.diagbot.client.bean;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2018/12/18 10:53
+ */
+@Getter
+@Setter
+public class TreatInput {
+    private String disease;
+    private String filds;
+}

+ 3 - 3
icss-service/src/main/java/com/diagbot/client/hystrix/TreatServiceHystrix.java

@@ -1,9 +1,9 @@
 package com.diagbot.client.hystrix;
 
 import com.diagbot.client.TreatServiceClient;
+import com.diagbot.client.bean.GdbResponse;
 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 lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
 @Slf4j
 public class TreatServiceHystrix implements TreatServiceClient {
     @Override
-    public Response<ResponseTreatData> treatPageData(SearchData searchData) {
+    public Response<GdbResponse> treatPageData(TreatInput treatInput) {
         log.error("【hystrix】调用{}异常", "treatPageData");
         return null;
     }

+ 106 - 56
icss-service/src/main/java/com/diagbot/facade/TreatmentFacade.java

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