Search in sources :

Example 6 with ItemDAO

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

the class ViewCRFServlet method verifyUniqueItemPlacementInGroups.

private ArrayList<ItemGroupCrvVersionUtil> verifyUniqueItemPlacementInGroups(String crfName) {
    // get all items with group / version info from db
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    int check_group_count = 0;
    StringBuffer item_messages = null;
    // use for first record in the group
    String temp_buffer = null;
    ArrayList<ItemGroupCrvVersionUtil> results = new ArrayList<ItemGroupCrvVersionUtil>();
    ItemGroupCrvVersionUtil cur_item = null;
    StringBuffer error_message = null;
    ArrayList<ItemGroupCrvVersionUtil> item_group_crf_records = idao.findAllWithItemDetailsGroupCRFVersionMetadataByCRFId(crfName);
    for (ItemGroupCrvVersionUtil check_group : item_group_crf_records) {
        if (results.size() == 0 || !check_group.getItemName().equals(cur_item.getItemName())) {
            // delete ',' from versions property
            cur_item = new ItemGroupCrvVersionUtil(check_group.getItemName(), check_group.getGroupName(), check_group.getGroupOID(), check_group.getCrfVersionName(), check_group.getCrfVersionStatus(), check_group.getItemOID(), check_group.getItemDescription(), check_group.getItemDataType(), check_group.getId());
            cur_item.setVersions(check_group.getCrfVersionName());
            temp_buffer = respage.getString("verifyUniqueItemPlacementInGroups_4") + check_group.getGroupName() + respage.getString("verifyUniqueItemPlacementInGroups_5") + check_group.getCrfVersionName() + "'";
            results.add(cur_item);
        } else {
            if (check_group.getItemName().equals(cur_item.getItemName()) && !check_group.getGroupName().equals(cur_item.getGroupName())) {
                // add message for the first item
                error_message = new StringBuffer();
                error_message.append(respage.getString("verifyUniqueItemPlacementInGroups_4") + check_group.getGroupName());
                error_message.append(respage.getString("verifyUniqueItemPlacementInGroups_5"));
                error_message.append(check_group.getCrfVersionName());
                // if ( temp_buffer != null){cur_item.setErrorMesages(cur_item.getErrorMesages() + temp_buffer);}
                if (temp_buffer != null) {
                    cur_item.getArrErrorMesages().add(temp_buffer);
                }
                temp_buffer = null;
                cur_item.getArrErrorMesages().add(error_message);
                if (check_group.getCrfVersionStatus() == 1 && cur_item.getCrfVersionStatus() != 1) {
                    cur_item.setCrfVersionStatus(1);
                }
            }
            cur_item.setVersions(cur_item.getVersions() + "," + check_group.getCrfVersionName());
        }
    }
    return results;
}
Also used : ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemGroupCrvVersionUtil(org.akaza.openclinica.core.util.ItemGroupCrvVersionUtil) ArrayList(java.util.ArrayList)

Example 7 with ItemDAO

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

the class EditSelectedServlet method selectAll.

public DatasetBean selectAll(DatasetBean db) {
    HashMap events = (HashMap) session.getAttribute(CreateDatasetServlet.EVENTS_FOR_CREATE_DATASET);
    if (events == null) {
        events = new HashMap();
    }
    request.setAttribute("eventlist", events);
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    ArrayList allItems = selectAll(events, crfdao, idao);
    Iterator it = events.keySet().iterator();
    while (it.hasNext()) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) it.next();
        if (!db.getEventIds().contains(new Integer(sed.getId()))) {
            db.getEventIds().add(new Integer(sed.getId()));
        }
    }
    // for (int j = 0; j < allItems.size(); j++) {
    // ItemBean item = (ItemBean) allItems.get(j);
    // ArrayList ids = db.getItemIds();
    // ArrayList itemDefCrfs = db.getItemDefCrf();
    // Integer itemId = new Integer(item.getId());
    // if (!ids.contains(itemId)) {
    // ids.add(itemId);
    // itemDefCrfs.add(item);
    // }
    // }
    db.getItemDefCrf().clear();
    db.setItemDefCrf(allItems);
    return db;
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)

Example 8 with ItemDAO

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

the class CreateDatasetServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    String action = fp.getString("action");
    if (StringUtil.isBlank(action)) {
        // step 1 -- instructions, and continue button
        session.setAttribute("newDataset", new DatasetBean());
        session.setAttribute("allItems", new ArrayList());
        session.setAttribute("crf", new CRFBean());
        session.setAttribute("allSelectedItems", new ArrayList());
        forwardPage(Page.CREATE_DATASET_1);
    } else {
        StudyBean studyWithEventDefs = currentStudy;
        if (currentStudy.getParentStudyId() > 0) {
            studyWithEventDefs = new StudyBean();
            studyWithEventDefs.setId(currentStudy.getParentStudyId());
        }
        if ("begin".equalsIgnoreCase(action)) {
            // step 2 -- select study events/crfs
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            StudyBean studyWithEventDefinitions = currentStudy;
            if (currentStudy.getParentStudyId() > 0) {
                studyWithEventDefinitions = new StudyBean();
                studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
            }
            ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
            CRFDAO crfdao = new CRFDAO(sm.getDataSource());
            HashMap events = new LinkedHashMap();
            for (int i = 0; i < seds.size(); i++) {
                StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
                ArrayList<CRFBean> crfs = (ArrayList<CRFBean>) crfdao.findAllActiveByDefinition(sed);
                if (currentStudy.getParentStudyId() > 0) {
                    // sift through these CRFs and see which ones are hidden
                    HideCRFManager hideCRFs = HideCRFManager.createHideCRFManager();
                    crfs = hideCRFs.removeHiddenCRFBeans(studyWithEventDefinitions, sed, crfs, sm.getDataSource());
                }
                if (!crfs.isEmpty()) {
                    events.put(sed, crfs);
                }
            }
            // datasets
            if (events.isEmpty()) {
                addPageMessage(respage.getString("not_have_study_definitions_assigned"));
                forwardPage(Page.CREATE_DATASET_1);
            } else {
                crfdao = new CRFDAO(sm.getDataSource());
                ItemDAO idao = new ItemDAO(sm.getDataSource());
                ArrayList sedItemIds = CreateDatasetServlet.allSedItemIdsInStudy(events, crfdao, idao);
                session.setAttribute("numberOfStudyItems", Integer.toString(sedItemIds.size()));
                request.setAttribute("eventlist", events);
                session.setAttribute(EVENTS_FOR_CREATE_DATASET, events);
                session.setAttribute("newDataset", new DatasetBean());
                session.setAttribute("allItems", new ArrayList());
                session.setAttribute("crf", new CRFBean());
                forwardPage(Page.CREATE_DATASET_2);
            }
        } else if ("beginsubmit".equalsIgnoreCase(action)) {
            String saveItems = fp.getString(SAVE_BUTTON);
            String saveContinue = fp.getString(SAVE_CONTINUE_BUTTON);
            DatasetBean db = (DatasetBean) session.getAttribute("newDataset");
            if (db == null) {
                db = new DatasetBean();
            }
            extractIdsFromForm(db);
            extractEventIds(db);
            session.setAttribute("newDataset", db);
            // +"");
            if (!StringUtil.isBlank(saveItems)) {
                request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
                // BWP 3095>>
                String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_so_far");
                summary += genAttMsg(db);
                addPageMessage(summary);
                int crfId = fp.getInt("crfId");
                if (crfId > 0) {
                    // user choose a crf and select items
                    forwardPage(Page.CREATE_DATASET_2);
                } else {
                    ArrayList sgclasses = (ArrayList) session.getAttribute("allSelectedGroups");
                    if (sgclasses == null || sgclasses.size() == 0) {
                        sgclasses = setUpStudyGroups();
                    }
                    session.setAttribute("allSelectedGroups", sgclasses);
                    request.setAttribute("allSelectedGroups", sgclasses);
                    // TODO push out list of subject groups here???
                    // form submitted from "view selected item ' or
                    // attribute page, so
                    // forward back to "view selected item " page
                    forwardPage(Page.CREATE_DATASET_VIEW_SELECTED);
                }
            } else {
                if (db.getItemIds().size() == 0) {
                    request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
                    addPageMessage(respage.getString("should_select_one_item_to_create_dataset"));
                    forwardPage(Page.CREATE_DATASET_2);
                } else {
                    String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_totally_for_this_dataset");
                    summary += genAttMsg(db);
                    addPageMessage(summary);
                    // 0 means using
                    fp.addPresetValue("firstmonth", 0);
                    // default month
                    fp.addPresetValue("firstyear", 1900);
                    fp.addPresetValue("lastmonth", 0);
                    fp.addPresetValue("lastyear", 2100);
                    setPresetValues(fp.getPresetValues());
                    logger.warn("found preset values while setting date: " + fp.getPresetValues().toString());
                    request.setAttribute(BEAN_MONTHS, getMonths());
                    request.setAttribute(BEAN_YEARS, getYears());
                    forwardPage(Page.CREATE_DATASET_3);
                }
            }
        } else if ("scopesubmit".equalsIgnoreCase(action)) {
            ArrayList months = getMonths();
            ArrayList years = getYears();
            int firstMonth = fp.getInt("firstmonth");
            int firstYear = fp.getInt("firstyear");
            int lastMonth = fp.getInt("lastmonth");
            int lastYear = fp.getInt("lastyear");
            if (fp.getInt("firstmonth") == 0) {
                // default value
                firstMonth = 1;
            }
            if (fp.getInt("lastmonth") == 0) {
                // default value
                lastMonth = 12;
            }
            errors = new HashMap();
            if (fp.getInt("firstmonth") > 0 && firstYear == 1900) {
                Validator.addError(errors, "firstmonth", restext.getString("if_specify_month_also_specify_year"));
            }
            if (fp.getInt("lastmonth") > 0 && lastYear == 2100) {
                Validator.addError(errors, "lastmonth", restext.getString("if_specify_month_also_specify_year"));
            }
            Date dateStart = getFirstDayOfMonth(firstYear, firstMonth);
            Date dateEnd = getLastDayOfMonth(lastYear, lastMonth);
            if (dateEnd.compareTo(dateStart) < 0) {
                Validator.addError(errors, "firstmonth", restext.getString("the_from_should_be_come_before_to"));
            }
            if (!errors.isEmpty()) {
                String[] fieldNames = { "firstmonth", "firstyear", "lastmonth", "lastyear" };
                fp.setCurrentIntValuesAsPreset(fieldNames);
                setInputMessages(errors);
                addPageMessage(respage.getString("errors_in_submission_see_below"));
                setPresetValues(fp.getPresetValues());
                request.setAttribute(BEAN_MONTHS, getMonths());
                request.setAttribute(BEAN_YEARS, getYears());
                forwardPage(Page.CREATE_DATASET_3);
            } else {
                DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
                dsb.setDateStart(dateStart);
                dsb.setDateEnd(dateEnd);
                session.setAttribute("newDataset", dsb);
                if (fp.getString("submit").equals(resword.getString("continue_to_apply_filter"))) {
                    // FilterDAO fdao = new FilterDAO(sm.getDataSource());
                    // Collection filters = fdao.findAll();
                    // TODO make findAllByProject
                    // request.setAttribute("filters",filters);
                    EntityBeanTable table = getFilterTable();
                    session.setAttribute("partOfCreateDataset", new Integer(1));
                    // to be used in createFiltersThree servlet, tbh
                    request.setAttribute("table", table);
                    forwardPage(Page.APPLY_FILTER);
                } else {
                    request.setAttribute("statuses", Status.toActiveArrayList());
                    // YW, 2-20-2008 <<these attributes will show on the
                    // CREATE_DATASET_4
                    String temp = dsb.getODMMetaDataVersionOid();
                    request.setAttribute("mdvOID", temp != null && temp.length() > 0 ? temp : "v1.0.0");
                    temp = dsb.getODMMetaDataVersionName();
                    request.setAttribute("mdvName", temp != null && temp.length() > 0 ? temp : "MetaDataVersion_v1.0.0");
                    request.setAttribute("mdvPrevStudy", dsb.getODMPriorStudyOid());
                    request.setAttribute("mdvPrevOID", dsb.getODMPriorMetaDataVersionOid());
                    // YW >>
                    forwardPage(Page.CREATE_DATASET_4);
                }
            }
        } else if ("specifysubmit".equalsIgnoreCase(action)) {
            Validator v = new Validator(request);
            v.addValidation("dsName", Validator.NO_BLANKS);
            v.addValidation("dsName", Validator.NO_SEMI_COLONS_OR_COLONS);
            v.addValidation("dsDesc", Validator.NO_BLANKS);
            v.addValidation("dsStatus", Validator.IS_VALID_TERM, TermType.STATUS);
            v.addValidation("dsName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
            v.addValidation("dsDesc", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
            String mdvOID = fp.getString("mdvOID");
            String mdvName = fp.getString("mdvName");
            String mdvPrevStudy = fp.getString("mdvPrevStudy");
            if (mdvPrevStudy != null && mdvPrevStudy.length() > 0) {
                v.addValidation("mdvPrevOID", Validator.NO_BLANKS);
            }
            String mdvPrevOID = fp.getString("mdvPrevOID");
            errors = v.validate();
            String dsName = fp.getString("dsName");
            if (!StringUtil.isBlank(dsName)) {
                // YW, << 3-19-2008
                if (dsName.contains("/") || dsName.contains("\\")) {
                    v.addError(errors, "dsName", restext.getString("slash_not_allowed"));
                }
                // 2-20-2008, no check for editing dataset
                if (((DatasetBean) session.getAttribute("newDataset")).getId() <= 0) {
                    // YW >>
                    // logger.info("dsName" + fp.getString("dsName"));
                    DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
                    DatasetBean dsBean = (DatasetBean) dsdao.findByNameAndStudy(fp.getString("dsName").trim(), currentStudy);
                    if (dsBean.getId() > 0) {
                        Validator.addError(errors, "dsName", restext.getString("dataset_name_used_by_another_choose_unique"));
                    }
                }
            }
            if (!errors.isEmpty()) {
                String[] fieldNames = { "dsName", "dsDesc" };
                fp.setCurrentStringValuesAsPreset(fieldNames);
                fp.addPresetValue("dsStatusId", fp.getInt("dsStatus"));
                fp.addPresetValue("mdvOID", mdvOID);
                fp.addPresetValue("mdvName", mdvName);
                fp.addPresetValue("mdvPrevStudy", mdvPrevStudy);
                fp.addPresetValue("mdvPrevOID", mdvPrevOID);
                addPageMessage(respage.getString("errors_in_submission_see_below"));
                setInputMessages(errors);
                setPresetValues(fp.getPresetValues());
                request.setAttribute("statuses", Status.toActiveArrayList());
                forwardPage(Page.CREATE_DATASET_4);
            } else {
                session.setAttribute("mdvOID", mdvOID);
                session.setAttribute("mdvName", mdvName);
                session.setAttribute("mdvPrevStudy", mdvPrevStudy);
                session.setAttribute("mdvPrevOID", mdvPrevOID);
                if (mdvPrevOID != null && mdvPrevOID.length() > 0 && (mdvPrevStudy == null || mdvPrevStudy.length() <= 0)) {
                    mdvPrevStudy = currentStudy.getId() + "";
                }
                DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
                dsb.setSQLStatement(dsb.generateQuery());
                String dbName = SQLInitServlet.getField("dataBase");
                if ("oracle".equals(dbName)) {
                    dsb.setSQLStatement(dsb.generateOracleQuery());
                }
                // TODO set up oracle syntax for the query, grab the
                // database
                // from the session manager and feed it to the dataset bean
                // possibly done, tbh 1/4/2005
                // TODO look for the filter here, re-create the sql
                // statement
                // and put it in here
                // possibly done need to test, tbh 1/7/2005
                FilterBean fb = (FilterBean) session.getAttribute("newFilter");
                if (fb != null) {
                    // FilterDAO fDAO = new FilterDAO(sm.getDataSource());
                    dsb.setSQLStatement(dsb.getSQLStatement() + " " + fb.getSQLStatement());
                }
                // dataset if dataset name has been changed.
                if (dsb.getId() > 0 && !dsb.getName().equals(fp.getString("dsName"))) {
                    dsb.setId(0);
                }
                // YW >>
                dsb.setODMMetaDataVersionName(mdvName);
                dsb.setODMMetaDataVersionOid(mdvOID);
                dsb.setODMPriorMetaDataVersionOid(mdvPrevOID);
                dsb.setODMPriorStudyOid(mdvPrevStudy);
                dsb.setName(fp.getString("dsName"));
                dsb.setDescription(fp.getString("dsDesc"));
                dsb.setStatus(Status.get(fp.getInt("dsStatus")));
                dsb.setDatasetItemStatus(DatasetItemStatus.get(fp.getInt("itemStatus")));
                session.removeAttribute("partOfCreateDataset");
                Date ddate = new SimpleDateFormat("MM/dd/yyyy").parse("01/01/1900");
                // done to remove the set up of going to get the filter, tbh
                // set up dataset here, grab primary key???!!!???
                // added by jxu
                request.setAttribute("defaultStart", local_df.parse(local_df.format(ddate)));
                request.setAttribute("defaultEnd", getLastDayOfMonth(2100, 12));
                session.setAttribute("newDataset", dsb);
                forwardPage(Page.CONFIRM_DATASET);
            }
        } else if ("confirmall".equalsIgnoreCase(action)) {
            String submit = fp.getString("btnSubmit");
            logger.info("reached confirm all");
            if (!resword.getString("confirm_and_save").equalsIgnoreCase(submit)) {
                // we're going back, so we should not destroy the
                // data we've created, tbh
                // session.removeAttribute("newDataset");
                // session.removeAttribute("newFilter");
                forwardPage(Page.CREATE_DATASET_4);
            } else {
                DatasetDAO ddao = new DatasetDAO(sm.getDataSource());
                DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
                dsb.setStudyId(this.currentStudy.getId());
                dsb.setOwner(ub);
                // dsb.setOwnerId(ub.getId());
                //
                // at this point, dataset itemId will still be kept
                // uniquely.
                dsb = finalUpateDatasetBean(dsb);
                if (dsb.getId() == 0) {
                    // if the bean hasn't been created already that is...
                    logger.info("*** about to create the dataset bean");
                    dsb = (DatasetBean) ddao.create(dsb);
                    logger.info("created dataset bean: " + dsb.getId() + ", name: " + dsb.getName());
                    if (!dsb.isActive()) {
                        addPageMessage(restext.getString("problem_creating_dataset_try_again"));
                        forwardPage(Page.EXTRACT_DATASETS_MAIN);
                    }
                } else // YW, 2-20-2008 << for editing existing dataset
                if (dsb.getId() > 0) {
                    dsb = (DatasetBean) ddao.updateAll(dsb);
                    if (!dsb.isActive()) {
                        addPageMessage(restext.getString("problem_creating_dataset_try_again"));
                        forwardPage(Page.EXTRACT_DATASETS_MAIN);
                    }
                    dsb = (DatasetBean) ddao.updateGroupMap(dsb);
                    if (!dsb.isActive()) {
                        addPageMessage(restext.getString("problem_updating_subject_group_class_when_updating_dataset"));
                        forwardPage(Page.EXTRACT_DATASETS_MAIN);
                    }
                }
                // YW >>
                logger.info("setting data set id here");
                // may be easier to just set the dataset bean
                // back into the session?
                request.setAttribute("dataset", dsb);
                forwardPage(Page.EXPORT_DATASETS);
            }
        } else {
            // refine this bit to catch errors, hopefully
            addPageMessage(restext.getString("creating_new_dataset_cancelled"));
            forwardPage(Page.CREATE_DATASET_1);
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) LinkedHashMap(java.util.LinkedHashMap) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) FilterBean(org.akaza.openclinica.bean.extract.FilterBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) Date(java.util.Date) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) SimpleDateFormat(java.text.SimpleDateFormat) Validator(org.akaza.openclinica.control.form.Validator)

Example 9 with ItemDAO

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

the class ViewEventCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int eventCRFId = fp.getInt("id", true);
    int studySubId = fp.getInt("studySubId", true);
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    SectionDAO secdao = new SectionDAO(sm.getDataSource());
    if (eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_an_event_CRF_to_view"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
    } else {
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        request.setAttribute("studySub", studySub);
        EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
        CRFBean crf = cdao.findByVersionId(eventCRF.getCRFVersionId());
        request.setAttribute("crf", crf);
        ArrayList sections = secdao.findAllByCRFVersionId(eventCRF.getCRFVersionId());
        for (int j = 0; j < sections.size(); j++) {
            SectionBean section = (SectionBean) sections.get(j);
            ArrayList itemData = iddao.findAllByEventCRFId(eventCRFId);
            ArrayList displayItemData = new ArrayList();
            for (int i = 0; i < itemData.size(); i++) {
                ItemDataBean id = (ItemDataBean) itemData.get(i);
                DisplayItemBean dib = new DisplayItemBean();
                ItemBean item = (ItemBean) idao.findByPK(id.getItemId());
                ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(item.getId(), eventCRF.getCRFVersionId());
                item.setItemMeta(ifm);
                dib.setItem(item);
                dib.setData(id);
                dib.setMetadata(ifm);
                displayItemData.add(dib);
            }
            section.setItems(displayItemData);
        }
        request.setAttribute("sections", sections);
        request.setAttribute("studySubId", new Integer(studySubId).toString());
        forwardPage(Page.VIEW_EVENT_CRF);
    }
}
Also used : EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 10 with ItemDAO

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

the class DataEntryServlet method loadItemsWithGroupRows.

protected void loadItemsWithGroupRows(DisplayItemWithGroupBean itemWithGroup, SectionBean sb, EventDefinitionCRFBean edcb, EventCRFBean ecb, HttpServletRequest request) {
    //this method is a copy of the method: createItemWithGroups ,
    //only modified for load one DisplayItemWithGroupBean.
    //
    ItemDAO idao = new ItemDAO(getDataSource());
    // For adding null values to display items
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<String> nullValuesList = new ArrayList<String>();
    // BWP>> Get a List<String> of any null values such as NA or NI
    // method returns null values as a List<String>
    nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(edcb.getId(), getDataSource());
    // >>BWP
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    ArrayList data = iddao.findAllActiveBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
    DisplayItemGroupBean itemGroup = itemWithGroup.getItemGroup();
    // to arrange item groups and other single items, the ordinal of
    // a item group will be the ordinal of the first item in this
    // group
    DisplayItemBean firstItem = itemGroup.getItems().get(0);
    DisplayItemBean checkItem = firstItem;
    // does not work if there is not any data in the first item of the group
    // i.e. imports.
    // does it make a difference if we take a last item?
    boolean noNeedToSwitch = false;
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        if (idb.getItemId() == firstItem.getItem().getId()) {
            noNeedToSwitch = true;
        }
    }
    if (!noNeedToSwitch) {
        checkItem = itemGroup.getItems().get(itemGroup.getItems().size() - 1);
    }
    // so we are either checking the first or the last item, BUT ONLY ONCE
    itemWithGroup.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
    itemWithGroup.setItemGroup(itemGroup);
    itemWithGroup.setInGroup(true);
    itemWithGroup.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
    List<ItemBean> itBeans = idao.findAllItemsByGroupId(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
    boolean hasData = false;
    int checkAllColumns = 0;
    // first item should be same as the row number
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        LOGGER.debug("check all columns: " + checkAllColumns);
        if (idb.getItemId() == checkItem.getItem().getId()) {
            hasData = true;
            LOGGER.debug("set has data to --TRUE--");
            checkAllColumns = 0;
            // so that we only fire once a row
            LOGGER.debug("has data set to true");
            DisplayItemGroupBean digb = new DisplayItemGroupBean();
            // always get a fresh copy for items, may use other
            // better way to
            // do deep copy, like clone
            List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), edcb, 0, getServletContext());
            digb.setItems(dibs);
            LOGGER.trace("set with dibs list of : " + dibs.size());
            digb.setGroupMetaBean(runDynamicsCheck(itemGroup.getGroupMetaBean(), request));
            digb.setItemGroupBean(itemGroup.getItemGroupBean());
            itemWithGroup.getItemGroups().add(digb);
            itemWithGroup.getDbItemGroups().add(digb);
        }
    }
    List<DisplayItemGroupBean> groupRows = itemWithGroup.getItemGroups();
    LOGGER.trace("how many group rows:" + groupRows.size());
    LOGGER.trace("how big is the data:" + data.size());
    if (hasData) {
        // the group
        for (int i = 0; i < groupRows.size(); i++) {
            DisplayItemGroupBean displayGroup = groupRows.get(i);
            for (DisplayItemBean dib : displayGroup.getItems()) {
                for (int j = 0; j < data.size(); j++) {
                    ItemDataBean idb = (ItemDataBean) data.get(j);
                    if (idb.getItemId() == dib.getItem().getId() && !idb.isSelected()) {
                        idb.setSelected(true);
                        dib.setData(idb);
                        LOGGER.debug("--> set data " + idb.getId() + ": " + idb.getValue());
                        if (shouldLoadDBValues(dib)) {
                            LOGGER.debug("+++should load db values is true, set value");
                            dib.loadDBValue();
                            LOGGER.debug("+++data loaded: " + idb.getName() + ": " + idb.getOrdinal() + " " + idb.getValue());
                            LOGGER.debug("+++try dib OID: " + dib.getItem().getOid());
                        }
                        break;
                    }
                }
            }
        }
    } else {
        // no data, still add a blank row for displaying
        DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
        List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
        digb2.setItems(dibs);
        LOGGER.trace("set with nullValuesList of : " + nullValuesList);
        digb2.setEditFlag("initial");
        digb2.setGroupMetaBean(itemGroup.getGroupMetaBean());
        digb2.setItemGroupBean(itemGroup.getItemGroupBean());
        itemWithGroup.getItemGroups().add(digb2);
        itemWithGroup.getDbItemGroups().add(digb2);
    }
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean)

Aggregations

ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)56 ArrayList (java.util.ArrayList)43 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)43 HashMap (java.util.HashMap)25 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)22 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)22 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)21 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)21 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)20 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)19 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)18 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)16 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)14 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)14 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)14 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)13 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)12 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)12 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)12