Search in sources :

Example 11 with RuleSetBean

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

the class RulesPostImportContainerService method validateRuleSetRuleDefs.

public RulesPostImportContainer validateRuleSetRuleDefs(RulesPostImportContainer importContainer, RuleSetRuleBean ruleSetRuleForm) {
    RuleSetBean ruleSetBean = ruleSetRuleForm.getRuleSetBean();
    RuleSetRuleBean ruleSetRuleBean = ruleSetRuleForm;
    AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper = new AuditableBeanWrapper<RuleSetBean>(ruleSetBean);
    ruleSetBeanWrapper.getAuditableBean().setStudy(currentStudy);
    if (isRuleSetExpressionValid(ruleSetBeanWrapper)) {
        RuleSetBean persistentRuleSetBean = getRuleSetDao().findByExpressionAndStudy(ruleSetBean, currentStudy.getId());
        if (persistentRuleSetBean != null) {
            List<RuleSetRuleBean> importedRuleSetRules = ruleSetBeanWrapper.getAuditableBean().getRuleSetRules();
            persistentRuleSetBean.setUpdaterAndDate(getUserAccount());
            ruleSetBeanWrapper.setAuditableBean(persistentRuleSetBean);
            for (RuleSetRuleBean persistentruleSetRuleBean : persistentRuleSetBean.getRuleSetRules()) {
                if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.equals(persistentruleSetRuleBean)) {
                    persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.EXACT_DOUBLE);
                    // itr.remove();
                    break;
                } else if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.getRuleBean() != null && ruleSetRuleBean.getRuleBean().equals(persistentruleSetRuleBean.getRuleBean())) {
                    // persistentruleSetRuleBean.setActions(ruleSetRuleBean.getActions());
                    persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.TO_BE_REMOVED);
                    // itr.remove();
                    break;
                }
                ruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.LINE);
            }
            ruleSetBeanWrapper.getAuditableBean().addRuleSetRules(importedRuleSetRules);
        // ruleSetBeanWrapper.getAuditableBean().setId(persistentRuleSetBean.getId());
        } else {
            ruleSetBeanWrapper.getAuditableBean().setOwner(getUserAccount());
            ruleSetBeanWrapper.getAuditableBean().setStudyEventDefinition(getExpressionService().getStudyEventDefinitionFromExpression(ruleSetBean.getTarget().getValue()));
            ruleSetBeanWrapper.getAuditableBean().setCrf(getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue()));
            ruleSetBeanWrapper.getAuditableBean().setCrfVersion(getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue()));
            ruleSetBeanWrapper.getAuditableBean().setItem(getExpressionService().getItemBeanFromExpression(ruleSetBean.getTarget().getValue()));
            ruleSetBeanWrapper.getAuditableBean().setItemGroup(getExpressionService().getItemGroupExpression(ruleSetBean.getTarget().getValue()));
        }
        List<RuleSetBean> eventActionsRuleSetBean = getRuleSetDao().findAllEventActions(currentStudy);
        isRuleSetRuleValid(importContainer, ruleSetBeanWrapper, eventActionsRuleSetBean);
    }
    putRuleSetInCorrectContainer(ruleSetBeanWrapper, importContainer);
    logger.info("# of Valid RuleSetDefs : " + importContainer.getValidRuleSetDefs().size());
    logger.info("# of InValid RuleSetDefs : " + importContainer.getInValidRuleSetDefs().size());
    logger.info("# of Overwritable RuleSetDefs : " + importContainer.getDuplicateRuleSetDefs().size());
    return importContainer;
}
Also used : AuditableBeanWrapper(org.akaza.openclinica.domain.rule.AuditableBeanWrapper) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 12 with RuleSetBean

use of org.akaza.openclinica.domain.rule.RuleSetBean 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 13 with RuleSetBean

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

the class StudyEventBeanListener method createRuleSet.

private List<RuleSetBean> createRuleSet(Integer studyEventDefId) {
    List<RuleSetBean> ruleSetsDB = getRuleSetDao().findAllByStudyEventDefIdWhereItemIsNull(studyEventDefId);
    List<RuleSetBean> ruleSetCopies = new ArrayList<RuleSetBean>();
    for (RuleSetBean ruleSetDB : ruleSetsDB) {
        RuleSetBean ruleSetCopy = (RuleSetBean) SerializationUtils.clone(ruleSetDB);
        ruleSetCopies.add(ruleSetCopy);
    }
    return ruleSetCopies;
}
Also used : ArrayList(java.util.ArrayList) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 14 with RuleSetBean

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

the class RuleSetService method getRuleSetsByCrfStudyAndStudyEventDefinition.

/*
     * (non-Javadoc)
     * @see
     * org.akaza.openclinica.service.rule.RuleSetServiceInterface#getRuleSetsByCrfStudyAndStudyEventDefinition(org.akaza.openclinica.bean.managestudy.StudyBean,
     * org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean, org.akaza.openclinica.bean.submit.CRFVersionBean)
     */
public List<RuleSetBean> getRuleSetsByCrfStudyAndStudyEventDefinition(StudyBean study, StudyEventDefinitionBean sed, CRFVersionBean crfVersion) {
    CRFBean crf = getCrfDao().findByVersionId(crfVersion.getId());
    logger.debug("crfVersionID : " + crfVersion.getId() + " studyId : " + study.getId() + " studyEventDefinition : " + sed.getId());
    List<RuleSetBean> ruleSets = getRuleSetDao().findByCrfVersionOrCrfAndStudyAndStudyEventDefinition(crfVersion, crf, study, sed);
    logger.info("getRuleSetsByCrfStudyAndStudyEventDefinition() : ruleSets Size {} : ", ruleSets.size());
    if (ruleSets != null && ruleSets.size() > 0) {
        for (RuleSetBean ruleSetBean : ruleSets) {
            getObjects(ruleSetBean);
        }
    } else {
        ruleSets = new ArrayList<RuleSetBean>();
    }
    return ruleSets;
// return eagerFetchRuleSet(ruleSets);
}
Also used : RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 15 with RuleSetBean

use of org.akaza.openclinica.domain.rule.RuleSetBean 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)

Aggregations

RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)67 ArrayList (java.util.ArrayList)28 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)26 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)19 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)15 HashMap (java.util.HashMap)13 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)9 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)9 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)8 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)7 Map (java.util.Map)6 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)6 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)5 RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)5 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)5 Locale (java.util.Locale)4