|
@@ -0,0 +1,154 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.diagbot.biz.push.entity.FeatureRateV2;
|
|
|
+import com.diagbot.biz.push.entity.ResponseDataWithExplainV2;
|
|
|
+import com.diagbot.client.AiptServiceClient;
|
|
|
+import com.diagbot.client.TranServiceClient;
|
|
|
+import com.diagbot.dto.DiseaseDeptDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.dto.SYFDTO;
|
|
|
+import com.diagbot.dto.SYFDeptDTO;
|
|
|
+import com.diagbot.dto.SYFDiseaseDeptDTO;
|
|
|
+import com.diagbot.dto.SYFFeatureDTO;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+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.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.vo.AIVO;
|
|
|
+import com.diagbot.vo.DiseaseDeptVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2020/4/16 17:45
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class AIV2Facade {
|
|
|
+ @Autowired
|
|
|
+ private AiptServiceClient aiptServiceClient;
|
|
|
+ @Autowired
|
|
|
+ private TranServiceClient tranServiceClient;
|
|
|
+ @Autowired
|
|
|
+ private AssembleFacade assembleFacade;
|
|
|
+
|
|
|
+
|
|
|
+ public SYFDTO pushDisForSYFV2(AIVO aivo, String type) {
|
|
|
+ if (StringUtil.isBlank(aivo.getHospitalCode())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院编码");
|
|
|
+ }
|
|
|
+ RespDTO<ResponseDataWithExplainV2> res = aiptServiceClient.pushWithExplainV2(assembleFacade.assembleData(aivo, type));
|
|
|
+ RespDTOUtil.respNGDealCover(res, "中间层没有结果返回");
|
|
|
+ SYFDTO syfdto = new SYFDTO();
|
|
|
+
|
|
|
+ List<SYFDiseaseDeptDTO> items = Lists.newLinkedList();
|
|
|
+ List<FeatureRateV2> dis = res.data.getDis();
|
|
|
+ if (ListUtil.isNotEmpty(dis)) {
|
|
|
+ Map<String, List<SYFFeatureDTO>> disFeatureMap = new LinkedHashMap<>();
|
|
|
+ List<SYFFeatureDTO> disDTO = BeanUtil.listCopyTo(dis, SYFFeatureDTO.class);
|
|
|
+
|
|
|
+ //关联邵逸夫医院映射
|
|
|
+ DiseaseDeptVO diseaseDeptVO = new DiseaseDeptVO();
|
|
|
+ diseaseDeptVO.setHospitalCode(aivo.getHospitalCode());
|
|
|
+ List<String> disNames = dis.stream().map(i -> i.getFeatureName()).collect(Collectors.toList());
|
|
|
+ diseaseDeptVO.setConceptNames(disNames);
|
|
|
+ RespDTO<List<DiseaseDeptDTO>> diseaseDeptDTORes
|
|
|
+ = tranServiceClient.getDiseaseDeptByConceptNames(diseaseDeptVO);
|
|
|
+ RespDTOUtil.respNGDealCover(diseaseDeptDTORes, "诊断科室映射关系未维护");
|
|
|
+ List<DiseaseDeptDTO> diseaseDeptDTOList = diseaseDeptDTORes.data;
|
|
|
+ Map<String, List<DiseaseDeptDTO>> diseaseDeptMap
|
|
|
+ = EntityUtil.makeEntityListMap(diseaseDeptDTOList, "conceptDisName");
|
|
|
+ //诊断分类
|
|
|
+ for (SYFFeatureDTO featureRateDTO : disDTO) {
|
|
|
+ //关联外部诊断科室
|
|
|
+ if (diseaseDeptMap != null
|
|
|
+ && ListUtil.isNotEmpty(diseaseDeptMap.get(featureRateDTO.getFeatureName()))) {
|
|
|
+ List<DiseaseDeptDTO> ddList = diseaseDeptMap.get(featureRateDTO.getFeatureName());
|
|
|
+ featureRateDTO.setDeptName(ddList.get(0).getDeptName());
|
|
|
+ featureRateDTO.setSubDeptName(ddList.get(0).getSubDeptName());
|
|
|
+ featureRateDTO.setDiseaseName(ddList.get(0).getDiseaseName());
|
|
|
+ featureRateDTO.setDeptCode(ddList.get(0).getDeptCode());
|
|
|
+ featureRateDTO.setSubDeptCode(ddList.get(0).getSubDeptCode());
|
|
|
+ if (StringUtil.isNotBlank(ddList.get(0).getSubDeptName())
|
|
|
+ && (!ddList.get(0).getDeptName().equals(ddList.get(0).getSubDeptName()))) {
|
|
|
+ featureRateDTO
|
|
|
+ .setConcatDept(ddList.get(0).getDeptName() + "-" + ddList.get(0).getSubDeptName());
|
|
|
+ } else {
|
|
|
+ featureRateDTO.setConcatDept(ddList.get(0).getDeptName());
|
|
|
+ }
|
|
|
+ featureRateDTO.setUrl(ddList.get(0).getUrl());
|
|
|
+ } else {
|
|
|
+ featureRateDTO.setDiseaseName(featureRateDTO.getFeatureName());
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(featureRateDTO.getDesc())) {
|
|
|
+ featureRateDTO.setDesc("{\"可能诊断\":\"\"}");
|
|
|
+ }
|
|
|
+ Map<String, Object> descMap = FastJsonUtils.getJsonToMap(featureRateDTO.getDesc());
|
|
|
+ for (String disClass : descMap.keySet()) {
|
|
|
+ List<SYFFeatureDTO> featureRateDTOList = Lists.newLinkedList();
|
|
|
+ if (disFeatureMap.get(disClass) != null) {
|
|
|
+ featureRateDTOList = disFeatureMap.get(disClass);
|
|
|
+ }
|
|
|
+ featureRateDTOList.add(featureRateDTO);
|
|
|
+ disFeatureMap.put(disClass, featureRateDTOList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //仅分析确诊、拟诊、可能诊断,其他类型(如:警惕)不参与分诊推理
|
|
|
+ List<SYFFeatureDTO> featureRateList = Lists.newLinkedList();
|
|
|
+ if (disFeatureMap.containsKey("确诊")) {
|
|
|
+ featureRateList.addAll(disFeatureMap.get("确诊"));
|
|
|
+ } else if (disFeatureMap.containsKey("拟诊")) {
|
|
|
+ featureRateList.addAll(disFeatureMap.get("拟诊"));
|
|
|
+ } else if (disFeatureMap.containsKey("可能诊断")) {
|
|
|
+ featureRateList.addAll(disFeatureMap.get("可能诊断"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ListUtil.isEmpty(featureRateList)){
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "推理结果为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SYFFeatureDTO> syfFeatureDTOList = featureRateList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> StringUtil.isNotBlank(i.getConcatDept()))
|
|
|
+ .limit(2)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<String, List<SYFFeatureDTO>> featureMap
|
|
|
+ = EntityUtil.makeEntityListMap(syfFeatureDTOList, "concatDept");
|
|
|
+ for (Map.Entry<String, List<SYFFeatureDTO>> entry : featureMap.entrySet()) {
|
|
|
+ SYFDiseaseDeptDTO item = new SYFDiseaseDeptDTO();
|
|
|
+ BeanUtil.copyProperties(entry.getValue().get(0), item);
|
|
|
+ item.setDiseaseNames(entry.getValue()
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getDiseaseName())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ item.setDept(entry.getKey());
|
|
|
+ items.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //按大科室分组展示
|
|
|
+ Map<String, List<SYFDiseaseDeptDTO>> itemMap = EntityUtil.makeEntityListMap(items, "deptName");
|
|
|
+ List<SYFDeptDTO> syfDeptDTOList = Lists.newLinkedList();
|
|
|
+ itemMap.entrySet().forEach(item -> {
|
|
|
+ SYFDeptDTO syfDeptDTO = new SYFDeptDTO();
|
|
|
+ syfDeptDTO.setDeptName(item.getKey());
|
|
|
+ syfDeptDTO.setDeptCode(item.getValue().get(0).getDeptCode());
|
|
|
+ syfDeptDTO.setDiseaseDept(item.getValue());
|
|
|
+ syfDeptDTOList.add(syfDeptDTO);
|
|
|
+ });
|
|
|
+ syfdto.setDiseaseDept(syfDeptDTOList);
|
|
|
+ return syfdto;
|
|
|
+ }
|
|
|
+}
|