Search in sources :

Example 76 with StudySubjectDAO

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

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

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

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

the class ReassignStudySubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String action = request.getParameter("action");
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studySubId = fp.getInt("id");
    if (studySubId == 0) {
        addPageMessage(respage.getString("please_choose_a_subject_to_reassign"));
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
        return;
    } else {
        StudySubjectBean studySub = (StudySubjectBean) ssdao.findByPK(studySubId);
        int subjectId = studySub.getSubjectId();
        request.setAttribute("studySub", studySub);
        SubjectBean subject = (SubjectBean) subdao.findByPK(subjectId);
        request.setAttribute("subject", subject);
        SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
        ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
        if (StringUtil.isBlank(action)) {
            ArrayList studies = null;
            DisplayStudyBean displayStudy = new DisplayStudyBean();
            StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
            if (study.getParentStudyId() > 0) {
                // current in site
                studies = (ArrayList) sdao.findAllByParent(study.getParentStudyId());
                StudyBean parent = (StudyBean) sdao.findByPK(study.getParentStudyId());
                displayStudy.setParent(parent);
                // studies.add(parent);
                displayStudy.setChildren(studies);
            } else {
                studies = (ArrayList) sdao.findAllByParent(study.getId());
                displayStudy.setParent(study);
                displayStudy.setChildren(studies);
            // studies.add(study);
            }
            // request.setAttribute("studies", studies);
            request.setAttribute("displayStudy", displayStudy);
            forwardPage(Page.REASSIGN_STUDY_SUBJECT);
        } else {
            int studyId = fp.getInt("studyId");
            if (studyId == 0) {
                addPageMessage(respage.getString("please_choose_a_study_site_to_reassign_the_subject"));
                forwardPage(Page.REASSIGN_STUDY_SUBJECT);
                return;
            }
            StudyBean st = (StudyBean) sdao.findByPK(studyId);
            if ("confirm".equalsIgnoreCase(action)) {
                StudySubjectBean sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabel(studySub.getLabel(), studyId, studySub.getId());
                if (sub1.getId() > 0) {
                    addPageMessage(respage.getString("the_study_subject_ID_used_by_another_in_study_site"));
                    forwardPage(Page.REASSIGN_STUDY_SUBJECT);
                    return;
                }
                // YW << comment out this message
                // if (groupMaps.size() > 0) {
                // addPageMessage("Warning: This subject has Group data
                // assoicated with current study,"
                // + "the group data will be lost if it is reassigned to
                // another study.");
                // }
                // YW >>
                request.setAttribute("newStudy", st);
                forwardPage(Page.REASSIGN_STUDY_SUBJECT_CONFIRM);
            } else {
                logger.info("submit to reassign the subject");
                studySub.setUpdatedDate(new Date());
                studySub.setUpdater(ub);
                studySub.setStudyId(studyId);
                ssdao.update(studySub);
                for (int i = 0; i < groupMaps.size(); i++) {
                    SubjectGroupMapBean sgm = (SubjectGroupMapBean) groupMaps.get(i);
                    sgm.setUpdatedDate(new Date());
                    sgm.setUpdater(ub);
                    sgm.setStatus(Status.DELETED);
                    sgmdao.update(sgm);
                }
                MessageFormat mf = new MessageFormat("");
                mf.applyPattern(respage.getString("subject_reassigned"));
                Object[] arguments = { studySub.getLabel(), st.getName() };
                addPageMessage(mf.format(arguments));
                forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
            }
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) MessageFormat(java.text.MessageFormat) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) DisplayStudyBean(org.akaza.openclinica.bean.admin.DisplayStudyBean) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DisplayStudyBean(org.akaza.openclinica.bean.admin.DisplayStudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 80 with StudySubjectDAO

use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO 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)

Aggregations

StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)102 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)86 ArrayList (java.util.ArrayList)63 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)62 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)62 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)59 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)58 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)54 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)50 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)42 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)41 Date (java.util.Date)38 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)32 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)29 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)27 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)24 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)23 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)23