Search in sources :

Example 26 with DisplayItemBean

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

the class InitialDataEntryServlet method validateDisplayItemGroupBean.

@Override
protected List<DisplayItemGroupBean> validateDisplayItemGroupBean(DiscrepancyValidator v, DisplayItemGroupBean digb, List<DisplayItemGroupBean> digbs, List<DisplayItemGroupBean> formGroups, HttpServletRequest request, HttpServletResponse response) {
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    formGroups = loadFormValueForItemGroup(digb, digbs, formGroups, edcb.getId(), request);
    String inputName = "";
    for (int i = 0; i < formGroups.size(); i++) {
        DisplayItemGroupBean displayGroup = formGroups.get(i);
        List<DisplayItemBean> items = displayGroup.getItems();
        int order = displayGroup.getOrdinal();
        if (displayGroup.isAuto() && displayGroup.getFormInputOrdinal() > 0) {
            order = displayGroup.getFormInputOrdinal();
        }
        for (DisplayItemBean displayItem : items) {
            if (displayGroup.isAuto()) {
                inputName = getGroupItemInputName(displayGroup, order, displayItem);
            } else {
                inputName = getGroupItemManualInputName(displayGroup, order, displayItem);
            }
            validateDisplayItemBean(v, displayItem, inputName, request);
        }
    }
    return formGroups;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 27 with DisplayItemBean

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

the class VerifyImportedCRFDataServlet method processRequest.

@Override
@SuppressWarnings(value = "unchecked")
public void processRequest() throws Exception {
    ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
    itemDataDao.setFormatDates(false);
    EventCRFDAO eventCrfDao = new EventCRFDAO(sm.getDataSource());
    CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(sm.getDataSource());
    String action = request.getParameter("action");
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    resetPanel();
    panel.setStudyInfoShown(false);
    panel.setOrderedData(true);
    setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));
    setToPanel(resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
    setToPanel(resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
    setToPanel(resword.getString("CRF_spreadsheet_template"), respage.getString("br_download_blank_CRF_spreadsheet_from"));
    setToPanel(resword.getString("example_CRF_br_spreadsheets"), respage.getString("br_download_example_CRF_instructions_from"));
    if ("confirm".equalsIgnoreCase(action)) {
        List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
        logger.info("Size of displayItemBeanWrappers : " + displayItemBeanWrappers.size());
        forwardPage(Page.VERIFY_IMPORT_CRF_DATA);
    }
    if ("save".equalsIgnoreCase(action)) {
        // setup ruleSets to run if applicable
        RuleSetServiceInterface ruleSetService = (RuleSetServiceInterface) SpringServletAccess.getApplicationContext(context).getBean("ruleSetService");
        List<ImportDataRuleRunnerContainer> containers = this.ruleRunSetup(sm.getDataSource(), currentStudy, ub, ruleSetService);
        List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
        // System.out.println("Size of displayItemBeanWrappers : " +
        // displayItemBeanWrappers.size());
        HashMap<Integer, String> importedCRFStatuses = (HashMap<Integer, String>) session.getAttribute("importedCRFStatuses");
        for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
            boolean resetSDV = false;
            int eventCrfBeanId = -1;
            EventCRFBean eventCrfBean = new EventCRFBean();
            // TODO : tom , the wrapper object has all the necessary data -
            // as you see we check the
            // is to see if this data is Savable if it is then we go ahead
            // and save it. if not we discard.
            // So the change needs to happen here , instead of discarding we
            // need to file discrepancy notes
            // and save the data. If you look in the
            // Page.VERIFY_IMPORT_CRF_DATA jsp file you can see how I am
            // pulling the errors. and use that in the same way.
            logger.info("right before we check to make sure it is savable: " + wrapper.isSavable());
            if (wrapper.isSavable()) {
                ArrayList<Integer> eventCrfInts = new ArrayList<Integer>();
                // wrapper.getValidationErrors().toString());
                for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
                    eventCrfBeanId = displayItemBean.getData().getEventCRFId();
                    eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
                    logger.info("found value here: " + displayItemBean.getData().getValue());
                    logger.info("found status here: " + eventCrfBean.getStatus().getName());
                    // System.out.println("found event crf bean name here: "
                    // +
                    // eventCrfBean.getEventName()+" id "+eventCrfBean.getId
                    // ());
                    // SO, items can be created in a wrapper which is set to
                    // overwrite
                    // we get around this by checking the bean first, to
                    // make sure it's not null
                    ItemDataBean itemDataBean = new ItemDataBean();
                    itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
                    if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
                        if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
                            resetSDV = true;
                        logger.info("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
                        itemDataBean.setUpdatedDate(new Date());
                        itemDataBean.setUpdater(ub);
                        itemDataBean.setValue(displayItemBean.getData().getValue());
                        // set status?
                        itemDataDao.update(itemDataBean);
                        logger.info("updated: " + itemDataBean.getItemId());
                        // need to set pk here in order to create dn
                        displayItemBean.getData().setId(itemDataBean.getId());
                    } else {
                        resetSDV = true;
                        itemDataDao.create(displayItemBean.getData());
                        logger.info("created: " + displayItemBean.getData().getItemId() + "event CRF ID = " + eventCrfBean.getId() + "CRF VERSION ID =" + eventCrfBean.getCRFVersionId());
                        // does this dao function work for repeating
                        // events/groups?
                        // ItemDataBean itemDataBean =
                        // itemDataDao.findByEventCRFIdAndItemName(
                        // eventCrfBean,
                        // displayItemBean.getItem().getName());
                        ItemDataBean itemDataBean2 = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
                        logger.info("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
                        displayItemBean.getData().setId(itemDataBean2.getId());
                    }
                    // logger.info("created item data bean:
                    // "+displayItemBean.getData().getId());
                    // logger.info("created:
                    // "+displayItemBean.getData().getName());
                    // logger.info("continued:
                    // "+displayItemBean.getData().getItemId());
                    ItemDAO idao = new ItemDAO(sm.getDataSource());
                    ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
                    // logger.info("continued2: getName " +
                    // ibean.getName());
                    // System.out.println("*** checking for validation errors: "
                    // + ibean.getName());
                    String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
                    if (wrapper.getValidationErrors().containsKey(itemOid)) {
                        ArrayList messageList = (ArrayList) wrapper.getValidationErrors().get(itemOid);
                        // could it be more than one? tbh 08/2008
                        for (int iter = 0; iter < messageList.size(); iter++) {
                            String message = (String) messageList.get(iter);
                            DiscrepancyNoteBean parentDn = ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, ub, sm.getDataSource(), currentStudy);
                            ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), ub, sm.getDataSource(), currentStudy);
                        // System.out.println("*** created disc note with message: "
                        // + message);
                        // displayItemBean);
                        }
                    }
                    // "+displayItemBean.getDbData().getName());
                    if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
                        String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
                        if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
                            crfBusinessLogicHelper.markCRFStarted(eventCrfBean, ub);
                        } else {
                            crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
                        }
                        eventCrfInts.add(new Integer(eventCrfBean.getId()));
                    }
                }
                // Reset the SDV status if item data has been changed or added
                if (eventCrfBean != null && resetSDV)
                    eventCrfDao.setSDVStatus(false, ub.getId(), eventCrfBean.getId());
            // end of item datas, tbh
            // crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
            // System .out.println("*** just updated event crf bean: "+
            // eventCrfBean.getId());
            // need to update the study event status as well, tbh
            // crfBusinessLogicHelper.updateStudyEvent(eventCrfBean,
            // ub);
            // above should do it for us, tbh 08/2008
            }
        }
        addPageMessage(respage.getString("data_has_been_successfully_import"));
        addPageMessage(this.ruleActionWarnings(this.runRules(currentStudy, ub, containers, ruleSetService, ExecutionMode.SAVE)));
        // forwardPage(Page.SUBMIT_DATA_SERVLET);
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
    // replaced tbh, 06/2009
    }
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ImportDataRuleRunnerContainer(org.akaza.openclinica.logic.rulerunner.ImportDataRuleRunnerContainer) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) RuleSetServiceInterface(org.akaza.openclinica.service.rule.RuleSetServiceInterface) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) CrfBusinessLogicHelper(org.akaza.openclinica.web.job.CrfBusinessLogicHelper) ArrayList(java.util.ArrayList) List(java.util.List) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DisplayItemBeanWrapper(org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) Date(java.util.Date) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)

Example 28 with DisplayItemBean

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

the class VariableSubstitutionHelper method replaceVariables.

/**
     * Replaces the variables in each {@link DisplayItemBean} of the {@link DisplaySectionBean}.
     *
     * @param section
     *            The display section to have its items processed.
     * @param study
     *            Study associated with the display section.
     * @param studySubject
     *            Subject associated with the display section.
     */
public static void replaceVariables(DisplaySectionBean section, StudyBean study, StudySubjectBean studySubject, StudyEventDefinitionBean eventDef, StudyEventBean event, DataSource dataSource) {
    StrSubstitutor subst = new StrSubstitutor(buildTokensMap(section, studySubject, study, eventDef, event, dataSource));
    for (DisplayItemBean displayItem : section.getItems()) {
        ItemFormMetadataBean metadata = displayItem.getMetadata();
        metadata.setRightItemText(replace(subst, metadata.getRightItemText()));
        metadata.setLeftItemText(replace(subst, metadata.getLeftItemText()));
        metadata.setHeader(replace(subst, metadata.getHeader()));
        metadata.setSubHeader(replace(subst, metadata.getSubHeader()));
    }
}
Also used : StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 29 with DisplayItemBean

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

the class CellFactoryPrintDecorator method addUnits.

public Element addUnits(Element tdCell, DisplayItemBean displayBean) {
    if (displayBean == null) {
        return tdCell;
    }
    ItemBean itemBean = displayBean.getItem();
    if (itemBean == null) {
        return tdCell;
    }
    StringBuilder units = new StringBuilder(displayBean.getItem().getUnits());
    if (units.length() < 1) {
        return tdCell;
    }
    Element spanElement = new Element("span");
    spanElement.setAttribute("style", "float:left;clear:both");
    // surround units with parentheses
    units = units.insert(0, "(");
    units = units.append(")");
    spanElement.addContent(" " + units.toString());
    tdCell.addContent(spanElement);
    return tdCell;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Element(org.jdom.Element)

Example 30 with DisplayItemBean

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

the class FormBeanUtil method createSingleColumn.

/**
     * Create a table containing a single column of Items.
     * 
     * @param tbody
     *            The JDOM Element representing a tbody tag for the XHTML table.
     * @param items
     *            The DisplayItemBeans representing the Items for the table.
     * @param tabindex
     *            The Integer representing the form field's tab index.
     * @param hasDiscrepancyMgt
     *            A boolean value specifying whether discrepancy icons should be
     *            displayed.
     * @param hasDBValues
     *            A boolean value specifying whether the input elements are
     *            prefiled with database values.
     * @param forPrinting
     *            A boolean value specifying whether the CRF is being displayed
     *            for printing (therefore, the D Note icons should not be
     *            enabled or clickable).
     */
private void createSingleColumn(Element tbody, List<DisplayItemBean> items, Integer tabindex, boolean hasDiscrepancyMgt, boolean hasDBValues, boolean forPrinting) {
    CellFactory cellFactory = new CellFactory();
    // Use this decorator class to generate vertical checkboxes, if any of
    // the
    // items have this type of layout
    CellFactoryPrintDecorator cellFactoryPrintDecorator = new CellFactoryPrintDecorator();
    // Create header/subheader rows, if necessary
    String tmpName;
    for (DisplayItemBean disBean : items) {
        tmpName = disBean.getMetadata().getHeader();
        if (tmpName != null && tmpName.length() > 0) {
            Element tr = createHeaderSubheaderCell(disBean, true);
            // add the row to the tbody element]
            tbody.addContent(tr);
        }
        // Does the row tag need a subheader type background?
        tmpName = disBean.getMetadata().getSubHeader();
        if (tmpName != null && tmpName.length() > 0) {
            Element tr2 = createHeaderSubheaderCell(disBean, false);
            tbody.addContent(tr2);
        }
        // Create the row containing the item + form field
        Element trRow = new Element("tr");
        String leftSideTxt = "";
        String questNumber = "";
        tbody.addContent(trRow);
        String responseName = disBean.getMetadata().getResponseSet().getResponseType().getName();
        Element tdCell = new Element("td");
        String classNames = CssRules.getClassNamesForTag("td");
        tdCell.setAttribute("class", classNames);
        // use vertical-alignment for these TD cells
        tdCell.setAttribute("style", "vertical-align:top");
        boolean horizontalLayout = "horizontal".equalsIgnoreCase(disBean.getMetadata().getResponseLayout());
        // Just use this method for vertical checkboxes and radio buttons
        if (("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName)) && !horizontalLayout) {
            cellFactoryPrintDecorator.createCellContentsForVerticalLayout(tdCell, responseName, disBean, ++tabindex, hasDiscrepancyMgt, hasDBValues, forPrinting);
        } else {
            cellFactory.createCellContents(tdCell, responseName, disBean, ++tabindex, hasDiscrepancyMgt, hasDBValues, forPrinting);
        }
        questNumber = disBean.getMetadata().getQuestionNumberLabel();
        boolean hasQuestion = questNumber.length() > 0;
        leftSideTxt = disBean.getMetadata().getLeftItemText();
        cellFactory.addTextToCell(tdCell, leftSideTxt, CellFactory.LEFT);
        if (hasQuestion) {
            addQuestionNumbers(tdCell, questNumber);
        }
        trRow.addContent(tdCell);
    }
}
Also used : Element(org.jdom.Element) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean)

Aggregations

DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)80 ArrayList (java.util.ArrayList)44 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)37 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)33 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)24 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)22 HashMap (java.util.HashMap)19 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)18 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)16 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)16 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)15 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)15 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)12 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)12 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)12 DisplayItemWithGroupBean (org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean)11 Element (org.jdom.Element)10 List (java.util.List)8 Map (java.util.Map)8 HttpSession (javax.servlet.http.HttpSession)8