Sfoglia il codice sorgente

正则规则优化4

wangfeng 4 anni fa
parent
commit
ac0c303f41
1 ha cambiato i file con 60 aggiunte e 13 eliminazioni
  1. 60 13
      src/main/java/com/diagbot/facade/SysRegularConfigFacade.java

+ 60 - 13
src/main/java/com/diagbot/facade/SysRegularConfigFacade.java

@@ -9,6 +9,7 @@ import com.diagbot.entity.SysRegularConfig;
 import com.diagbot.enums.IsDeleteEnum;
 import com.diagbot.enums.RegularConfigEnum;
 import com.diagbot.model.entity.Allergy;
+import com.diagbot.model.entity.AllergyMedicine;
 import com.diagbot.model.label.PastLabel;
 import com.diagbot.service.impl.SysRegularConfigServiceImpl;
 import com.diagbot.util.ListUtil;
@@ -37,11 +38,19 @@ public class SysRegularConfigFacade extends SysRegularConfigServiceImpl {
         List<SysRegularConfig> regularConfigs = list(regularQuery);
         if (ListUtil.isNotEmpty(regularConfigs)) {
             for (SysRegularConfig data : regularConfigs) {
-                String pattern = data.getRulesValue();
+                String pattern = "";
+                String patternMax = "";
+                if (data.getRulesTepy().equals(RegularConfigEnum.allergy.getKey())) {
+                    pattern =  data.getRulesValue().split("¥")[0];
+                    patternMax = data.getRulesValue().split("¥")[1];
+                } else {
+                    pattern = data.getRulesValue();
+                }
                 // 创建 Pattern 对象
                 Pattern r = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
                 // 现在创建 matcher 对象
                 Matcher m = r.matcher(regularConfigDataVO.getText());
+                int trueMin = 0;
                 while (m.find()) {
                     //System.out.println(m.group());
                     String steing = m.group();
@@ -49,32 +58,57 @@ public class SysRegularConfigFacade extends SysRegularConfigServiceImpl {
                     Integer type = data.getRulesTepy();
                     if (data.getRulesTepy().equals(RegularConfigEnum.lis.getKey())) {
                         value = steing.replaceAll("([^\\d\\.]|\\.(?=[^\\.]*\\.))", "");
+                        RegularValueDTO regularValueDTO = new RegularValueDTO();
+                        regularValueDTO.setKey(data.getRulesName());
+                        regularValueDTO.setType(type);
+                        regularValueDTO.setValue(value);
+                        listData.add(regularValueDTO);
+                    } else if (data.getRulesTepy().equals(RegularConfigEnum.allergy.getKey())) {
+                        //取否认的数
+                        trueMin++;
                     }
-                    RegularValueDTO regularValueDTO = new RegularValueDTO();
-                    regularValueDTO.setKey(data.getRulesName());
-                    regularValueDTO.setType(type);
-                    regularValueDTO.setValue(value);
-                    listData.add(regularValueDTO);
-                    System.out.println(listData.toString());
                 }
+                int trueMax = 0;
+                //取所有符合的
+                if (data.getRulesTepy().equals(RegularConfigEnum.allergy.getKey())) {
+                    Pattern rMax = Pattern.compile(patternMax, Pattern.CASE_INSENSITIVE);
+                    // 现在创建 matcher 对象
+                    Matcher mMax = rMax.matcher(regularConfigDataVO.getText());
+                    while (mMax.find()) {
+                        if (data.getRulesTepy().equals(RegularConfigEnum.allergy.getKey())) {
+                            trueMax++;
+                        }
+                    }
+                    int mun = trueMax - trueMin;
+                    if (mun > 0) {
+                        RegularValueDTO regularValueDTO = new RegularValueDTO();
+                        regularValueDTO.setKey(data.getRulesName());
+                        regularValueDTO.setType(data.getRulesTepy()
+                        );
+                        listData.add(regularValueDTO);
+                    }
+                }
+
+
             }
+
+
         }
         return listData;
     }
 
     /**
-     *
      * @param wordCrfDTO
      * @return
      */
     public WordCrfDTO getRegularConfigs(WordCrfDTO wordCrfDTO) {
-        String symptom = wordCrfDTO.getSymptom();
+        String symptom = wordCrfDTO.getSymptom();//现病史
         RegularConfigDataVO regularConfigData = new RegularConfigDataVO();
         regularConfigData.setText(symptom);
         List<RegularValueDTO> regularConfigDatas = getRegularConfigDatas(regularConfigData);
         List<Lis> lisData = wordCrfDTO.getLis();
         PastLabel pastLabel = wordCrfDTO.getPastLabel();//获取过敏史数据
-        List<Allergy> allergies = pastLabel.getAllergies();
+        List<AllergyMedicine> allergies = pastLabel.getAllergyMedicines();
         if (ListUtil.isNotEmpty(regularConfigDatas)) {
             for (RegularValueDTO data : regularConfigDatas) {
                 if (data.getType().equals(RegularConfigEnum.lis.getKey())) {
@@ -84,15 +118,28 @@ public class SysRegularConfigFacade extends SysRegularConfigServiceImpl {
                     lis.setName(data.getKey());
                     lis.setValue(Double.valueOf(data.getValue()));
                     lisData.add(lis);
-                }else if(data.getType().equals(RegularConfigEnum.allergy.getKey())){
-                    Allergy allergy = new Allergy();
+                } else if (data.getType().equals(RegularConfigEnum.allergy.getKey())) {
+                    AllergyMedicine allergy = new AllergyMedicine();
                     allergy.setName(data.getKey());
                     allergy.setStandName(data.getKey());
                     allergies.add(allergy);
                 }
             }
         }
-        pastLabel.setAllergies(allergies);
+        String pasts = wordCrfDTO.getPasts();//既往史
+        RegularConfigDataVO regularConfigPasts = new RegularConfigDataVO();
+        regularConfigData.setText(pasts);
+        regularConfigData.setRulesTepy(RegularConfigEnum.allergy.getKey());
+        List<RegularValueDTO> regularConfigPastss = getRegularConfigDatas(regularConfigData);
+        if (ListUtil.isNotEmpty(regularConfigPastss)) {
+            for(RegularValueDTO dataPasts : regularConfigPastss){
+                AllergyMedicine allergy = new AllergyMedicine();
+                allergy.setName(dataPasts.getKey());
+                allergy.setStandName(dataPasts.getKey());
+                allergies.add(allergy);
+            }
+        }
+        pastLabel.setAllergyMedicines(allergies);
         wordCrfDTO.setPastLabel(pastLabel);
         wordCrfDTO.setLis(lisData);
         return wordCrfDTO;