Search in sources :

Example 1 with DownloadDiscrepancyNote

use of org.akaza.openclinica.bean.extract.DownloadDiscrepancyNote 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)

Aggregations

ArrayList (java.util.ArrayList)1 DownloadDiscrepancyNote (org.akaza.openclinica.bean.extract.DownloadDiscrepancyNote)1 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)1 ListNotesFilter (org.akaza.openclinica.dao.managestudy.ListNotesFilter)1 DiscrepancyNoteThread (org.akaza.openclinica.service.DiscrepancyNoteThread)1 DiscrepancyNoteUtil (org.akaza.openclinica.service.DiscrepancyNoteUtil)1 ViewNotesFilterCriteria (org.akaza.openclinica.service.managestudy.ViewNotesFilterCriteria)1 ViewNotesService (org.akaza.openclinica.service.managestudy.ViewNotesService)1