Search in sources :

Example 71 with ItemBean

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

the class ItemDAO method findByNameAndCRFId.

public EntityBean findByNameAndCRFId(String name, int crfId) {
    ItemBean eb = new ItemBean();
    this.setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), name);
    variables.put(new Integer(2), new Integer(crfId));
    String sql = digester.getQuery("findByNameAndCRFId");
    ArrayList alist = this.select(sql, variables);
    Iterator it = alist.iterator();
    if (it.hasNext()) {
        eb = (ItemBean) this.getEntityFromHashMap((HashMap) it.next());
    }
    return eb;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 72 with ItemBean

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

the class ItemDAO method findAllItemsByGroupIdOrdered.

public List<ItemBean> findAllItemsByGroupIdOrdered(int id, int crfVersionId) {
    this.setTypesExpected();
    HashMap<Integer, Integer> variables = new HashMap<Integer, Integer>();
    variables.put(1, id);
    variables.put(2, crfVersionId);
    String sql = digester.getQuery("findAllItemsByGroupIdOrdered");
    List listofMaps = this.select(sql, variables);
    List<ItemBean> beanList = new ArrayList<ItemBean>();
    ItemBean bean;
    for (Object map : listofMaps) {
        bean = (ItemBean) this.getEntityFromHashMap((HashMap) map);
        beanList.add(bean);
    }
    return beanList;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 73 with ItemBean

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

the class ScoreCalculator method doCalculation.

/*
     * Perform all calculations in a CRFVersion. The parameter 'itemdata' might
     * be overwritten.
     * 
     * @param calcItemGroupSizes @param items @param itemdata @param
     * itemGroupSizes @param databaseErrors @return ArrayList<String> which
     * records left_item_text of items who failed to be updated into database.
     * 
     * 
     * //this method has not been fully tested yet
     * 
     * 
     * public ArrayList<String> doCalculations( HashMap<String,ItemBean>
     * items, HashMap<String,String> itemdata, HashMap<Integer,TreeSet<Integer>>
     * itemOrdinals) { ArrayList<String> updateFailedItems = new ArrayList<String>();
     * if(itemdata==null) { //here, actually only record errors but doesn't
     * return errors. logger.error("In scoreCalculator doCalculations(), items
     * are empty!"); errors.add("Calculation cannot be started because needed
     * items are empty!"); return updateFailedItems; } ItemFormMetadataDAO
     * ifmdao = new ItemFormMetadataDAO(sm.getDataSource()); ItemDAO idao = new
     * ItemDAO(sm.getDataSource()); ItemDataDAO iddao = new
     * ItemDataDAO(sm.getDataSource());
     * 
     * NumberFormat nf = NumberFormat.getInstance(); Parser parser = new
     * Parser(items,itemdata); try { //for calculation type List<ItemFormMetadataBean>
     * derivedItemList = ifmdao.findAllByCRFVersionIdAndResponseTypeId(
     * ecb.getCRFVersionId(), ResponseType.CALCULATION.getId());
     * if(derivedItemList.size()>0) { Collections.sort(derivedItemList); for
     * (ItemFormMetadataBean ifmb: derivedItemList) { ItemBean ib =
     * (ItemBean)idao.findByPK(ifmb.getItemId()); ResponseOptionBean rob =
     * (ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0); //YW,
     * 1-16-2008, << enable: 1. evaluate combination of expression and
     * functions 2. scoring for group items. //int groupsize =
     * iddao.getMaxOrdinalForGroup(ecb,
     * (SectionBean)sdao.findByPK(ifmb.getSectionId()), //
     * (ItemGroupBean)igdao.findByName(ifmb.getGroupLabel())); int groupsize =
     * 1; if(itemOrdinals.containsKey(ib.getId())) { groupsize =
     * (itemOrdinals.get(ib.getId())).size(); } String value = ""; String
     * parsedExp = ""; for(int i=0; i<groupsize; ++i) { ItemDataBean idb =
     * (ItemDataBean)iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb
     * .getItemId(), ecb.getId(), i+1); StringBuffer err = new StringBuffer();
     * parsedExp = parser.parse(rob.getValue(), i+1);
     * if(parser.getErrors().length()>0) { err.append(parser.getErrors());
     * parser.setErrors(new StringBuffer()); } else { value =
     * ScoreUtil.eval(parsedExp, err); //YW >> String exp = rob.getValue(); exp =
     * exp.replace("##", ","); if(writeToDB(ib,idb,exp,value,err)) {
     * itemdata.put(ib.getId()+"_"+(i+1), idb.getValue()); }else { String key =
     * (i+1)>1 ? ifmb.getLeftItemText()+"_"+(i+1) : ifmb.getLeftItemText();
     * updateFailedItems.add(key); } } if(err.length()>0) { String key = (i+1)>1 ?
     * ifmb.getLeftItemText()+"_"+(i+1) : ifmb.getLeftItemText();
     * errors.add("Item " + key + " contains calculation errors: " +
     * err.toString()); } } } }
     * 
     * //YW, 1-16-2008, for group-calculation type. Current restrictions: //1.
     * an item with group-calculation type is not repeatable. //2. only
     * calculate sum(), avg(), min(), max(), median(), stdev() //3. formula
     * arguments only contain item beans //4. only one item bean per argument
     * List<ItemFormMetadataBean> itemList =
     * ifmdao.findAllByCRFVersionIdAndResponseTypeId( ecb.getCRFVersionId(),
     * ResponseType.GROUP_CALCULATION.getId()); if(itemList.size()>0) {
     * Collections.sort(itemList); for (ItemFormMetadataBean ifmb: itemList) {
     * ItemBean ib = (ItemBean)idao.findByPK(ifmb.getItemId());
     * ResponseOptionBean rob =
     * (ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0);
     * StringBuffer err = new StringBuffer(); parser.setErrors(err); String
     * parsedExp = parser.parse(rob.getValue(),itemOrdinals); String value = "";
     * if(parser.getErrors().length()>0) { err.append(parser.getErrors()); }else {
     * value = ScoreUtil.eval(parsedExp,err);
     * 
     * ItemDataBean idb =
     * (ItemDataBean)iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb
     * .getItemId(), ecb.getId(), 1); String exp = rob.getValue(); exp =
     * exp.replace("##", ","); if(writeToDB(ib,idb,exp,value,err)) {
     * itemdata.put(ib.getId()+"_"+idb.getOrdinal(), idb.getValue()); } else {
     * updateFailedItems.add(ifmb.getLeftItemText()); } }
     * 
     * if(err.length()>0) { errors.add("Item " + ifmb.getLeftItemText() + "
     * contains calculation errors: " + err.toString()); } } } } catch
     * (OpenClinicaException e) { logger.error(e.getMessage()); }
     * //ecb.setNeedsRecalc(false); //EventCRFDAO ecdao = new
     * EventCRFDAO(sm.getDataSource()); //ecb = ecdao.update(ecb);
     * 
     * return updateFailedItems; }
     */
/**
     * Performs calculation. <br>
     * Notice: both parameter 'itemdata' and parameter 'errs' might be updated
     * in this method.
     * 
     * @param displayItems
     * @param items
     * @param itemdata
     * @param errs
     * @return
     * 
     * @author ywang (Jan. 2008)
     */
public String doCalculation(DisplayItemBean displayItem, HashMap<String, ItemBean> items, HashMap<String, String> itemdata, HashMap<Integer, TreeSet<Integer>> itemOrdinals, StringBuffer errs, int ordinal) {
    if (itemdata == null) {
        logger.error("In DataEntryServlet doCalculation(), itemdata map is empty!");
        errs.append("Calculation cannot be started because needed items are empty" + "; ");
        return "";
    }
    String value = "";
    NumberFormat nf = NumberFormat.getInstance();
    Parser parser = new Parser(items, itemdata);
    ItemBean ib = displayItem.getItem();
    ItemFormMetadataBean ifm = displayItem.getMetadata();
    ResponseOptionBean rob = (ResponseOptionBean) ifm.getResponseSet().getOptions().get(0);
    ArrayList<ScoreToken> parsedExp = new ArrayList<ScoreToken>();
    int type = ifm.getResponseSet().getResponseTypeId();
    if (type == 8) {
        parsedExp = parser.assignVariables(parser.parseScoreTokens(rob.getValue()), ordinal);
    } else if (type == 9) {
        // YW, 1-16-2008, for group-calculation type. Current restrictions:
        // 1. only calculate sum(), avg(), min(), max(), median(), stdev()
        // 2. formula arguments only contain item beans
        // 3. only one item bean per argument
        parsedExp = parser.assignVariables(parser.parseScoreTokens(rob.getValue()), itemOrdinals);
    }
    if (parser.getErrors().length() > 0) {
        errs.append(parser.getErrors());
    } else {
        try {
            value = ScoreUtil.eval(parsedExp);
        } catch (ScoreException se) {
            logger.error(se.getMessage());
        }
        ItemDataType idt = ib.getDataType();
        if (value == null || value.length() == 0) {
            value = "";
            String exp = rob.getValue();
            exp = exp.replace("##", ",");
            errs.append("Result is empty in" + " " + exp + "; ");
        // errors.append(resexception.getString("result_is_empty_in") +
        // " " + exp + "; ");
        } else {
            value = this.getMathContextValue(value, ifm, idt, errs);
        }
        // idb.setStatus(Status.UNAVAILABLE);
        itemdata.put(ib.getId() + "_" + ordinal, value);
    }
    return value;
}
Also used : ScoreException(org.akaza.openclinica.exception.ScoreException) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) NumberFormat(java.text.NumberFormat)

Example 74 with ItemBean

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

the class SPSSReportBean method getMetadataFile.

public StringBuffer getMetadataFile(SPSSVariableNameValidator svnv, ExtractBean eb) {
    itemNames.clear();
    // Is it necessary to
    String[] attributes = createAttributes(eb);
    // validate
    // StudyGroupClassBean
    // names? YW
    String[] attributeTypes = createAttributeTypes(eb);
    StringBuffer answer = new StringBuffer();
    answer.append("* NOTE: If you have put this file in a different folder \n" + "* from the associated data file, you will have to change the FILE \n" + "* location on the line below to point to the physical location of your data file.\n");
    answer.append("GET DATA  " + "/TYPE = TXT" + "/FILE = '" + getDatFileName() + "' " + "/DELCASE = LINE " + "/DELIMITERS = \"\\t\" " + "/ARRANGEMENT = DELIMITED " + "/FIRSTCASE = " + FIRSTCASE + " " + // since
    "/IMPORTCASE = ALL ");
    if (data.size() <= 0) {
        answer.append(".\n");
    } else {
        ArrayList columns = (ArrayList) data.get(this.COLUMNS_IND);
        int startItem = columns.size() - items.size();
        logger.debug("--> generated start item " + startItem + " from " + columns.size() + " minus " + items.size());
        answer.append("/VARIABLES = \n");
        int index;
        for (int i = 0; i < columns.size(); i++) {
            String itemName = (String) columns.get(i);
            // YW << Why do we need "V_" here? Right now it has been
            // removed, because:
            // This "V_" exists in .sps file but not exists in .dat file.
            // String varLabel = "V_" + itemName;
            String varLabel = svnv.getValidName(itemName);
            itemNames.add(varLabel);
            // builtin attributes
            if (i < startItem) {
                if (varLabel.startsWith("Gender")) {
                    gender = true;
                }
                index = builtinIndex(varLabel, attributes);
                logger.debug("varLabel[" + varLabel + "] index[" + index + "] attributeTypes[" + attributeTypes[1] + "]");
                answer.append("\t" + varLabel + " " + attributeTypes[index]);
                // >> tbh #5524
                DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
                ItemBean ib = dih.getItem();
                // << tbh
                if (attributeTypes[index].equals("A")) {
                    int len = getDataColumnMaxLen(i);
                    if (len == 0) {
                        // mininum length required by spss
                        len = 1;
                    }
                    // >> tbh #5524
                    ArrayList metas = ib.getItemMetas();
                    for (int k = 0; k < metas.size(); k++) {
                        ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
                        ResponseSetBean rsb = ifmb.getResponseSet();
                        ArrayList options = rsb.getOptions();
                        for (int l = 0; l < options.size(); l++) {
                            ResponseOptionBean ro = (ResponseOptionBean) options.get(l);
                            if (ro.getText().length() > len) {
                                len = ro.getText().length();
                            }
                        }
                    }
                    // << tbh
                    if (len > 8) {
                        len = 8;
                    }
                    answer.append(len);
                }
                answer.append("\n");
            }
        // YW >>
        }
        // items
        logger.debug("--> looking at " + startItem + " out of " + columns.size());
        for (int i = startItem; i < columns.size(); i++) {
            DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i - startItem);
            ItemBean ib = dih.getItem();
            // YW <<
            String varLabel = (String) itemNames.get(i);
            int dataTypeId = ib.getItemDataTypeId();
            // String.
            if (dataTypeId == 9) {
                // date
                answer.append("\t" + varLabel + " ADATE10\n");
            } else if (dataTypeId == 7) {
                // float
                answer.append("\t" + varLabel + " F8.2\n");
            } else if (dataTypeId == 6 && isIntType(ib)) {
                // pure int data
                // type for one
                // item.
                answer.append("\t" + varLabel + " F8.0\n");
            } else {
                // string
                // YW >>
                int len = getDataColumnMaxLen(i);
                if (len == 0) {
                    // mininum length required by spss
                    len = 1;
                }
                ArrayList metas = ib.getItemMetas();
                int optionCount = 0;
                for (int k = 0; k < metas.size(); k++) {
                    ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
                    ResponseSetBean rsb = ifmb.getResponseSet();
                    if (rsb.getResponseType().equals(ResponseType.CHECKBOX) || rsb.getResponseType().equals(ResponseType.RADIO) || rsb.getResponseType().equals(ResponseType.SELECT) || rsb.getResponseType().equals(ResponseType.SELECTMULTI)) {
                        optionCount++;
                    }
                    // tbh >> #5524: all possible response value options should be reviewed so that length is OK
                    ArrayList options = rsb.getOptions();
                    for (int l = 0; l < options.size(); l++) {
                        ResponseOptionBean ro = (ResponseOptionBean) options.get(l);
                        if (ro.getText().length() > len) {
                            len = ro.getText().length();
                        }
                    }
                // << tbh
                }
                if (optionCount == metas.size()) {
                    // value labels
                    if (len > 8) {
                        len = 8;
                    }
                }
                answer.append("\t" + varLabel + " A" + len + "\n");
            }
        }
        answer.append(".\n");
        answer.append("VARIABLE LABELS\n");
        // builtin attributes
        for (int i = 0; i < startItem; ++i) {
            String varLabel = (String) itemNames.get(i);
            if ((String) descriptions.get(itemNames.get(i)) != null) {
                answer.append("\t" + varLabel + " \"" + (String) descriptions.get(itemNames.get(i)) + "\"\n");
            } else {
                for (int j = 0; j < eb.getStudyGroupClasses().size(); ++j) {
                    answer.append("\t" + varLabel + " \"" + (String) descriptions.get(((StudyGroupClassBean) eb.getStudyGroupClasses().get(j)).getName()) + "\"\n");
                }
            }
        }
        // items
        for (int i = startItem; i < itemNames.size(); i++) {
            DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i - startItem);
            ItemBean ib = dih.getItem();
            String varLabel = (String) itemNames.get(i);
            answer.append("\t" + varLabel + " \"" + ib.getDescription() + "\"\n");
        }
        answer.append(".\n");
        answer.append("VALUE LABELS\n");
        if (isGender()) {
            answer.append("\t" + "Gender" + "\n");
            answer.append("\t" + "'M'" + " \"" + "Male" + "\"\n");
            answer.append("\t" + "'F'" + " \"" + "Female" + "\"\n\t/\n");
        }
        for (int i = 0; i < items.size(); i++) {
            String temp = "";
            DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
            ItemBean ib = dih.getItem();
            String varLabel = (String) itemNames.get(i + startItem);
            temp += "\t" + varLabel + "\n";
            boolean allOption = true;
            ArrayList metas = ib.getItemMetas();
            HashMap optionMap = new LinkedHashMap();
            for (int k = 0; k < metas.size(); k++) {
                ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
                ResponseSetBean rsb = ifmb.getResponseSet();
                if (rsb.getResponseType().equals(ResponseType.TEXT) || rsb.getResponseType().equals(ResponseType.FILE) || rsb.getResponseType().equals(ResponseType.TEXTAREA)) {
                    // has text response, dont show value labels
                    allOption = false;
                    break;
                } else {
                    for (int j = 0; j < rsb.getOptions().size(); j++) {
                        ResponseOptionBean ob = (ResponseOptionBean) rsb.getOptions().get(j);
                        String key = ob.getValue();
                        if (optionMap.containsKey(key)) {
                            ArrayList a = (ArrayList) optionMap.get(key);
                            if (!a.contains(ob.getText())) {
                                a.add(ob.getText());
                                optionMap.put(key, a);
                            }
                        } else {
                            ArrayList a = new ArrayList();
                            a.add(ob.getText());
                            optionMap.put(key, a);
                        }
                    }
                }
            }
            Iterator it = optionMap.keySet().iterator();
            while (it.hasNext()) {
                String value = (String) it.next();
                ArrayList a = (ArrayList) optionMap.get(value);
                String texts = "";
                if (a.size() > 1) {
                    for (int n = 0; n < a.size(); n++) {
                        texts += (String) a.get(n);
                        if (n < a.size() - 1) {
                            texts += "/";
                        }
                    }
                } else {
                    texts = (String) a.get(0);
                }
                if (value.length() > 8) {
                    value = value.substring(0, 8);
                }
                if (isValueText(value)) {
                    temp += "\t'" + value + "' \"" + texts + "\"\n";
                } else {
                    temp += "\t" + value + " \"" + texts + "\"\n";
                }
            }
            if (allOption) {
                answer.append(temp + "\t/\n");
            }
        }
    }
    answer.append(".\n EXECUTE.\n");
    return answer;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) LinkedHashMap(java.util.LinkedHashMap) Iterator(java.util.Iterator) ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 75 with ItemBean

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

the class ItemDAO method findAllWithItemDataByFormLayoutId.

// select name, ordinal, oc_oid, item_data_id, i.item_id as item_id, value
//
// from item_data id, item i
// where id.item_id=i.item_id and event_crf_id = ? order by i.item_id,ordinal;
public ArrayList<ItemBean> findAllWithItemDataByFormLayoutId(int crfVersionId, int eventCRFId) {
    this.unsetTypeExpected();
    // (item)name
    this.setTypeExpected(1, TypeNames.STRING);
    // ordinal
    this.setTypeExpected(2, TypeNames.INT);
    // oc_oid
    this.setTypeExpected(3, TypeNames.STRING);
    // item_data_id
    this.setTypeExpected(4, TypeNames.INT);
    // item_id
    this.setTypeExpected(5, TypeNames.INT);
    // (item)value
    this.setTypeExpected(6, TypeNames.STRING);
    ArrayList<ItemBean> answer = new ArrayList<ItemBean>();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(crfVersionId));
    variables.put(new Integer(2), new Integer(eventCRFId));
    String sql = digester.getQuery("findAllWithItemDataByFormLayoutId");
    ArrayList rows = super.select(sql, variables);
    Iterator it = rows.iterator();
    int cur_item_id = 0;
    ItemBean item_bean = null;
    ItemDataBean item_data_bean = null;
    while (it.hasNext()) {
        HashMap row = (HashMap) it.next();
        Integer id = (Integer) row.get("item_id");
        if (cur_item_id != id.intValue()) {
            item_bean = new ItemBean();
            answer.add(item_bean);
            cur_item_id = id.intValue();
            item_bean.setId(cur_item_id);
            item_bean.setName((String) row.get("name"));
            item_bean.setOid((String) row.get("oc_oid"));
        }
        item_data_bean = new ItemDataBean();
        item_data_bean.setValue((String) row.get("value"));
        item_data_bean.setOrdinal(((Integer) row.get("ordinal")).intValue());
        item_data_bean.setId(((Integer) row.get("item_data_id")).intValue());
        item_data_bean.setItemId(cur_item_id);
        item_bean.addItemDataElement(item_data_bean);
    }
    return answer;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) 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