|
@@ -1,6 +1,7 @@
|
|
|
package org.jeecg.modules.medical.ruleengine;
|
|
package org.jeecg.modules.medical.ruleengine;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -14,6 +15,7 @@ import org.jeecg.modules.medical.entity.MidIncidentAudit;
|
|
|
import org.jeecg.modules.medical.entity.MidIncidentWarningVO;
|
|
import org.jeecg.modules.medical.entity.MidIncidentWarningVO;
|
|
|
import org.jeecg.modules.medical.entity.RuleAttr;
|
|
import org.jeecg.modules.medical.entity.RuleAttr;
|
|
|
import org.jeecg.modules.medical.entity.RuleFactorRela;
|
|
import org.jeecg.modules.medical.entity.RuleFactorRela;
|
|
|
|
|
+import org.jeecg.modules.medical.ruleengine.dict.DictUtil;
|
|
|
import org.jeecg.modules.medical.ruleengine.plugin.InterfItemListPlugin;
|
|
import org.jeecg.modules.medical.ruleengine.plugin.InterfItemListPlugin;
|
|
|
import org.jeecg.modules.medical.service.IEventAttrService;
|
|
import org.jeecg.modules.medical.service.IEventAttrService;
|
|
|
import org.jeecg.modules.medical.service.IFactorAttrRelaService;
|
|
import org.jeecg.modules.medical.service.IFactorAttrRelaService;
|
|
@@ -33,8 +35,10 @@ import javax.annotation.PostConstruct;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -67,9 +71,16 @@ public class RuleEngine {
|
|
|
InterfItemListPlugin interfItemListPlugin;
|
|
InterfItemListPlugin interfItemListPlugin;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
IMidIncidentAuditService midIncidentAuditService;
|
|
IMidIncidentAuditService midIncidentAuditService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ DictUtil dictUtil;
|
|
|
|
|
|
|
|
public static ThreadLocal<MidIncidentWarningVO> midIncidentWarningVOThreadLocal = new ThreadLocal<>();
|
|
public static ThreadLocal<MidIncidentWarningVO> midIncidentWarningVOThreadLocal = new ThreadLocal<>();
|
|
|
|
|
|
|
|
|
|
+ public static Map<String, Set<Integer>> itemCodeAndRuleIdMap = new HashMap<>();
|
|
|
|
|
+ public static Map<String,List<RuleAttr>> interfRuleAttrList = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
public void initMedicalInsRule() {
|
|
public void initMedicalInsRule() {
|
|
|
List<MedicalInsRuleInfo> medicalInsRuleInfoList = medicalInsRuleInfoService.lambdaQuery().eq(MedicalInsRuleInfo::getState, Constant.EFF_STATE).list();
|
|
List<MedicalInsRuleInfo> medicalInsRuleInfoList = medicalInsRuleInfoService.lambdaQuery().eq(MedicalInsRuleInfo::getState, Constant.EFF_STATE).list();
|
|
@@ -95,13 +106,32 @@ public class RuleEngine {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
|
|
+
|
|
|
MemeryPageUtil.batchDeal(medicalInsRuleInfoIdList, 1000, pageDataList -> {
|
|
MemeryPageUtil.batchDeal(medicalInsRuleInfoIdList, 1000, pageDataList -> {
|
|
|
List<MedicalInsRuleProject> medicalInsRuleProjectList = medicalInsRuleProjectService.lambdaQuery().in(MedicalInsRuleProject::getMedicineInsRuleInfoId, pageDataList).list();
|
|
List<MedicalInsRuleProject> medicalInsRuleProjectList = medicalInsRuleProjectService.lambdaQuery().in(MedicalInsRuleProject::getMedicineInsRuleInfoId, pageDataList).list();
|
|
|
if (CollectionUtil.isNotEmpty(medicalInsRuleProjectList)) {
|
|
if (CollectionUtil.isNotEmpty(medicalInsRuleProjectList)) {
|
|
|
MedicalInsRuleProject medicalInsRuleProject = null;
|
|
MedicalInsRuleProject medicalInsRuleProject = null;
|
|
|
for (int index = 0; index < medicalInsRuleProjectList.size(); index++) {
|
|
for (int index = 0; index < medicalInsRuleProjectList.size(); index++) {
|
|
|
medicalInsRuleProject = medicalInsRuleProjectList.get(index);
|
|
medicalInsRuleProject = medicalInsRuleProjectList.get(index);
|
|
|
- setMIDProjectCodeToRedis(medicalInsRuleProject);
|
|
|
|
|
|
|
+ if(StringUtils.isNotBlank(medicalInsRuleProject.getProejctCode())) {
|
|
|
|
|
+ if (itemCodeAndRuleIdMap.containsKey(medicalInsRuleProject.getProejctCode())) {
|
|
|
|
|
+ itemCodeAndRuleIdMap.get(medicalInsRuleProject.getProejctCode()).add(medicalInsRuleProject.getMedicineInsRuleInfoId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Set<Integer> ruleIdSet = new HashSet<>();
|
|
|
|
|
+ ruleIdSet.add(medicalInsRuleProject.getMedicineInsRuleInfoId());
|
|
|
|
|
+ itemCodeAndRuleIdMap.put(medicalInsRuleProject.getProejctCode(), ruleIdSet);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtils.isNotBlank(medicalInsRuleProject.getCorrelationProjectCode())) {
|
|
|
|
|
+ if (itemCodeAndRuleIdMap.containsKey(medicalInsRuleProject.getCorrelationProjectCode())) {
|
|
|
|
|
+ itemCodeAndRuleIdMap.get(medicalInsRuleProject.getCorrelationProjectCode()).add(medicalInsRuleProject.getMedicineInsRuleInfoId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Set<Integer> ruleIdSet = new HashSet<>();
|
|
|
|
|
+ ruleIdSet.add(medicalInsRuleProject.getMedicineInsRuleInfoId());
|
|
|
|
|
+ itemCodeAndRuleIdMap.put(medicalInsRuleProject.getCorrelationProjectCode(), ruleIdSet);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+// setMIDProjectCodeToRedis(medicalInsRuleProject);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -109,6 +139,12 @@ public class RuleEngine {
|
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ List<RuleAttr> ruleAttrList = ruleAttrService.lambdaQuery().list();
|
|
|
|
|
+ interfRuleAttrList = ruleAttrList.stream().collect(Collectors.groupingBy(RuleAttr::getInterfName));
|
|
|
|
|
+// for(Map.Entry<String,List<RuleAttr>> map : interfRuleAttrList.entrySet()){
|
|
|
|
|
+// redisTemplate.opsForValue().append(map.getKey(), JSON.toJSONString(map.getValue()));
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -126,6 +162,7 @@ public class RuleEngine {
|
|
|
|
|
|
|
|
public Integer getMIDMedicalId(String itemCode) {
|
|
public Integer getMIDMedicalId(String itemCode) {
|
|
|
Object medicineInsRuleId = redisTemplate.opsForHash().get(Constant.MEDICAL_RULE_CACHE_KEY, itemCode);
|
|
Object medicineInsRuleId = redisTemplate.opsForHash().get(Constant.MEDICAL_RULE_CACHE_KEY, itemCode);
|
|
|
|
|
+// redisTemplate.opsForSet().add(Constant.MEDICAL_RULE_CACHE_KEY)
|
|
|
if (null != medicineInsRuleId) {
|
|
if (null != medicineInsRuleId) {
|
|
|
return (Integer) medicineInsRuleId;
|
|
return (Integer) medicineInsRuleId;
|
|
|
}
|
|
}
|
|
@@ -135,12 +172,18 @@ public class RuleEngine {
|
|
|
public Result dealMidInterfaceEngin(String intefName, Map<String, Object> paramMap, MidIncidentWarningVO midIncidentWarningVO) {
|
|
public Result dealMidInterfaceEngin(String intefName, Map<String, Object> paramMap, MidIncidentWarningVO midIncidentWarningVO) {
|
|
|
midIncidentWarningVOThreadLocal.set(midIncidentWarningVO);
|
|
midIncidentWarningVOThreadLocal.set(midIncidentWarningVO);
|
|
|
try {
|
|
try {
|
|
|
- List<RuleAttr> ruleAttrList = ruleAttrService.lambdaQuery().eq(RuleAttr::getInterfName, intefName).list();
|
|
|
|
|
- List<Integer> medicalInsRuleInfoIdList = getMedicalInsRuleInfoIdByIntef(intefName, paramMap, ruleAttrList);
|
|
|
|
|
|
|
+ List<RuleAttr> ruleAttrList = interfRuleAttrList.get(intefName);
|
|
|
|
|
+ if(null == ruleAttrList){
|
|
|
|
|
+ return Result.error("接口:"+intefName+" 未配置 对应的规则属性");
|
|
|
|
|
+ }
|
|
|
List<Map<String, Object>> itemList = interfItemListPlugin.findProIntersection(paramMap, ruleAttrList);
|
|
List<Map<String, Object>> itemList = interfItemListPlugin.findProIntersection(paramMap, ruleAttrList);
|
|
|
|
|
|
|
|
|
|
+ MidIncidentAudit midIncidentAudit = insertMidWarning(midIncidentWarningVO);
|
|
|
|
|
+ midIncidentAudit.setInterfName(intefName);
|
|
|
for (Map<String, Object> itemMap : itemList) {
|
|
for (Map<String, Object> itemMap : itemList) {
|
|
|
- runEngine(itemMap, medicalInsRuleInfoIdList);
|
|
|
|
|
|
|
+ dictUtil.transferItemMap(itemMap);
|
|
|
|
|
+ Set<Integer> medicalInsRuleInfoIdList = itemCodeAndRuleIdMap.get(itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY));
|
|
|
|
|
+ runEngine(itemMap, medicalInsRuleInfoIdList,midIncidentAudit);
|
|
|
}
|
|
}
|
|
|
}finally {
|
|
}finally {
|
|
|
midIncidentWarningVOThreadLocal.remove();
|
|
midIncidentWarningVOThreadLocal.remove();
|
|
@@ -149,8 +192,7 @@ public class RuleEngine {
|
|
|
return Result.ok();
|
|
return Result.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void insertMidWarning(){
|
|
|
|
|
- MidIncidentWarningVO midIncidentWarningVO = RuleEngine.midIncidentWarningVOThreadLocal.get();
|
|
|
|
|
|
|
+ public MidIncidentAudit insertMidWarning(MidIncidentWarningVO midIncidentWarningVO){
|
|
|
MidIncidentAudit midIncidentAudit = new MidIncidentAudit();
|
|
MidIncidentAudit midIncidentAudit = new MidIncidentAudit();
|
|
|
midIncidentAudit.setMedicalDeptCode(midIncidentWarningVO.getMedical_dept_code());
|
|
midIncidentAudit.setMedicalDeptCode(midIncidentWarningVO.getMedical_dept_code());
|
|
|
midIncidentAudit.setMedicalDeptName(midIncidentWarningVO.getMedical_dept_name());
|
|
midIncidentAudit.setMedicalDeptName(midIncidentWarningVO.getMedical_dept_name());
|
|
@@ -164,12 +206,13 @@ public class RuleEngine {
|
|
|
midIncidentAudit.setPrescriptionNumber(midIncidentWarningVO.getDoctor_advice_no());
|
|
midIncidentAudit.setPrescriptionNumber(midIncidentWarningVO.getDoctor_advice_no());
|
|
|
midIncidentAudit.setNoticeType("事中预警");
|
|
midIncidentAudit.setNoticeType("事中预警");
|
|
|
midIncidentAuditService.save(midIncidentAudit);
|
|
midIncidentAuditService.save(midIncidentAudit);
|
|
|
|
|
+ return midIncidentAudit;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public List<Integer> getMedicalInsRuleInfoIdByIntef(String intefName, Map<String, Object> paramMap, List<RuleAttr> ruleAttrList) {
|
|
public List<Integer> getMedicalInsRuleInfoIdByIntef(String intefName, Map<String, Object> paramMap, List<RuleAttr> ruleAttrList) {
|
|
|
|
|
|
|
|
List<Integer> medicalIdList = new ArrayList<>();
|
|
List<Integer> medicalIdList = new ArrayList<>();
|
|
|
-
|
|
|
|
|
|
|
+ Map<String,List<Integer>> itemCodeAndRuleIdMap = new HashMap<>();
|
|
|
for (RuleAttr ruleAttr : ruleAttrList) {
|
|
for (RuleAttr ruleAttr : ruleAttrList) {
|
|
|
String itemCode = null;
|
|
String itemCode = null;
|
|
|
if (StringUtils.isNotBlank(ruleAttr.getAttrPath())) {
|
|
if (StringUtils.isNotBlank(ruleAttr.getAttrPath())) {
|
|
@@ -223,7 +266,7 @@ public class RuleEngine {
|
|
|
*
|
|
*
|
|
|
* @param paramMap
|
|
* @param paramMap
|
|
|
*/
|
|
*/
|
|
|
- public void runEngine(Map<String, Object> paramMap, List<Integer> medicalInsRuleInfoIdList) {
|
|
|
|
|
|
|
+ public void runEngine(Map<String, Object> paramMap, Set<Integer> medicalInsRuleInfoIdList,MidIncidentAudit midIncidentAudit) {
|
|
|
LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
|
|
LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
|
|
|
query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
|
|
query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
|
|
|
query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
|
|
query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
|
|
@@ -240,7 +283,7 @@ public class RuleEngine {
|
|
|
MedicalInsRuleInfo medicalInsRuleInfo = medicalInsRuleInfoService.getById(medicalRuleInsInfoId);
|
|
MedicalInsRuleInfo medicalInsRuleInfo = medicalInsRuleInfoService.getById(medicalRuleInsInfoId);
|
|
|
List<FactorEnchance> factorEnchanceListTemp = enchanceTypeMap.get(medicalRuleInsInfoId);
|
|
List<FactorEnchance> factorEnchanceListTemp = enchanceTypeMap.get(medicalRuleInsInfoId);
|
|
|
|
|
|
|
|
- factorEnchangeFactory.runFactorEnchange(medicalRuleInsInfoId, medicalInsRuleInfo, paramMap, factorEnchangeIdList, factorEnchanceListTemp);
|
|
|
|
|
|
|
+ factorEnchangeFactory.runFactorEnchange(medicalRuleInsInfoId, medicalInsRuleInfo, midIncidentAudit, paramMap, factorEnchangeIdList, factorEnchanceListTemp);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|