Search in sources :

Example 26 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class DeleteEventCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int studySubId = fp.getInt(STUDY_SUB_ID, true);
    int eventCRFId = fp.getInt(EVENT_CRF_ID);
    String action = request.getParameter("action");
    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_delete"));
        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);
        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());
        dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
        ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId());
        request.setAttribute("items", itemData);
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("displayEventCRF", dec);
            forwardPage(Page.DELETE_EVENT_CRF);
        } else {
            logger.info("submit to delete the event CRF from event");
            // OC-6303 Deleting Event CRF resets Show / Hide logic
            // delete records from DynamicItemForm and DynamicItemGroup
            // getDynamicsItemFormMetadataDao().delete(eventCRFId);
            // getDynamicsItemGroupMetadataDao().delete(eventCRFId);
            eventCRF.setOldStatus(eventCRF.getStatus());
            eventCRF.setStatus(Status.RESET);
            eventCRF.setUpdater(ub);
            ecdao.update(eventCRF);
            for (ItemDataBean itemdata : itemData) {
                // OC-6343 Rule behaviour must be reset if an Event CRF is deleted
                // delete the records from ruleActionRunLogDao
                List<RuleActionRunLogBean> ruleActionRunLog = getRuleActionRunLogDao().findAllItemData(itemdata.getId());
                if (ruleActionRunLog.size() != 0) {
                    getRuleActionRunLogDao().delete(itemdata.getId());
                }
                // OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted
                // parentDiscrepancyNoteList is the list of the parent DNs records only
                ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId());
                for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) {
                    if (parentDiscrepancyNote.getResolutionStatusId() != 4) {
                        // if the DN's resolution status is
                        // not set to Closed
                        String description = resword.getString("dn_auto-closed_description");
                        String detailedNotes = resword.getString("dn_auto_closed_detailed_notes");
                        // create new DN record , new DN Map record , also update the parent record
                        createDiscrepancyNoteBean(description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote);
                    }
                }
                iddao = new ItemDataDAO(sm.getDataSource());
                ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
                ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId());
                ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId);
                // Updating Dn_item_data_map actovated column into false for the existing DNs
                ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId());
                if (dnBeans.size() != 0) {
                    DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean();
                    dnBean.setEntityId(itemdata.getId());
                    dnBean.setActivated(false);
                    getDnDao().updateDnMapActivation(dnBean);
                }
                // Default Values are not addressed
                itemdata.setValue("");
                itemdata.setOldStatus(itemdata.getStatus());
                itemdata.setOwner(ub);
                itemdata.setStatus(Status.AVAILABLE);
                itemdata.setUpdater(ub);
                iddao.updateUser(itemdata);
                iddao.update(itemdata);
            }
            // OC-6291 event_crf status change
            eventCRF.setOldStatus(eventCRF.getStatus());
            eventCRF.setStatus(Status.AVAILABLE);
            eventCRF.setUpdater(ub);
            ecdao.update(eventCRF);
            if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) {
                event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
                event.setUpdater(ub);
                sedao = new StudyEventDAO(sm.getDataSource());
                sedao.update(event);
            }
            String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont");
            addPageMessage(emailBody);
            // sendEmail(emailBody);
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
    }
}
Also used : 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) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) 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) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) 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) 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) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 27 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class RemoveStudyServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt("id");
    StudyBean study = (StudyBean) sdao.findByPK(studyId);
    // find all sites
    ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
    // find all user and roles in the study, include ones in sites
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userRoles = udao.findAllByStudyId(studyId);
    // find all subjects in the study, include ones in sites
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList subjects = ssdao.findAllByStudy(study);
    // find all events in the study, include ones in sites
    StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList definitions = sefdao.findAllByStudy(study);
    String action = request.getParameter("action");
    if (studyId == 0) {
        addPageMessage(respage.getString("please_choose_a_study_to_remove"));
        forwardPage(Page.STUDY_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("studyToRemove", study);
            request.setAttribute("sitesToRemove", sites);
            request.setAttribute("userRolesToRemove", userRoles);
            request.setAttribute("subjectsToRemove", subjects);
            request.setAttribute("definitionsToRemove", definitions);
            forwardPage(Page.REMOVE_STUDY);
        } else {
            logger.info("submit to remove the study");
            // change all statuses to unavailable
            StudyDAO studao = new StudyDAO(sm.getDataSource());
            study.setOldStatus(study.getStatus());
            study.setStatus(Status.DELETED);
            study.setUpdater(ub);
            study.setUpdatedDate(new Date());
            studao.update(study);
            // remove all sites
            for (int i = 0; i < sites.size(); i++) {
                StudyBean site = (StudyBean) sites.get(i);
                if (!site.getStatus().equals(Status.DELETED)) {
                    site.setOldStatus(site.getStatus());
                    site.setStatus(Status.AUTO_DELETED);
                    site.setUpdater(ub);
                    site.setUpdatedDate(new Date());
                    sdao.update(site);
                }
            }
            // remove all users and roles
            for (int i = 0; i < userRoles.size(); i++) {
                StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
                logger.info("remove user role" + role.getName());
                if (!role.getStatus().equals(Status.DELETED)) {
                    role.setStatus(Status.AUTO_DELETED);
                    role.setUpdater(ub);
                    role.setUpdatedDate(new Date());
                    udao.updateStudyUserRole(role, role.getUserName());
                }
            }
            // YW << bug fix for that current active study has been deleted
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.DELETED);
                currentRole.setStatus(Status.DELETED);
            } else // (auto-removed)
            if (currentStudy.getParentStudyId() == study.getId()) {
                currentStudy.setStatus(Status.AUTO_DELETED);
                // we may need handle this later?
                currentRole.setStatus(Status.DELETED);
            }
            // remove all subjects
            for (int i = 0; i < subjects.size(); i++) {
                StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
                if (!subject.getStatus().equals(Status.DELETED)) {
                    subject.setStatus(Status.AUTO_DELETED);
                    subject.setUpdater(ub);
                    subject.setUpdatedDate(new Date());
                    ssdao.update(subject);
                }
            }
            // remove all study_group_class
            // changed by jxu on 08-31-06, to fix the problem of no study_id
            // in study_group table
            StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
            StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
            SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
            // YW 09-27-2007, enable status updating for StudyGroupClassBean
            ArrayList groups = sgcdao.findAllByStudy(study);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
                if (!group.getStatus().equals(Status.DELETED)) {
                    group.setStatus(Status.AUTO_DELETED);
                    group.setUpdater(ub);
                    group.setUpdatedDate(new Date());
                    sgcdao.update(group);
                    // all subject_group_map
                    ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
                    for (int j = 0; j < subjectGroupMaps.size(); j++) {
                        SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
                        if (!sgMap.getStatus().equals(Status.DELETED)) {
                            sgMap.setStatus(Status.AUTO_DELETED);
                            sgMap.setUpdater(ub);
                            sgMap.setUpdatedDate(new Date());
                            sgmdao.update(sgMap);
                        }
                    }
                }
            }
            ArrayList groupClasses = sgcdao.findAllActiveByStudy(study);
            for (int i = 0; i < groupClasses.size(); i++) {
                StudyGroupClassBean gc = (StudyGroupClassBean) groupClasses.get(i);
                if (!gc.getStatus().equals(Status.DELETED)) {
                    gc.setStatus(Status.AUTO_DELETED);
                    gc.setUpdater(ub);
                    gc.setUpdatedDate(new Date());
                    sgcdao.update(gc);
                }
            }
            // remove all event definitions and event
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            for (int i = 0; i < definitions.size(); i++) {
                StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
                if (!definition.getStatus().equals(Status.DELETED)) {
                    definition.setStatus(Status.AUTO_DELETED);
                    definition.setUpdater(ub);
                    definition.setUpdatedDate(new Date());
                    sefdao.update(definition);
                    ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
                    for (int j = 0; j < edcs.size(); j++) {
                        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
                        if (!edc.getStatus().equals(Status.DELETED)) {
                            edc.setStatus(Status.AUTO_DELETED);
                            edc.setUpdater(ub);
                            edc.setUpdatedDate(new Date());
                            edcdao.update(edc);
                        }
                    }
                    ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
                    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                    for (int j = 0; j < events.size(); j++) {
                        StudyEventBean event = (StudyEventBean) events.get(j);
                        if (!event.getStatus().equals(Status.DELETED)) {
                            event.setStatus(Status.AUTO_DELETED);
                            event.setUpdater(ub);
                            event.setUpdatedDate(new Date());
                            sedao.update(event);
                            ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
                            ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
                            for (int k = 0; k < eventCRFs.size(); k++) {
                                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                                if (!eventCRF.getStatus().equals(Status.DELETED)) {
                                    eventCRF.setOldStatus(eventCRF.getStatus());
                                    eventCRF.setStatus(Status.AUTO_DELETED);
                                    eventCRF.setUpdater(ub);
                                    eventCRF.setUpdatedDate(new Date());
                                    ecdao.update(eventCRF);
                                    ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
                                    for (int a = 0; a < itemDatas.size(); a++) {
                                        ItemDataBean item = (ItemDataBean) itemDatas.get(a);
                                        if (!item.getStatus().equals(Status.DELETED)) {
                                            item.setOldStatus(item.getStatus());
                                            item.setStatus(Status.AUTO_DELETED);
                                            item.setUpdater(ub);
                                            item.setUpdatedDate(new Date());
                                            iddao.update(item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // for definitions
            DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
            ArrayList dataset = datadao.findAllByStudyId(study.getId());
            for (int i = 0; i < dataset.size(); i++) {
                DatasetBean data = (DatasetBean) dataset.get(i);
                if (!data.getStatus().equals(Status.DELETED)) {
                    data.setStatus(Status.AUTO_DELETED);
                    data.setUpdater(ub);
                    data.setUpdatedDate(new Date());
                    datadao.update(data);
                }
            }
            addPageMessage(resexception.getString("this_study_has_been_removed_succesfully"));
            forwardPage(Page.STUDY_LIST_SERVLET);
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) Date(java.util.Date) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 28 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class RemoveSubjectServlet method processRequest.

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

Example 29 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class RestoreCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    int crfId = fp.getInt("id", true);
    String action = request.getParameter("action");
    if (crfId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_to_restore"));
        forwardPage(Page.CRF_LIST_SERVLET);
    } else {
        CRFBean crf = (CRFBean) cdao.findByPK(crfId);
        ArrayList versions = cvdao.findAllByCRFId(crfId);
        crf.setVersions(versions);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        ArrayList edcs = (ArrayList) edcdao.findAllByCRF(crfId);
        SectionDAO secdao = new SectionDAO(sm.getDataSource());
        EventCRFDAO evdao = new EventCRFDAO(sm.getDataSource());
        ArrayList eventCRFs = evdao.findAllByCRF(crfId);
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("crfToRestore", crf);
            request.setAttribute("eventCRFs", eventCRFs);
            forwardPage(Page.RESTORE_CRF);
        } else {
            logger.info("submit to restore the crf");
            crf.setStatus(Status.AVAILABLE);
            crf.setUpdater(ub);
            crf.setUpdatedDate(new Date());
            cdao.update(crf);
            for (int i = 0; i < versions.size(); i++) {
                CRFVersionBean version = (CRFVersionBean) versions.get(i);
                if (version.getStatus().equals(Status.AUTO_DELETED)) {
                    version.setStatus(Status.AVAILABLE);
                    version.setUpdater(ub);
                    version.setUpdatedDate(new Date());
                    cvdao.update(version);
                    ArrayList sections = secdao.findAllByCRFVersionId(version.getId());
                    for (int j = 0; j < sections.size(); j++) {
                        SectionBean section = (SectionBean) sections.get(j);
                        if (section.getStatus().equals(Status.AUTO_DELETED)) {
                            section.setStatus(Status.AVAILABLE);
                            section.setUpdater(ub);
                            section.setUpdatedDate(new Date());
                            secdao.update(section);
                        }
                    }
                }
            }
            for (int i = 0; i < edcs.size(); i++) {
                EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(i);
                if (edc.getStatus().equals(Status.AUTO_DELETED)) {
                    edc.setStatus(Status.AVAILABLE);
                    edc.setUpdater(ub);
                    edc.setUpdatedDate(new Date());
                    edcdao.update(edc);
                }
            }
            ItemDataDAO idao = new ItemDataDAO(sm.getDataSource());
            for (int i = 0; i < eventCRFs.size(); i++) {
                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(i);
                if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
                    eventCRF.setStatus(Status.AVAILABLE);
                    eventCRF.setUpdater(ub);
                    eventCRF.setUpdatedDate(new Date());
                    evdao.update(eventCRF);
                    ArrayList items = idao.findAllByEventCRFId(eventCRF.getId());
                    for (int j = 0; j < items.size(); j++) {
                        ItemDataBean item = (ItemDataBean) items.get(j);
                        if (item.getStatus().equals(Status.AUTO_DELETED)) {
                            item.setStatus(Status.AVAILABLE);
                            item.setUpdater(ub);
                            item.setUpdatedDate(new Date());
                            idao.update(item);
                        }
                    }
                }
            }
            addPageMessage(respage.getString("the_CRF") + crf.getName() + " " + respage.getString("has_been_restored_succesfully"));
            forwardPage(Page.CRF_LIST_SERVLET);
        }
    }
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) 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) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 30 with ItemDataBean

use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.

the class RestoreCRFVersionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    int versionId = fp.getInt("id", true);
    String action = fp.getString("action");
    if (versionId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_version_to_restore"));
        forwardPage(Page.CRF_LIST_SERVLET);
    } else {
        if (StringUtil.isBlank(action)) {
            addPageMessage(respage.getString("no_action_specified"));
            forwardPage(Page.CRF_LIST_SERVLET);
            return;
        }
        CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
        SectionDAO secdao = new SectionDAO(sm.getDataSource());
        EventCRFDAO evdao = new EventCRFDAO(sm.getDataSource());
        // find all event crfs by version id
        ArrayList eventCRFs = evdao.findAllByCRFVersion(versionId);
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("versionToRestore", version);
            request.setAttribute("eventCRFs", eventCRFs);
            forwardPage(Page.RESTORE_CRF_VERSION);
        } else {
            logger.info("submit to restore the crf version");
            // version
            version.setStatus(Status.AVAILABLE);
            version.setUpdater(ub);
            version.setUpdatedDate(new Date());
            cvdao.update(version);
            // all sections
            ArrayList sections = secdao.findAllByCRFVersionId(version.getId());
            for (int j = 0; j < sections.size(); j++) {
                SectionBean section = (SectionBean) sections.get(j);
                if (section.getStatus().equals(Status.AUTO_DELETED)) {
                    section.setStatus(Status.AVAILABLE);
                    section.setUpdater(ub);
                    section.setUpdatedDate(new Date());
                    secdao.update(section);
                }
            }
            // all item data related to event crfs
            ItemDataDAO idao = new ItemDataDAO(sm.getDataSource());
            for (int i = 0; i < eventCRFs.size(); i++) {
                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(i);
                if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
                    eventCRF.setStatus(Status.AVAILABLE);
                    eventCRF.setUpdater(ub);
                    eventCRF.setUpdatedDate(new Date());
                    evdao.update(eventCRF);
                    ArrayList items = idao.findAllByEventCRFId(eventCRF.getId());
                    for (int j = 0; j < items.size(); j++) {
                        ItemDataBean item = (ItemDataBean) items.get(j);
                        if (item.getStatus().equals(Status.AUTO_DELETED)) {
                            item.setStatus(Status.AVAILABLE);
                            item.setUpdater(ub);
                            item.setUpdatedDate(new Date());
                            idao.update(item);
                        }
                    }
                }
            }
            addPageMessage(respage.getString("the_CRF_version") + version.getName() + " " + respage.getString("has_been_restored_succesfully"));
            forwardPage(Page.CRF_LIST_SERVLET);
        }
    }
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Aggregations

ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)133 ArrayList (java.util.ArrayList)74 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)64 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)61 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)42 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)41 HashMap (java.util.HashMap)39 Date (java.util.Date)37 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)37 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)33 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)33 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)26 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)26 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)26 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)21 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)21 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)20 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)20 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)18