4342. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/9/2017 3:51:30 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.

4342.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:51:30 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-web\src\main\java\gov\va\nvap\web\util\file PdfGenerator.java Fri Apr 21 20:03:30 2017 UTC

4342.2 Comparison summary

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

4342.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

4342.4 Active regular expressions

No regular expressions were active.

4342.5 Comparison detail

        1   package go v.va.nvap. web.util.f ile;
        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.Ite rator;
        9   import jav a.util.Map ;
        10   import jav a.util.log ging.Level ;
        11   import jav a.util.log ging.Logge r;
        12  
        13   import org .apache.pd fbox.excep tions.COSV isitorExce ption;
        14   import org .apache.pd fbox.pdmod el.PDDocum ent;
        15   import org .apache.pd fbox.pdmod el.PDPage;
        16   import org .apache.pd fbox.pdmod el.common. PDRectangl e;
        17   import org .apache.pd fbox.pdmod el.edit.PD PageConten tStream;
        18   import org .apache.pd fbox.pdmod el.font.PD Font;
        19   import org .apache.pd fbox.pdmod el.font.PD Type1Font;
        20   import org .apache.pd fbox.pdmod el.graphic s.xobject. PDJpeg;
        21  
        22  
        23   /**
        24    * @author  Sridhar V arma Allur i
        25    * @author  Zack Pete rson
        26    * This cl ass is a h elper clas s to gener ate a pdf  by replaci ng a templ ate string  with actu al values 
        27    */
        28   public cla ss PdfGene rator {
        29           pr ivate PDDo cument doc ument = nu ll;
        30           pr ivate PDFo nt font =  null;
        31       privat e PDFont b old_font =  null;
        32           pr ivate int  begin_x =  0;
        33           pr ivate PDRe ctangle re ct = null;
        34           pr ivate int  line = 0;
        35           pr ivate int  lineSpacin g = 15;
        36           pr ivate floa t begin_y  = 0;
        37       
        38       privat e final in t PAGE_WID TH = 125;
        39       privat e final in t INDENT_W IDTH = 65;
        40       privat e final in t MAX_LINE S = 48;
        41       
        42       privat e boolean  firstPage  = true;
        43       privat e String l etterType  = null;
        44  
        45           /* *
        46            *  
        47            *  Default c onstructor  initializ ing member  variables   
        48            * /
        49           pu blic PdfGe nerator()  {
        50                    docu ment = new  PDDocumen t();
        51                    font  = null;
        52           bo ld_font =  null;
        53                    begi n_x = 0;
        54                    rect  = null;
        55                    line  = 0;
        56                    line Spacing =  13;
        57                    begi n_y = 0;
        58           }
        59  
        60           /* *
        61            *  Creates a  pdf docum ent from t emplate an d patients Details. 
        62            *  A page is  created f or each pa tient in t he collect ion.
        63            *  @param  t emplate  T he templat e that is  used to cr eate the p df documen t
        64            *  @param  p atientsDet ails a col lection of  patient d etails tha t are repl aced in te mplate
        65        * @pa ram type i s a string  denoting  type of le tter being  created
        66            *  @return a  stream th at has the  pdf docum ent
        67            * /
        68           pu blic ByteA rrayOutput Stream cre ate(String  template,
        69                             ArrayL ist<HashMa p<String,  String>> p atientsDet ails, Stri ng type) {
        70                    Byte ArrayOutpu tStream os tream = ne w ByteArra yOutputStr eam();
        71           // Set the le tter type
        72           le tterType =  type;
        73                    // S plit up th e template  into indi vidual lin es 
        74                    Stri ng[] lines  = templat e.split("\ n");
        75           //  Split lin es at spac e nearest  page width  limit
        76           Ar rayList<St ring> adju stedLines  = new Arra yList<Stri ng>();
        77           fo r (String  str : line s) {
        78                while(st r.length()  > PAGE_WI DTH) {
        79                    int  spaceDelim  = str.las tIndexOf(3 2, PAGE_WI DTH);
        80                    adju stedLines. add(str.su bstring(0,  spaceDeli m));
        81                    str  = str.subs tring(spac eDelim + 1 );
        82                }
        83                adjusted Lines.add( str);
        84           }
        85           
        86                    try  {
        87                             for (H ashMap<Str ing, Strin g> hashMap  : patient sDetails)  {
        88                                      PDPage p age = addP age(adjust edLines, h ashMap);
        89                                      document .addPage(p age);
        90                             }
        91                             docume nt.save(os tream);
        92                             docume nt.close() ;
        93                    } ca tch (COSVi sitorExcep tion e) {
        94                             ostrea m = null;
        95                    } ca tch (IOExc eption e)  {
        96                             ostrea m = null;
        97                    }
        98                    retu rn ostream ;
        99           }
        100  
        101       /**
        102        * Cre ates a pdf  document  from multi ple templa tes and pa tientsDeta ils collec tions.
        103        * A p age is cre ated for e ach patien t in the c ollections .
        104        *
        105        * @pa ram templa teArray Th e template s that are  used to c reate the  pdf docume nt
        106        * @pa ram patien tsDetailsL ist A List  of patien t details  that are r eplaced in  the templ ates
        107        * @re turn a str eam that h as the pdf  document
        108        */
        109       public  ByteArray OutputStre am create( String[] t emplateArr ay,
        110           Ar rayList<Ar rayList<Ha shMap<Stri ng, String >>> patien tsDetailsL ist) {
        111           By teArrayOut putStream  ostream =  new ByteAr rayOutputS tream();
        112           
        113           //  there mus t be exact ly one tem plate for  each patie nt detail  collection
        114           if  (template Array.leng th != pati entsDetail sList.size ()) {
        115                return n ull;
        116           }
        117           
        118           fo r (int i =  0; i < te mplateArra y.length;  i++) {
        119                String t emplate =  templateAr ray[i];
        120                ArrayLis t<HashMap< String, St ring>> pat ientsDetai ls = patie ntsDetails List.get(i );
        121                
        122                // Split  up the te mplate int o individu al lines 
        123                String[]  lines = t emplate.sp lit("\n");
        124                // Split  lines at  space near est page w idth limit
        125                ArrayLis t<String>  adjustedLi nes = new  ArrayList< String>();
        126                for (Str ing str :  lines) {
        127                    whil e (str.len gth() > PA GE_WIDTH)  {
        128                         int spaceD elim = str .lastIndex Of(32, PAG E_WIDTH);
        129                         adjustedLi nes.add(st r.substrin g(0, space Delim));
        130                         str = str. substring( spaceDelim  + 1);
        131                    }
        132                    adju stedLines. add(str);
        133                }
        134                try {
        135                    for  (HashMap<S tring, Str ing> hashM ap : patie ntsDetails ) {
        136                         PDPage pag e = addPag e(adjusted Lines, has hMap);
        137                         document.a ddPage(pag e);
        138                    }
        139                } catch  (IOExcepti on e) {
        140                    ostr eam = null ;
        141                }
        142           }
        143           
        144           tr y {
        145                document .save(ostr eam);
        146                document .close();
        147           }  catch (COS VisitorExc eption e)  {
        148                ostream  = null;
        149           }  catch (IOE xception e ) {
        150                ostream  = null;
        151           }
        152           
        153           re turn ostre am;
        154       }
        155           
        156           /* *
        157            *  A pdf pag e per pati ent is cre ated from  template. 
        158            *  A page is  created f or each pa tient in t he collect ion.
        159            *  @param  l ines  An a rray of ea ch individ ual line
        160            *  @param  p atientDeta il hashmap  with pati ent inform ation
        161            *  @return a  stream th at has the  pdf docum ent
        162            * /
        163           pr ivate PDPa ge addPage (ArrayList <String> l ines, Hash Map<String , String>  patientDet ail)
        164                             throws  IOExcepti on {
        165                    PDPa ge page =  new PDPage ();
        166                    font  = PDType1 Font.TIMES _ROMAN;
        167           bo ld_font =  PDType1Fon t.TIMES_BO LD;
        168           
        169                    line  = 0;
        170                    begi n_x = (int )(INDENT_W IDTH * .75 );
        171                    rect  = page.ge tMediaBox( );
        172                    begi n_y = (flo at)(rect.g etHeight()  - (INDENT _WIDTH * 0 .65));
        173           
        174           bo olean dela yResonsMul tiline = f alse;
        175           In putStream  imgIn = nu ll;
        176           
        177                    PDPa geContentS tream cont entStream  = new PDPa geContentS tream(docu ment, page );
        178           // Add the VA  Seal imag e to the d ocument.
        179           if  (firstPag e) {
        180                try {
        181                    imgI n = getCla ss().getCl assLoader( ).getResou rceAsStrea m("Officia l_VA_Seal_ hres.jpg") ;
        182                    PDJp eg img = n ew PDJpeg( document,  imgIn);
        183                    cont entStream. drawImage( img, begin _x, begin_ y - img.ge tHeight()) ;
        184                } catch  (IOExcepti on ex) {
        185                    Logg er.getLogg er(PdfGene rator.clas s.getName( )).log(Lev el.SEVERE,  null, ex) ;
        186                }
        187           }
        188           
        189           if (imgIn !=  null) {
        190                imgIn.cl ose();
        191           }
        192           
        193           in t i = 0;
        194           It erator<Str ing> itr =  lines.ite rator();
        195           wh ile (itr.h asNext())  {
        196                String s tr = itr.n ext();
        197                i++; 
        198                if(i > M AX_LINES)  {
        199                    firs tPage = fa lse;
        200                    cont entStream. close();
        201                    docu ment.addPa ge(page);
        202                    docu ment.addPa ge(addPage (lines, pa tientDetai l));
        203                    brea k;
        204                }
        205                             conten tStream.be ginText();
        206                             conten tStream.se tFont(font , 10);
        207                //Bold a nd center  the VA Fac ility name /address/p hone
        208                if (i <  6 && first Page) {
        209                    cont entStream. setFont(bo ld_font, 1 0);
        210                    floa t lineWidt h = bold_f ont.getStr ingWidth(g etUpdatedS tring(str,  patientDe tail))/100 0 * 10;
        211                    cont entStream. moveTextPo sitionByAm ount((page .getMediaB ox().getWi dth() - li neWidth) /  2, begin_ y - lineSp acing * (+ +line));
        212                    if ( i == 5) {
        213                         begin_y -=  lineSpaci ng;
        214                    }
        215                } 
        216                //Handle s applying  bold text  to specia l cases.
        217                else if  ((i > 7 &&  i <= 12)  || (str.ma tches("^\\ s*AUTHORIZ ATION/REVO CATION: Re voked auth orization  to all Pro viders and  Organizat ions") 
        218                    && l etterType. equals("re voked"))
        219                    || ( str.matche s("^\\s*Ex piration D ate:\\s.+" ) && lette rType.equa ls("expiri ng"))) {
        220                    cont entStream. setFont(bo ld_font, 1 0);
        221                    cont entStream. moveTextPo sitionByAm ount(begin _x, begin_ y - lineSp acing * (+ +line));
        222                } else i f (str.mat ches("^\\s *Reason:\\ s.+") && l etterType. equals("de layed")) {
        223                    cont entStream. setFont(bo ld_font, 1 0);
        224                    cont entStream. moveTextPo sitionByAm ount(begin _x, begin_ y - lineSp acing * (+ +line));
        225                    if ( str.endsWi th(",")) {
        226                         delayReson sMultiline  = true;
        227                    }
        228                } else i f (delayRe sonsMultil ine) {
        229                    dela yResonsMul tiline = f alse;
        230                    cont entStream. setFont(bo ld_font, 1 0);
        231                    cont entStream. moveTextPo sitionByAm ount(begin _x, begin_ y - lineSp acing * (+ +line));  
        232                } else {
        233                    cont entStream. moveTextPo sitionByAm ount(begin _x, begin_ y - lineSp acing * (+ +line));
        234                }
        235                             conten tStream.dr awString(g etUpdatedS tring(str,  patientDe tail));
        236                itr.remo ve();
        237                             conten tStream.en dText();
        238           }
        239                    cont entStream. close();
        240                    retu rn page;
        241           }
        242  
        243           /* *
        244            *  This meth od replace s string t hat has th e keys wit h  patient  informati on. 
        245            *  @param  t emplateStr ing  Templ ate string  that has  keys
        246            *  @param  p atientDeta il a colle ction of p atient det ails that  are replac ed in temp late
        247            *  @return S tring that  has keys  replaced w ith values
        248            * /
        249           pr ivate Stri ng getUpda tedString( String tem plateStrin g,
        250                             HashMa p<String,  String> pa tientDetai l) {
        251                    Stri ng updated String = t emplateStr ing;
        252                    for  (Map.Entry <String, S tring> ent ry : patie ntDetail.e ntrySet())  {
        253                             String  key = ent ry.getKey( );
        254                             String  value = e ntry.getVa lue();
        255                             update dString =  updatedStr ing.replac e(key, val ue);
        256                    }
        257           up datedStrin g = update dString.re placeAll(" \r", "\n") ;
        258                    retu rn updated String;
        259           }
        260   }