Search in sources :

Example 16 with StudyEventDefinitionDAO

use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.

the class AuditLogStudyServlet method processRequest.

/*
     * (non-Javadoc) Assume that we get the user id automatically. We will jump
     * from the edit user page if the user is an admin, they can get to see the
     * users' log
     * 
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
/*
     * (non-Javadoc) redo this servlet to run the audits per study subject for
     * the study; need to add a studyId param and then use the
     * StudySubjectDAO.findAllByStudyOrderByLabel() method to grab a lot of
     * study subject beans and then return them much like in
     * ViewStudySubjectAuditLogServet.process()
     * 
     * currentStudy instead of studyId?
     */
@Override
protected void processRequest() throws Exception {
    int studyId = currentStudy.getId();
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    AuditDAO adao = new AuditDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO studydao = new StudyDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    HashMap eventCRFAuditsHashMap = new HashMap();
    HashMap eventsHashMap = new HashMap();
    HashMap studySubjectAuditsHashMap = new HashMap();
    HashMap subjectHashMap = new HashMap();
    ArrayList studySubjects = subdao.findAllByStudyOrderByLabel(currentStudy);
    logger.info("found " + studySubjects.size() + " study subjects");
    request.setAttribute("studySubjects", studySubjects);
    for (int ss = 0; ss < studySubjects.size(); ss++) {
        ArrayList studySubjectAudits = new ArrayList();
        ArrayList eventCRFAudits = new ArrayList();
        StudySubjectBean studySubject = (StudySubjectBean) studySubjects.get(ss);
        // request.setAttribute("studySub"+ss, studySubject);
        SubjectBean subject = (SubjectBean) sdao.findByPK(studySubject.getSubjectId());
        subjectHashMap.put(new Integer(studySubject.getId()), subject);
        // logger.info("just set a subject with a status of
        // "+subject.getStatus().getName());
        // request.setAttribute("subject"+ss, subject);
        StudyBean study = (StudyBean) studydao.findByPK(studySubject.getStudyId());
        request.setAttribute("study", study);
        // hmm, repetitive work?
        // Show both study subject and subject audit events together
        // Study
        studySubjectAudits.addAll(adao.findStudySubjectAuditEvents(studySubject.getId()));
        // subject
        // value
        // changed
        // Global
        studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
        // subject
        // value
        // changed
        studySubjectAuditsHashMap.put(new Integer(studySubject.getId()), studySubjectAudits);
        // request.setAttribute("studySubjectAudits"+ss,
        // studySubjectAudits);
        // Get the list of events
        ArrayList events = sedao.findAllByStudySubject(studySubject);
        for (int i = 0; i < events.size(); i++) {
            // Link study event definitions
            StudyEventBean studyEvent = (StudyEventBean) events.get(i);
            studyEvent.setStudyEventDefinition((StudyEventDefinitionBean) seddao.findByPK(studyEvent.getStudyEventDefinitionId()));
            // Link event CRFs
            studyEvent.setEventCRFs(ecdao.findAllByStudyEvent(studyEvent));
        }
        // for (int i = 0; i < events.size(); i++) {
        // StudyEventBean studyEvent = (StudyEventBean) events.get(i);
        // ArrayList eventCRFs = studyEvent.getEventCRFs();
        // for (int j = 0; j < eventCRFs.size(); j++) {
        // //Link CRF and CRF Versions
        // EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(j);
        // eventCRF.setCrfVersion((CRFVersionBean)
        // cvdao.findByPK(eventCRF.getCRFVersionId()));
        // eventCRF.setCrf((CRFBean)
        // cdao.findByVersionId(eventCRF.getCRFVersionId()));
        // //Get the event crf audits
        // eventCRFAudits.addAll(adao.findEventCRFAuditEvents(eventCRF.getId()));
        // }
        // }
        eventsHashMap.put(new Integer(studySubject.getId()), events);
    // request.setAttribute("events"+ss, events);
    // eventCRFAuditsHashMap.put(new Integer(studySubject.getId()),
    // eventCRFAudits);
    // request.setAttribute("eventCRFAudits"+ss, eventCRFAudits);
    }
    // request.setAttribute("eventCRFAudits", eventCRFAuditsHashMap);
    request.setAttribute("events", eventsHashMap);
    request.setAttribute("studySubjectAudits", studySubjectAuditsHashMap);
    request.setAttribute("study", currentStudy);
    request.setAttribute("subjects", subjectHashMap);
    // FormProcessor fp = new FormProcessor(request);
    // 
    // AuditEventDAO aeDAO = new AuditEventDAO(sm.getDataSource());
    // ArrayList al = aeDAO.findAllByStudyId(currentStudy.getId());
    // 
    // EntityBeanTable table = fp.getEntityBeanTable();
    // ArrayList allRows = AuditEventStudyRow.generateRowsFromBeans(al);
    // String[] columns = { "Date and Time", "Action", "Entity/Operation",
    // "Record ID", "Changes and Additions","Other Info" };
    // table.setColumns(new ArrayList(Arrays.asList(columns)));
    // table.hideColumnLink(4);
    // table.hideColumnLink(1);
    // table.hideColumnLink(5);
    // table.setQuery("AuditLogUser?userLogId="+userId, new HashMap());
    // String[] columns =
    // {resword.getString("date_and_time"),resword.getString("action_message"),
    // resword.getString("entity_operation"),
    // resword.getString("updated_by"),resword.getString("subject_unique_ID"),resword.getString("changes_and_additions"),
    // //"Other Info",
    // resword.getString("actions")};
    // table.setColumns(new ArrayList(Arrays.asList(columns)));
    // table.setAscendingSort(false);
    // table.hideColumnLink(1);
    // table.hideColumnLink(5);
    // table.hideColumnLink(6);
    // //table.hideColumnLink(7);
    // table.setQuery("AuditLogStudy", new HashMap());
    // table.setRows(allRows);
    // table.computeDisplay();
    // 
    // 
    // request.setAttribute("table", table);
    logger.warn("*** found servlet, sending to page ***");
    String pattn = "";
    String pattern2 = "";
    pattn = ResourceBundleProvider.getFormatBundle().getString("date_format_string");
    pattern2 = ResourceBundleProvider.getFormatBundle().getString("date_time_format_string");
    request.setAttribute("dateFormatPattern", pattn);
    request.setAttribute("dateTimeFormatPattern", pattern2);
    forwardPage(Page.AUDIT_LOG_STUDY);
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) AuditDAO(org.akaza.openclinica.dao.admin.AuditDAO) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 17 with StudyEventDefinitionDAO

use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO 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 18 with StudyEventDefinitionDAO

use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.

the class EditDatasetServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int dsId = fp.getInt("dsId");
    DatasetBean dataset = initializeAttributes(dsId);
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    StudyBean study = (StudyBean) sdao.findByPK(dataset.getStudyId());
    // Checking if user has permission to access the current study/site
    checkRoleByUserAndStudy(ub, study.getParentStudyId(), study.getId());
    // Checking the dataset belongs to current study or a site of current study
    if (study.getId() != currentStudy.getId() && study.getParentStudyId() != currentStudy.getId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    if ((currentRole.isMonitor() || currentRole.isInvestigator()) && dataset.getOwnerId() != ub.getId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    HashMap events = (LinkedHashMap) session.getAttribute("eventsForCreateDataset");
    // << tbh
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    // >> tbh 11/2009
    if (events == null || events.isEmpty()) {
        events = new LinkedHashMap();
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyBean studyWithEventDefinitions = currentStudy;
        if (currentStudy.getParentStudyId() > 0) {
            studyWithEventDefinitions = new StudyBean();
            studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
        }
        ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
        for (int i = 0; i < seds.size(); i++) {
            StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
            ArrayList crfs = (ArrayList) crfdao.findAllActiveByDefinition(sed);
            if (!crfs.isEmpty()) {
                events.put(sed, crfs);
            }
        }
        if (events.isEmpty()) {
            addPageMessage(respage.getString("not_have_study_definitions_assigned"));
            forwardPage(Page.VIEW_DATASETS);
        } else {
            request.setAttribute("eventlist", events);
            session.setAttribute("eventsForCreateDataset", events);
        }
    }
    /*
         * if ("validate".equalsIgnoreCase(action)) { //check name, description, status for right now Validator v = new Validator(request);
         * v.addValidation("dsName", Validator.NO_BLANKS); 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); //what else to validate?
         * HashMap errors = v.validate(); if (!StringUtil.isBlank(fp.getString("dsName"))) { //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 && (dsBean.getId() != fp.getInt("dsId"))) { 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("dsStatus", fp.getInt("dsStatus"));
         * addPageMessage(restext.getString("errors_in_update_see_below")); setInputMessages(errors); setPresetValues(fp.getPresetValues()); //TODO determine if
         * this is necessary //int dsId = fp.getInt("dsId"); //DatasetDAO dsDAO = new DatasetDAO(sm.getDataSource()); //DatasetBean showDataset = (DatasetBean)
         * dsDAO.findByPK(dsId); request.setAttribute("dataset", dataset); //maybe just set the above to the session? request.setAttribute("statuses",
         * getStatuses()); forwardPage(Page.EDIT_DATASET); } else { dataset.setName(fp.getString("dsName")); dataset.setDescription(fp.getString("dsDesc"));
         * dataset.setStatus(Status.get(fp.getInt("dsStatus"))); dataset.setUpdater(ub); //dataset.setUpdaterId(ub.getId()); dsDAO.update(dataset);
         * addPageMessage(restext.getString("dataset_properties_updated")); //forward to view all datasets ArrayList datasets = (ArrayList)
         * dsDAO.findAllByStudyId(currentStudy.getId()); //changed from findAll() EntityBeanTable table = fp.getEntityBeanTable(); 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.setQuery("ViewDatasets", new HashMap()); table.setRows(datasetRows);
         * table.computeDisplay(); request.setAttribute("table", table); //request.setAttribute("datasets", datasets); forwardPage(Page.VIEW_DATASETS); } } else
         * {
         */
    request.setAttribute("dataset", dataset);
    request.setAttribute("statuses", getStatuses());
    forwardPage(Page.EDIT_DATASET);
// }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with StudyEventDefinitionDAO

use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.

the class ViewStudyServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt("id");
    if (studyId == 0) {
        addPageMessage(respage.getString("please_choose_a_study_to_view"));
        forwardPage(Page.STUDY_LIST_SERVLET);
    } else {
        if (currentStudy.getId() != studyId && currentStudy.getParentStudyId() != studyId) {
            checkRoleByUserAndStudy(ub, studyId, 0);
        }
        String viewFullRecords = fp.getString("viewFull");
        StudyBean study = (StudyBean) sdao.findByPK(studyId);
        StudyConfigService scs = new StudyConfigService(sm.getDataSource());
        study = scs.setParametersForStudy(study);
        StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
        String randomizationStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "randomization").getValue();
        String participantStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "participantPortal").getValue();
        if (participantStatusInOC == "")
            participantStatusInOC = "disabled";
        if (randomizationStatusInOC == "")
            randomizationStatusInOC = "disabled";
        RandomizationRegistrar randomizationRegistrar = new RandomizationRegistrar();
        SeRandomizationDTO seRandomizationDTO = randomizationRegistrar.getCachedRandomizationDTOObject(study.getOid(), false);
        if (seRandomizationDTO != null && seRandomizationDTO.getStatus().equalsIgnoreCase("ACTIVE") && randomizationStatusInOC.equalsIgnoreCase("enabled")) {
            study.getStudyParameterConfig().setRandomization("enabled");
        } else {
            study.getStudyParameterConfig().setRandomization("disabled");
        }
        ;
        ParticipantPortalRegistrar participantPortalRegistrar = new ParticipantPortalRegistrar();
        String pStatus = participantPortalRegistrar.getCachedRegistrationStatus(study.getOid(), session);
        if (participantPortalRegistrar != null && pStatus.equalsIgnoreCase("ACTIVE") && participantStatusInOC.equalsIgnoreCase("enabled")) {
            study.getStudyParameterConfig().setParticipantPortal("enabled");
        } else {
            study.getStudyParameterConfig().setParticipantPortal("disabled");
        }
        ;
        request.setAttribute("studyToView", study);
        if ("yes".equalsIgnoreCase(viewFullRecords)) {
            UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
            StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
            ArrayList sites = new ArrayList();
            ArrayList userRoles = new ArrayList();
            ArrayList subjects = new ArrayList();
            if (this.currentStudy.getParentStudyId() > 0 && this.currentRole.getRole().getId() > 3) {
                sites.add(this.currentStudy);
                userRoles = udao.findAllUsersByStudy(currentStudy.getId());
                subjects = ssdao.findAllByStudy(currentStudy);
            } else {
                sites = (ArrayList) sdao.findAllByParent(studyId);
                userRoles = udao.findAllUsersByStudy(studyId);
                subjects = ssdao.findAllByStudy(study);
            }
            // find all subjects in the study, include ones in sites
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            // StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            // ArrayList displayStudySubs = new ArrayList();
            // for (int i = 0; i < subjects.size(); i++) {
            // StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
            // // find all events
            // ArrayList events = sedao.findAllByStudySubject(studySub);
            // 
            // // find all eventcrfs for each event
            // EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            // 
            // DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
            // dssb.setStudyEvents(events);
            // dssb.setStudySubject(studySub);
            // displayStudySubs.add(dssb);
            // }
            // find all events in the study, include ones in sites
            ArrayList definitions = seddao.findAllByStudy(study);
            for (int i = 0; i < definitions.size(); i++) {
                StudyEventDefinitionBean def = (StudyEventDefinitionBean) definitions.get(i);
                ArrayList crfs = (ArrayList) edcdao.findAllActiveParentsByEventDefinitionId(def.getId());
                def.setCrfNum(crfs.size());
            }
            String moduleManager = CoreResources.getField("moduleManager");
            request.setAttribute("moduleManager", moduleManager);
            String portalURL = CoreResources.getField("portalURL");
            request.setAttribute("portalURL", portalURL);
            request.setAttribute("config", study);
            request.setAttribute("sitesToView", sites);
            request.setAttribute("siteNum", sites.size() + "");
            request.setAttribute("userRolesToView", userRoles);
            request.setAttribute("userNum", userRoles.size() + "");
            // request.setAttribute("subjectsToView", displayStudySubs);
            // request.setAttribute("subjectNum", subjects.size() + "");
            request.setAttribute("definitionsToView", definitions);
            request.setAttribute("defNum", definitions.size() + "");
            forwardPage(Page.VIEW_FULL_STUDY);
        } else {
            forwardPage(Page.VIEW_STUDY);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyConfigService(org.akaza.openclinica.dao.service.StudyConfigService) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) RandomizationRegistrar(org.akaza.openclinica.service.pmanage.RandomizationRegistrar) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) SeRandomizationDTO(org.akaza.openclinica.service.pmanage.SeRandomizationDTO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 20 with StudyEventDefinitionDAO

use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.

the class DefineStudyEventServlet method submitDefinition.

/**
 * Inserts the new study into database NullPointer catch added by tbh
 * 092007, mean to fix task #1642 in Mantis
 */
private void submitDefinition() throws NullPointerException {
    StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
    // added tbh 092007, to catch bug # 1531
    if (sed.getName() == "" || sed.getName() == null) {
        throw new NullPointerException();
    }
    logger.debug("Definition bean to be created:" + sed.getName() + sed.getStudyId());
    // fine the last one's ordinal
    ArrayList defs = edao.findAllByStudy(currentStudy);
    if (defs == null || defs.isEmpty()) {
        sed.setOrdinal(1);
    } else {
        int lastCount = defs.size() - 1;
        StudyEventDefinitionBean last = (StudyEventDefinitionBean) defs.get(lastCount);
        sed.setOrdinal(last.getOrdinal() + 1);
    }
    sed.setOwner(ub);
    sed.setCreatedDate(new Date());
    sed.setStatus(Status.AVAILABLE);
    StudyEventDefinitionBean sed1 = (StudyEventDefinitionBean) edao.create(sed);
    EventDefinitionCRFDAO cdao = new EventDefinitionCRFDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList eventDefinitionCRFs = new ArrayList();
    if (session.getAttribute("edCRFs") != null) {
        eventDefinitionCRFs = (ArrayList) session.getAttribute("edCRFs");
    }
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        edc.setOwner(ub);
        edc.setCreatedDate(new Date());
        edc.setStatus(Status.AVAILABLE);
        edc.setStudyEventDefinitionId(sed1.getId());
        edc.setOrdinal(i + 1);
        StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) seddao.findByPK(sed.getId());
        CRFBean cBean = (CRFBean) crfdao.findByPK(edc.getCrfId());
        String crfPath = sedBean.getOid() + "." + cBean.getOid();
        getEventDefinitionCrfTagService().saveEventDefnCrfOfflineTag(2, crfPath, edc, sedBean);
        cdao.create(edc);
    }
    session.removeAttribute("definition");
    session.removeAttribute("edCRFs");
    session.removeAttribute("crfsWithVersion");
    addPageMessage(respage.getString("the_new_event_definition_created_succesfully"));
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) Date(java.util.Date) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Aggregations

StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)101 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)86 ArrayList (java.util.ArrayList)76 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)69 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)62 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)60 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)57 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)55 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)55 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)51 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)50 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)48 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)45 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)44 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)43 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)40 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)40 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)37 Date (java.util.Date)36 HashMap (java.util.HashMap)28