瀏覽代碼

未经产妇和经产妇添加既往史匹配规则

zhoutg 4 年之前
父節點
當前提交
88b1c47526

+ 1 - 1
src/main/java/com/diagbot/facade/KlDiagnoseDetailFacade.java

@@ -312,6 +312,6 @@ public class KlDiagnoseDetailFacade {
         String pateern = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";
         String content = formulas.stream().collect(Collectors.joining(","));
         //获取公式中的编码
-        return RegexUtil.getRegexDatas(content, pateern);
+        return RegexUtil.getRegexDataAll(content, pateern);
     }
 }

+ 32 - 12
src/main/java/com/diagbot/rule/GroupRule.java

@@ -6,9 +6,11 @@ import com.diagbot.dto.RuleBaseDTO;
 import com.diagbot.dto.RuleSimpleDTO;
 import com.diagbot.dto.WordCrfDTO;
 import com.diagbot.util.CoreUtil;
+import com.diagbot.util.ListUtil;
 import com.diagbot.util.MsgNewUtil;
 import com.diagbot.util.RegexUtil;
 import com.diagbot.util.StringUtil;
+import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -80,9 +82,11 @@ public class GroupRule {
         String menstrual = wordCrfDTO.getMenstrual(); // 月经史
         String marriage = wordCrfDTO.getMarriage(); // 婚姻
         String marital = wordCrfDTO.getMarital();// 婚育史
+        String pasts = wordCrfDTO.getPasts(); // 既往史
         boolean flag = false;
         String regex = "";
         String regex2 = "";
+        List<String> groupList = Lists.newArrayList(); // 分组信息
         List<String> nameList = CoreUtil.getSplit(ruleBaseDTO.getBaseLibName());
         for (String name : nameList) {
             switch (name) {
@@ -135,23 +139,39 @@ public class GroupRule {
                         flag = true;
                     }
                     break;
-                case "未经产妇":
+                case "未经产妇": // 女性+(婚育史或既往史)数值累加为0
                     regex = "(\\d+)-(\\d+)-(\\d+)-(\\d+)";
-                    if (sex == 2 && StringUtil.isNotBlank(marital) && RegexUtil.getRegexRes(marital, regex)) {
-                        if (Integer.parseInt(RegexUtil.getRegexData(marital, regex, 1))
-                                + Integer.parseInt(RegexUtil.getRegexData(marital, regex, 2))
-                                + Integer.parseInt(RegexUtil.getRegexData(marital, regex, 3)) == 0) {
-                            flag = true;
+                    if (sex == 2) {
+                        if (StringUtil.isNotBlank(marital) && RegexUtil.getRegexRes(marital, regex)) {
+                            // 婚育史判断
+                            groupList = RegexUtil.getRegexDataList(marital, regex);
+                        } else if (StringUtil.isNotBlank(pasts) && RegexUtil.getRegexRes(pasts, regex)) {
+                            // 既往史判断
+                            groupList = RegexUtil.getRegexDataList(pasts, regex);
+                        }
+                        if (ListUtil.isNotEmpty(groupList) && groupList.size() == 4) {
+                            if (Integer.parseInt(groupList.get(0)) + Integer.parseInt(groupList.get(1))
+                                    + Integer.parseInt(groupList.get(2)) == 0) {
+                                flag = true;
+                            }
                         }
                     }
                     break;
-                case "经产妇":
+                case "经产妇": // 女性+(婚育史或既往史)数值累加>=1
                     regex = "(\\d+)-(\\d+)-(\\d+)-(\\d+)";
-                    if (sex == 2 && StringUtil.isNotBlank(marital) && RegexUtil.getRegexRes(marital, regex)) {
-                        if (Integer.parseInt(RegexUtil.getRegexData(marital, regex, 1))
-                                + Integer.parseInt(RegexUtil.getRegexData(marital, regex, 2))
-                                + Integer.parseInt(RegexUtil.getRegexData(marital, regex, 3)) >= 1) {
-                            flag = true;
+                    if (sex == 2) {
+                        if (StringUtil.isNotBlank(marital) && RegexUtil.getRegexRes(marital, regex)) {
+                            // 婚育史判断
+                            groupList = RegexUtil.getRegexDataList(marital, regex);
+                        } else if (StringUtil.isNotBlank(pasts) && RegexUtil.getRegexRes(pasts, regex)) {
+                            // 既往史判断
+                            groupList = RegexUtil.getRegexDataList(pasts, regex);
+                        }
+                        if (ListUtil.isNotEmpty(groupList) && groupList.size() == 4) {
+                            if (Integer.parseInt(groupList.get(0)) + Integer.parseInt(groupList.get(1))
+                                    + Integer.parseInt(groupList.get(2)) >= 1) {
+                                flag = true;
+                            }
                         }
                     }
                     break;

+ 72 - 47
src/main/java/com/diagbot/util/RegexUtil.java

@@ -40,16 +40,12 @@ public class RegexUtil {
     /**
      * 是否有符合正则的数据(大小写敏感)
      *
-     * @param content 文本内容
-     * @param regex   表达式
-     * @param senstive 大小写是否敏感
+     * @param content  文本内容
+     * @param regex    表达式
      * @return
      */
-    public static Boolean getRegexRes(String content, String regex, boolean senstive) {
-        if (senstive) {
-            return getRegexResCommon(content, regex, true);
-        }
-        return getRegexResCommon(content, regex, false);
+    public static Boolean getRegexResSen(String content, String regex) {
+        return getRegexResCommon(content, regex, true);
     }
 
     /**
@@ -79,7 +75,7 @@ public class RegexUtil {
     /**
      * 获取pattern
      *
-     * @param regex 正则表达式
+     * @param regex     正则表达式
      * @param sensitive 大小写敏感
      * @return
      */
@@ -94,7 +90,7 @@ public class RegexUtil {
     }
 
     /**
-     * 根据正则获取指定分组数据(大小写不敏感)
+     * 根据正则获取第一个匹配的指定分组数据(大小写不敏感)
      *
      * @param content  文本内容
      * @param regex    表达式
@@ -106,22 +102,19 @@ public class RegexUtil {
     }
 
     /**
-     * 根据正则获取指定分组数据(大小写敏感)
+     * 根据正则获取第一个匹配的指定分组数据(大小写敏感)
      *
      * @param content  文本内容
      * @param regex    表达式
      * @param groupNum 获取第几个内容
      * @return
      */
-    public static String getRegexData(String content, String regex, Integer groupNum, Boolean sensitive) {
-        if (sensitive) {
-            return getRegexDataCommon(content, regex, groupNum, true);
-        }
-        return getRegexDataCommon(content, regex, groupNum, false);
+    public static String getRegexDataSen(String content, String regex, Integer groupNum) {
+        return getRegexDataCommon(content, regex, groupNum, true);
     }
 
     /**
-     * 根据正则获取指定分组数据(公共方法)
+     * 根据正则获取第一个匹配的指定分组数据(公共方法)
      *
      * @param content  文本内容
      * @param regex    表达式
@@ -148,38 +141,35 @@ public class RegexUtil {
     }
 
     /**
-     * 根据正则获取所有分组数据(大小写不敏感)
+     * 根据正则获取第一个匹配的所有分组数据(大小写不敏感)
      *
      * @param content
      * @param regex
      * @return
      */
-    public static List<String> getRegexData(String content, String regex) {
-        return getRegexDataCommon(content, regex, false);
+    public static List<String> getRegexDataList(String content, String regex) {
+        return getRegexDataListCommon(content, regex, false);
     }
 
     /**
-     * 根据正则获取所有分组数据(大小写敏感)
+     * 根据正则获取第一个匹配的所有分组数据(大小写敏感)
      *
      * @param content
      * @param regex
      * @return
      */
-    private static List<String> getRegexData(String content, String regex, Boolean sensitive) {
-        if (sensitive) {
-            getRegexDataCommon(content, regex, true);
-        }
-        return getRegexDataCommon(content, regex, false);
+    public static List<String> getRegexDataListSen(String content, String regex) {
+        return getRegexDataListCommon(content, regex, true);
     }
 
     /**
-     * 根据正则获取所有分组数据(内部方法)
+     * 根据正则获取第一个匹配的所有分组数据(内部方法)
      *
      * @param content
      * @param regex
      * @return
      */
-    private static List<String> getRegexDataCommon(String content, String regex, Boolean sensitive) {
+    private static List<String> getRegexDataListCommon(String content, String regex, Boolean sensitive) {
         List<String> list = Lists.newArrayList();
         try {
             if (StringUtil.isBlank(content)) {
@@ -198,18 +188,51 @@ public class RegexUtil {
         return list;
     }
 
-    public static List<String> getRegexDatas(String content, String pattern){
-        List<String> numbers=new ArrayList<>();
-        // 创建 Pattern 对象
-        Pattern r = Pattern.compile(pattern);
-        // 现在创建 matcher 对象
-        Matcher matcher = r.matcher(content);
-        while (matcher.find()) {
-            //获取当前匹配的值
-            numbers.add(matcher.group());
-        }
+    /**
+     * 根据正则获取所有匹配数据(大小写不敏感)
+     *
+     * @param content
+     * @param regex
+     * @return
+     */
+    public static List<String> getRegexDataAll(String content, String regex) {
+        return getRegexDataAllCommon(content, regex, false);
+    }
 
-        return numbers;
+    /**
+     * 根据正则获取所有匹配数据(大小写敏感)
+     *
+     * @param content
+     * @param regex
+     * @return
+     */
+    public static List<String> getRegexDataAllSen(String content, String regex) {
+        return getRegexDataAllCommon(content, regex, true);
+    }
+
+    /**
+     * 根据正则获取所有匹配数据(内部方法)
+     *
+     * @param content
+     * @param regex
+     * @return
+     */
+    private static List<String> getRegexDataAllCommon(String content, String regex, Boolean sensitive) {
+        List<String> list = Lists.newArrayList();
+        try {
+            if (StringUtil.isBlank(content)) {
+                return list;
+            }
+            Pattern pattern = getPattern(regex, sensitive);
+            Matcher matcher = pattern.matcher(content);
+            while (matcher.find()) {
+                //获取当前匹配的值
+                list.add(matcher.group());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return list;
     }
 
     /**
@@ -218,19 +241,21 @@ public class RegexUtil {
      * @param args
      */
     public static void main(String[] args) {
-        String regex1 = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";
-        // System.out.println(getRegexData("血小板计数  30.3", regex1, 2));
-        System.out.println(getRegexData("拟诊+(3.3/3.4)任一", regex1));
+        String str = "1-2-3-4, 法法,0-0-1-0";
+        String regex = "(\\d+)-(\\d+)-(\\d+)-(\\d+)";
+        System.out.println(getRegexDataList(str, regex));
 
-        String s1 = "ABC";
-        System.out.println(getRegexRes(s1, "Abc", true));
+        // String regex1 = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";
+        // // System.out.println(getRegexData("血小板计数  30.3", regex1, 2));
+        // System.out.println(getRegexData("拟诊+(3.3/3.4)任一", regex1));
+        //
+        // String s1 = "ABC";
+        // System.out.println(getRegexRes(s1, "Abc", true));
 
-        System.out.println(getRegexDatas("拟诊+(3.3/3.4)任一","([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])"));
+        System.out.println(getRegexDataAll("拟诊+(3.3/3.4)任一", "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])"));
 
         ArrayList<String> js = Lists.newArrayList("G.4", "G.1", "G.2", "G.3");
         List<String> collect = js.stream().sorted().collect(Collectors.toList());
         System.out.println(collect);
-
-
     }
 }