Search in sources :

Example 1 with RuleActionBean

use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.

the class RuleSetRuleBean method getAllActionsWithEvaluatesToAsKey.

@Transient
public HashMap<String, ArrayList<RuleActionBean>> getAllActionsWithEvaluatesToAsKey() {
    HashMap<String, ArrayList<RuleActionBean>> h = new HashMap<String, ArrayList<RuleActionBean>>();
    for (RuleActionBean action : actions) {
        String key = action.getExpressionEvaluatesTo().toString();
        if (h.containsKey(key)) {
            h.get(key).add(action);
        } else {
            ArrayList<RuleActionBean> a = new ArrayList<RuleActionBean>();
            a.add(action);
            h.put(key, a);
        }
    }
    return h;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Transient(javax.persistence.Transient)

Example 2 with RuleActionBean

use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.

the class RuleSetRuleBean method getActionsAsKeyPair.

@Transient
public HashMap<String, ArrayList<String>> getActionsAsKeyPair(String actionEvaluatesTo) {
    HashMap<String, ArrayList<String>> h = new HashMap<String, ArrayList<String>>();
    for (RuleActionBean action : actions) {
        String key = action.getExpressionEvaluatesTo().toString();
        if (actionEvaluatesTo.equals(key)) {
            if (h.containsKey(key)) {
                h.get(key).add(action.getSummary());
            } else {
                ArrayList<String> a = new ArrayList<String>();
                a.add(action.getSummary());
                h.put(key, a);
            }
        }
    }
    return h;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Transient(javax.persistence.Transient)

Example 3 with RuleActionBean

use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.

the class ImportDataRuleRunner method runRules.

@Transactional
private MessageContainer runRules(StudyBean currentStudy, UserAccountBean ub, HashMap<String, String> variableAndValue, HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted) {
    //Copied from DataEntryRuleRunner runRules
    MessageContainer messageContainer = new MessageContainer();
    for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
        // Sort the list of actions
        Collections.sort(entry.getValue(), new RuleActionContainerComparator());
        for (RuleActionContainer ruleActionContainer : entry.getValue()) {
            logger.info("START Expression is : {} , RuleAction : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString() });
            ruleActionContainer.getRuleSetBean().setTarget(ruleActionContainer.getExpressionBean());
            ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
            ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
            ItemDataBean itemData = getExpressionService().getItemDataBeanFromDb(ruleActionContainer.getRuleSetBean().getTarget().getValue());
            RuleActionBean rab = ap.execute(RuleRunnerMode.IMPORT_DATA, ExecutionMode.SAVE, ruleActionContainer.getRuleAction(), itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
            if (rab != null) {
                if (rab instanceof ShowActionBean) {
                    messageContainer.add(getExpressionService().getGroupOidOrdinal(ruleActionContainer.getRuleSetBean().getTarget().getValue()), rab);
                } else {
                    messageContainer.add(getExpressionService().getGroupOrdninalConcatWithItemOid(ruleActionContainer.getRuleSetBean().getTarget().getValue()), ruleActionContainer.getRuleAction());
                }
            }
            logger.info("END Expression is : {} , RuleAction : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString() });
        }
    }
    return messageContainer;
}
Also used : ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) HashMap(java.util.HashMap) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with RuleActionBean

use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.

the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreenOLD.

public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreenOLD(List<RuleSetBean> ruleSets, Boolean dryRun, StudyBean currentStudy, HashMap<String, String> variableAndValue, UserAccountBean ub) {
    if (variableAndValue == null || variableAndValue.isEmpty()) {
        logger.warn("You must be executing Rules in Batch");
        variableAndValue = new HashMap<String, String>();
    }
    List<RuleSetBasedViewContainer> ruleSetBasedView = new ArrayList<RuleSetBasedViewContainer>();
    for (RuleSetBean ruleSet : ruleSets) {
        for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
            ruleSet.setTarget(expressionBean);
            for (RuleSetRuleBean ruleSetRule : ruleSet.getRuleSetRules()) {
                String result = null;
                RuleBean rule = ruleSetRule.getRuleBean();
                ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, rule.getExpression(), ruleSet, variableAndValue);
                try {
                    OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
                    result = (String) oep.parseAndEvaluateExpression(rule.getExpression().getValue());
                    // HashMap<String, ArrayList<RuleActionBean>> actionsToBeExecuted = ruleSetRule.getAllActionsWithEvaluatesToAsKey(result);
                    List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
                    ItemDataBean itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
                    if (itemData != null) {
                        Iterator<RuleActionBean> itr = actionListBasedOnRuleExecutionResult.iterator();
                        while (itr.hasNext()) {
                            RuleActionBean ruleActionBean = itr.next();
                            RuleActionRunLogBean ruleActionRunLog = new RuleActionRunLogBean(ruleActionBean.getActionType(), itemData, itemData.getValue(), ruleSetRule.getRuleBean().getOid());
                            if (getRuleActionRunLogDao().findCountByRuleActionRunLogBean(ruleActionRunLog) > 0) {
                                itr.remove();
                            }
                        }
                    }
                    logger.info("RuleSet with target  : {} , Ran Rule : {}  The Result was : {} , Based on that {} action will be executed ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size() });
                    if (actionListBasedOnRuleExecutionResult.size() > 0) {
                        for (RuleActionBean ruleAction : actionListBasedOnRuleExecutionResult) {
                            ruleAction.setCuratedMessage(curateMessage(ruleAction, ruleSetRule));
                            // getDiscrepancyNoteService().saveFieldNotes(ruleAction.getSummary(), itemDataBeanId, "ItemData", currentStudy, ub);
                            ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleAction.getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleSet, getRuleActionRunLogDao(), ruleSetRule);
                            RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, ExecutionMode.SAVE, ruleAction, itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleSet, ruleSetRule, currentStudy, ruleAction));
                            if (rab != null) {
                                ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleSet, rule, result, ruleAction);
                            }
                        }
                    }
                } catch (OpenClinicaSystemException osa) {
                    String errorMessage = "RuleSet with target  : " + ruleSet.getTarget().getValue() + " , Ran Rule : " + rule.getName() + " , It resulted in an error due to : " + osa.getMessage();
                    // log error
                    logger.warn(errorMessage);
                }
            }
        }
    }
    return ruleSetBasedView;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetBasedViewContainer(org.akaza.openclinica.domain.rule.RuleSetBasedViewContainer) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ArrayList(java.util.ArrayList) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 5 with RuleActionBean

use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.

the class RulesPostImportContainerService method isRuleSetRuleValid.

/**
     * If the RuleSet contains any RuleSetRule object with an invalid RuleRef OID (OID that is not in DB or in the Valid Rule Lists) , Then add an error to the
     * ruleSetBeanWrapper, which in terms will make the RuleSet inValid.
     *
     * @param importContainer
     * @param ruleSetBeanWrapper
     */
private void isRuleSetRuleValid(RulesPostImportContainer importContainer, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
    for (RuleSetRuleBean ruleSetRuleBean : ruleSetBeanWrapper.getAuditableBean().getRuleSetRules()) {
        String ruleDefOid = ruleSetRuleBean.getOid();
        if (ruleSetRuleBean.getId() == null || ruleSetRuleBean.getRuleSetRuleBeanImportStatus() == RuleSetRuleBeanImportStatus.EXACT_DOUBLE) {
            EventDefinitionCRFBean eventDefinitionCRFBean = getExpressionService().getEventDefinitionCRF(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue());
            if (eventDefinitionCRFBean != null && eventDefinitionCRFBean.getStatus().isDeleted()) {
                ruleSetBeanWrapper.error(createError("OCRERR_0026"));
            }
            if (importContainer.getInValidRules().get(ruleDefOid) != null || importContainer.getValidRules().get(ruleDefOid) == null && getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId()) == null) {
                ruleSetBeanWrapper.error(createError("OCRERR_0025"));
            }
            if (importContainer.getValidRules().get(ruleDefOid) != null) {
                AuditableBeanWrapper<RuleBean> r = importContainer.getValidRules().get(ruleDefOid);
                if (!isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
                    ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            if (importContainer.getValidRules().get(ruleDefOid) == null) {
                RuleBean rule = getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId());
                AuditableBeanWrapper<RuleBean> r = new AuditableBeanWrapper<RuleBean>(rule);
                if (rule == null || !isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
                    ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            if (ruleSetRuleBean.getActions().size() == 0) {
                ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            for (RuleActionBean ruleActionBean : ruleSetRuleBean.getActions()) {
                isRuleActionValid(ruleActionBean, ruleSetBeanWrapper, eventDefinitionCRFBean, eventActionsRuleSetBean);
            }
        }
    }
}
Also used : AuditableBeanWrapper(org.akaza.openclinica.domain.rule.AuditableBeanWrapper) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Aggregations

RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)20 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)10 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)10 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)10 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)10 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)8 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)8 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)8 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)7 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)6 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)6 Map (java.util.Map)5 List (java.util.List)4 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)4 Transient (javax.persistence.Transient)3 ShowActionBean (org.akaza.openclinica.domain.rule.action.ShowActionBean)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HashSet (java.util.HashSet)2