Search in sources :

Example 6 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 7 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 8 with ItemDataType

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

the class OpenClinicaVariableNode method testCalculate.

@Override
String testCalculate() throws OpenClinicaSystemException {
    validate();
    String variableValue = testCalculateVariable();
    boolean isEventStatusParamExist = number.endsWith(STATUS);
    boolean isEventStartDateParamExist = number.endsWith(STARTDATE);
    boolean isEventStartDateAndStatusParamExist = (number.endsWith(STARTDATE) || number.endsWith(STATUS));
    if (variableValue != null) {
        return variableValue;
    }
    ItemBean item = getExpressionService().getItemBeanFromExpression(number);
    String testString = "test";
    String testInt = "1";
    String testBoolean = "true";
    String testDate = "2008-01-01";
    String testPDate = "";
    if (item != null) {
        ItemDataType itemDataType = ItemDataType.get(item.getItemDataTypeId());
        switch(itemDataType.getId()) {
            case 1:
                {
                    return theTest(testBoolean);
                }
            case 2:
                {
                    return theTest(testBoolean);
                }
            case 3:
                {
                    return theTest(testString);
                }
            case 4:
                {
                    return theTest(testString);
                }
            case 5:
                {
                    return theTest(testString);
                }
            case 6:
                {
                    return theTest(testInt);
                }
            case 7:
                {
                    return theTest(testInt);
                }
            case 8:
                {
                    return theTest(testString);
                }
            case 9:
                {
                    return theTest(testDate);
                }
            case 10:
                {
                    return theTest(testPDate);
                }
            case 11:
                {
                    return theTest(testString + ".txt");
                }
            default:
                throw new OpenClinicaSystemException("OCRERR_0011");
        }
    } else if (isEventStartDateAndStatusParamExist) {
        if (isEventStatusParamExist)
            return theTest(testString);
        else if (isEventStartDateParamExist)
            return theTest(testDate);
        else
            return null;
    } else {
        throw new OpenClinicaSystemException("OCRERR_0012", new String[] { number });
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 9 with ItemDataType

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

the class ItemDAO method findAllWithItemDetailsGroupCRFVersionMetadataByCRFId.

/*
     * select distinct item.name as item_name, item.description as description, item.item_id as item_id,
     * item.item_data_type_id as data_type, item.oc_oid as item_oid,
     * item_group.name as group_name, item_group.oc_oid as group_oid ,
     * crf_version.name as version_name, crf_version.status_id as v_status
     */
public ArrayList<ItemGroupCrvVersionUtil> findAllWithItemDetailsGroupCRFVersionMetadataByCRFId(String crfName) {
    this.unsetTypeExpected();
    // (crf)name
    this.setTypeExpected(1, TypeNames.STRING);
    // (crf)description
    this.setTypeExpected(2, TypeNames.STRING);
    // (crf)item_id
    this.setTypeExpected(3, TypeNames.INT);
    // (crf)data_type
    this.setTypeExpected(4, TypeNames.INT);
    // (crf)item_oid
    this.setTypeExpected(5, TypeNames.STRING);
    // (crf)group_name
    this.setTypeExpected(6, TypeNames.STRING);
    // (crf)group_oid
    this.setTypeExpected(7, TypeNames.STRING);
    // (crf)version_name
    this.setTypeExpected(8, TypeNames.STRING);
    // (crf)v_status
    this.setTypeExpected(9, TypeNames.INT);
    HashMap variables = new HashMap();
    variables.put(new Integer(1), crfName);
    String sql = digester.getQuery("findAllWithItemDetailsGroupCRFVersionMetadataByCRFId");
    ArrayList rows = this.select(sql, variables);
    ItemGroupCrvVersionUtil item = null;
    ItemDataType itemDT = null;
    ArrayList<ItemGroupCrvVersionUtil> item_group_crfversion_info = new ArrayList<ItemGroupCrvVersionUtil>();
    Iterator it = rows.iterator();
    while (it.hasNext()) {
        HashMap row = (HashMap) it.next();
        item = new ItemGroupCrvVersionUtil();
        item.setItemName((String) row.get("item_name"));
        item.setCrfVersionName((String) row.get("version_name"));
        item.setCrfVersionStatus(((Integer) row.get("v_status")).intValue());
        item.setGroupName((String) row.get("group_name"));
        item.setGroupOID((String) row.get("group_oid"));
        // (crf)
        this.setTypeExpected(2, TypeNames.STRING);
        // (crf)item_id
        this.setTypeExpected(3, TypeNames.INT);
        // (crf)data_type
        this.setTypeExpected(4, TypeNames.INT);
        // (crf)item_oid
        this.setTypeExpected(5, TypeNames.STRING);
        item.setItemDescription((String) row.get("description"));
        item.setItemOID((String) row.get("item_oid"));
        itemDT = ItemDataType.get((Integer) row.get("data_type"));
        item.setItemDataType(itemDT.getDescription());
        item.setId((Integer) row.get("item_id"));
        item_group_crfversion_info.add(item);
    }
    return item_group_crfversion_info;
}
Also used : ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) HashMap(java.util.HashMap) ItemGroupCrvVersionUtil(org.akaza.openclinica.core.util.ItemGroupCrvVersionUtil) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 10 with ItemDataType

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

the class ScoreCalculator method writeToDB.

protected boolean writeToDB(ItemBean ib, ItemFormMetadataBean ifm, ItemDataBean idb, String exp, String value, StringBuffer err) {
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    NumberFormat nf = NumberFormat.getInstance();
    if (idb == null) {
        idb = new ItemDataBean();
    }
    ItemDataType idt = ib.getDataType();
    if (value == null || value.length() == 0) {
        if (idb.isActive() && !"".equals(idb.getValue())) {
            idb.setValue("<erased>");
        } else {
            idb.setValue("");
        }
        err.append("Result is empty in" + " " + exp + "; ");
    } else {
        idb.setValue(this.getMathContextValue(value, ifm, idt, err));
    }
    idb.setStatus(Status.UNAVAILABLE);
    // idb.setNeedsRecalc(false);
    if (!idb.isActive()) {
        // will this need to change for double data entry?
        idb.setCreatedDate(new Date());
        idb.setOwner(ub);
        idb.setItemId(ib.getId());
        idb.setEventCRFId(ecb.getId());
        idb = (ItemDataBean) iddao.create(idb);
    } else {
        idb = (ItemDataBean) iddao.update(idb);
    }
    return idb.isActive();
}
Also used : ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) NumberFormat(java.text.NumberFormat)

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