Search in sources :

Example 76 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class DynamicsMetadataService method oneToManyOld.

@Deprecated
private void oneToManyOld(ItemDataBean itemDataBeanA, EventCRFBean eventCrfBeanA, ItemGroupMetadataBean itemGroupMetadataBeanA, ItemBean itemBeanB, ItemGroupBean itemGroupBeanB, ItemGroupMetadataBean itemGroupMetadataBeanB, EventCRFBean eventCrfBeanB, UserAccountBean ub, String value) {
    //List<ItemDataBean> itemDataBeans = new ArrayList<ItemDataBean>();
    Integer size = getItemDataDAO().getGroupSize(itemBeanB.getId(), eventCrfBeanB.getId());
    int maxOrdinal = getItemDataDAO().getMaxOrdinalForGroupByItemAndEventCrf(itemBeanB.getId(), eventCrfBeanB);
    if (size > 0 || maxOrdinal > 0) {
        List<ItemDataBean> itemDataBeans = getItemDataDAO().findAllByEventCRFIdAndItemId(eventCrfBeanB.getId(), itemBeanB.getId());
        for (ItemDataBean oidBasedItemData : itemDataBeans) {
            oidBasedItemData.setValue(value);
            getItemDataDAO().updateValue(oidBasedItemData, "yyyy-MM-dd");
        }
    } else {
        List<ItemBean> items = getItemDAO().findAllItemsByGroupId(itemGroupBeanB.getId(), eventCrfBeanB.getCRFVersionId());
        for (int ordinal = 1 + maxOrdinal; ordinal <= itemGroupMetadataBeanB.getRepeatNum() + maxOrdinal; ordinal++) {
            for (ItemBean itemBeanX : items) {
                ItemDataBean oidBasedItemData = getItemData(itemBeanX, eventCrfBeanB, ordinal);
                if (oidBasedItemData.getId() == 0) {
                    oidBasedItemData = createItemData(oidBasedItemData, itemBeanX, ordinal, eventCrfBeanB, ub);
                }
                if (itemBeanX.getId() == itemBeanB.getId()) {
                    oidBasedItemData.setValue(value);
                    getItemDataDAO().updateValue(oidBasedItemData, "yyyy-MM-dd");
                }
            }
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Example 77 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class DynamicsMetadataService method oneToIndexedMany.

private ItemDataBean oneToIndexedMany(ItemDataBean itemDataBeanA, EventCRFBean eventCrfBeanA, ItemGroupMetadataBean itemGroupMetadataBeanA, ItemBean itemBeanB, ItemGroupBean itemGroupBeanB, ItemGroupMetadataBean itemGroupMetadataBeanB, EventCRFBean eventCrfBeanB, UserAccountBean ub, int index) {
    ItemDataBean theOidBasedItemData = null;
    int size = getItemDataDAO().getGroupSize(itemBeanB.getId(), eventCrfBeanB.getId());
    int maxOrdinal = getItemDataDAO().getMaxOrdinalForGroupByItemAndEventCrf(itemBeanB.getId(), eventCrfBeanB);
    if (size > 0 && size >= index) {
        List<ItemDataBean> theItemDataBeans = getItemDataDAO().findAllByEventCRFIdAndItemId(eventCrfBeanB.getId(), itemBeanB.getId());
        theOidBasedItemData = theItemDataBeans.get(index - 1);
    } else {
        List<ItemBean> items = getItemDAO().findAllItemsByGroupId(itemGroupBeanB.getId(), eventCrfBeanB.getCRFVersionId());
        int number = itemGroupMetadataBeanB.getRepeatNum() > index ? itemGroupMetadataBeanB.getRepeatNum() : index <= itemGroupMetadataBeanB.getRepeatMax() ? index : 0;
        for (int ordinal = 1 + maxOrdinal; ordinal <= number + maxOrdinal - size; ordinal++) {
            for (ItemBean itemBeanX : items) {
                ItemDataBean oidBasedItemData = getItemData(itemBeanX, eventCrfBeanB, ordinal);
                if (oidBasedItemData.getId() == 0) {
                    oidBasedItemData = createItemData(oidBasedItemData, itemBeanX, ordinal, eventCrfBeanB, ub);
                }
            }
        }
        List<ItemDataBean> theItemDataBeans = getItemDataDAO().findAllByEventCRFIdAndItemId(eventCrfBeanB.getId(), itemBeanB.getId());
        theOidBasedItemData = theItemDataBeans.get(index - 1);
    }
    return theOidBasedItemData;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Example 78 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class DynamicsMetadataService method oneToEndMany.

private ItemDataBean oneToEndMany(ItemDataBean itemDataBeanA, EventCRFBean eventCrfBeanA, ItemGroupMetadataBean itemGroupMetadataBeanA, ItemBean itemBeanB, ItemGroupBean itemGroupBeanB, ItemGroupMetadataBean itemGroupMetadataBeanB, EventCRFBean eventCrfBeanB, UserAccountBean ub) {
    ItemDataBean theOidBasedItemData = null;
    int size = getItemDataDAO().getGroupSize(itemBeanB.getId(), eventCrfBeanB.getId());
    int maxOrdinal = getItemDataDAO().getMaxOrdinalForGroupByItemAndEventCrf(itemBeanB.getId(), eventCrfBeanB);
    List<ItemBean> items = getItemDAO().findAllItemsByGroupId(itemGroupBeanB.getId(), eventCrfBeanB.getCRFVersionId());
    if (1 + maxOrdinal > itemGroupMetadataBeanB.getRepeatMax()) {
        logger.debug("Cannot add new repeat of this group because it has reached MaxRepeat.");
    } else {
        for (ItemBean itemBeanX : items) {
            ItemDataBean oidBasedItemData = getItemData(itemBeanX, eventCrfBeanB, 1 + maxOrdinal);
            if (oidBasedItemData.getId() == 0) {
                oidBasedItemData = createItemData(oidBasedItemData, itemBeanX, 1 + maxOrdinal, eventCrfBeanB, ub);
            }
        }
    }
    List<ItemDataBean> theItemDataBeans = getItemDataDAO().findAllByEventCRFIdAndItemId(eventCrfBeanB.getId(), itemBeanB.getId());
    theOidBasedItemData = theItemDataBeans.get(theItemDataBeans.size() - 1);
    return theOidBasedItemData;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Example 79 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class ExpressionService method evaluateExpression.

public String evaluateExpression(String expression) throws OpenClinicaSystemException {
    String value = null;
    Map<Integer, ItemBean> itemBeansI = new HashMap<Integer, ItemBean>();
    if (items != null) {
        Iterator<ItemBean> iter = items.values().iterator();
        while (iter.hasNext()) {
            ItemBean item = iter.next();
            itemBeansI.put(item.getId(), item);
        }
    }
    if (expressionWrapper.getRuleSet() != null) {
        if (checkIfExpressionIsForScheduling(expression)) {
            StudyEvent studyEvent;
            if (expression.endsWith(this.STARTDATE)) {
                String oid = expression.substring(0, expression.indexOf(this.STARTDATE));
                studyEvent = getStudyEventFromOID(oid);
                if (studyEvent != null) {
                    logger.debug("Study Event Start Date: " + studyEvent.getDateStart().toString().substring(0, 10).trim());
                    return studyEvent.getDateStart().toString().substring(0, 10).trim();
                } else
                    return "";
            } else {
                String oid = expression.substring(0, expression.indexOf(this.STATUS));
                studyEvent = getStudyEventFromOID(oid);
                if (studyEvent != null) {
                    logger.debug("Status: " + SubjectEventStatus.getSubjectEventStatusName(studyEvent.getSubjectEventStatusId()));
                    return SubjectEventStatus.getSubjectEventStatusName(studyEvent.getSubjectEventStatusId());
                } else
                    return "";
            }
        }
        if (isExpressionPartial(expression)) {
            String fullExpression = constructFullExpressionIfPartialProvided(expression, expressionWrapper.getRuleSet().getTarget().getValue());
            List<ItemDataBean> itemDatas = getItemDatas(fullExpression);
            fullExpression = fixGroupOrdinal(fullExpression, expressionWrapper.getRuleSet().getTarget().getValue(), itemDatas, expressionWrapper.getEventCrf());
            if (checkSyntax(fullExpression)) {
                String valueFromForm = null;
                if (items == null) {
                    valueFromForm = getValueFromForm(fullExpression);
                } else {
                    valueFromForm = getValueFromForm(fullExpression, items);
                }
                String valueFromDb = null;
                if (itemBeansI == null) {
                    valueFromDb = getValueFromDb(fullExpression, itemDatas);
                } else {
                    valueFromDb = getValueFromDb(fullExpression, itemDatas, itemBeansI);
                }
                logger.debug("valueFromForm : {} , valueFromDb : {}", valueFromForm, valueFromDb);
                if (valueFromForm == null && valueFromDb == null) {
                    throw new OpenClinicaSystemException("OCRERR_0017", new Object[] { fullExpression, expressionWrapper.getRuleSet().getTarget().getValue() });
                }
                /*
                     * if (valueFromForm != null) { // TODO: Do this if type a
                     * date String dateFormat =
                     * ResourceBundleProvider.getFormatBundle
                     * ().getString("date_format_string"); String dateRegexp =
                     * ResourceBundleProvider
                     * .getFormatBundle().getString("date_regexp");
                     * valueFromForm =
                     * ExpressionTreeHelper.isValidDate(valueFromForm,
                     * dateFormat, dateRegexp); }
                     */
                value = valueFromForm == null ? valueFromDb : valueFromForm;
            }
        } else {
            // So Expression is not Partial
            HashMap<String, String> map = getValueFromDbb(expression);
            String valueFromDb = null;
            String matchEvents = null;
            String valueFromForm = null;
            if (checkSyntax(expression)) {
                valueFromDb = map.get("value");
                matchEvents = map.get("match");
                // if se_id are a match go in , otherwise nothing
                if (matchEvents != null && matchEvents.equals("true")) {
                    if (items == null) {
                        valueFromForm = getValueFromForm(expression);
                    } else {
                        valueFromForm = getValueFromForm(expression, items);
                    }
                }
                logger.debug("valueFromDb : {}", valueFromDb);
                value = valueFromForm == null ? valueFromDb : valueFromForm;
                if (value == null) {
                    logger.info("The value is " + value + "  for expression" + expression);
                    throw new OpenClinicaSystemException("OCRERR_0018", new Object[] { expression });
                }
            }
        }
    }
    return value;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 80 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class Key method runRulesBulk.

public HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>> runRulesBulk(List<RuleSetBean> ruleSets, ExecutionMode executionMode, 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>();
    }
    HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>> crfViewSpecificOrderedObjects = new HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>>();
    HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
    for (RuleSetBean ruleSet : ruleSets) {
        String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue());
        List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null;
        if (toBeExecuted.containsKey(key)) {
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        } else {
            toBeExecuted.put(key, new ArrayList<RuleActionContainer>());
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        }
        ItemDataBean itemData = null;
        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());
                    itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
                    // Actions
                    List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
                    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();
                            }
                        }
                    }
                    for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
                        RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet);
                        allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer);
                    }
                    logger.info("RuleSet with target  : {} , Ran Rule : {}  The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() });
                } catch (OpenClinicaSystemException osa) {
                // TODO: report something useful 
                }
            }
        }
    }
    for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
        // Sort the list of actions
        Collections.sort(entry.getValue(), new RuleActionContainerComparator());
        HashMap<Key, List<RuleActionBean>> hms = new HashMap<Key, List<RuleActionBean>>();
        for (RuleActionContainer ruleActionContainer : entry.getValue()) {
            //ruleSet.setTarget(ruleAction.getRuleSetExpression());
            ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
            ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
            RuleActionBean rab = null;
            ap.execute(RuleRunnerMode.RULSET_BULK, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
            if (rab != null) {
                Key k = new Key(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getExpressionEvaluatesTo().toString(), ruleActionContainer.getRuleAction().getRuleSetRule().getRuleBean());
                if (hms.containsKey(k)) {
                    hms.get(k).add(ruleActionContainer.getRuleAction());
                } else {
                    List<RuleActionBean> theActionBeansToShow = new ArrayList<RuleActionBean>();
                    theActionBeansToShow.add(ruleActionContainer.getRuleAction());
                    hms.put(k, theActionBeansToShow);
                }
            }
        }
        for (Map.Entry<Key, List<RuleActionBean>> theEntry : hms.entrySet()) {
            Key key = theEntry.getKey();
            List<RuleActionBean> value = theEntry.getValue();
            crfViewSpecificOrderedObjects = populateForCrfBasedRulesView(crfViewSpecificOrderedObjects, key.getRuleSet(), key.getRule(), key.getResult(), currentStudy, value);
        }
    }
    //logCrfViewSpecificOrderedObjects(crfViewSpecificOrderedObjects);
    return crfViewSpecificOrderedObjects;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) List(java.util.List) RuleBulkExecuteContainer(org.akaza.openclinica.domain.rule.RuleBulkExecuteContainer) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) RuleBulkExecuteContainerTwo(org.akaza.openclinica.domain.rule.RuleBulkExecuteContainerTwo) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) HashMap(java.util.HashMap) Map(java.util.Map) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Aggregations

ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)133 ArrayList (java.util.ArrayList)74 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)64 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)61 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)42 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)41 HashMap (java.util.HashMap)39 Date (java.util.Date)37 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)37 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)33 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)33 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)26 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)26 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)26 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)21 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)21 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)20 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)20 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)18