Search in sources :

Example 86 with DiscrepancyNoteBean

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

the class DownloadDiscrepancyNote method serializeThreadsToPDF.

public void serializeThreadsToPDF(List<DiscrepancyNoteThread> listOfThreads, OutputStream stream, String studyIdentifier) {
    ServletOutputStream servletStream = (ServletOutputStream) stream;
    Document pdfDoc = new Document();
    try {
        PdfWriter.getInstance(pdfDoc, servletStream);
        pdfDoc.open();
        //Create header for the study identifier or name
        if (studyIdentifier != null) {
            HeaderFooter header = new HeaderFooter(new Phrase("Study Identifier: " + studyIdentifier + " pg."), true);
            header.setAlignment(Element.ALIGN_CENTER);
            Paragraph para = new Paragraph("Study Identifier: " + studyIdentifier, new Font(Font.HELVETICA, 18, Font.BOLD, new Color(0, 0, 0)));
            para.setAlignment(Element.ALIGN_CENTER);
            pdfDoc.setHeader(header);
            pdfDoc.add(para);
        }
        for (DiscrepancyNoteThread discNoteThread : listOfThreads) {
            pdfDoc.add(this.createTableThreadHeader(discNoteThread));
            //Just the parent of the thread?  discNoteThread.getLinkedNoteList()
            for (DiscrepancyNoteBean discNoteBean : discNoteThread.getLinkedNoteList()) {
                //DiscrepancyNoteBean discNoteBean = discNoteThread.getLinkedNoteList().getFirst();
                if (discNoteBean.getParentDnId() > 0) {
                    pdfDoc.add(this.createTableFromBean(discNoteBean));
                    pdfDoc.add(new Paragraph("\n"));
                }
            }
        }
    //pdfDoc.add(new Paragraph(content));
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    pdfDoc.close();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) Color(java.awt.Color) DocumentException(com.lowagie.text.DocumentException) HeaderFooter(com.lowagie.text.HeaderFooter) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph) DiscrepancyNoteThread(org.akaza.openclinica.service.DiscrepancyNoteThread)

Example 87 with DiscrepancyNoteBean

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

the class DownloadDiscrepancyNote method downLoadThreadedDiscBeans.

public void downLoadThreadedDiscBeans(List<DiscrepancyNoteThread> listOfThreadedBeans, String format, HttpServletResponse response, String studyIdentifier) throws Exception {
    if (listOfThreadedBeans == null) {
        return;
    }
    StringBuilder allContent = new StringBuilder();
    String singleBeanContent = "";
    int counter = 0;
    int threadCounter = 0;
    if (CSV.equalsIgnoreCase(format)) {
        for (DiscrepancyNoteThread dnThread : listOfThreadedBeans) {
            threadCounter++;
            for (DiscrepancyNoteBean discNoteBean : dnThread.getLinkedNoteList()) {
                //DiscrepancyNoteBean discNoteBean = dnThread.getLinkedNoteList().getFirst();
                ++counter;
                singleBeanContent = counter == 1 ? serializeToString(discNoteBean, true, threadCounter) : serializeToString(discNoteBean, false, threadCounter);
                allContent.append(singleBeanContent);
            }
        }
    }
    //This must be a ServletOutputStream for our purposes
    ServletOutputStream servletStream = null;
    try {
        if (CSV.equalsIgnoreCase(format)) {
            String result = StringEscapeUtils.unescapeJava(allContent.toString());
            response.getWriter().print(result);
        //servletStream.print(allContent.toString());
        } else {
            //Create PDF version
            //this.serializeListToPDF(listOfBeans,servletStream, studyIdentifier);
            servletStream = (ServletOutputStream) response.getOutputStream();
            this.serializeThreadsToPDF(listOfThreadedBeans, servletStream, studyIdentifier);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (servletStream != null) {
            try {
                servletStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) IOException(java.io.IOException) DiscrepancyNoteThread(org.akaza.openclinica.service.DiscrepancyNoteThread)

Example 88 with DiscrepancyNoteBean

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

the class DownloadDiscrepancyNote method serializeToString.

public String serializeToString(EntityBean bean, boolean includeHeaderRow, int threadNumber) {
    DiscrepancyNoteBean discNoteBean = (DiscrepancyNoteBean) bean;
    StringBuilder writer = new StringBuilder("");
    //for CSV format
    if (includeHeaderRow) {
        writer.append("Study Subject ID");
        writer.append(",");
        writer.append("Subject Status");
        writer.append(",");
        writer.append("Study/Site OID");
        writer.append(",");
        //we're adding a thread number row
        writer.append("Thread ID");
        writer.append(",");
        writer.append("Note ID");
        writer.append(",");
        writer.append("Parent Note ID");
        writer.append(",");
        writer.append("Date Created");
        writer.append(",");
        writer.append("Date Update");
        writer.append(",");
        writer.append("Days Open");
        writer.append(",");
        writer.append("Days Since Updated");
        writer.append(",");
        if (discNoteBean.getDisType() != null) {
            writer.append("Discrepancy Type");
            writer.append(",");
        }
        writer.append("Resolution Status");
        writer.append(",");
        writer.append("Event Name");
        writer.append(",");
        writer.append("Event Occurrence");
        writer.append(",");
        writer.append("CRF Name");
        writer.append(",");
        writer.append("CRF Status");
        writer.append(",");
        writer.append("Group Label");
        writer.append(",");
        writer.append("Group Ordinal");
        writer.append(",");
        writer.append("Entity name");
        writer.append(",");
        writer.append("Entity value");
        writer.append(",");
        writer.append("Description");
        writer.append(",");
        writer.append("Detailed Notes");
        writer.append(",");
        writer.append("Assigned User");
        writer.append(",");
        writer.append("Study Id");
        writer.append("\n");
    }
    //Fields with embedded commas must be
    // delimited with double-quote characters.
    writer.append(escapeQuotesInCSV(discNoteBean.getStudySub().getLabel()));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getStudySub().getStatus().getName()));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getStudy().getOid()));
    writer.append(",");
    writer.append(escapeQuotesInCSV(threadNumber + ""));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getId() + ""));
    writer.append(",");
    writer.append(discNoteBean.getParentDnId() > 0 ? discNoteBean.getParentDnId() : "");
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getCreatedDateString() + ""));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getUpdatedDateString() + ""));
    writer.append(",");
    if (discNoteBean.getParentDnId() == 0) {
        writer.append(escapeQuotesInCSV(discNoteBean.getAge() + ""));
        writer.append(",");
        String daysSinceUpdated = escapeQuotesInCSV(discNoteBean.getDays() + "");
        writer.append(daysSinceUpdated.equals("0") ? "" : daysSinceUpdated);
        writer.append(",");
    } else {
        writer.append(",");
        writer.append(",");
    }
    if (discNoteBean.getDisType() != null) {
        writer.append(escapeQuotesInCSV(discNoteBean.getDisType().getName()));
        writer.append(",");
    }
    writer.append(escapeQuotesInCSV(RESOLUTION_STATUS_MAP.get(discNoteBean.getResolutionStatusId()) + ""));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getEventName()));
    writer.append(",");
    String eventOccurrence = null != discNoteBean.getStudyEventDefinitionBean() && discNoteBean.getStudyEventDefinitionBean().isRepeating() ? String.valueOf(discNoteBean.getEvent().getSampleOrdinal()) : "";
    writer.append(escapeQuotesInCSV(eventOccurrence));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getCrfName()));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getCrfStatus()));
    writer.append(",");
    String itemGroupName = discNoteBean.getItemGroupName() == null ? "" : String.valueOf(discNoteBean.getItemGroupName());
    writer.append(escapeQuotesInCSV(itemGroupName));
    writer.append(",");
    String itemDataOccurence = discNoteBean.getItemDataOrdinal() == null ? "" : String.valueOf(discNoteBean.getItemDataOrdinal());
    writer.append(escapeQuotesInCSV(itemDataOccurence));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getEntityName()));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getEntityValue()));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getDescription() + ""));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getDetailedNotes() + ""));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getAssignedUser().getName()));
    writer.append(",");
    writer.append(escapeQuotesInCSV(discNoteBean.getStudyId() + ""));
    writer.append("\n");
    return writer.toString();
}
Also used : DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)

Example 89 with DiscrepancyNoteBean

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

the class DownloadDiscrepancyNote method createThreadHeader.

private Paragraph createThreadHeader(DiscrepancyNoteThread discNoteThread) {
    String content = "";
    int size = discNoteThread.getLinkedNoteList().size();
    int counter = 0;
    for (DiscrepancyNoteBean discBean : discNoteThread.getLinkedNoteList()) {
        ++counter;
        content += discBean.getEntityName() + "; " + RESOLUTION_STATUS_MAP.get(discBean.getResolutionStatusId());
        if (size > 1 && counter != size) {
            content += " --->";
        }
    }
    Paragraph para = new Paragraph(content, new Font(Font.HELVETICA, 16, Font.BOLD, new Color(0, 0, 0)));
    return para;
}
Also used : DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) Color(java.awt.Color) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Example 90 with DiscrepancyNoteBean

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

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