3916. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/9/2017 3:50:58 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

3916.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:50:58 2017 UTC
2 eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-server\src\main\java\gov\va\nvap\server\service\privacy\pdf PdfGenerator.java Fri Apr 21 20:03:28 2017 UTC

3916.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 1 235
Removed 0 0

3916.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

3916.4 Active regular expressions

No regular expressions were active.

3916.5 Comparison detail

        1   package go v.va.nvap. server.ser vice.priva cy.pdf;
        2  
        3   import jav a.io.ByteA rrayOutput Stream;
        4   import jav a.io.IOExc eption;
        5   import jav a.io.Input Stream;
        6   import jav a.util.Arr ayList;
        7   import jav a.util.Has hMap;
        8   import jav a.util.Map ;
        9   import jav a.util.log ging.Level ;
        10   import jav a.util.log ging.Logge r;
        11   import org .apache.pd fbox.excep tions.COSV isitorExce ption;
        12   import org .apache.pd fbox.pdmod el.PDDocum ent;
        13   import org .apache.pd fbox.pdmod el.PDPage;
        14   import org .apache.pd fbox.pdmod el.common. PDRectangl e;
        15   import org .apache.pd fbox.pdmod el.edit.PD PageConten tStream;
        16   import org .apache.pd fbox.pdmod el.font.PD Font;
        17   import org .apache.pd fbox.pdmod el.font.PD Type1Font;
        18   import org .apache.pd fbox.pdmod el.graphic s.xobject. PDJpeg;
        19  
        20   /**
        21    * @author  Sridhar V arma Allur i
        22    * @author  Zack Pete rson This  class is a  helper cl ass to gen erate a pd f by repla cing a tem plate stri ng with ac tual value s
        23    */
        24   public cla ss PdfGene rator {
        25  
        26       privat e PDDocume nt documen t = null;
        27       privat e PDFont f ont = null ;
        28       privat e PDFont b old_font =  null;
        29       privat e int begi n_x = 0;
        30       privat e PDRectan gle rect =  null;
        31       privat e int line  = 0;
        32       privat e int line Spacing =  15;
        33       privat e float be gin_y = 0;
        34  
        35       privat e final in t PAGE_WID TH = 120;
        36       privat e final in t INDENT_W IDTH = 65;
        37       privat e final in t MAX_LINE S = 48;
        38  
        39       privat e boolean  firstPage  = true;
        40  
        41       /**
        42        *
        43        * Def ault const ructor ini tializing  member var iables
        44        */
        45       public  PdfGenera tor() {
        46           do cument = n ew PDDocum ent();
        47           fo nt = null;
        48           bo ld_font =  null;
        49           be gin_x = 0;
        50           re ct = null;
        51           li ne = 0;
        52           li neSpacing  = 13;
        53           be gin_y = 0;
        54       }
        55  
        56       /**
        57        * Cre ates a pdf  document  from templ ate and pa tientsDeta ils. A pag e is creat ed for eac h patient  in the col lection.
        58        *
        59        * @pa ram templa te The tem plate that  is used t o create t he pdf doc ument
        60        * @pa ram patien tsDetails  a collecti on of pati ent detail s that are  replaced  in templat e
        61        * @pa ram type i s a string  denoting  type of le tter being  created
        62        * @re turn a str eam that h as the pdf  document
        63        */
        64       public  ByteArray OutputStre am create( String tem plate, Arr ayList<Has hMap<Strin g, String> > patients Details, S tring type ) {
        65           By teArrayOut putStream  ostream =  new ByteAr rayOutputS tream();
        66  
        67           tr y {
        68                for (Has hMap<Strin g, String>  patientsD etail : pa tientsDeta ils) {
        69                    // R eplace the  address p laceholder  before sp litting th e template  since it' s a multi- line field
        70                    Stri ng templat eForPage =  template. replace("[ patientAdd ress]", pa tientsDeta il.get("[p atientAddr ess]"));
        71                    
        72                    // S plit up th e template  into indi vidual lin es
        73                    Stri ng[] lines  = templat eForPage.s plit("\n") ;
        74                    // S plit lines  at space  nearest pa ge width l imit
        75                    Arra yList<Stri ng> adjust edLines =  new ArrayL ist<String >();
        76                    for  (String st r : lines)  {
        77                         while (str .length()  > PAGE_WID TH) {
        78                             int sp aceDelim =  str.lastI ndexOf(32,  PAGE_WIDT H);
        79                             adjust edLines.ad d(str.subs tring(0, s paceDelim) );
        80                             str =  str.substr ing(spaceD elim + 1);
        81                         }
        82                         adjustedLi nes.add(st r);
        83                    }
        84                    
        85                    PDPa ge page =  addPage(ad justedLine s, patient sDetail);
        86                    docu ment.addPa ge(page);
        87                }
        88                document .save(ostr eam);
        89                document .close();
        90           }  catch (COS VisitorExc eption e)  {
        91                ostream  = null;
        92           }  catch (IOE xception e ) {
        93                ostream  = null;
        94           }
        95           re turn ostre am;
        96       }
        97  
        98       /**
        99        * Cre ates a pdf  document  from multi ple templa tes and pa tientsDeta ils collec tions. A p age is cre ated for e ach patien t in the
        100        * col lections.
        101        *
        102        * @pa ram templa teArray Th e template s that are  used to c reate the  pdf docume nt
        103        * @pa ram patien tsDetailsL ist A List  of patien t details  that are r eplaced in  the templ ates
        104        * @re turn a str eam that h as the pdf  document
        105        */
        106       public  ByteArray OutputStre am create( String[] t emplateArr ay,
        107           Ar rayList<Ar rayList<Ha shMap<Stri ng, String >>> patien tsDetailsL ist) {
        108           By teArrayOut putStream  ostream =  new ByteAr rayOutputS tream();
        109  
        110           //  there mus t be exact ly one tem plate for  each patie nt detail  collection
        111           if  (template Array.leng th != pati entsDetail sList.size ()) {
        112                return n ull;
        113           }
        114  
        115           fo r (int i =  0; i < te mplateArra y.length;  i++) {
        116                String t emplate =  templateAr ray[i];
        117                ArrayLis t<HashMap< String, St ring>> pat ientsDetai ls = patie ntsDetails List.get(i );
        118  
        119                // Split  up the te mplate int o individu al lines
        120                String[]  lines = t emplate.sp lit("\n");
        121                // Split  lines at  space near est page w idth limit
        122                ArrayLis t<String>  adjustedLi nes = new  ArrayList< String>();
        123                for (Str ing str :  lines) {
        124                    whil e (str.len gth() > PA GE_WIDTH)  {
        125                         int spaceD elim = str .lastIndex Of(32, PAG E_WIDTH);
        126                         adjustedLi nes.add(st r.substrin g(0, space Delim));
        127                         str = str. substring( spaceDelim  + 1);
        128                    }
        129                    adju stedLines. add(str);
        130                }
        131                try {
        132                    for  (HashMap<S tring, Str ing> hashM ap : patie ntsDetails ) {
        133                         PDPage pag e = addPag e(adjusted Lines, has hMap);
        134                         document.a ddPage(pag e);
        135                    }
        136                } catch  (IOExcepti on e) {
        137                    ostr eam = null ;
        138                }
        139           }
        140  
        141           tr y {
        142                document .save(ostr eam);
        143                document .close();
        144           }  catch (COS VisitorExc eption e)  {
        145                ostream  = null;
        146           }  catch (IOE xception e ) {
        147                ostream  = null;
        148           }
        149  
        150           re turn ostre am;
        151       }
        152  
        153       /**
        154        * A p df page pe r patient  is created  from temp late. A pa ge is crea ted for ea ch patient  in the co llection.
        155        *
        156        * @pa ram lines  An array o f each ind ividual li ne
        157        * @pa ram patien tDetail ha shmap with  patient i nformation
        158        * @re turn a str eam that h as the pdf  document
        159        */
        160       privat e PDPage a ddPage(Arr ayList<Str ing> lines , HashMap< String, St ring> pati entDetail)
        161           th rows IOExc eption {
        162           PD Page page  = new PDPa ge();
        163           fo nt = PDTyp e1Font.TIM ES_ROMAN;
        164           bo ld_font =  PDType1Fon t.TIMES_BO LD;
        165  
        166           li ne = 0;
        167           be gin_x = (i nt) (INDEN T_WIDTH *  .75);
        168           re ct = page. getMediaBo x();
        169           be gin_y = (f loat) (rec t.getHeigh t() - (IND ENT_WIDTH  * 0.65));
        170  
        171           PD PageConten tStream co ntentStrea m = new PD PageConten tStream(do cument, pa ge);
        172           In putStream  imgIn = nu ll;
        173           
        174           // Add the VA  Seal imag e to the d ocument.
        175           if  (firstPag e) {
        176                try {
        177                    imgI n = getCla ss().getCl assLoader( ).getResou rceAsStrea m("Officia l_VA_Seal_ hres.jpg") ;
        178                    PDJp eg img = n ew PDJpeg( document,  imgIn);
        179                    cont entStream. drawImage( img, begin _x, begin_ y - img.ge tHeight()) ;
        180                } catch  (IOExcepti on ex) {
        181                    Logg er.getLogg er(PdfGene rator.clas s.getName( )).log(Lev el.SEVERE,  null, ex) ;
        182                }
        183           }
        184           
        185           if (imgIn !=  null) {
        186                imgIn.cl ose();
        187           }
        188  
        189           in t i = 0;
        190           fo r (String  str : line s) {
        191                i++;
        192                if (i >  MAX_LINES)  {
        193                    brea k;
        194                }
        195                contentS tream.begi nText();
        196                contentS tream.setF ont(font,  11);
        197                if (line  < 6) { // bold and c enter the  facility n ame and ad dress
        198                    cont entStream. setFont(bo ld_font, 1 1);
        199                    floa t lineWidt h = bold_f ont.getStr ingWidth(g etUpdatedS tring(str,  patientDe tail)) / 1 000 * 10;
        200                    cont entStream. moveTextPo sitionByAm ount((page .getMediaB ox().getWi dth() - li neWidth) /  2, begin_ y - lineSp acing * (+ +line));
        201                } else i f (line >=  8 && line  <= 11) {
        202                    cont entStream. setFont(bo ld_font, 1 1);
        203                    cont entStream. moveTextPo sitionByAm ount(begin _x, begin_ y - lineSp acing * (+ +line));
        204                } else i f (str.con tains("Exp iration Da te:")) {
        205                    cont entStream. setFont(bo ld_font, 1 1);
        206                    cont entStream. moveTextPo sitionByAm ount(begin _x, begin_ y - lineSp acing * (+ +line));
        207                } else {
        208                    cont entStream. moveTextPo sitionByAm ount(begin _x, begin_ y - lineSp acing * (+ +line));
        209                }
        210                contentS tream.draw String(get UpdatedStr ing(str, p atientDeta il));
        211                contentS tream.endT ext();
        212           }
        213           co ntentStrea m.close();
        214           re turn page;
        215       }
        216  
        217       /**
        218        * Thi s method r eplaces st ring that  has the ke ys with pa tient info rmation.
        219        *
        220        * @pa ram templa teString T emplate st ring that  has keys
        221        * @pa ram patien tDetail a  collection  of patien t details  that are r eplaced in  template
        222        * @re turn Strin g that has  keys repl aced with  values
        223        */
        224       privat e String g etUpdatedS tring(Stri ng templat eString,
        225           Ha shMap<Stri ng, String > patientD etail) {
        226           St ring updat edString =  templateS tring;
        227           fo r (Map.Ent ry<String,  String> e ntry : pat ientDetail .entrySet( )) {
        228                String k ey = entry .getKey();
        229                String v alue = ent ry.getValu e();
        230                updatedS tring = up datedStrin g.replace( key, value );
        231           }
        232           up datedStrin g = update dString.re placeAll(" \r", "\n") ;
        233           re turn updat edString;
        234       }
        235   }