Search in sources :

Example 21 with ItemBean

use of org.akaza.openclinica.bean.submit.ItemBean 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 22 with ItemBean

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

the class RuleSetService method filterRuleSetsByHiddenItems.

public List<RuleSetBean> filterRuleSetsByHiddenItems(List<RuleSetBean> ruleSets, EventCRFBean eventCrf, CRFVersionBean crfVersion, List<ItemBean> itemBeansWithSCDShown) {
    ArrayList<RuleSetBean> shownRuleSets = new ArrayList<RuleSetBean>();
    for (RuleSetBean ruleSetBean : ruleSets) {
        logMe("Entering the filterRuleSetsBy HiddenItems? Thread::" + Thread.currentThread() + "eventCrf?" + eventCrf + "crfVersion??" + crfVersion + "ruleSets?" + ruleSets);
        ItemBean target = ruleSetBean.getItem();
        ItemFormMetadataBean metadataBean = this.getItemFormMetadataDao().findByItemIdAndCRFVersionId(target.getId(), crfVersion.getId());
        ItemDataBean itemData = this.getItemDataDao().findByItemIdAndEventCRFId(target.getId(), eventCrf.getId());
        DynamicsItemFormMetadataBean dynamicsBean = this.getDynamicsItemFormMetadataDao().findByMetadataBean(metadataBean, eventCrf, itemData);
        if (itemBeansWithSCDShown == null)
            itemBeansWithSCDShown = new ArrayList<ItemBean>();
        if (dynamicsBean == null) {
            if (metadataBean.isShowItem() || itemBeansWithSCDShown.contains(target)) {
                logger.debug("just added rule set bean");
                shownRuleSets.add(ruleSetBean);
            }
        } else {
            if (metadataBean.isShowItem() || dynamicsBean.isShowItem()) {
                logger.debug("just added rule set bean 2, with dyn bean");
                shownRuleSets.add(ruleSetBean);
            }
        }
    }
    return shownRuleSets;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ArrayList(java.util.ArrayList) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 23 with ItemBean

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

the class ExpressionService method isExpressionValidOLD.

/**
     * Given a Complete Expression check business logic validity of each
     * component. Will throw OpenClinicaSystemException with correct
     * explanation. This might allow immediate communication of message to user
     * .
     * 
     * @param expression
     */
@Deprecated
public void isExpressionValidOLD(String expression) {
    StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
    CRFBean crf = getCRFFromExpression(expression);
    if (studyEventDefinition == null || crf == null)
        throw new OpenClinicaSystemException("OCRERR_0020");
    EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
    if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0 || eventDefinitionCrf.getStatus() != Status.AVAILABLE)
        throw new OpenClinicaSystemException("OCRERR_0021");
    ItemGroupBean itemGroup = getItemGroupExpression(expression, crf);
    if (itemGroup == null)
        throw new OpenClinicaSystemException("OCRERR_0022");
    ItemBean item = getItemExpression(expression, itemGroup);
    if (item == null)
        throw new OpenClinicaSystemException("OCRERR_0023");
    logger.debug("Study Event Definition ID : " + studyEventDefinition.getId());
    logger.debug("Crf ID : " + crf.getId());
    logger.debug("Event Definition CRF ID : " + eventDefinitionCrf.getId());
    logger.debug("Item ID : " + item.getId());
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 24 with ItemBean

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

the class ExpressionService method isExpressionValid.

public String isExpressionValid(String oid, RuleSetBean ruleSet) {
    StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(ruleSet.getTarget().getValue());
    String[] theOid = oid.split(ESCAPED_SEPERATOR);
    if (theOid.length == 3) {
        ItemGroupBean itemGroup = getItemGroupDao().findByOid(theOid[0]);
        if (itemGroup != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
            ItemBean item = getItemDao().findItemByGroupIdandItemOid(itemGroup.getId(), theOid[1]);
            if (item != null) {
                return "OK";
            }
        }
    }
    if (theOid.length == 2) {
        ItemGroupBean itemGroup = getItemGroupDao().findByOid(theOid[0]);
        if (itemGroup != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
            ItemBean item = getItemDao().findItemByGroupIdandItemOid(itemGroup.getId(), theOid[1]);
            if (item != null) {
                return "OK";
            }
        }
    }
    if (theOid.length == 1) {
        ItemGroupBean itemGroup = getItemGroupDao().findByOid(oid);
        if (itemGroup != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
            return "OK";
        }
        ItemBean item = getItemDao().findItemByGroupIdandItemOid(getItemGroupExpression(ruleSet.getTarget().getValue()).getId(), oid);
        if (item != null) {
            return "OK";
        }
    }
    return oid;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean)

Example 25 with ItemBean

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

the class ExpressionService method getValueFromDbb.

public HashMap<String, String> getValueFromDbb(String expression) throws OpenClinicaSystemException {
    HashMap<String, String> map = new HashMap<>();
    if (isExpressionPartial(expression)) {
        throw new OpenClinicaSystemException("getValueFromDb:We cannot get the Value of a PARTIAL expression : " + expression);
    }
    try {
        // Get the studyEventId from RuleSet Target so we can know which
        // StudySubject we are dealing with.
        String ruleSetExpression = expressionWrapper.getRuleSet().getTarget().getValue();
        String ruleSetExpressionStudyEventId = getStudyEventDefinitionOidOrdinalFromExpression(ruleSetExpression);
        StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(ruleSetExpressionStudyEventId));
        // Prepare Method arguments
        String studyEventDefinitionOid = getStudyEventDefinitionOidFromExpression(expression);
        String crfOrCrfVersionOid = getCrfOidFromExpression(expression);
        String studyEventDefinitionOrdinal = getStudyEventDefinitionOidOrdinalFromExpression(expression);
        studyEventDefinitionOrdinal = studyEventDefinitionOrdinal.equals("") ? "1" : studyEventDefinitionOrdinal;
        String studySubjectId = String.valueOf(studyEvent.getStudySubjectId());
        System.out.println("studySubjectId:  " + studySubjectId);
        logger.debug("ruleSet studyEventId  {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEventDefinitionOrdinal {} ,studySubjectId {}", new Object[] { studyEvent.getId(), studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId });
        StudyEventBean studyEventofThisExpression = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOidsAndOrdinal(studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId);
        if (studyEvent.getId() == studyEventofThisExpression.getId())
            map.put("match", "true");
        logger.debug("studyEvent : {} , itemOid {} , itemGroupOid {}", new Object[] { studyEventofThisExpression.getId(), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression) });
        List<ItemDataBean> itemData = getItemDataDao().findByStudyEventAndOids(Integer.valueOf(studyEventofThisExpression.getId()), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression));
        expression = fixGroupOrdinal(expression, ruleSetExpression, itemData, expressionWrapper.getEventCrf());
        Integer index = getItemGroupOidOrdinalFromExpression(expression).equals("") ? 0 : Integer.valueOf(getItemGroupOidOrdinalFromExpression(expression)) - 1;
        ItemDataBean itemDataBean = itemData.get(index);
        ItemBean itemBean = (ItemBean) getItemDao().findByPK(itemDataBean.getItemId());
        String value = itemData.get(index).getValue();
        value = ifValueIsDate(itemBean, value);
        map.put("value", value);
        return map;
    } catch (Exception e) {
        return map;
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Aggregations

ItemBean (org.akaza.openclinica.bean.submit.ItemBean)132 ArrayList (java.util.ArrayList)77 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)56 HashMap (java.util.HashMap)50 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)43 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)42 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)36 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)26 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)25 Iterator (java.util.Iterator)23 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)22 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)22 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)21 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)20 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)15 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)15 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)13 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)13 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)13