|
@@ -7,29 +7,35 @@ import com.diagbot.client.bean.CalculateData;
|
|
import com.diagbot.client.bean.GdbResponse;
|
|
import com.diagbot.client.bean.GdbResponse;
|
|
import com.diagbot.client.bean.Response;
|
|
import com.diagbot.client.bean.Response;
|
|
import com.diagbot.client.bean.ResponseData;
|
|
import com.diagbot.client.bean.ResponseData;
|
|
-import com.diagbot.dto.FeatureConceptDTO;
|
|
|
|
import com.diagbot.dto.Lexeme;
|
|
import com.diagbot.dto.Lexeme;
|
|
import com.diagbot.dto.LisResult;
|
|
import com.diagbot.dto.LisResult;
|
|
import com.diagbot.entity.ScaleContent;
|
|
import com.diagbot.entity.ScaleContent;
|
|
-import com.diagbot.entity.SysLog;
|
|
|
|
import com.diagbot.enums.ScaleTypeEnum;
|
|
import com.diagbot.enums.ScaleTypeEnum;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.service.ScaleContentService;
|
|
import com.diagbot.service.ScaleContentService;
|
|
-import com.diagbot.util.DateUtil;
|
|
|
|
import com.diagbot.util.ListUtil;
|
|
import com.diagbot.util.ListUtil;
|
|
import com.diagbot.vo.SearchVo;
|
|
import com.diagbot.vo.SearchVo;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
- * 数据处理业务层
|
|
|
|
|
|
+ * 数据处理业务层
|
|
* </p>
|
|
* </p>
|
|
*
|
|
*
|
|
* @author Mark Huang
|
|
* @author Mark Huang
|
|
@@ -60,8 +66,9 @@ public class ClinicalFacade {
|
|
*/
|
|
*/
|
|
public ResponseData processClinicalData(@RequestBody SearchVo searchVo) {
|
|
public ResponseData processClinicalData(@RequestBody SearchVo searchVo) {
|
|
SearchVo sData = searchVo;
|
|
SearchVo sData = searchVo;
|
|
-
|
|
|
|
|
|
+ Map<String, List<Map<String, String>>> standWord = getStandWord();
|
|
Response<List<Lexeme>> resp = nlpServiceClient.split(sData.getSymptom());
|
|
Response<List<Lexeme>> resp = nlpServiceClient.split(sData.getSymptom());
|
|
|
|
+ addStandWord(resp.getData(), standWord, searchVo);
|
|
|
|
|
|
sData.setLisArr(processLis(sData.getLisArr()));
|
|
sData.setLisArr(processLis(sData.getLisArr()));
|
|
|
|
|
|
@@ -180,4 +187,230 @@ public class ClinicalFacade {
|
|
}
|
|
}
|
|
return response;
|
|
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++) {
|
|
|
|
+ if (i < feature.size() - 1) {
|
|
|
|
+ try {
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ System.out.println(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (i < feature.size() - 2) {
|
|
|
|
+ try {
|
|
|
|
+ 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 + 1).getProperty().contains("9"))) {
|
|
|
|
+ featureType.add(feature.get(i).getText() + "\t" + feature.get(i + 1).getText() + "\t"
|
|
|
|
+ + feature.get(i + 2).getText());
|
|
|
|
+ }
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ System.out.println(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //将标准词中体征指标值(数字)与分词结果中体征指标值(数字)比较
|
|
|
|
+ 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 {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ } 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 {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ } 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();
|
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+ File file = null;
|
|
|
|
+ BufferedReader reader = null;
|
|
|
|
+ String line = "";
|
|
|
|
+ try {
|
|
|
|
+ file = ResourceUtils.getFile("classpath:standword.txt");
|
|
|
|
+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "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();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|