Search in sources :

Example 1 with ExpressionBean

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

the class StratificationFactorBean method setExpressionAsString.

public void setExpressionAsString(String expressionAsString) {
    stratificationFactor = new ExpressionBean(Context.OC_RULES_V1, expressionAsString);
    this.expressionAsString = expressionAsString;
}
Also used : ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 2 with ExpressionBean

use of org.akaza.openclinica.domain.rule.expression.ExpressionBean 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 3 with ExpressionBean

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

the class RuleSetService method solidifyGroupOrdinalsUsingFormProperties.

/*
     * (non-Javadoc)
     * @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#solidifyGroupOrdinalsUsingFormProperties(java.util.List, java.util.HashMap)
     */
public List<RuleSetBean> solidifyGroupOrdinalsUsingFormProperties(List<RuleSetBean> ruleSets, HashMap<String, Integer> grouped) {
    for (RuleSetBean ruleSet : ruleSets) {
        ArrayList<ExpressionBean> expressionsWithCorrectGroupOrdinal = new ArrayList<ExpressionBean>();
        for (ExpressionBean expression : ruleSet.getExpressions()) {
            logger.debug("solidifyGroupOrdinals: Expression Value : " + expression.getValue());
            String groupOIDConcatItemOID = getExpressionService().getGroupOidConcatWithItemOid(expression.getValue());
            String itemOID = getExpressionService().getItemOid(expression.getValue());
            String groupOrdinal = getExpressionService().getGroupOrdninalCurated(expression.getValue());
            if (grouped.containsKey(groupOIDConcatItemOID) && groupOrdinal.equals("")) {
                for (int i = 0; i < grouped.get(groupOIDConcatItemOID); i++) {
                    ExpressionBean expBean = new ExpressionBean();
                    expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), i + 1));
                    expBean.setContext(expression.getContext());
                    expressionsWithCorrectGroupOrdinal.add(expBean);
                }
            } else if (grouped.containsKey(groupOIDConcatItemOID) && !groupOrdinal.equals("")) {
                ExpressionBean expBean = new ExpressionBean();
                expBean.setValue(expression.getValue());
                expBean.setContext(expression.getContext());
                expressionsWithCorrectGroupOrdinal.add(expBean);
            } else if (grouped.containsKey(itemOID)) {
                ExpressionBean expBean = new ExpressionBean();
                expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), null));
                expBean.setContext(expression.getContext());
                expressionsWithCorrectGroupOrdinal.add(expBean);
            }
        }
        ruleSet.setExpressions(expressionsWithCorrectGroupOrdinal);
        for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
            logger.debug("expressionBean value : {} ", expressionBean.getValue());
        }
    }
    return ruleSets;
}
Also used : ArrayList(java.util.ArrayList) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 4 with ExpressionBean

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

the class JobTriggerService method triggerJob.

public void triggerJob() {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    ArrayList<RuleSetBean> ruleSets = ruleSetDao.findAllRunOnSchedules(true);
    for (RuleSetBean ruleSet : ruleSets) {
        if (ruleSet.getStatus().AVAILABLE != null && ruleSet.isRunSchedule()) {
            if (ruleSet.getItemId() != null) {
                // item Specific Rule
                ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
                StudyBean currentStudy = (StudyBean) getStudyDao().findByPK(ruleSet.getStudyId());
                ResourceBundleProvider.updateLocale(Locale.getDefault());
                UserAccountBean ub = (UserAccountBean) getUserAccountDao().findByPK(1);
                ruleSetBeans.add(ruleSet);
                ruleSetService.runRulesInBulk(ruleSetBeans, false, currentStudy, ub, true);
            } else {
                // Event Specific Rule
                StudyEventChangeDetails studyEventChangeDetails = new StudyEventChangeDetails(true, true);
                ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
                ExpressionBean eBean = new ExpressionBean();
                eBean.setValue(ruleSet.getTarget().getValue() + ".A.B");
                ruleSet.setTarget(eBean);
                ruleSetBeans.add(ruleSet);
                ruleSetService.runRulesInBeanProperty(ruleSetBeans, 1, studyEventChangeDetails);
            }
        }
    }
}
Also used : Locale(java.util.Locale) StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 5 with ExpressionBean

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

the class RuleSetService method filterRuleSetsByGroupOrdinal.

/*
     * (non-Javadoc)
     * @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#filterRuleSetsByGroupOrdinal(java.util.List)
     */
public List<RuleSetBean> filterRuleSetsByGroupOrdinal(List<RuleSetBean> ruleSets) {
    for (RuleSetBean ruleSetBean : ruleSets) {
        List<ExpressionBean> expressionsWithCorrectGroupOrdinal = new ArrayList<ExpressionBean>();
        /**
         * get the itemDataSize by studyEventId,itemGroupOid,itemOid for the whole study
         * only run once
         */
        String itemOid = getExpressionService().getItemOid(ruleSetBean.getExpressions().get(0).getValue());
        String itemGroupOid = getExpressionService().getItemGroupOid(ruleSetBean.getExpressions().get(0).getValue());
        HashMap itemDataCountHm = getItemDataDao().findCountByStudyEventAndOIDs(ruleSetBean.getStudyId(), itemOid, itemGroupOid);
        int itemDataSize = 0;
        for (ExpressionBean expression : ruleSetBean.getExpressions()) {
            String studyEventId = getExpressionService().getStudyEventDefinitionOrdninalCurated(expression.getValue());
            itemOid = getExpressionService().getItemOid(expression.getValue());
            itemGroupOid = getExpressionService().getItemGroupOid(expression.getValue());
            String groupOrdinal = getExpressionService().getGroupOrdninalCurated(expression.getValue());
            String key = studyEventId + itemGroupOid + itemOid;
            if (itemDataCountHm.containsKey(key)) {
                itemDataSize = ((Integer) itemDataCountHm.get(key)).intValue();
                logger.debug("studyEventId {} , itemOid {} , itemGroupOid {} , groupOrdinal {} , itemDatas {}", new Object[] { studyEventId, itemOid, itemGroupOid, groupOrdinal, itemDataSize });
            }
            // case 1 : group ordinal = ""
            if (groupOrdinal.equals("") && itemDataSize > 0) {
                for (int k = 0; k < itemDataSize; k++) {
                    ExpressionBean expBean = new ExpressionBean();
                    expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), k + 1));
                    expBean.setContext(expression.getContext());
                    expressionsWithCorrectGroupOrdinal.add(expBean);
                }
            }
            // case 2 : group ordinal = x and itemDatas should be size >= x
            if (!groupOrdinal.equals("") && itemDataSize >= Integer.valueOf(groupOrdinal)) {
                ExpressionBean expBean = new ExpressionBean();
                expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), null));
                expBean.setContext(expression.getContext());
                expressionsWithCorrectGroupOrdinal.add(expBean);
            }
            itemDataSize = 0;
        }
        ruleSetBean.setExpressions(expressionsWithCorrectGroupOrdinal);
    }
    logExpressions(ruleSets);
    return ruleSets;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Aggregations

ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)31 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)19 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)14 ArrayList (java.util.ArrayList)13 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)10 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)9 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)8 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)8 HashMap (java.util.HashMap)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 ExpressionProcessor (org.akaza.openclinica.domain.rule.expression.ExpressionProcessor)5 Map (java.util.Map)4 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)3 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2