Search in sources :

Example 1 with ItemDataType

use of org.akaza.openclinica.bean.core.ItemDataType in project OpenClinica by OpenClinica.

the class DataEntryServlet method validateDisplayItemBeanText.

/**
 * Peform validation on a item which has a TEXT or TEXTAREA response type. If the item has a null value, it's automatically validated. Otherwise, it's
 * checked against its data type.
 *
 * @param v
 *            The Validator to add validations to.
 * @param dib
 *            The DisplayItemBean to validate.
 * @param request TODO
 * @return The DisplayItemBean which is validated.
 */
protected DisplayItemBean validateDisplayItemBeanText(DiscrepancyValidator v, DisplayItemBean dib, String inputName, HttpServletRequest request) {
    FormProcessor fp = new FormProcessor(request);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    if (StringUtil.isBlank(inputName)) {
        // for single items
        inputName = getInputName(dib);
    }
    ItemBean ib = dib.getItem();
    ItemFormMetadataBean ibMeta = dib.getMetadata();
    ItemDataType idt = ib.getDataType();
    ItemDataBean idb = dib.getData();
    boolean isNull = false;
    ArrayList nullValues = edcb.getNullValuesList();
    for (int i = 0; i < nullValues.size(); i++) {
        NullValue nv = (NullValue) nullValues.get(i);
        if (nv.getName().equals(fp.getString(inputName))) {
            isNull = true;
        }
    }
    if (!isNull) {
        if (StringUtil.isBlank(idb.getValue())) {
            // check required first
            if (ibMeta.isRequired() && ibMeta.isShowItem()) {
                v.addValidation(inputName, Validator.IS_REQUIRED);
            }
        } else {
            if (idt.equals(ItemDataType.ST)) {
                // a string's size could be more than 3999, which is more
                // than
                // the db field length
                v.addValidation(inputName, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 3999);
            } else if (idt.equals(ItemDataType.INTEGER)) {
                v.addValidation(inputName, Validator.IS_AN_INTEGER);
                v.alwaysExecuteLastValidation(inputName);
            } else if (idt.equals(ItemDataType.REAL)) {
                v.addValidation(inputName, Validator.IS_A_NUMBER);
                v.alwaysExecuteLastValidation(inputName);
            } else if (idt.equals(ItemDataType.BL)) {
            // there is no validation here since this data type is
            // explicitly
            // allowed to be null
            // if the string input for this field parses to a non-zero
            // number, the
            // value will be true; otherwise, 0
            } else if (idt.equals(ItemDataType.BN)) {
            } else if (idt.equals(ItemDataType.SET)) {
                // v.addValidation(inputName, Validator.NO_BLANKS_SET);
                v.addValidation(inputName, Validator.IN_RESPONSE_SET_SINGLE_VALUE, dib.getMetadata().getResponseSet());
            } else if (idt.equals(ItemDataType.DATE)) {
                v.addValidation(inputName, Validator.IS_A_DATE);
                v.alwaysExecuteLastValidation(inputName);
            } else if (idt.equals(ItemDataType.PDATE)) {
                v.addValidation(inputName, Validator.IS_PARTIAL_DATE);
                v.alwaysExecuteLastValidation(inputName);
            }
            if (ibMeta.getWidthDecimal().length() > 0) {
                ArrayList<String> params = new ArrayList<String>();
                params.add(0, idt.getName());
                params.add(1, ibMeta.getWidthDecimal());
                v.addValidation(inputName, Validator.IS_VALID_WIDTH_DECIMAL, params);
                v.alwaysExecuteLastValidation(inputName);
            }
            // >> tbh 4/30/2010 #4963 removing custom validations firing during AE
            customValidation(v, dib, inputName);
        /*
                 * if (!StringUtil.isBlank(customValidationString)) { Validation customValidation = null; if (customValidationString.startsWith("func:")) { try
                 * { customValidation = Validator.processCRFValidationFunction(customValidationString ); } catch (Exception e) { e.printStackTrace(); } } else
                 * if (customValidationString.startsWith("regexp:")) { try { customValidation = Validator.processCRFValidationRegex(customValidationString); }
                 * catch (Exception e) { } } if (customValidation != null) { customValidation .setErrorMessage(dib.getMetadata().getRegexpErrorMsg());
                 * v.addValidation(inputName, customValidation); } }
                 */
        }
    }
    return dib;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) NullValue(org.akaza.openclinica.bean.core.NullValue) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 2 with ItemDataType

use of org.akaza.openclinica.bean.core.ItemDataType in project OpenClinica by OpenClinica.

the class ItemDataDAO method getEntityFromHashMap.

public Object getEntityFromHashMap(HashMap hm) {
    ItemDataBean eb = new ItemDataBean();
    this.setEntityAuditInformation(eb, hm);
    eb.setId(((Integer) hm.get("item_data_id")).intValue());
    eb.setEventCRFId(((Integer) hm.get("event_crf_id")).intValue());
    eb.setItemId(((Integer) hm.get("item_id")).intValue());
    eb.setValue((String) hm.get("value"));
    // fetching out from database
    if (formatDates) {
        ItemDataType dataType = getDataType(eb.getItemId());
        if (dataType.equals(ItemDataType.DATE)) {
            eb.setValue(Utils.convertedItemDateValue(eb.getValue(), oc_df_string, local_df_string, locale));
        } else if (dataType.equals(ItemDataType.PDATE)) {
            eb.setValue(reFormatPDate(eb.getValue()));
        }
    }
    eb.setStatus(Status.get(((Integer) hm.get("status_id")).intValue()));
    eb.setOrdinal(((Integer) hm.get("ordinal")).intValue());
    eb.setDeleted(((Boolean) hm.get("deleted")).booleanValue());
    eb.setOldStatus(Status.get(hm.get("old_status_id") == null ? 1 : ((Integer) hm.get("old_status_id")).intValue()));
    return eb;
}
Also used : ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Example 3 with ItemDataType

use of org.akaza.openclinica.bean.core.ItemDataType in project OpenClinica by OpenClinica.

the class ItemDataDAO method upsert.

public EntityBean upsert(EntityBean eb) {
    ItemDataBean idb = (ItemDataBean) eb;
    // YW 12-06-2007 << convert to oc_date_format_string pattern before
    // inserting into database
    ItemDataType dataType = getDataType(idb.getItemId());
    if (dataType.equals(ItemDataType.DATE)) {
        idb.setValue(Utils.convertedItemDateValue(idb.getValue(), local_df_string, oc_df_string, locale));
    } else if (dataType.equals(ItemDataType.PDATE)) {
        idb.setValue(formatPDate(idb.getValue()));
    }
    HashMap<Integer, Comparable> variables = new HashMap<Integer, Comparable>();
    int id = getNextPK();
    variables.put(new Integer(1), new Integer(id));
    variables.put(new Integer(2), new Integer(idb.getEventCRFId()));
    variables.put(new Integer(3), new Integer(idb.getItemId()));
    variables.put(new Integer(4), new Integer(idb.getStatus().getId()));
    variables.put(new Integer(5), idb.getValue());
    variables.put(new Integer(6), new Integer(idb.getOwnerId()));
    variables.put(new Integer(7), new Integer(idb.getOrdinal()));
    variables.put(new Integer(8), new Integer(idb.getUpdaterId()));
    variables.put(new Integer(9), new Boolean(idb.isDeleted()));
    this.execute(digester.getQuery("upsert"), variables);
    if (isQuerySuccessful()) {
        idb.setId(id);
    }
    return idb;
}
Also used : ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Example 4 with ItemDataType

use of org.akaza.openclinica.bean.core.ItemDataType in project OpenClinica by OpenClinica.

the class ItemDataDAO method create.

public EntityBean create(EntityBean eb) {
    ItemDataBean idb = (ItemDataBean) eb;
    // YW 12-06-2007 << convert to oc_date_format_string pattern before
    // inserting into database
    ItemDataType dataType = getDataType(idb.getItemId());
    if (dataType.equals(ItemDataType.DATE)) {
        idb.setValue(Utils.convertedItemDateValue(idb.getValue(), local_df_string, oc_df_string, locale));
    } else if (dataType.equals(ItemDataType.PDATE)) {
        idb.setValue(formatPDate(idb.getValue()));
    }
    HashMap<Integer, Comparable> variables = new HashMap<Integer, Comparable>();
    int id = getNextPK();
    variables.put(new Integer(1), new Integer(id));
    variables.put(new Integer(2), new Integer(idb.getEventCRFId()));
    variables.put(new Integer(3), new Integer(idb.getItemId()));
    variables.put(new Integer(4), new Integer(idb.getStatus().getId()));
    variables.put(new Integer(5), idb.getValue());
    variables.put(new Integer(6), new Integer(idb.getOwnerId()));
    variables.put(new Integer(7), new Integer(idb.getOrdinal()));
    variables.put(new Integer(8), new Integer(idb.getStatus().getId()));
    variables.put(new Integer(9), new Boolean(idb.isDeleted()));
    this.execute(digester.getQuery("create"), variables);
    if (isQuerySuccessful()) {
        idb.setId(id);
    }
    return idb;
}
Also used : ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Example 5 with ItemDataType

use of org.akaza.openclinica.bean.core.ItemDataType in project OpenClinica by OpenClinica.

the class ItemDataDAO method update.

public EntityBean update(EntityBean eb) {
    ItemDataBean idb = (ItemDataBean) eb;
    // YW 12-06-2007 << convert to oc_date_format_string pattern before
    // inserting into database
    ItemDataType dataType = getDataType(idb.getItemId());
    if (dataType.equals(ItemDataType.DATE)) {
        idb.setValue(Utils.convertedItemDateValue(idb.getValue(), local_df_string, oc_df_string, locale));
    } else if (dataType.equals(ItemDataType.PDATE)) {
        idb.setValue(formatPDate(idb.getValue()));
    }
    idb.setActive(false);
    HashMap<Integer, Comparable> variables = new HashMap<Integer, Comparable>();
    variables.put(new Integer(1), new Integer(idb.getEventCRFId()));
    variables.put(new Integer(2), new Integer(idb.getItemId()));
    variables.put(new Integer(3), new Integer(idb.getStatus().getId()));
    variables.put(new Integer(4), idb.getValue());
    variables.put(new Integer(5), new Integer(idb.getUpdaterId()));
    variables.put(new Integer(6), new Integer(idb.getOrdinal()));
    variables.put(new Integer(7), new Integer(idb.getOldStatus().getId()));
    variables.put(new Integer(8), new Boolean(idb.isDeleted()));
    variables.put(new Integer(9), new Integer(idb.getId()));
    this.execute(digester.getQuery("update"), variables);
    if (isQuerySuccessful()) {
        idb.setActive(true);
    }
    return idb;
}
Also used : ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean)

Aggregations

ItemDataType (org.akaza.openclinica.bean.core.ItemDataType)14 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)10 HashMap (java.util.HashMap)7 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)5 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)4 ArrayList (java.util.ArrayList)3 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)3 NumberFormat (java.text.NumberFormat)2 Date (java.util.Date)1 Iterator (java.util.Iterator)1 NullValue (org.akaza.openclinica.bean.core.NullValue)1 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)1 ResponseOptionBean (org.akaza.openclinica.bean.submit.ResponseOptionBean)1 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)1 Validation (org.akaza.openclinica.control.form.Validation)1 ItemGroupCrvVersionUtil (org.akaza.openclinica.core.util.ItemGroupCrvVersionUtil)1 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)1 DynamicsItemFormMetadataBean (org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean)1 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)1 ScoreException (org.akaza.openclinica.exception.ScoreException)1