|
@@ -0,0 +1,194 @@
|
|
|
|
+package org.diagbot.push.transform;
|
|
|
|
+
|
|
|
|
+import org.diagbot.bigdata.common.ApplicationCacheUtil;
|
|
|
|
+import org.diagbot.common.javabean.Rule;
|
|
|
|
+import org.diagbot.common.javabean.MedicalIndication;
|
|
|
|
+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.push.controller.ParticipleController;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+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 = "阴性";
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理临床数据
|
|
|
|
+ *
|
|
|
|
+ * @param searchdata
|
|
|
|
+ * @return ResponseData
|
|
|
|
+ */
|
|
|
|
+ public SearchData processClinicalData(SearchData searchdata) {
|
|
|
|
+ SearchData sData = searchdata;
|
|
|
|
+
|
|
|
|
+ sData = calculateLis(sData);
|
|
|
|
+
|
|
|
|
+ return sData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ResponseData applyrules(SearchData sData, ResponseData bigDataResponse) {
|
|
|
|
+
|
|
|
|
+ List<MedicalIndication> reminder;
|
|
|
|
+ try {
|
|
|
|
+ Map<String, List<Rule>> rule = ApplicationCacheUtil.get_rule_filter_map();
|
|
|
|
+
|
|
|
|
+ reminder = applytolis(sData, rule);
|
|
|
|
+
|
|
|
|
+ bigDataResponse.setMedicalIndications(reminder);
|
|
|
|
+
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return bigDataResponse;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> applytolis(SearchData sData, Map<String, List<Rule>> rule) {
|
|
|
|
+
|
|
|
|
+ List<MedicalIndication> reminder = new ArrayList<>();
|
|
|
|
+ try {
|
|
|
|
+ List<LisDetail> lisarr = sData.getLisArr();
|
|
|
|
+ String name;
|
|
|
|
+ String detail;
|
|
|
|
+
|
|
|
|
+ for (LisDetail lis : lisarr) {
|
|
|
|
+ detail = lis.getDetailName();
|
|
|
|
+// name = lis.getName();
|
|
|
|
+ String key = detail;
|
|
|
|
+ if (rule.get(key) != null) {
|
|
|
|
+ reminder.addAll(compare(rule.get(key), lis));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (MedicalIndication r: reminder) {
|
|
|
|
+ System.out.println(r.getName());
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<MedicalIndication> compare(List<Rule> rules, LisDetail lis) {
|
|
|
|
+ List<MedicalIndication> reminder = new ArrayList<>();
|
|
|
|
+ boolean minmatch, maxmatch;
|
|
|
|
+ Double minval, maxval;
|
|
|
|
+ String minop, maxop, minunit, maxunit;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Double numval = lis.getValue();
|
|
|
|
+ String unit = lis.getUnits();
|
|
|
|
+ String otherval = lis.getOtherValue();
|
|
|
|
+
|
|
|
|
+ if (null == numval && otherval.trim().length() > 0) {
|
|
|
|
+ for (Rule rule : rules) {
|
|
|
|
+ if (rule.getMin_operator().equals("=") && otherval.contains(rule.getMin_value())) {
|
|
|
|
+ MedicalIndication medind = new MedicalIndication();
|
|
|
|
+ medind.setName(rule.getRemind());
|
|
|
|
+ reminder.add(medind);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } 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 && minunit.equals(unit) ) {
|
|
|
|
+ switch (minop) {
|
|
|
|
+ case ">":
|
|
|
|
+ if (numval > minval) { minmatch = true; }
|
|
|
|
+ break;
|
|
|
|
+ case ">=":
|
|
|
|
+ if (numval >= minval) { minmatch = true; }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else { minmatch = true; }
|
|
|
|
+
|
|
|
|
+ if (String.valueOf(maxval).trim().length() > 0 && maxunit.equals(unit) ) {
|
|
|
|
+ switch (maxop) {
|
|
|
|
+ case "<":
|
|
|
|
+ if (numval < maxval) { maxmatch = true; }
|
|
|
|
+ break;
|
|
|
|
+ case "<=":
|
|
|
|
+ if (numval <= maxval) { maxmatch = true; }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else { maxmatch = true; }
|
|
|
|
+
|
|
|
|
+ if (minmatch && maxmatch) {
|
|
|
|
+ MedicalIndication medind = new MedicalIndication();
|
|
|
|
+ medind.setName(rule.getRemind());
|
|
|
|
+ reminder.add(medind);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ return reminder;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private SearchData calculateLis(SearchData sData) {
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<LisDetail> processLis(List<LisDetail> lisArr) {
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+}
|