Search in sources :

Example 96 with ItemBean

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

the class ImportHelper method getInputName.

/**
     * @param dib
     *            A DisplayItemBean representing an input on the CRF.
     * @return The name of the input in the HTML form.
     */
public final String getInputName(DisplayItemBean dib) {
    ItemBean ib = dib.getItem();
    String inputName = "input" + ib.getId();
    return inputName;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean)

Example 97 with ItemBean

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

the class ImportHelper 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.
     * @return The DisplayItemBean which is validated.
     */
public DisplayItemBean validateDisplayItemBeanText(DiscrepancyValidator discValidator, DisplayItemBean dib, String inputName) {
    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;
    if (!isNull) {
        if (StringUtil.isBlank(idb.getValue())) {
            // check required first
            if (ibMeta.isRequired()) {
                discValidator.addValidation(inputName, Validator.IS_REQUIRED);
            }
        } else {
            if (idt.equals(ItemDataType.ST)) {
                // a string's size could be more than 255, which is more
                // than
                // the db field length
                discValidator.addValidation(inputName, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 3999);
            } else if (idt.equals(ItemDataType.INTEGER)) {
            // hard edit check, will comment out for now, tbh 05/2008
            // v.addValidation(inputName, Validator.IS_AN_INTEGER);
            // v.alwaysExecuteLastValidation(inputName);
            } else if (idt.equals(ItemDataType.REAL)) {
            // hard edit check, will comment out for now, tbh 05/08
            // 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);
                discValidator.addValidation(inputName, Validator.IN_RESPONSE_SET_SINGLE_VALUE, dib.getMetadata().getResponseSet());
            } else if (idt.equals(ItemDataType.DATE)) {
            // hard edit check, will comment out for now, tbh 05/08
            //v.addValidation(inputName, Validator.IS_A_DATE);
            // v.alwaysExecuteLastValidation(inputName);
            }
            String customValidationString = dib.getMetadata().getRegexp();
            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());
                    discValidator.addValidation(inputName, customValidation);
                }
            }
        }
    }
    return dib;
}
Also used : Validation(org.akaza.openclinica.control.form.Validation) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 98 with ItemBean

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

the class CreateCRFVersionServlet method uploadFile.

/**
     * Uploads the excel version file
     * 
     * @param version
     * @throws Exception
     */
public String uploadFile(String theDir, CRFVersionBean version) throws Exception {
    List<File> theFiles = uploadHelper.returnFiles(request, context, theDir);
    // Enumeration files = multi.getFileNames();
    errors.remove("excel_file");
    String tempFile = null;
    for (File f : theFiles) {
        // File f = multi.getFile(name);
        if (f == null || f.getName() == null) {
            logger.debug("file is empty.");
            Validator.addError(errors, "excel_file", resword.getString("you_have_to_provide_spreadsheet"));
            session.setAttribute("version", version);
            return tempFile;
        } else if (f.getName().indexOf(".xls") < 0 && f.getName().indexOf(".XLS") < 0) {
            logger.debug("file name:" + f.getName());
            Validator.addError(errors, "excel_file", respage.getString("file_you_uploaded_not_seem_excel_spreadsheet"));
            session.setAttribute("version", version);
            return tempFile;
        } else {
            logger.debug("file name:" + f.getName());
            tempFile = f.getName();
            // create the inputstream here, so that it can be enclosed in a
            // try/finally block and closed :: BWP, 06/08/2007
            FileInputStream inStream = null;
            FileInputStream inStreamClassic = null;
            SpreadSheetTableRepeating htab = null;
            SpreadSheetTableClassic sstc = null;
            // create newCRFBean here
            NewCRFBean nib = null;
            try {
                inStream = new FileInputStream(theDir + tempFile);
                // *** now change the code here to generate sstable, tbh
                // 06/07
                htab = new SpreadSheetTableRepeating(inStream, ub, // FileInputStream(theDir + tempFile), ub,
                version.getName(), locale, currentStudy.getId());
                htab.setMeasurementUnitDao((MeasurementUnitDao) SpringServletAccess.getApplicationContext(context).getBean("measurementUnitDao"));
                if (!htab.isRepeating()) {
                    inStreamClassic = new FileInputStream(theDir + tempFile);
                    sstc = new SpreadSheetTableClassic(inStreamClassic, ub, version.getName(), locale, currentStudy.getId());
                    sstc.setMeasurementUnitDao((MeasurementUnitDao) SpringServletAccess.getApplicationContext(context).getBean("measurementUnitDao"));
                }
                if (htab.isRepeating()) {
                    htab.setCrfId(version.getCrfId());
                    // not the best place for this but for now...
                    session.setAttribute("new_table", "y");
                } else {
                    sstc.setCrfId(version.getCrfId());
                }
                if (htab.isRepeating()) {
                    nib = htab.toNewCRF(sm.getDataSource(), respage);
                } else {
                    nib = sstc.toNewCRF(sm.getDataSource(), respage);
                }
                // bwp; 2/28/07; updated 6/11/07;
                // This object is created to pull preview information out of
                // the
                // spreadsheet
                HSSFWorkbook workbook = null;
                FileInputStream inputStream = null;
                try {
                    inputStream = new FileInputStream(theDir + tempFile);
                    workbook = new HSSFWorkbook(inputStream);
                    // Store the Sections, Items, Groups, and CRF name and
                    // version information
                    // so they can be displayed in a preview. The Map
                    // consists of the
                    // names "sections," "items," "groups," and "crf_info"
                    // as keys, each of which point
                    // to a Map containing data on those CRF sections.
                    // Check if it's the old template
                    Preview preview;
                    if (htab.isRepeating()) {
                        // the preview uses date formatting with default
                        // values in date fields: yyyy-MM-dd
                        preview = new SpreadsheetPreviewNw();
                    } else {
                        preview = new SpreadsheetPreview();
                    }
                    session.setAttribute("preview_crf", preview.createCrfMetaObject(workbook));
                } catch (Exception exc) {
                    // opening the stream could
                    // throw FileNotFoundException
                    exc.printStackTrace();
                    String message = resword.getString("the_application_encountered_a_problem_uploading_CRF");
                    logger.debug(message + ": " + exc.getMessage());
                    this.addPageMessage(message);
                } finally {
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException io) {
                        // ignore this close()-related exception
                        }
                    }
                }
                ArrayList ibs = isItemSame(nib.getItems(), version);
                if (!ibs.isEmpty()) {
                    ArrayList warnings = new ArrayList();
                    warnings.add(resexception.getString("you_may_not_modify_items"));
                    for (int i = 0; i < ibs.size(); i++) {
                        ItemBean ib = (ItemBean) ibs.get(i);
                        if (ib.getOwner().getId() == ub.getId()) {
                            warnings.add(resword.getString("the_item") + " '" + ib.getName() + "' " + resexception.getString("in_your_spreadsheet_already_exists") + ib.getDescription() + "), DATA_TYPE(" + ib.getDataType().getName() + "), UNITS(" + ib.getUnits() + "), " + resword.getString("and_or") + " PHI_STATUS(" + ib.isPhiStatus() + "). UNITS " + resword.getString("and") + " DATA_TYPE(PDATE to DATE) " + resexception.getString("will_not_be_changed_if") + " PHI, DESCRIPTION, DATA_TYPE from PDATE to DATE " + resexception.getString("will_be_changed_if_you_continue"));
                        } else {
                            warnings.add(resword.getString("the_item") + " '" + ib.getName() + "' " + resexception.getString("in_your_spreadsheet_already_exists") + ib.getDescription() + "), DATA_TYPE(" + ib.getDataType().getName() + "), UNITS(" + ib.getUnits() + "), " + resword.getString("and_or") + " PHI_STATUS(" + ib.isPhiStatus() + "). " + resexception.getString("these_field_cannot_be_modified_because_not_owner"));
                        }
                        request.setAttribute("warnings", warnings);
                    }
                }
                ItemBean ib = isResponseValid(nib.getItems(), version);
                if (ib != null) {
                    nib.getErrors().add(resword.getString("the_item") + ": " + ib.getName() + " " + resexception.getString("in_your_spreadsheet_already_exits_in_DB"));
                }
            } catch (IOException io) {
                logger.warn("Opening up the Excel file caused an error. the error message is: " + io.getMessage());
            } finally {
                if (inStream != null) {
                    try {
                        inStream.close();
                    } catch (IOException ioe) {
                    }
                }
                if (inStreamClassic != null) {
                    try {
                        inStreamClassic.close();
                    } catch (IOException ioe) {
                    }
                }
            }
            // request.setAttribute("excelErrors", .getErrors());
            session.setAttribute("excelErrors", nib.getErrors());
            session.setAttribute("htmlTable", nib.getHtmlTable());
            session.setAttribute("nib", nib);
        }
    }
    return tempFile;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) MeasurementUnitDao(org.akaza.openclinica.dao.hibernate.MeasurementUnitDao) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) CRFReadingException(org.akaza.openclinica.exception.CRFReadingException) IOException(java.io.IOException) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) File(java.io.File)

Example 99 with ItemBean

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

the class BeanFactory method createItemBean.

/*
     * Create an ItemBean from a Map specifying its property values, as in
     * {item_name: Item1, ...) etc.
     */
public ItemBean createItemBean(Map<String, String> itemValuesMap) {
    ItemBean iBean = new ItemBean();
    String itemDesc = itemValuesMap.get("description_label");
    String itemDataType;
    iBean.setDescription(itemDesc);
    itemDesc = itemValuesMap.get("item_name");
    iBean.setName(itemDesc);
    itemDesc = itemValuesMap.get("units");
    iBean.setUnits(itemDesc);
    itemDataType = itemValuesMap.get("data_type");
    // TODO: solve the problem with the getByName method
    ItemDataType itemDT = ItemDataType.getByName(itemDataType);
    iBean.setItemDataTypeId(itemDT.getId());
    return iBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType)

Example 100 with ItemBean

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

the class CRFVersionMetadataUtil method retrieveFormMetadata.

/**
     * Builds and returns an ArrayList of SectionBeans that comprise the metadata of a CRFVersion.
     */
public ArrayList<SectionBean> retrieveFormMetadata(FormLayoutBean formLayout) throws Exception {
    ItemDAO idao = new ItemDAO(dataSource);
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(dataSource);
    // tbh, 102007
    SectionDAO sdao = new SectionDAO(dataSource);
    ItemGroupDAO igdao = new ItemGroupDAO(dataSource);
    ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO(dataSource);
    ArrayList sections = (ArrayList) sdao.findByLayoutId(formLayout.getId());
    HashMap versionMap = new HashMap();
    for (int i = 0; i < sections.size(); i++) {
        SectionBean section = (SectionBean) sections.get(i);
        versionMap.put(new Integer(section.getId()), section.getItems());
        // YW 08-21-2007, add group metadata
        ArrayList<ItemGroupBean> igs = (ArrayList<ItemGroupBean>) igdao.findGroupByLayoutId(formLayout.getId());
        for (int j = 0; j < igs.size(); ++j) {
            ArrayList<ItemGroupMetadataBean> igms = (ArrayList<ItemGroupMetadataBean>) igmdao.findMetaByGroupAndSection(igs.get(j).getId(), section.getCRFVersionId(), section.getId());
            if (!igms.isEmpty()) {
                // Note, the following logic has been adapted here -
                // "for a given crf version,
                // all the items in the same group have the same group
                // metadata
                // so we can get one of them and set metadata for the
                // group"
                igs.get(j).setMeta(igms.get(0));
                igs.get(j).setItemGroupMetaBeans(igms);
            }
        }
        ((SectionBean) sections.get(i)).setGroups(igs);
    // YW >>
    }
    ArrayList items = idao.findAllItemsByLayoutId(formLayout.getId());
    // then different query will be used
    if (igmdao.versionIncluded(formLayout.getId())) {
        for (int i = 0; i < items.size(); i++) {
            ItemBean item = (ItemBean) items.get(i);
            ItemFormMetadataBean ifm = ifmdao.findByItemIdAndFormLayoutId(item.getId(), formLayout.getId());
            item.setItemMeta(ifm);
            // logger.info("option******" +
            // ifm.getResponseSet().getOptions().size());
            ArrayList its = (ArrayList) versionMap.get(new Integer(ifm.getSectionId()));
            its.add(item);
        }
    } else {
        for (int i = 0; i < items.size(); i++) {
            ItemBean item = (ItemBean) items.get(i);
            ItemFormMetadataBean ifm = ifmdao.findByItemIdAndFormLayoutIdNotInIGM(item.getId(), formLayout.getId());
            item.setItemMeta(ifm);
            // logger.info("option******" +
            // ifm.getResponseSet().getOptions().size());
            ArrayList its = (ArrayList) versionMap.get(new Integer(ifm.getSectionId()));
            its.add(item);
        }
    }
    for (int i = 0; i < sections.size(); i++) {
        SectionBean section = (SectionBean) sections.get(i);
        section.setItems((ArrayList) versionMap.get(new Integer(section.getId())));
    }
    return sections;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) ArrayList(java.util.ArrayList) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

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