Search in sources :

Example 11 with EventDefinitionCRFDAO

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

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

the class ViewStudyServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt("id");
    if (studyId == 0) {
        addPageMessage(respage.getString("please_choose_a_study_to_view"));
        forwardPage(Page.STUDY_LIST_SERVLET);
    } else {
        if (currentStudy.getId() != studyId && currentStudy.getParentStudyId() != studyId) {
            checkRoleByUserAndStudy(ub, studyId, 0);
        }
        String viewFullRecords = fp.getString("viewFull");
        StudyBean study = (StudyBean) sdao.findByPK(studyId);
        StudyConfigService scs = new StudyConfigService(sm.getDataSource());
        study = scs.setParametersForStudy(study);
        StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
        String randomizationStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "randomization").getValue();
        String participantStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "participantPortal").getValue();
        if (participantStatusInOC == "")
            participantStatusInOC = "disabled";
        if (randomizationStatusInOC == "")
            randomizationStatusInOC = "disabled";
        RandomizationRegistrar randomizationRegistrar = new RandomizationRegistrar();
        SeRandomizationDTO seRandomizationDTO = randomizationRegistrar.getCachedRandomizationDTOObject(study.getOid(), false);
        if (seRandomizationDTO != null && seRandomizationDTO.getStatus().equalsIgnoreCase("ACTIVE") && randomizationStatusInOC.equalsIgnoreCase("enabled")) {
            study.getStudyParameterConfig().setRandomization("enabled");
        } else {
            study.getStudyParameterConfig().setRandomization("disabled");
        }
        ;
        ParticipantPortalRegistrar participantPortalRegistrar = new ParticipantPortalRegistrar();
        String pStatus = participantPortalRegistrar.getCachedRegistrationStatus(study.getOid(), session);
        if (participantPortalRegistrar != null && pStatus.equalsIgnoreCase("ACTIVE") && participantStatusInOC.equalsIgnoreCase("enabled")) {
            study.getStudyParameterConfig().setParticipantPortal("enabled");
        } else {
            study.getStudyParameterConfig().setParticipantPortal("disabled");
        }
        ;
        request.setAttribute("studyToView", study);
        if ("yes".equalsIgnoreCase(viewFullRecords)) {
            UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
            StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
            ArrayList sites = new ArrayList();
            ArrayList userRoles = new ArrayList();
            ArrayList subjects = new ArrayList();
            if (this.currentStudy.getParentStudyId() > 0 && this.currentRole.getRole().getId() > 3) {
                sites.add(this.currentStudy);
                userRoles = udao.findAllUsersByStudy(currentStudy.getId());
                subjects = ssdao.findAllByStudy(currentStudy);
            } else {
                sites = (ArrayList) sdao.findAllByParent(studyId);
                userRoles = udao.findAllUsersByStudy(studyId);
                subjects = ssdao.findAllByStudy(study);
            }
            // find all subjects in the study, include ones in sites
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            // StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            //                ArrayList displayStudySubs = new ArrayList();
            //                for (int i = 0; i < subjects.size(); i++) {
            //                    StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
            //                    // find all events
            //                    ArrayList events = sedao.findAllByStudySubject(studySub);
            //
            //                    // find all eventcrfs for each event
            //                    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            //
            //                    DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
            //                    dssb.setStudyEvents(events);
            //                    dssb.setStudySubject(studySub);
            //                    displayStudySubs.add(dssb);
            //                }
            // find all events in the study, include ones in sites
            ArrayList definitions = seddao.findAllByStudy(study);
            for (int i = 0; i < definitions.size(); i++) {
                StudyEventDefinitionBean def = (StudyEventDefinitionBean) definitions.get(i);
                ArrayList crfs = (ArrayList) edcdao.findAllActiveParentsByEventDefinitionId(def.getId());
                def.setCrfNum(crfs.size());
            }
            String moduleManager = CoreResources.getField("moduleManager");
            request.setAttribute("moduleManager", moduleManager);
            String portalURL = CoreResources.getField("portalURL");
            request.setAttribute("portalURL", portalURL);
            request.setAttribute("config", study);
            request.setAttribute("sitesToView", sites);
            request.setAttribute("siteNum", sites.size() + "");
            request.setAttribute("userRolesToView", userRoles);
            request.setAttribute("userNum", userRoles.size() + "");
            // request.setAttribute("subjectsToView", displayStudySubs);
            // request.setAttribute("subjectNum", subjects.size() + "");
            request.setAttribute("definitionsToView", definitions);
            request.setAttribute("defNum", definitions.size() + "");
            forwardPage(Page.VIEW_FULL_STUDY);
        } else {
            forwardPage(Page.VIEW_STUDY);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyConfigService(org.akaza.openclinica.dao.service.StudyConfigService) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) RandomizationRegistrar(org.akaza.openclinica.service.pmanage.RandomizationRegistrar) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) SeRandomizationDTO(org.akaza.openclinica.service.pmanage.SeRandomizationDTO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 13 with EventDefinitionCRFDAO

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

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

the class InitUpdateEventDefinitionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
    String idString = request.getParameter("id");
    logger.info("definition id: " + idString);
    if (StringUtil.isBlank(idString)) {
        addPageMessage(respage.getString("please_choose_a_definition_to_edit"));
        forwardPage(Page.LIST_DEFINITION_SERVLET);
    } else {
        // definition id
        int defId = Integer.valueOf(idString.trim()).intValue();
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
        StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
        String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
        if (participateFormStatus.equals("enabled"))
            baseUrl();
        request.setAttribute("participateFormStatus", participateFormStatus);
        if (currentStudy.getId() != sed.getStudyId()) {
            addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
            forwardPage(Page.MENU_SERVLET);
            return;
        }
        EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
        ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllParentsByDefinition(defId);
        FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        ArrayList newEventDefinitionCRFs = new ArrayList();
        for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
            EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
            ArrayList versions = (ArrayList) fldao.findAllActiveByCRF(edc.getCrfId());
            edc.setVersions(versions);
            CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
            edc.setCrfName(crf.getName());
            edc.setCrf(crf);
            edc.setParticipantForm(edc.isParticipantForm());
            // TO DO: use a better way on JSP page,eg.function tag
            edc.setNullFlags(processNullValues(edc));
            FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(edc.getDefaultVersionId());
            edc.setDefaultVersionName(formLayout.getName());
            String crfPath = sed.getOid() + "." + edc.getCrf().getOid();
            edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
            newEventDefinitionCRFs.add(edc);
        }
        session.setAttribute("definition", sed);
        session.setAttribute("eventDefinitionCRFs", newEventDefinitionCRFs);
        // changed above to new list because static, in-place updating is
        // updating all EDCs, tbh 102007
        ArrayList<String> sdvOptions = new ArrayList<String>();
        sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
        request.setAttribute("sdvOptions", sdvOptions);
        forwardPage(Page.UPDATE_EVENT_DEFINITION1);
    }
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 15 with EventDefinitionCRFDAO

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

the class ListStudySubjectServlet method getDisplayStudyEventsForStudySubject.

public static DisplayStudyEventBean getDisplayStudyEventsForStudySubject(StudySubjectBean studySub, StudyEventBean event, DataSource ds, UserAccountBean ub, StudyUserRoleBean currentRole, StudyBean study) {
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
    StudyEventDAO sedao = new StudyEventDAO(ds);
    EventCRFDAO ecdao = new EventCRFDAO(ds);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
    event.setStudyEventDefinition(sed);
    // find all active crfs in the definition
    ArrayList eventDefinitionCRFs = edcdao.findAllActiveByEventDefinitionId(sed.getId());
    ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
    // construct info needed on view study event page
    DisplayStudyEventBean de = new DisplayStudyEventBean();
    de.setStudyEvent(event);
    de.setDisplayEventCRFs(ViewStudySubjectServlet.getDisplayEventCRFs(ds, eventCRFs, eventDefinitionCRFs, ub, currentRole, event.getSubjectEventStatus(), study));
    ArrayList al = ViewStudySubjectServlet.getUncompletedCRFs(ds, eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus());
    // ViewStudySubjectServlet.populateUncompletedCRFsWithCRFAndVersions(ds,
    // al);
    de.setUncompletedCRFs(al);
    return de;
}
Also used : DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)84 ArrayList (java.util.ArrayList)72 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)58 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)53 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)51 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)45 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)41 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)41 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)39 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)39 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)36 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)35 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)30 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)28 Date (java.util.Date)27 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)27 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26