|
@@ -1,14 +1,19 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
import com.diagbot.biz.push.entity.FeatureRate;
|
|
|
-import com.diagbot.biz.push.entity.ResponseData;
|
|
|
+import com.diagbot.biz.push.entity.FeatureRateWithExplain;
|
|
|
+import com.diagbot.biz.push.entity.ResponseDataWithExplain;
|
|
|
import com.diagbot.biz.push.vo.SearchVO;
|
|
|
import com.diagbot.client.AiptServiceClient;
|
|
|
import com.diagbot.client.TranServiceClient;
|
|
|
import com.diagbot.dto.AIDTO;
|
|
|
+import com.diagbot.dto.DiseaseDeptDTO;
|
|
|
import com.diagbot.dto.FeatureRateDTO;
|
|
|
import com.diagbot.dto.HospitalDeptDTO;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.dto.SYFDTO;
|
|
|
+import com.diagbot.dto.SYFDiseaseDeptDTO;
|
|
|
+import com.diagbot.dto.SYFFeatureDTO;
|
|
|
import com.diagbot.enums.SysTypeEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
@@ -19,6 +24,7 @@ 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.diagbot.vo.HospitalDeptVO;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -52,12 +58,12 @@ public class AIFacade {
|
|
|
* @return AI接口返回结果
|
|
|
*/
|
|
|
public AIDTO push(AIVO aivo, String type) {
|
|
|
- RespDTO<ResponseData> res = aiptServiceClient.aiptData(assembleData(aivo, type));
|
|
|
+ RespDTO<ResponseDataWithExplain> res = aiptServiceClient.pushWithExplain(assembleData(aivo, type));
|
|
|
RespDTOUtil.respNGDealCover(res, "中间层没有结果返回");
|
|
|
AIDTO aidto = new AIDTO();
|
|
|
switch (type) {
|
|
|
case "1":
|
|
|
- List<FeatureRate> symptom = res.data.getSymptom();
|
|
|
+ List<FeatureRateWithExplain> symptom = res.data.getSymptom();
|
|
|
if (ListUtil.isNotEmpty(symptom)) {
|
|
|
List<FeatureRateDTO> symptomDTO = BeanUtil.listCopyTo(symptom, FeatureRateDTO.class);
|
|
|
aidto.setItems(symptomDTO);
|
|
@@ -166,6 +172,135 @@ public class AIFacade {
|
|
|
return aidto;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 调用ai接口业务逻辑
|
|
|
+ *
|
|
|
+ * @param aivo 搜索参数
|
|
|
+ * @return AI接口返回结果
|
|
|
+ */
|
|
|
+ public SYFDTO pushDisForSYF(AIVO aivo, String type) {
|
|
|
+ if (StringUtil.isBlank(aivo.getHospitalCode())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "请输入医院编码");
|
|
|
+ }
|
|
|
+ RespDTO<ResponseDataWithExplain> res = aiptServiceClient.pushWithExplain(assembleData(aivo, type));
|
|
|
+ RespDTOUtil.respNGDealCover(res, "中间层没有结果返回");
|
|
|
+ SYFDTO syfdto = new SYFDTO();
|
|
|
+
|
|
|
+ List<SYFDiseaseDeptDTO> items = new ArrayList<>();
|
|
|
+ List<FeatureRate> 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());
|
|
|
+ if (StringUtil.isNotBlank(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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (disFeatureMap.get("确诊") != null) {
|
|
|
+ items = getItemsForSYF(disFeatureMap, "确诊", 1);
|
|
|
+ }
|
|
|
+ if (disFeatureMap.get("拟诊") != null && ListUtil.isEmpty(items)) {
|
|
|
+ items = getItemsForSYF(disFeatureMap, "拟诊", 2);
|
|
|
+ }
|
|
|
+ if (disFeatureMap.get("可能诊断") != null && ListUtil.isEmpty(items)) {
|
|
|
+ List<SYFFeatureDTO> featureRateList = disFeatureMap.get("可能诊断");
|
|
|
+ List<SYFDiseaseDeptDTO> mergeFeatureList = Lists.newLinkedList();
|
|
|
+ Map<String, List<SYFFeatureDTO>> syfFeatureMap = new HashMap<>();
|
|
|
+ //根据阈值(0.05)过滤诊断
|
|
|
+ featureRateList = featureRateList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> (i.getRate() != null && Double.valueOf(i.getRate()) > 0.05d))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (SYFFeatureDTO syfFeatureDTO : featureRateList) {
|
|
|
+ if (StringUtil.isNotBlank(syfFeatureDTO.getConcatDept())) {
|
|
|
+ List<SYFFeatureDTO> features = Lists.newLinkedList();
|
|
|
+ if (syfFeatureMap.containsKey(syfFeatureDTO.getConcatDept())) {
|
|
|
+ features = syfFeatureMap.get(syfFeatureDTO.getConcatDept());
|
|
|
+ }
|
|
|
+ features.add(syfFeatureDTO);
|
|
|
+ syfFeatureMap.put(syfFeatureDTO.getConcatDept(), features);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ SYFDiseaseDeptDTO syfDiseaseDeptDTO = new SYFDiseaseDeptDTO();
|
|
|
+ syfDiseaseDeptDTO.setRate(Double.valueOf(syfFeatureDTO.getRate()));
|
|
|
+ List<SYFFeatureDTO> features = Lists.newLinkedList();
|
|
|
+ features.add(syfFeatureDTO);
|
|
|
+ syfDiseaseDeptDTO.setFeatures(features);
|
|
|
+ mergeFeatureList.add(syfDiseaseDeptDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (syfFeatureMap != null) {
|
|
|
+ for (Map.Entry<String, List<SYFFeatureDTO>> entry : syfFeatureMap.entrySet()) {
|
|
|
+ SYFDiseaseDeptDTO syfDiseaseDeptDTO = new SYFDiseaseDeptDTO();
|
|
|
+ syfDiseaseDeptDTO.setDept(entry.getKey());
|
|
|
+ syfDiseaseDeptDTO.setUrl(entry.getValue().get(0).getUrl());
|
|
|
+ syfDiseaseDeptDTO.setFeatures(entry.getValue());
|
|
|
+ Double rate = 0d;
|
|
|
+ for (SYFFeatureDTO feature : entry.getValue()) {
|
|
|
+ rate += Double.valueOf(feature.getRate());
|
|
|
+ }
|
|
|
+ syfDiseaseDeptDTO.setRate(rate);
|
|
|
+ mergeFeatureList.add(syfDiseaseDeptDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Collections.sort(mergeFeatureList, new Comparator<SYFDiseaseDeptDTO>() {
|
|
|
+ @Override
|
|
|
+ public int compare(SYFDiseaseDeptDTO o1, SYFDiseaseDeptDTO o2) {
|
|
|
+ return Double.compare(o2.getRate(), o1.getRate());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ for (SYFDiseaseDeptDTO syfDiseaseDeptDTO : mergeFeatureList) {
|
|
|
+ if (items.size() < 2) {
|
|
|
+ items.add(syfDiseaseDeptDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ syfdto.setDiseaseDept(items);
|
|
|
+ return syfdto;
|
|
|
+ }
|
|
|
+
|
|
|
private List<FeatureRateDTO> getItems(Map<String, List<FeatureRateDTO>> disFeatureMap,
|
|
|
String type, int size) {
|
|
|
List<FeatureRateDTO> items = new ArrayList<>();
|
|
@@ -200,6 +335,70 @@ public class AIFacade {
|
|
|
return items;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 邵逸夫科室推理(确诊、拟诊)
|
|
|
+ *
|
|
|
+ * @param disFeatureMap
|
|
|
+ * @param type
|
|
|
+ * @param size
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<SYFDiseaseDeptDTO> getItemsForSYF(Map<String, List<SYFFeatureDTO>> disFeatureMap,
|
|
|
+ String type, int size) {
|
|
|
+ List<SYFDiseaseDeptDTO> items = new ArrayList<>();
|
|
|
+ List<SYFFeatureDTO> featureRateList = disFeatureMap.get(type);
|
|
|
+ if (ListUtil.isEmpty(featureRateList)) {
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+ List<SYFDiseaseDeptDTO> mergeFeatureList = Lists.newLinkedList();
|
|
|
+ Map<String, List<SYFFeatureDTO>> syfFeatureMap = new HashMap<>();
|
|
|
+ for (SYFFeatureDTO syfFeatureDTO : featureRateList) {
|
|
|
+ if (StringUtil.isNotBlank(syfFeatureDTO.getConcatDept())) {
|
|
|
+ SYFDiseaseDeptDTO syfDiseaseDeptDTO = new SYFDiseaseDeptDTO();
|
|
|
+ syfDiseaseDeptDTO.setDept(syfFeatureDTO.getConcatDept());
|
|
|
+ syfDiseaseDeptDTO.setUrl(syfFeatureDTO.getUrl());
|
|
|
+ List<SYFFeatureDTO> features = Lists.newLinkedList();
|
|
|
+ if (syfFeatureMap.containsKey(syfFeatureDTO.getConcatDept())) {
|
|
|
+ features = syfFeatureMap.get(syfFeatureDTO.getConcatDept());
|
|
|
+ } else {
|
|
|
+ mergeFeatureList.add(syfDiseaseDeptDTO);
|
|
|
+ }
|
|
|
+ features.add(syfFeatureDTO);
|
|
|
+ syfDiseaseDeptDTO.setFeatures(features);
|
|
|
+ syfFeatureMap.put(syfFeatureDTO.getConcatDept(), features);
|
|
|
+ } else {
|
|
|
+ SYFDiseaseDeptDTO syfDiseaseDeptDTO = new SYFDiseaseDeptDTO();
|
|
|
+ List<SYFFeatureDTO> features = Lists.newLinkedList();
|
|
|
+ features.add(syfFeatureDTO);
|
|
|
+ syfDiseaseDeptDTO.setFeatures(features);
|
|
|
+ mergeFeatureList.add(syfDiseaseDeptDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (SYFDiseaseDeptDTO syfDiseaseDeptDTO : mergeFeatureList) {
|
|
|
+ if (StringUtil.isNotBlank(syfDiseaseDeptDTO.getDept())) {
|
|
|
+ if (syfFeatureMap.containsKey(syfDiseaseDeptDTO.getDept())) {
|
|
|
+ syfDiseaseDeptDTO.setFeatures(syfFeatureMap.get(syfDiseaseDeptDTO.getDept()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Collections.sort(mergeFeatureList, new Comparator<SYFDiseaseDeptDTO>() {
|
|
|
+ @Override
|
|
|
+ public int compare(SYFDiseaseDeptDTO o1, SYFDiseaseDeptDTO o2) {
|
|
|
+ return Integer.compare(o2.getFeatures().size(), o1.getFeatures().size());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ for (SYFDiseaseDeptDTO syfDiseaseDeptDTO : mergeFeatureList) {
|
|
|
+ if (items.size() < size) {
|
|
|
+ items.add(syfDiseaseDeptDTO);
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+
|
|
|
private SearchVO assembleData(AIVO aivo, String type) {
|
|
|
SearchVO searchVO = new SearchVO();
|
|
|
searchVO.setAge(aivo.getAge());
|