소스 검색

过敏原

zhoutg 3 년 전
부모
커밋
8af3cb00cb
3개의 변경된 파일150개의 추가작업 그리고 2개의 파일을 삭제
  1. 13 0
      src/main/java/com/diagbot/facade/BillFacade.java
  2. 74 0
      src/main/java/com/diagbot/rule/OtherRule.java
  3. 63 2
      src/main/java/com/diagbot/util/RedisUtil.java

+ 13 - 0
src/main/java/com/diagbot/facade/BillFacade.java

@@ -9,6 +9,9 @@ import com.diagbot.enums.LexiconEnum;
 import com.diagbot.enums.RuleTypeEnum;
 import com.diagbot.enums.TypeEnum;
 import com.diagbot.process.BillProcess;
+import com.diagbot.rule.DrugRule;
+import com.diagbot.rule.OtherRule;
+import com.diagbot.util.MsgNewUtil;
 import com.diagbot.util.RedisUtil;
 import com.diagbot.util.StringUtil;
 import com.diagbot.vo.Drug;
@@ -36,6 +39,12 @@ public class BillFacade {
     CommonFacade commonFacade;
     @Autowired
     RedisUtil redisUtil;
+    @Autowired
+    DrugRule drugRule;
+    @Autowired
+    MsgNewUtil msgNewUtil;
+    @Autowired
+    OtherRule otherRule;
 
     /**
      * 开单合理性业务
@@ -48,10 +57,14 @@ public class BillFacade {
         List<RuleVO> ruleVOList = getRuleVO(wordCrfDTO);
         billProcess.processRule(ruleVOList, wordCrfDTO, res);
 
+        // 【特殊规则】过敏原自身过敏
+        otherRule.allergy(wordCrfDTO, res);
+
         // 结果去重处理
         commonFacade.dealMsg(res.getBillMsgList());
     }
 
+
     /**
      * 获取开单项入参
      *

+ 74 - 0
src/main/java/com/diagbot/rule/OtherRule.java

@@ -0,0 +1,74 @@
+package com.diagbot.rule;
+
+import com.diagbot.dto.BillMsg;
+import com.diagbot.dto.IndicationDTO;
+import com.diagbot.dto.RuleSimpleDTO;
+import com.diagbot.dto.WordCrfDTO;
+import com.diagbot.enums.ConEnum;
+import com.diagbot.enums.RedisEnum;
+import com.diagbot.enums.TypeEnum;
+import com.diagbot.model.entity.AllergyMedicine;
+import com.diagbot.model.entity.Negative;
+import com.diagbot.model.label.PastLabel;
+import com.diagbot.util.CoreUtil;
+import com.diagbot.util.ListUtil;
+import com.diagbot.util.MsgNewUtil;
+import com.diagbot.util.RedisUtil;
+import com.diagbot.util.StringUtil;
+import com.diagbot.vo.Drug;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @description: 其他特殊规则
+ * @author: zhoutg
+ * @time: 2020/8/3 14:47
+ */
+@Component
+public class OtherRule {
+
+    @Autowired
+    MsgNewUtil msgNewUtil;
+    @Autowired
+    RedisUtil redisUtil;
+
+    /**
+     * 过敏原自身过敏,如果规则已存在,就不再比较;如果不存在,比较是否与自身过敏
+     *
+     * @param
+     * @return
+     */
+    public void allergy(WordCrfDTO wordCrfDTO, IndicationDTO res) {
+        // 药物过敏源
+        PastLabel pastLabel = wordCrfDTO.getPastLabel();
+        List<AllergyMedicine> allergyMedicines = pastLabel.getAllergyMedicines();
+        if (ListUtil.isEmpty(wordCrfDTO.getDrugOrder()) || ListUtil.isEmpty(allergyMedicines)) {
+            return;
+        }
+        // 获取已维护的自身过敏规则,如果包含standName就不用再比较
+        Map<String, Integer> allergyMap = redisUtil.get(RedisEnum.drugAllergen.getName());
+        for (Drug drug : wordCrfDTO.getDrugOrder()) {
+            for (AllergyMedicine allergy : allergyMedicines) {
+                String name = allergy.getName();
+                String standName = allergy.getStandName();
+                Negative negative = allergy.getNegative(); // null表示阳性
+                if (allergyMap == null || !allergyMap.containsKey(standName)) {
+                    // 执行到这里说明自身过敏的规则没有维护
+                    if (negative == null && StringUtil.isNotBlank(drug.getUniqueName()) && drug.getUniqueName().equals(standName)) {
+                        RuleSimpleDTO ruleSimpleDTO = new RuleSimpleDTO();
+                        ruleSimpleDTO.setInputName(drug.getName());
+                        ruleSimpleDTO.setLibName(drug.getUniqueName());
+                        ruleSimpleDTO.setLibTypeName(TypeEnum.drug.getName());
+                        ruleSimpleDTO.setContent(name);
+                        ruleSimpleDTO.setConType(ConEnum.allergicmeds.getName());
+                        BillMsg billMsg = msgNewUtil.getCommonBillMsg(ruleSimpleDTO);
+                        CoreUtil.addBeanToList(res.getBillMsgList(), billMsg);
+                    }
+                }
+            }
+        }
+    }
+
+}

+ 63 - 2
src/main/java/com/diagbot/util/RedisUtil.java

@@ -11,8 +11,10 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.SessionCallback;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -90,7 +92,66 @@ public class RedisUtil {
      * @return
      */
     public <T> void multiSet(Map<String, T> map) {
-        redisTemplate.opsForValue().multiSet(map);
+        putHashMap("ffff", map);
+        Map<String, T> sonMap = new LinkedHashMap<>();
+        int j = 1;
+        for (String key : map.keySet()) {
+            sonMap.put(key, map.get(key));
+            if (j / 5000 > 0 && j % 5000 == 0) {
+                redisTemplate.opsForValue().multiSet(sonMap);
+                System.out.println("添加redis");
+                sonMap.clear();
+            }
+            j++;
+        }
+        // System.out.println(map.size());
+        // int threadNum = 1; // 推荐的总线程数 = cpu个数 * 每个cpu的核数
+        // List<Map<String, T>> threadData = divideByCopies(map, threadNum);
+        // int sum = 0;
+        // for (Map<String, T> map1 : threadData) {
+        //     sum += map1.size();
+        // }
+        // System.out.println(sum == map.size());
+        //
+        // List<Future<Boolean>> list = new ArrayList<>();
+        // ExecutorService executor = Executors.newFixedThreadPool(threadNum);
+        // for (int i = 0; i < threadNum; i++) {
+        //     final int index = i; // 这一行代码很重要,如果使用成员变量,下面会报错
+        //     Future<Boolean> future = executor.submit(new Callable<Boolean>() {
+        //         @Override
+        //         public Boolean call() {
+        //             Map<String, T> data = threadData.get(index);
+        //             redisTemplate.opsForValue().multiSet(data);
+        //             return true;
+        //         }
+        //     });
+        //     list.add(future);
+        // }
+        //
+        // // 拼接返回数据
+        // System.out.println(list.size());
+        // for (int i = 0; i < list.size(); i++) {
+        //     Future<Boolean> future = list.get(i);
+        //     while (!future.isDone()) {
+        //         ; // 这一行代码很重要
+        //     }
+        // }
+        System.out.println("添加完毕");
+    }
+
+    public <T> List<Map<String, T>> divideByCopies(Map<String, T> originList, int num) {
+        List<Map<String, T>> list = new ArrayList<>();
+        if (originList == null || originList.isEmpty() || num < 0) {
+            return null;
+        }
+        for (int i = 0; i < num; i++) {
+            list.add(new LinkedHashMap<>());
+        }
+        int j  = 0;
+        for (String key : originList.keySet()) {
+            list.get(j % num).put(key, originList.get(key));
+        }
+        return list;
     }
 
     /**
@@ -294,7 +355,7 @@ public class RedisUtil {
      * @param key
      * @param map
      */
-    public void putHashMap(String key, Map<String, Object> map) {
+    public <T> void putHashMap(String key, Map<String, T> map) {
         if (MapUtils.isNotEmpty(map)) {
             redisTemplate.opsForHash().putAll(key, map);
         }