|
@@ -0,0 +1,167 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.client.AIServiceClient;
|
|
|
+import com.diagbot.client.bean.FeatureRate;
|
|
|
+import com.diagbot.client.bean.Response;
|
|
|
+import com.diagbot.client.bean.ResponseData;
|
|
|
+import com.diagbot.client.bean.SearchData;
|
|
|
+import com.diagbot.dto.PushDTO;
|
|
|
+import com.diagbot.entity.DeptInfo;
|
|
|
+import com.diagbot.entity.DeptVital;
|
|
|
+import com.diagbot.entity.QuestionInfo;
|
|
|
+import com.diagbot.entity.VitalOrder;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.vo.PushVO;
|
|
|
+import com.diagbot.web.DeptInfoController;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.sun.corba.se.impl.ior.OldJIDLObjectKeyTemplate;
|
|
|
+import com.sun.xml.internal.ws.config.metro.dev.FeatureReader;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2018/11/20 11:18
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class PushFacade {
|
|
|
+ @Autowired
|
|
|
+ private AIServiceClient aiServiceClient;
|
|
|
+ @Autowired
|
|
|
+ private QuestionFacade questionFacade;
|
|
|
+ @Autowired
|
|
|
+ private DeptInfoFacade deptInfoFacade;
|
|
|
+ @Autowired
|
|
|
+ private DeptVitalFacade deptVitalFacade;
|
|
|
+ @Autowired
|
|
|
+ private VitalOrderFacade vitalOrderFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推理接口
|
|
|
+ *
|
|
|
+ * @param pushVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PushDTO push(PushVO pushVO) {
|
|
|
+ PushDTO pushDTO = new PushDTO();
|
|
|
+ SearchData searchData = new SearchData();
|
|
|
+ searchData.setAge(pushVO.getAge());
|
|
|
+ searchData.setSymptom(pushVO.getSymptom());
|
|
|
+ searchData.setVital(pushVO.getVital());
|
|
|
+ searchData.setLis(pushVO.getLis());
|
|
|
+ searchData.setPacs(pushVO.getPacs());
|
|
|
+ searchData.setPast(pushVO.getPast());
|
|
|
+ searchData.setOther(pushVO.getOther());
|
|
|
+ switch (pushVO.getSex()) {
|
|
|
+ case 1:
|
|
|
+ searchData.setSex("M");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ searchData.setSex("F");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ searchData.setSex("A");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_ERROR, "性别参数错误");
|
|
|
+ }
|
|
|
+ String featureType = pushVO.getFeatureType();
|
|
|
+ String[] featureTypes = featureType.split(",|,");
|
|
|
+ Set<String> featureTypeSet = new HashSet(Arrays.asList(featureTypes));
|
|
|
+
|
|
|
+
|
|
|
+ searchData.setFeatureType(pushVO.getFeatureType());
|
|
|
+ searchData.setSysCode("1");
|
|
|
+ searchData.setLength(10);
|
|
|
+
|
|
|
+ Response<ResponseData> res = aiServiceClient.bayesPageData(searchData);
|
|
|
+ List<FeatureRate> symptom = res.getData().getSymptom();
|
|
|
+ List<FeatureRate> dis = res.getData().getDis();
|
|
|
+ List<FeatureRate> pacs = res.getData().getPacs();
|
|
|
+ List<FeatureRate> labs = res.getData().getLabs();
|
|
|
+
|
|
|
+ Map<String, Object> symptomMap = list2Map(symptom);
|
|
|
+ Map<String, Object> vitalMap = new HashMap<>();
|
|
|
+ Map<String, Object> disMap = list2Map(dis);
|
|
|
+ Map<String, Object> labMap = list2Map(labs);
|
|
|
+ Map<String, Object> pacsMap = list2Map(pacs);
|
|
|
+
|
|
|
+ //症状(主诉 type=1;现病史 type=2) 返回 tagName+id
|
|
|
+ if (featureTypeSet.contains("1") || featureTypeSet.contains("2")) {
|
|
|
+ QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper();
|
|
|
+ questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).in("tag_name", symptomMap.keySet()).eq("type", "2");
|
|
|
+ List<QuestionInfo> questionInfoList = questionFacade.list(questionInfoQueryWrapper);
|
|
|
+ Map<String, QuestionInfo> questionInfoMap = EntityUtil.makeEntityMap(questionInfoList, "tagName");
|
|
|
+ for (Map.Entry<String, Object> entry : symptomMap.entrySet()) {
|
|
|
+ entry.setValue(questionInfoMap.get(entry.getKey()).getId());
|
|
|
+ }
|
|
|
+ pushDTO.setSymptomMap(symptomMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ pushDTO.setDisMap(disMap);
|
|
|
+ pushDTO.setPacsMap(pacsMap);
|
|
|
+ pushDTO.setLabMap(labMap);
|
|
|
+
|
|
|
+ //查体 返回模板
|
|
|
+ if (featureTypeSet.contains("4") && dis != null && dis.size() > 0) {
|
|
|
+ String deptName = dis.get(0).getExtraProperty();
|
|
|
+ QueryWrapper<DeptInfo> deptInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ deptInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("name", deptName);
|
|
|
+ DeptInfo deptInfo = deptInfoFacade.getOne(deptInfoQueryWrapper);
|
|
|
+ if (deptInfo == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "科室信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<DeptVital> deptVitalQueryWrapper = new QueryWrapper<>();
|
|
|
+ deptVitalQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("dept_id", deptInfo.getId());
|
|
|
+ List<DeptVital> deptVitalList = deptVitalFacade.list(deptVitalQueryWrapper);
|
|
|
+ if (deptVitalList.size() > 0) {
|
|
|
+ Map<Long, DeptVital> deptVitalMap = EntityUtil.makeEntityMap(deptVitalList, "vitalId");
|
|
|
+ //排序
|
|
|
+ QueryWrapper<VitalOrder> vitalOrderQueryWrapper = new QueryWrapper<>();
|
|
|
+ vitalOrderQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).in("question_id", deptVitalMap.keySet()).orderByAsc("order_no");
|
|
|
+ List<VitalOrder> vitalOrderList = vitalOrderFacade.list(vitalOrderQueryWrapper);
|
|
|
+ Map<Long, VitalOrder> vitalOrderMap = EntityUtil.makeEntityMap(vitalOrderList, "id");
|
|
|
+ //标签列表
|
|
|
+ QueryWrapper<QuestionInfo> vitalQueryWrapper = new QueryWrapper<>();
|
|
|
+ vitalQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).in("id", deptVitalMap.keySet());
|
|
|
+ List<QuestionInfo> vitalList = questionFacade.list(vitalQueryWrapper);
|
|
|
+ Map<Long, QuestionInfo> vitalQuestionMap = EntityUtil.makeEntityMap(vitalList, "id");
|
|
|
+ for (Map.Entry<Long, VitalOrder> entry : vitalOrderMap.entrySet()) {
|
|
|
+ QuestionInfo vitalQuestion = vitalQuestionMap.get(entry.getKey());
|
|
|
+ if (vitalQuestion != null) {
|
|
|
+ vitalMap.put(vitalQuestion.getTagName(), vitalQuestion);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pushDTO.setVitalMap(vitalMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pushDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将list 转换成 map
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> list2Map(List<FeatureRate> list) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ for (FeatureRate featureRate : list) {
|
|
|
+ map.put(featureRate.getFeatureName(), null);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|