Search in sources :

Example 86 with ItemBean

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

the class InsertActionValidator method validateValueExpressionInPropertyBean.

public void validateValueExpressionInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
    if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
        if (getExpressionService().getExpressionSize(propertyBean.getValueExpression().getValue()).intValue() > 2) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
        try {
            getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue());
        } catch (OpenClinicaSystemException ose) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
        // Use ValueExression in destinationProperty to get CRF
        ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getValueExpression().getValue());
        if (item == null)
            return;
        CRFBean destinationPropertyValueExpressionCrf = getCrfDAO().findByItemOid(item.getOid());
        // Use Target to get CRF
        CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
        if (targetCrf == null) {
            ItemBean targetItem = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
            targetCrf = getCrfDAO().findByItemOid(targetItem.getOid());
        }
        if (destinationPropertyValueExpressionCrf.getId() != targetCrf.getId()) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
    } else {
        String valueExpression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getValueExpression().getValue(), getRuleSetBean().getTarget().getValue());
        ItemBean item = getExpressionService().getItemBeanFromExpression(valueExpression);
        if (!getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue(), getRuleSetBean(), 2) || item == null) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 87 with ItemBean

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

the class RandomizeActionValidator method validateOidInPropertyBean.

public void validateOidInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
    if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
        if (getExpressionService().getExpressionSize(propertyBean.getOid()).intValue() > 3) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
        try {
            getExpressionService().isExpressionValid(propertyBean.getOid());
        } catch (OpenClinicaSystemException ose) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
        // Use OID in destinationProperty to get CRF
        CRFBean destinationPropertyOidCrf = getExpressionService().getCRFFromExpression(propertyBean.getOid());
        if (destinationPropertyOidCrf == null) {
            ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getOid());
            destinationPropertyOidCrf = getCrfDAO().findByItemOid(item.getOid());
        }
        // Use Target get CRF
        CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
        if (targetCrf == null) {
            ItemBean item = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
            targetCrf = getCrfDAO().findByItemOid(item.getOid());
        }
        // Get All event definitions the selected CRF belongs to
        List<StudyEventDefinitionBean> destinationPropertyStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(destinationPropertyOidCrf);
        List<StudyEventDefinitionBean> targetStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(targetCrf);
        Collection intersection = CollectionUtils.intersection(destinationPropertyStudyEventDefinitions, targetStudyEventDefinitions);
        if (intersection.size() == 0) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
    } else {
        String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), getRuleSetBean().getTarget().getValue());
        ItemBean item = getExpressionService().getItemBeanFromExpression(expression);
        if (!getExpressionService().isRandomizeActionExpressionValid(propertyBean.getOid(), getRuleSetBean(), 3) || item == null) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Collection(java.util.Collection) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 88 with ItemBean

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

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

the class CRFVersionDAO method generateDeleteQueries.

/**
     * Generates all the delete queries for deleting a version
     * 
     * @param versionId
     * @param items
     */
public ArrayList generateDeleteQueries(int versionId, ArrayList items) {
    ArrayList sqls = new ArrayList();
    String sql = digester.getQuery("deleteScdItemMetadataByVersion") + versionId + ")";
    sqls.add(sql);
    sql = digester.getQuery("deleteItemMetaDataByVersion") + versionId;
    sqls.add(sql);
    sql = digester.getQuery("deleteSectionsByVersion") + versionId;
    sqls.add(sql);
    sql = digester.getQuery("deleteItemMapByVersion") + versionId;
    sqls.add(sql);
    sql = digester.getQuery("deleteItemGroupMetaByVersion") + versionId;
    sqls.add(sql);
    for (int i = 0; i < items.size(); i++) {
        ItemBean item = (ItemBean) items.get(i);
        sql = digester.getQuery("deleteItemsByVersion") + item.getId();
        sqls.add(sql);
    }
    sql = digester.getQuery("deleteResponseSetByVersion") + versionId;
    sqls.add(sql);
    sql = digester.getQuery("delete") + versionId;
    sqls.add(sql);
    return sqls;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ArrayList(java.util.ArrayList)

Example 90 with ItemBean

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

the class CRFVersionDAO method findItemFromMap.

public Collection findItemFromMap(int versionId) {
    this.unsetTypeExpected();
    this.setTypeExpected(1, TypeNames.INT);
    this.setTypeExpected(2, TypeNames.STRING);
    this.setTypeExpected(3, TypeNames.INT);
    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(versionId));
    String sql = digester.getQuery("findItemFromMap");
    ArrayList alist = this.select(sql, variables);
    ArrayList al = new ArrayList();
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        ItemBean eb = new ItemBean();
        HashMap hm = (HashMap) it.next();
        eb.setId(((Integer) hm.get("item_id")).intValue());
        eb.setName((String) hm.get("name"));
        Integer ownerId = (Integer) hm.get("owner_id");
        eb.setOwnerId(ownerId.intValue());
        al.add(eb);
    }
    return al;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

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