Search in sources :

Example 16 with CRFVersionBean

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

the class DynamicsMetadataService method insert.

private void insert(Integer itemDataId, List<PropertyBean> properties, UserAccountBean ub, RuleSetBean ruleSet, Status itemDataStatus, List<StratificationFactorBean> stratificationFactorBeans) {
    ItemDataBean itemDataBeanA = (ItemDataBean) getItemDataDAO().findByPK(itemDataId);
    EventCRFBean eventCrfBeanA = (EventCRFBean) getEventCRFDAO().findByPK(itemDataBeanA.getEventCRFId());
    StudyEventBean studyEventBeanA = (StudyEventBean) getStudyEventDAO().findByPK(eventCrfBeanA.getStudyEventId());
    ItemGroupMetadataBean itemGroupMetadataBeanA = (ItemGroupMetadataBean) getItemGroupMetadataDAO().findByItemAndCrfVersion(itemDataBeanA.getItemId(), eventCrfBeanA.getCRFVersionId());
    Boolean isGroupARepeating = isGroupRepeating(itemGroupMetadataBeanA);
    String itemGroupAOrdinal = getExpressionService().getGroupOrdninalCurated(ruleSet.getTarget().getValue());
    for (PropertyBean propertyBean : properties) {
        String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), ruleSet.getTarget().getValue());
        ItemBean itemBeanB = getExpressionService().getItemBeanFromExpression(expression);
        ItemGroupBean itemGroupBeanB = getExpressionService().getItemGroupExpression(expression);
        ItemGroupMetadataBean itemGroupMetadataBeanB = null;
        Boolean isGroupBRepeating = null;
        String itemGroupBOrdinal = null;
        EventCRFBean eventCrfBeanB = null;
        Boolean isItemInSameForm = getItemFormMetadataDAO().findByItemIdAndCRFVersionId(itemBeanB.getId(), eventCrfBeanA.getCRFVersionId()).getId() != 0 ? true : false;
        // Item Does not below to same form
        if (!isItemInSameForm) {
            List<EventCRFBean> eventCrfs = getEventCRFDAO().findAllByStudyEventAndCrfOrCrfVersionOid(studyEventBeanA, getExpressionService().getCrfOid(expression));
            if (eventCrfs.size() == 0) {
                CRFVersionBean crfVersion = getExpressionService().getCRFVersionFromExpression(expression);
                CRFBean crf = getExpressionService().getCRFFromExpression(expression);
                int crfVersionId = 0;
                EventDefinitionCRFBean eventDefinitionCRFBean = getEventDefinitionCRfDAO().findByStudyEventDefinitionIdAndCRFId(studyEventBeanA.getStudyEventDefinitionId(), crf.getId());
                if (eventDefinitionCRFBean.getId() != 0) {
                    crfVersionId = crfVersion != null ? crfVersion.getId() : eventDefinitionCRFBean.getDefaultVersionId();
                }
                // Create new event crf
                eventCrfBeanB = eventCrfBeanA.copy();
                eventCrfBeanB.setStatus(Status.AVAILABLE);
                eventCrfBeanB.setId(0);
                eventCrfBeanB.setCRFVersionId(crfVersionId);
                eventCrfBeanB = (EventCRFBean) getEventCRFDAO().create(eventCrfBeanB);
            } else {
                eventCrfBeanB = eventCrfs.get(0);
            }
        }
        if (isItemInSameForm) {
            eventCrfBeanB = eventCrfBeanA;
        }
        itemGroupMetadataBeanB = (ItemGroupMetadataBean) getItemGroupMetadataDAO().findByItemAndCrfVersion(itemBeanB.getId(), eventCrfBeanB.getCRFVersionId());
        isGroupBRepeating = isGroupRepeating(itemGroupMetadataBeanB);
        itemGroupBOrdinal = getExpressionService().getGroupOrdninalCurated(expression);
        // If A and B are both non repeating groups
        if (!isGroupARepeating && !isGroupBRepeating) {
            ItemDataBean oidBasedItemData = oneToOne(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, 1);
            oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
            if (itemDataStatus != null)
                oidBasedItemData.setStatus(itemDataStatus);
            getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
        }
        // If A is not repeating group & B is a repeating group with no index selected
        if (!isGroupARepeating && isGroupBRepeating && itemGroupBOrdinal.equals("")) {
            List<ItemDataBean> oidBasedItemDatas = oneToMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub);
            for (ItemDataBean oidBasedItemData : oidBasedItemDatas) {
                oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
                if (itemDataStatus != null)
                    oidBasedItemData.setStatus(itemDataStatus);
                getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
            }
        }
        // If A is not repeating group & B is a repeating group with index selected
        if (!isGroupARepeating && isGroupBRepeating && !itemGroupBOrdinal.equals("")) {
            ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupBOrdinal));
            oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
            if (itemDataStatus != null)
                oidBasedItemData.setStatus(itemDataStatus);
            getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
        }
        // If A is repeating/ non repeating group & B is a repeating group with index selected as END
        if (isGroupBRepeating && itemGroupBOrdinal.equals("END")) {
            ItemDataBean oidBasedItemData = oneToEndMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub);
            oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
            if (itemDataStatus != null)
                oidBasedItemData.setStatus(itemDataStatus);
            getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
        }
        // If A is repeating group with index & B is a repeating group with index selected
        if (isGroupARepeating && isGroupBRepeating && !itemGroupBOrdinal.equals("") && !itemGroupBOrdinal.equals("END")) {
            ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupBOrdinal));
            oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
            if (itemDataStatus != null)
                oidBasedItemData.setStatus(itemDataStatus);
            getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
        }
        // If A is repeating group with index & B is a repeating group with no index selected
        if (isGroupARepeating && isGroupBRepeating && itemGroupBOrdinal.equals("")) {
            ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupAOrdinal));
            oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
            if (itemDataStatus != null)
                oidBasedItemData.setStatus(itemDataStatus);
            getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
        }
    //            // If A is repeating group with index & B is none-repeating group
    //            if (isGroupARepeating && !isGroupBRepeating ) {
    //                ItemDataBean oidBasedItemData =
    //                        oneToOne(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, 1);
    //
    //                oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA));
    //                getItemDataDAO().updateValue(oidBasedItemData, "yyyy-MM-dd");
    //            }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DynamicsItemGroupMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemGroupMetadataBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) PropertyBean(org.akaza.openclinica.domain.rule.action.PropertyBean)

Example 17 with CRFVersionBean

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

the class RuleSetService method filterRuleSetsByStudyEventOrdinal.

@SuppressWarnings("unchecked")
public List<RuleSetBean> filterRuleSetsByStudyEventOrdinal(List<RuleSetBean> ruleSets, String crfVersionId) {
    ArrayList<RuleSetBean> validRuleSets = new ArrayList<RuleSetBean>();
    for (RuleSetBean ruleSetBean : ruleSets) {
        String studyEventDefinitionOrdinal = getExpressionService().getStudyEventDefinitionOrdninalCurated(ruleSetBean.getTarget().getValue());
        String studyEventDefinitionOid = getExpressionService().getStudyEventDefenitionOid(ruleSetBean.getTarget().getValue());
        String crfOrCrfVersionOid = getExpressionService().getCrfOid(ruleSetBean.getTarget().getValue());
        // whole expression is provided in target
        if (studyEventDefinitionOid != null && crfOrCrfVersionOid != null) {
            List<StudyEventBean> studyEvents = null;
            if (crfOrCrfVersionOid.equals("STARTDATE") || crfOrCrfVersionOid.equals("STATUS")) {
                StudyEventDefinitionBean sedBean = getStudyEventDefinitionDao().findByOid(studyEventDefinitionOid);
                studyEvents = (List<StudyEventBean>) getStudyEventDao().findAllByDefinition(sedBean.getId());
                logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
            } else {
                studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionOid, crfOrCrfVersionOid);
                logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
            }
            if (studyEventDefinitionOrdinal.equals("") && studyEvents.size() > 0) {
                for (StudyEventBean studyEvent : studyEvents) {
                    ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
                }
                validRuleSets.add(ruleSetBean);
            } else {
                for (StudyEventBean studyEvent : studyEvents) {
                    if (studyEventDefinitionOrdinal.equals(String.valueOf(studyEvent.getSampleOrdinal()))) {
                        ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
                    }
                }
                validRuleSets.add(ruleSetBean);
            }
        } else {
            // partial expression is provided in target
            CRFBean crf = null;
            List<CRFVersionBean> crfVersions = new ArrayList<CRFVersionBean>();
            CRFVersionBean crfVersion = null;
            if (crfOrCrfVersionOid == null) {
                crf = getCrfDao().findByItemOid(getExpressionService().getItemOid(ruleSetBean.getTarget().getValue()));
                if (crfVersionId != null) {
                    crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
                    crfVersions.add(crfVersion);
                } else {
                    crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
                }
            } else {
                crf = getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue());
                if (crfVersionId != null) {
                    crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
                } else {
                    crfVersion = getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue());
                }
                if (crfVersion != null) {
                    crfVersions.add(crfVersion);
                } else {
                    crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
                }
            }
            List<StudyEventDefinitionBean> studyEventDefinitions = getStudyEventDefinitionDao().findAllByCrf(crf);
            for (StudyEventDefinitionBean studyEventDefinitionBean : studyEventDefinitions) {
                for (CRFVersionBean crfVersionBean : crfVersions) {
                    String expression = getExpressionService().constructFullExpressionIfPartialProvided(ruleSetBean.getTarget().getValue(), crfVersionBean, studyEventDefinitionBean);
                    List<StudyEventBean> studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionBean.getOid(), crfVersionBean.getOid());
                    logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionBean.getOid(), crfVersionBean.getOid(), studyEvents.size() });
                    for (StudyEventBean studyEvent : studyEvents) {
                        ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent, expression));
                    }
                }
            }
            validRuleSets.add(ruleSetBean);
        }
    }
    logExpressions(validRuleSets);
    logger.debug("Size of RuleSets post filterRuleSetsByStudyEventOrdinal() {} ", validRuleSets.size());
    return validRuleSets;
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 18 with CRFVersionBean

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

the class ExpressionService method ruleExpressionChecker.

public boolean ruleExpressionChecker(String expression) {
    boolean result = false;
    boolean isRuleExpressionValid = false;
    isExpressionValid(expression);
    if (checkIfExpressionIsForScheduling(expression)) {
        if (checkSyntax(expression))
            return true;
        else
            return false;
    }
    if (expressionWrapper.getRuleSet() != null) {
        if (isExpressionPartial(expressionWrapper.getRuleSet().getTarget().getValue())) {
            return true;
        }
        String fullExpression = constructFullExpressionIfPartialProvided(expression, expressionWrapper.getRuleSet().getTarget().getValue());
        if (isExpressionPartial(expression)) {
            isRuleExpressionValid = checkSyntax(fullExpression);
        } else {
            isRuleExpressionValid = checkRuleExpressionSyntax(fullExpression);
        }
        if (isRuleExpressionValid) {
            isExpressionValid(fullExpression);
            result = true;
        }
        String targetGroupOid = getItemGroupOid(expressionWrapper.getRuleSet().getTarget().getValue());
        String ruleGroupOid = getItemGroupOid(fullExpression);
        CRFVersionBean targetCrfVersion = getCRFVersionFromExpression(expressionWrapper.getRuleSet().getTarget().getValue());
        CRFVersionBean ruleCrfVersion = getCRFVersionFromExpression(fullExpression);
        Boolean isTargetGroupRepeating = targetCrfVersion == null ? getItemGroupDao().isItemGroupRepeatingBasedOnAllCrfVersions(targetGroupOid) : getItemGroupDao().isItemGroupRepeatingBasedOnCrfVersion(targetGroupOid, targetCrfVersion.getId());
        Boolean isRuleGroupRepeating = ruleCrfVersion == null ? getItemGroupDao().isItemGroupRepeatingBasedOnAllCrfVersions(ruleGroupOid) : getItemGroupDao().isItemGroupRepeatingBasedOnCrfVersion(ruleGroupOid, ruleCrfVersion.getId());
        if (!isTargetGroupRepeating && isRuleGroupRepeating) {
            String ordinal = getItemGroupOidOrdinalFromExpression(fullExpression);
            if (ordinal.equals("") || ordinal.equals("ALL")) {
                result = false;
            }
        }
    } else {
        if (checkSyntax(expression) && getItemBeanFromExpression(expression) != null) {
            result = true;
        }
    }
    return result;
}
Also used : CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 19 with CRFVersionBean

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

the class ExpressionService method getCRFFromExpression.

public CRFBean getCRFFromExpression(String expression) {
    if (expression.split(ESCAPED_SEPERATOR).length < 3) {
        return null;
    }
    CRFBean crf;
    logger.debug("Expression : " + expression);
    logger.debug("Expression : " + getCrfOidFromExpression(expression));
    CRFVersionBean crfVersion = getCrfVersionDao().findByOid(getCrfOidFromExpression(expression));
    if (crfVersion != null) {
        int crfId = getCrfVersionDao().getCRFIdFromCRFVersionId(crfVersion.getId());
        crf = (CRFBean) getCrfDao().findByPK(crfId);
    } else {
        crf = getCrfDao().findByOid(getCrfOidFromExpression(expression));
    }
    return crf;
// return crfVersions.size() > 0 ? crfVersions.get(0) : null;
}
Also used : CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 20 with CRFVersionBean

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

the class RuleSetService method getRuleSetBeanByRuleSetRuleAndSubstituteCrfVersion.

// TODO: look into the commented line make sure logic doesn't break
private RuleSetBean getRuleSetBeanByRuleSetRuleAndSubstituteCrfVersion(String ruleSetRuleId, String crfVersionId, StudyBean currentStudy) {
    RuleSetBean ruleSetBean = null;
    if (ruleSetRuleId != null && crfVersionId != null && ruleSetRuleId.length() > 0 && crfVersionId.length() > 0) {
        RuleSetRuleBean ruleSetRule = getRuleSetRuleDao().findById(Integer.valueOf(ruleSetRuleId));
        // ruleSetBean = getRuleSetById(currentStudy, String.valueOf(ruleSetRule.getRuleSetBean().getId()), ruleSetRule.getRuleBean());
        ruleSetBean = ruleSetRule.getRuleSetBean();
        filterByRules(ruleSetBean, ruleSetRule.getRuleBean().getId());
        CRFVersionBean crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
        ruleSetBean = replaceCrfOidInTargetExpression(ruleSetBean, crfVersion.getOid());
    }
    return ruleSetBean;
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Aggregations

CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)100 ArrayList (java.util.ArrayList)70 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)61 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)54 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)53 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)46 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)44 HashMap (java.util.HashMap)38 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)37 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)36 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)33 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)32 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)30 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)30 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)25 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)22 Iterator (java.util.Iterator)20 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)20