3098. EPMO Open Source Coordination Office Redaction File Detail Report

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

3098.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:49:48 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-client\src\main\java\gov\va\nvap\service\adapter\audit DirectServiceEndpoint.java Fri Apr 21 20:03:26 2017 UTC

3098.2 Comparison summary

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

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

3098.4 Active regular expressions

No regular expressions were active.

3098.5 Comparison detail

        1   package go v.va.nvap. service.ad apter.audi t;
        2  
        3   /*
        4    * To chan ge this te mplate, ch oose Tools  | Templat es
        5    * and ope n the temp late in th e editor.
        6    */
        7   import gov .va.med.nh in.adapter .audit.Aud itSummarie sType;
        8   import gov .va.med.nh in.adapter .audit.Aud itSummaryT ype;
        9   import gov .va.med.nh in.adapter .audit.Aud itType;
        10   import gov .va.med.nh in.adapter .audit.Aud itsType;
        11   import gov .va.med.nh in.adapter .audit.Get Audits;
        12   import gov .va.med.nh in.adapter .audit.Get AuditsResp onse;
        13   import gov .va.med.nh in.adapter .audit.Get AuditsSumm ary;
        14   import gov .va.med.nh in.adapter .audit.Get AuditsSumm aryRespons e;
        15   import gov .va.med.nh in.adapter .audit.Pag eInfoType;
        16   import gov .va.med.nh in.adapter .audit.Sor tDirection ;
        17   import gov .va.med.nh in.adapter .audit.Sor tFieldsTyp e;
        18   import gov .va.med.nh in.adapter .audit.Sum maryFields Type;
        19  
        20   import gov .va.nvap.s ervice.ada pter.audit .DirectAud itManager;
        21   import gov .va.nvap.s ervice.aud it.AuditEx ception;
        22   import jav a.io.IOExc eption;
        23   import jav a.io.Input Stream;
        24   import jav a.io.Unsup portedEnco dingExcept ion;
        25   import jav a.net.Malf ormedURLEx ception;
        26   import jav a.net.Http URLConnect ion;
        27   import jav a.net.URL;
        28   import jav a.net.URLE ncoder;
        29   import jav a.security .InvalidKe yException ;
        30   import jav a.security .NoSuchAlg orithmExce ption;
        31   import jav a.text.Sim pleDateFor mat;
        32   import jav a.util.Cal endar;
        33   import jav a.util.Dat e;
        34   import jav a.util.Gre gorianCale ndar;
        35   import jav a.util.Has hMap;
        36   import jav a.util.Map .Entry;
        37   import jav a.util.Pro perties;
        38   import jav a.util.Tim eZone;
        39   import jav a.util.log ging.Level ;
        40   import jav a.util.log ging.Logge r;
        41   import jav ax.crypto. Mac;
        42   import jav ax.crypto. spec.Secre tKeySpec;
        43  
        44   import jav ax.xml.XML Constants;
        45   import jav ax.xml.dat atype.Data typeConfig urationExc eption;
        46   import jav ax.xml.dat atype.Data typeFactor y;
        47   import jav ax.xml.par sers.Docum entBuilder ;
        48   import jav ax.xml.par sers.Docum entBuilder Factory;
        49   import jav ax.xml.par sers.Parse rConfigura tionExcept ion;
        50  
        51   import org .w3c.dom.D ocument;
        52   import org .w3c.dom.E lement;
        53   import org .w3c.dom.N ode;
        54   import org .w3c.dom.N odeList;
        55   import org .xml.sax.S AXExceptio n;
        56   import web logic.net. http.Https URLConnect ion;
        57   import gov .va.nvap.c ommon.util .DocumentB uilderFact oryUtil;
        58   import jav a.io.ByteA rrayInputS tream;
        59   import org .apache.co mmons.io.I OUtils;
        60   import sta tic org.ap ache.commo ns.lang.St ringEscape Utils.esca peXml;
        61  
        62   /**
        63    *
        64    * @author  564685
        65    */
        66   public cla ss DirectS erviceEndp oint imple ments Dire ctAuditMan ager
        67   {
        68  
        69       Proper ties props ;
        70  
        71       public  DirectSer viceEndpoi nt()
        72       {
        73           pr ops = new  Properties ();
        74           In putStream  stream = D irectServi ceEndpoint .class.get ResourceAs Stream("/M ETA-INF/di rect.prope rties");
        75           tr y {
        76                props.lo ad(stream) ;
        77           }
        78           ca tch (IOExc eption ex)  {
        79                throw ne w RuntimeE xception(" \nFailed :  Unable to  load dire ct propert ies");
        80           }
        81           fi nally {
        82                try {
        83                    stre am.close() ;
        84                }
        85                catch (I OException  ex) {
        86  
        87                }
        88           }
        89  
        90       }
        91  
        92       privat e String c reateSearc hString(Ha shMap<Stri ng, String > search)
        93       {
        94           St ring searc h_url = "" ;
        95           fo r (Entry<S tring, Str ing> entry  : search. entrySet() ) {
        96                try {
        97                    if ( search_url .equals("" )) {
        98                         search_url  += "?" +  entry.getK ey() + "="  + URLEnco der.encode (entry.get Value(), " UTF-8");
        99                    }
        100                    else  {
        101                         search_url  += "&" +  entry.getK ey() + "="  + URLEnco der.encode (entry.get Value(), " UTF-8");
        102                    }
        103                }
        104                catch (U nsupported EncodingEx ception ex ) {
        105                    Logg er.getLogg er(DirectS erviceEndp oint.class .getName() ).log(Leve l.SEVERE,  null, ex);
        106                }
        107           }
        108           re turn searc h_url;
        109       }
        110  
        111       privat e Document  getDoc(St ring searc h_url) thr ows Direct ServiceExc eption
        112       {
        113           Ht tpURLConne ction conn  = null;
        114           Do cument doc  = null;
        115           tr y {
        116                URL url  = new URL( (String) p rops.get(" direct.url ") + searc h_url);
        117  
        118                conn = ( HttpURLCon nection) u rl.openCon nection();
        119                Date dt  = new Date ();
        120                SimpleDa teFormat s df = new S impleDateF ormat("MM/ dd/yyyy HH :mm:ss z") ;
        121                String d str = sdf. format(dt) ;
        122                String r eqstr = "G ET\n" + ds tr + "\n"  + search_u rl;
        123                Mac sha2 56_HMAC =  Mac.getIns tance("Hma cSHA256");
        124                SecretKe ySpec secr et_key = n ew SecretK eySpec(((S tring) pro ps.get("di rect.priva tekey")).g etBytes(),  "HmacSHA2 56");
        125                sha256_H MAC.init(s ecret_key) ;
        126                byte[] s ha = sha25 6_HMAC.doF inal(reqst r.getBytes ());
        127                String e ncsha = ne w sun.misc .BASE64Enc oder().enc ode(sha);
        128                String a uth = "DAA S " + ((St ring) prop s.get("dir ect.public key")) + " :" + encsh a;
        129                conn.set RequestPro perty("Aut horization ", auth);
        130                conn.set RequestPro perty("Dat e", dstr);
        131                String c harset = " UTF-8";
        132  
        133                // Allow  Inputs
        134                conn.set DoInput(tr ue);
        135  
        136                // Allow  Outputs
        137                conn.set DoOutput(t rue);
        138  
        139                // Don't  use a cac hed copy.
        140                conn.set UseCaches( false);
        141  
        142                // Use a  GET metho d.
        143                conn.set RequestMet hod("GET") ;
        144  
        145                conn.set RequestPro perty("Con nection",  "Keep-Aliv e");
        146                conn.set RequestPro perty("Acc ept-Charse t", charse t);
        147                conn.set RequestPro perty("Cha rset", cha rset);
        148                conn.set RequestPro perty("Cac he-Control ", "no-cac he");
        149  
        150                try {
        151                    conn .connect() ;
        152                } catch( Exception  e) {
        153                    thro w new Dire ctServiceE xception() ;
        154                }
        155  
        156                //added  the respon se message  on failur e as well,  because i t can help  with debu gging pote ntially
        157                /*if (co nn.getResp onseCode()  != 200) {
        158                    thro w new Audi tException ();
        159                    //th row new Ru ntimeExcep tion("\nFa iled : HTT P error co de : " + c onn.getRes ponseCode( ) + "\nHTT P response  : " + con n.getRespo nseMessage ());
        160                }*/
        161                InputStr eam is = n ull;
        162                InputStr eam newIs  = null;
        163                try {
        164                    Docu mentBuilde rFactory d bFactory =  DocumentB uilderFact oryUtil.ge tDocumentB uilderFact ory(null,  true, fals e, false);
        165  
        166                    Docu mentBuilde r dBuilder  = dbFacto ry.newDocu mentBuilde r();
        167                    is =  conn.getI nputStream ();
        168  
        169                    fina l String s trEscaped  = escapeXm l(IOUtils. toString(i s, "UTF-8" ));
        170                    //st rEscaped =  escapeXml (strEscape d);
        171                    newI s = new By teArrayInp utStream(s trEscaped. getBytes(" UTF-8"));
        172  
        173                    doc  = dBuilder .parse(new Is);
        174                }
        175                catch (S AXExceptio n e) {
        176                    e.pr intStackTr ace();
        177                }
        178                catch (P arserConfi gurationEx ception e)  {
        179                    e.pr intStackTr ace();
        180                }
        181                finally  {
        182                    if ( conn != nu ll) {
        183                         conn.disco nnect();
        184                    }
        185                    if ( is != null ) {
        186                         try {
        187                             is.clo se();
        188                         }
        189                         catch (IOE xception i o) {
        190  
        191                         }
        192                    }
        193                    if ( newIs != n ull) {
        194                         try {
        195                             newIs. close();
        196                         }
        197                         catch (IOE xception i o) {
        198  
        199                         }
        200                    }
        201                }
        202  
        203           }
        204           ca tch (Malfo rmedURLExc eption ex)  {
        205                Logger.g etLogger(D irectServi ceEndpoint .class.get Name()).lo g(Level.SE VERE, null , ex);
        206           }
        207           ca tch (IOExc eption ex)  {
        208                Logger.g etLogger(D irectServi ceEndpoint .class.get Name()).lo g(Level.SE VERE, null , ex);
        209           }
        210           ca tch (NoSuc hAlgorithm Exception  ex) {
        211                Logger.g etLogger(D irectServi ceEndpoint .class.get Name()).lo g(Level.SE VERE, null , ex);
        212           }
        213           ca tch (Inval idKeyExcep tion ex) {
        214                Logger.g etLogger(D irectServi ceEndpoint .class.get Name()).lo g(Level.SE VERE, null , ex);
        215           }
        216           re turn doc;
        217  
        218       }
        219  
        220       privat e AuditsTy pe getAudi ts(HashMap <String, S tring> sea rch) throw s DirectSe rviceExcep tion
        221       {
        222           St ring searc h_url = cr eateSearch String(sea rch);
        223  
        224           Au ditsType a uditsType  = new Audi tsType();
        225           Do cument doc  = this.ge tDoc(((Str ing) props .get("dire ct.audit") ) + search _url);
        226           tr y {
        227                if (doc  != null) {
        228                    Node List nList  = doc.get ElementsBy TagName("i tem");
        229                    Data typeFactor y df = Dat atypeFacto ry.newInst ance();
        230                    for  (int temp  = 0; temp  < nList.ge tLength();  temp++) {
        231  
        232                         Node nNode  = nList.i tem(temp);
        233  
        234                         if (nNode. getNodeTyp e() == Nod e.ELEMENT_ NODE) {
        235                             Elemen t eElement  = (Elemen t) nNode;
        236                             AuditT ype audit  = new Audi tType();
        237                             audit. setOrganiz ationName( eElement.g etElements ByTagName( "recipient ").item(0) .getTextCo ntent());
        238                             audit. setPatient GivenName( eElement.g etElements ByTagName( "first").i tem(0).get TextConten t());
        239                             audit. setPatient LastName(e Element.ge tElementsB yTagName(" last").ite m(0).getTe xtContent( ));
        240                             audit. setPatient SSN(eEleme nt.getElem entsByTagN ame("ssn") .item(0).g etTextCont ent());
        241                             audit. setUserId( eElement.g etElements ByTagName( "username" ).item(0). getTextCon tent());
        242                             Calend ar auditTi me = Grego rianCalend ar.getInst ance(TimeZ one.getTim eZone("UTC "));
        243                             auditT ime.setTim e(new Date ((Long.par seLong(eEl ement.getE lementsByT agName("di sclosed"). item(0).ge tTextConte nt())) * 1 000L));
        244                             audit. setAuditTi me(df.newX MLGregoria nCalendar( (Gregorian Calendar)  auditTime) );
        245                             audit. setPurpose ForUse(eEl ement.getE lementsByT agName("pu rpose").it em(0).getT extContent ());
        246                             audit. setDocumen tTitle(eEl ement.getE lementsByT agName("ti tle").item (0).getTex tContent() );
        247                             audits Type.getAu dit().add( audit);
        248                         }
        249                    }
        250                }
        251           }
        252           ca tch (Excep tion ex) {
        253                throw ne w DirectSe rviceExcep tion();
        254                //ex.pri ntStackTra ce();
        255           }
        256           re turn audit sType;
        257       }
        258  
        259       @Overr ide
        260       public  GetAudits Response g etAudits(G etAudits b ody) throw s DirectSe rviceExcep tion
        261       {
        262           Ge tAuditsRes ponse ret  = new GetA uditsRespo nse();
        263           Ha shMap<Stri ng, String > search =  new HashM ap<String,  String>() ;
        264           in t pageSize  = -1, pag eNumber =  0;
        265  
        266           if  (body.get FromDate()  != null)  {
        267                search.p ut("start" , Long.toS tring(body .getFromDa te().toGre gorianCale ndar().get TimeInMill is() / 100 0L));
        268           }
        269           if  (body.get ToDate() ! = null) {
        270                search.p ut("end",  Long.toStr ing(body.g etToDate() .toGregori anCalendar ().getTime InMillis()  / 1000L)) ;
        271           }
        272           if  (body.get PatientSSN s() != nul l && body. getPatient SSNs().get Value().si ze() > 0)  {
        273                search.p ut("ssn",  body.getPa tientSSNs( ).getValue ().get(0)) ;
        274           }
        275           if  (body.get PatientGiv enNames()  != null &&  body.getP atientGive nNames().g etValue(). size() > 0 ) {
        276                search.p ut("first" , body.get PatientGiv enNames(). getValue() .get(0));
        277           }
        278           if  (body.get PatientLas tNames() ! = null &&  body.getPa tientLastN ames().get Value().si ze() > 0)  {
        279                search.p ut("last",  body.getP atientLast Names().ge tValue().g et(0));
        280           }
        281           if  (body.get PageInfo()  != null)  {
        282                PageInfo Type pageI nfo = body .getPageIn fo();
        283                pageSize  = pageInf o.getPageS ize();
        284                pageNumb er = pageI nfo.getPag eNumber();
        285                if (page Size > 0)  {
        286                    sear ch.put("re cords", In teger.toSt ring(pageS ize));
        287                }
        288                search.p ut("page",  Integer.t oString(pa geNumber)) ;
        289           }
        290           el se {
        291                pageSize  = -1;
        292                pageNumb er = 0;
        293           }
        294  
        295           if  (body.get SortFields () != null  && body.g etSortFiel ds().getSo rtField()  != null) {
        296                SortFiel dsType sor tFields =  body.getSo rtFields() ;
        297                String o rder = sor tFields.ge tSortField ().get(0). getField() .name();
        298                order =  converOrde r(order);
        299                if (sort Fields.get SortField( ).get(0).g etDirectio n().equals (SortDirec tion.ASC))  {
        300                    orde r += " asc ";
        301                }
        302                else {
        303                    orde r += " des c";
        304                }
        305                search.p ut("order" , order);
        306           }
        307           Au ditsType a udits = th is.getAudi ts(search) ;
        308           in t size = a udits.getA udit().siz e();
        309           Pa geInfoType  pageInfo  = new Page InfoType() ;
        310           pa geInfo.set PageSize(p ageSize !=  -1 ? Math .min(pageS ize, size)  : size);
        311           pa geInfo.set PageNumber (pageNumbe r);
        312           re t.setAudit s(audits);
        313           re t.setPageI nfo(pageIn fo);
        314           re turn ret;
        315  
        316       }
        317       
        318       @Overr ide
        319       public  Long getA uditsCount (GetAudits  body) thr ows Direct ServiceExc eption {
        320            G etAuditsRe sponse ret  = new Get AuditsResp onse();
        321           Ha shMap<Stri ng,String>  search= n ew HashMap <String,St ring>();
        322           in t pageSize  = -1, pag eNumber =  0;
        323           
        324           
        325                if (body .getFromDa te() != nu ll) {
        326                    sear ch.put("st art", Long .toString( body.getFr omDate().t oGregorian Calendar() .getTimeIn Millis()/1 000L));
        327                }
        328                if (body .getToDate () != null ) {
        329                    sear ch.put("en d", Long.t oString(bo dy.getToDa te().toGre gorianCale ndar().get TimeInMill is()/1000L ));
        330                }
        331                if (body .getPatien tSSNs() !=  null && b ody.getPat ientSSNs() .getValue( ).size() >  0) {
        332                    sear ch.put("ss n", body.g etPatientS SNs().getV alue().get (0));
        333                }
        334                if (body .getPatien tGivenName s() != nul l && body. getPatient GivenNames ().getValu e().size()  > 0) {
        335                    sear ch.put("fi rst", body .getPatien tGivenName s().getVal ue().get(0 ));
        336                }
        337                if (body .getPatien tLastNames () != null  && body.g etPatientL astNames() .getValue( ).size() >  0) {
        338                    sear ch.put("la st", body. getPatient LastNames( ).getValue ().get(0)) ;
        339                }
        340                /*if (bo dy.getPage Info() !=  null) {
        341                    Page InfoType p ageInfo =  body.getPa geInfo();
        342                    page Size = pag eInfo.getP ageSize();
        343                    page Number = p ageInfo.ge tPageNumbe r();
        344                    if(p ageSize >  0){
        345                         search.put ("records" , Integer. toString(p ageSize));
        346                    }
        347                    sear ch.put("pa ge", Integ er.toStrin g(pageNumb er));
        348                }
        349                else {
        350                    page Size = -1;
        351                    page Number = 0 ;
        352                }*/
        353                
        354                /*if (bo dy.getSort Fields() ! = null &&  body.getSo rtFields() .getSortFi eld() != n ull) {
        355                    Sort FieldsType  sortField s = body.g etSortFiel ds();
        356                    Stri ng order =  sortField s.getSortF ield().get (0).getFie ld().name( );
        357                    orde r = conver Order(orde r);
        358                    if(s ortFields. getSortFie ld().get(0 ).getDirec tion().equ als(SortDi rection.AS C)){
        359                         order += "  asc";
        360                    }
        361                    else {
        362                         order += "  desc";
        363                    }
        364                    sear ch.put("or der", orde r);
        365                }*/
        366                AuditsTy pe audits  = this.get Audits(sea rch);
        367                Long tot alCount =  new Long(a udits.getA udit().siz e());
        368           re turn total Count;
        369       
        370       }
        371  
        372       @Overr ide
        373       public  GetAudits SummaryRes ponse getA uditSummar y(GetAudit sSummary a udit) thro ws DirectS erviceExce ption
        374       {
        375           Ge tAuditsSum maryRespon se ret = n ew GetAudi tsSummaryR esponse();
        376           Ha shMap<Stri ng, String > search =  new HashM ap<String,  String>() ;
        377           if  (audit.ge tFromDate( ) != null)  {
        378                search.p ut("start" , Long.toS tring(audi t.getFromD ate().toGr egorianCal endar().ge tTimeInMil lis() / 10 00L));
        379           }
        380           if  (audit.ge tToDate()  != null) {
        381                search.p ut("end",  Long.toStr ing(audit. getToDate( ).toGregor ianCalenda r().getTim eInMillis( ) / 1000L) );
        382           }
        383  
        384           re t.setAudit Summaries( getAuditSu mmary(sear ch));
        385           re t.setGroup ByFields(a udit.getGr oupByField s());
        386           re turn ret;
        387       }
        388  
        389       privat e AuditSum mariesType  getAuditS ummary(Has hMap<Strin g, String>  search) t hrows Dire ctServiceE xception
        390       {
        391           Au ditSummari esType ret  = new Aud itSummarie sType();
        392           St ring searc h_url = th is.createS earchStrin g(search);
        393           Do cument doc  = this.ge tDoc(((Str ing) props .get("dire ct.auditsu mmary")) +  search_ur l);
        394  
        395           if  (doc != n ull) {
        396                NodeList  nList = d oc.getElem entsByTagN ame("item" );
        397  
        398                for (int  temp = 0;  temp < nL ist.getLen gth(); tem p++) {
        399  
        400                    Node  nNode = n List.item( temp);
        401  
        402                    if ( nNode.getN odeType()  == Node.EL EMENT_NODE ) {
        403                         Element eE lement = ( Element) n Node;
        404                         AuditSumma ryType aud it = new A uditSummar yType();
        405                         SummaryFie ldsType su mField = n ew Summary FieldsType ();
        406                         sumField.g etSummaryF ield().add (eElement. getElement sByTagName ("sent_to" ).item(0). getTextCon tent());
        407                         audit.setS ummaryFiel ds(sumFiel d);
        408                         String tot al = eElem ent.getEle mentsByTag Name("tota l").item(0 ).getTextC ontent();
        409                         //  int co unt = Inte ger.getInt eger(eElem ent.getEle mentsByTag Name("tota l").item(0 ).getTextC ontent());
        410                         audit.setC ount(Long. parseLong( total));
        411                         ret.getAud itSummary( ).add(audi t);
        412                    }
        413                }
        414           }
        415  
        416           re turn ret;
        417       }
        418  
        419       privat e String c onverOrder (String or der)
        420       {
        421           if  (order.eq uals("PATI ENT_SSN"))  {
        422                return " ssn";
        423           }
        424           if  (order.eq uals("PATI ENT_GIVEN_ NAME")) {
        425                return " first";
        426           }
        427           if  (order.eq uals("PATI ENT_LAST_N AME")) {
        428                return " last";
        429           }
        430           if  (order.eq uals("AUDI T_TIME"))  {
        431                return " disclosed" ;
        432           }
        433           if  (order.eq uals("DOCU MENT_TITLE ")) {
        434                return " title";
        435           }
        436           if  (order.eq uals("ORGA NIZATION_N AME")) {
        437                return " recipient" ;
        438           }
        439           if  (order.eq uals("USER _ID")) {
        440                return " username";
        441           }
        442           if  (order.eq uals("PURP OSE_FOR_US E")) {
        443                return " purpose";
        444           }
        445           // can't sort  by
        446           re turn "disc losed";
        447       }
        448   }