Просмотр исходного кода

Merge branch 'push-dev-preprocess' into push-test

MarkHuang 5 лет назад
Родитель
Сommit
ae5613f849

+ 40 - 0
bigdata-web/src/main/java/org/diagbot/bigdata/common/ApplicationCacheUtil.java

@@ -2,6 +2,7 @@ package org.diagbot.bigdata.common;
 
 import org.diagbot.bigdata.dao.model.ResultMappingFilter;
 import org.diagbot.bigdata.util.BigDataConstants;
+import org.diagbot.common.javabean.Rule;
 import org.diagbot.nlp.participle.ParticipleUtil;
 import org.diagbot.nlp.participle.cfg.Configuration;
 import org.diagbot.nlp.participle.cfg.DefaultConfig;
@@ -30,6 +31,8 @@ public class ApplicationCacheUtil {
     public static Map<String, Map<String, ResultMappingFilter>> doc_result_mapping_filter_map = null;
     //诊断依据标准词
     public static Map<String, List<Map<String, String>>> kl_result_mapping_standword_map = null;
+    // 规则
+    public static Map<String, List<Rule>> rule_filter_map = null;
 
     public static Map<String, Map<String, String>> getStandard_info_synonym_map() {
         if (standard_info_synonym_map == null) {
@@ -214,6 +217,43 @@ public class ApplicationCacheUtil {
         return kl_result_mapping_standword_map;
     }
 
+    public static Map<String, List<Rule>> get_rule_filter_map() {
+        if (rule_filter_map == null || rule_filter_map.size() == 0) {
+            create_rule_filter_map();
+        }
+        return rule_filter_map;
+    }
+
+    public static void create_rule_filter_map() {
+        rule_filter_map = new HashMap<>();
+        List<Rule> rulelist;
+        Map<String, String> rule;
+        String key;
+
+        String[] labels = {"set_name","idx_name","min_operator","min_value","min_unit",
+                "max_operator","max_value","max_unit","remind"};
+
+        Configuration configuration = new DefaultConfig();
+        List<String> fileContents = configuration.readFileContents("rule_filter.dict");
+
+        for (String line:fileContents) {
+            rule = new HashMap<>();
+            String[] content = line.split("\\|");
+            if (labels.length == content.length) {
+//                for (int i=0; i<labels.length; i++) {
+//                    rule.put(labels[i], content[i]);
+//                }
+//                key = content[0] + "--" + content[1];
+                key = content[1];
+                if (rule_filter_map.get(key) == null) {
+                    rule_filter_map.put(key, new ArrayList<>());
+                }
+                rulelist = rule_filter_map.get(key);
+                rulelist.add(new Rule(content));
+            }
+        }
+    }
+
     public static void setProterty(Lexeme lexeme) {
         for (String featureType : lexeme.getProperty().split(",")) {
             switch (featureType) {

+ 1 - 1
bigdata-web/src/main/java/org/diagbot/bigdata/controller/AlgorithmController.java

@@ -34,7 +34,7 @@ public class AlgorithmController extends BaseController {
     public Response<ResponseData> algorithm(HttpServletRequest request, SearchData searchData) throws Exception {
         Response<ResponseData> response = new Response();
         AlgorithmCore core = new AlgorithmCore();
-        ResponseData responseData = core.algorithm(request, searchData);
+        ResponseData responseData = core.algorithm(request, searchData, null);
         response.setData(responseData);
         return response;
     }

+ 4 - 2
bigdata-web/src/main/java/org/diagbot/bigdata/work/AlgorithmCore.java

@@ -25,8 +25,10 @@ import java.util.*;
  **/
 public class AlgorithmCore {
     Logger logger = LoggerFactory.getLogger(AlgorithmCore.class);
-    public ResponseData algorithm(HttpServletRequest request, SearchData searchData) throws Exception {
-        ResponseData responseData = new ResponseData();
+    public ResponseData algorithm(HttpServletRequest request, SearchData searchData, ResponseData responseData) throws Exception {
+        if (responseData == null) {
+            responseData = new ResponseData();
+        }
         //录入文本处理,包括提取特征、推送类型转换等
         ParamsDataProxy paramsDataProxy = new ParamsDataProxy();
         logger.info("页面文本信息:" + searchData.getSymptom());

+ 26 - 2
common-push/src/main/java/org/diagbot/common/push/cache/CacheFileManager.java

@@ -30,7 +30,7 @@ public class CacheFileManager {
     public static void main(String[] args) {
         CacheFileManager cacheFileManager = new CacheFileManager();
         String p = cacheFileManager.getClass().getClassLoader().getResource("").getPath();
-        p = "d:/cache_file/";
+        p = "e:/cache_file/";
         File file = new File(p);
         if (!file.exists()) {
             file.mkdirs();
@@ -261,6 +261,30 @@ public class CacheFileManager {
                 fw.write("\n");
             }
             fw.close();
+
+            //规则过滤信息
+            sql = "SELECT set_name, idx_name, min_operator, min_value, min_unit, max_operator, " +
+                    " max_value, max_unit, remind FROM kl_rule ";
+            st = conn.createStatement();
+            rs = st.executeQuery(sql);
+            fw = new FileWriter(path + "rule_filter.dict");
+            String r6, r7, r8, r9;
+            while (rs.next()) {
+                r1 = rs.getString(1);
+                r2 = rs.getString(2);
+                r3 = rs.getString(3);
+                r4 = rs.getString(4);
+                r5 = rs.getString(5);
+                r6 = rs.getString(6);
+                r7 = rs.getString(7);
+                r8 = rs.getString(8);
+                r9 = rs.getString(9);
+                fw.write(encrypDES.encrytor(r1+ "|" + r2 + "|" + r3 + "|" + r4 + "|" + r5
+                        + "|" + r6 + "|" + r7 + "|" + r8 + "|" + r9));
+                fw.write("\n");
+            }
+            fw.close();
+
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
@@ -318,7 +342,7 @@ public class CacheFileManager {
             }
             fw.close();
 
-            sql = "SELECT lib_name FROM kl_concept WHERE is_deleted = 'N' AND lib_type = 70 AND lib_name regexp '[0-9]'";
+            sql = "SELECT lib_name FROM kl_concept WHERE is_deleted = 'N' AND lib_name regexp '[0-9]'";
             st = conn.createStatement();
             rs = st.executeQuery(sql);
 

+ 10 - 0
common-service/src/main/java/org/diagbot/common/javabean/MedicalIndication.java

@@ -7,6 +7,8 @@ import java.util.List;
  */
 public class MedicalIndication {
     private String name;
+    // 触发推送的规则
+    private String rule;
     private List<MedicalIndicationDetail> details;
 
     public String getName() {
@@ -17,6 +19,14 @@ public class MedicalIndication {
         this.name = name;
     }
 
+    public String getRule() {
+        return rule;
+    }
+
+    public void setRule(String rule) {
+        this.rule = rule;
+    }
+
     public List<MedicalIndicationDetail> getDetails() {
         return details;
     }

+ 50 - 0
common-service/src/main/java/org/diagbot/common/javabean/Rule.java

@@ -0,0 +1,50 @@
+package org.diagbot.common.javabean;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 触发规则
+ * @author Mark Huang
+ * @since 27/08/2019
+ */
+@Getter
+@Setter
+public class Rule {
+    // 套餐名称
+    private String set_name;
+    // 指标名称
+    private String idx_name;
+    // 最小值操作符
+    private String min_operator;
+    // 最小值
+    private String min_value;
+    // 最小值单位
+    private String min_unit;
+    // 最大值操作符
+    private String max_operator;
+    // 最大值
+    private String max_value;
+    // 最大值单位
+    private String max_unit;
+    // 推送名称
+    private String remind;
+
+    public Rule() { }
+
+    public Rule(String[] elements) {
+//        Rule rule = new Rule();
+
+        if (elements.length == 9) {
+            this.set_name = elements[0];
+            this.idx_name = elements[1];
+            this.min_operator = elements[2];
+            this.min_value = elements[3];
+            this.min_unit = elements[4];
+            this.max_operator = elements[5];
+            this.max_value = elements[6];
+            this.max_unit = elements[7];
+            this.remind = elements[8];
+        }
+    }
+}

+ 7 - 0
nlp/pom.xml

@@ -38,6 +38,13 @@
             <artifactId>poi-ooxml</artifactId>
             <version>3.17</version>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/org.mongodb/bson -->
+        <dependency>
+            <groupId>org.mongodb</groupId>
+            <artifactId>bson</artifactId>
+            <version>3.10.2</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 11 - 6
push-web/src/main/java/org/diagbot/push/controller/AlgorithmController.java

@@ -11,8 +11,6 @@ import org.diagbot.common.work.FeatureRate;
 import org.diagbot.common.work.ResponseData;
 import org.diagbot.common.work.SearchData;
 import org.diagbot.graph.util.CacheUtil;
-import org.diagbot.graphWeb.work.DiseaseCalculate;
-import org.diagbot.graphWeb.work.FilterSortDiag;
 import org.diagbot.graphWeb.work.GraphCalculate;
 import org.diagbot.graphWeb.work.LisPacsCalculate;
 import org.diagbot.nlp.util.Constants;
@@ -29,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.diagbot.push.transform.PreProcess;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.*;
@@ -120,10 +119,15 @@ public class AlgorithmController extends BaseController {
     }
 
     public Response<ResponseData> combine(HttpServletRequest request, SearchData searchData) throws Exception {
+        logger.info("开始规则转换......");
+        PreProcess prepro = new PreProcess();
+        searchData = prepro.processClinicalData(searchData);
+        ResponseData RuleResponseData = prepro.applyrules(searchData);
+
         logger.info("开始推送服务......");
         Response<ResponseData> response = new Response();
         AlgorithmCore core = new AlgorithmCore();
-        ResponseData bigDataResponseData = core.algorithm(request, searchData);
+        ResponseData bigDataResponseData = core.algorithm(request, searchData, RuleResponseData);
 
         GraphCalculate graphCalculate = new GraphCalculate();
         ResponseData graphResponseData = graphCalculate.calculate(request, searchData);
@@ -157,7 +161,8 @@ public class AlgorithmController extends BaseController {
         List<MedicalIndication> medicalIndications = graphResponseData.getMedicalIndications();
         if (medicalIndications != null && medicalIndications.size() > 0) {
             logger.info("指标推送!!!!!!!!!");
-            bigDataResponseData.setMedicalIndications(medicalIndications);
+            bigDataResponseData.getMedicalIndications().addAll(medicalIndications);
+//            bigDataResponseData.setMedicalIndications(medicalIndications);
         }
         //推送管理评估
         bigDataResponseData.setManagementEvaluation(graphResponseData.getManagementEvaluation());
@@ -172,11 +177,11 @@ public class AlgorithmController extends BaseController {
         Map<String, String> vitalCache = CacheUtil.getVitalCache();
         List<String> featureList = Arrays.asList(searchData.getFeatureTypes());
         List<FeatureRate> vitals = graphResponseData.getVitals();
-        if(featureList.contains(Constants.feature_type_vital_index)){
+        if(featureList.contains(Constants.feature_type_vital_index) && this.getVital(vitalCache,vitals).size() > 0){
             bigDataResponseData.setVitals(this.getVital(vitalCache,vitals));
 
         }
-        if(featureList.contains(Constants.feature_type_vital)){
+        if(featureList.contains(Constants.feature_type_vital) && vitals.size() > 0){
             bigDataResponseData.setVitals(vitals);
         }
 

+ 200 - 0
push-web/src/main/java/org/diagbot/push/transform/PreProcess.java

@@ -0,0 +1,200 @@
+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 ruleResponse = new ResponseData();
+
+        List<MedicalIndication> reminder;
+        try {
+            Map<String, List<Rule>> rule = ApplicationCacheUtil.get_rule_filter_map();
+
+            reminder = applytolis(sData, rule);
+
+            ruleResponse.setMedicalIndications(reminder);
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            return ruleResponse;
+        }
+    }
+
+    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));
+                }
+            }
+
+        } 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 {
+            String detailname = lis.getDetailName();
+            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());
+                        medind.setRule(detailname + ": " + otherval);
+                        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 && 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());
+                        medind.setRule(detailname + ": " + numval + " " + unit);
+                        reminder.add(medind);
+
+                        System.out.println(medind.getRule() + " -> " + medind.getName());
+                    }
+                }
+            }
+
+        } 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;
+    }
+}