Search in sources :

Example 6 with DiscrepancyNoteUtil

use of org.akaza.openclinica.service.DiscrepancyNoteUtil in project OpenClinica by OpenClinica.

the class ViewSectionDataEntryServlet method processRequest.

// BWP 01/08>>
@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", fp.getString("exitTo"));
    }
    int crfVersionId = fp.getInt("crfVersionId", true);
    int sectionId = fp.getInt("sectionId");
    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");
    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 {
            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);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(getDataSource());
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(getDataSource());
    StudyEventDAO studyEventDAO = new StudyEventDAO(getDataSource());
    StudyEventDefinitionBean studyEventDefinition = (StudyEventDefinitionBean) studyEventDefinitionDAO.findByPK(edcb.getStudyEventDefinitionId());
    StudyEventBean studyEvent = (StudyEventBean) studyEventDAO.findByPK(ecb.getStudyEventId());
    VariableSubstitutionHelper.replaceVariables(dsb, currentStudy, (StudySubjectBean) studySubjectDAO.findByPK(studySubjectId), studyEventDefinition, studyEvent, getDataSource());
    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) 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) 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) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) 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 7 with DiscrepancyNoteUtil

use of org.akaza.openclinica.service.DiscrepancyNoteUtil in project OpenClinica by OpenClinica.

the class DownloadDiscrepancyNote method createTableFromBean.

private Table createTableFromBean(DiscrepancyNoteBean discBean) throws BadElementException {
    Table table = new Table(2);
    table.setTableFitsPage(true);
    table.setCellsFitPage(true);
    table.setBorderWidth(1);
    table.setBorderColor(new java.awt.Color(0, 0, 0));
    table.setPadding(4);
    table.setSpacing(4);
    Cell cell = new Cell("Discrepancy note id: " + discBean.getId());
    cell.setHeader(true);
    cell.setColspan(2);
    table.addCell(cell);
    table.endHeaders();
    cell = new Cell("Subject name: " + discBean.getSubjectName());
    table.addCell(cell);
    cell = new Cell("CRF name: " + discBean.getCrfName());
    table.addCell(cell);
    cell = new Cell("Description: " + discBean.getDescription());
    table.addCell(cell);
    if (discBean.getDisType() != null) {
        cell = new Cell("Discrepancy note type: " + discBean.getDisType().getName());
        table.addCell(cell);
    }
    cell = new Cell("Event name: " + discBean.getEventName());
    table.addCell(cell);
    cell = new Cell("Parent note ID: " + (discBean.getParentDnId() > 0 ? discBean.getParentDnId() : ""));
    table.addCell(cell);
    cell = new Cell("Resolution status: " + new DiscrepancyNoteUtil().getResolutionStatusName(discBean.getResolutionStatusId()));
    table.addCell(cell);
    cell = new Cell("Detailed notes: " + discBean.getDetailedNotes());
    table.addCell(cell);
    cell = new Cell("Entity name: " + discBean.getEntityName());
    table.addCell(cell);
    cell = new Cell("Entity value: " + discBean.getEntityValue());
    table.addCell(cell);
    cell = new Cell("Date updated: " + discBean.getUpdatedDateString());
    table.addCell(cell);
    cell = new Cell("Study ID: " + discBean.getStudyId());
    table.addCell(cell);
    return table;
}
Also used : Color(java.awt.Color) Table(com.lowagie.text.Table) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) Cell(com.lowagie.text.Cell)

Example 8 with DiscrepancyNoteUtil

use of org.akaza.openclinica.service.DiscrepancyNoteUtil in project OpenClinica by OpenClinica.

the class DownloadDiscrepancyNote method createTableThreadHeader.

private Table createTableThreadHeader(DiscrepancyNoteThread discNoteThread) throws BadElementException {
    Table table = new Table(2);
    table.setTableFitsPage(true);
    table.setCellsFitPage(true);
    table.setBorderWidth(1);
    table.setBorderColor(new java.awt.Color(0, 0, 0));
    table.setPadding(4);
    table.setSpacing(4);
    if (discNoteThread == null || discNoteThread.getLinkedNoteList().isEmpty()) {
        return table;
    }
    //Get information for the header; the resolution status, however, has to be the latest
    //resolution status for the DN thread
    DiscrepancyNoteBean dnBean = discNoteThread.getLinkedNoteList().getFirst();
    DiscrepancyNoteUtil discUtil = new DiscrepancyNoteUtil();
    String latestResolutionStatus = discUtil.getResolutionStatusName(discNoteThread.getLinkedNoteList().getFirst().getResolutionStatusId());
    StringBuilder content = new StringBuilder("");
    if (dnBean != null) {
        if (!"".equalsIgnoreCase(dnBean.getEntityName())) {
            content.append("Item field name/value: ");
            content.append(dnBean.getEntityName());
            if (!"".equalsIgnoreCase(dnBean.getEntityValue())) {
                content.append(" = ");
                content.append(dnBean.getEntityValue());
            }
        }
        Paragraph para = new Paragraph(content.toString(), new Font(Font.HELVETICA, 14, Font.BOLD, new Color(0, 0, 0)));
        Cell cell = new Cell(para);
        cell.setHeader(true);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setColspan(2);
        table.addCell(cell);
        table.endHeaders();
        //Add at least three more rows of data -- dnBean.getSubjectName()
        //row 1
        cell = createCell("Study Subject", dnBean.getSubjectName());
        table.addCell(cell);
        cell = createCell("Study Event", dnBean.getEventName());
        table.addCell(cell);
        //row 2
        cell = createCell("Study Event Date", dnBean.getEventStart() + "");
        table.addCell(cell);
        StringBuilder tmpStrBuilder = new StringBuilder("CRF: ");
        tmpStrBuilder.append(dnBean.getCrfName());
        tmpStrBuilder.append("\n");
        tmpStrBuilder.append("Status: ");
        tmpStrBuilder.append(dnBean.getCrfStatus());
        content.append(dnBean.getCrfName());
        cell = new Cell(new Paragraph(tmpStrBuilder.toString(), new Font(Font.HELVETICA, 14, Font.BOLD, new Color(0, 0, 0))));
        table.addCell(cell);
        //row 3
        cell = createCell("Type", discUtil.getResolutionStatusTypeName(dnBean.getDiscrepancyNoteTypeId()));
        table.addCell(cell);
        cell = createCell("Resolution Status", latestResolutionStatus);
        table.addCell(cell);
        cell = createCell("Number of notes", discNoteThread.getLinkedNoteList().size() + "");
        table.addCell(cell);
        cell = createCell("Discrepancy Note ID", dnBean.getId() + "");
        table.addCell(cell);
        cell = createCell("Days Open", dnBean.getAge() + "");
        table.addCell(cell);
        String daysSinceUpdated = escapeQuotesInCSV(dnBean.getDays() + "");
        cell = createCell("Days Since Updated", daysSinceUpdated.equals("0") ? "" : daysSinceUpdated + "");
        table.addCell(cell);
    }
    return table;
}
Also used : Color(java.awt.Color) Table(com.lowagie.text.Table) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) Color(java.awt.Color) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) Cell(com.lowagie.text.Cell) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Example 9 with DiscrepancyNoteUtil

use of org.akaza.openclinica.service.DiscrepancyNoteUtil in project OpenClinica by OpenClinica.

the class ListDiscNotesSubjectServlet method processRequest.

// < ResourceBundleresexception,respage;
@Override
protected void processRequest() throws Exception {
    String module = request.getParameter("module");
    String moduleStr = "manage";
    if (module != null && module.trim().length() > 0) {
        if ("submit".equals(module)) {
            request.setAttribute("module", "submit");
            moduleStr = "submit";
        } else if ("admin".equals(module)) {
            request.setAttribute("module", "admin");
            moduleStr = "admin";
        } else {
            request.setAttribute("module", "manage");
        }
    }
    // << tbh 02/2010 filter out the entire module parameter to catch injections
    // BWP 3098>> close the info side panel and show icons
    request.setAttribute("closeInfoShowIcons", true);
    // <<
    // Determine whether to limit the displayed DN's to a certain DN type
    int resolutionStatus = 0;
    try {
        resolutionStatus = Integer.parseInt(request.getParameter("resolutionStatus"));
    } catch (NumberFormatException nfe) {
        // Show all DN's
        resolutionStatus = -1;
    }
    // Determine whether we already have a collection of resolutionStatus
    // Ids, and if not
    // create a new attribute. If there is no resolution status, then the
    // Set object should be cleared,
    // because we do not have to save a set of filter IDs.
    boolean hasAResolutionStatus = resolutionStatus >= 1 && resolutionStatus <= 5;
    Set<Integer> resolutionStatusIds = (HashSet) session.getAttribute(RESOLUTION_STATUS);
    // remove the session if there is no resolution status
    if (!hasAResolutionStatus && resolutionStatusIds != null) {
        session.removeAttribute(RESOLUTION_STATUS);
        resolutionStatusIds = null;
    }
    if (hasAResolutionStatus) {
        if (resolutionStatusIds == null) {
            resolutionStatusIds = new HashSet<Integer>();
        }
        resolutionStatusIds.add(resolutionStatus);
        session.setAttribute(RESOLUTION_STATUS, resolutionStatusIds);
    }
    int discNoteType = 0;
    try {
        discNoteType = Integer.parseInt(request.getParameter("type"));
    } catch (NumberFormatException nfe) {
        // Show all DN's
        discNoteType = -1;
    }
    request.setAttribute(DISCREPANCY_NOTE_TYPE, discNoteType);
    DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
    // Generate a summary of how we are filtering;
    Map<String, List<String>> filterSummary = discNoteUtil.generateFilterSummary(discNoteType, resolutionStatusIds);
    if (!filterSummary.isEmpty()) {
        request.setAttribute(FILTER_SUMMARY, filterSummary);
    }
    locale = LocaleResolver.getLocale(request);
    StudyBean sbean = (StudyBean) session.getAttribute("study");
    //List<DiscrepancyNoteBean> allDiscNotes = discNoteUtil.getThreadedDNotesForStudy(sbean, resolutionStatusIds, sm.getDataSource(), discNoteType, true);
    //Map stats = discNoteUtil.generateDiscNoteSummary(allDiscNotes);
    Map stats = discNoteUtil.generateDiscNoteSummaryRefactored(sm.getDataSource(), currentStudy, resolutionStatusIds, discNoteType);
    request.setAttribute("summaryMap", stats);
    Set mapKeys = stats.keySet();
    request.setAttribute("mapKeys", mapKeys);
    // < resword =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.words",locale);
    StudyDAO studyDAO = 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());
    EventCRFDAO edao = new EventCRFDAO(sm.getDataSource());
    EventDefinitionCRFDAO eddao = new EventDefinitionCRFDAO(sm.getDataSource());
    SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
    DiscrepancyNoteDAO dnDAO = new DiscrepancyNoteDAO(sm.getDataSource());
    ListDiscNotesSubjectTableFactory factory = new ListDiscNotesSubjectTableFactory(ResourceBundleProvider.getTermsBundle(locale));
    factory.setStudyEventDefinitionDao(seddao);
    factory.setSubjectDAO(subdao);
    factory.setStudySubjectDAO(sdao);
    factory.setStudyEventDAO(sedao);
    factory.setStudyBean(currentStudy);
    factory.setStudyGroupClassDAO(sgcdao);
    factory.setSubjectGroupMapDAO(sgmdao);
    factory.setStudyDAO(studyDAO);
    factory.setCurrentRole(currentRole);
    factory.setCurrentUser(ub);
    factory.setEventCRFDAO(edao);
    factory.setEventDefintionCRFDAO(eddao);
    factory.setStudyGroupDAO(sgdao);
    factory.setDiscrepancyNoteDAO(dnDAO);
    factory.setModule(moduleStr);
    factory.setDiscNoteType(discNoteType);
    // factory.setStudyHasDiscNotes(allDiscNotes != null &&
    // !allDiscNotes.isEmpty());
    factory.setResolutionStatus(resolutionStatus);
    factory.setResolutionStatusIds(resolutionStatusIds);
    factory.setResword(ResourceBundleProvider.getWordsBundle(locale));
    String listDiscNotesHtml = factory.createTable(request, response).render();
    request.setAttribute("listDiscNotesHtml", listDiscNotesHtml);
    forwardPage(getJSP());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ListDiscNotesSubjectTableFactory(org.akaza.openclinica.control.submit.ListDiscNotesSubjectTableFactory) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) List(java.util.List) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) HashSet(java.util.HashSet) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) Map(java.util.Map)

Example 10 with DiscrepancyNoteUtil

use of org.akaza.openclinica.service.DiscrepancyNoteUtil in project OpenClinica by OpenClinica.

the class UpdateStudyEventServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormDiscrepancyNotes discNotes = null;
    FormProcessor fp = new FormProcessor(request);
    int studyEventId = fp.getInt(EVENT_ID, true);
    int studySubjectId = fp.getInt(STUDY_SUBJECT_ID, true);
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
    if (StringUtil.isBlank(fromResolvingNotes)) {
        session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
        session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
        checkStudyLocked(Page.MANAGE_STUDY, respage.getString("current_study_locked"));
        checkStudyFrozen(Page.MANAGE_STUDY, respage.getString("current_study_frozen"));
    }
    if (studyEventId == 0 || studySubjectId == 0) {
        addPageMessage(respage.getString("choose_a_study_event_to_edit"));
        request.setAttribute("id", new Integer(studySubjectId).toString());
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        return;
    }
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    StudySubjectBean ssub = null;
    if (studySubjectId > 0) {
        ssub = (StudySubjectBean) ssdao.findByPK(studySubjectId);
        request.setAttribute("studySubject", ssub);
        // for the workflow
        request.setAttribute("id", studySubjectId + "");
    // box, so it can
    // link back to view
    // study subject
    }
    // YW 11-07-2007, a study event could not be updated if its study
    // subject has been removed
    // Status s = ((StudySubjectBean)new
    // StudySubjectDAO(sm.getDataSource()).findByPK(studySubjectId)).getStatus();
    Status s = ssub.getStatus();
    if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
        addPageMessage(resword.getString("study_event") + resterm.getString("could_not_be") + resterm.getString("updated") + "." + respage.getString("study_subject_has_been_deleted"));
        request.setAttribute("id", new Integer(studySubjectId).toString());
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
    // YW
    request.setAttribute(STUDY_SUBJECT_ID, new Integer(studySubjectId).toString());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    EventCRFDAO ecrfdao = new EventCRFDAO(sm.getDataSource());
    StudyEventBean studyEvent = (StudyEventBean) sedao.findByPK(studyEventId);
    studyEvent.setEventCRFs(ecrfdao.findAllByStudyEvent(studyEvent));
    // only owner, admins, and study director/coordinator can update
    // if (ub.getId() != studyEvent.getOwnerId()) {
    // if (!ub.isSysAdmin() &&
    // !currentRole.getRole().equals(Role.STUDYDIRECTOR)
    // && !currentRole.getRole().equals(Role.COORDINATOR)) {
    // addPageMessage(respage.getString("no_have_correct_privilege_current_study")
    // + respage.getString("change_study_contact_sysadmin"));
    // request.setAttribute("id", new Integer(studySubjectId).toString());
    // forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    // return;
    // }
    // }
    // above removed tbh 11162007
    ArrayList statuses = SubjectEventStatus.toArrayList();
    // remove more statuses here, tbh, 092007
    // ### updates to status setting, below added tbh 102007
    // following pieces of logic to be added:
    /*
         * REMOVED can happen at any step, COMPLETED can happen if the Subject
         * Event is already complete, COMPLETED can also happen if all required
         * CRFs in the Subject Event are completed, LOCKED can occur when all
         * Event CRFs are completed, or not started, or removed, LOCKED/REMOVED
         * are only options, however, when the user is study director or study
         * coordinator SKIPPED/STOPPED? Additional rules spelled out on Nov 16
         * 2007: STOPPED should only be in the list of choices after IDE has
         * been started, i.e. not when SCHEDULED SKIPPED should only be in the
         * list before IDE has been started, i.e. when SCHEDULED reminder about
         * LOCKED happening only when CRFs are completed (not as in the
         * above...) if a status is LOCKED already, it should allow a user to
         * set the event back to COMPLETED
         */
    StudyDAO sdao = new StudyDAO(this.sm.getDataSource());
    StudyBean studyBean = (StudyBean) sdao.findByPK(ssub.getStudyId());
    checkRoleByUserAndStudy(ub, studyBean.getParentStudyId(), studyBean.getId());
    // To remove signed status from the list
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    boolean removeSign = false;
    // DiscrepancyNoteDAO discDao = new
    // DiscrepancyNoteDAO(sm.getDataSource());
    ArrayList eventCrfs = studyEvent.getEventCRFs();
    for (int i = 0; i < eventCrfs.size(); i++) {
        EventCRFBean ecrf = (EventCRFBean) eventCrfs.get(i);
        EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(studyBean, studyEventId, ecrf.getCRFVersionId());
        if (ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) || ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) && edcBean.isDoubleEntry() == true) {
            removeSign = true;
            break;
        }
    }
    if (currentRole.isResearchAssistant()) {
        removeSign = true;
    }
    if (currentRole.isResearchAssistant2()) {
        removeSign = true;
    }
    if (removeSign == true || !currentRole.isInvestigator()) {
        statuses.remove(SubjectEventStatus.SIGNED);
    }
    /*
         * if(!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.
         * DATA_ENTRY_STARTED)) {
         * statuses.remove(SubjectEventStatus.DATA_ENTRY_STARTED);
         * //statuses.remove(SubjectEventStatus.SKIPPED); // per new rule
         * 11-2007 }
         */
    if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.NOT_SCHEDULED)) {
        statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
    }
    if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
        // can't lock a non-completed CRF, but removed above
        statuses.remove(SubjectEventStatus.SCHEDULED);
    // statuses.remove(SubjectEventStatus.SKIPPED);
    // addl rule: skipped should only be present before data starts
    // being entered
    }
    if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
        statuses.remove(SubjectEventStatus.SKIPPED);
    }
    ArrayList getECRFs = studyEvent.getEventCRFs();
    // above removed tbh 102007, require to get all definitions, no matter
    // if they are filled in or now
    EventDefinitionCRFDAO edefcrfdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList getAllECRFs = (ArrayList) edefcrfdao.findAllByDefinition(studyBean, studyEvent.getStudyEventDefinitionId());
    // does the study event have all complete CRFs which are required?
    logger.debug("found number of ecrfs: " + getAllECRFs.size());
    // may not be populated, only entered crfs seem to ping the list
    for (int u = 0; u < getAllECRFs.size(); u++) {
        EventDefinitionCRFBean ecrfBean = (EventDefinitionCRFBean) getAllECRFs.get(u);
        //
        logger.debug("found number of existing ecrfs: " + getECRFs.size());
        if (getECRFs.size() == 0) {
            statuses.remove(SubjectEventStatus.COMPLETED);
            statuses.remove(SubjectEventStatus.LOCKED);
        }
        // otherwise...
        for (int uv = 0; uv < getECRFs.size(); uv++) {
            EventCRFBean existingBean = (EventCRFBean) getECRFs.get(uv);
            logger.debug("***** found: " + existingBean.getCRFVersionId() + " " + existingBean.getCrf().getId() + " " + existingBean.getCrfVersion().getName() + " " + existingBean.getStatus().getName() + " " + existingBean.getStage().getName());
            logger.debug("***** comparing above to ecrfBean.DefaultVersionID: " + ecrfBean.getDefaultVersionId());
            // this is addressed in the if-clause above
            if (!existingBean.getStatus().equals(Status.UNAVAILABLE) && edefcrfdao.isRequiredInDefinition(existingBean.getCRFVersionId(), studyEvent)) {
                logger.debug("found that " + existingBean.getCrfVersion().getName() + " is required...");
                // that is, it's not completed but required to complete
                statuses.remove(SubjectEventStatus.COMPLETED);
                statuses.remove(SubjectEventStatus.LOCKED);
            // per new rule above 11-16-2007
            }
        // }
        }
    }
    // below added 092007, tbh, task #1390
    if (!ub.isSysAdmin() && !currentRole.getRole().equals(Role.STUDYDIRECTOR) && !currentRole.getRole().equals(Role.COORDINATOR)) {
        statuses.remove(SubjectEventStatus.LOCKED);
    }
    // scheduled
    if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
        statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
        statuses.remove(SubjectEventStatus.SCHEDULED);
    }
    // ### tbh, above modified 102007
    request.setAttribute("statuses", statuses);
    String action = fp.getString("action");
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEvent.getStudyEventDefinitionId());
    request.setAttribute(EVENT_DEFINITION_BEAN, sed);
    if (action.equalsIgnoreCase("submit")) {
        discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
        DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
        SubjectEventStatus ses = SubjectEventStatus.get(fp.getInt(SUBJECT_EVENT_STATUS_ID));
        studyEvent.setSubjectEventStatus(ses);
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
        if (ses.equals(SubjectEventStatus.SKIPPED) || ses.equals(SubjectEventStatus.STOPPED)) {
            studyEvent.setStatus(Status.UNAVAILABLE);
            for (int i = 0; i < eventCRFs.size(); i++) {
                EventCRFBean ecb = eventCRFs.get(i);
                ecb.setOldStatus(ecb.getStatus());
                ecb.setStatus(Status.UNAVAILABLE);
                ecb.setUpdater(ub);
                ecb.setUpdatedDate(new Date());
                ecdao.update(ecb);
            }
        } else {
            for (int i = 0; i < eventCRFs.size(); i++) {
                EventCRFBean ecb = eventCRFs.get(i);
                ecb.setUpdater(ub);
                ecb.setUpdatedDate(new Date());
                ecdao.update(ecb);
            }
        }
        // YW 3-12-2008, 2220 fix
        String strEnd = fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
        String strEndScheduled = fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
        Date start = fp.getDateTime(INPUT_STARTDATE_PREFIX);
        Date end = null;
        v.addValidation(INPUT_STARTDATE_PREFIX, Validator.IS_DATE_TIME);
        v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX);
        if (!strEndScheduled.equals("")) {
            v.addValidation(INPUT_ENDDATE_PREFIX, Validator.IS_DATE_TIME);
            v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX);
        }
        //     v.addValidation(INPUT_LOCATION, Validator.NO_BLANKS); Disable validation on location, location can be empty when updating a study event
        HashMap errors = v.validate();
        // YW, 3-12-2008, 2220 fix <<
        if (!strEnd.equals("") && !errors.containsKey(INPUT_STARTDATE_PREFIX) && !errors.containsKey(INPUT_ENDDATE_PREFIX)) {
            end = fp.getDateTime(INPUT_ENDDATE_PREFIX);
            if (!fp.getString(INPUT_STARTDATE_PREFIX + "Date").equals(fp.getString(INPUT_ENDDATE_PREFIX + "Date"))) {
                if (end.before(start)) {
                    v.addError(errors, INPUT_ENDDATE_PREFIX, resexception.getString("input_provided_not_occure_after_previous_start_date_time"));
                }
            } else {
                // if in same date, only check when both had time entered
                if (fp.timeEntered(INPUT_STARTDATE_PREFIX) && fp.timeEntered(INPUT_ENDDATE_PREFIX)) {
                    if (end.before(start) || end.equals(start)) {
                        v.addError(errors, INPUT_ENDDATE_PREFIX, resexception.getString("input_provided_not_occure_after_previous_start_date_time"));
                    }
                }
            }
        }
        if (!errors.isEmpty()) {
            setInputMessages(errors);
            String[] prefixes = { INPUT_STARTDATE_PREFIX, INPUT_ENDDATE_PREFIX };
            fp.setCurrentDateTimeValuesAsPreset(prefixes);
            setPresetValues(fp.getPresetValues());
            studyEvent.setLocation(fp.getString(INPUT_LOCATION));
            request.setAttribute("changeDate", fp.getString("changeDate"));
            request.setAttribute(EVENT_BEAN, studyEvent);
            forwardPage(Page.UPDATE_STUDY_EVENT);
        } else if (studyEvent.getSubjectEventStatus().isSigned()) {
            // Checks if the status is signed
            // -----------------
            request.setAttribute(STUDY_SUBJECT_ID, new Integer(studySubjectId).toString());
            if (fp.getString(INPUT_STARTDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Half").equals("")) {
                studyEvent.setStartTimeFlag(false);
            } else {
                studyEvent.setStartTimeFlag(true);
            }
            studyEvent.setDateStarted(start);
            if (!strEnd.equals("")) {
                studyEvent.setDateEnded(end);
                if (fp.getString(INPUT_ENDDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Half").equals("")) {
                    studyEvent.setEndTimeFlag(false);
                } else {
                    studyEvent.setEndTimeFlag(true);
                }
            }
            studyEvent.setLocation(fp.getString(INPUT_LOCATION));
            studyEvent.setStudyEventDefinition(sed);
            // -------------------
            ssdao = new StudySubjectDAO(sm.getDataSource());
            StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(studyEvent.getStudySubjectId());
            ecdao = new EventCRFDAO(sm.getDataSource());
            eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
            ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
            RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
            StudyBean study = (StudyBean) sdao.findByPK(ssb.getStudyId());
            ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, studyEvent.getStudyEventDefinitionId());
            ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
            populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
            ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, studyEvent.getSubjectEventStatus(), study);
            request.setAttribute("studySubject", ssb);
            request.setAttribute("uncompletedEventDefinitionCRFs", uncompletedEventDefinitionCRFs);
            request.setAttribute("displayEventCRFs", displayEventCRFs);
            request.setAttribute(EVENT_BEAN, studyEvent);
            session.setAttribute("eventSigned", studyEvent);
            DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
            DisplayStudyEventBean displayEvBean = new DisplayStudyEventBean();
            List<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
            // Set up a Map for the JSP view, mapping the eventCRFId to
            // another Map: the
            // inner Map maps the resolution status name to the number of
            // notes for that
            // eventCRF id, as in New --> 2
            displayEvBean.setStudyEvent(studyEvent);
            displayEvents.add(displayEvBean);
            // Don't filter for res status or disc note type; disc note
            // beans are returned with eventCRFId set
            discNoteUtil.injectParentDiscNotesIntoDisplayStudyEvents(displayEvents, new HashSet(), sm.getDataSource(), 0);
            Map discNoteByEventCRFid = discNoteUtil.createDiscNoteMapByEventCRF(displayEvents);
            request.setAttribute("discNoteByEventCRFid", discNoteByEventCRFid);
            forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
        } else {
            logger.debug("no validation error");
            // YW 08-17-2007 << update start_time_flag column
            if (fp.getString(INPUT_STARTDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Half").equals("")) {
                studyEvent.setStartTimeFlag(false);
            } else {
                studyEvent.setStartTimeFlag(true);
            }
            // YW >>
            studyEvent.setDateStarted(start);
            // YW, 3-12-2008, 2220 fix which adding End datetime <<
            if (!strEnd.equals("")) {
                studyEvent.setDateEnded(end);
                if (fp.getString(INPUT_ENDDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Half").equals("")) {
                    studyEvent.setEndTimeFlag(false);
                } else {
                    studyEvent.setEndTimeFlag(true);
                }
            }
            // YW >>
            studyEvent.setLocation(fp.getString(INPUT_LOCATION));
            logger.debug("update study event...");
            studyEvent.setUpdater(ub);
            studyEvent.setUpdatedDate(new Date());
            StudyEventBean updatedStudyEvent = (StudyEventBean) sedao.update(studyEvent);
            // save discrepancy notes into DB
            FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
            AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
            AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
            AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
            //       getRuleSetService().runRulesInBeanProperty(createRuleSet(ssub,sed),currentStudy,ub,request,ssub);
            addPageMessage(respage.getString("study_event_updated"));
            request.setAttribute("id", new Integer(studySubjectId).toString());
            session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        // FORWARD SHOULD BE TO THE NEW PAGE
        }
    } else if (action.equalsIgnoreCase("confirm")) {
        // confirming the signed
        // status
        String username = request.getParameter("j_user");
        String password = request.getParameter("j_pass");
        //tring encodedUserPass = org.akaza.openclinica.core.SecurityManager.getInstance().encrytPassword(password);
        SecurityManager securityManager = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
        UserAccountBean ub = (UserAccountBean) session.getAttribute("userBean");
        StudyEventBean seb = (StudyEventBean) session.getAttribute("eventSigned");
        if (securityManager.verifyPassword(password, getUserDetails()) && ub.getName().equals(username)) {
            seb.setUpdater(ub);
            seb.setUpdatedDate(new Date());
            sedao.update(seb);
            // If all the StudyEvents become signed we will make the
            // StudySubject signed as well
            List studyEvents = sedao.findAllByStudySubject(ssub);
            boolean allSigned = true;
            for (Iterator iterator = studyEvents.iterator(); iterator.hasNext(); ) {
                StudyEventBean temp = (StudyEventBean) iterator.next();
                if (!temp.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED)) {
                    allSigned = false;
                    break;
                }
            }
            if (allSigned) {
                logger.debug("Signing StudySubject [" + ssub.getSubjectId() + "]");
                ssub.setStatus(Status.SIGNED);
                ssub.setUpdater(ub);
                ssdao.update(ssub);
            }
            // save discrepancy notes into DB
            FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
            AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
            AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
            AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
            session.removeAttribute("eventSigned");
            request.setAttribute("id", new Integer(studySubjectId).toString());
            addPageMessage(respage.getString("study_event_updated"));
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        } else {
            request.setAttribute(STUDY_SUBJECT_ID, new Integer(studySubjectId).toString());
            request.setAttribute("studyEvent", seb);
            // -------------------
            ssdao = new StudySubjectDAO(sm.getDataSource());
            StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(studyEvent.getStudySubjectId());
            // prepare to figure out what the display should look like
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
            ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
            RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
            StudyBean study = (StudyBean) sdao.findByPK(ssb.getStudyId());
            ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, studyEvent.getStudyEventDefinitionId());
            ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
            populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
            ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, studyEvent.getSubjectEventStatus(), study);
            request.setAttribute("studySubject", ssb);
            request.setAttribute("uncompletedEventDefinitionCRFs", uncompletedEventDefinitionCRFs);
            request.setAttribute("displayEventCRFs", displayEventCRFs);
            // ------------------
            request.setAttribute("studyEvent", session.getAttribute("eventSigned"));
            addPageMessage(restext.getString("password_match"));
            forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
        }
    } else {
        logger.debug("no action, go to update page");
        DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
        StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByPK(studyEvent.getStudySubjectId());
        int studyId = studySubjectBean.getStudyId();
        boolean subjectStudyIsCurrentStudy = studyId == currentStudy.getId();
        boolean isParentStudy = studyBean.getParentStudyId() < 1;
        ArrayList<DiscrepancyNoteBean> allNotesforSubjectAndEvent = new ArrayList<DiscrepancyNoteBean>();
        if (subjectStudyIsCurrentStudy && isParentStudy) {
            allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudyAndId(currentStudy, studySubjectBean.getId());
        } else {
            // findAllStudyEventByStudiesAndSubjectId
            if (!isParentStudy) {
                StudyBean stParent = (StudyBean) sdao.findByPK(studyBean.getParentStudyId());
                allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(stParent, studyBean, studySubjectBean.getId());
            } else {
                allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(currentStudy, studyBean, studySubjectBean.getId());
            }
        }
        if (!allNotesforSubjectAndEvent.isEmpty()) {
            setRequestAttributesForNotes(allNotesforSubjectAndEvent);
        }
        HashMap presetValues = new HashMap();
        // YW 08-17-2007 <<
        if (studyEvent.getStartTimeFlag() == true) {
            Calendar c = new GregorianCalendar();
            c.setTime(studyEvent.getDateStarted());
            presetValues.put(INPUT_STARTDATE_PREFIX + "Hour", new Integer(c.get(Calendar.HOUR_OF_DAY)));
            presetValues.put(INPUT_STARTDATE_PREFIX + "Minute", new Integer(c.get(Calendar.MINUTE)));
            // necessary.
            switch(c.get(Calendar.AM_PM)) {
                case 0:
                    presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "am");
                    break;
                case 1:
                    presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "pm");
                    break;
                default:
                    presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "");
                    break;
            }
        } else {
            presetValues.put(INPUT_STARTDATE_PREFIX + "Hour", new Integer(-1));
            presetValues.put(INPUT_STARTDATE_PREFIX + "Minute", new Integer(-1));
            presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "");
        }
        // YW >>
        String dateValue = local_df.format(studyEvent.getDateStarted());
        presetValues.put(INPUT_STARTDATE_PREFIX + "Date", dateValue);
        // YW 3-12-2008, add end datetime for 2220 fix<<
        presetValues.put(INPUT_ENDDATE_PREFIX + "Hour", new Integer(-1));
        presetValues.put(INPUT_ENDDATE_PREFIX + "Minute", new Integer(-1));
        presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "");
        if (studyEvent.getDateEnded() != null) {
            if (studyEvent.getEndTimeFlag() == true) {
                Calendar c = new GregorianCalendar();
                c.setTime(studyEvent.getDateEnded());
                presetValues.put(INPUT_ENDDATE_PREFIX + "Hour", new Integer(c.get(Calendar.HOUR_OF_DAY)));
                presetValues.put(INPUT_ENDDATE_PREFIX + "Minute", new Integer(c.get(Calendar.MINUTE)));
                // necessary.
                switch(c.get(Calendar.AM_PM)) {
                    case 0:
                        presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "am");
                        break;
                    case 1:
                        presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "pm");
                        break;
                    default:
                        presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "");
                        break;
                }
            }
            presetValues.put(INPUT_ENDDATE_PREFIX + "Date", local_df.format(studyEvent.getDateEnded()));
        }
        // YW >>
        setPresetValues(presetValues);
        request.setAttribute("studyEvent", studyEvent);
        request.setAttribute("studySubject", studySubjectBean);
        discNotes = new FormDiscrepancyNotes();
        session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
        forwardPage(Page.UPDATE_STUDY_EVENT);
    }
// else
}
Also used : RuleSetDAO(org.akaza.openclinica.dao.rule.RuleSetDAO) SecurityManager(org.akaza.openclinica.core.SecurityManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) HashSet(java.util.HashSet) Status(org.akaza.openclinica.bean.core.Status) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) DiscrepancyValidator(org.akaza.openclinica.control.form.DiscrepancyValidator) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) 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) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DiscrepancyNoteUtil (org.akaza.openclinica.service.DiscrepancyNoteUtil)10 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)7 ArrayList (java.util.ArrayList)6 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)6 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)6 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)6 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)6 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)6 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)6 Date (java.util.Date)5 HashMap (java.util.HashMap)5 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)5 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)5 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)5 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)5 Map (java.util.Map)4 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)4 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)4