Search in sources :

Example 1 with ItemFormMetadataBean

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

the class ItemFormMetadataDAO method findByItemIdAndFormLayoutId.

public ItemFormMetadataBean findByItemIdAndFormLayoutId(int itemId, int layoutId) {
    this.setTypesExpected();
    // TODO note to come back here, tbh
    // version name
    this.setTypeExpected(28, TypeNames.STRING);
    // add more here for display, tbh 082007
    // group_label
    this.setTypeExpected(29, TypeNames.STRING);
    // repeat_max
    this.setTypeExpected(30, TypeNames.INT);
    // section_name
    this.setTypeExpected(31, TypeNames.STRING);
    logMe("Current Thread:::" + Thread.currentThread() + "types Expected?");
    HashMap<Integer, Object> variables = new HashMap<Integer, Object>();
    variables.put(new Integer(1), new Integer(itemId));
    variables.put(new Integer(2), new Integer(layoutId));
    String sql = digester.getQuery("findByItemIdAndFormLayoutId");
    logMe("Thread?" + Thread.currentThread() + "SQL?" + sql + "variables?" + variables);
    ArrayList alist = this.select(sql, variables);
    Iterator it = alist.iterator();
    ItemFormMetadataBean ifmb = new ItemFormMetadataBean();
    HashMap hm = new HashMap();
    if (it.hasNext()) {
        hm = (HashMap) it.next();
        ifmb = (ItemFormMetadataBean) this.getEntityFromHashMap(hm);
    }
    // EntityBean eb =
    // this.executeFindByPKQuery("findByItemIdAndCRFVersionId", variables);
    /*
         * if (!ifmb.isActive()) { return new ItemFormMetadataBean(); } else {
         */
    // ItemFormMetadataBean ifmb = (ItemFormMetadataBean) eb;
    String versionName = (String) hm.get("cvname");
    String groupLabel = (String) hm.get("group_label");
    String sectionName = (String) hm.get("section_name");
    Integer repeatMax = (Integer) hm.get("repeat_max");
    int repeatMaxInt = repeatMax != null ? repeatMax.intValue() : 0;
    // caught an NPE here, tbh 082007?
    // new Integer((Integer)hm.get("repeat_max")).intValue();
    ifmb.setCrfVersionName(versionName);
    ifmb.setGroupLabel(groupLabel);
    // logger.info(">>>added group name: "+groupLabel);
    ifmb.setSectionName(sectionName);
    // logger.info("<<<added section name: "+sectionName);
    ifmb.setRepeatMax(repeatMaxInt);
    // return (ItemFormMetadataBean) eb;
    return ifmb;
// }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 2 with ItemFormMetadataBean

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

the class ItemFormMetadataDAO method findByItemIdAndFormLayoutIdNotInIGM.

public ItemFormMetadataBean findByItemIdAndFormLayoutIdNotInIGM(int itemId, int formLayoutId) {
    this.setTypesExpected();
    HashMap<Integer, Integer> variables = new HashMap<Integer, Integer>();
    variables.put(new Integer(1), new Integer(itemId));
    variables.put(new Integer(2), new Integer(formLayoutId));
    EntityBean eb = this.executeFindByPKQuery("findByItemIdAndFormLayoutIdNotInIGM", variables);
    if (!eb.isActive()) {
        return new ItemFormMetadataBean();
    } else {
        return (ItemFormMetadataBean) eb;
    }
}
Also used : HashMap(java.util.HashMap) EntityBean(org.akaza.openclinica.bean.core.EntityBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 3 with ItemFormMetadataBean

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

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

use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean 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)

Aggregations

ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)93 ArrayList (java.util.ArrayList)58 HashMap (java.util.HashMap)36 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)36 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)28 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)25 DynamicsItemFormMetadataBean (org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean)25 Iterator (java.util.Iterator)21 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)18 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)16 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)14 ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)13 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)12 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)9 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)8 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)8