|
@@ -2,10 +2,14 @@ package com.diagbot.facade;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.client.AiptServiceClient;
|
|
|
import com.diagbot.client.bean.AdverseReaction;
|
|
|
+import com.diagbot.client.bean.ConceptBaseVO;
|
|
|
+import com.diagbot.client.bean.DisTypeVO;
|
|
|
import com.diagbot.client.bean.Medicition;
|
|
|
import com.diagbot.client.bean.MedicitionClass;
|
|
|
import com.diagbot.dto.IntroduceDetailDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
import com.diagbot.entity.InquiryDrug;
|
|
|
import com.diagbot.entity.InquiryInfo;
|
|
|
import com.diagbot.entity.IntroduceDetail;
|
|
@@ -21,7 +25,9 @@ import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.EntityUtil;
|
|
|
import com.diagbot.util.FastJsonUtils;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -50,6 +56,8 @@ public class TreatmentFacade {
|
|
|
InquiryInfoFacade inquiryInfoFacade;
|
|
|
@Autowired
|
|
|
InquiryDrugFacade inquiryDrugFacade;
|
|
|
+ @Autowired
|
|
|
+ AiptServiceClient aiptServiceClient;
|
|
|
|
|
|
/**
|
|
|
* 获取治疗方案
|
|
@@ -57,169 +65,20 @@ public class TreatmentFacade {
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Object> getTreatment(Map<String, JSONObject> treatmentMap, Long diseaseId, Long patientId) {
|
|
|
- Map<String, Object> retMap = new LinkedHashMap<>();
|
|
|
- QuestionInfo disease = questionFacade.getById(diseaseId);
|
|
|
- if (disease == null) {
|
|
|
- throw new CommonException(CommonErrorCode.NOT_EXISTS, "诊断不存在");
|
|
|
- }
|
|
|
- if (treatmentMap.size() == 0) {
|
|
|
- throw new CommonException(CommonErrorCode.NOT_EXISTS, "未找到治疗方案");
|
|
|
- }
|
|
|
- if (!treatmentMap.containsKey(disease.getTagName())) {
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "诊断名称和id不匹配");
|
|
|
- }
|
|
|
-
|
|
|
- //一般治疗
|
|
|
- List<IntroduceDetail> commonTreatmentDetailList = getIntroduceDetailList(diseaseId, IntroducePositionEnum.CommonTreatment.getKey());
|
|
|
- IntroduceDetailDTO commonDetailDTO = new IntroduceDetailDTO();
|
|
|
- if (ListUtil.isNotEmpty(commonTreatmentDetailList)) {
|
|
|
- BeanUtil.copyProperties(commonTreatmentDetailList.get(0), commonDetailDTO);
|
|
|
- }
|
|
|
- retMap.put("commonTreatment", commonDetailDTO);
|
|
|
-
|
|
|
- //手术治疗
|
|
|
- List<IntroduceDetail> surgeryTreatmentDetailList = getIntroduceDetailList(diseaseId, IntroducePositionEnum.SurgeryTreatment.getKey());
|
|
|
- IntroduceDetailDTO surgeryDetailDTO = new IntroduceDetailDTO();
|
|
|
- if (ListUtil.isNotEmpty(surgeryTreatmentDetailList)) {
|
|
|
- BeanUtil.copyProperties(surgeryTreatmentDetailList.get(0), surgeryDetailDTO);
|
|
|
- }
|
|
|
- retMap.put("surgeryTreatment", surgeryDetailDTO);
|
|
|
-
|
|
|
-
|
|
|
- //获取知识图谱治疗方案
|
|
|
- JSONObject treatmentJson = treatmentMap.get(disease.getTagName());
|
|
|
- if (treatmentJson == null || treatmentJson.isEmpty()) {
|
|
|
- return retMap;
|
|
|
- }
|
|
|
-
|
|
|
- List<MedicitionClass> drugsList = FastJsonUtils.getJsonToListByKey(treatmentJson.toString(), "treatment", MedicitionClass.class);
|
|
|
-
|
|
|
- List<String> classNameList = drugsList.stream().map(drugs -> drugs.getBigdrugsName()).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());
|
|
|
- List<IntroduceMap> introduceMapList = getIntroduceMapList(drugClassIds, QuestionTypeEnum.DrugClass.getKey());
|
|
|
- Map<Long, IntroduceMap> introduceMapMap = EntityUtil.makeEntityMap(introduceMapList, "questionId");
|
|
|
-
|
|
|
- for (MedicitionClass medicitionClass : drugsList) {
|
|
|
- QuestionInfo drugClass = drugClassMap.get(medicitionClass.getBigdrugsName());
|
|
|
- if (drugClass != null) {
|
|
|
- medicitionClass.setId(drugClass.getId());
|
|
|
- if (introduceMapMap.get(drugClass.getId()) != null) {
|
|
|
- medicitionClass.setShowInfo("1");
|
|
|
- }
|
|
|
- }
|
|
|
- LinkedList<Medicition> medicitionList = medicitionClass.getMedicitionsList();
|
|
|
- List<String> drugNameList = medicitionList.stream().map(medicition -> medicition.getMedicitionName()).collect(Collectors.toList());
|
|
|
- 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());
|
|
|
- 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("1");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- medicitionClass.setMedicitionsList(medicitionList);
|
|
|
- }
|
|
|
-
|
|
|
- retMap.put("treatment", drugsList);
|
|
|
-
|
|
|
- //判断是否慢病,慢病增加回访时间,上次用药,不良反应
|
|
|
- Boolean isChronic = disTypeFacade.judgeByDisId(diseaseId, DisTypeEnum.CHRONIC.getKey());
|
|
|
- if (isChronic) {
|
|
|
- //慢病,增加回访时间,暂时前端写死, 以后由只是图谱返回
|
|
|
- retMap.put("followUp", null);
|
|
|
-
|
|
|
+ public Map<String, Object> getTreatment(Map<String, Object> map, Long patientId) {
|
|
|
+ Map<String, Object> retMap = map;
|
|
|
+ //慢病 上次用药处理
|
|
|
+ if (map.containsKey("drugHistory")) {
|
|
|
//上次用药
|
|
|
if (patientId == null) {
|
|
|
retMap.put("drugHistory", null);
|
|
|
} else {
|
|
|
retMap.put("drugHistory", getDrugHistory(patientId));
|
|
|
}
|
|
|
-
|
|
|
- //不良反应
|
|
|
- List<AdverseReaction> adverseReactionList = FastJsonUtils.getJsonToListByKey(treatmentJson.toString(), "adverseEvent", AdverseReaction.class);
|
|
|
- List<String> adNameList = adverseReactionList.stream().map(adverseReaction -> adverseReaction.getName()).collect(Collectors.toList());
|
|
|
- List<QuestionInfo> adList = getTopQuestionList(adNameList, QuestionTypeEnum.AdverseReaction.getKey());
|
|
|
- Map<String, QuestionInfo> adMap = EntityUtil.makeEntityMap(adList, "tagName");
|
|
|
- List<Long> adIds = adList.stream().map(ad -> ad.getId()).collect(Collectors.toList());
|
|
|
- List<IntroduceMap> adIntroduceMapList = getIntroduceMapList(adIds, QuestionTypeEnum.AdverseReaction.getKey());
|
|
|
- Map<Long, IntroduceMap> adIntroduceMapMap = EntityUtil.makeEntityMap(adIntroduceMapList, "questionId");
|
|
|
- for (AdverseReaction adverseReaction : adverseReactionList) {
|
|
|
- adverseReaction.setTagName(adverseReaction.getName());
|
|
|
- if (null != adMap && adMap.size() > 0) {
|
|
|
- QuestionInfo adInfo = adMap.get(adverseReaction.getName());
|
|
|
- if (adInfo != null) {
|
|
|
- adverseReaction.setId(adInfo.getId());
|
|
|
- }
|
|
|
- IntroduceMap adIntorduceMap = adIntroduceMapMap.get(adInfo.getId());
|
|
|
- if (adIntorduceMap != null) {
|
|
|
- adverseReaction.setShowInfo("1");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- retMap.put("adverseReactions", adverseReactionList);
|
|
|
}
|
|
|
return retMap;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 根据展示位置获取提示信息明细列表
|
|
|
- *
|
|
|
- * @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;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 根据病人id获取历史用药内容
|
|
@@ -237,6 +96,10 @@ public class TreatmentFacade {
|
|
|
Boolean chronicHistroy = false;
|
|
|
Boolean not_chronicHistory = false;
|
|
|
for (InquiryInfo inquiryInfo : inquiryInfoList) {
|
|
|
+ //慢病和普通病都取到上次用药之后不再遍历
|
|
|
+ if (chronicHistroy && not_chronicHistory) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
String[] diseases = inquiryInfo.getDiagnose().split(",|,");
|
|
|
if (diseases.length > 0) {
|
|
|
QueryWrapper<InquiryDrug> inquiryDrugQueryWrapper = new QueryWrapper<>();
|
|
@@ -245,26 +108,35 @@ public class TreatmentFacade {
|
|
|
List<Medicition> medicitionList = Lists.newLinkedList();
|
|
|
for (InquiryDrug inquiryDrug : inquiryDrugList) {
|
|
|
Medicition medicition = new Medicition();
|
|
|
- medicition.setId(inquiryDrug.getConceptId());
|
|
|
+ medicition.setConceptId(inquiryDrug.getConceptId());
|
|
|
medicition.setMedicitionName(inquiryDrug.getConceptName());
|
|
|
+ medicition.setLibType(8);
|
|
|
medicition.setIsShow("1");
|
|
|
- Boolean hasIntroduce = introduceMapFacade.hasIntroduceByQuestionName(inquiryDrug.getConceptName(), QuestionTypeEnum.Drug.getKey());
|
|
|
- if (hasIntroduce) {
|
|
|
+ ConceptBaseVO conceptBaseVO = new ConceptBaseVO();
|
|
|
+ conceptBaseVO.setName(medicition.getMedicitionName());
|
|
|
+ conceptBaseVO.setLibType(8);
|
|
|
+ RespDTO<Boolean> res = aiptServiceClient.existConceptDetail(conceptBaseVO);
|
|
|
+ if (RespDTOUtil.respIsOK(res) && res.data == true) {
|
|
|
medicition.setShowInfo("1");
|
|
|
} else {
|
|
|
medicition.setShowInfo("0");
|
|
|
}
|
|
|
medicitionList.add(medicition);
|
|
|
}
|
|
|
- Boolean isChronic = disTypeFacade.judgeByDisName(diseases[0], DisTypeEnum.CHRONIC.getKey());
|
|
|
- if (isChronic) {
|
|
|
- if (!chronicHistroy)
|
|
|
+
|
|
|
+ DisTypeVO disTypeVO = new DisTypeVO();
|
|
|
+ disTypeVO.setName(diseases[0]);
|
|
|
+ disTypeVO.setDisType(DisTypeEnum.CHRONIC.getKey());
|
|
|
+ RespDTO<Boolean> resDisType = aiptServiceClient.verifyDisType(disTypeVO);
|
|
|
+ if (RespDTOUtil.respIsOK(resDisType) && resDisType.data == true) {
|
|
|
+ if (!chronicHistroy) {
|
|
|
drugHistoryMap.put("慢病用药内容", medicitionList);
|
|
|
- chronicHistroy = true;
|
|
|
- } else {
|
|
|
- if (!not_chronicHistory) {
|
|
|
- drugHistoryMap.put("普通病用药内容", medicitionList);
|
|
|
- not_chronicHistory = true;
|
|
|
+ chronicHistroy = true;
|
|
|
+ } else {
|
|
|
+ if (!not_chronicHistory) {
|
|
|
+ drugHistoryMap.put("普通病用药内容", medicitionList);
|
|
|
+ not_chronicHistory = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|