Search in sources :

Example 21 with ResponseOptionBean

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

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

the class ImportCRFDataService method matchValueWithManyOptions.

/*
     * difference from the above is only a 'contains' in the place of an 'equals'. and a few other switches...also need
     * to keep in mind that there are non-null values that need to be taken into account
     */
private String matchValueWithManyOptions(DisplayItemBean displayItemBean, String value, List options) {
    String returnedValue = null;
    // boolean checkComplete = true;
    String entireOptions = "";
    String[] simValues = value.split(",");
    String simValue = value.replace(",", "");
    // also remove all spaces, so they will fit up with the entire set
    // of options
    simValue = simValue.replace(" ", "");
    boolean checkComplete = true;
    if (!options.isEmpty()) {
        for (Object responseOption : options) {
            ResponseOptionBean responseOptionBean = (ResponseOptionBean) responseOption;
            // logger.debug("testing response option bean get value: " + responseOptionBean.getValue());
            // entireOptions += responseOptionBean.getValue() + "{0,1}|";//
            // once, or not at all
            entireOptions += responseOptionBean.getValue();
        // trying smth new, tbh 01/2009
        // logger.debug("checking on this string: " +
        // entireOptions + " versus this value " + simValue);
        // checkComplete = Pattern.matches(entireOptions, simValue); //
        // switch values, tbh
        // if (!checkComplete) {
        // return returnedValue;
        // }
        }
        // remove spaces, since they are causing problems:
        entireOptions = entireOptions.replace(" ", "");
        // following may be superfluous, tbh
        ArrayList nullValues = displayItemBean.getEventDefinitionCRF().getNullValuesList();
        for (Object nullValue : nullValues) {
            NullValue nullValueTerm = (NullValue) nullValue;
            entireOptions += nullValueTerm.getName();
        // logger.debug("found and added " + nullValueTerm.getName());
        }
        for (String sim : simValues) {
            sim = sim.replace(" ", "");
            // logger.debug("checking on this string: " + entireOptions + " versus this value " + sim);
            // Pattern.matches(
            checkComplete = entireOptions.contains(sim);
            // sim);
            if (!checkComplete) {
                return returnedValue;
            }
        }
    }
    return value;
}
Also used : NullValue(org.akaza.openclinica.bean.core.NullValue) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Example 23 with ResponseOptionBean

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

the class DataEntryServlet method loadFormValue.

/**
     * Read in form values and write them to a display item bean. Note that this results in the form value being written to both the response set bean and the
     * item data bean. The ResponseSetBean is used to display preset values on the form in the event of error, and the ItemDataBean is used to send values to
     * the database.
     *
     * @param dib
     *            The DisplayItemBean to write data into.
     * @param request TODO
     * @return The DisplayItemBean, with form data loaded.
     */
protected DisplayItemBean loadFormValue(DisplayItemBean dib, HttpServletRequest request) {
    String inputName = getInputName(dib);
    FormProcessor fp = new FormProcessor(request);
    org.akaza.openclinica.bean.core.ResponseType rt = dib.getMetadata().getResponseSet().getResponseType();
    if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.CHECKBOX) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECTMULTI) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECT)) {
        dib.loadFormValue(fp.getStringArray(inputName));
    // YW, 2-4-2008 << calculation result has been written in dib-data
    } else if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.CALCULATION) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.GROUP_CALCULATION)) {
        dib.loadFormValue(dib.getData().getValue());
        ResponseOptionBean rob = (ResponseOptionBean) dib.getMetadata().getResponseSet().getOptions().get(0);
        LOGGER.trace("test print of options for coding: " + rob.getValue());
    // YW >>
    } else {
        LOGGER.trace("test print: " + inputName + ": " + fp.getString(inputName));
        dib.loadFormValue(fp.getString(inputName));
    }
    return dib;
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Example 24 with ResponseOptionBean

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

the class PrintHorizontalFormBuilder method addResponseLayoutRow.

private void addResponseLayoutRow(ArrayList subHeadList, List<DisplayItemBean> displayBeans) {
    Element thRow = new Element("tr");
    String responseName;
    String responseLayout;
    ItemFormMetadataBean metaBean;
    // Now create the th row
    Element th2;
    ResponseSetBean respBean;
    ResponseOptionBean optBean;
    int j = 0;
    for (DisplayItemBean dBean : displayBeans) {
        j++;
        metaBean = dBean.getMetadata();
        respBean = metaBean.getResponseSet();
        responseName = respBean.getResponseType().getName();
        if (responseName == null) {
            responseName = "";
        }
        responseLayout = metaBean.getResponseLayout();
        if (responseLayout == null) {
            responseLayout = "";
        }
        // next to a rad or check *with* a horizontal layout.
        if ((responseName.equalsIgnoreCase("radio") || responseName.equalsIgnoreCase("checkbox")) && responseLayout.equalsIgnoreCase("horizontal")) {
            for (int i = 0; i < respBean.getOptions().size(); i++) {
                optBean = (ResponseOptionBean) respBean.getOptions().get(i);
                if (optBean != null) {
                    th2 = createThCell(optBean.getText(), 1);
                    // Add font for printing
                    String classNames = th2.getAttribute("class").getValue();
                    classNames = classNames + " general_font";
                    th2.setAttribute("class", classNames);
                    thRow.addContent(th2);
                }
            }
        } else {
            // create empty cells for non-radios or checks, or rads and
            // checks
            // without horizontal layout
            th2 = createThCell("", 1);
            thRow.addContent(th2);
        }
        if (j % maxColRow == 0) {
            subHeadList.add(thRow);
            thRow = new Element("tr");
        }
    }
    if (j % maxColRow != 0)
        subHeadList.add(thRow);
    // now add the final empty th cell for the row
    th2 = createThCell();
    thRow.addContent(th2);
}
Also used : Element(org.jdom.Element) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 25 with ResponseOptionBean

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

the class FormBeanUtil method addBeansToResponseOptions.

public void addBeansToResponseOptions(List<String> values, List<ResponseOptionBean> respOptions) {
    ResponseOptionBean respBean;
    String tmpVal = "";
    // them
    for (String val : values) {
        respBean = new ResponseOptionBean();
        // BWP>> set text to the extended version, "not applicable"?
        tmpVal = DataEntryInputGenerator.NULL_VALUES_LONGVERSION.get(val);
        if (tmpVal != null && tmpVal.length() > 0) {
            respBean.setText(tmpVal);
        } else {
            respBean.setText(val);
        }
        respBean.setValue(val);
        respOptions.add(respBean);
    }
}
Also used : ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Aggregations

ResponseOptionBean (org.akaza.openclinica.bean.submit.ResponseOptionBean)31 ArrayList (java.util.ArrayList)20 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)9 Element (org.jdom.Element)8 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)7 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)5 HashMap (java.util.HashMap)4 NumberFormat (java.text.NumberFormat)3 Iterator (java.util.Iterator)3 NullValue (org.akaza.openclinica.bean.core.NullValue)3 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)3 DisplayItemWithGroupBean (org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean)3 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)3 Random (java.util.Random)2 HttpSession (javax.servlet.http.HttpSession)2 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)2 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)2 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)2