Search in sources :

Example 6 with ExpressionBean

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

the class RulesPostImportContainerService method isRuleActionValid.

private void isRuleActionValid(RuleActionBean ruleActionBean, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, EventDefinitionCRFBean eventDefinitionCRFBean, List<RuleSetBean> eventActionsRuleSetBean) {
    RuleActionRunBean ruleActionRun = ruleActionBean.getRuleActionRun();
    if (ruleActionBean.getActionType().getCode() != 6 && !ruleActionRun.getInitialDataEntry() && !ruleActionRun.getAdministrativeDataEntry() && !ruleActionRun.getBatch() && !ruleActionRun.getDoubleDataEntry() && !ruleActionRun.getImportDataEntry())
        ruleSetBeanWrapper.error(createError("OCRERR_0050"));
    String message = "";
    String emailSubject = "";
    if (ruleActionBean instanceof org.akaza.openclinica.domain.rule.action.NotificationActionBean) {
        message = ((NotificationActionBean) ruleActionBean).getMessage();
        emailSubject = ((NotificationActionBean) ruleActionBean).getSubject();
        if (emailSubject.length() > 330)
            ruleSetBeanWrapper.error(createError("OCRERR_0048"));
        if (message.length() > 2040)
            ruleSetBeanWrapper.error(createError("OCRERR_0049"));
    }
    if (ruleActionBean instanceof org.akaza.openclinica.domain.rule.action.EmailActionBean)
        isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper);
    if (ruleActionBean instanceof DiscrepancyNoteActionBean)
        isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper);
    if (ruleActionBean instanceof ShowActionBean) {
        if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
            List<PropertyBean> properties = ((ShowActionBean) ruleActionBean).getProperties();
            //if (ruleActionBean.getRuleActionRun().getBatch() == true || ruleActionBean.getRuleActionRun().getImportDataEntry() == true) {
            if (ruleActionBean.getRuleActionRun().getBatch() == true) {
                ruleSetBeanWrapper.error("ShowAction " + ((ShowActionBean) ruleActionBean).toString() + " is not Valid. You cannot have Batch=\"true\". ");
            //+ " is not Valid. You cannot have ImportDataEntry=\"true\" Batch=\"true\". ");
            }
            for (PropertyBean propertyBean : properties) {
                String result = getExpressionService().checkValidityOfItemOrItemGroupOidInCrf(propertyBean.getOid(), ruleSetBeanWrapper.getAuditableBean());
                // String result = getExpressionService().isExpressionValid(oid, ruleSetBeanWrapper.getAuditableBean(), 2) ? "OK" : "";
                if (!result.equals("OK")) {
                    ruleSetBeanWrapper.error("ShowAction OID " + result + " is not Valid. ");
                }
            }
        }
    }
    if (ruleActionBean instanceof HideActionBean) {
        if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
            List<PropertyBean> properties = ((HideActionBean) ruleActionBean).getProperties();
            //if (ruleActionBean.getRuleActionRun().getBatch() == true || ruleActionBean.getRuleActionRun().getImportDataEntry() == true) {
            if (ruleActionBean.getRuleActionRun().getBatch() == true) {
                ruleSetBeanWrapper.error("HideAction " + ((HideActionBean) ruleActionBean).toString() + " is not Valid. You cannot have Batch=\"true\". ");
            //+ " is not Valid. You cannot have ImportDataEntry=\"true\" Batch=\"true\". ");
            }
            for (PropertyBean propertyBean : properties) {
                String result = getExpressionService().checkValidityOfItemOrItemGroupOidInCrf(propertyBean.getOid(), ruleSetBeanWrapper.getAuditableBean());
                // String result = getExpressionService().isExpressionValid(oid, ruleSetBeanWrapper.getAuditableBean(), 2) ? "OK" : "";
                if (!result.equals("OK")) {
                    ruleSetBeanWrapper.error("HideAction OID " + result + " is not Valid. ");
                }
            }
        }
    }
    if (ruleActionBean instanceof InsertActionBean) {
        if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
            DataBinder dataBinder = new DataBinder(ruleActionBean);
            Errors errors = dataBinder.getBindingResult();
            InsertActionValidator insertActionValidator = getInsertActionValidator();
            insertActionValidator.setEventDefinitionCRFBean(eventDefinitionCRFBean);
            insertActionValidator.setRuleSetBean(ruleSetBeanWrapper.getAuditableBean());
            insertActionValidator.setExpressionService(expressionService);
            insertActionValidator.validate(ruleActionBean, errors);
            if (errors.hasErrors()) {
                ruleSetBeanWrapper.error("InsertAction is not valid: " + errors.getAllErrors().get(0).getCode());
            }
        }
    }
    if (ruleActionBean instanceof RandomizeActionBean) {
        if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
            DataBinder dataBinder = new DataBinder(ruleActionBean);
            Errors errors = dataBinder.getBindingResult();
            RandomizeActionValidator randomizeActionValidator = getRandomizeActionValidator();
            randomizeActionValidator.setEventDefinitionCRFBean(eventDefinitionCRFBean);
            randomizeActionValidator.setRuleSetBean(ruleSetBeanWrapper.getAuditableBean());
            randomizeActionValidator.setExpressionService(expressionService);
            randomizeActionValidator.validate(ruleActionBean, errors);
            RandomizeActionBean randomizeActionBean = (RandomizeActionBean) ruleActionBean;
            //        ruleSetBeanWrapper.error(createError("OCRERR_0050"));
            if (randomizeActionBean.getStratificationFactors() != null) {
                for (StratificationFactorBean factor : randomizeActionBean.getStratificationFactors()) {
                    if (factor.getStratificationFactor() != null && factor.getStratificationFactor().getValue() != null && factor.getStratificationFactor().getValue().length() != 0) {
                        String expressionContextName = factor.getStratificationFactor().getContextName();
                        Context context = expressionContextName != null ? Context.getByName(expressionContextName) : Context.OC_RULES_V1;
                        factor.getStratificationFactor().setContext(context);
                        ExpressionBean expBean = factor.getStratificationFactor();
                        String expValue = expBean.getValue();
                        String prefix = "STUDYGROUPCLASSLIST";
                        boolean sgcExist = false;
                        if (expValue.startsWith("SS.")) {
                            String param = expValue.split("\\.", -1)[1].trim();
                            if (param.startsWith(prefix)) {
                                String gcName = param.substring(21, param.indexOf("\"]"));
                                StudyGroupClassDAO studyGroupClassDAO = new StudyGroupClassDAO(ds);
                                ArrayList<StudyGroupClassBean> studyGroupClasses = studyGroupClassDAO.findAllByStudy(currentStudy);
                                for (StudyGroupClassBean studyGroupClass : studyGroupClasses) {
                                    if (studyGroupClass.getName().equalsIgnoreCase(gcName.trim())) {
                                        sgcExist = true;
                                        break;
                                    }
                                }
                            }
                            if (!param.equalsIgnoreCase("BIRTHDATE") && !param.equalsIgnoreCase("SEX") && !sgcExist) {
                                ruleSetBeanWrapper.error(createError("OCRERR_0051", expBean.getValue()));
                            }
                        } else {
                            isStratificationExpressionValid(expBean, ruleSetBeanWrapper);
                        }
                    }
                }
            }
            if (errors.hasErrors())
                ruleSetBeanWrapper.error("Randomize Action is not valid: " + errors.getAllErrors().get(0).getCode());
        }
    }
    if (ruleActionBean instanceof EventActionBean) {
        DataBinder dataBinder = new DataBinder(ruleActionBean);
        Errors errors = dataBinder.getBindingResult();
        eventActionValidator.setRuleSetBeanWrapper(ruleSetBeanWrapper);
        eventActionValidator.setExpressionService(expressionService);
        eventActionValidator.setRespage(respage);
        eventActionValidator.validate(ruleActionBean, errors);
        String currentTarget = null;
        currentTarget = ruleSetBeanWrapper.getAuditableBean().getOriginalTarget().getValue();
        if (currentTarget.contains(".STARTDATE") || currentTarget.contains(".STATUS")) {
            if (ruleActionBean.getActionType().getCode() == 6)
                //Validation , move to Validate Rule page under eventActinValidator
                inValidateInfiniteLoop(ruleActionBean, ruleSetBeanWrapper, eventActionsRuleSetBean);
        } else {
            ruleSetBeanWrapper.error(createError("OCRERR_0044"));
        }
        if (errors.hasErrors()) {
            ruleSetBeanWrapper.error("EventAction is not valid: " + errors.getAllErrors().get(0).getDefaultMessage());
        }
    }
}
Also used : DiscrepancyNoteActionBean(org.akaza.openclinica.domain.rule.action.DiscrepancyNoteActionBean) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RuleActionRunBean(org.akaza.openclinica.domain.rule.action.RuleActionRunBean) StratificationFactorBean(org.akaza.openclinica.domain.rule.action.StratificationFactorBean) RandomizeActionBean(org.akaza.openclinica.domain.rule.action.RandomizeActionBean) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) EmailActionBean(org.akaza.openclinica.bean.rule.action.EmailActionBean) DataBinder(org.springframework.validation.DataBinder) InsertActionValidator(org.akaza.openclinica.validator.rule.action.InsertActionValidator) ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) HideActionBean(org.akaza.openclinica.domain.rule.action.HideActionBean) Context(org.akaza.openclinica.domain.rule.expression.Context) RandomizeActionValidator(org.akaza.openclinica.validator.rule.action.RandomizeActionValidator) NotificationActionBean(org.akaza.openclinica.domain.rule.action.NotificationActionBean) InsertActionBean(org.akaza.openclinica.domain.rule.action.InsertActionBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) Errors(org.springframework.validation.Errors) PropertyBean(org.akaza.openclinica.domain.rule.action.PropertyBean)

Example 7 with ExpressionBean

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

the class RulesPostImportContainerService method isStratificationExpressionValid.

public boolean isStratificationExpressionValid(ExpressionBean expBean, AuditableBeanWrapper<RuleSetBean> beanWrapper) {
    boolean isValid = true;
    ExpressionBean expressionBean = isExpressionValid(expBean, beanWrapper);
    ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, expressionBean, ExpressionObjectWrapper.CONTEXT_TARGET);
    ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
    ep.setRespage(respage);
    //    String errorString = ep.isRuleExpressionValid();
    String errorString = ep.isRuleAssignmentExpressionValid();
    if (errorString != null) {
        beanWrapper.error(errorString);
        isValid = false;
    }
    return isValid;
}
Also used : ExpressionProcessor(org.akaza.openclinica.domain.rule.expression.ExpressionProcessor) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 8 with ExpressionBean

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

the class RulesPostImportContainerService method getExpressionService.

private ExpressionService getExpressionService() {
    expressionService = this.expressionService != null ? expressionService : new ExpressionService(new ExpressionObjectWrapper(ds, currentStudy, (ExpressionBean) null, (RuleSetBean) null));
    expressionService.setExpressionWrapper(new ExpressionObjectWrapper(ds, currentStudy, (ExpressionBean) null, (RuleSetBean) null));
    return expressionService;
}
Also used : ExpressionService(org.akaza.openclinica.service.rule.expression.ExpressionService) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 9 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>();
        for (ExpressionBean expression : ruleSetBean.getExpressions()) {
            String studyEventId = getExpressionService().getStudyEventDefinitionOrdninalCurated(expression.getValue());
            String itemOid = getExpressionService().getItemOid(expression.getValue());
            String itemGroupOid = getExpressionService().getItemGroupOid(expression.getValue());
            String groupOrdinal = getExpressionService().getGroupOrdninalCurated(expression.getValue());
            List<ItemDataBean> itemDatas = getItemDataDao().findByStudyEventAndOids(Integer.valueOf(studyEventId), itemOid, itemGroupOid);
            logger.debug("studyEventId {} , itemOid {} , itemGroupOid {} , groupOrdinal {} , itemDatas {}", new Object[] { studyEventId, itemOid, itemGroupOid, groupOrdinal, itemDatas.size() });
            // case 1 : group ordinal = ""
            if (groupOrdinal.equals("") && itemDatas.size() > 0) {
                for (int k = 0; k < itemDatas.size(); 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("") && itemDatas.size() >= Integer.valueOf(groupOrdinal)) {
                ExpressionBean expBean = new ExpressionBean();
                expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), null));
                expBean.setContext(expression.getContext());
                expressionsWithCorrectGroupOrdinal.add(expBean);
            }
        }
        ruleSetBean.setExpressions(expressionsWithCorrectGroupOrdinal);
    }
    logExpressions(ruleSets);
    return ruleSets;
}
Also used : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 10 with ExpressionBean

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

the class RuleSetService method replaceSEDOrdinal.

public ExpressionBean replaceSEDOrdinal(ExpressionBean targetExpression, StudyEventBean studyEvent) {
    ExpressionBean expression = new ExpressionBean(targetExpression.getContext(), targetExpression.getValue());
    expression.setValue(getExpressionService().replaceStudyEventDefinitionOIDWith(expression.getValue(), String.valueOf(studyEvent.getId())));
    return expression;
}
Also used : 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 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 HashMap (java.util.HashMap)6 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)6 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)6 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)5 ExpressionProcessor (org.akaza.openclinica.domain.rule.expression.ExpressionProcessor)5 Map (java.util.Map)4 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)4 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)3 NotificationActionBean (org.akaza.openclinica.domain.rule.action.NotificationActionBean)3 PropertyBean (org.akaza.openclinica.domain.rule.action.PropertyBean)3