Logic.DocsCreation.java Source code

Java tutorial

Introduction

Here is the source code for Logic.DocsCreation.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Logic;

import DB.StartDB;
import GUI.AdminJFrame;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import javax.swing.JTable;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 *
 * @author 
 */
public class DocsCreation {
    String log4jConfPath = "./src/resources/log4j.properties";
    GetServiceNorm norm = new GetServiceNorm();
    private boolean flagExistNorm;
    private String[] arrNorm;

    public DocsCreation() {
        PropertyConfigurator.configure(log4jConfPath);
    }

    private static final Logger log = Logger.getLogger(AdminJFrame.class);

    public void createPdfDoc(JTable Table, GetPatientData data, StartDB con, boolean flag,
            ArrayList<String> arrPatient, String crb) {
        try {
            norm.getNorm(con.getConnection());
            int b = arrPatient.size();
            if (b == -1) {
                return;
            }
            String path = System.getProperty("user.home");
            path = path + "//Desktop//";
            File theDir = new File(path, "???");
            // if the directory does not exist, create it
            if (!theDir.exists()) {

                boolean result = false;

                try {
                    theDir.mkdir();
                    result = true;
                } catch (SecurityException se) {
                    //handle it
                }
                if (result) {
                    System.out.println("DIR created");
                }
            }
            for (int k = 0; k < b; k++) {
                String id = arrPatient.get(k);//Table.getModel().getValueAt(k, 0).toString(); 
                data = new GetPatientData();
                data.getMainData(con.getConnection(), id, crb);
                data.getPatientDocs(con.getConnection(), id);
                String[] arr = null;
                String fname = data.getName().replaceAll(" ", "") + data.getBirth();

                Document doc = new Document();
                String fileName = path + "\\???\\" + fname + ".pdf";
                String pdfName = "";
                FileOutputStream fos = new FileOutputStream(fileName);
                PdfWriter.getInstance(doc, fos);
                doc.open();

                BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\ARIAL.TTF", BaseFont.IDENTITY_H,
                        BaseFont.EMBEDDED);
                BaseFont bfn = BaseFont.createFont("C:\\Windows\\Fonts\\ARIALI.TTF", BaseFont.IDENTITY_H,
                        BaseFont.EMBEDDED);
                // 
                Paragraph title = new Paragraph(data.getCrbName() + "\n", new Font(bf, 16, Font.BOLD));
                title.setAlignment(Element.ALIGN_CENTER);
                doc.add(title);
                // ? 
                Paragraph lpu = new Paragraph("?   " + data.getLpu(), new Font(bf, 12));
                lpu.setAlignment(Element.ALIGN_RIGHT);
                doc.add(lpu);
                doc.add(new Phrase(
                        "____________________________________________________________________________________\n",
                        new Font(bf, 11, Font.BOLD)));

                doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getName() + " (" + data.getSex() + ")\n", new Font(bf, 13)));
                doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getBirth() + "\n", new Font(bf, 13)));
                doc.add(new Phrase(" ? ??: ",
                        new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getDate() + "\n", new Font(bf, 13)));

                if (data.getSnils() != null) {
                    doc.add(new Phrase("? : ", new Font(bf, 13, Font.BOLD)));
                    doc.add(new Phrase(data.getSnils() + "\n", new Font(bf, 13)));
                }
                if (data.getDocs() != null) {
                    doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
                    doc.add(new Phrase(data.getDocs() + " ", new Font(bf, 13)));
                    ;
                }
                if (data.getPolicy() != null) {
                    doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
                    doc.add(new Phrase(data.getPolicy() + "; ", new Font(bf, 13)));
                }

                if (data.getPhone() != null) {
                    doc.add(new Phrase("?  ", new Font(bf, 13, Font.BOLD)));
                    doc.add(new Phrase(data.getPhone() + "; ", new Font(bf, 13)));
                }
                //  ?

                data.getDoneServiceCount(con.getConnection(), id);
                data.getDoneServiceData(con.getConnection(), id);
                // data.getDoneServiceProp(con.getConnection(), id,data.getService_code().get(k));
                //  ?
                doc.add(new Paragraph("\n ?: \n", new Font(bf, 16, Font.BOLD)));

                for (int i = 0; i < data.getCount(); i++) {
                    data.getDoneServiceProp(con.getConnection(), id, data.getService_code().get(i));
                    doc.add(new Phrase(data.getService_name().get(i) + " : \n", new Font(bf, 12, Font.BOLD)));
                    if (data.getService_result().get(i) != null) {
                        arr = data.getService_result().get(i).split(";");

                        for (int l = 0; l < norm.getCode().size(); l++) {
                            if (data.getService_code().get(i).equals(norm.getCode().get(l))) {
                                flagExistNorm = true;
                                if ("".equals(data.getSex()))
                                    arrNorm = norm.getNormsWoman().get(l).split(";");
                                else if ("".equals(data.getSex())) {
                                    arrNorm = norm.getNormsMan().get(l).split(";");
                                }

                                break;
                            } else
                                flagExistNorm = false;
                        }

                        //<editor-fold defaultstate="collapsed" desc="?? ?? ">
                        //                switch(data.getService_name().get(i)){            
                        //                    
                        //                    case "01.?()":
                        //                    doc.add(new Phrase("  ? - " +arr[0]+ " ;\n " ,new Font(bf, 12)));
                        //                    break;
                        //                    
                        //                    case "02.??":                 
                        //                        doc.add(new Phrase("? - " + arr[0] +" ; ",new Font(bf, 12)));
                        //                        doc.add(new Phrase("? - " + arr[2] +" ; ",new Font(bf, 12)));
                        //                        doc.add(new Phrase("?  - " + arr[1] +" ;\n ",new Font(bf, 12)));               
                        //                        break; 
                        //
                        //                    case "03.  ?":                 
                        //                        doc.add(new Phrase("   - " + arr[0] +" ; ",new Font(bf, 12)));
                        //                        doc.add(new Phrase("?   - " + arr[1] +" ;",new Font(bf, 12)));
                        //                        doc.add(new Phrase("? - " + arr[2] +" ;\n ",new Font(bf, 12)));
                        //                        break; 
                        //
                        //                     case "06.?  " :                 
                        //                            
                        //                     {   
                        //                            doc.add(new Phrase("  " +";\n ",new Font(bf, 12)));
                        //                            pdfName = "C:\\MDKTemp\\"+fname+"ECG.pdf";
                        //                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                        //                            targetFile.write(data.getPDFData(con.getConnection(), id));
                        //                            targetFile.close();
                        //                            log.info("pdf  ? "+id+ "?");
                        //                            } catch (Exception ex) {
                        //                                    log.error(ex, ex);                            
                        //                            }
                        //                        }
                        //                     break;         
                        //
                        //                     case "08.? ":                 
                        //                        doc.add(new Phrase(" ?? - " + arr[0] +" ;\n",new Font(bf, 12)));               
                        //                        break; 
                        //
                        //                     case "13.  ":                 
                        //                        doc.add(new Phrase("\n (), / - " + arr[0] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase(", /- " + arr[1] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase(", / - " + arr[2] +" - \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase(" (),-/ - " + arr[3] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase(" (), -/ - " + arr[4] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase("? ? - " + arr[5] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase("pH - " + arr[6] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase(", / - " + arr[7] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase("??? ?, / - " + arr[8] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase("? - " + arr[9] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase(" (), / - " + arr[10] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase(" - " + arr[11] +" ; \n",new Font(bf, 12)));
                        //                        doc.add(new Phrase("? - " + arr[12] +" ;\n",new Font(bf, 12)));
                        //                        break; 
                        //
                        //                        case "16.  ?":                 
                        //                        doc.add(new Phrase(" - " + arr[0] +" ;",new Font(bf, 12)));
                        //                        doc.add(new Phrase(" - " + arr[1] +" ;",new Font(bf, 12)));                
                        //                        break;
                        //                    } 
                        //</editor-fold>    
                        //            
                        int arrSize = arr.length;
                        for (int j = 0; (j < arrSize); j++) {

                            if (data.getService_name().get(i).contains("?")
                                    || data.getService_name().get(i).contains("")) {
                                doc.add(new Phrase("  " + ";\n ", new Font(bf, 12)));
                                pdfName = "C:\\MDKTemp\\" + fname + "ECG.pdf";
                                try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                                    targetFile.write(data.getPDFData(con.getConnection(), id));
                                    targetFile.close();
                                    log.info("pdf  ? " + id + "?");

                                    break;
                                } catch (Exception ex) {
                                    log.error(ex, ex);
                                }
                            }
                            if (flagExistNorm) {
                                String[] border;
                                border = new String[2];

                                border = arrNorm[j].split(" - ");
                                if (Float.parseFloat(arr[j]) >= Float.parseFloat(border[0])) {
                                    if (Float.parseFloat(arr[j]) <= Float.parseFloat(border[1])) {
                                        //   ?

                                        doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                                new Font(bf, 12)));
                                    } else {
                                        //    
                                        doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                                new Font(bf, 12, Font.UNDERLINE)));
                                        if (border[0].equals(border[1])) {
                                            doc.add(new Phrase("! (? " + border[0] + ");\n",
                                                    new Font(bfn, 12, Font.UNDERLINE)));
                                        } else
                                            doc.add(new Phrase(
                                                    "! (? " + border[0] + " - " + border[1] + ");\n",
                                                    new Font(bfn, 12, Font.UNDERLINE)));
                                    }
                                } else {
                                    //    
                                    doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                            new Font(bf, 12, Font.UNDERLINE)));
                                    if (border[0].equals(border[1])) {
                                        doc.add(new Phrase("! (? " + border[0] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                    } else
                                        doc.add(new Phrase(
                                                "! (? " + border[0] + " - " + border[1] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                }
                            } else
                                doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                        new Font(bf, 12)));

                        }

                    }
                }
                //  ?
                data.getAppoitedServiceCount(con.getConnection(), id);
                data.getAppServiceData(con.getConnection(), id);
                doc.add(new Phrase("? ? :\n", new Font(bf, 16, Font.BOLD)));
                for (int j = 0; j < data.getCount(); j++) {
                    if (data.getService_result().get(j) != null) {
                        doc.add(new Phrase(data.getService_name().get(j) + " - ", new Font(bf, 12, Font.BOLD)));
                        doc.add(new Phrase(data.getService_result().get(j) + " ; ", new Font(bf, 12)));
                    }
                    if (data.getService_result().get(j) == null) {
                        doc.add(new Phrase(data.getService_name().get(j) + " ; ", new Font(bf, 12, Font.BOLD)));
                    }
                }
                // 
                data.getRenServiceCount(con.getConnection(), id);
                data.getRenServiceData(con.getConnection(), id);
                doc.add(new Phrase("\n : ", new Font(bf, 16, Font.BOLD)));
                for (int i = 0; i < data.getCount(); i++) {
                    if (data.getService_name().get(i) == null) {
                        doc.add(new Phrase("? ", new Font(bf, 12)));
                    }
                    doc.add(new Phrase(data.getService_name().get(i) + " ; ", new Font(bf, 12, Font.BOLD)));
                }
                // 
                data.getEarlierServiceCount(con.getConnection(), id);
                data.getEarServiceData(con.getConnection(), id);
                doc.add(new Phrase("\n  : ", new Font(bf, 16, Font.BOLD)));
                for (int i = 0; i < data.getCount(); i++) {
                    if (data.getService_result().get(i) != null) {
                        doc.add(new Phrase(data.getService_name().get(i) + " - ", new Font(bf, 12, Font.BOLD)));
                        doc.add(new Phrase(data.getService_date().get(i) + " ; ", new Font(bf, 12)));
                    }
                    if (data.getService_result().get(i) == null) {
                        doc.add(new Phrase(data.getService_name().get(i) + " ;", new Font(bf, 12)));
                    }

                }
                doc.close();
                if (!flag) {
                    if (!pdfName.equals("")) {
                        AddCover1 cov = new AddCover1();
                        String tempFile = fileName;
                        String ECGFile = pdfName;
                        String res = path + "//???//" + fname + "ECG.pdf";
                        File file = new File(res);
                        file.getParentFile().mkdirs();
                        cov.manipulatePdf(ECGFile, res, tempFile);
                        File dfile = new File(fileName);
                        if (dfile.delete()) {
                            System.out.println(dfile.getName() + " is deleted!");
                        } else {
                            System.out.println("Delete operation is failed.");
                        }

                    }
                }

                if (flag) {
                    if (!pdfName.equals("")) {
                        AddCover1 cov = new AddCover1();
                        String tempFile = fileName;
                        String ECGFile = pdfName;
                        String res = "C:\\" + fname + "ECG.pdf";
                        File file = new File(res);
                        file.getParentFile().mkdirs();
                        cov.manipulatePdf(ECGFile, res, tempFile);
                        File dfile = new File(fileName);
                        if (dfile.delete()) {
                            System.out.println(dfile.getName() + " is deleted!");
                        } else {
                            System.out.println("Delete operation is failed.");
                        }

                        File pfile = new File(res);
                        try {
                            Desktop.getDesktop().print(pfile);
                            Thread.sleep(2000);
                        } catch (IOException ex) {
                            log.error(ex, ex);
                        }
                    } else {
                        File pfile = new File(fileName);
                        try {
                            Desktop.getDesktop().print(pfile);
                            Thread.sleep(2000);
                        } catch (IOException ex) {
                            log.error(ex, ex);
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error(e, e);
        }

    }

    //   public void createPrintPdfDoc(JTable Table, GetPatientData data,StartDB con){
    //          try {
    //              norm.getNorm(con.getConnection());
    //            int b = Table.getRowCount();
    //            if(b == -1){
    //                return;
    //            }
    //            for (int k = 0; k < b; k++) {
    //            String id = Table.getModel().getValueAt(k, 0).toString(); 
    //            data = new GetPatientData();
    //            data.getMainData(con.getConnection(), id);
    //            data.getPatientDocs(con.getConnection(), id);
    //            String[] arr = null;
    //            String fname = data.getName().replaceAll(" ","") + data.getBirth();
    //            
    //            Document doc = new Document();
    //            String fileName ="C:\\" + fname + ".pdf";
    //            String pdfName = "";
    //            FileOutputStream fos = new FileOutputStream(fileName);
    //            PdfWriter.getInstance(doc, fos); 
    //            doc.open();
    //            
    //            
    //            BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\ARIAL.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    //            BaseFont bfn = BaseFont.createFont("C:\\Windows\\Fonts\\ARIALI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    //            // 
    //            Paragraph title = new Paragraph(data.getCrbName()+"\n",new Font(bf,16,Font.BOLD));
    //            title.setAlignment(Element.ALIGN_CENTER);
    //            doc.add(title);
    //            // ? 
    //            Paragraph lpu = new Paragraph("?   "+ data.getLpu() ,new Font(bf,12));
    //            lpu.setAlignment(Element.ALIGN_RIGHT);
    //            doc.add(lpu);
    //            doc.add (new Phrase("____________________________________________________________________________________\n",new Font(bf, 11, Font.BOLD)));
    //            
    //            
    //            doc.add (new Phrase(": ",new Font(bf, 13, Font.BOLD)));
    //            doc.add (new Phrase(data.getName()+" ("+data.getSex()+")\n",new Font(bf, 13))); 
    //            doc.add (new Phrase(" ?: ",new Font(bf, 13, Font.BOLD)));
    //            doc.add (new Phrase(data.getBirth()+"\n",new Font(bf, 13))); 
    //            doc.add (new Phrase(" ? ??: ",new Font(bf, 13, Font.BOLD)));
    //            doc.add (new Phrase(data.getDate()+"\n",new Font(bf, 13))); 
    //            
    //            if(data.getSnils()!=null){
    //                doc.add (new Phrase("? : ",new Font(bf, 13, Font.BOLD)));
    //                doc.add (new Phrase(data.getSnils()+"\n",new Font(bf, 13))); 
    //            }
    //            if(data.getPass_ser()!=null){
    //                doc.add (new Phrase("? ??: ",new Font(bf, 13, Font.BOLD)));
    //                doc.add (new Phrase(data.getPass_ser()+"; : ",new Font(bf, 13))); 
    //                doc.add (new Phrase(data.getPass_num()+"; \n",new Font(bf, 13))); 
    //            }
    //            if(data.getOldPol()!=null){
    //                doc.add (new Phrase(" ?(? ) : ",new Font(bf, 13, Font.BOLD)));
    //                doc.add (new Phrase(data.getOldPol()+";  ",new Font(bf, 13))); 
    //            }
    //            if(data.getNewPol()!=null){
    //                doc.add (new Phrase(" ?( ) : ",new Font(bf, 13, Font.BOLD)));
    //                doc.add (new Phrase(data.getNewPol()+"; ",new Font(bf, 13))); 
    //            }
    //            doc.add(new Paragraph("\n ?: \n",new Font(bf, 14, Font.BOLD)));    
    //            //  ?
    //            for (int i = 0; i < data.getCount(); i++) {
    //                data.getDoneServiceProp(con.getConnection(), id,data.getService_code().get(i));
    //                doc.add(new Phrase(data.getService_name().get(i)+ " : \n" ,new Font(bf, 12, Font.BOLD)));
    //                if(data.getService_result().get(i)!= null){
    //                    arr = data.getService_result().get(i).split(";");
    //                for (int l = 0; l < norm.getCode().size(); l++) {
    //                        if (data.getService_code().get(i).equals(norm.getCode().get(l)) ) {
    //                            flagExistNorm = true;
    //                            if ("".equals(data.getSex())) 
    //                                arrNorm = norm.getNormsWoman().get(l).split(";");
    //                            else
    //                                arrNorm = norm.getNormsMan().get(l).split(";");
    //                            break;
    //                        }  
    //                        else
    //                            flagExistNorm = false;
    //                    }
    //                             
    //                //<editor-fold defaultstate="collapsed" desc="?? ?? ">
    //                //                switch(data.getService_name().get(i)){            
    ////                    
    ////                    case "01.?()":
    ////                    doc.add(new Phrase("  ? - " +arr[0]+ " ;\n " ,new Font(bf, 12)));
    ////                    break;
    ////                    
    ////                    case "02.??":                 
    ////                        doc.add(new Phrase("? - " + arr[0] +" ; ",new Font(bf, 12)));
    ////                        doc.add(new Phrase("? - " + arr[2] +" ; ",new Font(bf, 12)));
    ////                        doc.add(new Phrase("?  - " + arr[1] +" ;\n ",new Font(bf, 12)));               
    ////                        break; 
    ////
    ////                    case "03.  ?":                 
    ////                        doc.add(new Phrase("   - " + arr[0] +" ; ",new Font(bf, 12)));
    ////                        doc.add(new Phrase("?   - " + arr[1] +" ;",new Font(bf, 12)));
    ////                        doc.add(new Phrase("? - " + arr[2] +" ;\n ",new Font(bf, 12)));
    ////                        break; 
    ////
    ////                     case "06.?  " :                 
    ////                            
    ////                     {   
    ////                            doc.add(new Phrase("  " +";\n ",new Font(bf, 12)));
    ////                            pdfName = "C:\\MDKTemp\\"+fname+"ECG.pdf";
    ////                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
    ////                            targetFile.write(data.getPDFData(con.getConnection(), id));
    ////                            targetFile.close();
    ////                            log.info("pdf  ? "+id+ "?");
    ////                            } catch (Exception ex) {
    ////                                    log.error(ex, ex);                            
    ////                            }
    ////                        }
    ////                     break;         
    ////
    ////                     case "08.? ":                 
    ////                        doc.add(new Phrase(" ?? - " + arr[0] +" ;\n",new Font(bf, 12)));               
    ////                        break; 
    ////
    ////                     case "13.  ":                 
    ////                        doc.add(new Phrase("\n (), / - " + arr[0] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase(", /- " + arr[1] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase(", / - " + arr[2] +" - \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase(" (),-/ - " + arr[3] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase(" (), -/ - " + arr[4] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase("? ? - " + arr[5] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase("pH - " + arr[6] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase(", / - " + arr[7] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase("??? ?, / - " + arr[8] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase("? - " + arr[9] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase(" (), / - " + arr[10] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase(" - " + arr[11] +" ; \n",new Font(bf, 12)));
    ////                        doc.add(new Phrase("? - " + arr[12] +" ;\n",new Font(bf, 12)));
    ////                        break; 
    ////
    ////                        case "16.  ?":                 
    ////                        doc.add(new Phrase(" - " + arr[0] +" ;",new Font(bf, 12)));
    ////                        doc.add(new Phrase(" - " + arr[1] +" ;",new Font(bf, 12)));                
    ////                        break;
    ////                    } 
    ////</editor-fold>              
    //                    int arrSize = arr.length;     
    //                    for (int j = 0 ; (j < arrSize ); j++) {
    //                        
    //                        if (data.getService_name().get(i).contains("?") || data.getService_name().get(i).contains("")) {
    //                            doc.add(new Phrase("  " +";\n ",new Font(bf, 12)));
    //                            pdfName = "C:\\MDKTemp\\"+fname+"ECG.pdf";
    //                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
    //                                targetFile.write(data.getPDFData(con.getConnection(), id));
    //                                targetFile.close();                           
    //                                log.info("pdf  ? "+id+ "?");
    //                               
    //                                break;
    //                            } catch (Exception ex) {
    //                                    log.error(ex, ex);                            
    //                            }
    //                        }
    //                    if (flagExistNorm) {
    //                        String[] border;
    //
    //                        border = arrNorm[j].split(" - ");
    //                        if (Float.parseFloat(arr[j]) >= Float.parseFloat(border[0])) {
    //                            if (Float.parseFloat(arr[j]) <= Float.parseFloat(border[1])) {
    //                                //   ?
    //
    //                                doc.add(new Phrase(data.getService_prop().get(j)+ " - " + arr[j] +" ;\n",new Font(bf, 12)));
    //                            }
    //                            else{
    //                            //    
    //                                doc.add(new Phrase(data.getService_prop().get(j)+ " - " + arr[j] +" ; ",new Font(bf, 12, Font.UNDERLINE)));
    //                                if (border[0].equals(border[1])) {
    //                                    doc.add(new Phrase("! (? "+border[0]+");\n",new Font(bfn, 12, Font.UNDERLINE)));
    //                                }
    //                                else
    //                                    doc.add(new Phrase("! (? "+border[0]+" - "+border[1]+");\n",new Font(bfn, 12, Font.UNDERLINE)));
    //                            }
    //                        }
    //                        else{
    //                        //    
    //                       // doc.add(new Phrase(data.getService_prop().get(j)+ " - " + arr[j] +" ; ! (? "+border[0]+" - "+border[1]+");\n",new Font(bfn, 12)));
    //                        doc.add(new Phrase(data.getService_prop().get(j)+ " - " + arr[j] +" ; ",new Font(bf, 12, Font.UNDERLINE)));
    //                            if (border[0].equals(border[1])) {
    //                                    doc.add(new Phrase("! (? "+border[0]+");\n",new Font(bfn, 12, Font.UNDERLINE)));
    //                                }
    //                                else
    //                                    doc.add(new Phrase("! (? "+border[0]+" - "+border[1]+");\n",new Font(bfn, 12, Font.UNDERLINE)));
    //                        }
    //                    }
    //                    else
    //                        doc.add(new Phrase(data.getService_prop().get(j)+ " - " + arr[j] +" ;\n",new Font(bf, 12)));
    //                        
    //                    }
    //                    
    //                }
    //            }
    //                //  ?
    //               data.getAppoitedServiceCount(con.getConnection(), id);
    //               data.getAppServiceData(con.getConnection(), id); 
    //               doc.add(new Phrase("? ? :\n",new Font(bf, 16,Font.BOLD)));         
    //               for (int j = 0; j < data.getCount(); j++) {
    //                    if(data.getService_result().get(j) != null){
    //                       doc.add(new Phrase(data.getService_name().get(j)+" - ",new Font(bf, 12,Font.BOLD)));                    
    //                       doc.add(new Phrase(data.getService_result().get(j)+" ; ",new Font(bf, 12)));   
    //                    }
    //                    if(data.getService_result().get(j) == null){
    //                        doc.add(new Phrase(data.getService_name().get(j)+" ; ",new Font(bf, 12,Font.BOLD)));   
    //                    }
    //                }
    //                    // 
    //                data.getRenServiceCount(con.getConnection(), id);
    //                data.getRenServiceData(con.getConnection(), id);
    //                   doc.add(new Phrase("\n : ",new Font(bf, 16, Font.BOLD)));               
    //                  for (int i = 0; i < data.getCount(); i++) {
    //                      if(data.getService_name().get(i) == null){
    //                          doc.add(new Phrase("? ",new Font(bf, 12)));                          
    //                      }
    //                       doc.add(new Phrase(data.getService_name().get(i)+" ; ",new Font(bf, 12, Font.BOLD)));   
    //                  }
    //                  // 
    //                data.getEarlierServiceCount(con.getConnection(), id);
    //                data.getEarServiceData(con.getConnection(), id);            
    //                doc.add(new Phrase("\n  : ",new Font(bf, 16,  Font.BOLD)));               
    //                  for (int i = 0; i < data.getCount(); i++) {     
    //                     if(data.getService_result().get(i)!= null){
    //                          doc.add(new Phrase(data.getService_name().get(i)+" - ",new Font(bf, 12, Font.BOLD)));                    
    //                          doc.add(new Phrase(data.getService_date().get(i)+" ; ",new Font(bf, 12)));  
    //                      }
    //                      if(data.getService_result().get(i)== null){
    //                           doc.add(new Phrase(data.getService_name().get(i)+" ;",new Font(bf, 12)));  
    //                      }                                          
    //                
    //                }
    //                    doc.close();                   
    //                    if(!pdfName.equals("")){
    //                    AddCover1 cov = new AddCover1();
    //                    String tempFile = fileName;
    //                    String ECGFile = pdfName;
    //                    String res = "C:\\"+fname+"ECG.pdf";
    //                    File file = new File(res);
    //                    file.getParentFile().mkdirs();
    //                    cov.manipulatePdf(ECGFile, res,tempFile); 
    //                    File dfile = new File(fileName);
    //                    if(dfile.delete()){
    //             System.out.println(dfile.getName() + " is deleted!");
    //                    }else{
    //                            System.out.println("Delete operation is failed.");
    //                    }                       
    //                    
    //                    File pfile = new File(res); 
    //                    try {
    //                        Desktop.getDesktop().print(pfile);
    //                        Thread.sleep(2000);
    //                    } catch (IOException ex) {
    //                                log.error(ex, ex);                   
    //                    }
    //                    }else{
    //                    File pfile = new File(fileName); 
    //                    try {
    //                        Desktop.getDesktop().print(pfile);
    //                        Thread.sleep(2000);
    //                    } catch (IOException ex) {
    //                         log.error(ex, ex);
    //                        }
    //                    }
    //            }
    //        } catch (Exception e) {
    //            log.error(e, e);
    //        }
    //        
    //    }

}