Search in sources :

Example 26 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class CreateFiltersTwoServlet method processRequest.

// < ResourceBundle restext,resword,respage,resexception;
@Override
public void processRequest() throws Exception {
    // we can't get to here without an action:
    // begin--takes us to specify parameters,
    // where the user will select CRF, then section,
    // then parameters of the section: a little tricky
    // to do entirely with javascript, but can be done.
    // possible to set up the CRF-section relationship,
    // and then have a screen 3.5 with the parameters?
    // criteria--takes us to specify criteria, that is,
    // to specify and, or, not and, etc. here we'll take the
    // list we just generated online and generate a chain
    // of filterobjectbeans, which will in turn,
    // generate the SQL add on for the dataset.
    String action = request.getParameter("action");
    StudyBean studyWithEventDefs = currentStudy;
    if (currentStudy.getParentStudyId() > 0) {
        studyWithEventDefs = new StudyBean();
        studyWithEventDefs.setId(currentStudy.getParentStudyId());
    }
    if (StringUtil.isBlank(action)) {
    // throw an error
    } else if ("begin".equalsIgnoreCase(action)) {
        StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
        HashMap events = sedao.findCRFsByStudy(studyWithEventDefs);
        // if events are empty -- resend to first filter page with message
        if (events.isEmpty()) {
            addPageMessage(respage.getString("no_CRF_assigned_pick_another"));
            FormProcessor fp = new FormProcessor(request);
            FilterDAO fdao = new FilterDAO(sm.getDataSource());
            EntityBeanTable table = fp.getEntityBeanTable();
            ArrayList filters = (ArrayList) fdao.findAll();
            ArrayList filterRows = FilterRow.generateRowsFromBeans(filters);
            String[] columns = { resword.getString("filter_name"), resword.getString("description"), resword.getString("created_by"), resword.getString("created_date"), resword.getString("status"), resword.getString("actions") };
            table.setColumns(new ArrayList(Arrays.asList(columns)));
            table.hideColumnLink(5);
            table.addLink(resword.getString("create_new_filter"), "CreateFiltersOne?action=begin");
            table.setQuery("CreateFiltersOne", new HashMap());
            table.setRows(filterRows);
            table.computeDisplay();
            request.setAttribute("table", table);
            forwardPage(Page.CREATE_FILTER_SCREEN_1);
        } else {
            // else, send to the following page:
            request.setAttribute("events", events);
            forwardPage(Page.CREATE_FILTER_SCREEN_3);
        }
    } else if ("crfselected".equalsIgnoreCase(action)) {
        // get the crf id, return to a new page with sections
        // and parameters attached, tbh
        FormProcessor fp = new FormProcessor(request);
        HashMap errors = new HashMap();
        int crfId = fp.getInt("crfId");
        if (crfId > 0) {
            CRFVersionDAO cvDAO = new CRFVersionDAO(sm.getDataSource());
            CRFDAO cDAO = new CRFDAO(sm.getDataSource());
            SectionDAO secDAO = new SectionDAO(sm.getDataSource());
            Collection sections = secDAO.findByVersionId(crfId);
            CRFVersionBean cvBean = (CRFVersionBean) cvDAO.findByPK(crfId);
            CRFBean cBean = (CRFBean) cDAO.findByPK(cvBean.getCrfId());
            request.setAttribute("sections", sections);
            session.setAttribute("cBean", cBean);
            // for further pages,
            session.setAttribute("cvBean", cvBean);
            // tbh
            forwardPage(Page.CREATE_FILTER_SCREEN_3_1);
        } else {
            addPageMessage(respage.getString("select_a_CRF_before_picking"));
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            HashMap events = sedao.findCRFsByStudy(studyWithEventDefs);
            request.setAttribute("events", events);
            forwardPage(Page.CREATE_FILTER_SCREEN_3);
        }
    } else if ("sectionselected".equalsIgnoreCase(action)) {
        // TODO set the crf and the section into session,
        // allow for the user to go back and forth,
        // set up the questions to be picked,
        // allow the user to move on to create_filter_screen_4
        FormProcessor fp = new FormProcessor(request);
        int sectionId = fp.getInt("sectionId");
        if (sectionId > 0) {
            SectionDAO secDAO = new SectionDAO(sm.getDataSource());
            SectionBean secBean = (SectionBean) secDAO.findByPK(sectionId);
            session.setAttribute("secBean", secBean);
            ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(sm.getDataSource());
            Collection metadatas = ifmDAO.findAllBySectionId(sectionId);
            if (metadatas.size() > 0) {
                request.setAttribute("metadatas", metadatas);
                forwardPage(Page.CREATE_FILTER_SCREEN_3_2);
            } else {
                CRFVersionBean cvBean = (CRFVersionBean) session.getAttribute("cvBean");
                addPageMessage(respage.getString("section_not_have_questions_select_another"));
                // SectionDAO secDAO = new SectionDAO(sm.getDataSource());
                Collection sections = secDAO.findByVersionId(cvBean.getId());
                request.setAttribute("sections", sections);
                forwardPage(Page.CREATE_FILTER_SCREEN_3_1);
            }
        } else {
            CRFVersionBean cvBean = (CRFVersionBean) session.getAttribute("cvBean");
            addPageMessage(respage.getString("select_section_before_select_question"));
            SectionDAO secDAO = new SectionDAO(sm.getDataSource());
            Collection sections = secDAO.findByVersionId(cvBean.getId());
            request.setAttribute("sections", sections);
            forwardPage(Page.CREATE_FILTER_SCREEN_3_1);
        }
    } else if ("questionsselected".equalsIgnoreCase(action)) {
        ArrayList alist = this.extractIdsFromForm();
        // and send the user to create_filter_screen_4
        if (alist.size() > 0) {
            ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(sm.getDataSource());
            Collection questions = ifmDAO.findByMultiplePKs(alist);
            session.setAttribute("questions", questions);
            forwardPage(Page.CREATE_FILTER_SCREEN_4);
        } else {
            SectionBean secBean = (SectionBean) session.getAttribute("secBean");
            addPageMessage(respage.getString("select_questions_before_set_parameters"));
            ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(sm.getDataSource());
            Collection metadatas = ifmDAO.findAllBySectionId(secBean.getId());
            request.setAttribute("metadatas", metadatas);
            forwardPage(Page.CREATE_FILTER_SCREEN_3_2);
        }
    } else if ("validatecriteria".equalsIgnoreCase(action)) {
        // TODO look at the criteria and create a list of filterobjectdata
        // beans, so that we can create the SQL later on in
        // the process.
        // also, throw the user back to the process or throw
        // them forward into the createServletThree process
        FormProcessor fp = new FormProcessor(request);
        String logical = fp.getString("logical");
        ArrayList questions = (ArrayList) session.getAttribute("questions");
        ArrayList filterobjects = new ArrayList();
        // (ArrayList)session.getAttribute("filterobjects");
        Iterator q_it = questions.iterator();
        int arrCnt = 0;
        while (q_it.hasNext()) {
            ItemFormMetadataBean ifmBean = (ItemFormMetadataBean) q_it.next();
            String opString = "operator:" + ifmBean.getId();
            String valString = "value:" + ifmBean.getId();
            String remString = "remove:" + ifmBean.getId();
            if ("remove".equals(fp.getString(remString))) {
                logger.info("found the string: " + remString);
                // TODO remove the question from from the list,
                // redirect to that page again????? <--maybe not?
                // questions.remove(arrCnt);
                // shouldn't have to remove the above, just do nothing
                arrCnt++;
            } else {
                String operator = fp.getString(opString);
                String value = fp.getString(valString);
                FilterObjectBean fob = new FilterObjectBean();
                fob.setItemId(ifmBean.getId());
                fob.setItemName(ifmBean.getHeader() + " " + ifmBean.getLeftItemText() + " " + ifmBean.getRightItemText());
                // case operator:
                if ("equal to".equalsIgnoreCase(operator)) {
                    fob.setOperand("=");
                } else if ("greater than".equalsIgnoreCase(operator)) {
                    fob.setOperand(">");
                } else if ("less than".equalsIgnoreCase(operator)) {
                    fob.setOperand("<");
                } else if ("greater than or equal".equalsIgnoreCase(operator)) {
                    fob.setOperand(">=");
                } else if ("less than or equal".equalsIgnoreCase(operator)) {
                    fob.setOperand("<=");
                } else if ("like".equalsIgnoreCase(operator)) {
                    fob.setOperand(" like ");
                } else if ("not like".equalsIgnoreCase(operator)) {
                    fob.setOperand(" not like ");
                } else {
                    fob.setOperand("!=");
                }
                fob.setValue(value);
                filterobjects.add(fob);
            }
        // end else
        //
        }
        // end while
        session.setAttribute("questions", questions);
        // TODO where does the connector come into play?
        // session.setAttribute("filterobjects",filterobjects);
        FilterDAO fDAO = new FilterDAO(sm.getDataSource());
        String newSQL = (String) session.getAttribute("newSQL");
        ArrayList newExp = (ArrayList) session.getAttribute("newExp");
        // human readable explanation
        String newNewSQL = fDAO.genSQLStatement(newSQL, logical, filterobjects);
        ArrayList newNewExp = fDAO.genExplanation(newExp, logical, filterobjects);
        if (arrCnt == questions.size()) {
            newNewSQL = newSQL;
            newNewExp = newExp;
        // don't change anything, if we've removed everything from this
        // list
        }
        logger.info("new SQL Generated: " + newNewSQL);
        String sub = fp.getString("submit");
        if ("Specify Filter Metadata".equals(sub)) {
            // add new params, create the filter object,
            // and go to create metadata
            FilterBean fb = new FilterBean();
            fb.setSQLStatement(newNewSQL + ")");
            // adding parens here to finish off other
            // statement--might add first part of statement here
            // for legibility's sake
            // tbh 06-02-2005
            session.removeAttribute("newSQL");
            // end of the road
            session.setAttribute("newFilter", fb);
            request.setAttribute("statuses", getStatuses());
            forwardPage(Page.CREATE_FILTER_SCREEN_5);
        } else {
            // replace the 'old' sql with the new sql gathered from the
            // session
            session.setAttribute("newSQL", newNewSQL);
            session.setAttribute("newExp", newNewExp);
            // add new params, and go back
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            HashMap events = sedao.findCRFsByStudy(currentStudy);
            //
            request.setAttribute("events", events);
            forwardPage(Page.CREATE_FILTER_SCREEN_3);
        }
    }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) FilterDAO(org.akaza.openclinica.dao.extract.FilterDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) Iterator(java.util.Iterator) FilterObjectBean(org.akaza.openclinica.bean.extract.FilterObjectBean) Collection(java.util.Collection) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO) FilterBean(org.akaza.openclinica.bean.extract.FilterBean)

Example 27 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class EditSelectedServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    boolean selectAll = fp.getBoolean("all");
    boolean selectAllItemsGroupsAttrs = fp.getBoolean("allAttrsAndItems");
    // BWP 3095: Only show a "select all items" like on a side info panel if
    // it
    // is not part of the EditSelected-related JSP>>
    request.setAttribute("EditSelectedSubmitted", true);
    // <<
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    // CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    ItemFormMetadataDAO imfdao = new ItemFormMetadataDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    DatasetBean db = (DatasetBean) session.getAttribute("newDataset");
    if (db == null) {
        db = new DatasetBean();
        session.setAttribute("newDataset", db);
    }
    // << tbh
    // HashMap eventlist = (HashMap) request.getAttribute("eventlist");
    // if (eventlist == null) {
    // System.out.println("TTTTT found the second hashmap!");
    HashMap eventlist = (LinkedHashMap) session.getAttribute("eventsForCreateDataset");
    // }
    ArrayList<String> ids = CreateDatasetServlet.allSedItemIdsInStudy(eventlist, crfdao, idao);
    // >> tbh 11/09, need to fill in a session variable
    if (selectAll) {
        logger.info("select all..........");
        db = selectAll(db);
        MessageFormat msg = new MessageFormat("");
        msg.setLocale(locale);
        msg.applyPattern(respage.getString("choose_include_all_items_dataset"));
        Object[] arguments = { ids.size() };
        addPageMessage(msg.format(arguments));
    // addPageMessage("You choose to include all items in current study
    // for the dataset, " +db.getItemIds().size() + " items total.");
    }
    if (selectAllItemsGroupsAttrs) {
        logger.info("select everything....");
        db = selectAll(db);
        db.setShowCRFcompletionDate(true);
        db.setShowCRFinterviewerDate(true);
        db.setShowCRFinterviewerName(true);
        db.setShowCRFstatus(true);
        db.setShowCRFversion(true);
        db.setShowEventEnd(true);
        db.setShowEventEndTime(true);
        db.setShowEventLocation(true);
        db.setShowEventStart(true);
        db.setShowEventStartTime(true);
        db.setShowEventStatus(true);
        db.setShowSubjectAgeAtEvent(true);
        db.setShowSubjectDob(true);
        db.setShowSubjectGender(true);
        db.setShowSubjectGroupInformation(true);
        db.setShowSubjectStatus(true);
        db.setShowSubjectUniqueIdentifier(true);
        // select all groups
        ArrayList sgclasses = (ArrayList) session.getAttribute("allSelectedGroups");
        //
        ArrayList newsgclasses = new ArrayList();
        StudyDAO studydao = new StudyDAO(sm.getDataSource());
        StudyGroupClassDAO sgclassdao = new StudyGroupClassDAO(sm.getDataSource());
        StudyBean theStudy = (StudyBean) studydao.findByPK(sm.getUserBean().getActiveStudyId());
        sgclasses = sgclassdao.findAllActiveByStudy(theStudy);
        for (int i = 0; i < sgclasses.size(); i++) {
            StudyGroupClassBean sgclass = (StudyGroupClassBean) sgclasses.get(i);
            sgclass.setSelected(true);
            newsgclasses.add(sgclass);
        }
        session.setAttribute("allSelectedGroups", newsgclasses);
        request.setAttribute("allSelectedGroups", newsgclasses);
    }
    session.setAttribute("newDataset", db);
    HashMap events = (HashMap) session.getAttribute(CreateDatasetServlet.EVENTS_FOR_CREATE_DATASET);
    if (events == null) {
        events = new HashMap();
    }
    ArrayList allSelectItems = selectAll ? selectAll(events, crfdao, idao) : ViewSelectedServlet.getAllSelected(db, idao, imfdao);
    // >> tbh
    session.setAttribute("numberOfStudyItems", new Integer(ids.size()).toString());
    // << tbh 11/2009
    session.setAttribute("allSelectedItems", allSelectItems);
    setUpStudyGroups();
    forwardPage(Page.CREATE_DATASET_VIEW_SELECTED);
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) MessageFormat(java.text.MessageFormat) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)

Example 28 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class FormBeanUtil method createDisplaySectionBWithFormGroupsForPrint.

public DisplaySectionBean createDisplaySectionBWithFormGroupsForPrint(int sectionId, int crfVersionId, DataSource dataSource, int eventCRFDefId, EventCRFBean eventCrfBean, ServletContext context) {
    DisplaySectionBean displaySectionBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(dataSource);
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(dataSource);
    ItemDAO itemDao = new ItemDAO(dataSource);
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    SectionDAO sectionDao = new SectionDAO(dataSource);
    // Give the DisplaySectionBean a legitimate SectionBean
    SectionBean secBean = (SectionBean) sectionDao.findByPK(sectionId);
    displaySectionBean.setSection(secBean);
    // changed from: findGroupBySectionId
    List<ItemGroupBean> itemGroupBeans = formGroupDAO.findLegitGroupAllBySectionId(sectionId);
    // all items associated with the section, including those not in a group
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    // Sort these items according to their position on the CRF; their
    // ordinal
    Collections.sort(allMetas);
    // The DisplayItemGroupBean(s) for "nongrouped" items
    List<DisplayItemGroupBean> nonGroupBeans = null;
    // if(itemGroupBeans.isEmpty()) return displaySectionBean;
    // Find out whether there are any checkboxes/radios/select elements
    // and if so, get any null values
    // associated with them
    List<String> nullValuesList = new ArrayList<String>();
    boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
    if (itemsHaveChecksRadios && eventCRFDefId > 0) {
        // method returns null values as a List<String>
        nullValuesList = this.getNullValuesByEventCRFDefId(eventCRFDefId, dataSource);
    }
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayItemGBean;
    for (ItemGroupBean itemGroup : itemGroupBeans) {
        //TODO:fix me!
        itBeans = itemDao.findAllItemsByGroupIdForPrint(itemGroup.getId(), crfVersionId, sectionId);
        logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
        //TODO:fix me add item_form_metadata.section_id to the query
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSectionForPrint(itemGroup.getId(), crfVersionId, sectionId);
        if (!metadata.isEmpty()) {
            // for a given crf version, all the items in the same group
            // have the same group metadata info
            // so we can get one of the metadata and set the metadata for
            // the group
            ItemGroupMetadataBean meta = metadata.get(0);
            itemGroup.setMeta(meta);
        }
        displayItems = getDisplayBeansFromItemsForPrint(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context, crfVersionId);
        displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
        displayFormBeans.add(displayItemGBean);
    }
    // We still have to sort these display item group beans on their
    // ItemGroupMetadataBean?
    // then number their ordinals accordingly
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
            return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
        }
    });
    // Now provide the display item group beans with an ordinal
    int digOrdinal = 0;
    for (DisplayItemGroupBean digBean : displayFormBeans) {
        digBean.setOrdinal(++digOrdinal);
    }
    // find out whether there are any ungrouped items by comparing the
    // number of
    // grouped items to allMetas.size()
    // List<DisplayItemGroupBean> nonGroupBeans=null;
    int tempCount = 0;
    for (DisplayItemGroupBean groupBean : displayFormBeans) {
        tempCount += groupBean.getItems().size();
    }
    if (tempCount < allMetas.size()) {
        nonGroupBeans = createGroupBeansForNongroupedItems(allMetas, displayFormBeans, sectionId, dataSource, nullValuesList, eventCrfBean, context);
    }
    if (nonGroupBeans != null) {
        displayFormBeans.addAll(nonGroupBeans);
    }
    // sort the list according to the ordinal of the contained
    // DisplayItemGroupBeans
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
            Integer compInt = disFormGroupBean1.getOrdinal();
            Integer compInt2 = disFormGroupBean.getOrdinal();
            return compInt2.compareTo(compInt);
        }
    });
    displaySectionBean.setDisplayFormGroups(displayFormBeans);
    return displaySectionBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 29 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class FormBeanUtil method sectionHasUngroupedItems.

public boolean sectionHasUngroupedItems(DataSource dataSource, int sectionId, List<DisplayItemGroupBean> displayFormBeans) {
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    int size = allMetas.size();
    int tempCount = 0;
    String grpName = "";
    // Only count grouped items
    for (DisplayItemGroupBean groupBean : displayFormBeans) {
        grpName = groupBean.getItemGroupBean().getName();
        if (!(grpName.equalsIgnoreCase("Ungrouped") || grpName.length() < 1)) {
            tempCount += groupBean.getItems().size();
        }
    }
    return tempCount < size;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 30 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class FormBeanUtil method getDisplayBeansFromItems.

/**
     * Create a List of DisplayItemBeans from a List of Items.
     * 
     * @param itemBeans
     *            A List of ItemBeans that will provide the source of each
     *            DisplayItemBean
     * @param dataSource
     *            A DataSource for the DAO classes.
     * @param crfVersionId
     *            The CRF version Id for fetching associated
     *            ItemFormMetadataBeans.
     * @param sectionId
     *            The section ID associated with the Items.
     * @param nullValuesList
     *            A List of Strings containing "null values" such as "not
     *            applicable" or NA.
     * @return A List of DisplayItemBeans.
     */
public static List<DisplayItemBean> getDisplayBeansFromItems(List<ItemBean> itemBeans, DataSource dataSource, EventCRFBean eventCrfBean, int sectionId, List<String> nullValuesList, ServletContext context) {
    // logger = LoggerFactory.getLogger(getClass().getName());
    List<DisplayItemBean> disBeans = new ArrayList<DisplayItemBean>();
    if (itemBeans == null || itemBeans.isEmpty())
        return disBeans;
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    ItemDataDAO itemDataDAO = new ItemDataDAO(dataSource);
    DisplayItemBean displayBean;
    ItemFormMetadataBean meta;
    // Add any null values to checks or radios
    String responseName;
    List<ResponseOptionBean> respOptions;
    ResponseOptionBean respBean;
    boolean hasNullValues = nullValuesList != null && !nullValuesList.isEmpty();
    String tmpVal = "";
    // findByItemIdAndCRFVersionId
    for (ItemBean iBean : itemBeans) {
        displayBean = new DisplayItemBean();
        //TODO: eventcrfBean is not valid??
        meta = metaDao.findByItemIdAndCRFVersionId(iBean.getId(), eventCrfBean.getCRFVersionId());
        // Only include Items that belong to the associated section
        if (meta.getSectionId() == sectionId) {
            displayBean.setItem(iBean);
            //findByItemIdAndEventCRFIdAndOrdinal(iBean.getId(), eventCrfBean.getId(), ordinal)
            ItemDataBean itemDataBean = itemDataDAO.findByItemIdAndEventCRFId(iBean.getId(), eventCrfBean.getId());
            // null values is set by adding the event def. crf bean, but
            // here we have taken a different approach, tbh
            // displayBean.setEventDefinitionCRF();
            displayBean.setMetadata(runDynamicsCheck(meta, eventCrfBean, itemDataBean, context));
            displayBean.setData(itemDataBean);
            displayBean.setDbData(itemDataBean);
            // System.out.println("just set: " + itemDataBean.getValue() + " from " + itemDataBean.getItemId());
            responseName = displayBean.getMetadata().getResponseSet().getResponseType().getName();
            respOptions = displayBean.getMetadata().getResponseSet().getOptions();
            if (hasNullValues && respOptions != null && ("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName) || "single-select".equalsIgnoreCase(responseName) || "multi-select".equalsIgnoreCase(responseName))) {
                for (String val : nullValuesList) {
                    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);
                }
            }
            disBeans.add(displayBean);
        // logger.info("### respOptions size
        // "+respOptions.size()+" of item name "+iBean.getName());
        }
    // logger.info("### found name "+iBean.getName()+" and found
    // response size: "+
    // displayBean.getMetadata().getResponseSet().getOptions().size());
    }
    // sort the List of DisplayItemBeans on their ordinal
    Collections.sort(disBeans);
    return disBeans;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Aggregations

ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)31 ArrayList (java.util.ArrayList)25 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)25 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)21 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)20 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)13 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)13 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)11 HashMap (java.util.HashMap)10 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)9 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)9 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)8 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)8 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)8 SectionDAO (org.akaza.openclinica.dao.submit.SectionDAO)8 ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)7 ItemGroupDAO (org.akaza.openclinica.dao.submit.ItemGroupDAO)7