Search in sources :

Example 21 with RuleSetRuleBean

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

the class RulesPostImportContainerServiceTest method getRuleSet.

private RuleSetBean getRuleSet(String ruleOid, String target, String oidRef) {
    RuleSetBean ruleSet = new RuleSetBean();
    ruleSet.setTarget(createExpression(Context.OC_RULES_V1, target));
    ruleSet.setOriginalTarget(createExpression(Context.OC_RULES_V1, target));
    RuleSetRuleBean ruleSetRule = createRuleSetRule(ruleSet, ruleOid, oidRef);
    ruleSet.addRuleSetRule(ruleSetRule);
    return ruleSet;
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 22 with RuleSetRuleBean

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

the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreen.

public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreen(List<RuleSetBean> ruleSets, ExecutionMode executionMode, 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>();
    HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
    for (RuleSetBean ruleSet : ruleSets) {
        String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue());
        List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null;
        if (toBeExecuted.containsKey(key)) {
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        } else {
            toBeExecuted.put(key, new ArrayList<RuleActionContainer>());
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        }
        ItemDataBean itemData = null;
        for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
            ruleSet.setTarget(expressionBean);
            System.out.println("tg expression:" + ruleSet.getTarget().getValue());
            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());
                    itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
                    System.out.println("The result: " + result);
                    List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
                    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();
                            }
                        }
                    }
                    for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
                        RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet);
                        allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer);
                    }
                    logger.info("RuleSet with target  : {} , Ran Rule : {}  The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() });
                } catch (OpenClinicaSystemException osa) {
                // TODO: report something useful
                }
            }
        }
    }
    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()) {
            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());
            RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
            System.out.println(" Action Trigger: " + ap.toString());
            if (rab != null) {
                ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule().getRuleBean(), ruleActionContainer.getRuleAction().getExpressionEvaluatesTo().toString(), ruleActionContainer.getRuleAction());
            }
        }
    }
    return ruleSetBasedView;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetBasedViewContainer(org.akaza.openclinica.domain.rule.RuleSetBasedViewContainer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) HashMap(java.util.HashMap) Map(java.util.Map) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 23 with RuleSetRuleBean

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

the class RuleSetRuleDao method findByRuleSetStudyIdAndStatusAvail.

/**
     * Use this method carefully as we force an eager fetch. It is also annotated with 
     * Transactional so it can be called from Quartz threads. 
     * @param studyId
     * @return List of RuleSetRuleBeans 
     */
@SuppressWarnings("unchecked")
@Transactional
public ArrayList<RuleSetRuleBean> findByRuleSetStudyIdAndStatusAvail(Integer studyId) {
    String query = "from " + getDomainClassName() + " ruleSetRule  where ruleSetRule.ruleSetBean.studyId = :studyId and status = :status ";
    org.hibernate.Query q = getCurrentSession().createQuery(query);
    q.setInteger("studyId", studyId);
    q.setParameter("status", org.akaza.openclinica.domain.Status.AVAILABLE);
    q.setCacheable(true);
    q.setCacheRegion(getDomainClassName());
    //JN: enabling statistics for hibernate queries etc... to monitor the performance
    Statistics stats = getSessionFactory().getStatistics();
    logger.info("EntityRuleSet" + stats.getEntityInsertCount());
    logger.info(stats.getQueryExecutionMaxTimeQueryString());
    logger.info("hit count" + stats.getSecondLevelCacheHitCount());
    stats.logSummary();
    ArrayList<RuleSetRuleBean> ruleSetRules = (ArrayList<RuleSetRuleBean>) q.list();
    // Forcing eager fetch of actions & their properties
    for (RuleSetRuleBean ruleSetRuleBean : ruleSetRules) {
        for (RuleActionBean action : ruleSetRuleBean.getActions()) {
            if (action instanceof RandomizeActionBean) {
                ((RandomizeActionBean) action).getProperties().size();
            }
            if (action instanceof InsertActionBean) {
                ((InsertActionBean) action).getProperties().size();
            }
            if (action instanceof ShowActionBean) {
                ((ShowActionBean) action).getProperties().size();
            }
            if (action instanceof HideActionBean) {
                ((HideActionBean) action).getProperties().size();
            }
            if (action instanceof EventActionBean) {
                ((EventActionBean) action).getProperties().size();
            }
        }
    }
    return ruleSetRules;
}
Also used : ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) HideActionBean(org.akaza.openclinica.domain.rule.action.HideActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) InsertActionBean(org.akaza.openclinica.domain.rule.action.InsertActionBean) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RandomizeActionBean(org.akaza.openclinica.domain.rule.action.RandomizeActionBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with RuleSetRuleBean

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

the class RuleSetDaoTest method createRuleSetRule.

private RuleSetRuleBean createRuleSetRule(RuleSetBean ruleSet, RuleBean ruleBean) {
    RuleSetRuleBean ruleSetRule = new RuleSetRuleBean();
    DiscrepancyNoteActionBean ruleAction = new DiscrepancyNoteActionBean();
    ruleAction.setMessage("HELLO WORLD");
    ruleAction.setExpressionEvaluatesTo(true);
    ruleSetRule.addAction(ruleAction);
    ruleSetRule.setRuleSetBean(ruleSet);
    ruleSetRule.setRuleBean(ruleBean);
    return ruleSetRule;
}
Also used : DiscrepancyNoteActionBean(org.akaza.openclinica.domain.rule.action.DiscrepancyNoteActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 25 with RuleSetRuleBean

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

the class RuleSetDaoTest method createStubRuleSetBean.

private RuleSetBean createStubRuleSetBean() {
    RuleSetBean ruleSet = new RuleSetBean();
    ruleSet.setTarget(createExpression(Context.OC_RULES_V1, "SE_ED2REPEA.F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_NAME"));
    RuleSetRuleBean ruleSetRule = createRuleSetRule(ruleSet, null);
    ruleSet.addRuleSetRule(ruleSetRule);
    return ruleSet;
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Aggregations

RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)33 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)20 ArrayList (java.util.ArrayList)12 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)10 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)10 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)9 HashMap (java.util.HashMap)7 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)7 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)7 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)6 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)6 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)5 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)5 Map (java.util.Map)3 AuditableBeanWrapper (org.akaza.openclinica.domain.rule.AuditableBeanWrapper)3 ShowActionBean (org.akaza.openclinica.domain.rule.action.ShowActionBean)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2