Search in sources :

Example 76 with StudyEventDAO

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

the class RemoveStudyEventServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // studyEventId
    int studyEventId = fp.getInt("id");
    // studySubjectId
    int studySubId = fp.getInt("studySubId");
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    if (studyEventId == 0) {
        addPageMessage(respage.getString("please_choose_a_SE_to_remove"));
        request.setAttribute("id", new Integer(studySubId).toString());
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    } else {
        StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        request.setAttribute("studySub", studySub);
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
        event.setStudyEventDefinition(sed);
        StudyDAO studydao = new StudyDAO(sm.getDataSource());
        StudyBean study = (StudyBean) studydao.findByPK(studySub.getStudyId());
        request.setAttribute("study", study);
        String action = request.getParameter("action");
        if ("confirm".equalsIgnoreCase(action)) {
            //
            // if (!event.getStatus().equals(Status.AVAILABLE)) {
            // addPageMessage(respage.getString("this_event_is_not_available_for_this_study")
            // + " "
            // +
            // respage.getString("please_contact_sysadmin_for_more_information"));
            // request.setAttribute("id", new
            // Integer(studySubId).toString());
            // forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
            // return;
            // }
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            // find all crfs in the definition
            ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllByEventDefinitionId(study, sed.getId());
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
            // construct info needed on view study event page
            DisplayStudyEventBean de = new DisplayStudyEventBean();
            de.setStudyEvent(event);
            de.setDisplayEventCRFs(getDisplayEventCRFs(eventCRFs, eventDefinitionCRFs));
            request.setAttribute("displayEvent", de);
            forwardPage(Page.REMOVE_STUDY_EVENT);
        } else {
            logger.info("submit to remove the event from study");
            // remove event from study
            event.setStatus(Status.DELETED);
            event.setUpdater(ub);
            event.setUpdatedDate(new Date());
            sedao.update(event);
            // remove all event crfs
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            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.setStatus(Status.AUTO_DELETED);
                    eventCRF.setUpdater(ub);
                    eventCRF.setUpdatedDate(new Date());
                    ecdao.update(eventCRF);
                    // remove 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.DELETED)) {
                            item.setStatus(Status.AUTO_DELETED);
                            item.setUpdater(ub);
                            item.setUpdatedDate(new Date());
                            iddao.update(item);
                        }
                    }
                }
            }
            String emailBody = respage.getString("the_event") + " " + event.getStudyEventDefinition().getName() + " " + respage.getString("has_been_removed_from_the_subject_record_for") + " " + studySub.getLabel() + " " + respage.getString("in_the_study") + " " + study.getName() + ".";
            addPageMessage(emailBody);
            //                sendEmail(emailBody);
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) 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 77 with StudyEventDAO

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

the class RemoveStudySubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    // studySubjectId
    String studySubIdString = request.getParameter("id");
    String subIdString = request.getParameter("subjectId");
    String studyIdString = request.getParameter("studyId");
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) {
        addPageMessage(respage.getString("please_choose_a_study_subject_to_remove"));
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
    } else {
        int studyId = Integer.valueOf(studyIdString.trim()).intValue();
        int studySubId = Integer.valueOf(studySubIdString.trim()).intValue();
        int subjectId = Integer.valueOf(subIdString.trim()).intValue();
        SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        StudyDAO studydao = new StudyDAO(sm.getDataSource());
        StudyBean study = (StudyBean) studydao.findByPK(studyId);
        checkRoleByUserAndStudy(ub, study.getParentStudyId(), study.getId());
        // find study events
        StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
        //            ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId);
        ArrayList<DisplayStudyEventBean> displayEvents = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, sm.getDataSource(), ub, currentRole);
        String action = request.getParameter("action");
        if ("confirm".equalsIgnoreCase(action)) {
            if (!studySub.getStatus().equals(Status.AVAILABLE)) {
                addPageMessage(respage.getString("this_subject_is_not_available_for_this_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
                forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
                return;
            }
            request.setAttribute("subject", subject);
            request.setAttribute("study", study);
            request.setAttribute("studySub", studySub);
            request.setAttribute("events", displayEvents);
            forwardPage(Page.REMOVE_STUDY_SUBJECT);
        } else {
            logger.info("submit to remove the subject from study");
            // remove subject from study
            studySub.setStatus(Status.DELETED);
            studySub.setUpdater(ub);
            studySub.setUpdatedDate(new Date());
            subdao.update(studySub);
            // remove all study events
            // remove all event crfs
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            for (int j = 0; j < displayEvents.size(); j++) {
                DisplayStudyEventBean dispEvent = displayEvents.get(j);
                StudyEventBean event = dispEvent.getStudyEvent();
                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.setStatus(Status.AUTO_DELETED);
                            eventCRF.setUpdater(ub);
                            eventCRF.setUpdatedDate(new Date());
                            ecdao.update(eventCRF);
                            // remove 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.DELETED)) {
                                    item.setStatus(Status.AUTO_DELETED);
                                    item.setUpdater(ub);
                                    item.setUpdatedDate(new Date());
                                    iddao.update(item);
                                }
                            }
                        }
                    }
                }
            }
            String emailBody = respage.getString("the_subject") + " " + subject.getName() + " " + respage.getString("has_been_removed_from_the_study") + study.getName() + ".";
            addPageMessage(emailBody);
            //                try{
            //                    sendEmail(emailBody);    
            //                }catch(Exception ex){
            //                    addPageMessage(respage.getString("mail_cannot_be_sent_to_admin"));
            //                }
            forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
        }
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) 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) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) 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) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 78 with StudyEventDAO

use of org.akaza.openclinica.dao.managestudy.StudyEventDAO 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");
            eventCRF.setStatus(Status.AVAILABLE);
            eventCRF.setUpdater(ub);
            eventCRF.setUpdatedDate(new Date());
            ecdao.update(eventCRF);
            // restore all the item data
            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);
                }
            }
            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 79 with StudyEventDAO

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

the class RestoreEventDefinitionServlet 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);
    // 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());
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(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_restore"));
        forwardPage(Page.LIST_DEFINITION_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            if (!sed.getStatus().equals(Status.DELETED)) {
                addPageMessage(respage.getString("this_SED_cannot_be_restored") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
                forwardPage(Page.LIST_DEFINITION_SERVLET);
                return;
            }
            String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
            request.setAttribute("participateFormStatus", participateFormStatus);
            if (participateFormStatus.equals("enabled"))
                baseUrl();
            request.setAttribute("definitionToRestore", sed);
            request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
            request.setAttribute("events", events);
            forwardPage(Page.RESTORE_DEFINITION);
        } else {
            logger.info("submit to restore the definition");
            // restore definition
            sed.setStatus(Status.AVAILABLE);
            sed.setUpdater(ub);
            sed.setUpdatedDate(new Date());
            sdao.update(sed);
            // restore all crfs
            for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
                EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
                if (edc.getStatus().equals(Status.AUTO_DELETED)) {
                    edc.setStatus(Status.AVAILABLE);
                    edc.setUpdater(ub);
                    edc.setUpdatedDate(new Date());
                    edao.update(edc);
                }
            }
            // restore 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.AUTO_DELETED)) {
                    event.setStatus(Status.AVAILABLE);
                    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.AUTO_DELETED)) {
                            eventCRF.setStatus(Status.AVAILABLE);
                            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(Status.AVAILABLE);
                                    item.setUpdater(ub);
                                    item.setUpdatedDate(new Date());
                                    iddao.update(item);
                                }
                            }
                        }
                    }
                }
            }
            String emailBody = respage.getString("the_SED") + " " + sed.getName() + "(" + respage.getString("and_all_associated_event_data_restored_to_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)

Example 80 with StudyEventDAO

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

the class PrintDataEntryServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    boolean isSubmitted = false;
    int eventCRFId = fp.getInt("ecId");
    //JN:The following were the the global variables, moved as local.
    EventCRFBean ecb;
    SectionDAO sdao = new SectionDAO(getDataSource());
    ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
    ArrayList sectionBeans = new ArrayList();
    String age = "";
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    // Whether IE6 or IE7 is involved
    String isIE = fp.getString("ie");
    if ("y".equalsIgnoreCase(isIE)) {
        request.setAttribute("isInternetExplorer", "true");
    }
    if (eventCRFId == 0) {
        ecb = new EventCRFBean();
    // super.ecb.setCRFVersionId(sb.getCRFVersionId());
    } else {
        EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        // Get all the SectionBeans attached to this ECB
        ArrayList sects = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
        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));
            }
        }
        // This is the StudySubjectBean
        StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
        StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
        // This is the SubjectBean
        SubjectDAO subjectDao = new SubjectDAO(getDataSource());
        int subjectId = sub.getSubjectId();
        int studyId = sub.getStudyId();
        SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
        StudyEventDAO sedao = new StudyEventDAO(getDataSource());
        StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
        se.setStudyEventDefinition(sed);
        // Let us process the age
        if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
            // YW 11-16-2007 enrollment-date is used for computing age
            age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
        }
        // Get the study then the parent study
        StudyDAO studydao = new StudyDAO(getDataSource());
        StudyBean study = (StudyBean) studydao.findByPK(studyId);
        if (study.getParentStudyId() > 0) {
            // this is a site,find parent
            StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
            request.setAttribute("studyTitle", parentStudy.getName() + " - " + study.getName());
        } else {
            request.setAttribute("studyTitle", study.getName());
        }
        request.setAttribute("studySubject", sub);
        request.setAttribute("subject", subject);
        request.setAttribute("studyEvent", se);
        request.setAttribute("age", age);
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
        // Get the section beans from super
        sectionBeans = super.getAllDisplayBeans(request);
    }
    // Find out whether the sections involve groups
    ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
    // Find truely grouped tables, not groups with a name of 'Ungrouped'
    // CRF VERSION ID WILL BE 0 IF "ecId" IS NOT IN THE QUERYSTRING
    int crfVersionId = ecb.getCRFVersionId();
    List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionId);
    boolean sectionsHaveGroups = false;
    if (itemGroupBeans.size() > 0) {
        sectionsHaveGroups = true;
        // 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 an event or data is involved
        // or not
        DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(true, getDataSource(), getServletContext());
        handler.setCrfVersionId(crfVersionId);
        handler.setEventCRFId(eventCRFId);
        List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
        CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
        CRFDAO crfDao = new CRFDAO(getDataSource());
        request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
        // Make available the CRF names and versions for
        // the web page's header
        CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
        request.setAttribute("crfVersionBean", crfverBean);
        CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
        request.setAttribute("crfBean", crfBean);
        // Set an attribute signaling that an event and/or data is involved
        request.setAttribute("dataInvolved", "true");
    }
    request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
    request.setAttribute("EventCRFBean", ecb);
    // We do not need most of these attributes if groups are involved
    if (!sectionsHaveGroups) {
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
        request.setAttribute("allSections", sectionBeans);
        request.setAttribute("displayAll", "1");
        request.setAttribute(BEAN_DISPLAY, dsb);
        request.setAttribute("sec", sb);
        forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
    } else {
        // end if(! sectionsHaveGroups)
        forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DisplaySectionBeanHandler(org.akaza.openclinica.view.display.DisplaySectionBeanHandler) 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) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) 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) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Aggregations

StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)107 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)90 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)80 ArrayList (java.util.ArrayList)76 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)69 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)69 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)62 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)61 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)57 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)57 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)51 Date (java.util.Date)49 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)49 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)41 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)40 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)38 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)35 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)35 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)33 HashMap (java.util.HashMap)29