Search in sources :

Example 61 with ItemBean

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

the class ExpressionService method isExpressionValid.

/**
     * 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
     */
public void isExpressionValid(String expression) {
    int length = expression.split(ESCAPED_SEPERATOR).length;
    ItemBean item = null;
    ItemGroupBean itemGroup = null;
    CRFBean crf = null;
    boolean isEventStartDateAndStatusParamExist = (expression.endsWith(STARTDATE) || expression.endsWith(STATUS));
    if (length > 0 && !isEventStartDateAndStatusParamExist) {
        item = getItemFromExpression(expression);
        if (item == null)
            throw new OpenClinicaSystemException("OCRERR_0023");
    // throw new OpenClinicaSystemException("item is Invalid");
    }
    if (length > 1 && !isEventStartDateAndStatusParamExist) {
        String itemGroupOid = getItemGroupOidFromExpression(expression);
        itemGroup = getItemGroupDao().findByOid(itemGroupOid);
        ArrayList<ItemGroupBean> igBean = (ArrayList<ItemGroupBean>) getItemGroupDao().findGroupsByItemID(item.getId());
        if (itemGroup == null || itemGroup.getId() != igBean.get(0).getId())
            throw new OpenClinicaSystemException("OCRERR_0022");
    // throw new OpenClinicaSystemException("itemGroup is Invalid");
    }
    if (length > 2 && !isEventStartDateAndStatusParamExist) {
        crf = getCRFFromExpression(expression);
        if (crf == null || crf.getId() != itemGroup.getCrfId())
            throw new OpenClinicaSystemException("OCRERR_0033");
    // throw new OpenClinicaSystemException("CRF is Invalid");
    }
    if (length > 3 && !isEventStartDateAndStatusParamExist) {
        StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
        crf = getCRFFromExpression(expression);
        if (studyEventDefinition == null || crf == null)
            throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
        // throw new
        // OpenClinicaSystemException("StudyEventDefinition is Invalid");
        EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
        if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0)
            throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
    // throw new
    // OpenClinicaSystemException("StudyEventDefinition is Invalid");
    }
    if (length == 2 && isEventStartDateAndStatusParamExist) {
        StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpressionForEventScheduling(expression);
        // studyEventDefinition.getOid());
        if (studyEventDefinition == null)
            throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
    }
    if (length != 2 && isEventStartDateAndStatusParamExist) {
        throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 62 with ItemBean

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

the class ExpressionService method getValueFromForm.

public String getValueFromForm(String expression, Map<String, ItemBean> itemBeans) {
    if (itemBeans == null)
        logger.debug("The Map that stores ItemBeans is null. Item Date value cannot be processed.");
    String result = null;
    HashMap<String, String> formValues = expressionWrapper.getItemsAndTheirValues();
    if (formValues != null && !formValues.isEmpty()) {
        String withGroup = getItemGroupPLusItem(expression);
        String withoutGroup = getItemOidFromExpression(expression);
        result = formValues.containsKey(withGroup) ? formValues.get(withGroup) : formValues.containsKey(withoutGroup) ? formValues.get(withoutGroup) : null;
        if (itemBeans != null) {
            ItemBean itemBean = itemBeans.containsKey(withGroup) ? itemBeans.get(withGroup) : itemBeans.containsKey(withoutGroup) ? itemBeans.get(withoutGroup) : null;
            result = ifValueIsDate(itemBean, result);
        }
    } else {
        logger.warn("The HashMap that stores form values was null, Better this be a Bulk operation");
    }
    return result;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean)

Example 63 with ItemBean

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

the class ExpressionService method checkValidityOfItemOrItemGroupOidInCrf.

public String checkValidityOfItemOrItemGroupOidInCrf(String oid, RuleSetBean ruleSet) {
    oid = oid.trim();
    String[] theOid = oid.split(ESCAPED_SEPERATOR);
    if (theOid.length == 2) {
        ItemGroupBean itemGroup = getItemGroupDao().findByOid(theOid[0]);
        Boolean isItemGroupBePartOfCrfOrNull = ruleSet.getCrfId() != null ? itemGroup.getCrfId().equals(ruleSet.getCrfId()) : true;
        if (itemGroup != null && isItemGroupBePartOfCrfOrNull) {
            if (ruleSet.getCrfId() != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
                return "OK";
            }
            if (ruleSet.getCrfId() != null && !itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
                return oid;
            }
            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) {
            if (ruleSet.getCrfId() != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
                return "OK";
            }
            if (ruleSet.getCrfId() != null && !itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
                return oid;
            }
            return "OK";
        }
        // ItemBean item =
        // getItemDao().findItemByGroupIdandItemOid(getItemGroupExpression(ruleSet.getTarget().getValue()).getId(),
        // oid);
        ArrayList<ItemBean> items = (ArrayList<ItemBean>) getItemDao().findByOid(oid);
        if (items == null || items.size() != 0) {
            return "OK";
        }
    }
    return oid;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ArrayList(java.util.ArrayList) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean)

Example 64 with ItemBean

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

the class ExpressionService method getItemFromExpression.

public ItemBean getItemFromExpression(String expression) {
    String itemKey = getItemOidFromExpression(expression);
    logger.debug("Expression : {} , Item OID : {}", expression, itemKey);
    if (items.containsKey(itemKey)) {
        return items.get(itemKey);
    } else {
        List<ItemBean> persistentItems = getItemDao().findByOid(itemKey);
        ItemBean item = persistentItems.size() > 0 ? persistentItems.get(0) : null;
        if (item != null) {
            items.put(itemKey, item);
            return item;
        } else {
            return null;
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean)

Example 65 with ItemBean

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

the class ExpressionService method deContextualizeExpression.

@SuppressWarnings("unchecked")
private String deContextualizeExpression(int j, String ruleExpression, String ruleSetTargetExpression) {
    String ruleSetExpression = ruleSetTargetExpression;
    String[] splitRuleSetExpression = ruleSetExpression.split(ESCAPED_SEPERATOR);
    String buildExpression = "";
    ItemBean item = null;
    String groupOidWithoutOrdinal = "";
    String groupOidFromItem = "";
    String repeatOrdinal = "";
    if (j == 3) {
        item = getItemFromExpression(ruleExpression);
        int indexOfOpenBrack = splitRuleSetExpression[2].indexOf("[");
        if (indexOfOpenBrack != -1) {
            groupOidWithoutOrdinal = splitRuleSetExpression[2].substring(0, indexOfOpenBrack);
        } else {
            groupOidWithoutOrdinal = splitRuleSetExpression[2];
        }
        ArrayList<ItemGroupBean> igBean = (ArrayList<ItemGroupBean>) getItemGroupDao().findGroupsByItemID(item.getId());
        groupOidFromItem = igBean.get(0).getOid();
    }
    for (int i = 0; i < j; i++) {
        if (j == 3 && i == 2 && !groupOidFromItem.equalsIgnoreCase(groupOidWithoutOrdinal)) {
            ArrayList<ItemFormMetadataBean> itemFormMetadataBeans = getItemFormMetadataDao().findAllByItemId(item.getId());
            List<ItemGroupMetadataBean> itemGroupMetadataBeans = getItemGroupMetadataDao().findByCrfVersion(itemFormMetadataBeans.get(0).getCrfVersionId());
            if (!itemGroupMetadataBeans.get(0).isRepeatingGroup()) {
                repeatOrdinal = "[1]";
            }
            buildExpression = buildExpression + groupOidFromItem + repeatOrdinal + SEPERATOR;
        } else {
            buildExpression = buildExpression + splitRuleSetExpression[i] + SEPERATOR;
        }
    }
    return buildExpression + ruleExpression;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ArrayList(java.util.ArrayList) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

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