|
@@ -144,7 +144,7 @@ public class RuleEngine {
|
|
|
public static Map<String, Set<Integer>> itemCodeAndRuleIdMap = new HashMap<>();
|
|
|
public static Map<Integer, List<RuleFactorRela>> ruleIdAndFatorEnchanceIdMap = new HashMap<>();
|
|
|
public static Map<Integer, List<FactorEnchance>> allEnchanceTypeMap = new HashMap<>();
|
|
|
-
|
|
|
+ public static Map<Integer, MedicalInsRuleInfo> allMedicalMap = new HashMap<>();
|
|
|
|
|
|
public void initMedicalInsRule() {
|
|
|
log.info("进入初始化RuleEngine");
|
|
@@ -158,9 +158,8 @@ public class RuleEngine {
|
|
|
* 后续提醒通过redis加载id,把id传入规则引擎,迅速调用对应规则
|
|
|
*/
|
|
|
List<MedicalInsRuleInfo> midMedicalInsRuleInfoList = new ArrayList<>();
|
|
|
- Map<Integer, MedicalInsRuleInfo> medicalMap = new HashMap<>();
|
|
|
for (MedicalInsRuleInfo medicalInsRuleInfo : medicalInsRuleInfoList) {
|
|
|
- medicalMap.put(medicalInsRuleInfo.getId(), medicalInsRuleInfo);
|
|
|
+ allMedicalMap.put(medicalInsRuleInfo.getId(), medicalInsRuleInfo);
|
|
|
if (Constant.TREATMEN_TYPE_ADVANCE_WARNING.equals(medicalInsRuleInfo.getCallScenario())) {
|
|
|
advanceWaringRuleIdList.add(medicalInsRuleInfo.getId());
|
|
|
} else {
|
|
@@ -172,6 +171,7 @@ public class RuleEngine {
|
|
|
List<RuleAttr> ruleAttrList = ruleAttrService.list();
|
|
|
interfRuleAttrList = ruleAttrList.stream().collect(Collectors.groupingBy(RuleAttr::getInterfName));
|
|
|
initFactor();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@PostConstruct
|
|
@@ -643,31 +643,69 @@ public class RuleEngine {
|
|
|
|
|
|
Set<String> auditDetailSet = new HashSet<>();
|
|
|
Set<Integer> medicalInsRuleInfoIdList = itemCodeAndRuleIdMap.get(itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY));
|
|
|
+ List<MedicalInsRuleProject> medicalInsRuleProjectList = null;
|
|
|
if (CollectionUtil.isEmpty(medicalInsRuleInfoIdList)) {
|
|
|
log.error("项目编码未匹配到对应的医保规则:{} 再次从数据库检索", itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY));
|
|
|
- List<MedicalInsRuleProject> medicalInsRuleProjectList = medicalInsRuleProjectService.getRuleProjectByMedicalProjectCode(itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY).toString());
|
|
|
+ medicalInsRuleProjectList = medicalInsRuleProjectService.getRuleProjectByMedicalProjectCode(itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY).toString());
|
|
|
if(CollectionUtil.isEmpty(medicalInsRuleProjectList)){
|
|
|
log.error("项目编码未匹配到对应的医保规则:{} 在规则库数据库中未检索到数据,退出规则执行", itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY));
|
|
|
return;
|
|
|
}
|
|
|
medicalInsRuleInfoIdList = medicalInsRuleProjectList.stream().map(MedicalInsRuleProject::getMedicalInsRuleInfoId).collect(Collectors.toSet());
|
|
|
log.info("数据库检索到匹配规则ID列表:{}", medicalInsRuleInfoIdList);
|
|
|
+ }else{
|
|
|
+ medicalInsRuleProjectList = medicalInsRuleProjectService.getRuleProjectByRuleIdAndProjectCode(new ArrayList<>(medicalInsRuleInfoIdList), itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY).toString());
|
|
|
}
|
|
|
Object diagnose = itemMap.get(Constant.MEDICAL_DIAGNOSE_CODE_KEY);
|
|
|
if (null != diagnose) {
|
|
|
//获取诊断编码配置的规则ID,加入需要执行的规则
|
|
|
Set<Integer> diagnoseMedicalInsRuleInfoIdList = itemCodeAndRuleIdMap.get(diagnose.toString());
|
|
|
+ List<MedicalInsRuleProject> medicalInsRuleProjectTempList = null;
|
|
|
if (CollectionUtil.isNotEmpty(diagnoseMedicalInsRuleInfoIdList)) {
|
|
|
- medicalInsRuleInfoIdList.addAll(diagnoseMedicalInsRuleInfoIdList);
|
|
|
+ medicalInsRuleProjectTempList = medicalInsRuleProjectService.getRuleProjectByDiagCode(diagnose.toString());
|
|
|
+ if(CollectionUtil.isEmpty(medicalInsRuleProjectTempList)){
|
|
|
+ log.info("诊断编码未匹配到对应的医保规则:{} 在规则库数据库中未检索到数据,退出规则执行", diagnose);
|
|
|
+ }
|
|
|
+ Set<Integer> medicalInsRuleInfoIdDiagSet = medicalInsRuleProjectList.stream().map(MedicalInsRuleProject::getMedicalInsRuleInfoId).collect(Collectors.toSet());
|
|
|
+ log.info("数据库检索到匹配规则ID列表:{} 诊断编码为:{}", medicalInsRuleInfoIdDiagSet, diagnose);
|
|
|
+ }else{
|
|
|
+ medicalInsRuleProjectTempList = medicalInsRuleProjectService.getRuleProjectByRuleIdAndDiagCode(new ArrayList<>(medicalInsRuleInfoIdList), diagnose.toString());
|
|
|
}
|
|
|
+ if(CollectionUtil.isNotEmpty(medicalInsRuleProjectTempList)){
|
|
|
+ if(CollectionUtil.isNotEmpty(medicalInsRuleProjectList)){
|
|
|
+ medicalInsRuleProjectList.addAll(medicalInsRuleProjectTempList);
|
|
|
+ }else {
|
|
|
+ medicalInsRuleProjectList = medicalInsRuleProjectTempList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isEmpty(medicalInsRuleProjectList)){
|
|
|
+ log.error("医保规则对象被误删,请联系管理员");
|
|
|
+ return;
|
|
|
}
|
|
|
- runAfterEngine(auditDetailSet, itemMap, medicalInsRuleInfoIdList, afterwardsAudit, itemList);
|
|
|
+ for(MedicalInsRuleProject medicalInsRuleProject : medicalInsRuleProjectList) {
|
|
|
+ setProjectToLocalMap(itemMap, medicalInsRuleProject);
|
|
|
+ runAfterEngine(itemMap, medicalInsRuleProject.getMedicalInsRuleInfoId(), afterwardsAudit, itemList);
|
|
|
+ }
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param itemMap
|
|
|
+ * @param medicalInsRuleProject
|
|
|
+ */
|
|
|
+ public void setProjectToLocalMap(Map<String,Object> itemMap, MedicalInsRuleProject medicalInsRuleProject){
|
|
|
+ String jsonStr = JSON.toJSONString(medicalInsRuleProject);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
|
|
+ Map<String,Object> transferMedicalMap = filterMap(jsonObject);
|
|
|
+ itemMap.putAll(transferMedicalMap);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void insertLog(MidIncidentWarningVO midIncidentWarningVO) {
|
|
|
MidIncidentVisitLog midIncidentVisitLog = new MidIncidentVisitLog();
|
|
@@ -915,7 +953,6 @@ public class RuleEngine {
|
|
|
List<FactorEnchance> factorEnchanceList = factorEnchanceService.listByIds(factorEnchangeIdList);
|
|
|
Map<Integer, List<FactorEnchance>> enchanceTypeMap = factorEnchanceList.stream().collect(Collectors.groupingBy(FactorEnchance::getFactorCatalog));
|
|
|
for (Integer medicalRuleInsInfoId : enchanceTypeMap.keySet()) {
|
|
|
-
|
|
|
List<FactorEnchance> factorEnchanceListTemp = enchanceTypeMap.get(medicalRuleInsInfoId);
|
|
|
paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_ID, medicalRuleInsInfoId);
|
|
|
paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_CODE, medicalInsRuleInfo.getRuleCode());
|
|
@@ -967,46 +1004,27 @@ public class RuleEngine {
|
|
|
*
|
|
|
* @param paramMap
|
|
|
*/
|
|
|
- public void runAfterEngine(Set<String> auditDetailSet, Map<String, Object> paramMap, Set<Integer> medicalInsRuleInfoIdList, AfterwardsAudit afterIncidentAudit, List<Map<String, Object>> itemList) {
|
|
|
- if (CollectionUtil.isEmpty(medicalInsRuleInfoIdList)) {
|
|
|
+ public void runAfterEngine(Map<String, Object> paramMap, Integer medicalRuleInsInfoId, AfterwardsAudit afterIncidentAudit, List<Map<String, Object>> itemList) {
|
|
|
+ if (null == medicalRuleInsInfoId) {
|
|
|
log.error("未有对应的规则,接口数据:{}", paramMap);
|
|
|
return;
|
|
|
}
|
|
|
-// LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
|
|
|
-// query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
|
|
|
-// query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
|
|
|
-// query.orderByAsc(RuleFactorRela::getSeqNum);
|
|
|
-// List<RuleFactorRela> ruleFactorRelaList = ruleFactorRelaService.list(query);
|
|
|
- Map<Integer, List<FactorEnchance>> enchanceTypeMap = new HashMap<>();
|
|
|
- for(Integer medicalRuleINfoId : medicalInsRuleInfoIdList){
|
|
|
- enchanceTypeMap.put(medicalRuleINfoId, allEnchanceTypeMap.get(medicalRuleINfoId));
|
|
|
- }
|
|
|
- if (CollectionUtil.isNotEmpty(enchanceTypeMap)) {
|
|
|
-// Map<Integer, List<RuleFactorRela>> ruleIdAndFatorEnchanceIdMap = ruleFactorRelaList.stream().collect(Collectors.groupingBy(RuleFactorRela::getMedicalInsRuleInfoId));
|
|
|
-// Set<Integer> factorEnchangeIdList = ruleFactorRelaList.stream().map(RuleFactorRela::getFactorEnhanceId).collect(Collectors.toSet());
|
|
|
-// List<FactorEnchance> factorEnchanceList = factorEnchanceService.listByIds(factorEnchangeIdList);
|
|
|
-// Map<Integer, List<FactorEnchance>> enchanceTypeMap = factorEnchanceList.stream().collect(Collectors.groupingBy(FactorEnchance::getFactorCatalog));
|
|
|
- for (Integer medicalRuleInsInfoId : enchanceTypeMap.keySet()) {
|
|
|
- String auditDetailKeyStr = paramMap.get(Constant.MEDICAL_PROJECT_NAME_KEY) + "_" + medicalRuleInsInfoId;
|
|
|
- if (auditDetailSet.contains(auditDetailKeyStr)) {
|
|
|
- log.error("项目编码:{} 规则ID:{} 已经执行过规则引擎,此次忽略", paramMap.get(Constant.MEDICAL_PROJECT_NAME_KEY), medicalRuleInsInfoId);
|
|
|
- continue;
|
|
|
- }
|
|
|
- auditDetailSet.add(auditDetailKeyStr);
|
|
|
- MedicalInsRuleInfo medicalInsRuleInfo = medicalInsRuleInfoService.getById(medicalRuleInsInfoId);
|
|
|
- List<FactorEnchance> factorEnchanceListTemp = enchanceTypeMap.get(medicalRuleInsInfoId);
|
|
|
- paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_ID, medicalRuleInsInfoId);
|
|
|
- paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_CODE, medicalInsRuleInfo.getRuleCode());
|
|
|
- paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_NAME, medicalInsRuleInfo.getRuleName());
|
|
|
- List<RuleFactorRela> ruleFactorRelaSortList = ruleIdAndFatorEnchanceIdMap.get(medicalRuleInsInfoId);
|
|
|
- getRuleProjectIntoMap(medicalInsRuleInfo, paramMap);
|
|
|
- paramMap.put(SystemEventAttrConstant.ADVICE_DETAILS_LIST_KEY, itemList);
|
|
|
- boolean auditFlag = factorEnchangeFactory.runFactorEnchange(medicalRuleInsInfoId, medicalInsRuleInfo, afterIncidentAudit, paramMap, ruleFactorRelaSortList, factorEnchanceListTemp, itemList);
|
|
|
- if (Constant.VALIDATION_HANDER_METHOD_RETURN.equals(medicalInsRuleInfo.getViolationHandingMethod()) && auditFlag) {
|
|
|
- log.error("事后提醒数据:{} 规则名:{} 触发诊断类规则,直接全金额,后续规则无需再跑", paramMap, medicalInsRuleInfo);
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (allEnchanceTypeMap.containsKey(medicalRuleInsInfoId)) {
|
|
|
+ MedicalInsRuleInfo medicalInsRuleInfo = allMedicalMap.get(medicalRuleInsInfoId);
|
|
|
+ List<FactorEnchance> factorEnchanceListTemp = allEnchanceTypeMap.get(medicalRuleInsInfoId);
|
|
|
+ paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_ID, medicalRuleInsInfoId);
|
|
|
+ paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_CODE, medicalInsRuleInfo.getRuleCode());
|
|
|
+ paramMap.put(SystemEventAttrConstant.MEDICAL_INS_RULE_INFO_NAME, medicalInsRuleInfo.getRuleName());
|
|
|
+ List<RuleFactorRela> ruleFactorRelaSortList = ruleIdAndFatorEnchanceIdMap.get(medicalRuleInsInfoId);
|
|
|
+ getRuleProjectIntoMap(medicalInsRuleInfo, paramMap);
|
|
|
+ paramMap.put(SystemEventAttrConstant.ADVICE_DETAILS_LIST_KEY, itemList);
|
|
|
+ boolean auditFlag = factorEnchangeFactory.runFactorEnchange(medicalRuleInsInfoId, medicalInsRuleInfo, afterIncidentAudit, paramMap, ruleFactorRelaSortList, factorEnchanceListTemp, itemList);
|
|
|
+ if (Constant.VALIDATION_HANDER_METHOD_RETURN.equals(medicalInsRuleInfo.getViolationHandingMethod()) && auditFlag) {
|
|
|
+ log.error("事后提醒数据:{} 规则名:{} 触发诊断类规则,直接全金额,后续规则无需再跑", paramMap, medicalInsRuleInfo);
|
|
|
+ return;
|
|
|
}
|
|
|
+ }else{
|
|
|
+ log.error("该医保规则ID:{} 未有配置医保规则处理流程-请到规则配置页面进行配置", medicalRuleInsInfoId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1067,53 +1085,42 @@ public class RuleEngine {
|
|
|
boolean correlationDiagnoseFlag = Arrays.stream(selectedRolesArr).anyMatch(attr -> attr.equals("correlationMedicalDiagnoseCode"));
|
|
|
boolean projectCodeFlag = Arrays.stream(selectedRolesArr).anyMatch(attr -> attr.equals("projectCode"));
|
|
|
String projectCode = null;
|
|
|
- if (projectCodeFlag && null != itemMap.get(Constant.PROJECT_CODE_KEY)) {
|
|
|
- projectCode = itemMap.get(Constant.PROJECT_CODE_KEY).toString();
|
|
|
- } else {
|
|
|
- return;
|
|
|
+ if (projectCodeFlag && null != itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY)) {
|
|
|
+ projectCode = itemMap.get(Constant.MEDICAL_PROJECT_CODE_KEY).toString();
|
|
|
}
|
|
|
- List<MedicalInsRuleProject> medicalInsRuleProjectList = medicalInsRuleProjectService.lambdaQuery().eq(MedicalInsRuleProject::getMedicalInsRuleInfoId, medicalInsRuleInfo.getId())
|
|
|
- .eq(projectCodeFlag, MedicalInsRuleProject::getProjectCode, projectCode).eq(MedicalInsRuleProject::getState, Constant.EFF_STATE).list();
|
|
|
- List<String> correlationProjectCodeList = new ArrayList<>();
|
|
|
- String collectionProjectCode = null;
|
|
|
- if (CollectionUtil.isNotEmpty(medicalInsRuleProjectList)) {
|
|
|
- if (medicalInsRuleProjectList.size() == 1) {
|
|
|
- String jsonStr = JSON.toJSONString(medicalInsRuleProjectList.get(0));
|
|
|
- collectionProjectCode = medicalInsRuleProjectList.get(0).getCorrelationProjectCode();
|
|
|
- JSONObject ruleProjectJSONObject = JSON.parseObject(jsonStr);
|
|
|
- Map<String, Object> filterMap = filterMap(ruleProjectJSONObject);
|
|
|
- itemMap.putAll(filterMap);
|
|
|
- } else {
|
|
|
- correlationProjectCodeList = medicalInsRuleProjectList.stream().map(MedicalInsRuleProject::getProjectCode).collect(Collectors.toList());
|
|
|
- itemMap.put(SystemEventAttrConstant.MEDICAL_INS_CORRELATIONPROJECTCODELIST, correlationProjectCodeList);
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
if (diagnoseFlag) {
|
|
|
List<MedicalInsRuleProjectDiagnose> medicalInsRuleProjectDiagnoseList = null;
|
|
|
boolean conditionFlag = false;
|
|
|
if (StringUtils.isNotBlank(projectCode)) {
|
|
|
conditionFlag = true;
|
|
|
}
|
|
|
- medicalInsRuleProjectDiagnoseList = medicalInsRuleProjectDiagnoseService.lambdaQuery().eq(conditionFlag, MedicalInsRuleProjectDiagnose::getMedicalInsProjectCode, projectCode).eq(MedicalInsRuleProjectDiagnose::getMedicalInsRuleInfoId, medicalInsRuleInfo.getId())
|
|
|
- .eq(MedicalInsRuleProjectDiagnose::getProjectCodeType, 1).list();
|
|
|
+ medicalInsRuleProjectDiagnoseList = medicalInsRuleProjectDiagnoseService.lambdaQuery().eq(MedicalInsRuleProjectDiagnose::getMedicalInsRuleInfoId, medicalInsRuleInfo.getId())
|
|
|
+ .eq(MedicalInsRuleProjectDiagnose::getProjectCodeType, 1).last(conditionFlag, " and INSTR('"+projectCode+"', medical_ins_project_code)").list();
|
|
|
if (CollectionUtil.isNotEmpty(medicalInsRuleProjectDiagnoseList)) {
|
|
|
List<String> medicalDiagnoseStrList = medicalInsRuleProjectDiagnoseList.stream().map(MedicalInsRuleProjectDiagnose::getMedicalDiagnoseCode).collect(Collectors.toList());
|
|
|
itemMap.put(SystemEventAttrConstant.MEDICAL_INS_MEDICALDIAGNOSECODELIST, medicalDiagnoseStrList);
|
|
|
+ }else{
|
|
|
+ log.error("配置了诊断编码规则属性,但是具体规则参数未配置,请管理员尽快配置 医保规则:{}", medicalInsRuleInfo);
|
|
|
+ itemMap.put(SystemEventAttrConstant.MEDICAL_INS_MEDICALDIAGNOSECODELIST, new ArrayList<>());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (correlationDiagnoseFlag) {
|
|
|
List<MedicalInsRuleProjectDiagnose> medicalInsRuleProjectDiagnoseList = null;
|
|
|
boolean conditionFlag = false;
|
|
|
+ String collectionProjectCode = itemMap.getOrDefault(SystemEventAttrConstant.MEDICAL_INS_CORRELATIONMEDICALDIAGNOSECODE,"").toString();
|
|
|
if (StringUtils.isNotBlank(collectionProjectCode)) {
|
|
|
conditionFlag = true;
|
|
|
}
|
|
|
- medicalInsRuleProjectDiagnoseList = medicalInsRuleProjectDiagnoseService.lambdaQuery().eq(conditionFlag, MedicalInsRuleProjectDiagnose::getMedicalInsProjectCode, collectionProjectCode).eq(MedicalInsRuleProjectDiagnose::getMedicalInsRuleInfoId, medicalInsRuleInfo.getId())
|
|
|
- .eq(MedicalInsRuleProjectDiagnose::getProjectCodeType, 2).list();
|
|
|
+ medicalInsRuleProjectDiagnoseList = medicalInsRuleProjectDiagnoseService.lambdaQuery().eq(MedicalInsRuleProjectDiagnose::getMedicalInsRuleInfoId, medicalInsRuleInfo.getId())
|
|
|
+ .eq(MedicalInsRuleProjectDiagnose::getProjectCodeType, 2).last(conditionFlag, " and INSTR('"+projectCode+"', medical_ins_project_code)").list();
|
|
|
if (CollectionUtil.isNotEmpty(medicalInsRuleProjectDiagnoseList)) {
|
|
|
List<String> medicalDiagnoseStrList = medicalInsRuleProjectDiagnoseList.stream().map(MedicalInsRuleProjectDiagnose::getMedicalDiagnoseCode).collect(Collectors.toList());
|
|
|
itemMap.put(SystemEventAttrConstant.MEDICAL_INS_CORRELATIONMEDICALDIAGNOSECODE, medicalDiagnoseStrList);
|
|
|
+ }else{
|
|
|
+ log.error("配置了关联诊断编码规则属性,但是具体规则参数未配置,请管理员尽快配置 医保规则:{}", medicalInsRuleInfo);
|
|
|
+ itemMap.put(SystemEventAttrConstant.MEDICAL_INS_CORRELATIONMEDICALDIAGNOSECODE, new ArrayList<>());
|
|
|
}
|
|
|
}
|
|
|
|