Search in sources :

Example 1 with ResponseSetBean

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

the class CreateCRFVersionServlet method isResponseValid.

private ItemBean isResponseValid(HashMap items, CRFVersionBean version) {
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ItemFormMetadataDAO metadao = new ItemFormMetadataDAO(sm.getDataSource());
    Set names = items.keySet();
    Iterator it = names.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();
        ItemBean oldItem = (ItemBean) idao.findByNameAndCRFId(name, version.getCrfId());
        ItemBean item = (ItemBean) items.get(name);
        if (oldItem.getId() > 0) {
            // found same item in DB
            ArrayList metas = metadao.findAllByItemId(oldItem.getId());
            for (int i = 0; i < metas.size(); i++) {
                ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(i);
                ResponseSetBean rsb = ifmb.getResponseSet();
                if (hasDifferentOption(rsb, item.getItemMeta().getResponseSet()) != null) {
                    return item;
                }
            }
        }
    }
    return null;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Set(java.util.Set) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 2 with ResponseSetBean

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

the class BeanFactory method createMetadataBean.

/**
     * Create an ItemFormMetadataBean from the values referred to by a Map
     * object. The Map contains the Item values from the Sreadsheet template, as
     * in (item_name: Item1, etc...}
     * 
     * @param map
     *            A Map involving the column names and values Of items.
     * @param ordinal
     *            The ordinal property for the meta data bean.
     * @param crfName
     *            The CRF name.
     * @return An ItemFormMetadataBean representing the values from the Map.
     */
public ItemFormMetadataBean createMetadataBean(Map<String, String> map, int ordinal, String crfName) {
    if (map == null)
        return new ItemFormMetadataBean();
    ItemFormMetadataBean metadataBean = new ItemFormMetadataBean();
    // the POI library returns all numbers as doubles (2.0), we round
    // off the numbers to 2, for instance
    NumberFormat numFormatter = NumberFormat.getInstance();
    numFormatter.setMaximumFractionDigits(0);
    String itemPageNum;
    String columnNum;
    String questNum;
    metadataBean.setOrdinal(ordinal);
    metadataBean.setResponseLayout(map.get("response_layout"));
    metadataBean.setParentLabel(map.get("parent_item"));
    metadataBean.setLeftItemText(map.get("left_item_text"));
    metadataBean.setRightItemText(map.get("right_item_text"));
    metadataBean.setDefaultValue(map.get("default_value"));
    metadataBean.setHeader(map.get("header"));
    metadataBean.setSubHeader(map.get("subheader"));
    itemPageNum = map.get("page_number");
    try {
        itemPageNum = numFormatter.format(Double.parseDouble(itemPageNum));
    } catch (NumberFormatException nfe) {
        itemPageNum = "";
    }
    metadataBean.setPageNumberLabel(itemPageNum);
    columnNum = map.get("column_number");
    try {
        columnNum = numFormatter.format(Double.parseDouble(columnNum));
        metadataBean.setColumnNumber(Integer.parseInt(columnNum));
    } catch (NumberFormatException nfe) {
        metadataBean.setColumnNumber(0);
    }
    questNum = map.get("question_number");
    try {
        questNum = numFormatter.format(Double.parseDouble(questNum));
    } catch (NumberFormatException nfe) {
        questNum = "";
    }
    metadataBean.setQuestionNumberLabel(questNum);
    String requStr = map.get("required");
    requStr = requStr.equalsIgnoreCase("") ? "0" : requStr;
    double required;
    try {
        required = Double.parseDouble(requStr);
    } catch (NumberFormatException nfe) {
        required = 0;
    }
    if (required > 0) {
        metadataBean.setRequired(true);
    }
    ResponseSetBean respBean = this.createResponseSetBean(map, crfName);
    metadataBean.setResponseSet(respBean);
    return metadataBean;
}
Also used : ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) NumberFormat(java.text.NumberFormat)

Example 3 with ResponseSetBean

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

the class BeanFactory method createResponseSetBean.

/* Create a ResponseSetBean from a Map of property/value pairs */
public ResponseSetBean createResponseSetBean(Map<String, String> itemValuesMap, String crfName) {
    ResponseSetBean rBean = new ResponseSetBean();
    // If an item has a response label that has already been defined (by
    // previous
    // item definitions) then use the response_options_text and
    // response_values associated
    // with that response label
    String[] innerArray = new String[2];
    String responseType = itemValuesMap.get("response_type");
    String responseLab = itemValuesMap.get("response_label");
    String optionsTxt = itemValuesMap.get("response_options_text");
    String optionsVals = itemValuesMap.get("response_values");
    rBean.setResponseType(ResponseType.getByName(responseType));
    rBean.setLabel(itemValuesMap.get("response_label"));
    // Find out if the response text and option values are already cached
    // for
    // this CRF. The String index is the CRF name; the String array refrs to
    // the options text and options values.
    Map<String, String[]> responseLabels = cachedResponseLabels.get(crfName);
    if (responseLabels == null) {
        responseLabels = new HashMap<String, String[]>();
        cachedResponseLabels.put(crfName, responseLabels);
    }
    if (responseLabels.get(responseLab) == null) {
        innerArray[0] = optionsTxt;
        innerArray[1] = optionsVals;
        responseLabels.put(responseLab, innerArray);
    }
    // if the item has a response label but no values for
    // response_options_text
    // or response_values, provide the item with the cached values for these
    // properties
    String[] tmpArr;
    if (responseLab != null && responseLab.length() != 0 && optionsTxt != null && optionsTxt.length() == 0 && optionsVals != null && optionsVals.length() == 0) {
        tmpArr = responseLabels.get(responseLab);
        // The responseLabel is stored in the Map
        if (tmpArr != null) {
            rBean.setOptions(tmpArr[0], tmpArr[1]);
            return rBean;
        }
    }
    rBean.setOptions(optionsTxt, optionsVals);
    return rBean;
}
Also used : ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean)

Example 4 with ResponseSetBean

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

the class BeanFactory method createItemFormMetadataBean.

/*
     * Create an ItemFormMetadataBean from the values referred to by a Map.Entry
     * object. The Map.Entry contains an integer pointing to a Map of Item
     * values from the Sreadsheet template, as in (item_name: Item1, etc...}
     */
public ItemFormMetadataBean createItemFormMetadataBean(Map.Entry<Integer, Map<String, String>> me, String crfName) {
    if (me == null)
        return new ItemFormMetadataBean();
    ItemFormMetadataBean metadataBean = new ItemFormMetadataBean();
    // the POI library returns all numbers as doubles (2.0), we round
    // off the numbers to 2, for instance
    NumberFormat numFormatter = NumberFormat.getInstance();
    numFormatter.setMaximumFractionDigits(0);
    String itemPageNum;
    String columnNum;
    String questNum;
    metadataBean.setOrdinal(me.getKey());
    Map<String, String> map = me.getValue();
    // response_layout property for checkboxes and radio buttons
    metadataBean.setResponseLayout(map.get("response_layout"));
    metadataBean.setDefaultValue(map.get("default_value"));
    metadataBean.setParentLabel(map.get("parent_item"));
    metadataBean.setLeftItemText(map.get("left_item_text"));
    metadataBean.setRightItemText(map.get("right_item_text"));
    metadataBean.setHeader(map.get("header"));
    metadataBean.setSubHeader(map.get("subheader"));
    metadataBean.setGroupLabel(map.get("group_label"));
    itemPageNum = map.get("page_number");
    try {
        itemPageNum = numFormatter.format(Double.parseDouble(itemPageNum));
    } catch (NumberFormatException nfe) {
        itemPageNum = "";
    }
    metadataBean.setPageNumberLabel(itemPageNum);
    columnNum = map.get("column_number");
    try {
        columnNum = numFormatter.format(Double.parseDouble(columnNum));
        metadataBean.setColumnNumber(Integer.parseInt(columnNum));
    } catch (NumberFormatException nfe) {
        metadataBean.setColumnNumber(0);
    }
    questNum = map.get("question_number");
    //We support any character in QUESTION_NUMBER field. So there is no need to do this number formatting.
    //        try {
    //            questNum = numFormatter.format(Double.parseDouble(questNum));
    //        } catch (NumberFormatException nfe) {
    //            questNum = "";
    //        }
    metadataBean.setQuestionNumberLabel(questNum);
    String requStr = map.get("required");
    requStr = requStr.equalsIgnoreCase("") ? "0" : requStr;
    double required;
    try {
        required = Double.parseDouble(requStr);
    } catch (NumberFormatException nfe) {
        required = 0;
    }
    if (required > 0) {
        metadataBean.setRequired(true);
    }
    ResponseSetBean respBean = this.createResponseSetBean(map, crfName);
    metadataBean.setResponseSet(respBean);
    return metadataBean;
}
Also used : ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) NumberFormat(java.text.NumberFormat)

Example 5 with ResponseSetBean

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

the class DataEntryServlet method addAttachedFilePath.

protected String addAttachedFilePath(DisplayItemBean dib, String attachedFilePath) {
    String fileName = "";
    ItemDataBean idb = dib.getData();
    String itemDataValue = idb.getValue();
    String dbValue = dib.getDbData().getValue();
    ResponseSetBean rsb = dib.getMetadata().getResponseSet();
    org.akaza.openclinica.bean.core.ResponseType rt = rsb.getResponseType();
    if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.FILE) && itemDataValue.length() > 0) {
        File file = new File(itemDataValue);
        fileName = file.getName();
        if (itemDataValue.length() > fileName.length()) {
            // itemDataValue includes file path
            idb.setValue(itemDataValue);
        } else {
            File f = new File(dbValue);
            fileName = f.getName();
            if (fileName.equals(itemDataValue) && dbValue.length() > itemDataValue.length()) {
                // since filename is unique by timestamp, re-upload will
                // append
                // another timestamp to the same filename
                idb.setValue(dbValue);
            } else {
                idb.setValue(attachedFilePath + itemDataValue);
                fileName = itemDataValue;
            }
        }
    }
    return fileName;
}
Also used : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) File(java.io.File)

Aggregations

ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)14 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)9 ArrayList (java.util.ArrayList)6 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)4 ResponseOptionBean (org.akaza.openclinica.bean.submit.ResponseOptionBean)3 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)3 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 NumberFormat (java.text.NumberFormat)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 Pattern (java.util.regex.Pattern)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)2 NewCRFBean (org.akaza.openclinica.bean.admin.NewCRFBean)2 MeasurementUnitOidGenerator (org.akaza.openclinica.bean.oid.MeasurementUnitOidGenerator)2 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)2