Search in sources :

Example 41 with StudySubjectBean

use of org.akaza.openclinica.bean.managestudy.StudySubjectBean 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 42 with StudySubjectBean

use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.

the class ListSubjectTableFactory method setDataAndLimitVariables.

@SuppressWarnings("unchecked")
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
    // initialize i18n
    resword = ResourceBundleProvider.getWordsBundle(getLocale());
    resformat = ResourceBundleProvider.getFormatBundle(getLocale());
    Limit limit = tableFacade.getLimit();
    ListSubjectFilter listSubjectFilter = getListSubjectFilter(limit);
    if (!limit.isComplete()) {
        Integer totalRows = getSubjectDao().getCountWithFilter(listSubjectFilter, getCurrentStudy());
        if (totalRows == null) {
            totalRows = 0;
        }
        tableFacade.setTotalRows(totalRows.intValue());
    }
    ListSubjectSort listSubjectSort = getListSubjectSort(limit);
    int rowStart = limit.getRowSelect().getRowStart();
    int rowEnd = limit.getRowSelect().getRowEnd();
    Collection<SubjectBean> items = getSubjectDao().getWithFilterAndSort(getCurrentStudy(), listSubjectFilter, listSubjectSort, rowStart, rowEnd);
    Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
    for (SubjectBean subject : items) {
        UserAccountBean owner = (UserAccountBean) getUserAccountDao().findByPK(subject.getOwnerId());
        UserAccountBean updater = subject.getUpdaterId() == 0 ? null : (UserAccountBean) getUserAccountDao().findByPK(subject.getUpdaterId());
        HashMap<Object, Object> h = new HashMap<Object, Object>();
        String studySubjectIdAndStudy = "";
        List<StudySubjectBean> studySubjects = getStudySubjectDao().findAllBySubjectId(subject.getId());
        for (StudySubjectBean studySubjectBean : studySubjects) {
            StudyBean study = (StudyBean) getStudyDao().findByPK(studySubjectBean.getStudyId());
            studySubjectIdAndStudy += studySubjectIdAndStudy.length() == 0 ? "" : ",";
            studySubjectIdAndStudy += study.getIdentifier() + "-" + studySubjectBean.getLabel();
        }
        h.put("studySubjectIdAndStudy", studySubjectIdAndStudy);
        h.put("subject", subject);
        h.put("subject.uniqueIdentifier", subject.getUniqueIdentifier());
        h.put("subject.gender", subject.getGender());
        Date tempDate = subject.getCreatedDate();
        String tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
        h.put("subject.createdDate", tempDateStr);
        h.put("subject.owner", owner);
        tempDate = subject.getUpdatedDate();
        tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
        h.put("subject.updatedDate", tempDateStr);
        h.put("subject.updater", updater);
        h.put("subject.status", subject.getStatus());
        theItems.add(h);
    }
    tableFacade.setItems(theItems);
}
Also used : ListSubjectFilter(org.akaza.openclinica.dao.submit.ListSubjectFilter) HashMap(java.util.HashMap) ListSubjectSort(org.akaza.openclinica.dao.submit.ListSubjectSort) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) 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) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Limit(org.jmesa.limit.Limit)

Example 43 with StudySubjectBean

use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.

the class ExportExcelStudySubjectAuditLogServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    AuditDAO adao = new AuditDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO studydao = new StudyDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    StudySubjectBean studySubject = null;
    SubjectBean subject = null;
    ArrayList events = null;
    ArrayList studySubjectAudits = new ArrayList();
    ArrayList eventCRFAudits = new ArrayList();
    ArrayList studyEventAudits = new ArrayList();
    ArrayList allDeletedEventCRFs = new ArrayList();
    ArrayList allEventCRFs = new ArrayList();
    ArrayList allEventCRFItems = new ArrayList();
    String attachedFilePath = Utils.getAttachedFilePath(currentStudy);
    FormProcessor fp = new FormProcessor(request);
    int studySubId = fp.getInt("id", true);
    if (studySubId == 0) {
        addPageMessage(respage.getString("please_choose_a_subject_to_view"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
    } else {
        studySubject = (StudySubjectBean) subdao.findByPK(studySubId);
        StudyBean study = (StudyBean) studydao.findByPK(studySubject.getStudyId());
        // Check if this StudySubject would be accessed from the Current Study
        if (studySubject.getStudyId() != currentStudy.getId()) {
            if (currentStudy.getParentStudyId() > 0) {
                addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                forwardPage(Page.MENU_SERVLET);
                return;
            } else {
                // The SubjectStudy is not belong to currentstudy and current study is not a site.
                Collection sites = studydao.findOlnySiteIdsByStudy(currentStudy);
                if (!sites.contains(study.getId())) {
                    addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                    forwardPage(Page.MENU_SERVLET);
                    return;
                }
            }
        }
        subject = (SubjectBean) sdao.findByPK(studySubject.getSubjectId());
        /* Show both study subject and subject audit events together */
        // Study subject value changed
        Collection studySubjectAuditEvents = adao.findStudySubjectAuditEvents(studySubject.getId());
        // integer values.
        for (Iterator iterator = studySubjectAuditEvents.iterator(); iterator.hasNext(); ) {
            AuditBean auditBean = (AuditBean) iterator.next();
            if (auditBean.getAuditEventTypeId() == 3) {
                auditBean.setOldValue(Status.get(Integer.parseInt(auditBean.getOldValue())).getName());
                auditBean.setNewValue(Status.get(Integer.parseInt(auditBean.getNewValue())).getName());
            }
        }
        studySubjectAudits.addAll(studySubjectAuditEvents);
        // Global subject value changed
        studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
        studySubjectAudits.addAll(adao.findStudySubjectGroupAssignmentAuditEvents(studySubject.getId()));
        // Get the list of events
        events = sedao.findAllByStudySubject(studySubject);
        for (int i = 0; i < events.size(); i++) {
            // Link study event definitions
            StudyEventBean studyEvent = (StudyEventBean) events.get(i);
            studyEvent.setStudyEventDefinition((StudyEventDefinitionBean) seddao.findByPK(studyEvent.getStudyEventDefinitionId()));
            // Link event CRFs
            studyEvent.setEventCRFs(ecdao.findAllByStudyEvent(studyEvent));
            // Find deleted Event CRFs
            List deletedEventCRFs = adao.findDeletedEventCRFsFromAuditEvent(studyEvent.getId());
            allDeletedEventCRFs.addAll(deletedEventCRFs);
            List eventCRFs = (List) adao.findAllEventCRFAuditEvents(studyEvent.getId());
            allEventCRFs.addAll(eventCRFs);
            List eventCRFItems = (List) adao.findAllEventCRFAuditEventsWithItemDataType(studyEvent.getId());
            allEventCRFItems.addAll(eventCRFItems);
            logger.info("deletedEventCRFs size[" + deletedEventCRFs.size() + "]");
            logger.info("allEventCRFItems size[" + allEventCRFItems.size() + "]");
        }
        for (int i = 0; i < events.size(); i++) {
            StudyEventBean studyEvent = (StudyEventBean) events.get(i);
            studyEventAudits.addAll(adao.findStudyEventAuditEvents(studyEvent.getId()));
            ArrayList eventCRFs = studyEvent.getEventCRFs();
            for (int j = 0; j < eventCRFs.size(); j++) {
                // Link CRF and CRF Versions
                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(j);
                eventCRF.setCrfVersion((CRFVersionBean) cvdao.findByPK(eventCRF.getCRFVersionId()));
                eventCRF.setCrf(cdao.findByVersionId(eventCRF.getCRFVersionId()));
                // Get the event crf audits
                eventCRFAudits.addAll(adao.findEventCRFAuditEventsWithItemDataType(eventCRF.getId()));
                logger.info("eventCRFAudits size [" + eventCRFAudits.size() + "] eventCRF id [" + eventCRF.getId() + "]");
            }
        }
        ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
        for (Object o : eventCRFAudits) {
            AuditBean ab = (AuditBean) o;
            if (ab.getAuditTable().equalsIgnoreCase("item_data")) {
                ItemDataBean idBean = (ItemDataBean) itemDataDao.findByPK(ab.getEntityId());
                ab.setOrdinal(idBean.getOrdinal());
            }
        }
    }
    try {
        WritableFont headerFormat = new WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLUE2);
        WritableCellFormat cellFormat = new WritableCellFormat();
        cellFormat.setFont(headerFormat);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=export.xls");
        WorkbookSettings wbSettings = new WorkbookSettings();
        wbSettings.setLocale(new Locale("en", "EN"));
        WritableWorkbook workbook = Workbook.createWorkbook(response.getOutputStream(), wbSettings);
        int row = 0;
        // Subject Information
        workbook.createSheet("Subject Information", 0);
        WritableSheet excelSheet = workbook.getSheet(0);
        // Subject Summary
        String[] excelRow = new String[] { "study_subject_ID", "secondary_subject_ID", "date_of_birth", "person_ID", "created_by", "status" };
        for (int i = 0; i < excelRow.length; i++) {
            Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
            excelSheet.addCell(label);
        }
        row++;
        excelRow = new String[] { studySubject.getLabel(), studySubject.getSecondaryLabel(), dateFormat(subject.getDateOfBirth()), subject.getUniqueIdentifier(), studySubject.getOwner().getName(), studySubject.getStatus().getName() };
        for (int i = 0; i < excelRow.length; i++) {
            Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
            excelSheet.addCell(label);
        }
        row++;
        row++;
        // Subject Audit Events
        excelRow = new String[] { "audit_event", "date_time_of_server", "user", "value_type", "old", "new" };
        for (int i = 0; i < excelRow.length; i++) {
            Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
            excelSheet.addCell(label);
        }
        row++;
        for (int j = 0; j < studySubjectAudits.size(); j++) {
            AuditBean audit = (AuditBean) studySubjectAudits.get(j);
            excelRow = new String[] { audit.getAuditEventTypeName(), dateTimeFormat(audit.getAuditDate()), audit.getUserName(), audit.getEntityName(), audit.getOldValue(), audit.getNewValue() };
            for (int i = 0; i < excelRow.length; i++) {
                Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                excelSheet.addCell(label);
            }
            row++;
        }
        row++;
        // Study Events
        excelRow = new String[] { "study_events", "location", "date", "occurrence_number" };
        for (int i = 0; i < excelRow.length; i++) {
            Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
            excelSheet.addCell(label);
        }
        row++;
        for (int j = 0; j < events.size(); j++) {
            StudyEventBean event = (StudyEventBean) events.get(j);
            if (event.getStartTimeFlag()) {
                excelRow = new String[] { event.getStudyEventDefinition().getName(), event.getLocation(), dateTimeFormat(event.getDateStarted()), Integer.toString(event.getSampleOrdinal()) };
            } else {
                excelRow = new String[] { event.getStudyEventDefinition().getName(), event.getLocation(), dateFormat(event.getDateStarted()), Integer.toString(event.getSampleOrdinal()) };
            }
            for (int i = 0; i < excelRow.length; i++) {
                Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                excelSheet.addCell(label);
            }
            row++;
        }
        autoSizeColumns(excelSheet);
        int sheet = 0;
        // Study Event Summary Looper
        for (int eventCount = 0; eventCount < events.size(); eventCount++) {
            row = 0;
            sheet++;
            StudyEventBean event = (StudyEventBean) events.get(eventCount);
            workbook.createSheet(event.getStudyEventDefinition().getName().replace("/", ".") + "_" + event.getSampleOrdinal(), sheet);
            excelSheet = workbook.getSheet(sheet);
            Label label = null;
            // Header
            label = new Label(0, row, ResourceBundleProvider.getResWord("name"), cellFormat);
            excelSheet.addCell(label);
            label = new Label(1, row, event.getStudyEventDefinition().getName(), cellFormat);
            excelSheet.addCell(label);
            row++;
            label = new Label(0, row, "Location");
            excelSheet.addCell(label);
            label = new Label(1, row, event.getLocation());
            excelSheet.addCell(label);
            row++;
            label = new Label(0, row, "Start Date");
            excelSheet.addCell(label);
            if (event.getStartTimeFlag()) {
                label = new Label(1, row, dateTimeFormat(event.getDateStarted()));
            } else {
                label = new Label(1, row, dateFormat(event.getDateStarted()));
            }
            excelSheet.addCell(label);
            row++;
            label = new Label(0, row, "Status");
            excelSheet.addCell(label);
            label = new Label(1, row, event.getSubjectEventStatus().getName());
            excelSheet.addCell(label);
            row++;
            label = new Label(0, row, ResourceBundleProvider.getResWord("occurrence_number"));
            excelSheet.addCell(label);
            label = new Label(1, row, Integer.toString(event.getSampleOrdinal()));
            excelSheet.addCell(label);
            row++;
            row++;
            // End Header
            // Audit for Deleted Event CRFs
            excelRow = new String[] { "name", "version", "deleted_by", "delete_date" };
            for (int i = 0; i < excelRow.length; i++) {
                label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                excelSheet.addCell(label);
            }
            row++;
            for (int j = 0; j < allDeletedEventCRFs.size(); j++) {
                DeletedEventCRFBean deletedEventCRF = (DeletedEventCRFBean) allDeletedEventCRFs.get(j);
                if (deletedEventCRF.getStudyEventId() == event.getId()) {
                    excelRow = new String[] { deletedEventCRF.getCrfName(), deletedEventCRF.getFormLayout(), deletedEventCRF.getDeletedBy(), dateFormat(deletedEventCRF.getDeletedDate()) };
                    for (int i = 0; i < excelRow.length; i++) {
                        label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                        excelSheet.addCell(label);
                    }
                    row++;
                }
            }
            row++;
            row++;
            // Audit Events for Study Event
            excelRow = new String[] { "audit_event", "date_time_of_server", "user", "value_type", "old", "new" };
            for (int i = 0; i < excelRow.length; i++) {
                label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                excelSheet.addCell(label);
            }
            row++;
            for (int j = 0; j < studyEventAudits.size(); j++) {
                AuditBean studyEvent = (AuditBean) studyEventAudits.get(j);
                if (studyEvent.getEntityId() == event.getId()) {
                    String getOld = studyEvent.getOldValue();
                    String oldValue = "";
                    if (getOld.equals("0"))
                        oldValue = "invalid";
                    else if (getOld.equals("1"))
                        oldValue = "scheduled";
                    else if (getOld.equals("2"))
                        oldValue = "not_scheduled";
                    else if (getOld.equals("3"))
                        oldValue = "data_entry_started";
                    else if (getOld.equals("4"))
                        oldValue = "completed";
                    else if (getOld.equals("5"))
                        oldValue = "stopped";
                    else if (getOld.equals("6"))
                        oldValue = "skipped";
                    else if (getOld.equals("7"))
                        oldValue = "locked";
                    else if (getOld.equals("8"))
                        oldValue = "signed";
                    else
                        oldValue = studyEvent.getOldValue();
                    String getNew = studyEvent.getNewValue();
                    String newValue = "";
                    if (getNew.equals("0"))
                        newValue = "invalid";
                    else if (getNew.equals("1"))
                        newValue = "scheduled";
                    else if (getNew.equals("2"))
                        newValue = "not_scheduled";
                    else if (getNew.equals("3"))
                        newValue = "data_entry_started";
                    else if (getNew.equals("4"))
                        newValue = "completed";
                    else if (getNew.equals("5"))
                        newValue = "removed";
                    else if (getNew.equals("6"))
                        newValue = "skipped";
                    else if (getNew.equals("7"))
                        newValue = "locked";
                    else if (getNew.equals("8"))
                        newValue = "signed";
                    else if (getNew.equals("9"))
                        newValue = "forzen";
                    else
                        newValue = studyEvent.getNewValue();
                    excelRow = new String[] { studyEvent.getAuditEventTypeName(), dateTimeFormat(studyEvent.getAuditDate()), studyEvent.getUserName(), studyEvent.getEntityName() + "(" + studyEvent.getOrdinal() + ")", oldValue, newValue };
                    for (int i = 0; i < excelRow.length; i++) {
                        label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                        excelSheet.addCell(label);
                    }
                    row++;
                }
            }
            row++;
            row++;
            // Event CRFs Audit Events
            for (int j = 0; j < allEventCRFs.size(); j++) {
                AuditBean auditBean = (AuditBean) allEventCRFs.get(j);
                if (auditBean.getStudyEventId() == event.getId()) {
                    // Audit Events for Study Event
                    excelRow = new String[] { "name", "version", "date_interviewed", "interviewer_name", "owner" };
                    for (int i = 0; i < excelRow.length; i++) {
                        label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                        excelSheet.addCell(label);
                    }
                    row++;
                    excelRow = new String[] { auditBean.getCrfName(), auditBean.getCrfVersionName(), dateFormat(auditBean.getDateInterviewed()), auditBean.getInterviewerName(), auditBean.getUserName() };
                    for (int i = 0; i < excelRow.length; i++) {
                        label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                        excelSheet.addCell(label);
                    }
                    row++;
                    row++;
                    excelRow = new String[] { "audit_event", "date_time_of_server", "user", "value_type", "old", "new" };
                    for (int i = 0; i < excelRow.length; i++) {
                        label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                        excelSheet.addCell(label);
                    }
                    row++;
                    row++;
                    for (int k = 0; k < allEventCRFItems.size(); k++) {
                        row--;
                        AuditBean eventCrfAudit = (AuditBean) allEventCRFItems.get(k);
                        if (eventCrfAudit.getStudyEventId() == event.getId() && eventCrfAudit.getEventCrfVersionId() == auditBean.getEventCrfVersionId()) {
                            String oldValue = "";
                            String newValue = "";
                            if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("Status")) {
                                String getOld = eventCrfAudit.getOldValue();
                                if (getOld.equals("0"))
                                    oldValue = "invalid";
                                else if (getOld.equals("1"))
                                    oldValue = "available";
                                else if (getOld.equals("2"))
                                    oldValue = "unavailable";
                                else if (getOld.equals("3"))
                                    oldValue = "private";
                                else if (getOld.equals("4"))
                                    oldValue = "pending";
                                else if (getOld.equals("5"))
                                    oldValue = "removed";
                                else if (getOld.equals("6"))
                                    oldValue = "locked";
                                else if (getOld.equals("7"))
                                    oldValue = "auto-removed";
                                else {
                                    oldValue = getOld;
                                }
                            } else if (eventCrfAudit.getAuditEventTypeId() == 32) {
                                String getOld = eventCrfAudit.getOldValue();
                                if (getOld.equals("0"))
                                    oldValue = "FALSE";
                                else if (getOld.equals("1"))
                                    oldValue = "TRUE";
                                else {
                                    oldValue = getOld;
                                }
                            } else {
                                oldValue = eventCrfAudit.getOldValue();
                            }
                            if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("Status")) {
                                String getNew = eventCrfAudit.getNewValue();
                                if (getNew.equals("0"))
                                    newValue = "invalid";
                                else if (getNew.equals("1"))
                                    newValue = "available";
                                else if (getNew.equals("2"))
                                    newValue = "unavailable";
                                else if (getNew.equals("3"))
                                    newValue = "private";
                                else if (getNew.equals("4"))
                                    newValue = "pending";
                                else if (getNew.equals("5"))
                                    newValue = "removed";
                                else if (getNew.equals("6"))
                                    newValue = "locked";
                                else if (getNew.equals("7"))
                                    newValue = "auto-removed";
                                else {
                                    newValue = getNew;
                                }
                            } else if (eventCrfAudit.getAuditEventTypeId() == 32) {
                                String getNew = eventCrfAudit.getNewValue();
                                if (getNew.equals("0"))
                                    newValue = "FALSE";
                                else if (getNew.equals("1"))
                                    newValue = "TRUE";
                                else {
                                    newValue = getNew;
                                }
                            } else {
                                newValue = eventCrfAudit.getNewValue();
                            }
                            String ordinal = "";
                            if (eventCrfAudit.getOrdinal() != 0) {
                                ordinal = "(" + eventCrfAudit.getOrdinal() + ")";
                            } else if (eventCrfAudit.getOrdinal() == 0 && eventCrfAudit.getItemDataRepeatKey() != 0) {
                                ordinal = "(" + eventCrfAudit.getItemDataRepeatKey() + ")";
                            }
                            excelRow = new String[] { eventCrfAudit.getAuditEventTypeName(), dateTimeFormat(eventCrfAudit.getAuditDate()), eventCrfAudit.getUserName(), eventCrfAudit.getEntityName() + ordinal, oldValue, newValue };
                            for (int i = 0; i < excelRow.length; i++) {
                                label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
                                excelSheet.addCell(label);
                            }
                            row++;
                            row++;
                        }
                        row++;
                    }
                    row++;
                }
                autoSizeColumns(excelSheet);
            }
        }
        workbook.write();
        workbook.close();
        session.setAttribute("subject", null);
        session.setAttribute("study", null);
        session.setAttribute("studySub", null);
        session.setAttribute("studyEventAudits", null);
        session.setAttribute("studySubjectAudits", null);
        session.setAttribute("events", null);
        session.setAttribute("eventCRFAudits", null);
        session.setAttribute("allDeletedEventCRFs", null);
    } catch (Exception e) {
        throw e;
    } finally {
    // proposed move session attributes here
    }
}
Also used : Locale(java.util.Locale) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) DeletedEventCRFBean(org.akaza.openclinica.bean.admin.DeletedEventCRFBean) ArrayList(java.util.ArrayList) Label(jxl.write.Label) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) AuditDAO(org.akaza.openclinica.dao.admin.AuditDAO) DeletedEventCRFBean(org.akaza.openclinica.bean.admin.DeletedEventCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) 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) WritableFont(jxl.write.WritableFont) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) WorkbookSettings(jxl.WorkbookSettings) WritableSheet(jxl.write.WritableSheet) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) AuditBean(org.akaza.openclinica.bean.admin.AuditBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) WritableCellFormat(jxl.write.WritableCellFormat) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) WritableWorkbook(jxl.write.WritableWorkbook) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) Collection(java.util.Collection)

Example 44 with StudySubjectBean

use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.

the class ListStudySubjectServlet method processRequest.

// >>
// < ResourceBundleresword;
@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    locale = LocaleResolver.getLocale(request);
    // < resword =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.words",locale);
    // BWP 3098 << close the info side panel and show icons
    request.setAttribute("closeInfoShowIcons", true);
    // >>
    // BWP 3195, 3330 : designed to address pagination issues
    String pageNumber = fp.getString(SUBJECT_PAGE_NUMBER);
    StringBuilder paginatingQuery = new StringBuilder("");
    String filterKeyword = fp.getString(FILTER_KEYWORD);
    String tmpSearch = fp.getString(SEARCH_SUBMITTED);
    boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword) && !"+".equalsIgnoreCase(filterKeyword);
    if (pageNumber != null && !"".equalsIgnoreCase(pageNumber)) {
        int tempNum = 0;
        try {
            tempNum = Integer.parseInt(pageNumber);
        } catch (NumberFormatException nfe) {
        // tempNum is already initialized to 0
        }
        if (tempNum > 0) {
            paginatingQuery = new StringBuilder(SUBJECT_PAGE_NUMBER).append("=").append(pageNumber);
            paginatingQuery.append("&ebl_paginated=1");
        }
    }
    // URL encode the search keyword, since it will be a parameter in the
    // URL
    String filterKeywordURLEncode = java.net.URLEncoder.encode(filterKeyword, "UTF-8");
    if (searchSubmitted) {
        paginatingQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
        paginatingQuery.append("&").append(FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
    }
    request.setAttribute(PAGINATING_QUERY, paginatingQuery.toString());
    StudyDAO stdao = new StudyDAO(sm.getDataSource());
    StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    // YW << update study parameters of current study.
    // "collectDob" and "genderRequired" are set as the same as the parent
    // study
    // tbh, also add the params "subjectPersonIdRequired",
    // "subjectIdGeneration", "subjectIdPrefixSuffix"
    int parentStudyId = currentStudy.getParentStudyId();
    ArrayList studyGroupClasses = new ArrayList();
    ArrayList allDefs = new ArrayList();
    // tbh
    if (parentStudyId > 0) {
        StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
        studyGroupClasses = sgcdao.findAllActiveByStudy(parentStudy);
        allDefs = seddao.findAllActiveByStudy(parentStudy);
    } else {
        parentStudyId = currentStudy.getId();
        studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
        allDefs = seddao.findAllActiveByStudy(currentStudy);
    }
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "collectDob");
    currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "genderRequired");
    currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectPersonIdRequired");
    currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
    currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdPrefixSuffix");
    currentStudy.getStudyParameterConfig().setSubjectIdPrefixSuffix(parentSPV.getValue());
    // for all the study groups for each group class
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        ArrayList groups = sgdao.findAllByGroupClass(sgc);
        sgc.setStudyGroups(groups);
    }
    request.setAttribute("studyGroupClasses", studyGroupClasses);
    // information for the event tabs
    session.setAttribute("allDefsArray", allDefs);
    session.setAttribute("allDefsNumber", new Integer(allDefs.size()));
    session.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
    // find all the subjects in current study
    ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
    ArrayList<DisplayStudySubjectBean> displayStudySubs = new ArrayList<DisplayStudySubjectBean>();
    // BEGIN LOOPING THROUGH SUBJECTS
    for (int i = 0; i < subjects.size(); i++) {
        StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
        ArrayList groups = (ArrayList) sgmdao.findAllByStudySubject(studySub.getId());
        ArrayList subGClasses = new ArrayList();
        for (int j = 0; j < studyGroupClasses.size(); j++) {
            StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(j);
            boolean hasClass = false;
            for (int k = 0; k < groups.size(); k++) {
                SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groups.get(k);
                if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
                    subGClasses.add(sgmb);
                    hasClass = true;
                    break;
                }
            }
            if (!hasClass) {
                subGClasses.add(new SubjectGroupMapBean());
            }
        }
        ArrayList subEvents = new ArrayList();
        // find all events order by definition ordinal
        ArrayList events = sedao.findAllByStudySubject(studySub);
        for (int j = 0; j < allDefs.size(); j++) {
            StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(j);
            boolean hasDef = false;
            // logger.info("...set blank to "+blankid);
            for (int k = 0; k < events.size(); k++) {
                StudyEventBean se = (StudyEventBean) events.get(k);
                if (se.getStudyEventDefinitionId() == sed.getId()) {
                    se.setStudyEventDefinition(sed);
                    // logger.info(">>>found assigned id "+sed.getId()+" sed
                    // name: "+sed.getName()+" "+se.getId());
                    subEvents.add(se);
                    hasDef = true;
                }
            }
            if (!hasDef) {
                StudyEventBean blank = new StudyEventBean();
                blank.setSubjectEventStatus(SubjectEventStatus.NOT_SCHEDULED);
                blank.setStudyEventDefinitionId(sed.getId());
                // how can we set the following:
                // logger.info("...resetting blank id: "+blank.getId()+" to
                // "+blankid);
                // blank.setId(blankid);
                blank.setStudyEventDefinition(sed);
                // logger.info(">>>blank id: "+blank.getId());
                // logger.info(">>>found unassigned id "+sed.getId()+" sed
                // name: "+sed.getName()+" ");
                subEvents.add(blank);
            }
        }
        // logger.info("subevents size after all adds: "+subEvents.size());
        // reorganize the events and find the repeating ones
        // subEvents:[aa bbb cc d ee]
        // finalEvents:[a(2) b(3) c(2) d e(2)]
        int prevDefId = 0;
        int currDefId = 0;
        ArrayList finalEvents = new ArrayList();
        int repeatingNum = 1;
        int count = 0;
        StudyEventBean event = new StudyEventBean();
        // begin looping through subject events
        for (int j = 0; j < subEvents.size(); j++) {
            StudyEventBean se = (StudyEventBean) subEvents.get(j);
            currDefId = se.getStudyEventDefinitionId();
            if (currDefId != prevDefId) {
                // find a new event
                if (repeatingNum > 1) {
                    event.setRepeatingNum(repeatingNum);
                    repeatingNum = 1;
                }
                // add current event to final
                finalEvents.add(se);
                event = se;
                count++;
            // logger.info("event id? "+event.getId());
            } else {
                // repeating event
                repeatingNum++;
                event.getRepeatEvents().add(se);
                // event.getRepeatEvents().size());
                if (j == subEvents.size() - 1) {
                    event.setRepeatingNum(repeatingNum);
                    repeatingNum = 1;
                }
            }
            prevDefId = currDefId;
        }
        // end looping through subject events
        DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
        // logger.info("final events size: "+finalEvents.size());
        dssb.setStudyEvents(finalEvents);
        dssb.setStudySubject(studySub);
        dssb.setStudyGroups(subGClasses);
        displayStudySubs.add(dssb);
    }
    // END LOOPING THROUGH SUBJECTS
    // Set a subject property to determine whether to show a signed-type
    // icon (electronic signature)
    // in the JSP view or not
    // Get all event crfs by studyevent id; then use
    // EventDefinitionCRFDAO.isRequired to
    // determine whether any uncompleted CRFs are required.
    boolean isRequiredUncomplete = false;
    for (DisplayStudySubjectBean subject : displayStudySubs) {
        for (Iterator it = subject.getStudyEvents().iterator(); it.hasNext(); ) {
            StudyEventBean event = (StudyEventBean) it.next();
            if (event.getSubjectEventStatus() != null && event.getSubjectEventStatus().getId() == 3) {
                // disallow the subject from signing any studies
                subject.setStudySignable(false);
                break;
            } else {
                // determine whether the subject has any required,
                // uncompleted event CRFs
                isRequiredUncomplete = eventHasRequiredUncompleteCRFs(event);
                if (isRequiredUncomplete) {
                    subject.setStudySignable(false);
                    break;
                }
            }
        }
    }
    fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudySubjectRow.generateRowsFromBeans(displayStudySubs);
    ArrayList columnArray = new ArrayList();
    columnArray.add(resword.getString("study_subject_ID"));
    columnArray.add(resword.getString("subject_status"));
    columnArray.add(resword.getString("OID"));
    columnArray.add(resword.getString("gender"));
    // new
    columnArray.add(resword.getString("secondary_ID"));
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        columnArray.add(sgc.getName());
    }
    for (int i = 0; i < allDefs.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(i);
        columnArray.add(sed.getName());
    }
    columnArray.add(resword.getString("actions"));
    String[] columns = new String[columnArray.size()];
    columnArray.toArray(columns);
    // String[] columns = {"ID", "Subject Status", "Gender", "Enrollment
    // Date",
    // "Study Events", "Actions" };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.setQuery(getBaseURL(), new HashMap());
    table.hideColumnLink(columnArray.size() - 1);
    // table.addLink("Enroll a new subject",
    // "javascript:leftnavExpand('addSubjectRowExpress');");
    table.setRows(allStudyRows);
    if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
        table.setKeywordFilter(filterKeyword);
    }
    table.computeDisplay();
    request.setAttribute("table", table);
    // request.setAttribute("subjects", subjects);
    String idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
    // set up auto study subject id
    if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
        //Shaoyu Su
        //int nextLabel = ssdao.findTheGreatestLabel() + 1;
        //request.setAttribute("label", new Integer(nextLabel).toString());
        request.setAttribute("label", resword.getString("id_generated_Save_Add"));
    }
    FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
    forwardPage(getJSP());
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) 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) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) Iterator(java.util.Iterator) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO)

Example 45 with StudySubjectBean

use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.

the class RemoveSiteServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    String idString = request.getParameter("id");
    logger.info("site id:" + idString);
    int siteId = Integer.valueOf(idString.trim()).intValue();
    StudyBean study = (StudyBean) sdao.findByPK(siteId);
    if (currentStudy.getId() != study.getParentStudyId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    // find all user and roles
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userRoles = udao.findAllByStudyId(siteId);
    // find all subjects
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList subjects = ssdao.findAllByStudy(study);
    // find all events
    StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList definitions = sefdao.findAllByStudy(study);
    String action = request.getParameter("action");
    if (StringUtil.isBlank(idString)) {
        addPageMessage(respage.getString("please_choose_a_site_to_remove"));
        forwardPage(Page.SITE_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("siteToRemove", study);
            request.setAttribute("userRolesToRemove", userRoles);
            request.setAttribute("subjectsToRemove", subjects);
            forwardPage(Page.REMOVE_SITE);
        } else {
            logger.info("submit to remove the site");
            // 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 users and roles
            for (int i = 0; i < userRoles.size(); i++) {
                StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
                if (!role.getStatus().equals(Status.DELETED)) {
                    role.setStatus(Status.AUTO_DELETED);
                    role.setUpdater(ub);
                    role.setUpdatedDate(new Date());
                    // YW << So study_user_role table status_id field can be
                    // updated
                    udao.updateStudyUserRole(role, role.getUserName());
                }
            // YW 06-18-2007 >>
            }
            // YW << bug fix that current active study has been deleted
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.DELETED);
                // currentRole.setRole(Role.INVALID);
                currentRole.setStatus(Status.DELETED);
            }
            // remove all subjects
            for (int i = 0; i < subjects.size(); i++) {
                StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
            }
            // remove all study_group
            StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
            SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
            ArrayList groups = sgdao.findAllByStudy(study);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupBean group = (StudyGroupBean) groups.get(i);
                if (!group.getStatus().equals(Status.DELETED)) {
                    group.setStatus(Status.AUTO_DELETED);
                    group.setUpdater(ub);
                    group.setUpdatedDate(new Date());
                    sgdao.update(group);
                    // all subject_group_map
                    ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(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);
                        }
                    }
                }
            }
            // remove all events
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            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);
                    ArrayList events = sedao.findAllByStudySubject(subject);
                    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 subjects
            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(respage.getString("this_site_has_been_removed_succesfully"));
            String fromListSite = (String) session.getAttribute("fromListSite");
            if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
                session.removeAttribute("fromListSite");
                forwardPage(Page.SITE_LIST_SERVLET);
            } else {
                session.removeAttribute("fromListSite");
                if (currentRole.getRole().equals(Role.ADMIN)) {
                    forwardPage(Page.STUDY_LIST_SERVLET);
                } else {
                    forwardPage(Page.SITE_LIST_SERVLET);
                }
            }
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) 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) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) 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)

Aggregations

StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)155 ArrayList (java.util.ArrayList)102 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)86 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)71 HashMap (java.util.HashMap)66 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)66 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)57 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)52 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)52 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)49 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)43 Date (java.util.Date)42 Iterator (java.util.Iterator)38 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)35 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)29 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)26 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)26 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)23