Search in sources :

Example 21 with EventDefinitionCRFDAO

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

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

the class RemoveSiteServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    String idString = request.getParameter("id");
    logger.info("site id:" + idString);
    int siteId = Integer.valueOf(idString.trim()).intValue();
    StudyBean study = (StudyBean) sdao.findByPK(siteId);
    if (currentStudy.getId() != study.getParentStudyId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    // find all user and roles
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userRoles = udao.findAllByStudyId(siteId);
    // find all subjects
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList subjects = ssdao.findAllByStudy(study);
    // find all events
    StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList definitions = sefdao.findAllByStudy(study);
    String action = request.getParameter("action");
    if (StringUtil.isBlank(idString)) {
        addPageMessage(respage.getString("please_choose_a_site_to_remove"));
        forwardPage(Page.SITE_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("siteToRemove", study);
            request.setAttribute("userRolesToRemove", userRoles);
            request.setAttribute("subjectsToRemove", subjects);
            forwardPage(Page.REMOVE_SITE);
        } else {
            logger.info("submit to remove the site");
            // change all statuses to unavailable
            StudyDAO studao = new StudyDAO(sm.getDataSource());
            study.setOldStatus(study.getStatus());
            study.setStatus(Status.DELETED);
            study.setUpdater(ub);
            study.setUpdatedDate(new Date());
            studao.update(study);
            // remove all users and roles
            for (int i = 0; i < userRoles.size(); i++) {
                StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
                if (!role.getStatus().equals(Status.DELETED)) {
                    role.setStatus(Status.AUTO_DELETED);
                    role.setUpdater(ub);
                    role.setUpdatedDate(new Date());
                    // YW << So study_user_role table status_id field can be
                    // updated
                    udao.updateStudyUserRole(role, role.getUserName());
                }
            // YW 06-18-2007 >>
            }
            // YW << bug fix that current active study has been deleted
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.DELETED);
                // currentRole.setRole(Role.INVALID);
                currentRole.setStatus(Status.DELETED);
            }
            // remove all subjects
            for (int i = 0; i < subjects.size(); i++) {
                StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
            }
            // remove all study_group
            StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
            SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
            ArrayList groups = sgdao.findAllByStudy(study);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupBean group = (StudyGroupBean) groups.get(i);
                if (!group.getStatus().equals(Status.DELETED)) {
                    group.setStatus(Status.AUTO_DELETED);
                    group.setUpdater(ub);
                    group.setUpdatedDate(new Date());
                    sgdao.update(group);
                    // all subject_group_map
                    ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
                    for (int j = 0; j < subjectGroupMaps.size(); j++) {
                        SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
                        if (!sgMap.getStatus().equals(Status.DELETED)) {
                            sgMap.setStatus(Status.AUTO_DELETED);
                            sgMap.setUpdater(ub);
                            sgMap.setUpdatedDate(new Date());
                            sgmdao.update(sgMap);
                        }
                    }
                }
            }
            // remove all events
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            for (int i = 0; i < subjects.size(); i++) {
                StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
                if (!subject.getStatus().equals(Status.DELETED)) {
                    subject.setStatus(Status.AUTO_DELETED);
                    subject.setUpdater(ub);
                    subject.setUpdatedDate(new Date());
                    ssdao.update(subject);
                    ArrayList events = sedao.findAllByStudySubject(subject);
                    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                    for (int j = 0; j < events.size(); j++) {
                        StudyEventBean event = (StudyEventBean) events.get(j);
                        if (!event.getStatus().equals(Status.DELETED)) {
                            event.setStatus(Status.AUTO_DELETED);
                            event.setUpdater(ub);
                            event.setUpdatedDate(new Date());
                            sedao.update(event);
                            ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
                            ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
                            for (int k = 0; k < eventCRFs.size(); k++) {
                                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                                if (!eventCRF.getStatus().equals(Status.DELETED)) {
                                    eventCRF.setOldStatus(eventCRF.getStatus());
                                    eventCRF.setStatus(Status.AUTO_DELETED);
                                    eventCRF.setUpdater(ub);
                                    eventCRF.setUpdatedDate(new Date());
                                    ecdao.update(eventCRF);
                                    ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
                                    for (int a = 0; a < itemDatas.size(); a++) {
                                        ItemDataBean item = (ItemDataBean) itemDatas.get(a);
                                        if (!item.getStatus().equals(Status.DELETED)) {
                                            item.setOldStatus(item.getStatus());
                                            item.setStatus(Status.AUTO_DELETED);
                                            item.setUpdater(ub);
                                            item.setUpdatedDate(new Date());
                                            iddao.update(item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // for subjects
            DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
            ArrayList dataset = datadao.findAllByStudyId(study.getId());
            for (int i = 0; i < dataset.size(); i++) {
                DatasetBean data = (DatasetBean) dataset.get(i);
                if (!data.getStatus().equals(Status.DELETED)) {
                    data.setStatus(Status.AUTO_DELETED);
                    data.setUpdater(ub);
                    data.setUpdatedDate(new Date());
                    datadao.update(data);
                }
            }
            addPageMessage(respage.getString("this_site_has_been_removed_succesfully"));
            String fromListSite = (String) session.getAttribute("fromListSite");
            if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
                session.removeAttribute("fromListSite");
                forwardPage(Page.SITE_LIST_SERVLET);
            } else {
                session.removeAttribute("fromListSite");
                if (currentRole.getRole().equals(Role.ADMIN)) {
                    forwardPage(Page.STUDY_LIST_SERVLET);
                } else {
                    forwardPage(Page.SITE_LIST_SERVLET);
                }
            }
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 23 with EventDefinitionCRFDAO

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

the class LockCRFVersionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int crfVersionId = fp.getInt("id", true);
    String action = fp.getString("action");
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    if (crfVersionId == 0) {
        addPageMessage(respage.getString("choose_valid_crf_version"));
        forwardPage(Page.CRF_LIST_SERVLET);
        return;
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(crfVersionId);
    //System.out.println("crf version found:" + version.getName());
    CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
    if (!ub.isSysAdmin() && (version.getOwnerId() != ub.getId())) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ArrayList eventCRFs = ecdao.findAllStudySubjectByCRFVersion(crfVersionId);
    if (StringUtil.isBlank(action)) {
        request.setAttribute("crfVersionToLock", version);
        request.setAttribute("crf", crf);
        request.setAttribute("eventSubjectsUsingVersion", eventCRFs);
        forwardPage(Page.CONFIRM_LOCKING_CRF_VERSION);
    } else if ("confirm".equalsIgnoreCase(action)) {
        version.setStatus(Status.LOCKED);
        version.setUpdater(ub);
        cvdao.update(version);
        ArrayList versionList = (ArrayList) cvdao.findAllByCRF(version.getCrfId());
        if (versionList.size() > 0) {
            EventDefinitionCRFDAO edCRFDao = new EventDefinitionCRFDAO(sm.getDataSource());
            ArrayList edcList = (ArrayList) edCRFDao.findAllByCRF(version.getCrfId());
            for (int i = 0; i < edcList.size(); i++) {
                EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) edcList.get(i);
                // @pgawade 18-May-2011 #5414 - Changes for setting the correct
                // default crf version Id to event
                // when existing default version is locked
                // RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao,
                // versionList);
                RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao, versionList, crfVersionId);
            }
        }
        addPageMessage(respage.getString("crf_version_archived_successfully"));
        forwardPage(Page.CRF_LIST_SERVLET);
    }
}
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) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 24 with EventDefinitionCRFDAO

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

the class RestoreSiteServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    String idString = request.getParameter("id");
    logger.info("site id:" + idString);
    int siteId = Integer.valueOf(idString.trim()).intValue();
    StudyBean study = (StudyBean) sdao.findByPK(siteId);
    // find all user and roles
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userRoles = udao.findAllByStudyId(siteId);
    // find all subjects
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList subjects = ssdao.findAllByStudy(study);
    // find all events
    StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList definitions = sefdao.findAllByStudy(study);
    String action = request.getParameter("action");
    if (StringUtil.isBlank(idString)) {
        addPageMessage(respage.getString("please_choose_a_site_to_restore"));
        forwardPage(Page.SITE_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            // site can be restored when its parent study is not "removed"
            // -- YW -6-21-2007
            StudyBean parentstudy = (StudyBean) sdao.findByPK(study.getParentStudyId());
            if (!"removed".equals(parentstudy.getStatus().getName())) {
                request.setAttribute("siteToRestore", study);
                request.setAttribute("userRolesToRestore", userRoles);
                request.setAttribute("subjectsToRestore", subjects);
            // request.setAttribute("definitionsToRestore",
            // definitions);
            } else {
                MessageFormat mf = new MessageFormat("");
                mf.applyPattern(respage.getString("choosen_site_cannot_restored"));
                Object[] arguments = { study.getName(), parentstudy.getName() };
                addPageMessage(mf.format(arguments));
                forwardPage(Page.STUDY_LIST_SERVLET);
            }
            forwardPage(Page.RESTORE_SITE);
        } else {
            logger.info("submit to restore the site");
            // change all statuses to unavailable
            StudyDAO studao = new StudyDAO(sm.getDataSource());
            study.setStatus(study.getOldStatus());
            study.setUpdater(ub);
            study.setUpdatedDate(new Date());
            studao.update(study);
            // restore all users and roles
            for (int i = 0; i < userRoles.size(); i++) {
                StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
                if (role.getStatus().equals(Status.AUTO_DELETED)) {
                    role.setStatus(Status.AVAILABLE);
                    role.setUpdater(ub);
                    role.setUpdatedDate(new Date());
                    // YW << So study_user_role table status_id field can be
                    // updated
                    udao.updateStudyUserRole(role, role.getUserName());
                }
            // YW 06-18-2007 >>
            }
            // study
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.AVAILABLE);
                StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
                StudyUserRoleBean rInParent = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getParentStudyId());
                // according to logic in SecureController.java: inherited
                // role from parent study, pick the higher role
                currentRole.setRole(Role.max(r.getRole(), rInParent.getRole()));
            }
            // YW >>
            // restore all study_group
            StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
            SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
            ArrayList groups = sgdao.findAllByStudy(study);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupBean group = (StudyGroupBean) groups.get(i);
                if (group.getStatus().equals(Status.AUTO_DELETED)) {
                    group.setStatus(Status.AVAILABLE);
                    group.setUpdater(ub);
                    group.setUpdatedDate(new Date());
                    sgdao.update(group);
                    // all subject_group_map
                    ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
                    for (int j = 0; j < subjectGroupMaps.size(); j++) {
                        SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
                        if (sgMap.getStatus().equals(Status.AUTO_DELETED)) {
                            sgMap.setStatus(Status.AVAILABLE);
                            sgMap.setUpdater(ub);
                            sgMap.setUpdatedDate(new Date());
                            sgmdao.update(sgMap);
                        }
                    }
                }
            }
            // restore all events with subjects
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            for (int i = 0; i < subjects.size(); i++) {
                StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
                if (subject.getStatus().equals(Status.AUTO_DELETED)) {
                    subject.setStatus(Status.AVAILABLE);
                    subject.setUpdater(ub);
                    subject.setUpdatedDate(new Date());
                    ssdao.update(subject);
                    ArrayList events = sedao.findAllByStudySubject(subject);
                    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                    for (int j = 0; j < events.size(); j++) {
                        StudyEventBean event = (StudyEventBean) events.get(j);
                        if (event.getStatus().equals(Status.AUTO_DELETED)) {
                            event.setStatus(Status.AVAILABLE);
                            event.setUpdater(ub);
                            event.setUpdatedDate(new Date());
                            sedao.update(event);
                            ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
                            ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
                            for (int k = 0; k < eventCRFs.size(); k++) {
                                // YW << fix broken page for storing site
                                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                                // >> YW
                                if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
                                    eventCRF.setStatus(eventCRF.getOldStatus());
                                    eventCRF.setUpdater(ub);
                                    eventCRF.setUpdatedDate(new Date());
                                    ecdao.update(eventCRF);
                                    ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
                                    for (int a = 0; a < itemDatas.size(); a++) {
                                        ItemDataBean item = (ItemDataBean) itemDatas.get(a);
                                        if (item.getStatus().equals(Status.AUTO_DELETED)) {
                                            item.setStatus(item.getOldStatus());
                                            item.setUpdater(ub);
                                            item.setUpdatedDate(new Date());
                                            iddao.update(item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // for subjects
            DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
            ArrayList dataset = datadao.findAllByStudyId(study.getId());
            for (int i = 0; i < dataset.size(); i++) {
                DatasetBean data = (DatasetBean) dataset.get(i);
                data.setStatus(Status.AVAILABLE);
                data.setUpdater(ub);
                data.setUpdatedDate(new Date());
                datadao.update(data);
            }
            addPageMessage(respage.getString("this_site_has_been_restored_succesfully"));
            String fromListSite = (String) session.getAttribute("fromListSite");
            if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
                session.removeAttribute("fromListSite");
                forwardPage(Page.SITE_LIST_SERVLET);
            } else {
                session.removeAttribute("fromListSite");
                if (currentRole.getRole().equals(Role.ADMIN)) {
                    forwardPage(Page.STUDY_LIST_SERVLET);
                } else {
                    forwardPage(Page.SITE_LIST_SERVLET);
                }
            }
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) MessageFormat(java.text.MessageFormat) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) Date(java.util.Date) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean)

Example 25 with EventDefinitionCRFDAO

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

the class ViewStudySubjectAuditLogServlet method processRequest.

@Override
public void processRequest() throws Exception {
    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());
    FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
    ArrayList studySubjectAudits = new ArrayList();
    ArrayList eventCRFAudits = new ArrayList();
    ArrayList studyEventAudits = new ArrayList();
    ArrayList allDeletedEventCRFs = new ArrayList();
    String attachedFilePath = Utils.getAttachedFilePath(currentStudy);
    // studySubjectId
    int studySubId = fp.getInt("id", true);
    request.setAttribute("id", studySubId);
    if (studySubId == 0) {
        addPageMessage(respage.getString("please_choose_a_subject_to_view"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
    } else {
        StudySubjectBean studySubject = (StudySubjectBean) subdao.findByPK(studySubId);
        StudyBean study = (StudyBean) studydao.findByPK(studySubject.getStudyId());
        // Check if this StudySubject would be accessed from the Current Study
        if (studySubject.getStudyId() != currentStudy.getId()) {
            if (currentStudy.getParentStudyId() > 0) {
                addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                forwardPage(Page.MENU_SERVLET);
                return;
            } else {
                // The SubjectStudy is not belong to currentstudy and current study is not a site.
                Collection sites = studydao.findOlnySiteIdsByStudy(currentStudy);
                if (!sites.contains(study.getId())) {
                    addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                    forwardPage(Page.MENU_SERVLET);
                    return;
                }
            }
        }
        request.setAttribute("studySub", studySubject);
        SubjectBean subject = (SubjectBean) sdao.findByPK(studySubject.getSubjectId());
        StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
        study.getStudyParameterConfig().setCollectDob(spvdao.findByHandleAndStudy(study.getId(), "collectDob").getValue());
        String collectdob = "used";
        if (study.getStudyParameterConfig().getCollectDob().equals("2")) {
            collectdob = "yearOnly";
        } else if (study.getStudyParameterConfig().getCollectDob().equals("3")) {
            collectdob = "notUsed";
        } else if (study.getStudyParameterConfig().getCollectDob().equals("1")) {
            collectdob = "used";
        }
        request.setAttribute("collectdob", collectdob);
        request.setAttribute("subject", subject);
        request.setAttribute("study", study);
        /* Show both study subject and subject audit events together */
        // Study subject value changed
        Collection studySubjectAuditEvents = adao.findStudySubjectAuditEvents(studySubject.getId());
        // integer values.
        for (Iterator iterator = studySubjectAuditEvents.iterator(); iterator.hasNext(); ) {
            AuditBean auditBean = (AuditBean) iterator.next();
            if (auditBean.getAuditEventTypeId() == 3) {
                auditBean.setOldValue(Status.get(Integer.parseInt(auditBean.getOldValue())).getName());
                auditBean.setNewValue(Status.get(Integer.parseInt(auditBean.getNewValue())).getName());
            }
        }
        studySubjectAudits.addAll(studySubjectAuditEvents);
        // Global subject value changed
        studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
        studySubjectAudits.addAll(adao.findStudySubjectGroupAssignmentAuditEvents(studySubject.getId()));
        request.setAttribute("studySubjectAudits", 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));
            // Find deleted Event CRFs
            List deletedEventCRFs = adao.findDeletedEventCRFsFromAuditEventByEventCRFStatus(studyEvent.getId());
            allDeletedEventCRFs.addAll(deletedEventCRFs);
            logger.info("deletedEventCRFs size[" + deletedEventCRFs.size() + "]");
        }
        for (int i = 0; i < events.size(); i++) {
            StudyEventBean studyEvent = (StudyEventBean) events.get(i);
            studyEventAudits.addAll(adao.findStudyEventAuditEvents(studyEvent.getId()));
            ArrayList eventCRFs = studyEvent.getEventCRFs();
            for (int j = 0; j < eventCRFs.size(); j++) {
                // Link CRF and CRF Versions
                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(j);
                eventCRF.setFormLayout((FormLayoutBean) fldao.findByPK(eventCRF.getFormLayoutId()));
                eventCRF.setCrf(cdao.findByVersionId(eventCRF.getCRFVersionId()));
                // Get the event crf audits
                eventCRFAudits.addAll(adao.findEventCRFAuditEventsWithItemDataType(eventCRF.getId()));
                logger.info("eventCRFAudits size [" + eventCRFAudits.size() + "] eventCRF id [" + eventCRF.getId() + "]");
            }
        }
        ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
        for (Object o : eventCRFAudits) {
            AuditBean ab = (AuditBean) o;
            if (ab.getAuditTable().equalsIgnoreCase("item_data")) {
                ItemDataBean idBean = (ItemDataBean) itemDataDao.findByPK(ab.getEntityId());
                ab.setOrdinal(idBean.getOrdinal());
            }
        }
        request.setAttribute("events", events);
        request.setAttribute("eventCRFAudits", eventCRFAudits);
        request.setAttribute("studyEventAudits", studyEventAudits);
        request.setAttribute("allDeletedEventCRFs", allDeletedEventCRFs);
        request.setAttribute("attachedFilePath", attachedFilePath);
        forwardPage(Page.VIEW_STUDY_SUBJECT_AUDIT);
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) AuditDAO(org.akaza.openclinica.dao.admin.AuditDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) AuditBean(org.akaza.openclinica.bean.admin.AuditBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) 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) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) Collection(java.util.Collection) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO)

Aggregations

EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)84 ArrayList (java.util.ArrayList)72 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)58 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)53 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)51 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)45 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)41 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)41 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)39 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)39 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)36 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)35 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)30 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)28 Date (java.util.Date)27 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)27 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26