Search in sources :

Example 16 with RuleSetRuleBean

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

the class RuleController method mapRulesToRulesPostImportContainer.

private RulesPostImportContainer mapRulesToRulesPostImportContainer(org.openclinica.ns.rules.v31.Rules rules) {
    RulesPostImportContainer rpic = new RulesPostImportContainer();
    for (RuleAssignmentType rat : rules.getRuleAssignment()) {
        TargetType targetType = rat.getTarget();
        ExpressionBean targetBean = new ExpressionBean(Context.OC_RULES_V1, targetType.getValue());
        RunOnScheduleType scheduleType = rules.getRuleAssignment().get(0).getRunOnSchedule();
        RuleSetBean ruleSetBean = new RuleSetBean();
        ruleSetBean.setOriginalTarget(targetBean);
        if (scheduleType != null) {
            if (!scheduleType.getTime().equals("")) {
                ruleSetBean.setRunTime(scheduleType.getTime());
            }
        }
        for (RuleRefType rrt : rat.getRuleRef()) {
            RuleSetRuleBean ruleSetRuleBean = new RuleSetRuleBean();
            ruleSetRuleBean.setOid(rrt.getOID());
            for (DiscrepancyNoteActionType discrepancyNoteActionType : rrt.getDiscrepancyNoteAction()) {
                DiscrepancyNoteActionBean action = new DiscrepancyNoteActionBean();
                action.setMessage(discrepancyNoteActionType.getMessage());
                action.setExpressionEvaluatesTo(Boolean.valueOf(discrepancyNoteActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(discrepancyNoteActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(discrepancyNoteActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(discrepancyNoteActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(discrepancyNoteActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(discrepancyNoteActionType.getRun().isBatch());
                ruleSetRuleBean.addAction(action);
            }
            for (EmailActionType emailActionType : rrt.getEmailAction()) {
                EmailActionBean action = new EmailActionBean();
                action.setMessage(emailActionType.getMessage());
                action.setTo(emailActionType.getTo());
                action.setExpressionEvaluatesTo(Boolean.valueOf(emailActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(emailActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(emailActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(emailActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(emailActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(emailActionType.getRun().isBatch());
                ruleSetRuleBean.addAction(action);
            }
            for (ShowActionType showActionType : rrt.getShowAction()) {
                ShowActionBean action = new ShowActionBean();
                action.setMessage(showActionType.getMessage());
                action.setExpressionEvaluatesTo(Boolean.valueOf(showActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(showActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(showActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(showActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(showActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(showActionType.getRun().isBatch());
                for (PropertyType propertyType : showActionType.getDestinationProperty()) {
                    PropertyBean property = new PropertyBean();
                    property.setOid(propertyType.getOID());
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (HideActionType hideActionType : rrt.getHideAction()) {
                HideActionBean action = new HideActionBean();
                action.setMessage(hideActionType.getMessage());
                action.setExpressionEvaluatesTo(Boolean.valueOf(hideActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(hideActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(hideActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(hideActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(hideActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(hideActionType.getRun().isBatch());
                for (PropertyType propertyType : hideActionType.getDestinationProperty()) {
                    PropertyBean property = new PropertyBean();
                    property.setOid(propertyType.getOID());
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (InsertActionType insertActionType : rrt.getInsertAction()) {
                InsertActionBean action = new InsertActionBean();
                action.setExpressionEvaluatesTo(Boolean.valueOf(insertActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(insertActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(insertActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(insertActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(insertActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(insertActionType.getRun().isBatch());
                ruleSetRuleBean.addAction(action);
                for (PropertyType propertyType : insertActionType.getDestinationProperty()) {
                    PropertyBean property = new PropertyBean();
                    property.setOid(propertyType.getOID());
                    property.setValue(propertyType.getValue());
                    ExpressionBean expressionBean = new ExpressionBean(Context.OC_RULES_V1, propertyType.getValueExpression().getValue());
                    property.setValueExpression(expressionBean);
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (EventActionType eventActionType : rrt.getEventAction()) {
                EventActionBean action = new EventActionBean();
                action.setExpressionEvaluatesTo(Boolean.valueOf(eventActionType.getIfExpressionEvaluates()));
                action.setOc_oid_reference(eventActionType.getOID());
                action.getRuleActionRun().setNot_started(eventActionType.getRunOnStatus().isNotScheduled());
                action.getRuleActionRun().setScheduled(eventActionType.getRunOnStatus().isScheduled());
                action.getRuleActionRun().setData_entry_started(eventActionType.getRunOnStatus().isDataEntryStarted());
                action.getRuleActionRun().setComplete(eventActionType.getRunOnStatus().isCompleted());
                action.getRuleActionRun().setSkipped(eventActionType.getRunOnStatus().isSkipped());
                action.getRuleActionRun().setStopped(eventActionType.getRunOnStatus().isStopped());
                for (EventDestinationType eventDestinationType : eventActionType.getEventDestination()) {
                    EventPropertyBean property = new EventPropertyBean();
                    property.setProperty(eventDestinationType.getProperty());
                    ExpressionBean expressionBean = new ExpressionBean(Context.OC_RULES_V1, eventDestinationType.getValueExpression().getValue());
                    property.setValueExpression(expressionBean);
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (NotificationActionType notificationActionType : rrt.getNotificationAction()) {
                NotificationActionBean action = new NotificationActionBean();
                action.setExpressionEvaluatesTo(Boolean.valueOf(notificationActionType.getIfExpressionEvaluates()));
                action.setTo(notificationActionType.getTo());
                action.setSubject(notificationActionType.getSubject());
                action.setMessage(notificationActionType.getMessage());
                ruleSetRuleBean.addAction(action);
            }
            ruleSetBean.addRuleSetRule(ruleSetRuleBean);
        }
        rpic.addRuleSet(ruleSetBean);
    }
    for (RuleDefType rdt : rules.getRuleDef()) {
        RuleBean ruleBean = new RuleBean();
        ExpressionBean ruleExpressionBean = new ExpressionBean(Context.OC_RULES_V1, rdt.getExpression().getValue());
        ruleBean.setExpression(ruleExpressionBean);
        ruleBean.setDescription(rdt.getDescription());
        ruleBean.setName(rdt.getName());
        ruleBean.setOid(rdt.getOID());
        rpic.addRuleDef(ruleBean);
    }
    return rpic;
}
Also used : DiscrepancyNoteActionBean(org.akaza.openclinica.domain.rule.action.DiscrepancyNoteActionBean) EventPropertyBean(org.akaza.openclinica.domain.rule.action.EventPropertyBean) RuleAssignmentType(org.openclinica.ns.rules.v31.RuleAssignmentType) DiscrepancyNoteActionType(org.openclinica.ns.rules.v31.DiscrepancyNoteActionType) PropertyType(org.openclinica.ns.rules.v31.PropertyType) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RunOnScheduleType(org.openclinica.ns.rules.v31.RunOnScheduleType) EventActionType(org.openclinica.ns.rules.v31.EventActionType) RuleRefType(org.openclinica.ns.rules.v31.RuleRefType) TargetType(org.openclinica.ns.rules.v31.TargetType) EmailActionBean(org.akaza.openclinica.domain.rule.action.EmailActionBean) EventDestinationType(org.openclinica.ns.rules.v31.EventDestinationType) ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) HideActionBean(org.akaza.openclinica.domain.rule.action.HideActionBean) ShowActionType(org.openclinica.ns.rules.v31.ShowActionType) HideActionType(org.openclinica.ns.rules.v31.HideActionType) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) InsertActionBean(org.akaza.openclinica.domain.rule.action.InsertActionBean) NotificationActionBean(org.akaza.openclinica.domain.rule.action.NotificationActionBean) NotificationActionType(org.openclinica.ns.rules.v31.NotificationActionType) InsertActionType(org.openclinica.ns.rules.v31.InsertActionType) RuleDefType(org.openclinica.ns.rules.v31.RuleDefType) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) EmailActionType(org.openclinica.ns.rules.v31.EmailActionType) RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) PropertyBean(org.akaza.openclinica.domain.rule.action.PropertyBean) EventPropertyBean(org.akaza.openclinica.domain.rule.action.EventPropertyBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 17 with RuleSetRuleBean

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

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

the class RuleSetService method loadRuleSetRuleWithPersistentRulesWithHashMap.

public void loadRuleSetRuleWithPersistentRulesWithHashMap(RuleSetBean ruleSetBean, HashMap<String, RuleBean> persistentRules) {
    for (RuleSetRuleBean ruleSetRule : ruleSetBean.getRuleSetRules()) {
        if (ruleSetRule.getId() == null) {
            String ruleOid = ruleSetRule.getOid();
            ruleSetRule.setRuleBean(persistentRules.get(ruleOid));
        }
    }
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 19 with RuleSetRuleBean

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

the class RuleSetService method updateRuleSet.

/*
     * (non-Javadoc)
     * @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#updateRuleSet(org.akaza.openclinica.domain.rule.RuleSetBean,
     * org.akaza.openclinica.bean.login.UserAccountBean, org.akaza.openclinica.domain.Status)
     */
public RuleSetBean updateRuleSet(RuleSetBean ruleSetBean, UserAccountBean user, Status status) {
    ruleSetBean.setStatus(status);
    ruleSetBean.setUpdater(user);
    for (RuleSetRuleBean ruleSetRuleBean : ruleSetBean.getRuleSetRules()) {
        ruleSetRuleBean.setStatus(status);
        ruleSetRuleBean.setUpdater(user);
    }
    ruleSetBean = saveRuleSet(ruleSetBean);
    ruleSetAuditDao.saveOrUpdate(createRuleSetAuditBean(ruleSetBean, user, status));
    return ruleSetBean;
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 20 with RuleSetRuleBean

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

the class RulesPostImportContainerService method addNewRuleSetBeanInList.

private void addNewRuleSetBeanInList(String target, String destination, List<RuleSetBean> eventActionsRuleSetBean) {
    ExpressionBean expression = new ExpressionBean();
    expression.setValue(target);
    RuleSetBean ruleSetBean = new RuleSetBean();
    ruleSetBean.setOriginalTarget(expression);
    EventActionBean eventActionBean = new EventActionBean();
    eventActionBean.setOc_oid_reference(destination);
    List<RuleActionBean> listRuleActionBean = new ArrayList<RuleActionBean>();
    listRuleActionBean.add(eventActionBean);
    RuleSetRuleBean ruleSetRuleBean = new RuleSetRuleBean();
    ruleSetRuleBean.setActions(listRuleActionBean);
    ruleSetBean.addRuleSetRule(ruleSetRuleBean);
    eventActionsRuleSetBean.add(ruleSetBean);
}
Also used : EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ArrayList(java.util.ArrayList) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) 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