Search in sources :

Example 6 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class CreateCRFVersionServlet method processRequest.

@SuppressWarnings("unchecked")
@Override
public void processRequest() throws Exception {
    resetPanel();
    panel.setStudyInfoShown(true);
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    // keep the module in the session
    session.setAttribute(MODULE, module);
    request.setAttribute("xformEnabled", CoreResources.getField("xform.enabled"));
    String action = request.getParameter("action");
    CRFVersionBean version = (CRFVersionBean) session.getAttribute("version");
    if (StringUtil.isBlank(action)) {
        logger.debug("action is blank");
        request.setAttribute("version", version);
        forwardPage(Page.CREATE_CRF_VERSION);
    } else if ("confirm".equalsIgnoreCase(action)) {
        String dir = SQLInitServlet.getField("filePath");
        if (!new File(dir).exists()) {
            logger.debug("The filePath in datainfo.properties is invalid " + dir);
            addPageMessage(resword.getString("the_filepath_you_defined"));
            forwardPage(Page.CREATE_CRF_VERSION);
            // BWP 01/13/2009 >>
            return;
        // >>
        }
        // All the uploaded files will be saved in filePath/crf/original/
        String theDir = dir + "crf" + File.separator + "original" + File.separator;
        if (!new File(theDir).isDirectory()) {
            new File(theDir).mkdirs();
            logger.debug("Made the directory " + theDir);
        }
        // MultipartRequest multi = new MultipartRequest(request, theDir, 50 * 1024 * 1024);
        String tempFile = "";
        try {
            tempFile = uploadFile(theDir, version);
        } catch (CRFReadingException crfException) {
            Validator.addError(errors, "excel_file", crfException.getMessage());
            String msg = crfException.getMessage();
            request.setAttribute("formMessages", errors);
            forwardPage(Page.CREATE_CRF_VERSION);
            return;
        } catch (Exception e) {
            // 
            logger.warn("*** Found exception during file upload***");
            e.printStackTrace();
        }
        session.setAttribute("tempFileName", tempFile);
        // provided and/or not xls format
        if (errors.isEmpty()) {
            String s = ((NewCRFBean) session.getAttribute("nib")).getVersionName();
            if (s.length() > 255) {
                Validator.addError(errors, "excel_file", resword.getString("the_version_CRF_version_more_than_255"));
            } else if (s.length() <= 0) {
                Validator.addError(errors, "excel_file", resword.getString("the_VERSION_column_was_blank"));
            }
            version.setName(s);
            if (version.getCrfId() == 0) {
                version.setCrfId(fp.getInt("crfId"));
            }
            session.setAttribute("version", version);
        }
        if (!errors.isEmpty()) {
            logger.debug("has validation errors ");
            request.setAttribute("formMessages", errors);
            forwardPage(Page.CREATE_CRF_VERSION);
        } else {
            CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
            ArrayList versions = (ArrayList) vdao.findAllByCRF(crf.getId());
            for (int i = 0; i < versions.size(); i++) {
                CRFVersionBean version1 = (CRFVersionBean) versions.get(i);
                if (version.getName().equals(version1.getName())) {
                    // version already exists
                    logger.debug("Version already exists; owner or not:" + ub.getId() + "," + version1.getOwnerId());
                    if (ub.getId() != version1.getOwnerId()) {
                        // not owner
                        addPageMessage(respage.getString("CRF_version_try_upload_exists_database") + version1.getOwner().getName() + respage.getString("please_contact_owner_to_delete"));
                        forwardPage(Page.CREATE_CRF_VERSION);
                        return;
                    } else {
                        // owner,
                        ArrayList definitions = edao.findByDefaultVersion(version1.getId());
                        if (!definitions.isEmpty()) {
                            // used in
                            // definition
                            request.setAttribute("definitions", definitions);
                            forwardPage(Page.REMOVE_CRF_VERSION_DEF);
                            return;
                        } else {
                            // not used in definition
                            int previousVersionId = version1.getId();
                            version.setId(previousVersionId);
                            session.setAttribute("version", version);
                            session.setAttribute("previousVersionId", new Integer(previousVersionId));
                            forwardPage(Page.REMOVE_CRF_VERSION_CONFIRM);
                            return;
                        }
                    }
                }
            }
            // didn't find same version in the DB,let user upload the excel
            // file
            logger.debug("didn't find same version in the DB,let user upload the excel file.");
            // List excelErr =
            // ((ArrayList)request.getAttribute("excelErrors"));
            List excelErr = (ArrayList) session.getAttribute("excelErrors");
            logger.debug("excelErr.isEmpty()=" + excelErr.isEmpty());
            if (excelErr != null && excelErr.isEmpty()) {
                addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
                forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
            } else {
                logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
                forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
            }
            return;
        }
    } else if ("confirmsql".equalsIgnoreCase(action)) {
        NewCRFBean nib = (NewCRFBean) session.getAttribute("nib");
        if (nib != null && nib.getItemQueries() != null) {
            request.setAttribute("openQueries", nib.getItemQueries());
        } else {
            request.setAttribute("openQueries", new HashMap());
        }
        boolean canDelete = false;
        // check whether need to delete previous version
        Boolean deletePreviousVersion = (Boolean) session.getAttribute("deletePreviousVersion");
        Integer previousVersionId = (Integer) session.getAttribute("previousVersionId");
        if (deletePreviousVersion != null && deletePreviousVersion.equals(Boolean.TRUE) && previousVersionId != null && previousVersionId.intValue() > 0) {
            logger.debug("Need to delete previous version");
            // whether we can delete
            canDelete = canDeleteVersion(previousVersionId.intValue());
            if (!canDelete) {
                logger.debug("but cannot delete previous version");
                if (session.getAttribute("itemsHaveData") == null && session.getAttribute("eventsForVersion") == null) {
                    addPageMessage(respage.getString("you_are_not_owner_some_items_cannot_delete"));
                }
                if (session.getAttribute("itemsHaveData") == null) {
                    session.setAttribute("itemsHaveData", new ArrayList());
                }
                if (session.getAttribute("eventsForVersion") == null) {
                    session.setAttribute("eventsForVersion", new ArrayList());
                }
                forwardPage(Page.CREATE_CRF_VERSION_NODELETE);
                return;
            }
            ArrayList<ItemBean> nonSharedItems = (ArrayList<ItemBean>) vdao.findNotSharedItemsByVersion(previousVersionId.intValue());
            // htaycher: here is the trick we need to put in nib1.setItemQueries()
            // update statements for shared items and insert for nonShared that were just deleted 5927
            HashMap item_table_statements = new HashMap();
            ArrayList<String> temp = new ArrayList<String>(nonSharedItems.size());
            for (ItemBean item : nonSharedItems) {
                temp.add(item.getName());
                item_table_statements.put(item.getName(), nib.getBackupItemQueries().get(item.getName()));
            }
            for (String item_name : (Set<String>) nib.getItemQueries().keySet()) {
                // check if item shared
                if (!temp.contains(item_name)) {
                    item_table_statements.put(item_name, nib.getItemQueries().get(item_name));
                }
            }
            // statements to run
            if (!nonSharedItems.isEmpty()) {
                request.setAttribute("openQueries", item_table_statements);
            }
            // htaycher: put all statements in
            nib.setItemQueries(item_table_statements);
            session.setAttribute("nib", nib);
        }
        // submit
        logger.debug("commit sql");
        NewCRFBean nib1 = (NewCRFBean) session.getAttribute("nib");
        if (nib1 != null) {
            try {
                if (canDelete) {
                    nib1.deleteInsertToDB();
                } else {
                    nib1.insertToDB();
                }
                request.setAttribute("queries", nib1.getQueries());
                // YW << for add a link to "View CRF Version Data Entry".
                // For this purpose, CRFVersion id is needed.
                // So the latest CRFVersion Id of A CRF Id is it.
                CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
                ArrayList crfvbeans = new ArrayList();
                logger.debug("CRF-ID [" + version.getCrfId() + "]");
                int crfVersionId = 0;
                String versionOID = null;
                if (version.getCrfId() != 0) {
                    crfvbeans = cvdao.findAllByCRFId(version.getCrfId());
                    CRFVersionBean cvbean = (CRFVersionBean) crfvbeans.get(crfvbeans.size() - 1);
                    crfVersionId = cvbean.getId();
                    versionOID = cvbean.getOid();
                    for (Iterator iter = crfvbeans.iterator(); iter.hasNext(); ) {
                        cvbean = (CRFVersionBean) iter.next();
                        if (crfVersionId < cvbean.getId()) {
                            crfVersionId = cvbean.getId();
                        }
                    }
                }
                // Not needed; crfVersionId will be autoboxed in Java 5
                // this was added for the old CVS java compiler
                Integer cfvID = new Integer(crfVersionId);
                if (cfvID == 0) {
                    cfvID = cvdao.findCRFVersionId(nib1.getCrfId(), nib1.getVersionName());
                }
                CRFVersionBean finalVersion = (CRFVersionBean) cvdao.findByPK(cfvID);
                version.setCrfId(nib1.getCrfId());
                version.setOid(finalVersion.getOid());
                CRFBean crfBean = (CRFBean) cdao.findByPK(version.getCrfId());
                crfBean.setUpdatedDate(version.getCreatedDate());
                crfBean.setUpdater(ub);
                cdao.update(crfBean);
                // workaround to get a correct file name below, tbh 06/2008
                request.setAttribute("crfVersionId", cfvID);
                // YW >>
                // return those properties to initial values
                session.removeAttribute("version");
                session.removeAttribute("eventsForVersion");
                session.removeAttribute("itemsHaveData");
                session.removeAttribute("nib");
                session.removeAttribute("deletePreviousVersion");
                session.removeAttribute("previousVersionId");
                // save new version spreadsheet
                String tempFile = (String) session.getAttribute("tempFileName");
                if (tempFile != null) {
                    logger.debug("*** ^^^ *** saving new version spreadsheet" + tempFile);
                    try {
                        String dir = SQLInitServlet.getField("filePath");
                        File f = new File(dir + "crf" + File.separator + "original" + File.separator + tempFile);
                        // check to see whether crf/new/ folder exists
                        // inside, if not,
                        // creates
                        // the crf/new/ folder
                        String finalDir = dir + "crf" + File.separator + "new" + File.separator;
                        if (!new File(finalDir).isDirectory()) {
                            logger.debug("need to create folder for excel files" + finalDir);
                            new File(finalDir).mkdirs();
                        }
                        // String newFile = version.getCrfId() +
                        // version.getName() + ".xls";
                        String newFile = version.getCrfId() + version.getOid() + ".xls";
                        logger.debug("*** ^^^ *** new file: " + newFile);
                        File nf = new File(finalDir + newFile);
                        logger.debug("copying old file " + f.getName() + " to new file " + nf.getName());
                        copy(f, nf);
                    // ?
                    } catch (IOException ie) {
                        logger.debug("==============");
                        addPageMessage(respage.getString("CRF_version_spreadsheet_could_not_saved_contact"));
                    }
                }
                session.removeAttribute("tempFileName");
                session.removeAttribute(MODULE);
                session.removeAttribute("excelErrors");
                session.removeAttribute("htmlTab");
                forwardPage(Page.CREATE_CRF_VERSION_DONE);
            } catch (OpenClinicaException pe) {
                logger.debug("--------------");
                session.setAttribute("excelErrors", nib1.getErrors());
                // request.setAttribute("excelErrors", nib1.getErrors());
                forwardPage(Page.CREATE_CRF_VERSION_ERROR);
            }
        } else {
            forwardPage(Page.CREATE_CRF_VERSION);
        }
    } else if ("delete".equalsIgnoreCase(action)) {
        logger.debug("user wants to delete previous version");
        List excelErr = (ArrayList) session.getAttribute("excelErrors");
        logger.debug("for overwrite CRF version, excelErr.isEmpty()=" + excelErr.isEmpty());
        if (excelErr != null && excelErr.isEmpty()) {
            addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
            // should be moved to excelErr != null block
            session.setAttribute("deletePreviousVersion", Boolean.TRUE);
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
        } else {
            // should be moved to excelErr != null
            session.setAttribute("deletePreviousVersion", Boolean.FALSE);
            // block
            logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
            forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CRFReadingException(org.akaza.openclinica.exception.CRFReadingException) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) 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) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) IOException(java.io.IOException) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) CRFReadingException(org.akaza.openclinica.exception.CRFReadingException) IOException(java.io.IOException) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) File(java.io.File)

Example 7 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class PrintAllEventCRFServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    ArrayList<SectionBean> allSectionBeans;
    // The PrintDataEntry servlet handles this parameter
    boolean isSubmitted = false;
    StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    StudyDAO studyDao = new StudyDAO(sm.getDataSource());
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
    seds = sedao.findAllByStudy(currentStudy);
    // ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByStudy(site);
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> edcs = new ArrayList();
    for (StudyEventDefinitionBean sed : seds) {
        int defId = sed.getId();
        edcs.addAll(edcdao.findAllByDefinition(currentStudy, defId));
    }
    Map eventDefinitionDefaultVersions = new LinkedHashMap();
    for (int i = 0; i < edcs.size(); i++) {
        EventDefinitionCRFBean edc = edcs.get(i);
        ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
        edc.setVersions(versions);
        CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
        // edc.setCrfLabel(crf.getLabel());
        edc.setCrfName(crf.getName());
        // to show/hide edit action on jsp page
        if (crf.getStatus().equals(Status.AVAILABLE)) {
            edc.setOwner(crf.getOwner());
        }
        CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
        StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) sedao.findByPK(edc.getStudyEventDefinitionId());
        edc.setDefaultVersionName(defaultVersion.getName());
        if (defaultVersion.getStatus().isAvailable()) {
            List list = (ArrayList) eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
            if (list == null)
                list = new ArrayList();
            list.add(defaultVersion);
            eventDefinitionDefaultVersions.put(studyEventDefinitionBean, list);
        }
    }
    // Whether IE6 or IE7 is involved
    String isIE = fp.getString("ie");
    if ("y".equalsIgnoreCase(isIE)) {
        request.setAttribute("isInternetExplorer", "true");
    }
    SectionDAO sdao = new SectionDAO(sm.getDataSource());
    CRFVersionDAO crfVersionDAO = new CRFVersionDAO(sm.getDataSource());
    CRFDAO crfDao = new CRFDAO(sm.getDataSource());
    Map sedCrfBeans = null;
    for (Iterator it = eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
        if (sedCrfBeans == null)
            sedCrfBeans = new LinkedHashMap();
        StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) it.next();
        List crfVersions = (ArrayList) eventDefinitionDefaultVersions.get(sedBean);
        for (Iterator crfIt = crfVersions.iterator(); crfIt.hasNext(); ) {
            CRFVersionBean crfVersionBean = (CRFVersionBean) crfIt.next();
            allSectionBeans = new ArrayList<SectionBean>();
            ArrayList sectionBeans = new ArrayList();
            ItemGroupDAO itemGroupDao = new ItemGroupDAO(sm.getDataSource());
            // Find truely grouped tables, not groups with a name of 'Ungrouped'
            List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
            CRFBean crfBean = crfDao.findByVersionId(crfVersionBean.getId());
            if (itemGroupBeans.size() > 0) {
                // get a DisplaySectionBean for each section of the CRF, sort
                // them, then
                // dispatch the request to a print JSP. The constructor for this
                // handler takes
                // a boolean value depending on whether data is involved or not
                // ('false' in terms of this
                // servlet; see PrintDataEntryServlet).
                DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
                handler.setCrfVersionId(crfVersionBean.getId());
                // handler.setEventCRFId(eventCRFId);
                List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
                request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
                // Make available the CRF names and versions for
                // the web page's header
                CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
                request.setAttribute("crfVersionBean", crfverBean);
                request.setAttribute("crfBean", crfBean);
                // Set an attribute signaling that data is not involved
                request.setAttribute("dataInvolved", "false");
                PrintCRFBean printCrfBean = new PrintCRFBean();
                printCrfBean.setDisplaySectionBeans(displaySectionBeans);
                printCrfBean.setCrfVersionBean(crfVersionBean);
                printCrfBean.setCrfBean(crfBean);
                printCrfBean.setEventCrfBean(ecb);
                printCrfBean.setGrouped(true);
                List list = (ArrayList) sedCrfBeans.get(sedBean);
                if (list == null)
                    list = new ArrayList();
                list.add(printCrfBean);
                sedCrfBeans.put(sedBean, list);
                continue;
            }
            ecb = new EventCRFBean();
            ecb.setCRFVersionId(crfVersionBean.getId());
            CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
            ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
            for (int i = 0; i < sects.size(); i++) {
                sb = (SectionBean) sects.get(i);
                // super.sb = sb;
                int sectId = sb.getId();
                if (sectId > 0) {
                    allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
                }
            }
            request.setAttribute(INPUT_EVENT_CRF, ecb);
            request.setAttribute(SECTION_BEAN, sb);
            request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
            sectionBeans = super.getAllDisplayBeans(request);
            DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
            PrintCRFBean printCrfBean = new PrintCRFBean();
            printCrfBean.setAllSections(sectionBeans);
            printCrfBean.setDisplaySectionBean(dsb);
            printCrfBean.setEventCrfBean(ecb);
            printCrfBean.setCrfVersionBean(crfVersionBean);
            printCrfBean.setCrfBean(crfBean);
            printCrfBean.setGrouped(false);
            List list = (ArrayList) sedCrfBeans.get(sedBean);
            if (list == null)
                list = new ArrayList();
            list.add(printCrfBean);
            sedCrfBeans.put(sedBean, list);
        }
    }
    request.setAttribute("sedCrfBeans", sedCrfBeans);
    request.setAttribute("studyName", currentStudy.getName());
    forwardPage(Page.VIEW_ALL_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
Also used : ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) PrintCRFBean(org.akaza.openclinica.bean.managestudy.PrintCRFBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) LinkedHashMap(java.util.LinkedHashMap) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DisplaySectionBeanHandler(org.akaza.openclinica.view.display.DisplaySectionBeanHandler) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) SessionManager(org.akaza.openclinica.core.SessionManager) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) PrintCRFBean(org.akaza.openclinica.bean.managestudy.PrintCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 8 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class ListEventDefinitionServlet method processRequest.

/**
 * Processes the request
 */
@Override
public void processRequest() throws Exception {
    StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
    UserAccountDAO sdao = new UserAccountDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    CRFDAO crfDao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
    ArrayList seds = edao.findAllByStudy(currentStudy);
    // request.setAttribute("seds", seds);
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    for (int i = 0; i < seds.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
        Collection eventDefinitionCRFlist = edcdao.findAllParentsByDefinition(sed.getId());
        Map crfWithDefaultVersion = new LinkedHashMap();
        for (Iterator it = eventDefinitionCRFlist.iterator(); it.hasNext(); ) {
            EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
            CRFBean crfBean = (CRFBean) crfDao.findByPK(edcBean.getCrfId());
            CRFVersionBean crfVersionBean = (CRFVersionBean) crfVersionDao.findByPK(edcBean.getDefaultVersionId());
            logger.info("ED[" + sed.getName() + "]crf[" + crfBean.getName() + "]dv[" + crfVersionBean.getName() + "]");
            crfWithDefaultVersion.put(crfBean.getName(), crfVersionBean.getName());
        }
        sed.setCrfsWithDefaultVersion(crfWithDefaultVersion);
        logger.info("CRF size [" + sed.getCrfs().size() + "]");
        if (sed.getUpdater().getId() == 0) {
            sed.setUpdater(sed.getOwner());
            sed.setUpdatedDate(sed.getCreatedDate());
        }
        if (isPopulated(sed, sedao)) {
            sed.setPopulated(true);
        }
    }
    FormProcessor fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = StudyEventDefinitionRow.generateRowsFromBeans(seds);
    String[] columns = { resword.getString("order"), resword.getString("name"), resword.getString("OID"), resword.getString("repeating"), resword.getString("type"), resword.getString("category"), resword.getString("populated"), resword.getString("date_created"), resword.getString("date_updated"), resword.getString("CRFs"), resword.getString("default_version"), resword.getString("actions") };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    // >> tbh #4169 09/2009
    table.hideColumnLink(2);
    table.hideColumnLink(3);
    table.hideColumnLink(4);
    table.hideColumnLink(6);
    table.hideColumnLink(7);
    table.hideColumnLink(8);
    table.hideColumnLink(9);
    // crfs, tbh
    table.hideColumnLink(10);
    table.hideColumnLink(11);
    table.hideColumnLink(12);
    // << tbh 09/2009
    table.setQuery("ListEventDefinition", new HashMap());
    // if (!currentStudy.getStatus().isLocked()) {
    // table.addLink(resworkflow.getString(
    // "create_a_new_study_event_definition"), "DefineStudyEvent");
    // }
    table.setRows(allStudyRows);
    table.setPaginated(false);
    table.computeDisplay();
    request.setAttribute("table", table);
    request.setAttribute("defSize", new Integer(seds.size()));
    if (request.getParameter("read") != null && request.getParameter("read").equals("true")) {
        request.setAttribute("readOnly", true);
    }
    forwardPage(Page.STUDY_EVENT_DEFINITION_LIST);
}
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) LinkedHashMap(java.util.LinkedHashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) 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) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) LinkedHashMap(java.util.LinkedHashMap) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) Iterator(java.util.Iterator) Collection(java.util.Collection) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 9 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class AddCRFToDefinitionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String actionName = request.getParameter("actionName");
    String submit = request.getParameter("Submit");
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    ArrayList crfs = (ArrayList) cdao.findAllByStatus(Status.AVAILABLE);
    ArrayList edcs = (ArrayList) session.getAttribute("eventDefinitionCRFs");
    if (edcs == null) {
        edcs = new ArrayList();
    }
    HashMap crfIds = new HashMap();
    for (int i = 0; i < edcs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(i);
        Integer crfId = new Integer(edc.getCrfId());
        crfIds.put(crfId, edc);
    }
    for (int i = 0; i < crfs.size(); i++) {
        CRFBean crf = (CRFBean) crfs.get(i);
        if (crfIds.containsKey(new Integer(crf.getId()))) {
            crf.setSelected(true);
        }
    }
    session.setAttribute("crfsWithVersion", crfs);
    if (submit != null) {
        addCRF();
    } else {
        if (StringUtil.isBlank(actionName)) {
            FormProcessor fp = new FormProcessor(request);
            EntityBeanTable table = fp.getEntityBeanTable();
            ArrayList allRows = CRFRow.generateRowsFromBeans(crfs);
            String[] columns = { resword.getString("CRF_name"), resword.getString("date_created"), resword.getString("owner"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("selected") };
            table.setColumns(new ArrayList(Arrays.asList(columns)));
            table.hideColumnLink(5);
            table.setQuery("AddCRFToDefinition", new HashMap());
            table.setRows(allRows);
            table.computeDisplay();
            request.setAttribute("table", table);
            forwardPage(Page.UPDATE_EVENT_DEFINITION2);
        } else if (actionName.equalsIgnoreCase("next")) {
            Integer pageNumber = Integer.valueOf(request.getParameter("pageNum"));
            if (pageNumber != null) {
                if (pageNumber.intValue() == 2) {
                    String nextListPage = request.getParameter("next_list_page");
                    if (nextListPage != null && nextListPage.equalsIgnoreCase("true")) {
                        confirmDefinition();
                    }
                } else {
                    confirmDefinition();
                }
            }
        }
    }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 10 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class AddCRFToDefinitionServlet method addCRF.

private void addCRF() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
    ArrayList crfArray = new ArrayList();
    Map tmpCRFIdMap = (HashMap) session.getAttribute("tmpCRFIdMap");
    if (tmpCRFIdMap == null) {
        tmpCRFIdMap = new HashMap();
    }
    ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
    for (int i = 0; i < crfsWithVersion.size(); i++) {
        int id = fp.getInt("id" + i);
        String name = fp.getString("name" + i);
        String selected = fp.getString("selected" + i);
        if (!StringUtil.isBlank(selected) && "yes".equalsIgnoreCase(selected.trim())) {
            logger.info("one crf selected");
            CRFBean cb = new CRFBean();
            cb.setId(id);
            cb.setName(name);
            // only find active verions
            ArrayList versions = (ArrayList) vdao.findAllActiveByCRF(cb.getId());
            cb.setVersions(versions);
            crfArray.add(cb);
        } else {
            if (tmpCRFIdMap.containsKey(id)) {
                tmpCRFIdMap.remove(id);
            }
        }
    }
    for (Iterator tmpCRFIterator = tmpCRFIdMap.keySet().iterator(); tmpCRFIterator.hasNext(); ) {
        int id = (Integer) tmpCRFIterator.next();
        String name = (String) tmpCRFIdMap.get(id);
        boolean isExists = false;
        for (Iterator it = crfArray.iterator(); it.hasNext(); ) {
            CRFBean cb = (CRFBean) it.next();
            if (id == cb.getId()) {
                isExists = true;
            }
        }
        if (!isExists) {
            CRFBean cb = new CRFBean();
            cb.setId(id);
            cb.setName(name);
            // only find active verions
            ArrayList versions = (ArrayList) vdao.findAllActiveByCRF(cb.getId());
            cb.setVersions(versions);
            crfArray.add(cb);
        }
    }
    session.removeAttribute("tmpCRFIdMap");
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    if (crfArray.size() == 0) {
        // no crf seleted
        addPageMessage(respage.getString("no_new_CRF_added"));
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
        String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
        request.setAttribute("participateFormStatus", participateFormStatus);
        sed.setCrfs(new ArrayList());
        session.setAttribute("definition", sed);
        forwardPage(Page.UPDATE_EVENT_DEFINITION1);
    } else {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
        String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
        if (participateFormStatus.equals("enabled"))
            baseUrl();
        request.setAttribute("participateFormStatus", participateFormStatus);
        ArrayList edcs = (ArrayList) session.getAttribute("eventDefinitionCRFs");
        int ordinalForNewCRF = edcs.size();
        for (int i = 0; i < crfArray.size(); i++) {
            CRFBean crf = (CRFBean) crfArray.get(i);
            EventDefinitionCRFBean edcBean = new EventDefinitionCRFBean();
            edcBean.setCrfId(crf.getId());
            edcBean.setCrfName(crf.getName());
            edcBean.setStudyId(ub.getActiveStudyId());
            edcBean.setStatus(Status.AVAILABLE);
            edcBean.setStudyEventDefinitionId(sed.getId());
            edcBean.setStudyId(ub.getActiveStudyId());
            edcBean.setSourceDataVerification(SourceDataVerification.NOTREQUIRED);
            ordinalForNewCRF = ordinalForNewCRF + 1;
            edcBean.setOrdinal(ordinalForNewCRF);
            edcBean.setVersions(crf.getVersions());
            CRFVersionBean defaultVersion1 = (CRFVersionBean) vdao.findByPK(edcBean.getDefaultVersionId());
            edcBean.setDefaultVersionName(defaultVersion1.getName());
            ordinalForNewCRF++;
            edcs.add(edcBean);
        }
        session.setAttribute("eventDefinitionCRFs", edcs);
        ArrayList<String> sdvOptions = new ArrayList<String>();
        sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
        request.setAttribute("sdvOptions", sdvOptions);
        addPageMessage(respage.getString("has_have_been_added_need_confirmation"));
        forwardPage(Page.UPDATE_EVENT_DEFINITION1);
    }
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Aggregations

CRFBean (org.akaza.openclinica.bean.admin.CRFBean)138 ArrayList (java.util.ArrayList)95 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)78 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)78 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)70 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)67 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)63 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)44 HashMap (java.util.HashMap)43 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)43 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)37 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)27 Iterator (java.util.Iterator)26 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)26 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)22 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)21 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)20