Search in sources :

Example 66 with ItemDataDAO

use of org.akaza.openclinica.dao.submit.ItemDataDAO 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");
    // Integer subjectId = (Integer) session.getAttribute("subjectId");
    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());
        // set to open in View Within Record
        discrepancyNoteBean.setEventCRFId(idb.getEventCRFId());
        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("InitialDataEntry")) {
        // Open form in data entry mode from dn page
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(discrepancyNoteBean.getEventCRFId());
        request.setAttribute("event", ecb);
        p.setFileName(p.getFileName() + "?eventCRFId=" + discrepancyNoteBean.getEventCRFId() + "&exitTo=ViewNotes&fromViewNotes=1");
        String createNoteURL = CreateDiscrepancyNoteServlet.getAddChildURL(discrepancyNoteBean, ResolutionStatus.CLOSED, true);
        setPopUpURL(createNoteURL);
    } 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 67 with ItemDataDAO

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

the class RestoreEventCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // eventCRFId
    int eventCRFId = fp.getInt("id");
    // studySubjectId
    int studySubId = fp.getInt("studySubId");
    checkStudyLocked("ViewStudySubject?id" + studySubId, respage.getString("current_study_locked"));
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    if (eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_an_event_CRF_to_restore"));
        request.setAttribute("id", new Integer(studySubId).toString());
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    } else {
        EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        // YW 11-07-2007, an event CRF could not be restored if its study
        // subject has been removed
        Status s = studySub.getStatus();
        if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
            addPageMessage(resword.getString("event_CRF") + resterm.getString("could_not_be") + resterm.getString("restored") + "." + respage.getString("study_subject_has_been_deleted"));
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
        // YW
        request.setAttribute("studySub", studySub);
        // construct info needed on view event crf page
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        int crfVersionId = eventCRF.getCRFVersionId();
        CRFBean cb = cdao.findByVersionId(crfVersionId);
        eventCRF.setCrf(cb);
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
        eventCRF.setCrfVersion(cvb);
        // then get the definition so we can call
        // DisplayEventCRFBean.setFlags
        int studyEventId = eventCRF.getStudyEventId();
        StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
        int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
        event.setStudyEventDefinition(sed);
        request.setAttribute("event", event);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
        EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
        DisplayEventCRFBean dec = new DisplayEventCRFBean();
        dec.setEventCRF(eventCRF);
        dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
        // find all item data
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        ArrayList itemData = iddao.findAllByEventCRFId(eventCRF.getId());
        request.setAttribute("items", itemData);
        String action = request.getParameter("action");
        if ("confirm".equalsIgnoreCase(action)) {
            if (!eventCRF.getStatus().equals(Status.DELETED) && !eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
                addPageMessage(respage.getString("this_event_CRF_avilable_for_study") + " " + " " + respage.getString("please_contact_sysadmin_for_more_information"));
                request.setAttribute("id", new Integer(studySubId).toString());
                forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
                return;
            }
            request.setAttribute("displayEventCRF", dec);
            forwardPage(Page.RESTORE_EVENT_CRF);
        } else {
            logger.info("submit to restore the event CRF from study");
            // Set crf status to AVAILABLE to allow data
            // to be repopulated in the form properly
            eventCRF.setStatus(Status.AVAILABLE);
            ecdao.update(eventCRF);
            // restore all the item data to the appropriate status
            for (int a = 0; a < itemData.size(); a++) {
                ItemDataBean item = (ItemDataBean) itemData.get(a);
                if (item.getStatus().equals(Status.AUTO_DELETED)) {
                    item.setStatus(Status.AVAILABLE);
                    item.setUpdater(ub);
                    item.setUpdatedDate(new Date());
                    iddao.update(item);
                }
            }
            Status restoredStatus = null;
            if (eventCRF.getDateCompleted() != null) {
                if (edc.isDoubleEntry() && eventCRF.getDateValidateCompleted() == null) {
                    restoredStatus = Status.PENDING;
                    eventCRF.setStage(DataEntryStage.INITIAL_DATA_ENTRY);
                } else {
                    restoredStatus = Status.UNAVAILABLE;
                    eventCRF.setStage(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE);
                }
                // Reset the DisplayEventCRFBean
                dec.setEventCRF(eventCRF);
                dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
            } else {
                restoredStatus = Status.AVAILABLE;
            }
            eventCRF.setStatus(restoredStatus);
            eventCRF.setUpdater(ub);
            eventCRF.setUpdatedDate(new Date());
            ecdao.update(eventCRF);
            String emailBody = respage.getString("the_event_CRF") + cb.getName() + " " + respage.getString("has_been_restored_to_the_event") + " " + event.getStudyEventDefinition().getName() + ".";
            addPageMessage(emailBody);
            sendEmail(emailBody);
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) 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) Status(org.akaza.openclinica.bean.core.Status) 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) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 68 with ItemDataDAO

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

the class UpdateEventDefinitionServlet method removeAllEventsItems.

public void removeAllEventsItems(EventDefinitionCRFBean edc, StudyEventDefinitionBean sed) {
    StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
    EventCRFDAO ecrfDao = new EventCRFDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    // Getting Study Events
    ArrayList seList = seDao.findAllByStudyEventDefinitionAndCrfOids(sed.getOid(), edc.getCrf().getOid());
    for (int j = 0; j < seList.size(); j++) {
        StudyEventBean seBean = (StudyEventBean) seList.get(j);
        // Getting Event CRFs
        ArrayList ecrfList = ecrfDao.findAllByStudyEventAndCrfOrCrfVersionOid(seBean, edc.getCrf().getOid());
        for (int k = 0; k < ecrfList.size(); k++) {
            EventCRFBean ecrfBean = (EventCRFBean) ecrfList.get(k);
            ecrfBean.setOldStatus(ecrfBean.getStatus());
            ecrfBean.setStatus(Status.AUTO_DELETED);
            ecrfBean.setUpdater(ub);
            ecrfBean.setUpdatedDate(new Date());
            ecrfDao.update(ecrfBean);
            // Getting Item Data
            ArrayList itemData = iddao.findAllByEventCRFId(ecrfBean.getId());
            // remove all the item data
            for (int a = 0; a < itemData.size(); a++) {
                ItemDataBean item = (ItemDataBean) itemData.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);
                    DiscrepancyNoteDAO dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
                    List dnNotesOfRemovedItem = dnDao.findExistingNotesForItemData(item.getId());
                    if (!dnNotesOfRemovedItem.isEmpty()) {
                        DiscrepancyNoteBean itemParentNote = null;
                        for (Object obj : dnNotesOfRemovedItem) {
                            if (((DiscrepancyNoteBean) obj).getParentDnId() == 0) {
                                itemParentNote = (DiscrepancyNoteBean) obj;
                            }
                        }
                        DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
                        if (itemParentNote != null) {
                            dnb.setParentDnId(itemParentNote.getId());
                            dnb.setDiscrepancyNoteTypeId(itemParentNote.getDiscrepancyNoteTypeId());
                        }
                        dnb.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
                        dnb.setStudyId(currentStudy.getId());
                        dnb.setAssignedUserId(ub.getId());
                        dnb.setOwner(ub);
                        dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
                        dnb.setEntityId(item.getId());
                        dnb.setColumn("value");
                        dnb.setCreatedDate(new Date());
                        dnb.setDescription("The item has been removed, this Discrepancy Note has been Closed.");
                        dnDao.create(dnb);
                        dnDao.createMapping(dnb);
                        itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
                        dnDao.update(itemParentNote);
                    }
                }
            }
        }
    }
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) List(java.util.List) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 69 with ItemDataDAO

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

the class UpdateEventDefinitionServlet method restoreAllEventsItems.

public void restoreAllEventsItems(EventDefinitionCRFBean edc, StudyEventDefinitionBean sed) {
    StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
    EventCRFDAO ecrfDao = new EventCRFDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    // All Study Events
    ArrayList seList = seDao.findAllByStudyEventDefinitionAndCrfOids(sed.getOid(), edc.getCrf().getOid());
    for (int j = 0; j < seList.size(); j++) {
        StudyEventBean seBean = (StudyEventBean) seList.get(j);
        // All Event CRFs
        ArrayList ecrfList = ecrfDao.findAllByStudyEventAndCrfOrCrfVersionOid(seBean, edc.getCrf().getOid());
        for (int k = 0; k < ecrfList.size(); k++) {
            EventCRFBean ecrfBean = (EventCRFBean) ecrfList.get(k);
            ecrfBean.setStatus(ecrfBean.getOldStatus());
            ecrfBean.setUpdater(ub);
            ecrfBean.setUpdatedDate(new Date());
            ecrfDao.update(ecrfBean);
            // All Item Data
            ArrayList itemData = iddao.findAllByEventCRFId(ecrfBean.getId());
            // remove all the item data
            for (int a = 0; a < itemData.size(); a++) {
                ItemDataBean item = (ItemDataBean) itemData.get(a);
                if (item.getStatus().equals(Status.DELETED) || item.getStatus().equals(Status.AUTO_DELETED)) {
                    item.setStatus(item.getOldStatus());
                    item.setUpdater(ub);
                    item.setUpdatedDate(new Date());
                    iddao.update(item);
                }
            }
        }
    }
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date)

Example 70 with ItemDataDAO

use of org.akaza.openclinica.dao.submit.ItemDataDAO 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

ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)83 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)64 ArrayList (java.util.ArrayList)61 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)61 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)52 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)40 Date (java.util.Date)38 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)37 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)31 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)30 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)29 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)29 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)28 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)27 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)24 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)23 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)22 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)21 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)21