Search in sources :

Example 36 with DiscrepancyNoteBean

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

the class DeleteEventCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int studySubId = fp.getInt(STUDY_SUB_ID, true);
    int eventCRFId = fp.getInt(EVENT_CRF_ID);
    String action = request.getParameter("action");
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    if (eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_an_event_CRF_to_delete"));
        request.setAttribute("id", new Integer(studySubId).toString());
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    } else {
        EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        request.setAttribute("studySub", studySub);
        // construct info needed on view event crf page
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        int crfVersionId = eventCRF.getCRFVersionId();
        CRFBean cb = cdao.findByVersionId(crfVersionId);
        eventCRF.setCrf(cb);
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
        eventCRF.setCrfVersion(cvb);
        // then get the definition so we can call
        // DisplayEventCRFBean.setFlags
        int studyEventId = eventCRF.getStudyEventId();
        StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
        int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
        event.setStudyEventDefinition(sed);
        request.setAttribute("event", event);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
        EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
        DisplayEventCRFBean dec = new DisplayEventCRFBean();
        dec.setEventCRF(eventCRF);
        dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
        // find all item data
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
        ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId());
        request.setAttribute("items", itemData);
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("displayEventCRF", dec);
            forwardPage(Page.DELETE_EVENT_CRF);
        } else {
            logger.info("submit to delete the event CRF from event");
            // OC-6303 Deleting Event CRF resets Show / Hide logic
            // delete records from DynamicItemForm and DynamicItemGroup
            // getDynamicsItemFormMetadataDao().delete(eventCRFId);
            // getDynamicsItemGroupMetadataDao().delete(eventCRFId);
            eventCRF.setOldStatus(eventCRF.getStatus());
            eventCRF.setStatus(Status.RESET);
            eventCRF.setUpdater(ub);
            ecdao.update(eventCRF);
            for (ItemDataBean itemdata : itemData) {
                // OC-6343 Rule behaviour must be reset if an Event CRF is deleted
                // delete the records from ruleActionRunLogDao
                List<RuleActionRunLogBean> ruleActionRunLog = getRuleActionRunLogDao().findAllItemData(itemdata.getId());
                if (ruleActionRunLog.size() != 0) {
                    getRuleActionRunLogDao().delete(itemdata.getId());
                }
                // OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted
                // parentDiscrepancyNoteList is the list of the parent DNs records only
                ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId());
                for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) {
                    if (parentDiscrepancyNote.getResolutionStatusId() != 4) {
                        // if the DN's resolution status is
                        // not set to Closed
                        String description = resword.getString("dn_auto-closed_description");
                        String detailedNotes = resword.getString("dn_auto_closed_detailed_notes");
                        // create new DN record , new DN Map record , also update the parent record
                        createDiscrepancyNoteBean(description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote);
                    }
                }
                iddao = new ItemDataDAO(sm.getDataSource());
                ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
                ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId());
                ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId);
                // Updating Dn_item_data_map actovated column into false for the existing DNs
                ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId());
                if (dnBeans.size() != 0) {
                    DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean();
                    dnBean.setEntityId(itemdata.getId());
                    dnBean.setActivated(false);
                    getDnDao().updateDnMapActivation(dnBean);
                }
                // Default Values are not addressed
                itemdata.setValue("");
                itemdata.setOldStatus(itemdata.getStatus());
                itemdata.setOwner(ub);
                itemdata.setStatus(Status.AVAILABLE);
                itemdata.setUpdater(ub);
                iddao.updateUser(itemdata);
                iddao.update(itemdata);
            }
            // OC-6291 event_crf status change
            eventCRF.setOldStatus(eventCRF.getStatus());
            eventCRF.setStatus(Status.AVAILABLE);
            eventCRF.setUpdater(ub);
            ecdao.update(eventCRF);
            if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) {
                event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
                event.setUpdater(ub);
                sedao = new StudyEventDAO(sm.getDataSource());
                sedao.update(event);
            }
            String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont");
            addPageMessage(emailBody);
            // sendEmail(emailBody);
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
    }
}
Also used : StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 37 with DiscrepancyNoteBean

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

the class DiscrepancyNoteOutputServlet method processRequest.

/* Handle the HTTP Get or Post request. */
@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // the fileName contains any subject id and study unique protocol id;
    // see: chooseDownloadFormat.jsp
    String fileName = request.getParameter("fileName");
    // the filename is formulated correctly
    if (fileName != null) {
        fileName = fileName.replaceAll(" ", "_");
    }
    fileName = fileName == null ? "" : fileName;
    // the format will be either csv (comma separated values) or pdf (portable document format)
    String format = request.getParameter("fmt");
    String studyIdentifier = request.getParameter("studyIdentifier");
    // Determine whether to limit the displayed DN's to a certain resolutionStatus
    // CHANGED TO LIST OF RESOLUTION STATUS IDS
    /*int resolutionStatus = 0;
        try {
            resolutionStatus = Integer.parseInt(request.getParameter("resolutionStatus"));
        } catch(NumberFormatException nfe){
            //Show all DN's
            resolutionStatus=-1;
        }*/
    // possibly for a later implementation: int definitionId = fp.getInt("defId");
    //here subjectId actually is study_subject_id !!!
    int subjectId = fp.getInt("subjectId");
    int discNoteType = fp.getInt("discNoteType");
    DownloadDiscrepancyNote downLoader = new DownloadDiscrepancyNote();
    if ("csv".equalsIgnoreCase(format)) {
        fileName = fileName + ".csv";
        response.setContentType(DownloadDiscrepancyNote.CSV);
    } else {
        response.setContentType(DownloadDiscrepancyNote.PDF);
        fileName = fileName + ".pdf";
    }
    response.addHeader(CONTENT_DISPOSITION_HEADER, CONTENT_DISPOSITION_VALUE + fileName);
    // Are we downloading a List of discrepancy notes or just one?
    // Not needed now: boolean isList = ("y".equalsIgnoreCase(isAList));
    StudyBean studyBean = (StudyBean) session.getAttribute("study");
    //        Set<Integer> resolutionStatusIds = (HashSet) session.getAttribute("resolutionStatus");
    // It will also change any resolution status IDs among parents of children that have a different
    // id value (last boolean parameter; 'true' to perform the latter task)
    // In this case we want to include all the discrepancy notes, despite the res status or
    // type filtering, because we don't want to filter out parents, thus leaving out a child note
    // that might match the desired res status
    ListNotesFilter listNotesFilter = new ListNotesFilter();
    ViewNotesService viewNotesService = (ViewNotesService) WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getBean("viewNotesService");
    ViewNotesFilterCriteria filter = ViewNotesFilterCriteria.buildFilterCriteria(getFilters(request), getDateFormat(), discrepancyNoteTypesDecoder, resolutionStatusDecoder);
    List<DiscrepancyNoteBean> notes = viewNotesService.listNotes(currentStudy, filter, ViewNotesSortCriteria.buildFilterCriteria(getSortOrder(request)));
    ArrayList<DiscrepancyNoteBean> allDiscNotes = notes instanceof ArrayList ? (ArrayList<DiscrepancyNoteBean>) notes : new ArrayList<DiscrepancyNoteBean>(notes);
    allDiscNotes = populateRowsWithAttachedData(allDiscNotes);
    // Now we have to package all the discrepancy notes in DiscrepancyNoteThread objects
    // Do the filtering for type or status here
    DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
    Set<Integer> resolutionStatusIds = emptySet();
    List<DiscrepancyNoteThread> discrepancyNoteThreads = discNoteUtil.createThreads(allDiscNotes, sm.getDataSource(), studyBean);
    if ("csv".equalsIgnoreCase(format)) {
        /*response.setContentLength(
              downLoader.getListContentLength(allDiscNotes,DownloadDiscrepancyNote.CSV));*/
        //3014: this has been changed to only show the parent of the thread; then changed back again!
        int contentLen = downLoader.getThreadListContentLength(discrepancyNoteThreads);
        response.setContentLength(contentLen);
        /*downLoader.downLoadDiscBeans(allDiscNotes,
              DownloadDiscrepancyNote.CSV,response.getOutputStream(), null);*/
        downLoader.downLoadThreadedDiscBeans(discrepancyNoteThreads, DownloadDiscrepancyNote.CSV, response, null);
    } else {
        response.setHeader("Pragma", "public");
        /*downLoader.downLoadDiscBeans(allDiscNotes,
              DownloadDiscrepancyNote.PDF,
              response.getOutputStream(), studyIdentifier);*/
        downLoader.downLoadThreadedDiscBeans(discrepancyNoteThreads, DownloadDiscrepancyNote.PDF, response, studyIdentifier);
    }
}
Also used : DownloadDiscrepancyNote(org.akaza.openclinica.bean.extract.DownloadDiscrepancyNote) ViewNotesService(org.akaza.openclinica.service.managestudy.ViewNotesService) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ViewNotesFilterCriteria(org.akaza.openclinica.service.managestudy.ViewNotesFilterCriteria) ArrayList(java.util.ArrayList) ListNotesFilter(org.akaza.openclinica.dao.managestudy.ListNotesFilter) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) DiscrepancyNoteThread(org.akaza.openclinica.service.DiscrepancyNoteThread)

Example 38 with DiscrepancyNoteBean

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

the class ViewSectionDataEntryRESTUrlServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    boolean isSubmitted = false;
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    if (!fp.getString("exitTo").equals("")) {
        request.setAttribute("exitTo", request.getContextPath() + "/" + fp.getString("exitTo"));
    }
    int crfVersionId = fp.getInt("crfVersionId", true);
    Integer sectionId = (Integer) request.getAttribute("sectionId");
    if (sectionId == null || sectionId == 0) {
        sectionId = new Integer(1);
    }
    int eventCRFId = fp.getInt(EVENT_CRF_ID, true);
    int studySubjectId = fp.getInt("studySubjectId", true);
    String action = fp.getString("action");
    HttpSession session = request.getSession();
    String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
    if (StringUtil.isBlank(fromResolvingNotes)) {
        session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
        session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
    }
    // Added for
    request.setAttribute("studySubjectId", studySubjectId + "");
    // Mantis
    // Issue
    // 2268
    // Added
    request.setAttribute("crfListPage", fp.getString("crfListPage"));
    // for
    // Mantis
    // Issue
    // 2268
    // Added for
    request.setAttribute("eventId", fp.getString("eventId"));
    // Mantis
    // Issue
    // 2268
    // YW <<
    int sedId = fp.getInt("sedId");
    request.setAttribute("sedId", sedId + "");
    int crfId = fp.getInt("crfId");
    // BWP>> ... try to get crfId from crfVersionId
    if (crfId == 0 && crfVersionId > 0) {
        CRFVersionDAO crfVDao = new CRFVersionDAO(getDataSource());
        CRFVersionBean crvVBean = (CRFVersionBean) crfVDao.findByPK(crfVersionId);
        if (crvVBean != null) {
            crfId = crvVBean.getCrfId();
        }
    }
    // YW >>
    // int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
    Integer eventDefinitionCRFId = (Integer) (request.getAttribute("eventDefinitionCRFId"));
    EventDefinitionCRFDAO eventCrfDao = new EventDefinitionCRFDAO(getDataSource());
    edcb = (EventDefinitionCRFBean) eventCrfDao.findByPK(eventDefinitionCRFId);
    if (eventCRFId == 0 && edcb.getStudyId() != currentStudy.getParentStudyId() && edcb.getStudyId() != currentStudy.getId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_study_contact_sysadmin"), request);
        throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_director"), "1");
    }
    if (crfId == 0 && eventDefinitionCRFId > 0) {
        // eventCrfDao.findByPK(eventDefinitionCRFId);
        if (edcb != null) {
            crfId = edcb.getCrfId();
        }
    }
    request.setAttribute("crfId", crfId + "");
    request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId + "");
    String printVersion = fp.getString("print");
    // BWP>> this has to be removed for CRFs that do not display an
    // interviewdate
    // for a particular event
    session.removeAttribute("presetValues");
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    SectionDAO sdao = new SectionDAO(getDataSource());
    String age = "";
    if (sectionId == 0 && crfVersionId == 0 && eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_to_view"), request);
        // forwardPage(Page.SUBMIT_DATA_SERVLET);
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
        // >> changed tbh, 06/2009
        return;
    }
    if (studySubjectId > 0) {
        StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
        StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(studySubjectId);
        request.setAttribute("studySubject", sub);
    }
    if (eventCRFId > 0) {
        // for event crf, the input crfVersionId from url =0
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        StudyEventDAO sedao = new StudyEventDAO(getDataSource());
        StudyEventBean event = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
        // event.getSubjectEventStatus().getName());
        if (event.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED)) {
            request.setAttribute("isLocked", "yes");
        // System.out.println("this event crf is locked");
        } else // @pgawade 28-Aug-2012 Reverted the change no. 2 in
        // https://issuetracker.openclinica.com/view.php?id=12343#c56722
        {
            request.setAttribute("isLocked", "no");
        }
        if (studySubjectId <= 0) {
            studySubjectId = event.getStudySubjectId();
            request.setAttribute("studySubjectId", studySubjectId + "");
        }
        // Get the status/number of item discrepancy notes
        DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
        ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
        List<DiscrepancyNoteBean> eventCrfNotes = new ArrayList<DiscrepancyNoteBean>();
        List<DiscrepancyNoteThread> noteThreads = new ArrayList<DiscrepancyNoteThread>();
        // if (eventCRFId > 0) {
        // this method finds only parent notes
        allNotes = dndao.findAllTopNotesByEventCRF(eventCRFId);
        // add interviewer.jsp related notes to this Collection
        eventCrfNotes = dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
        if (!eventCrfNotes.isEmpty()) {
            allNotes.addAll(eventCrfNotes);
            // make sure a necessary request attribute "hasNameNote" is set
            // properly
            this.setAttributeForInterviewerDNotes(eventCrfNotes, request);
        }
        // }
        // Create disc note threads out of the various notes
        DiscrepancyNoteUtil dNoteUtil = new DiscrepancyNoteUtil();
        noteThreads = dNoteUtil.createThreadsOfParents(allNotes, getDataSource(), currentStudy, null, -1, true);
        // variables that provide values for the CRF discrepancy note header
        int updatedNum = 0;
        int openNum = 0;
        int closedNum = 0;
        int resolvedNum = 0;
        int notAppNum = 0;
        DiscrepancyNoteBean tempBean;
        for (DiscrepancyNoteThread dnThread : noteThreads) {
            /*
                 * 3014: do not count parent beans, only the last child disc
                 * note of the thread.
                 */
            tempBean = dnThread.getLinkedNoteList().getLast();
            if (tempBean != null) {
                if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
                    updatedNum++;
                } else if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
                    openNum++;
                } else if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
                    // if (dn.getParentDnId() > 0){
                    closedNum++;
                // }
                } else if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
                    // if (dn.getParentDnId() > 0){
                    resolvedNum++;
                // }
                } else if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
                    notAppNum++;
                }
            }
        }
        request.setAttribute("updatedNum", updatedNum + "");
        request.setAttribute("openNum", openNum + "");
        request.setAttribute("closedNum", closedNum + "");
        request.setAttribute("resolvedNum", resolvedNum + "");
        request.setAttribute("notAppNum", notAppNum + "");
        DisplayTableOfContentsBean displayBean = TableOfContentsServlet.getDisplayBean(ecb, getDataSource(), currentStudy);
        // Make sure that the interviewDate in the eventCRF is properly
        // formatted
        // for viewSectionDataEntry.jsp --> interviewer.jsp
        // int studyEventId = (Integer)request.getAttribute("studyEvent");
        // SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        //
        Date tmpDate = displayBean.getEventCRF().getDateInterviewed();
        String formattedInterviewerDate;
        try {
            DateFormat local_df = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
            formattedInterviewerDate = local_df.format(tmpDate);
        } catch (Exception e) {
            formattedInterviewerDate = "";
        }
        HashMap presetVals = (HashMap) session.getAttribute("presetValues");
        if (presetVals == null) {
            presetVals = new HashMap();
            session.setAttribute("presetValues", presetVals);
        }
        presetVals.put("interviewDate", formattedInterviewerDate);
        request.setAttribute("toc", displayBean);
        ArrayList sections = displayBean.getSections();
        request.setAttribute("sectionNum", sections.size() + "");
        if (!sections.isEmpty()) {
            if (sectionId == 0) {
                SectionBean firstSec = (SectionBean) sections.get(0);
                sectionId = firstSec.getId();
            }
        } else {
            addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF"), request);
            // forwardPage(Page.SUBMIT_DATA_SERVLET);
            forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
            // >> changed tbh, 06/2009
            return;
        }
    } else if (crfVersionId > 0) {
        // for viewing blank CRF
        DisplayTableOfContentsBean displayBean = ViewTableOfContentServlet.getDisplayBean(getDataSource(), crfVersionId);
        request.setAttribute("toc", displayBean);
        ArrayList sections = displayBean.getSections();
        request.setAttribute("sectionNum", sections.size() + "");
        if (!sections.isEmpty()) {
            if (sectionId == 0) {
                SectionBean firstSec = (SectionBean) sections.get(0);
                sectionId = firstSec.getId();
            }
        } else {
            addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF_version"), request);
            if (eventCRFId == 0) {
                forwardPage(Page.CRF_LIST_SERVLET, request, response);
            } else {
                // forwardPage(Page.SUBMIT_DATA_SERVLET);
                forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
            // >> changed tbh, 06/2009
            }
            return;
        }
    }
    sb = (SectionBean) sdao.findByPK(sectionId);
    if (eventCRFId == 0) {
        ecb = new EventCRFBean();
        ecb.setCRFVersionId(sb.getCRFVersionId());
        if (currentStudy.getParentStudyId() > 0) {
            // this is a site,find parent
            StudyDAO studydao = new StudyDAO(getDataSource());
            StudyBean parentStudy = (StudyBean) studydao.findByPK(currentStudy.getParentStudyId());
            request.setAttribute("studyTitle", parentStudy.getName());
            request.setAttribute("siteTitle", currentStudy.getName());
        } else {
            request.setAttribute("studyTitle", currentStudy.getName());
        }
    } else {
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        // This is the StudySubjectBean
        StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
        StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
        // This is the SubjectBean
        SubjectDAO subjectDao = new SubjectDAO(getDataSource());
        int subjectId = sub.getSubjectId();
        int studyId = sub.getStudyId();
        SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
        // Let us process the age
        if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
            StudyEventDAO sedao = new StudyEventDAO(getDataSource());
            StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
            StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
            se.setStudyEventDefinition(sed);
            request.setAttribute("studyEvent", se);
            // YW 11-16-2007 enrollment-date is used for computing age
            age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
        }
        // Get the study then the parent study
        StudyDAO studydao = new StudyDAO(getDataSource());
        StudyBean study = (StudyBean) studydao.findByPK(studyId);
        if (study.getParentStudyId() > 0) {
            // this is a site,find parent
            StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
            request.setAttribute("studyTitle", parentStudy.getName());
            request.setAttribute("siteTitle", study.getName());
        } else {
            request.setAttribute("studyTitle", study.getName());
        }
        request.setAttribute("studySubject", sub);
        request.setAttribute("subject", subject);
        request.setAttribute("age", age);
    }
    // FormBeanUtil formUtil = new FormBeanUtil();
    // DisplaySectionBean newDisplayBean = new DisplaySectionBean();
    boolean hasItemGroup = false;
    // we will look into db to see if any repeating items for this CRF
    // section
    ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
    List<ItemGroupBean> itemGroups = igdao.findLegitGroupBySectionId(sectionId);
    if (!itemGroups.isEmpty()) {
        hasItemGroup = true;
    }
    // if the List of DisplayFormGroups is empty, then the servlet defers to
    // the prior method
    // of generating a DisplaySectionBean for the application
    DisplaySectionBean dsb;
    // want to get displayBean with grouped and ungrouped items
    request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
    request.setAttribute(INPUT_EVENT_CRF, ecb);
    request.setAttribute(SECTION_BEAN, sb);
    dsb = super.getDisplayBean(hasItemGroup, false, request, isSubmitted);
    FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    if (discNotes == null) {
        discNotes = new FormDiscrepancyNotes();
        session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
    }
    /*
         * if (hasItemGroup) { //
         * dsb.setDisplayItemGroups(newDisplayBean.getDisplayItemGroups());
         * request.setAttribute("new_table", true); }
         */
    // If the Horizontal type table will be used, then set the
    // DisplaySectionBean's
    // DisplayFormGroups List to the ones we have just generated
    // @pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter
    // 'isSubmitted' to method createItemWithGroups
    List<DisplayItemWithGroupBean> displayItemWithGroups = super.createItemWithGroups(dsb, hasItemGroup, eventDefinitionCRFId, request, isSubmitted);
    dsb.setDisplayItemGroups(displayItemWithGroups);
    super.populateNotesWithDBNoteCounts(discNotes, dsb, request);
    if (fp.getString("fromViewNotes") != null && "1".equals(fp.getString("fromViewNotes"))) {
        request.setAttribute("fromViewNotes", fp.getString("fromViewNotes"));
    } else {
        session.removeAttribute("viewNotesURL");
    }
    if ("saveNotes".equalsIgnoreCase(action)) {
        LOGGER.info("33333how many group rows:" + dsb.getDisplayItemGroups().size());
        // let's save notes for the blank items
        DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
        discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
        for (int i = 0; i < dsb.getDisplayItemGroups().size(); i++) {
            DisplayItemWithGroupBean diwb = dsb.getDisplayItemGroups().get(i);
            if (diwb.isInGroup()) {
                List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
                LOGGER.info("dgbs size: " + dgbs.size());
                for (int j = 0; j < dgbs.size(); j++) {
                    DisplayItemGroupBean displayGroup = dgbs.get(j);
                    List<DisplayItemBean> items = displayGroup.getItems();
                    LOGGER.info("item size: " + items.size());
                    for (DisplayItemBean displayItem : items) {
                        String inputName = getGroupItemInputName(displayGroup, j, displayItem);
                        LOGGER.info("inputName:" + inputName);
                        LOGGER.info("item data id:" + displayItem.getData().getId());
                        AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, displayItem.getData().getId(), "itemData", currentStudy);
                    }
                }
            } else {
                DisplayItemBean dib = diwb.getSingleItem();
                // TODO work on this line
                String inputName = getInputName(dib);
                AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
                ArrayList childItems = dib.getChildren();
                for (int j = 0; j < childItems.size(); j++) {
                    DisplayItemBean child = (DisplayItemBean) childItems.get(j);
                    inputName = getInputName(child);
                    AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
                }
            }
        }
        addPageMessage("Discrepancy notes are saved successfully.", request);
        request.setAttribute("id", studySubjectId + "");
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET, request, response);
        // "ViewStudySubject?id=" + studySubjectId));
        return;
    } else {
        request.setAttribute(BEAN_DISPLAY, dsb);
        request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
        request.setAttribute("sec", sb);
        request.setAttribute("EventCRFBean", ecb);
        int tabNum = 1;
        if ("".equalsIgnoreCase(fp.getString("tabId"))) {
            tabNum = 1;
        } else {
            tabNum = fp.getInt("tabId");
        }
        request.setAttribute("tabId", new Integer(tabNum).toString());
        // 2808: Signal interviewer.jsp that the containing page is
        // viewSectionData,
        // for the purpose of suppressing discrepancy note icons for the
        // interview date and name fields
        request.setAttribute(ENCLOSING_PAGE, "viewSectionData");
        if ("yes".equalsIgnoreCase(printVersion)) {
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
        } else {
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY, request, response);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) DisplayItemWithGroupBean(org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DiscrepancyNoteThread(org.akaza.openclinica.service.DiscrepancyNoteThread) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) HttpSession(javax.servlet.http.HttpSession) DisplayTableOfContentsBean(org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) SimpleDateFormat(java.text.SimpleDateFormat)

Example 39 with DiscrepancyNoteBean

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

the class ViewNotesServlet method filterForOneSubject.

public ArrayList<DiscrepancyNoteBean> filterForOneSubject(ArrayList<DiscrepancyNoteBean> allNotes, int subjectId, int resolutionStatus) {
    if (allNotes == null || allNotes.isEmpty() || subjectId == 0)
        return allNotes;
    // Are the D Notes filtered by resolution?
    boolean filterByRes = resolutionStatus >= 1 && resolutionStatus <= 5;
    ArrayList<DiscrepancyNoteBean> filteredNotes = new ArrayList<DiscrepancyNoteBean>();
    StudySubjectDAO subjectDao = new StudySubjectDAO(sm.getDataSource());
    StudySubjectBean studySubjBean = (StudySubjectBean) subjectDao.findByPK(subjectId);
    for (DiscrepancyNoteBean discBean : allNotes) {
        if (discBean.getSubjectName().equalsIgnoreCase(studySubjBean.getLabel())) {
            if (!filterByRes) {
                filteredNotes.add(discBean);
            } else {
                if (discBean.getResolutionStatusId() == resolutionStatus) {
                    filteredNotes.add(discBean);
                }
            }
        }
    }
    return filteredNotes;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 40 with DiscrepancyNoteBean

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

the class ViewStudySubjectServlet method setRequestAttributesForNotes.

private void setRequestAttributesForNotes(List<DiscrepancyNoteBean> discBeans) {
    for (DiscrepancyNoteBean discrepancyNoteBean : discBeans) {
        if ("unique_identifier".equalsIgnoreCase(discrepancyNoteBean.getColumn())) {
            request.setAttribute(HAS_UNIQUE_ID_NOTE, "yes");
            request.setAttribute(UNIQUE_ID_NOTE, discrepancyNoteBean);
        } else if ("date_of_birth".equalsIgnoreCase(discrepancyNoteBean.getColumn())) {
            request.setAttribute(HAS_DOB_NOTE, "yes");
            request.setAttribute(DOB_NOTE, discrepancyNoteBean);
        } else if ("enrollment_date".equalsIgnoreCase(discrepancyNoteBean.getColumn())) {
            request.setAttribute(HAS_ENROLLMENT_NOTE, "yes");
            request.setAttribute(ENROLLMENT_NOTE, discrepancyNoteBean);
        } else if ("gender".equalsIgnoreCase(discrepancyNoteBean.getColumn())) {
            request.setAttribute(HAS_GENDER_NOTE, "yes");
            request.setAttribute(GENDER_NOTE, discrepancyNoteBean);
        }
    }
}
Also used : DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)

Aggregations

DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)122 ArrayList (java.util.ArrayList)81 HashMap (java.util.HashMap)62 Iterator (java.util.Iterator)44 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)34 Date (java.util.Date)20 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)20 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)20 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)20 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)18 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)18 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)14 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)14 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)13 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)11 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)11 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)11 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)10 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)10