Search in sources :

Example 31 with EntityBeanTable

use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.

the class ExtractDatasetsMainServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList datasets = (ArrayList) dsdao.findTopFive(currentStudy);
    ArrayList datasetRows = DatasetRow.generateRowsFromBeans(datasets);
    String[] columns = { resword.getString("dataset_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("view_all"), "ViewDatasets");
    table.addLink(resword.getString("view_my_datasets"), "ViewDatasets?action=owner&ownerId=" + ub.getId());
    table.addLink(resword.getString("create_dataset"), "CreateDataset");
    table.setQuery("ExtractDatasetsMain", new HashMap());
    table.setRows(datasetRows);
    table.computeDisplay();
    request.setAttribute("table", table);
    // the code above replaces the following lines:
    // DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
    // ArrayList datasets = (ArrayList)dsdao.findTopFive();
    // request.setAttribute("datasets", datasets);
    resetPanel();
    request.setAttribute(STUDY_INFO_PANEL, panel);
    forwardPage(Page.EXTRACT_DATASETS_MAIN);
}
Also used : HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO)

Example 32 with EntityBeanTable

use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.

the class RemoveDatasetServlet method getDatasetTable.

private EntityBeanTable getDatasetTable() {
    FormProcessor fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
    ArrayList datasets = new ArrayList();
    // if (ub.isSysAdmin()) {
    // datasets =
    // (ArrayList)dsdao.findAllByStudyIdAdmin(currentStudy.getId());
    // } else {
    datasets = dsdao.findAllByStudyId(currentStudy.getId());
    // }
    ArrayList datasetRows = DatasetRow.generateRowsFromBeans(datasets);
    String[] columns = { resword.getString("dataset_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("show_only_my_datasets"), "ViewDatasets?action=owner&ownerId=" + ub.getId());
    table.addLink(resword.getString("create_dataset"), "CreateDataset");
    table.setQuery("ViewDatasets", new HashMap());
    table.setRows(datasetRows);
    table.computeDisplay();
    return table;
}
Also used : HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO)

Example 33 with EntityBeanTable

use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.

the class ListEventsForSubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    String pageNumber = fp.getString(ListStudySubjectServlet.SUBJECT_PAGE_NUMBER);
    String filterKeyword = fp.getString(ListStudySubjectServlet.FILTER_KEYWORD);
    String tmpSearch = fp.getString(ListStudySubjectServlet.SEARCH_SUBMITTED);
    boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword);
    SubjectMatrixUtil matrixUtil = new SubjectMatrixUtil();
    String query = matrixUtil.createPaginatingQuery(pageNumber);
    StringBuilder extendedQuery = new StringBuilder(query);
    // URL encode the search keyword, since it will be a parameter in the
    // URL
    String filterKeywordURLEncode = java.net.URLEncoder.encode(filterKeyword, "UTF-8");
    if (searchSubmitted) {
        extendedQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
        extendedQuery.append("&").append(ListStudySubjectServlet.FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
    }
    request.setAttribute(ListStudySubjectServlet.PAGINATING_QUERY, extendedQuery.toString());
    int definitionId = fp.getInt("defId");
    int tabId = fp.getInt("tab");
    if (definitionId <= 0) {
        addPageMessage(respage.getString("please_choose_an_ED_ta_to_vies_details"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
        return;
    }
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(definitionId);
    StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    // find all the groups in the current study
    ArrayList studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
    // information for the event tabs
    ArrayList allDefs = seddao.findAllActiveByStudy(currentStudy);
    boolean isASite = false;
    if (currentStudy.getParentStudyId() > 0) {
        StudyDAO stdao = new StudyDAO(sm.getDataSource());
        StudyBean parent = (StudyBean) stdao.findByPK(currentStudy.getParentStudyId());
        allDefs = seddao.findAllActiveByStudy(parent);
    }
    ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(this.currentStudy, definitionId);
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        CRFBean crf = (CRFBean) crfdao.findByPK(edc.getCrfId());
        edc.setCrf(crf);
    }
    request.setAttribute("studyGroupClasses", studyGroupClasses);
    request.setAttribute("allDefsArray", allDefs);
    request.setAttribute("allDefsNumber", new Integer(allDefs.size()));
    request.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
    request.setAttribute("eventDefCRFSize", new Integer(eventDefinitionCRFs.size()));
    request.setAttribute("tabId", new Integer(tabId));
    request.setAttribute("studyEventDef", sed);
    request.setAttribute("eventDefCRFs", eventDefinitionCRFs);
    // find all the subjects in current study
    ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
    ArrayList displayStudySubs = new ArrayList();
    for (int i = 0; i < subjects.size(); i++) {
        StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
        ArrayList groups = (ArrayList) sgmdao.findAllByStudySubject(studySub.getId());
        ArrayList subGClasses = new ArrayList();
        for (int j = 0; j < studyGroupClasses.size(); j++) {
            StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(j);
            boolean hasClass = false;
            for (int k = 0; k < groups.size(); k++) {
                SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groups.get(k);
                if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
                    subGClasses.add(sgmb);
                    hasClass = true;
                    break;
                }
            }
            if (!hasClass) {
                subGClasses.add(new SubjectGroupMapBean());
            }
        }
        // find all eventcrfs for each event, for each event tab
        ArrayList displaySubjectEvents = new ArrayList();
        ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
        ArrayList events = sedao.findAllByStudySubjectAndDefinition(studySub, sed);
        for (int k = 0; k < events.size(); k++) {
            StudyEventBean seb = (StudyEventBean) events.get(k);
            DisplayStudyEventBean dseb = ListStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, seb, sm.getDataSource(), ub, currentRole, this.currentStudy);
            // ArrayList eventCRFs = ecdao.findAllByStudyEvent(seb);
            // ArrayList al =
            // ViewStudySubjectServlet.getUncompletedCRFs(sm.getDataSource(),
            // eventDefinitionCRFs, eventCRFs);
            // dseb.getUncompletedCRFs().add(al);
            displayEvents.add(dseb);
        }
        ArrayList al = new ArrayList();
        for (int k = 0; k < displayEvents.size(); k++) {
            DisplayStudyEventBean dseb = displayEvents.get(k);
            ArrayList eventCRFs = dseb.getDisplayEventCRFs();
            for (int a = 0; a < eventDefinitionCRFs.size(); a++) {
                EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(a);
                int crfId = edc.getCrfId();
                boolean hasCRF = false;
                for (int b = 0; b < eventCRFs.size(); b++) {
                    DisplayEventCRFBean decb = (DisplayEventCRFBean) eventCRFs.get(b);
                    // decb.getStage().getName() );
                    if (decb.getEventCRF().getCrf().getId() == crfId) {
                        dseb.getAllEventCRFs().add(decb);
                        // logger.info("hasCRf" + crfId +
                        // decb.getEventCRF().getCrf().getName());
                        hasCRF = true;
                        break;
                    }
                }
                if (hasCRF == false) {
                    DisplayEventCRFBean db = new DisplayEventCRFBean();
                    db.setEventDefinitionCRF(edc);
                    db.getEventDefinitionCRF().setCrf(edc.getCrf());
                    dseb.getAllEventCRFs().add(db);
                // logger.info("noCRf" + crfId);
                }
            }
            // Issue 3212 BWP <<
            if (currentStudy.getParentStudyId() > 0) {
                // check each eventDefCRFBean and set its isHidden property
                // to true, if its
                // persistent/database-derived hideCrf is true (domain rule:
                // hide the CRF from users logged into a site)
                HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
                hideCRFManager.optionallyCheckHideCRFProperty(dseb);
                // remove a DisplayEventCRFBean from a DisplayStudyEventBean
                // in the list
                // if it contains a hidden CRF in its event definition
                hideCRFManager.removeHiddenEventCRF(dseb);
                // generate a boolean request attribute indicating whether
                // any of the CRFs
                // should be hidden
                boolean hideCRFs = hideCRFManager.studyEventHasAHideCRFProperty(dseb);
                request.setAttribute("hideCRFs", hideCRFs);
            }
        // >>
        }
        DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
        dssb.setStudySubject(studySub);
        dssb.setStudyGroups(subGClasses);
        dssb.setStudyEvents(displayEvents);
        if (definitionId > 0) {
            dssb.setSedId(definitionId);
        } else {
            dssb.setSedId(-1);
        }
        displayStudySubs.add(dssb);
    }
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudySubjectEventsRow.generateRowsFromBeans(displayStudySubs);
    ArrayList columnArray = new ArrayList();
    columnArray.add(resword.getString("ID"));
    columnArray.add(resword.getString("subject_status"));
    columnArray.add(resword.getString("gender"));
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        columnArray.add(sgc.getName());
    }
    // columnArray.add("Event Sequence");
    columnArray.add(resword.getString("event_status"));
    columnArray.add(resword.getString("event_date"));
    // Issue 3212 BWP <<
    HideCRFManager hideCRFMgr = HideCRFManager.createHideCRFManager();
    hideCRFMgr.hideSpecifiedEventCRFDefBeans(eventDefinitionCRFs);
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        // Issue 3212 BWP <<
        if (!(currentStudy.getParentStudyId() > 0)) {
            columnArray.add(edc.getCrf().getName());
        } else {
            if (!edc.isHideCrf()) {
                columnArray.add(edc.getCrf().getName());
            }
        }
    // >>
    }
    columnArray.add(resword.getString("actions"));
    String[] columns = new String[columnArray.size()];
    columnArray.toArray(columns);
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.setQuery("ListEventsForSubject?module=" + module + "&defId=" + definitionId + "&tab=" + tabId, new HashMap());
    table.hideColumnLink(columnArray.size() - 1);
    // if(currentStudy.getStatus().isAvailable()){
    // table.addLink(resword.getString("add_new_subject"), "AddNewSubject");
    // }
    table.setRows(allStudyRows);
    if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
        table.setKeywordFilter(filterKeyword);
    }
    table.computeDisplay();
    request.setAttribute("table", table);
    forwardPage(Page.LIST_EVENTS_FOR_SUBJECT);
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 34 with EntityBeanTable

use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.

the class ListStudyServlet method processRequest.

/**
     * Finds all the studies
     *
     */
@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    ArrayList studies = (ArrayList) sdao.findAll();
    // find all parent studies
    ArrayList parents = (ArrayList) sdao.findAllParents();
    ArrayList displayStudies = new ArrayList();
    for (int i = 0; i < parents.size(); i++) {
        StudyBean parent = (StudyBean) parents.get(i);
        ArrayList children = (ArrayList) sdao.findAllByParent(parent.getId());
        DisplayStudyBean displayStudy = new DisplayStudyBean();
        displayStudy.setParent(parent);
        displayStudy.setChildren(children);
        displayStudies.add(displayStudy);
    }
    FormProcessor fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudyRow.generateRowsFromBeans(displayStudies);
    String[] columns = { resword.getString("name"), resword.getString("unique_identifier"), resword.getString("OID"), resword.getString("principal_investigator"), resword.getString("facility_name"), resword.getString("date_created"), resword.getString("status"), resword.getString("actions") };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.hideColumnLink(2);
    table.hideColumnLink(6);
    table.setQuery("ListStudy", new HashMap());
    table.addLink(resword.getString("create_a_new_study"), "CreateStudy");
    table.setRows(allStudyRows);
    table.computeDisplay();
    request.setAttribute("table", table);
    // request.setAttribute("studies", studies);
    session.setAttribute("fromListSite", "no");
    resetPanel();
    panel.setStudyInfoShown(false);
    panel.setOrderedData(true);
    setToPanel(resword.getString("in_the_application"), "");
    if (parents.size() > 0) {
        setToPanel(resword.getString("studies"), new Integer(parents.size()).toString());
    }
    if (studies.size() > 0) {
        setToPanel(resword.getString("sites"), new Integer(studies.size() - parents.size()).toString());
    }
    forwardPage(Page.STUDY_LIST);
}
Also used : 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) DisplayStudyBean(org.akaza.openclinica.bean.admin.DisplayStudyBean) DisplayStudyBean(org.akaza.openclinica.bean.admin.DisplayStudyBean) ArrayList(java.util.ArrayList) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 35 with EntityBeanTable

use of org.akaza.openclinica.web.bean.EntityBeanTable 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)

Aggregations

EntityBeanTable (org.akaza.openclinica.web.bean.EntityBeanTable)37 ArrayList (java.util.ArrayList)34 HashMap (java.util.HashMap)34 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)34 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)11 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)10 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)10 DatasetDAO (org.akaza.openclinica.dao.extract.DatasetDAO)9 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)9 FilterDAO (org.akaza.openclinica.dao.extract.FilterDAO)8 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)7 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)7 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)7 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)6 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)6 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)6 Date (java.util.Date)5 Iterator (java.util.Iterator)5 Map (java.util.Map)5 FilterBean (org.akaza.openclinica.bean.extract.FilterBean)5