Search in sources :

Example 1 with ListNotesFilter

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

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

the class ListNotesTableFactory method getListNoteFilter.

/**
     * A very custom way to filter the items. The AuditUserLoginFilter acts as a command for the Hibernate criteria object. Take the Limit information and
     * filter the rows.
     *
     * @param limit
     *            The Limit to use.
     */
public ListNotesFilter getListNoteFilter(Limit limit) {
    ListNotesFilter listNotesFilter = new ListNotesFilter();
    FilterSet filterSet = limit.getFilterSet();
    Collection<Filter> filters = filterSet.getFilters();
    for (Filter filter : filters) {
        String property = filter.getProperty();
        String value = filter.getValue();
        //Checking if the given date format is valid
        if ("discrepancyNoteBean.createdDate".equalsIgnoreCase(property) || "discrepancyNoteBean.updatedDate".equalsIgnoreCase(property)) {
            try {
                String date = formatDate(new Date(value));
                value = date;
            } catch (Exception ex) {
                value = "01-Jan-1700";
            }
        } else if ("discrepancyNoteBean.disType".equalsIgnoreCase(property)) {
            ResourceBundle reterm = ResourceBundleProvider.getTermsBundle();
            if (reterm.getString("Query_and_Failed_Validation_Check").equals(value)) {
                value = 31 + "";
            } else {
                value = DiscrepancyNoteType.getByName(value).getId() + "";
            }
        } else if ("discrepancyNoteBean.resolutionStatus".equalsIgnoreCase(property)) {
            ResourceBundle reterm = ResourceBundleProvider.getTermsBundle();
            if (reterm.getString("New_and_Updated").equalsIgnoreCase(value)) {
                value = 21 + "";
            } else {
                value = ResolutionStatus.getByName(value).getId() + "";
            }
        }
        //
        listNotesFilter.addFilter(property, value);
    }
    return listNotesFilter;
}
Also used : FilterSet(org.jmesa.limit.FilterSet) ListNotesFilter(org.akaza.openclinica.dao.managestudy.ListNotesFilter) DropdownFilter(org.akaza.openclinica.control.DropdownFilter) ListNotesFilter(org.akaza.openclinica.dao.managestudy.ListNotesFilter) Filter(org.jmesa.limit.Filter) ResourceBundle(java.util.ResourceBundle) Date(java.util.Date) MissingResourceException(java.util.MissingResourceException)

Aggregations

ListNotesFilter (org.akaza.openclinica.dao.managestudy.ListNotesFilter)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)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 DropdownFilter (org.akaza.openclinica.control.DropdownFilter)1 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)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 Filter (org.jmesa.limit.Filter)1 FilterSet (org.jmesa.limit.FilterSet)1