Browse Source

Merge remote-tracking branch 'origin/dev/KLBstand' into dev/KLBstand

gaodm 6 years ago
parent
commit
f5e438e196

+ 22 - 17
aipt-service/src/main/java/com/diagbot/facade/ConceptDetailFacade.java

@@ -66,7 +66,10 @@ public class ConceptDetailFacade extends ConceptDetailServiceImpl {
                 conceptIntroduceVO.setPosition(PositionTypeEnum.T2.getKey());
             }
         }
-        conceptDetailQueryWrapper.apply("find_in_set({0},position)", conceptIntroduceVO.getPosition());
+        //position=0,返回所有位置的内容
+        if (!conceptIntroduceVO.getPosition().equals(0)) {
+            conceptDetailQueryWrapper.apply("find_in_set({0},position)", conceptIntroduceVO.getPosition());
+        }
         if (ListUtil.isNotEmpty(conceptIntroduceVO.getTitles())) {
             conceptDetailQueryWrapper.in("title", conceptIntroduceVO.getTitles());
         }
@@ -108,27 +111,29 @@ public class ConceptDetailFacade extends ConceptDetailServiceImpl {
     /**
      * 是否存在提示信息-列表
      *
-     * @param nameList
-     * @param libType
+     * @param conceptList
      * @return
      */
-    public Map<String, Concept> existList(List<String> nameList, Integer libType) {
-        List<Concept> concepts = conceptFacade.getListByNamesAndType(nameList, libType);
-        Map<String, Concept> retMap = new LinkedHashMap<>();
-        if (ListUtil.isNotEmpty(concepts)) {
-            List<Long> conceptIds
-                    = concepts.stream().map(concept -> concept.getId()).collect(Collectors.toList());
+    public Map<String, Map<Long, List<ConceptDetail>>> hasConDetail(List<Concept> conceptList) {
+        Map<String, Map<Long, List<ConceptDetail>>> retMap = new LinkedHashMap<>();
+        Map<Long, List<ConceptDetail>> retSubMap = new LinkedHashMap<>();
+        if (ListUtil.isNotEmpty(conceptList)) {
+            List<Long> conceptIds = conceptList.stream().map(concept -> concept.getId()).collect(Collectors.toList());
             QueryWrapper<ConceptDetail> conceptDetailQueryWrapper = new QueryWrapper<>();
-            conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
-                    .in("concept_id", conceptIds);
+            conceptDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).in("concept_id", conceptIds);
             List<ConceptDetail> conceptDetailList = this.list(conceptDetailQueryWrapper);
             if (ListUtil.isNotEmpty(conceptDetailList)) {
-                Map<Long, List<ConceptDetail>> conceptDetailMap
-                        = EntityUtil.makeEntityListMap(conceptDetailList, "conceptId");
-                for (Concept concept : concepts) {
-                    if (conceptDetailMap.containsKey(concept.getId())
-                            && ListUtil.isNotEmpty(conceptDetailMap.get(concept.getId()))) {
-                        retMap.put(concept.getLibName(), concept);
+                Map<Long, List<ConceptDetail>> conceptDetailMap = EntityUtil.makeEntityListMap(conceptDetailList, "conceptId");
+                for (Concept concept : conceptList) {
+                    if (retMap.containsKey(concept.getLibName())) {
+                        retSubMap = retMap.get(concept.getLibName());
+                    }
+                    if (retSubMap == null) {
+                        retSubMap = new LinkedHashMap<>();
+                    }
+                    if (conceptDetailMap.containsKey(concept.getId()) && ListUtil.isNotEmpty(conceptDetailMap.get(concept.getId()))) {
+                        retSubMap.put(concept.getLibType(), conceptDetailMap.get(concept.getId()));
+                        retMap.put(concept.getLibName(), retSubMap);
                     }
                 }
             }

+ 13 - 0
aipt-service/src/main/java/com/diagbot/facade/ConceptFacade.java

@@ -168,6 +168,19 @@ public class ConceptFacade extends ConceptServiceImpl {
         return list;
     }
 
+    /**
+     * 根据名称获取概念list
+     *
+     * @param nameList
+     * @return
+     */
+    public List<Concept> getListByNames(List<String> nameList) {
+        QueryWrapper<Concept> conceptQueryWrapper = new QueryWrapper<>();
+        conceptQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
+                .in("lib_name", nameList);
+        List<Concept> list = this.list(conceptQueryWrapper);
+        return list;
+    }
 
     /**
      * 根据名称和类型获取概念列表Map

+ 94 - 60
aipt-service/src/main/java/com/diagbot/facade/TreatmentFacade.java

@@ -4,9 +4,10 @@ import com.alibaba.fastjson.JSONObject;
 import com.diagbot.client.bean.AdverseReaction;
 import com.diagbot.client.bean.Medicition;
 import com.diagbot.client.bean.MedicitionClass;
-import com.diagbot.dto.ConceptIntroduceDTO;
+import com.diagbot.dto.ConceptDetailDTO;
 import com.diagbot.dto.ConceptRes;
 import com.diagbot.entity.Concept;
+import com.diagbot.entity.ConceptDetail;
 import com.diagbot.entity.wrapper.ConceptWrapper;
 import com.diagbot.enums.ConceptTypeEnum;
 import com.diagbot.enums.DisTypeEnum;
@@ -15,15 +16,15 @@ import com.diagbot.enums.LexiconTypeEnum;
 import com.diagbot.enums.PositionTypeEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
-import com.diagbot.util.EntityUtil;
+import com.diagbot.util.BeanUtil;
 import com.diagbot.util.FastJsonUtils;
 import com.diagbot.util.ListUtil;
 import com.diagbot.vo.ConceptBaseVO;
-import com.diagbot.vo.ConceptIntroduceVO;
 import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -50,6 +51,8 @@ public class TreatmentFacade {
      */
     public Map<String, Object> getTreatment(Map<String, JSONObject> treatmentMap, String diseaseName, Integer disType) {
         Map<String, Object> retMap = new LinkedHashMap<>();
+        List<String> conceptNameList = Lists.newLinkedList();
+        conceptNameList.add(diseaseName);
         ConceptBaseVO conceptBaseVO = new ConceptBaseVO();
         conceptBaseVO.setName(diseaseName);
         conceptBaseVO.setLibType(LexiconTypeEnum.DIAGNOSIS.getKey());
@@ -63,50 +66,26 @@ public class TreatmentFacade {
         if (!treatmentMap.containsKey(diseaseName)) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "诊断名不在诊断列表中");
         }
-
-        //一般治疗
-        ConceptIntroduceVO conceptIntroduceVO = new ConceptIntroduceVO();
-        conceptIntroduceVO.setName(diseaseName);
-        conceptIntroduceVO.setLibType(LexiconTypeEnum.DIAGNOSIS.getKey());
-        conceptIntroduceVO.setPosition(PositionTypeEnum.T3.getKey());
-        conceptIntroduceVO.setType(ConceptTypeEnum.Disease.getKey());
-        ConceptIntroduceDTO commonTreatmentDetail = conceptDetailFacade.getConceptDetail(conceptIntroduceVO);
-        if (commonTreatmentDetail != null && ListUtil.isNotEmpty(commonTreatmentDetail.getDetails())) {
-            retMap.put("commonTreatment", commonTreatmentDetail.getDetails().get(0));
-        } else {
-            retMap.put("commonTreatment", null);
-        }
-
-        //手术治疗
-        conceptIntroduceVO.setPosition(PositionTypeEnum.T4.getKey());
-        ConceptIntroduceDTO surgeryTreatmentDetail = conceptDetailFacade.getConceptDetail(conceptIntroduceVO);
-        if (surgeryTreatmentDetail != null && ListUtil.isNotEmpty(surgeryTreatmentDetail.getDetails())) {
-            retMap.put("surgeryTreatment", surgeryTreatmentDetail.getDetails().get(0));
-        } else {
-            retMap.put("surgeryTreatment", null);
-        }
+        //治疗方案对应诊断
+        retMap.put("diseaseName", diseaseName);
 
         //获取知识图谱治疗方案
         JSONObject treatmentJson = treatmentMap.get(diseaseName);
         if (treatmentJson == null || treatmentJson.isEmpty()) {
             return retMap;
         }
-
         //推荐药物
         List<MedicitionClass> drugsList = FastJsonUtils.getJsonToListByKey(treatmentJson.toString(), "treatment", MedicitionClass.class);
+        //不良反应
+        List<AdverseReaction> adverseReactionList = FastJsonUtils.getJsonToListByKey(treatmentJson.toString(), "adverseEvent", AdverseReaction.class);
         if (ListUtil.isNotEmpty(drugsList)) {
             //药品大类
             List<String> cateBigNameList = drugsList.stream().map(drugs -> drugs.getBigdrugsName()).collect(Collectors.toList());
-            List<Concept> cateBigConceptList = conceptFacade.getListByNamesAndType(cateBigNameList, LexiconTypeEnum.DRUG_CATEGORY_BIG.getKey());
-            Map<String, Concept> cateBigConceptMap = EntityUtil.makeEntityMap(cateBigConceptList, "libName");
-            Map<String, Concept> cateBigInfoExistMap = conceptDetailFacade.existList(cateBigNameList, LexiconTypeEnum.DRUG_CATEGORY_BIG.getKey());
+            conceptNameList.addAll(cateBigNameList);
             //药品小类
             List<String> cateSmallNameList = drugsList.stream().map(drugs -> drugs.getSubdrugsName()).collect(Collectors.toList());
-            List<Concept> cateSmallConceptList = conceptFacade.getListByNamesAndType(cateSmallNameList, LexiconTypeEnum.DRUG_CATEGORY_SMALL.getKey());
-            Map<String, Concept> cateSmallConceptMap = EntityUtil.makeEntityMap(cateSmallConceptList, "libName");
-            //Map<String, Concept> cateSmallInfoExistMap = conceptDetailFacade.existList(cateSmallNameList, LexiconTypeEnum.DRUG_CATEGORY_SMALL.getKey());
-
-            //药品说明信息
+            conceptNameList.addAll(cateSmallNameList);
+            //药品
             List<Medicition> medicitionTotalList = Lists.newLinkedList();
             for (MedicitionClass medicitionClass : drugsList) {
                 if (medicitionClass.getMedicitionsList() != null) {
@@ -114,38 +93,74 @@ public class TreatmentFacade {
                 }
             }
             List<String> drugNameList = medicitionTotalList.stream().map(m -> m.getMedicitionName()).collect(Collectors.toList());
-            List<Concept> drugList = conceptFacade.getListByNamesAndType(drugNameList, LexiconTypeEnum.DRUGS.getKey());
-            Map<String, Concept> drugMap = EntityUtil.makeEntityMap(drugList, "libName");
-            Map<String, Concept> drugDetailMap = conceptDetailFacade.existList(drugNameList, LexiconTypeEnum.DRUGS.getKey());
+            conceptNameList.addAll(drugNameList);
+        }
+        if (ListUtil.isNotEmpty(adverseReactionList)) {
+            List<String> adNameList = adverseReactionList.stream().map(a -> a.getName()).collect(Collectors.toList());
+            conceptNameList.addAll(adNameList);
+        }
+        //概念
+        List<Concept> conceptList=conceptFacade.getListByNames(conceptNameList);
+        //概念map
+        Map<String, Map<Long, Concept>> conceptMap = conceptList2Map(conceptList);
+        //说明信息是否存在
+        Map<String, Map<Long, List<ConceptDetail>>> hasConDetailMap = conceptDetailFacade.hasConDetail(conceptList);
 
+        //一般治疗&&手术治疗
+        if (hasConDetailMap != null && hasConDetailMap.get(diseaseName) != null && ListUtil.isNotEmpty(hasConDetailMap.get(diseaseName).get(LexiconTypeEnum.DIAGNOSIS.getKey()))) {
+            List<ConceptDetail> diseaseConDetailList = hasConDetailMap.get(diseaseName).get(LexiconTypeEnum.DIAGNOSIS.getKey());
+            for (ConceptDetail conceptDetail : diseaseConDetailList) {
+                ConceptDetailDTO conceptDetailDTO = new ConceptDetailDTO();
+                List<String> positionList = Arrays.asList(conceptDetail.getPosition().split(",|,"));
+                if (positionList.contains(String.valueOf(PositionTypeEnum.T3.getKey())) && retMap.get("commonTreatment") == null) {
+                    BeanUtil.copyProperties(conceptDetail, conceptDetailDTO);
+                    retMap.put("commonTreatment", conceptDetailDTO);
+                }
+                if (positionList.contains(String.valueOf(PositionTypeEnum.T4.getKey())) && retMap.get("surgeryTreatment") == null) {
+                    BeanUtil.copyProperties(conceptDetail, conceptDetailDTO);
+                    retMap.put("surgeryTreatment", conceptDetailDTO);
+                }
+            }
+        } else {
+            retMap.put("commonTreatment", null);
+            retMap.put("surgeryTreatment", null);
+        }
+
+        if (ListUtil.isNotEmpty(drugsList)) {
             for (MedicitionClass medicitionClass : drugsList) {
-                Concept cateBigConcept = cateBigConceptMap.get(medicitionClass.getBigdrugsName());
-                if (cateBigConcept != null) {
-                    medicitionClass.setBigdrugsConceptId(cateBigConcept.getId());
-                    if (cateBigInfoExistMap.containsKey(cateBigConcept.getLibName())) {
-                        medicitionClass.setShowInfo("1");
-                    } else {
-                        medicitionClass.setShowInfo("0");
+                if (conceptMap != null && conceptMap.containsKey(medicitionClass.getBigdrugsName()) && conceptMap.get(medicitionClass.getBigdrugsName()) != null && conceptMap.get(medicitionClass.getBigdrugsName()).containsKey(LexiconTypeEnum.DRUG_CATEGORY_BIG.getKey())) {
+                    Concept cateBigConcept = conceptMap.get(medicitionClass.getBigdrugsName()).get(LexiconTypeEnum.DRUG_CATEGORY_BIG.getKey());
+                    if (cateBigConcept != null) {
+                        medicitionClass.setBigdrugsConceptId(cateBigConcept.getId());
+                        if (hasConDetailMap != null && hasConDetailMap.containsKey(cateBigConcept.getLibName()) && hasConDetailMap.get(cateBigConcept.getLibName()) != null && hasConDetailMap.get(cateBigConcept.getLibName()).containsKey(LexiconTypeEnum.DRUG_CATEGORY_BIG.getKey())) {
+                            medicitionClass.setShowInfo("1");
+                        } else {
+                            medicitionClass.setShowInfo("0");
+                        }
                     }
                 }
                 medicitionClass.setBigdrgusLibType(LexiconTypeEnum.DRUG_CATEGORY_BIG.getKey());
                 medicitionClass.setBigdrugsType(ConceptTypeEnum.Drug_Category_Big.getKey());
-                Concept cateSmallConcept = cateSmallConceptMap.get(medicitionClass.getSubdrugsName());
-                if (cateSmallConcept != null) {
-                    medicitionClass.setSubdrugsConceptId(cateSmallConcept.getId());
+                if (conceptMap != null && conceptMap.containsKey(medicitionClass.getSubdrugsName()) && conceptMap.get(medicitionClass.getSubdrugsName()) != null && conceptMap.get(medicitionClass.getSubdrugsName()).containsKey(LexiconTypeEnum.DRUG_CATEGORY_SMALL.getKey())) {
+                    Concept cateSmallConcept = conceptMap.get(medicitionClass.getSubdrugsName()).get(LexiconTypeEnum.DRUG_CATEGORY_SMALL.getKey());
+                    if (cateSmallConcept != null) {
+                        medicitionClass.setSubdrugsConceptId(cateSmallConcept.getId());
+                    }
                 }
                 medicitionClass.setSubdrugsLibType(LexiconTypeEnum.DRUG_CATEGORY_SMALL.getKey());
                 medicitionClass.setSubdrugsType(ConceptTypeEnum.Drug_Category_Small.getKey());
 
                 LinkedList<Medicition> medicitionList = medicitionClass.getMedicitionsList();
                 for (Medicition medicition : medicitionList) {
-                    Concept drugConcept = drugMap.get(medicition.getMedicitionName());
-                    if (drugConcept != null) {
-                        medicition.setConceptId(drugConcept.getId());
+                    if (conceptMap != null && conceptMap.containsKey(medicition.getMedicitionName()) && conceptMap.get(medicition.getMedicitionName()) != null && conceptMap.get(medicition.getMedicitionName()).containsKey(LexiconTypeEnum.DRUGS.getKey())) {
+                        Concept drugConcept = conceptMap.get(medicition.getMedicitionName()).get(LexiconTypeEnum.DRUGS.getKey());
+                        if (drugConcept != null) {
+                            medicition.setConceptId(drugConcept.getId());
+                        }
                     }
                     medicition.setLibType(LexiconTypeEnum.DRUGS.getKey());
                     medicition.setType(ConceptTypeEnum.Drug.getKey());
-                    if (drugDetailMap != null && drugDetailMap.containsKey(medicition.getMedicitionName())) {
+                    if (hasConDetailMap != null && hasConDetailMap.containsKey(medicition.getMedicitionName()) && hasConDetailMap.get(medicition.getMedicitionName()) != null && hasConDetailMap.get(medicition.getMedicitionName()).containsKey(LexiconTypeEnum.DRUGS.getKey())) {
                         medicition.setShowInfo("1");
                     } else {
                         medicition.setShowInfo("0");
@@ -178,19 +193,16 @@ public class TreatmentFacade {
                 //上次用药-icss层处理
                 retMap.put("drugHistory", null);
                 //不良反应
-                List<AdverseReaction> adverseReactionList = FastJsonUtils.getJsonToListByKey(treatmentJson.toString(), "adverseEvent", AdverseReaction.class);
-                List<String> adNameList = adverseReactionList.stream().map(a -> a.getName()).collect(Collectors.toList());
-                List<Concept> adConceptList = conceptFacade.getListByNamesAndType(adNameList, LexiconTypeEnum.SIDE_EFFECTS.getKey());
-                Map<String, Concept> adConceptMap = EntityUtil.makeEntityMap(adConceptList, "libName");
-                Map<String, Concept> adConceptDetailMap = conceptDetailFacade.existList(adNameList, LexiconTypeEnum.SIDE_EFFECTS.getKey());
                 for (AdverseReaction adverseReaction : adverseReactionList) {
-                    Concept adConcept = adConceptMap.get(adverseReaction.getName());
-                    if (adConcept != null) {
-                        adverseReaction.setConceptId(adConcept.getId());
+                    if (conceptMap != null && conceptMap.get(adverseReaction.getName()) != null && conceptMap.get(adverseReaction.getName()).containsKey(LexiconTypeEnum.SIDE_EFFECTS.getKey())) {
+                        Concept adConcept = conceptMap.get(adverseReaction.getName()).get(LexiconTypeEnum.SIDE_EFFECTS.getKey());
+                        if (adConcept != null) {
+                            adverseReaction.setConceptId(adConcept.getId());
+                        }
                     }
                     adverseReaction.setLibType(LexiconTypeEnum.SIDE_EFFECTS.getKey());
                     adverseReaction.setType(ConceptTypeEnum.SIDE_EFFECTS.getKey());
-                    if (adConceptDetailMap != null && adConceptDetailMap.containsKey(adverseReaction.getName())) {
+                    if (hasConDetailMap != null && hasConDetailMap.get(adverseReaction.getName()) != null && hasConDetailMap.get(adverseReaction.getName()).containsKey(LexiconTypeEnum.SIDE_EFFECTS.getKey())) {
                         adverseReaction.setShowInfo("1");
                     } else {
                         adverseReaction.setShowInfo("0");
@@ -201,4 +213,26 @@ public class TreatmentFacade {
         }
         return retMap;
     }
+
+    /**
+     * 转换概念list到map  Map<概念名称,Map<词性,概念对象>>
+     *
+     * @param conceptList
+     * @return
+     */
+    public Map<String, Map<Long, Concept>> conceptList2Map(List<Concept> conceptList) {
+        Map<String, Map<Long, Concept>> retMap = new LinkedHashMap<>();
+        Map<Long, Concept> retSubMap = new LinkedHashMap<>();
+        for (Concept concept : conceptList) {
+            if (retMap.containsKey(concept.getLibName())) {
+                retSubMap = retMap.get(concept.getLibName());
+            }
+            if (retSubMap == null) {
+                retSubMap = new LinkedHashMap<>();
+            }
+            retSubMap.put(concept.getLibType(), concept);
+            retMap.put(concept.getLibName(), retSubMap);
+        }
+        return retMap;
+    }
 }

+ 2 - 2
knowledgeman-service/src/main/java/com/diagbot/facade/ConceptFacade.java

@@ -203,8 +203,8 @@ public class ConceptFacade extends ConceptServiceImpl {
             QueryWrapper<Relation> relationQe = new QueryWrapper<>();
             relationQe.eq("relation_id", getAllForRelationVO.getRelationId());
             if (getAllForRelationVO.getRelationPosition() == 1) {
-                relationQe.in("start_id", conceptIdList);
-                relationQe.eq(getAllForRelationVO.getRelationConceptId() != null, "end_id", getAllForRelationVO.getRelationConceptId());
+            	relationQe.eq(getAllForRelationVO.getRelationConceptId() != null, "end_id", getAllForRelationVO.getRelationConceptId());
+            	relationQe.and(wrapper->wrapper.in("start_id", conceptIdList).or(getAllForRelationVO.getRelationConceptId() == null).in("end_id", conceptIdList));
                 reCouMap = relationFacade.list(relationQe).stream().collect(Collectors.groupingBy(Relation::getStartId, Collectors.counting()));
             } else if(getAllForRelationVO.getRelationConceptId() != null) {
                 relationQe.in("end_id", conceptIdList);

+ 12 - 13
knowledgeman-service/src/main/resources/mapper/RelationMapper.xml

@@ -150,15 +150,13 @@
     </select> -->
     
     <select id="multContactList" resultType="com.diagbot.dto.MultContactListDTO">
-    	SELECT
-		t1.start_id AS conceptId,
-		t1.modifier AS operName,
-		t1.gmt_modified AS operTime,
-		t1.is_deleted AS isDeleted,
-		GROUP_CONCAT(t1.end_id ORDER BY t2.order_no ASC) AS otherIds
-		FROM
-		(SELECT 
-		DISTINCT a.*
+    	SELECT 
+		a.start_id AS conceptId,
+		a.modifier AS operName,
+		a.gmt_modified AS operTime,
+		a.is_deleted AS isDeleted,
+		GROUP_CONCAT(a.end_id ORDER BY d.order_no ASC) AS otherIds,
+		SUM(CASE WHEN b.start_id IS NULL THEN 0 ELSE 1 END) AS notnullcou
 		FROM
 		(SELECT * FROM kl_relation WHERE relation_id=17
 		<choose>
@@ -174,11 +172,12 @@
 			</otherwise>
 		</choose>
 		) a
-		JOIN (SELECT start_id FROM kl_relation WHERE relation_id=17) b ON a.end_id=b.start_id
+		LEFT JOIN (SELECT start_id FROM kl_relation WHERE relation_id=17) b ON a.end_id=b.start_id
 		LEFT JOIN (SELECT end_id FROM kl_relation WHERE relation_id=17) c ON a.start_id=c.end_id
-		WHERE c.end_id IS NULL) t1
-		LEFT JOIN kl_relation_order t2 ON t1.id=t2.t_relation_id
-		GROUP BY start_id
+		LEFT JOIN kl_relation_order d ON a.id=d.t_relation_id
+		WHERE c.end_id IS NULL 
+		GROUP BY a.start_id
+		HAVING notnullcou>0
 		ORDER BY operTime DESC
     </select>