Search in sources :

Example 76 with EventCRFDAO

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

the class RestoreStudyServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt("id");
    StudyBean study = (StudyBean) sdao.findByPK(studyId);
    // find all sites
    ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
    // find all user and roles in the study, include ones in sites
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userRoles = udao.findAllByStudyId(studyId);
    // find all subjects in the study, include ones in sites
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList subjects = ssdao.findAllByStudy(study);
    // find all events in the study, include ones in sites
    StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList definitions = sefdao.findAllByStudy(study);
    String action = request.getParameter("action");
    if (studyId == 0) {
        addPageMessage(respage.getString("please_choose_a_study_to_restore"));
        forwardPage(Page.STUDY_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("studyToRestore", study);
            request.setAttribute("sitesToRestore", sites);
            request.setAttribute("userRolesToRestore", userRoles);
            request.setAttribute("subjectsToRestore", subjects);
            request.setAttribute("definitionsToRRestore", definitions);
            forwardPage(Page.RESTORE_STUDY);
        } else {
            logger.info("submit to restore the study");
            // 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);
            // YW 09-27-2007 << restore auto-removed sites
            for (int i = 0; i < sites.size(); i++) {
                StudyBean site = (StudyBean) sites.get(i);
                if (site.getStatus() == Status.AUTO_DELETED) {
                    site.setStatus(site.getOldStatus());
                    site.setUpdater(ub);
                    site.setUpdatedDate(new Date());
                    sdao.update(site);
                }
            }
            // 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());
                    udao.updateStudyUserRole(role, role.getUserName());
                }
            }
            // is current active study
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.AVAILABLE);
                StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
                currentRole.setRole(r.getRole());
            } else // active site will be restored as well if it was auto-removed
            if (currentStudy.getParentStudyId() == study.getId() && currentStudy.getStatus() == Status.AUTO_DELETED) {
                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.get(Role.max(r.getRole(), rInParent.getRole()).getId()));
            }
            // restore all subjects
            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);
                }
            }
            // restore all study_group
            StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
            StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
            SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
            ArrayList groups = sgcdao.findAllByStudy(study);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
                if (group.getStatus().equals(Status.AUTO_DELETED)) {
                    group.setStatus(Status.AVAILABLE);
                    group.setUpdater(ub);
                    group.setUpdatedDate(new Date());
                    sgcdao.update(group);
                    // all subject_group_map
                    ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(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 event definitions and event
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            for (int i = 0; i < definitions.size(); i++) {
                StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
                if (definition.getStatus().equals(Status.AUTO_DELETED)) {
                    definition.setStatus(Status.AVAILABLE);
                    definition.setUpdater(ub);
                    definition.setUpdatedDate(new Date());
                    sefdao.update(definition);
                    ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
                    for (int j = 0; j < edcs.size(); j++) {
                        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
                        if (edc.getStatus().equals(Status.AUTO_DELETED)) {
                            edc.setStatus(Status.AVAILABLE);
                            edc.setUpdater(ub);
                            edc.setUpdatedDate(new Date());
                            edcdao.update(edc);
                        }
                    }
                    ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
                    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++) {
                                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                                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 definitions
            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.AUTO_DELETED)) {
                    data.setStatus(Status.AVAILABLE);
                    data.setUpdater(ub);
                    data.setUpdatedDate(new Date());
                    datadao.update(data);
                }
            }
            addPageMessage(respage.getString("this_study_has_been_restored_succesfully"));
            forwardPage(Page.STUDY_LIST_SERVLET);
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) 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) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) 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) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 77 with EventCRFDAO

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

the class RestoreSubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int subjectId = fp.getInt("id");
    String action = fp.getString("action");
    if (subjectId == 0 || StringUtil.isBlank(action)) {
        addPageMessage(respage.getString("please_choose_a_subject_to_restore"));
        forwardPage(Page.SUBJECT_LIST_SERVLET);
    } else {
        SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
        // find all study subjects
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
        // find study events
        StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
        ArrayList events = sedao.findAllBySubjectId(subjectId);
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("subjectToRestore", subject);
            request.setAttribute("studySubs", studySubs);
            request.setAttribute("events", events);
            forwardPage(Page.RESTORE_SUBJECT);
        } else {
            logger.info("submit to restore the subject");
            // change all statuses to AVAILABLE
            subject.setStatus(Status.AVAILABLE);
            subject.setUpdater(ub);
            subject.setUpdatedDate(new Date());
            sdao.update(subject);
            // remove subject references from study
            for (int i = 0; i < studySubs.size(); i++) {
                StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
                if (studySub.getStatus().equals(Status.AUTO_DELETED)) {
                    studySub.setStatus(Status.AVAILABLE);
                    studySub.setUpdater(ub);
                    studySub.setUpdatedDate(new Date());
                    ssdao.update(studySub);
                }
            }
            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++) {
                        EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                        if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
                            eventCRF.setStatus(Status.AVAILABLE);
                            eventCRF.setUpdater(ub);
                            eventCRF.setUpdatedDate(new Date());
                            ecdao.update(eventCRF);
                            // restore all the item data
                            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(Status.AVAILABLE);
                                    item.setUpdater(ub);
                                    item.setUpdatedDate(new Date());
                                    iddao.update(item);
                                }
                            }
                        }
                    }
                }
            }
            String emailBody = respage.getString("the_subject") + subject.getName() + " " + respage.getString("has_been_restored_succesfully");
            addPageMessage(emailBody);
            //                sendEmail(emailBody);
            forwardPage(Page.SUBJECT_LIST_SERVLET);
        }
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 78 with EventCRFDAO

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

the class ResolveDiscrepancyServlet method processRequest.

/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int noteId = fp.getInt(INPUT_NOTE_ID);
    String module = (String) session.getAttribute("module");
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    dndao.setFetchMapping(true);
    // check that the note exists
    DiscrepancyNoteBean discrepancyNoteBean = (DiscrepancyNoteBean) dndao.findByPK(noteId);
    if (!discrepancyNoteBean.isActive()) {
        throw new InconsistentStateException(Page.MANAGE_STUDY_SERVLET, resexception.getString("you_are_trying_resolve_discrepancy_not_exist"));
    }
    // check that the note has not already been closed
    ArrayList children = dndao.findAllByParent(discrepancyNoteBean);
    discrepancyNoteBean.setChildren(children);
    // This logic has been reverted, issue-7459
    // if (parentNoteIsClosed(discrepancyNoteBean)) {
    // throw new InconsistentStateException(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET, respage
    // .getString("the_discrepancy_choose_has_been_closed_resolved_create_new"));
    // }
    // all clear, send the user to the resolved screen
    String entityType = discrepancyNoteBean.getEntityType().toLowerCase();
    discrepancyNoteBean.setResStatus(ResolutionStatus.get(discrepancyNoteBean.getResolutionStatusId()));
    discrepancyNoteBean.setDisType(DiscrepancyNoteType.get(discrepancyNoteBean.getDiscrepancyNoteTypeId()));
    // View Study Events <<
    if (currentRole.getRole().equals(Role.MONITOR) && !"itemdata".equalsIgnoreCase(entityType) && !"eventcrf".equalsIgnoreCase(entityType)) {
        redirectMonitor(module, discrepancyNoteBean);
        return;
    }
    // If Study is Frozen or Locked
    if (currentStudy.getStatus().isFrozen() && !"itemdata".equalsIgnoreCase(entityType) && !"eventcrf".equalsIgnoreCase(entityType)) {
        redirectMonitor(module, discrepancyNoteBean);
        return;
    }
    boolean toView = false;
    boolean isCompleted = false;
    if ("itemdata".equalsIgnoreCase(entityType)) {
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        ItemDataBean idb = (ItemDataBean) iddao.findByPK(discrepancyNoteBean.getEntityId());
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
        StudySubjectBean studySubjectBean = (StudySubjectBean) studySubjectDAO.findByPK(ecb.getStudySubjectId());
        discrepancyNoteBean.setSubjectId(studySubjectBean.getId());
        discrepancyNoteBean.setItemId(idb.getItemId());
        if (ecb.getStatus().equals(Status.UNAVAILABLE)) {
            isCompleted = true;
        }
        // we want to go to view note page if the note is
        toView = true;
    // for item data
    }
    // logger.info("set up pop up url: " + createNoteURL);
    // System.out.println("set up pop up url: " + createNoteURL);
    boolean goNext = prepareRequestForResolution(request, sm.getDataSource(), currentStudy, discrepancyNoteBean, isCompleted);
    Page p = getPageForForwarding(discrepancyNoteBean, isCompleted);
    // logger.info("found page for forwarding: " + p.getFileName());
    if (p == null) {
        throw new InconsistentStateException(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET, resexception.getString("the_discrepancy_note_triying_resolve_has_invalid_type"));
    } else {
        if (p.getFileName().contains("?")) {
            if (!p.getFileName().contains("fromViewNotes=1")) {
                p.setFileName(p.getFileName() + "&fromViewNotes=1");
            }
        } else {
            p.setFileName(p.getFileName() + "?fromViewNotes=1");
        }
        String createNoteURL = CreateDiscrepancyNoteServlet.getAddChildURL(discrepancyNoteBean, ResolutionStatus.CLOSED, true);
        setPopUpURL(createNoteURL);
    }
    if (!goNext) {
        setPopUpURL("");
        addPageMessage(respage.getString("you_may_not_perform_admin_edit_on_CRF_not_completed_by_user"));
        p = Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET;
    }
    forwardPage(p);
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) Page(org.akaza.openclinica.view.Page) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 79 with EventCRFDAO

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

the class ResolveDiscrepancyServlet method prepareRequestForResolution.

public boolean prepareRequestForResolution(HttpServletRequest request, DataSource ds, StudyBean currentStudy, DiscrepancyNoteBean note, boolean isCompleted) throws Exception {
    String entityType = note.getEntityType().toLowerCase();
    int id = note.getEntityId();
    if ("subject".equalsIgnoreCase(entityType)) {
        StudySubjectDAO ssdao = new StudySubjectDAO(ds);
        StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(id, currentStudy);
        request.setAttribute("action", "show");
        request.setAttribute("id", String.valueOf(note.getEntityId()));
        request.setAttribute("studySubId", String.valueOf(ssb.getId()));
    } else if ("studysub".equalsIgnoreCase(entityType)) {
        request.setAttribute("action", "show");
        request.setAttribute("id", String.valueOf(note.getEntityId()));
    } else if ("eventcrf".equalsIgnoreCase(entityType)) {
        request.setAttribute("editInterview", "1");
        EventCRFDAO ecdao = new EventCRFDAO(ds);
        EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(id);
        request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN, ecb);
        // If the request is passed along to ViewSectionDataEntryServlet,
        // that code needs
        // an event crf id; the (ecb.getId()+"") is necessary because
        // FormProcessor throws
        // a ClassCastException without the casting to a String
        request.setAttribute(ViewSectionDataEntryServlet.EVENT_CRF_ID, ecb.getId() + "");
    } else if ("studyevent".equalsIgnoreCase(entityType)) {
        StudyEventDAO sedao = new StudyEventDAO(ds);
        StudyEventBean seb = (StudyEventBean) sedao.findByPK(id);
        request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID, String.valueOf(id));
        request.setAttribute(UpdateStudyEventServlet.EVENT_ID, String.valueOf(id));
        request.setAttribute(UpdateStudyEventServlet.STUDY_SUBJECT_ID, String.valueOf(seb.getStudySubjectId()));
    } else // this is for item data
    if ("itemdata".equalsIgnoreCase(entityType)) {
        ItemDataDAO iddao = new ItemDataDAO(ds);
        ItemDAO idao = new ItemDAO(ds);
        ItemDataBean idb = (ItemDataBean) iddao.findByPK(id);
        ItemBean item = (ItemBean) idao.findByPK(idb.getItemId());
        ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO<>(ds);
        EventCRFDAO ecdao = new EventCRFDAO(ds);
        EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
        FormLayoutDAO fldao = new FormLayoutDAO(ds);
        FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(ecb.getFormLayoutId());
        StudyEventDAO sedao = new StudyEventDAO(ds);
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
        ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(ds);
        ItemFormMetadataBean ifmb = ifmdao.findByItemIdAndCRFVersionId(idb.getItemId(), ecb.getFormLayoutId());
        ItemGroupMetadataBean igmBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(idb.getItemId(), ecb.getCRFVersionId());
        ItemGroupDAO igdao = new ItemGroupDAO<>(ds);
        ItemGroupBean igBean = (ItemGroupBean) igdao.findByPK(igmBean.getItemGroupId());
        int repeatOrdinal = idb.getOrdinal();
        ItemDataBean idata = null;
        if (idb != null && idb.isDeleted()) {
            return false;
        }
        if (igmBean.isRepeatingGroup() && repeatOrdinal > 1) {
            List<ItemGroupMetadataBean> igms = igmdao.findMetaByGroupAndCrfVersion(igBean.getId(), ecb.getCRFVersionId());
            for (int i = 0; i < idb.getOrdinal(); i++) {
                for (ItemGroupMetadataBean igm : igms) {
                    idata = iddao.findByItemIdAndEventCRFIdAndOrdinal(igm.getItemId(), ecb.getId(), i + 1);
                    if (idata != null && idata.isDeleted()) {
                        repeatOrdinal--;
                        break;
                    }
                }
            }
        }
        EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
        StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
        // Cache the subject context for use during xform submission
        PFormCache cache = PFormCache.getInstance(context);
        PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
        subjectContext.setStudySubjectOid(ssb.getOid());
        subjectContext.setStudyEventDefinitionId(seb.getStudyEventDefinitionId());
        subjectContext.setOrdinal(seb.getSampleOrdinal());
        subjectContext.setFormLayoutOid(formLayout.getOid());
        subjectContext.setUserAccountId(ub.getId());
        subjectContext.setItemName(item.getName() + COMMENT);
        subjectContext.setItemRepeatOrdinal(repeatOrdinal);
        subjectContext.setItemInRepeatingGroup(igmBean.isRepeatingGroup());
        subjectContext.setItemRepeatGroupName(igBean.getLayoutGroupPath());
        String contextHash = cache.putSubjectContext(subjectContext);
        String formUrl = null;
        if (ecb.getId() > 0) {
            formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, currentStudy.getOid(), null, null, QUERY_FLAVOR);
        } else {
            formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, currentStudy.getOid(), QUERY_FLAVOR);
        }
        int hashIndex = formUrl.lastIndexOf("#");
        String part1 = formUrl;
        String part2 = "";
        if (hashIndex != -1) {
            part1 = formUrl.substring(0, hashIndex);
            part2 = formUrl.substring(hashIndex);
        }
        request.setAttribute(EnketoFormServlet.FORM_URL1, part1);
        request.setAttribute(EnketoFormServlet.FORM_URL2, part2);
    }
    return true;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) EnketoUrlService(org.akaza.openclinica.service.crfdata.EnketoUrlService) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) PFormCache(org.akaza.openclinica.web.pform.PFormCache) PFormCacheSubjectContextEntry(org.akaza.openclinica.service.crfdata.xform.PFormCacheSubjectContextEntry)

Example 80 with EventCRFDAO

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

the class RemoveEventDefinitionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String idString = request.getParameter("id");
    int defId = Integer.valueOf(idString.trim()).intValue();
    StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
    //        checkRoleByUserAndStudy(ub.getName(), sed.getStudyId(), 0);
    if (currentStudy.getId() != sed.getStudyId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    // find all CRFs
    EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
        edc.setVersions(versions);
        CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
        edc.setCrfName(crf.getName());
        CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
        edc.setDefaultVersionName(defaultVersion.getName());
        CRFBean cBean = (CRFBean) cdao.findByPK(edc.getCrfId());
        String crfPath = sed.getOid() + "." + cBean.getOid();
        edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
    }
    // finds all events
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    ArrayList events = (ArrayList) sedao.findAllByDefinition(sed.getId());
    String action = request.getParameter("action");
    if (StringUtil.isBlank(idString)) {
        addPageMessage(respage.getString("please_choose_a_SED_to_remove"));
        forwardPage(Page.LIST_DEFINITION_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            if (!sed.getStatus().equals(Status.AVAILABLE)) {
                addPageMessage(respage.getString("this_SED_is_not_available_for_this_study") + respage.getString("please_contact_sysadmin_for_more_information"));
                forwardPage(Page.LIST_DEFINITION_SERVLET);
                return;
            }
            StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
            String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
            if (participateFormStatus.equals("enabled"))
                baseUrl();
            request.setAttribute("participateFormStatus", participateFormStatus);
            request.setAttribute("definitionToRemove", sed);
            request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
            request.setAttribute("events", events);
            forwardPage(Page.REMOVE_DEFINITION);
        } else {
            logger.info("submit to remove the definition");
            // remove definition
            sed.setStatus(Status.DELETED);
            sed.setUpdater(ub);
            sed.setUpdatedDate(new Date());
            sdao.update(sed);
            // remove all crfs
            for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
                EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
                if (!edc.getStatus().equals(Status.DELETED)) {
                    edc.setStatus(Status.AUTO_DELETED);
                    edc.setUpdater(ub);
                    edc.setUpdatedDate(new Date());
                    edao.update(edc);
                }
            }
            // remove all events
            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);
                    // remove all the item data
                    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.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.setStatus(Status.AUTO_DELETED);
                                    item.setUpdater(ub);
                                    item.setUpdatedDate(new Date());
                                    iddao.update(item);
                                }
                            }
                        }
                    }
                }
            }
            String emailBody = respage.getString("the_SED") + sed.getName() + " " + respage.getString("has_been_removed_from_the_study") + currentStudy.getName() + ".";
            addPageMessage(emailBody);
            //                sendEmail(emailBody);
            forwardPage(Page.LIST_DEFINITION_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) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)106 ArrayList (java.util.ArrayList)80 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)76 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)73 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)71 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)57 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)51 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)51 Date (java.util.Date)50 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)49 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)49 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)45 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)43 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)41 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)37 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)34 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)32 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)24