|
@@ -0,0 +1,375 @@
|
|
|
|
+package org.diagbot.push.convert;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import org.diagbot.bigdata.common.ApplicationCacheUtil;
|
|
|
|
+import org.diagbot.common.javabean.MedicalIndication;
|
|
|
|
+import org.diagbot.common.javabean.MedicalIndicationDetail;
|
|
|
|
+import org.diagbot.common.javabean.Rule;
|
|
|
|
+import org.diagbot.common.work.LisDetail;
|
|
|
|
+import org.diagbot.common.work.ResponseData;
|
|
|
|
+import org.diagbot.common.work.SearchData;
|
|
|
|
+import org.diagbot.nlp.participle.ParticipleUtil;
|
|
|
|
+import org.diagbot.nlp.participle.word.Lexeme;
|
|
|
|
+import org.diagbot.nlp.participle.word.LexemePath;
|
|
|
|
+import org.diagbot.nlp.util.Constants;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+public class PreProcess {
|
|
|
|
+
|
|
|
|
+ private static String up = "升高";
|
|
|
|
+ private static String down = "降低";
|
|
|
|
+ private static String normal = "正常";
|
|
|
|
+
|
|
|
|
+ private static String pos = "阳性";
|
|
|
|
+ private static String neg = "阴性";
|
|
|
|
+
|
|
|
|
+ private List<Map<String, Object>> vitlist = new ArrayList<>();
|
|
|
|
+ private List<Map<String, Object>> pacslist = new ArrayList<>();
|
|
|
|
+ private String[] vitkeyset = {"index", "value", "unit"};
|
|
|
|
+ private String[] bptype = {"血压","收缩压","舒张压","/"};
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理临床数据
|
|
|
|
+ *
|
|
|
|
+ * @param searchdata
|
|
|
|
+ * @return ResponseData
|
|
|
|
+ */
|
|
|
|
+ public SearchData processClinicalData(SearchData searchdata) {
|
|
|
|
+ SearchData sData = searchdata;
|
|
|
|
+
|
|
|
|
+ sData.setLisArr(processLis(sData.getLisArr()));
|
|
|
|
+
|
|
|
|
+ if (sData.getLisArr().size() > 0) {
|
|
|
|
+ List<String> otherVal = sData.getLisArr().stream().map(lisArr -> lisArr.getOtherValue()).collect(Collectors.toList());
|
|
|
|
+ sData.setLis(String.join(",", otherVal));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return sData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ResponseData applyrules(SearchData sData) {
|
|
|
|
+
|
|
|
|
+ ResponseData ruleResponse = new ResponseData();
|
|
|
|
+
|
|
|
|
+ List<MedicalIndication> reminder;
|
|
|
|
+ try {
|
|
|
|
+ Map<String, List<Rule>> rule = ApplicationCacheUtil.get_rule_filter_map();
|
|
|
|
+
|
|
|
|
+ // 用规则处理化验结果
|
|
|
|
+ reminder = applytolis(sData.getLisArr(), rule);
|
|
|
|
+
|
|
|
|
+ // 用规则处理辅检结果
|
|
|
|
+ reminder.addAll(applytopacs(sData.getPacs(), rule));
|
|
|
|
+
|
|
|
|
+ // 用规则处理体征结果
|
|
|
|
+ reminder.addAll(applytovital(sData.getVital(), rule));
|
|
|
|
+
|
|
|
|
+ ruleResponse.setMedicalIndications(reminder);
|
|
|
|
+
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return ruleResponse;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> applytolis(List<LisDetail> lisarr, Map<String, List<Rule>> rule) {
|
|
|
|
+
|
|
|
|
+ List<MedicalIndication> reminder = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ String name;
|
|
|
|
+ String detail;
|
|
|
|
+
|
|
|
|
+ for (LisDetail lis : lisarr) {
|
|
|
|
+ detail = lis.getDetailName();
|
|
|
|
+// name = lis.getName();
|
|
|
|
+ String key = detail;
|
|
|
|
+ if (rule.get(key) != null) {
|
|
|
|
+ reminder.addAll(comparelis(rule.get(key), lis));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> applytopacs(String pacs, Map<String, List<Rule>> rule) {
|
|
|
|
+ List<MedicalIndication> reminder = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Set<String> pacsResultList = new HashSet<>();
|
|
|
|
+ Lexeme lexeme;
|
|
|
|
+ LexemePath<Lexeme> lexemes = ParticipleUtil.participle(pacs);
|
|
|
|
+ for (int i = 0; i < lexemes.size(); i++) {
|
|
|
|
+ lexeme = lexemes.get(i);
|
|
|
|
+ List<String> propetys = Arrays.asList(lexeme.getProperty().split(","));
|
|
|
|
+ if (lexeme.getText().trim().length() > 0) {
|
|
|
|
+ if(propetys.contains(Constants.word_property_PACS_Result)){
|
|
|
|
+ pacsResultList.add(lexeme.getText());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(pacsResultList.size()>0){
|
|
|
|
+ for (String pacsResult:pacsResultList) {
|
|
|
|
+ if(rule.containsKey(pacsResult)){
|
|
|
|
+ List<Rule> rules = rule.get(pacsResult);
|
|
|
|
+
|
|
|
|
+ List<MedicalIndicationDetail> mds = new ArrayList<>();
|
|
|
|
+ MedicalIndicationDetail medicalIndicationDetail = new MedicalIndicationDetail();
|
|
|
|
+ medicalIndicationDetail.setType(4);
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("controlType",2);
|
|
|
|
+ jsonObject.put("name",pacsResult);
|
|
|
|
+ medicalIndicationDetail.setContent(jsonObject);
|
|
|
|
+ mds.add(medicalIndicationDetail);
|
|
|
|
+ MedicalIndication medicalIndication = new MedicalIndication();
|
|
|
|
+ medicalIndication.setName(rules.get(0).getIdx_name()+","+rules.get(0).getRemind());
|
|
|
|
+ medicalIndication.setDetails(mds);
|
|
|
|
+ reminder.add(medicalIndication);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> applytovital(String vital, Map<String, List<Rule>> rule) {
|
|
|
|
+
|
|
|
|
+ List<MedicalIndication> reminder = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Map<String, Object> vitobj = new HashMap<>();
|
|
|
|
+ Lexeme lexeme;
|
|
|
|
+ LexemePath<Lexeme> lexemes = ParticipleUtil.participle(vital);
|
|
|
|
+ for (int i=0; i<lexemes.size(); i++) {
|
|
|
|
+ lexeme = lexemes.get(i);
|
|
|
|
+ if (lexeme.getText().trim().length() > 0) {
|
|
|
|
+ if (lexeme.getProperty().equals(Constants.word_property_vital_idx)) {
|
|
|
|
+ vitobj = new HashMap<>();
|
|
|
|
+ vitobj.put(vitkeyset[0], lexeme.getText());
|
|
|
|
+ } else if (lexeme.getProperty().equals(Constants.word_property_number) &&
|
|
|
|
+ vitobj.get(vitkeyset[0]) != null) {
|
|
|
|
+ vitobj.put(vitkeyset[1], lexeme.getText());
|
|
|
|
+ } else if (lexeme.getProperty().equals(Constants.word_property_unit) &&
|
|
|
|
+ vitobj.get(vitkeyset[1]) != null) {
|
|
|
|
+ vitobj.put(vitkeyset[2], lexeme.getText());
|
|
|
|
+
|
|
|
|
+ if (vitobj.get(vitkeyset[0]).toString().equals(bptype[0]) &&
|
|
|
|
+ vitobj.get(vitkeyset[1]).toString().contains(bptype[3])) {
|
|
|
|
+ String[] idx = Arrays.asList(bptype).subList(1,3).toArray(new String[2]);
|
|
|
|
+ String[] vals = vitobj.get(vitkeyset[1]).toString().split(bptype[3]);
|
|
|
|
+ String unit = vitobj.get(vitkeyset[2]).toString();
|
|
|
|
+
|
|
|
|
+ if (idx.length == vals.length) {
|
|
|
|
+ for (int j=0; j<idx.length; j++) {
|
|
|
|
+ vitobj = new HashMap<>();
|
|
|
|
+ vitobj.put(vitkeyset[0], idx[j]);
|
|
|
|
+ vitobj.put(vitkeyset[1], vals[j]);
|
|
|
|
+ vitobj.put(vitkeyset[2], unit);
|
|
|
|
+ vitlist.add(vitobj);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ vitlist.add(vitobj);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+// System.out.println(lexeme.getText() + ": " + lexeme.getProperty());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (Map<String, Object> obj : vitlist) {
|
|
|
|
+ String idx = obj.get(vitkeyset[0]).toString();
|
|
|
|
+ if (rule.get(idx) != null) {
|
|
|
|
+ reminder.addAll(comparevit(rule.get(idx), obj));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("\n");
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> comparelis(List<Rule> rules, LisDetail lis) {
|
|
|
|
+ List<MedicalIndication> reminder = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ String detailname = lis.getDetailName();
|
|
|
|
+ Double numval = lis.getValue();
|
|
|
|
+ String unit = lis.getUnits();
|
|
|
|
+ String otherval = lis.getOtherValue();
|
|
|
|
+
|
|
|
|
+ reminder = compare(rules, reminder, detailname, numval, unit, otherval);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> comparevit(List<Rule> rules, Map<String, Object> vit) {
|
|
|
|
+ List<MedicalIndication> reminder = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ String detailname = vit.get(vitkeyset[0]).toString();
|
|
|
|
+ Double numval = Double.valueOf(vit.get(vitkeyset[1]).toString());
|
|
|
|
+ String unit = vit.get(vitkeyset[2]).toString();
|
|
|
|
+ String otherval = "";
|
|
|
|
+
|
|
|
|
+ reminder = compare(rules, reminder, detailname, numval, unit, otherval);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> compare(List<Rule> rules, List<MedicalIndication> reminder,
|
|
|
|
+ String detailname, Double numval, String unit, String otherval) {
|
|
|
|
+ boolean minmatch, maxmatch;
|
|
|
|
+ Double minval, maxval;
|
|
|
|
+ String minop, maxop, minunit, maxunit;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ if (null == numval && otherval.trim().length() > 0) {
|
|
|
|
+ for (Rule rule : rules) {
|
|
|
|
+ if (rule.getEq_operator().equals("=") && otherval.contains(rule.getEq_value())) {
|
|
|
|
+ StringBuffer rulesContent = new StringBuffer();
|
|
|
|
+ StringBuffer append = rulesContent.append(rule.getIdx_name()).append(rule.getMin_operator()).append(rule.getMin_value()).append(rule.getMin_unit())
|
|
|
|
+ .append(rule.getMax_operator()).append(rule.getMax_value()).append(rule.getMax_unit())
|
|
|
|
+ .append(rule.getEq_operator()).append(rule.getEq_value()).append(rule.getEq_unit());
|
|
|
|
+ MedicalIndication medind = new MedicalIndication();
|
|
|
|
+ List<MedicalIndicationDetail> k = new ArrayList<>();
|
|
|
|
+ MedicalIndicationDetail mid = new MedicalIndicationDetail();
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+// jsonObject.put("name",detailname + ": " + otherval+ ", " +rule.getRemind());
|
|
|
|
+ jsonObject.put("name",append.toString());
|
|
|
|
+ jsonObject.put("controlType",2);
|
|
|
|
+ mid.setType(4);
|
|
|
|
+ mid.setContent(jsonObject);
|
|
|
|
+ k.add(mid);
|
|
|
|
+ medind.setName(rule.getRemind());
|
|
|
|
+ medind.setDetails(k);
|
|
|
|
+ medind.setRule(append.toString());
|
|
|
|
+ reminder.add(medind);
|
|
|
|
+
|
|
|
|
+ System.out.println(medind.getRule() + " -> " + medind.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (String.valueOf(numval).trim().length() > 0 && unit.length() > 0){
|
|
|
|
+ for (Rule rule : rules) {
|
|
|
|
+ minmatch = maxmatch = false;
|
|
|
|
+ minval = (rule.getMin_value().length()==0)?0:Double.valueOf(rule.getMin_value());
|
|
|
|
+ maxval = (rule.getMax_value().length()==0)?0:Double.valueOf(rule.getMax_value());
|
|
|
|
+ minunit = rule.getMin_unit();
|
|
|
|
+ maxunit = rule.getMax_unit();
|
|
|
|
+ minop = rule.getMin_operator();
|
|
|
|
+ maxop = rule.getMax_operator();
|
|
|
|
+
|
|
|
|
+ if ( String.valueOf(minval).trim().length() > 0) {
|
|
|
|
+ if (minunit.equals(unit) ) {
|
|
|
|
+ switch (minop) {
|
|
|
|
+ case ">":
|
|
|
|
+ if (numval > minval) { minmatch = true; }
|
|
|
|
+ break;
|
|
|
|
+ case ">=":
|
|
|
|
+ if (numval >= minval) { minmatch = true; }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else { minmatch = false; }
|
|
|
|
+ } else { minmatch = false; }
|
|
|
|
+
|
|
|
|
+ if (String.valueOf(maxval).trim().length() > 0 ) {
|
|
|
|
+ if (maxunit.equals(unit) ) {
|
|
|
|
+ switch (maxop) {
|
|
|
|
+ case "<":
|
|
|
|
+ if (numval < maxval) {
|
|
|
|
+ maxmatch = true;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "<=":
|
|
|
|
+ if (numval <= maxval) {
|
|
|
|
+ maxmatch = true;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else { maxmatch = false; }
|
|
|
|
+ } else { maxmatch = false; }
|
|
|
|
+
|
|
|
|
+ if (minmatch || maxmatch) {
|
|
|
|
+ StringBuffer rulesContent = new StringBuffer();
|
|
|
|
+ StringBuffer append = rulesContent.append(rule.getIdx_name()).append(rule.getMin_operator()).append(rule.getMin_value()).append(rule.getMin_unit())
|
|
|
|
+ .append(rule.getMax_operator()).append(rule.getMax_value()).append(rule.getMax_unit());
|
|
|
|
+
|
|
|
|
+ MedicalIndication medind = new MedicalIndication();
|
|
|
|
+ List<MedicalIndicationDetail> k = new ArrayList<>();
|
|
|
|
+ MedicalIndicationDetail mid = new MedicalIndicationDetail();
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+// jsonObject.put("name",detailname + ": " + numval + " " + unit+ "," +rule.getRemind());
|
|
|
|
+ jsonObject.put("name", append.toString());
|
|
|
|
+ jsonObject.put("controlType",2);
|
|
|
|
+ mid.setType(4);
|
|
|
|
+ mid.setContent(jsonObject);
|
|
|
|
+ k.add(mid);
|
|
|
|
+ medind.setName(rule.getRemind());
|
|
|
|
+ medind.setDetails(k);
|
|
|
|
+ medind.setRule(append.toString());
|
|
|
|
+ reminder.add(medind);
|
|
|
|
+
|
|
|
|
+ System.out.println(medind.getRule() + " -> " + medind.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<LisDetail> processLis(List<LisDetail> lisArr) {
|
|
|
|
+ if (lisArr == null) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ if (lisArr.size() == 0) {
|
|
|
|
+ return lisArr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String Otherval = "";
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < lisArr.size(); i++) {
|
|
|
|
+ LisDetail 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.getDetailName() + 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.getDetailName() + up);
|
|
|
|
+ } else if (lisres.getMinValue() != null && lisres.getValue() < lisres.getMinValue()) {
|
|
|
|
+ lisres.setOtherValue(Otherval + lisres.getDetailName() + down);
|
|
|
|
+ } else {
|
|
|
|
+ lisres.setOtherValue(Otherval + lisres.getDetailName() + normal);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return lisArr;
|
|
|
|
+ }
|
|
|
|
+}
|