List of usage examples for com.lowagie.text.pdf PdfCopyFields getWriter
public PdfWriter getWriter()
From source file:ErrMsgException.java
License:Open Source License
public static void main(String args[]) { // ?// w w w . j a va 2 s . co m if (args.length < 3 || args.length > 5) { usage(); return; } // ?? ArrayList<HashMap> bookmark = new ArrayList<HashMap>(); HashMap<String, Object> lastmap = null; ArrayDeque<ArrayList> queue = new ArrayDeque<ArrayList>(); queue.push(bookmark); // ????? try { File file = new File(args[2]); BufferedReader br = new BufferedReader(new FileReader(file)); String line; int previouslevel = 0; int lno = 0; while ((line = br.readLine()) != null) { lno++; if (line.startsWith("#")) continue; // ?# int level = 0; if (line.startsWith("\t")) { // do { line = line.substring(1); level++; } while (line.startsWith("\t")); } String lines[] = line.split("\t"); line = ""; if (lines.length > 2) { for (int i = 0; i < lines.length - 1; i++) { line += lines[i]; if (i < lines.length - 1) line += ""; } } else { line = lines[0]; } if (lines.length < 2) continue; int preample = 0; if (args.length >= 4) { preample = Integer.parseInt(args[3]); } int page = roman2arabic(lines[lines.length - 1], preample); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("Title", line); map.put("Action", "GoTo"); map.put("Page", page + " Fit"); if (args.length >= 5) { // ?? int foldlevel = Integer.parseInt(args[4]); if (foldlevel <= level) map.put("Open", "false"); } if (level > previouslevel) { if (level - previouslevel > 1) { // ??? throw new ErrMsgException( lno + ": ??2?????????"); } // ArrayList<HashMap> kids = new ArrayList<HashMap>(); kids.add(map); if (lastmap != null) { lastmap.put("Kids", kids); } else { throw new ErrMsgException( lno + ": ??????????"); } queue.push(kids); } else if (level < previouslevel) { // ? for (int i = previouslevel; i > level; i--) { queue.pop(); } queue.peek().add(map); } else { // ???????? queue.peek().add(map); } lastmap = map; previouslevel = level; } br.close(); } catch (IOException e) { System.out.println(e); return; } catch (ErrMsgException e) { System.out.println("?????\n" + e.getMessage()); return; } // PDF???? try { PdfReader reader = new PdfReader(args[0]); int maxpage = reader.getNumberOfPages(); OutputStream os = new FileOutputStream(args[1]); PdfCopyFields copyFields = new PdfCopyFields(os); copyFields.addDocument(reader); copyFields.setOutlines(bookmark); if (args.length > 3) { // ? PdfPageLabels labels = new PdfPageLabels(); if (maxpage > 0) labels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS, null, 1); if (maxpage > Integer.parseInt(args[3])) labels.addPageLabel(Integer.parseInt(args[3]) + 1, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, null, 1); copyFields.getWriter().setPageLabels(labels); } copyFields.close(); os.close(); } catch (DocumentException e) { System.out.println(e); return; } catch (IOException e) { System.out.println(e); return; } System.out.println(args[1] + " ?????"); }
From source file:org.oscarehr.eyeform.web.EyeformAction.java
License:Open Source License
public void doPrint(HttpServletRequest request, OutputStream os) throws IOException, DocumentException { String ids[] = request.getParameter("apptNos").split(","); String providerNo = LoggedInInfo.loggedInInfo.get().loggedInProvider.getProviderNo(); String cpp = request.getParameter("cpp"); boolean cppFromMeasurements = false; if (cpp != null && cpp.equals("measurements")) { cppFromMeasurements = true;/*from ww w . j av a 2 s . com*/ } String[] customCppIssues = OscarProperties.getInstance().getProperty("encounter.custom_cpp_issues", "") .split(","); PdfCopyFields finalDoc = new PdfCopyFields(os); finalDoc.getWriter().setStrictImageSequence(true); PdfRecordPrinter printer = new PdfRecordPrinter(request, os); int pageNum = 0; //loop through each visit..concatenate into 1 PDF for (int x = 0; x < ids.length; x++) { if (!StringUtils.isBlank(ids[x])) { int appointmentNo = Integer.parseInt(ids[x]); Appointment appointment = appointmentDao.find(appointmentNo); if (appointment == null) continue; else pageNum++; if (pageNum > 1) { printer.setNewPage(true); } Demographic demographic = demographicDao.getClientByDemographicNo(appointment.getDemographicNo()); printer.setDemographic(demographic); printer.setAppointment(appointment); //need to get notes first to set the signing provider List<CaseManagementNote> notes = caseManagementNoteDao .getMostRecentNotesByAppointmentNo(appointmentNo); notes = filterOutCpp(notes); if (notes.size() > 0) { String tmp = notes.get(0).getSigning_provider_no(); if (tmp != null && tmp.length() > 0) { Provider signingProvider = providerDao.getProvider(tmp); if (signingProvider != null) { printer.setSigningProvider(signingProvider.getFormattedName()); } } } printer.printDocHeaderFooter(); //get cpp items by appointmentNo (current history,past ocular hx, //medical hx, ocular meds, other meds, diagnostic notes /* if(cppFromMeasurements) { printCppItemFromMeasurements(printer,"Current History","cpp_currentHis",demographic.getDemographicNo(), appointmentNo, false); printCppItemFromMeasurements(printer,"Past Ocular History","cpp_pastOcularHis",demographic.getDemographicNo(), appointmentNo, true); printCppItemFromMeasurements(printer,"Medical History","cpp_medicalHis",demographic.getDemographicNo(), appointmentNo, true); printCppItemFromMeasurements(printer,"Family History","cpp_familyHis",demographic.getDemographicNo(), appointmentNo, true); printCppItemFromMeasurements(printer,"Diagnostic Notes","cpp_diagnostics",demographic.getDemographicNo(), appointmentNo, false); printCppItemFromMeasurements(printer,"Ocular Medication","cpp_ocularMeds",demographic.getDemographicNo(), appointmentNo, true); } else { */ Boolean includeCPPForPrevAppts = null; OscarProperties oscarProperties = OscarProperties.getInstance(); String eyeform_onlyPrintCurrentVisit = oscarProperties.getProperty("eyeform_onlyPrintCurrentVisit"); // if eyeform_onlyPrintCurrentVisit is not set at all then it should work as previously.. if (eyeform_onlyPrintCurrentVisit != null && eyeform_onlyPrintCurrentVisit.trim().length() > 0) { eyeform_onlyPrintCurrentVisit = eyeform_onlyPrintCurrentVisit.trim(); boolean onlyPrintCurrentApptRecordsFromEncounter = Boolean .parseBoolean(eyeform_onlyPrintCurrentVisit); //if only print current appt.. then includeCPPForPrevAppts = false if (onlyPrintCurrentApptRecordsFromEncounter) includeCPPForPrevAppts = false; else includeCPPForPrevAppts = true; } String whichEyeForm = OscarProperties.getInstance().getProperty("cme_js", ""); IssueDAO issueDao = (IssueDAO) SpringUtils.getBean("IssueDAO"); for (String customCppIssue : customCppIssues) { //Don't need to print out patient log if (customCppIssue != null && (customCppIssue.equalsIgnoreCase("PatientLog") || customCppIssue.equalsIgnoreCase("GlaucomaRiskFactors"))) continue; if (includeCPPForPrevAppts != null) { if (customCppIssue != null && customCppIssue.equalsIgnoreCase("GlaucomaRiskFactors")) { //For Dr.Jinapriya, replace PatientLog with GlaucomaRiskFactors, but still use PatientLog issue. Issue i = issueDao.findIssueByCode("PatientLog"); if (i != null) { printCppItem(printer, "Glaucoma Risk Factors", "PatientLog", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); } } else { //="PatientLog", or Misc Issue issue = issueDao.findIssueByCode(customCppIssue); if (issue != null) { printCppItem(printer, issue.getDescription(), customCppIssue, demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); } } } else { if (customCppIssue != null && customCppIssue.equalsIgnoreCase("GlaucomaRiskFactors")) { //For Dr.Jinapriya, replace PatientLog with GlaucomaRiskFactors, but still use PatientLog issue. Issue i = issueDao.findIssueByCode("PatientLog"); if (i != null) { printCppItem(printer, "Glaucoma Risk Factors", "PatientLog", demographic.getDemographicNo(), appointmentNo, true); } } else { //="PatientLog", or Misc Issue issue = issueDao.findIssueByCode(customCppIssue); if (issue != null) { printCppItem(printer, issue.getDescription(), customCppIssue, demographic.getDemographicNo(), appointmentNo, true); } } } } if (includeCPPForPrevAppts != null) { if (whichEyeForm != null && whichEyeForm.equalsIgnoreCase("eyeform_DrJinapriya")) { printCppItem(printer, "Subjective", "CurrentHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Past Ocular History", "PastOcularHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Medical History", "MedHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Ocular Diagnoses", "FamHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Objective", "DiagnosticNotes", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Drops Administered This Visit", "OcularMedication", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Systemic Meds", "OMeds", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); } else { printCppItem(printer, "Current History", "CurrentHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Past Ocular History", "PastOcularHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Medical History", "MedHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Family History", "FamHistory", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Diagnostic Notes", "DiagnosticNotes", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Ocular Medications", "OcularMedication", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); printCppItem(printer, "Other Medications", "OMeds", demographic.getDemographicNo(), appointmentNo, includeCPPForPrevAppts); } } else { if (whichEyeForm != null && whichEyeForm.equalsIgnoreCase("eyeform_DrJinapriya")) { printCppItem(printer, "Subjective", "CurrentHistory", demographic.getDemographicNo(), appointmentNo, false); printCppItem(printer, "Past Ocular History", "PastOcularHistory", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Medical History", "MedHistory", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Ocular Diagnoses", "FamHistory", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Objective", "DiagnosticNotes", demographic.getDemographicNo(), appointmentNo, false); printCppItem(printer, "Drops Administered This Visit", "OcularMedication", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Systemic Meds", "OMeds", demographic.getDemographicNo(), appointmentNo, true); } else { //work as it is printCppItem(printer, "Current History", "CurrentHistory", demographic.getDemographicNo(), appointmentNo, false); printCppItem(printer, "Past Ocular History", "PastOcularHistory", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Medical History", "MedHistory", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Family History", "FamHistory", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Diagnostic Notes", "DiagnosticNotes", demographic.getDemographicNo(), appointmentNo, false); printCppItem(printer, "Ocular Medications", "OcularMedication", demographic.getDemographicNo(), appointmentNo, true); printCppItem(printer, "Other Medications", "OMeds", demographic.getDemographicNo(), appointmentNo, true); } } printer.setNewPage(true); //ocular procs List<EyeformOcularProcedure> ocularProcs = null; if (includeCPPForPrevAppts == null || includeCPPForPrevAppts == true) ocularProcs = ocularProcDao.getAllPreviousAndCurrent(demographic.getDemographicNo(), appointmentNo); else ocularProcs = ocularProcDao.getAllCurrent(demographic.getDemographicNo(), appointmentNo); if (ocularProcs.size() > 0) { printer.printOcularProcedures(ocularProcs); } //specs history List<EyeformSpecsHistory> specsHistory; if (includeCPPForPrevAppts == null || includeCPPForPrevAppts == true) specsHistory = specsHistoryDao.getAllPreviousAndCurrent(demographic.getDemographicNo(), appointmentNo); else specsHistory = specsHistoryDao.getAllCurrent(demographic.getDemographicNo(), appointmentNo); if (specsHistory.size() > 0) { printer.printSpecsHistory(specsHistory); } //allergies List<Allergy> allergies = allergyDao.findAllergies(demographic.getDemographicNo()); if (allergies.size() > 0) { printer.printAllergies(allergies); } //rx printer.printRx(String.valueOf(demographic.getDemographicNo())); //measurements List<Measurements> measurements = measurementsDao.getMeasurementsByAppointment2(appointmentNo); if (measurements.size() > 0) { /* if(cppFromMeasurements) { if(getNumMeasurementsWithoutCpp(measurements)>0) { MeasurementFormatter formatter = new MeasurementFormatter(measurements); printer.printEyeformMeasurements(formatter); } } else { */ MeasurementFormatter formatter = new MeasurementFormatter(measurements); printer.printEyeformMeasurements(formatter); // } } //impression //let's filter out custom cpp notes, as they will already have been //printed out in CPP section List<CaseManagementNote> filteredNotes = new ArrayList<CaseManagementNote>(); for (CaseManagementNote note : notes) { boolean okToAdd = true; for (String i : customCppIssues) { if (i.equalsIgnoreCase("GlaucomaRiskFactors")) { //Dr.Jinapriy's GlaucomaRiskFactors=PatientLog in eyeform2 from Dr.Eric Tam if (containsIssue(note.getId().intValue(), "PatientLog")) { okToAdd = false; break; } } else { if (containsIssue(note.getId().intValue(), i)) { okToAdd = false; break; } } } if (okToAdd) filteredNotes.add(note); } if (filteredNotes.size() > 0) { printer.printNotes(filteredNotes); } //plan - followups/consults, procedures booked, tests booked, checkboxes /* List<FollowUp> followUps = followUpDao.getByAppointmentNo(appointmentNo); List<ProcedureBook> procedureBooks = procedureBookDao.getByAppointmentNo(appointmentNo); List<TestBookRecord> testBooks = testBookDao.getByAppointmentNo(appointmentNo); EyeForm eyeform = eyeFormDao.getByAppointmentNo(appointmentNo); printer.printEyeformPlan(followUps, procedureBooks, testBooks,eyeform); */ //photos DocumentResultsDao documentDao = (DocumentResultsDao) SpringUtils.getBean("documentResultsDao"); List<Document> documents = documentDao.getPhotosByAppointmentNo(appointmentNo); if (documents.size() > 0) { String servletUrl = request.getRequestURL().toString(); String url = servletUrl.substring(0, servletUrl.indexOf(request.getContextPath()) + request.getContextPath().length()); printer.printPhotos(url, documents); } //diagrams EFormValueDao eFormValueDao = (EFormValueDao) SpringUtils.getBean("EFormValueDao"); EFormGroupDao eFormGroupDao = (EFormGroupDao) SpringUtils.getBean("EFormGroupDao"); List<EFormGroup> groupForms = eFormGroupDao.getByGroupName("Eye form"); List<EFormValue> values = eFormValueDao.findByApptNo(appointmentNo); List<EFormValue> diagrams = new ArrayList<EFormValue>(); for (EFormValue value : values) { int formId = value.getFormId(); boolean include = false; for (EFormGroup group : groupForms) { if (group.getFormId() == formId) { include = true; break; } } if (include) diagrams.add(value); } if (diagrams.size() > 0) { printer.printDiagrams(diagrams); } } //!=null } //end of loop if (pageNum == 0) { printer.setNewPage(true); } printer.finish(); }