Search in sources :

Example 56 with RuleSetBean

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

the class ViewRuleAssignmentServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    List<RuleSetBean> ruleSets = getRuleSetService().getRuleSetsByStudy(currentStudy);
    ruleSets = getRuleSetService().filterByStatusEqualsAvailableOnlyRuleSetRules(ruleSets);
    EntityBeanTable table = fp.getWebEntityBeanTable();
    ArrayList allRows = ViewRuleAssignmentRow.generateRowsFromBeans((ArrayList) ruleSets);
    String[] columns = { resword.getString("rule_study_event_definition"), resword.getString("CRF_name"), resword.getString("rule_group_label"), resword.getString("rule_item_name"), resword.getString("rule_rules"), resword.getString("rule_ref_oid"), resword.getString("rule_action_type"), resword.getString("actions") };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.hideColumnLink(4);
    table.hideColumnLink(5);
    table.hideColumnLink(6);
    table.setQuery("ViewRuleAssignment", new HashMap());
    // table.addLink(resword.getString("rule_import_rule"), "ImportRule");
    table.addLink(resword.getString("test_rule_title"), "TestRule");
    table.setRows(allRows);
    table.computeDisplay();
    request.setAttribute("table", table);
    if (request.getParameter("read") != null && request.getParameter("read").equals("true")) {
        request.setAttribute("readOnly", true);
    }
    forwardPage(Page.VIEW_RULE_SETS);
}
Also used : HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.domain.EntityBeanTable) ArrayList(java.util.ArrayList) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 57 with RuleSetBean

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

the class StudyEventBeanListener method update.

@Override
public void update(Listener lstnr) {
    //	System.out.println("Triggering the rules based on event updates");
    StudyEventBeanContainer studyEventBeanContainer = (StudyEventBeanContainer) lstnr;
    //	if (studyEventBeanContainer.getChangeDetails().getStartDateChanged() || studyEventBeanContainer.getChangeDetails().getStatusChanged()){
    Integer studyEventDefId = studyEventBeanContainer.getEvent().getStudyEventDefinitionId();
    //		Integer studySubjectId = studyEventBeanContainer.getEvent().getStudySubjectId();
    Integer userId = studyEventBeanContainer.getEvent().getUpdaterId();
    Integer studyEventOrdinal = studyEventBeanContainer.getEvent().getSampleOrdinal();
    if (userId == 0)
        userId = studyEventBeanContainer.getEvent().getOwnerId();
    StudyEventBean studyEvent = studyEventBeanContainer.getEvent();
    ArrayList<RuleSetBean> ruleSets = (ArrayList<RuleSetBean>) createRuleSet(studyEventDefId);
    for (RuleSetBean ruleSet : ruleSets) {
        ArrayList<RuleSetBean> ruleSetBeans = new ArrayList();
        ExpressionBean eBean = new ExpressionBean();
        eBean.setValue(ruleSet.getTarget().getValue() + ".A.B");
        ruleSet.setTarget(eBean);
        ruleSet.addExpression(getRuleSetService().replaceSEDOrdinal(ruleSet.getTarget(), studyEvent));
        ruleSetBeans.add(ruleSet);
        // for (RuleSetBean ruleSet : ruleSetBeans){
        String targetProperty = ruleSet.getTarget().getValue().substring(ruleSet.getTarget().getValue().indexOf("."));
        if ((targetProperty.contains(ExpressionService.STARTDATE + ".A.B") && studyEventBeanContainer.getChangeDetails().getStartDateChanged()) || (targetProperty.contains(ExpressionService.STATUS + ".A.B") && studyEventBeanContainer.getChangeDetails().getStatusChanged())) {
            getRuleSetService().runIndividualRulesInBeanProperty(ruleSetBeans, userId, studyEventBeanContainer.getChangeDetails(), studyEventOrdinal);
        }
    }
//	}
}
Also used : ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudyEventBeanContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventBeanContainer) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 58 with RuleSetBean

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

the class RulesPostImportContainerService method validateRuleSetDefs.

public RulesPostImportContainer validateRuleSetDefs(RulesPostImportContainer importContainer) {
    List<RuleSetBean> eventActionsRuleSetBean = getRuleSetDao().findAllEventActions(currentStudy);
    for (RuleSetBean ruleSetBean : importContainer.getRuleSets()) {
        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();
                if (ruleSetBean.getRunTime() != null) {
                    if (ruleSetBean.getRunOnSchedule() == null) {
                        ruleSetBean.setRunOnSchedule(new RunOnSchedule(ruleSetBean.getRunTime()));
                    }
                }
                if (ruleSetBean.getRunOnSchedule() != null) {
                    persistentRuleSetBean.setRunSchedule(true);
                    if (ruleSetBean.getRunOnSchedule().getRunTime() != null) {
                        if (isRunTimeValid(ruleSetBeanWrapper, ruleSetBean.getRunOnSchedule().getRunTime())) {
                            persistentRuleSetBean.setRunTime(ruleSetBean.getRunOnSchedule().getRunTime());
                        }
                    } else {
                        // supposed to act like 23:00
                        persistentRuleSetBean.setRunTime(null);
                    }
                } else {
                    persistentRuleSetBean.setRunSchedule(false);
                    persistentRuleSetBean.setRunTime(null);
                }
                persistentRuleSetBean.setUpdaterAndDate(getUserAccount());
                ruleSetBeanWrapper.setAuditableBean(persistentRuleSetBean);
                Iterator<RuleSetRuleBean> itr = importedRuleSetRules.iterator();
                while (itr.hasNext()) {
                    RuleSetRuleBean ruleSetRuleBean = itr.next();
                    ruleSetRuleBean.setRuleBean(getRuleDao().findByOid(ruleSetRuleBean.getOid(), persistentRuleSetBean.getStudyId()));
                    // ruleSetRuleBean.setRuleSetBean(ruleSetBeanWrapper.getAuditableBean());
                    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 {
                if (importContainer.getValidRuleSetExpressionValues().contains(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue())) {
                    ruleSetBeanWrapper.error(createError("OCRERR_0031"));
                }
                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()));
                if (ruleSetBean.getRunTime() != null) {
                    if (ruleSetBean.getRunOnSchedule() == null) {
                        ruleSetBeanWrapper.getAuditableBean().setRunOnSchedule(new RunOnSchedule(ruleSetBean.getRunTime()));
                    }
                }
                if (ruleSetBean.getRunOnSchedule() != null) {
                    ruleSetBeanWrapper.getAuditableBean().setRunSchedule(true);
                    if (ruleSetBean.getRunOnSchedule().getRunTime() != null) {
                        //validate Time           isRunTimeValid
                        if (isRunTimeValid(ruleSetBeanWrapper, ruleSetBean.getRunOnSchedule().getRunTime())) {
                            ruleSetBeanWrapper.getAuditableBean().setRunTime(ruleSetBean.getRunOnSchedule().getRunTime());
                        }
                    } else {
                        // supposed to act like DEFAULT_TIME
                        ruleSetBeanWrapper.getAuditableBean().setRunTime(null);
                    }
                } else {
                    ruleSetBeanWrapper.getAuditableBean().setRunSchedule(false);
                    ruleSetBeanWrapper.getAuditableBean().setRunTime(null);
                }
            }
            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) RunOnSchedule(org.akaza.openclinica.domain.rule.RunOnSchedule) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 59 with RuleSetBean

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

the class RuleSetService method getRuleSetById.

/*
     * (non-Javadoc)
     * @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#getRuleSetById(org.akaza.openclinica.bean.managestudy.StudyBean, java.lang.String,
     * org.akaza.openclinica.domain.rule.RuleBean)
     */
public List<RuleSetRuleBean> getRuleSetById(StudyBean study, String id, RuleBean ruleBean) {
    logger.debug(" Study Id {} ", study.getId());
    RuleSetBean ruleSetBean = getRuleSetDao().findById(Integer.valueOf(id));
    return getRuleSetRuleDao().findByRuleSetBeanAndRuleBean(ruleSetBean, ruleBean);
}
Also used : RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 60 with RuleSetBean

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

the class RuleSetService method logExpressions.

private void logExpressions(List<RuleSetBean> validRuleSets) {
    if (logger.isDebugEnabled()) {
        for (RuleSetBean ruleSetBean : validRuleSets) {
            logger.debug("Expression : {} ", ruleSetBean.getTarget().getValue());
            List<ExpressionBean> expressions = ruleSetBean.getExpressions();
            if (expressions != null) {
                for (ExpressionBean expression : expressions) {
                    logger.debug("Expression post filtering SEDs : {} ", expression.getValue());
                }
            }
        }
    }
}
Also used : 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