|
@@ -1,26 +1,20 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.diagbot.biz.push.entity.ResponseData;
|
|
|
+import com.diagbot.biz.push.entity.SearchData;
|
|
|
import com.diagbot.client.AIServiceClient;
|
|
|
-import com.diagbot.client.NLPServiceClient;
|
|
|
import com.diagbot.client.bean.CalculateData;
|
|
|
import com.diagbot.client.bean.Response;
|
|
|
-import com.diagbot.client.bean.ResponseData;
|
|
|
-import com.diagbot.dto.Lexeme;
|
|
|
-import com.diagbot.dto.LisResult;
|
|
|
import com.diagbot.entity.ScaleContent;
|
|
|
import com.diagbot.enums.ScaleTypeEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.ScaleContentService;
|
|
|
-import com.diagbot.util.ListUtil;
|
|
|
-import com.diagbot.vo.SearchVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -39,110 +33,47 @@ public class ClinicalFacade {
|
|
|
private AIServiceClient aiServiceClient;
|
|
|
@Autowired
|
|
|
private ScaleContentService scaleContentService;
|
|
|
- @Autowired
|
|
|
- private NLPServiceClient nlpServiceClient;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ConceptFacade conceptFacade;
|
|
|
-
|
|
|
- private static String up = "升高";
|
|
|
- private static String down = "降低";
|
|
|
- private static String normal = "正常";
|
|
|
-
|
|
|
- private static String pos = "阳性";
|
|
|
- private static String neg = "阴性";
|
|
|
-
|
|
|
- // private static Map<String, List<Map<String, String>>> standWordObj = null;
|
|
|
|
|
|
/**
|
|
|
* 处理临床数据
|
|
|
*
|
|
|
- * @param searchVo
|
|
|
+ * @param searchData
|
|
|
* @return ResponseData
|
|
|
*/
|
|
|
- public ResponseData processClinicalData(@RequestBody SearchVo searchVo) {
|
|
|
- SearchVo sData = searchVo;
|
|
|
- // Map<String, List<Map<String, String>>> standWord = getStandWord();
|
|
|
- // // standWordObj = getStandWord();
|
|
|
- // Response<List<Lexeme>> resp = nlpServiceClient.split(sData.getSymptom());
|
|
|
- // if (null != resp && null != resp.getData()) {
|
|
|
- // addStandWord(resp.getData(), standWord, sData);
|
|
|
- // }
|
|
|
-
|
|
|
- // sData.setLisArr(processLis(sData.getLisArr()));
|
|
|
-
|
|
|
- /*if (ListUtil.isNotEmpty(sData.getLisArr())) {
|
|
|
- List<String> otherVal = sData.getLisArr().stream().map(lisArr -> lisArr.getOtherValue()).collect(Collectors.toList());
|
|
|
- sData.setLis(String.join(",", otherVal));
|
|
|
- }*/
|
|
|
-
|
|
|
- Response<ResponseData> res = aiServiceClient.bayesPageData(sData);
|
|
|
+ public ResponseData processClinicalData(@RequestBody SearchData searchData) {
|
|
|
+ Response<ResponseData> res = aiServiceClient.bayesPageData(searchData);
|
|
|
if (res == null || res.getData() == null) {
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "AI没有返回结果");
|
|
|
}
|
|
|
-
|
|
|
return res.getData();
|
|
|
}
|
|
|
|
|
|
- private List<LisResult> processLis(List<LisResult> lisArr) {
|
|
|
- if (ListUtil.isEmpty(lisArr)) {
|
|
|
- return lisArr;
|
|
|
- }
|
|
|
-
|
|
|
- String Otherval = "";
|
|
|
-
|
|
|
- for (int i = 0; i < lisArr.size(); i++) {
|
|
|
- LisResult lisres = lisArr.get(i);
|
|
|
-
|
|
|
- Otherval = (lisres.getOtherValue().trim().length() > 0) ? lisres.getOtherValue().trim() + "\n" : "";
|
|
|
- Otherval = lisres.getOtherValue();
|
|
|
-
|
|
|
- if (Otherval.indexOf(pos) >= 0 || Otherval.indexOf(neg) >= 0) {
|
|
|
- lisres.setOtherValue(lisres.getUniqueName() + Otherval);
|
|
|
- } else {
|
|
|
- Otherval = (Otherval.trim().length() > 0) ? Otherval.trim() + "\n" : "";
|
|
|
- if (lisres.getValue() == null) {
|
|
|
- continue;
|
|
|
- } else if (lisres.getMaxValue() != null && lisres.getValue() > lisres.getMaxValue()) {
|
|
|
- lisres.setOtherValue(Otherval + lisres.getUniqueName() + up);
|
|
|
- } else if (lisres.getMinValue() != null && lisres.getValue() < lisres.getMinValue()) {
|
|
|
- lisres.setOtherValue(Otherval + lisres.getUniqueName() + down);
|
|
|
- } else {
|
|
|
- lisres.setOtherValue(Otherval + lisres.getUniqueName() + normal);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return lisArr;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
- * 获取量表内容
|
|
|
+ * 获取量表动态内容
|
|
|
*
|
|
|
- * @param searchVo
|
|
|
+ * @param searchData
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Object> scale(SearchVo searchVo) {
|
|
|
- Map<String, Object> response = aiServiceClient.scale(searchVo);
|
|
|
+ public Map<String, Object> scale(SearchData searchData) {
|
|
|
+ Map<String, Object> response = aiServiceClient.scale(searchData);
|
|
|
if (null == response) {
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "量表没有返回结果");
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 获取量表内容
|
|
|
+ * 获取量表全文
|
|
|
*
|
|
|
- * @param searchVo
|
|
|
+ * @param searchData
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<ScaleContent> getScale(SearchVo searchVo) {
|
|
|
- Map<String, Object> response = aiServiceClient.scale(searchVo);
|
|
|
+ public List<ScaleContent> getScale(SearchData searchData) {
|
|
|
+ Map<String, Object> response = aiServiceClient.scale(searchData);
|
|
|
if (null == response) {
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "量表没有返回结果");
|
|
|
}
|
|
|
- List<ScaleContent> list = getContent(searchVo.getScaleName(), JSON.toJSONString(response));
|
|
|
+ List<ScaleContent> list = getContent(searchData.getScaleName(), JSON.toJSONString(response));
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -170,237 +101,4 @@ public class ClinicalFacade {
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
-
|
|
|
- public SearchVo addStandWord(List<Lexeme> lexemes, Map<String, List<Map<String, String>>> standWords, SearchVo sData) {
|
|
|
- List<Lexeme> feature = new ArrayList<>();
|
|
|
- //收集分词结果中体征指标或体征指标值(数字)
|
|
|
- for (int i = 0; i < lexemes.size(); i++) {
|
|
|
- if (lexemes.get(i).getProperty().contains("33") || lexemes.get(i).getProperty().contains("28")
|
|
|
- || lexemes.get(i).getProperty().contains("2") || lexemes.get(i).getProperty().contains("9")
|
|
|
- ) {
|
|
|
- feature.add(lexemes.get(i));
|
|
|
- }
|
|
|
- }
|
|
|
- //根据收集到的分词结果把体征指标和对应体征指标值(数字)拼接
|
|
|
- List<String> featureType = new ArrayList<>();
|
|
|
- for (int i = 0; i < feature.size(); i++) {
|
|
|
- boolean featureTypeState = true;
|
|
|
- if (i < feature.size() - 2) {
|
|
|
- if ((feature.get(i).getProperty().contains("33") && feature.get(i + 1).getProperty().contains("28")
|
|
|
- && feature.get(i + 2).getProperty().contains("2"))
|
|
|
- || (feature.get(i).getProperty().contains("33") && feature.get(i + 1).getProperty().contains("28")
|
|
|
- && feature.get(i + 2).getProperty().contains("9"))) {
|
|
|
- featureType.add(feature.get(i).getText() + "\t" + feature.get(i + 1).getText() + "\t"
|
|
|
- + feature.get(i + 2).getText());
|
|
|
- featureTypeState = false;
|
|
|
- }
|
|
|
- }
|
|
|
- if (i < feature.size() - 1 && featureTypeState) {
|
|
|
- if (feature.get(i).getProperty().contains("33") && feature.get(i + 1).getProperty().contains("28")) {
|
|
|
- featureType.add(feature.get(i).getText() + "\t" + feature.get(i + 1).getText());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //将标准词中体征指标值(数字)与分词结果中体征指标值(数字)比较
|
|
|
- for (String f : featureType) {
|
|
|
- String[] features = f.split("\t");
|
|
|
- if (standWords.containsKey(features[0])) {
|
|
|
- List<Map<String, String>> standWordList = standWords.get(features[0]);
|
|
|
- for (Map<String, String> standWordMap : standWordList) {
|
|
|
- if (standWordMap.containsKey("op") && standWordMap.containsKey("unit")
|
|
|
- && standWordMap.containsKey("value")) {
|
|
|
- if (features.length == 2) {
|
|
|
- judgment(sData, features, features[0], standWordMap);
|
|
|
- } else {
|
|
|
- if (standWordMap.get("unit").equals(features[2])) {
|
|
|
- judgment(sData, features, features[0], standWordMap);
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (standWordMap.containsKey("op") && standWordMap.containsKey("value")) {
|
|
|
- if (features.length == 2) {
|
|
|
- judgment(sData, features, features[0], standWordMap);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return sData;
|
|
|
- }
|
|
|
-
|
|
|
- //将标准词中体征指标值(数字)与分词结果中体征指标值(数字)比较
|
|
|
- private void judgment(SearchVo sData, String[] features, String standWordKey, Map<String, String> standWordMap) {
|
|
|
- if (standWordMap.get("op").contains(">=") || standWordMap.get("op").contains("≥")
|
|
|
- || standWordMap.get("op").contains(">") || standWordMap.get("op").contains("大于")
|
|
|
- || standWordMap.get("op").contains(">") || standWordMap.get("op").contains("大")) {
|
|
|
- //单独处理 血压≥140/90mmHg 类似情况
|
|
|
- if (features[1].contains("/")) {
|
|
|
- if (standWordMap.get("value").contains("/")) {
|
|
|
- String[] feature = features[1].split("/");
|
|
|
- Integer featuresSBP = Integer.valueOf(feature[0]); //分词特征收缩压
|
|
|
- Integer featuresDBP = Integer.valueOf(feature[1]); //分词特征舒张压
|
|
|
-
|
|
|
- String[] values = standWordMap.get("value").split("/");
|
|
|
- Integer standWordSBP = Integer.valueOf(values[0]); //标准词收缩压
|
|
|
- Integer standWordDBP = Integer.valueOf(values[1]); //标准词舒张压
|
|
|
- if (featuresSBP > standWordSBP && featuresDBP > standWordDBP) {
|
|
|
- String standWord = standWordKey
|
|
|
- + standWordMap.get("op")
|
|
|
- + standWordMap.get("value")
|
|
|
- + standWordMap.get("unit") + "。";
|
|
|
- sData.setSymptom(sData.getSymptom() + standWord);
|
|
|
- System.out.println(sData.getSymptom());
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- String num = getNum(standWordMap.get("value"));
|
|
|
- if (Double.valueOf(getNum(features[1])) > Double.valueOf(num)) {
|
|
|
- String standWord = standWordKey
|
|
|
- + standWordMap.get("op")
|
|
|
- + standWordMap.get("value")
|
|
|
- + standWordMap.get("unit") + "。";
|
|
|
- sData.setSymptom(sData.getSymptom() + standWord);
|
|
|
- System.out.println(sData.getSymptom());
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (standWordMap.get("op").contains("<=") || standWordMap.get("op").contains("≤")
|
|
|
- || standWordMap.get("op").contains("<") || standWordMap.get("op").contains("小于")
|
|
|
- || standWordMap.get("op").contains("<") || standWordMap.get("op").contains("少于")
|
|
|
- || standWordMap.get("op").contains("小")) {
|
|
|
- //单独处理 血压小于90/60mmHg 类似情况
|
|
|
- if (standWordMap.get("value").contains("/")) {
|
|
|
- if (features[1].contains("/")) {
|
|
|
- String[] feature = features[1].split("/");
|
|
|
- Integer featuresSBP = Integer.valueOf(feature[0]); //收缩压
|
|
|
- Integer featuresDBP = Integer.valueOf(feature[1]); //舒张压
|
|
|
-
|
|
|
- String[] values = standWordMap.get("value").split("/");
|
|
|
- Integer standWordSBP = Integer.valueOf(values[0]); //收缩压
|
|
|
- Integer standWordDBP = Integer.valueOf(values[1]); //舒张压
|
|
|
- if (featuresSBP < standWordSBP && featuresDBP < standWordDBP) {
|
|
|
- String standWord = standWordKey
|
|
|
- + standWordMap.get("op")
|
|
|
- + standWordMap.get("value")
|
|
|
- + standWordMap.get("unit") + "。";
|
|
|
- sData.setSymptom(sData.getSymptom() + standWord);
|
|
|
- System.out.println(sData.getSymptom());
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- String num = getNum(standWordMap.get("value"));
|
|
|
- if (Double.valueOf(getNum(features[1])) < Double.valueOf(num)) {
|
|
|
- String standWord = standWordKey
|
|
|
- + standWordMap.get("op")
|
|
|
- + standWordMap.get("value")
|
|
|
- + standWordMap.get("unit")
|
|
|
- + "。";
|
|
|
- sData.setSymptom(sData.getSymptom() + standWord);
|
|
|
- System.out.println(sData.getSymptom());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String getNum(String standWord) {
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- try {
|
|
|
- for (String num : standWord.replaceAll("[^0-9]", ",").split(",")) {
|
|
|
- if (num.length() > 0) {
|
|
|
- sb.append(num);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- e.printStackTrace();
|
|
|
- System.out.println(e.getMessage() + "不是标准数字");
|
|
|
- }
|
|
|
- return sb.toString();
|
|
|
- }
|
|
|
-
|
|
|
- private Map<String, List<Map<String, String>>> getStandWord() {
|
|
|
- Map<String, List<Map<String, String>>> standWordObj = new HashMap<>();
|
|
|
- List<List<Lexeme>> splitStandWords = new ArrayList<>();
|
|
|
- List<Lexeme> data = null;
|
|
|
- /*BufferedReader reader = null;
|
|
|
- InputStream inputStream = null;
|
|
|
- String line = "";
|
|
|
- try {
|
|
|
- //file = ResourceUtils.getFile("classpath:standword.txt");
|
|
|
- // Resource resource = new ClassPathResource("standword.txt");
|
|
|
- ClassPathResource classPathResource = new ClassPathResource("standword.txt");
|
|
|
- inputStream = classPathResource.getInputStream();
|
|
|
- // file = resource.getFile();
|
|
|
- reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
|
|
- while ((line = reader.readLine()) != null) {
|
|
|
- data = nlpServiceClient.split(line).getData();
|
|
|
- splitStandWords.add(data);
|
|
|
- // standWord.add(line);
|
|
|
- }
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- reader.close();
|
|
|
- inputStream.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }*/
|
|
|
- List<String> standWords = conceptFacade.getStandWord();
|
|
|
- for (String standWord : standWords) {
|
|
|
- data = nlpServiceClient.split(standWord).getData();
|
|
|
- splitStandWords.add(data);
|
|
|
- }
|
|
|
-
|
|
|
- List<Map<String, String>> standWordObjValList = null;
|
|
|
- Map<String, String> standWordObjVal = null;
|
|
|
- for (List<Lexeme> splitStandWord : splitStandWords) {
|
|
|
- standWordObjValList = new ArrayList<>();
|
|
|
- standWordObjVal = new HashMap<>();
|
|
|
- int i = 0;
|
|
|
- String standWordObjKey = "";
|
|
|
- for (Lexeme lexeme : splitStandWord) {
|
|
|
- i++;
|
|
|
- // if ("\uFEFF".equals(lexeme.getText()) || lexeme.getText().length() <= 0) {
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- if (lexeme.getProperty().contains("1") || lexeme.getProperty().contains("5")
|
|
|
- || lexeme.getProperty().contains("33")) {
|
|
|
- if (!standWordObj.containsKey(lexeme.getText())) {
|
|
|
- standWordObj.put(lexeme.getText(), standWordObjValList);
|
|
|
- } else {
|
|
|
- standWordObjKey = lexeme.getText();
|
|
|
- }
|
|
|
- } else if (lexeme.getProperty().contains("44")) {
|
|
|
-
|
|
|
- if (standWordObjVal.containsKey("op")) {
|
|
|
- standWordObjVal.put("op", standWordObjVal.get("op") + "," + lexeme.getText());
|
|
|
- } else {
|
|
|
- standWordObjVal.put("op", lexeme.getText());
|
|
|
- }
|
|
|
- } else if (lexeme.getProperty().contains("13") || lexeme.getProperty().contains("28")) {
|
|
|
- if (standWordObjVal.containsKey("value")) {
|
|
|
- standWordObjVal.put("value", standWordObjVal.get("value") + "," + lexeme.getText());
|
|
|
- } else {
|
|
|
- standWordObjVal.put("value", lexeme.getText());
|
|
|
- }
|
|
|
- } else if (lexeme.getProperty().contains("2") || lexeme.getProperty().contains("9")) {
|
|
|
- if (standWordObjVal.containsKey("unit")) {
|
|
|
- standWordObjVal.put("unit", standWordObjVal.get("unit") + "," + lexeme.getText());
|
|
|
- } else {
|
|
|
- standWordObjVal.put("unit", lexeme.getText());
|
|
|
- }
|
|
|
- }
|
|
|
- if (splitStandWord.size() == i) {
|
|
|
- if (standWordObj.containsKey(standWordObjKey)) {
|
|
|
- standWordObj.get(standWordObjKey).add(standWordObjVal);
|
|
|
- } else {
|
|
|
- standWordObjValList.add(standWordObjVal);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return standWordObj;
|
|
|
- }
|
|
|
}
|