4321. EPMO Open Source Coordination Office Redaction File Detail Report

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

4321.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:51:28 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\report PatientDiscoveryReportResults.java Fri Apr 21 20:15:58 2017 UTC

4321.2 Comparison summary

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

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

4321.4 Active regular expressions

No regular expressions were active.

4321.5 Comparison detail

        1   /*
        2    * To chan ge this te mplate, ch oose Tools  | Templat es
        3    * and ope n the temp late in th e editor.
        4    */
        5   package go v.va.nvap. web.report ;
        6  
        7   import gov .va.med.nh in.adapter .audit.Act ionType;
        8   import gov .va.med.nh in.adapter .audit.Act ionValuesT ype;
        9   import gov .va.med.nh in.adapter .audit.Aud itType;
        10   import gov .va.med.nh in.adapter .audit.Fie ldType;
        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.Pag eInfoType;
        14   import gov .va.med.nh in.adapter .audit.Sor tDirection ;
        15   import gov .va.med.nh in.adapter .audit.Sor tFieldType ;
        16   import gov .va.med.nh in.adapter .audit.Sor tFieldsTyp e;
        17   import gov .va.med.nh in.adapter .audit.Str ingValuesT ype;
        18   import gov .va.nvap.c ommon.date .Gregorian DateUtil;
        19   import gov .va.nvap.c ommon.vali dation.Nul lChecker;
        20   import gov .va.nvap.s ervice.ada pter.audit .AdapterAu ditManager ;
        21   import gov .va.nvap.s ervice.aud it.AuditEx ception;
        22   import gov .va.nvap.s ervice.pdq .PdqServic e;
        23   import gov .va.nvap.w eb.app.Res ponseDispa tcherHttpS ervlet;
        24   import gov .va.nvap.w eb.dao.Use rDocumentD AO;
        25   import gov .va.nvap.w eb.helper. privacy.Co nsentManag ementHelpe r;
        26   import gov .va.nvap.w eb.helper. report.Rep ortHelper;
        27   import gov .va.nvap.w eb.patient .ExcelGene ratorThrea d;
        28   import gov .va.nvap.w eb.user.Us erHelper;
        29   import gov .va.nvap.w eb.util.Pa ginator;
        30   import gov .va.nvap.w eb.util.da te.DateUti l;
        31   import gov .va.nvap.w eb.util.xl s.CsvExpor ter;
        32   import gov .va.nvap.w eb.util.xl s.ExcelExp orter;
        33  
        34   import jav a.io.IOExc eption;
        35   import jav a.util.Arr ayList;
        36   import jav a.util.Cal endar;
        37   import jav a.util.Dat e;
        38   import jav a.util.Has hMap;
        39   import jav a.util.Has hSet;
        40   import jav a.util.Lin kedHashMap ;
        41   import jav a.util.Lis t;
        42   import jav a.util.Map ;
        43  
        44   import jav ax.ejb.EJB ;
        45   import jav ax.servlet .ServletEx ception;
        46   import jav ax.servlet .http.Http ServletReq uest;
        47   import jav ax.servlet .http.Http ServletRes ponse;
        48   import jav ax.servlet .http.Http Session;
        49  
        50   /**
        51    * edited  by Irakli  Kakushadze
        52    */
        53   public cla ss Patient DiscoveryR eportResul ts extends  ResponseD ispatcherH ttpServlet  {
        54  
        55       /**
        56        * Ser ial UID.
        57        */
        58       privat e static f inal long  serialVers ionUID = - 1105605958 616174460L ;
        59       // pri vate stati c final Lo gger logge r =
        60       // Log ger.getLog ger(Patien tDiscovery ReportResu lts.class
        61       // .ge tName());
        62       privat e AdapterA uditManage r adapterA uditManage r;
        63       @EJB(b eanInterfa ce = PdqSe rvice.clas s, mappedN ame = "Pdq Service")
        64       PdqSer vice pdqSe rvice;
        65  
        66       public  void expo rtToCsv(fi nal HttpSe rvletReque st request ,
        67           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception, I OException  {
        68  
        69           fi nal List<M ap<String,  Object>>  results =  this.getRe sults(
        70                request. getSession (), new Pa ginator(th is.getRepo rtHelper() .getConsen tDirective sReportCap AsInt()));
        71  
        72           Cs vExporter  csvExporte r = new Cs vExporter( );
        73  
        74           Ma p<String,  String> cs vReportMap  = new Lin kedHashMap <String, S tring>();
        75  
        76           cs vReportMap .put("Date  Received  (CT)", "au ditTimeFor matted");
        77           cs vReportMap .put("SSN" , "ssn");
        78           cs vReportMap .put("Pati ent Last N ame", "las tName");
        79           cs vReportMap .put("Pati ent First  Name", "fi rstName");
        80           cs vReportMap .put("Pati ent Middle  Name", "m iddleName" );
        81           cs vReportMap .put("Purp ose of Use ", "purpos eOfUse");
        82           cs vReportMap .put("Send er", "faci lity");
        83           cs vReportMap .put("Send er OID", " facilityOi d");
        84           cs vReportMap .put("Rece iver", "re moteFacili ty");
        85           cs vReportMap .put("Rece iver OID",  "remoteFa cilityOid" );
        86           cs vReportMap .put("Mess age", "mes sage");
        87           cs vReportMap .put("Expl anation of  Failure",  "failureE xplanation ");
        88           cs vReportMap .put("Deta ils", "det ails");
        89  
        90           cs vExporter. exportToCS V(response , "Patient _Discovery _Audit_Det ail_Report ", results , (LinkedH ashMap<Str ing, Strin g>) csvRep ortMap);
        91       }
        92  
        93       /**
        94        * Exp ort to exc el - This  method is  called whe n the user  clicks on  the excel
        95        * ico n in the J SP. Reflec tion is us ed in the  ResponseDi spatcherHt tpServlet
        96        * to  call this  method bas ed on the  http param eters.
        97        *
        98        * @pa ram reques t HTTP Req uest
        99        * @pa ram respon se HTTP Re sponse
        100        * @th rows Servl etExceptio n
        101        * @th rows IOExc eption
        102        */
        103       public  void expo rtToExcel( final Http ServletReq uest reque st, final  HttpServle tResponse  response)  throws Ser vletExcept ion, IOExc eption {
        104           Ex celGenerat orThread e xGenThread  = new Exc elGenerato rThread("e xGenThread ");
        105  
        106           // Get the se ssion fina l
        107           Ht tpSession  session =  request.ge tSession(f alse);
        108  
        109           //       Crea te a map o f key whic h is based  on the re sult data  key and th e
        110           //       head ing value  The headin g is used  to create  the column  headers a nd the
        111           //       key  is used to  pull the  data from  the result s
        112           fi nal Map<St ring, Stri ng> patien tDiscovery Map = new  LinkedHash Map<String , String>( );
        113  
        114           //  Set the o ptional ro ws
        115           fi nal Object  startDate Str = sess ion.getAtt ribute("pa tientDisco veryQueryS tartDate") ;
        116           fi nal Object  endDateSt r = sessio n.getAttri bute("pati entDiscove ryQueryEnd Date");
        117           fi nal Object  patientMp iResPmpi =  session.g etAttribut e("patient DiscoveryM PIResults" );
        118  
        119           //  Generate  filters.
        120           fi nal Map<St ring, List <Object>>  filterMap  = new Link edHashMap< String, Li st<Object> >();
        121           fi nal Linked HashMap<St ring, Obje ct> filter s = new Li nkedHashMa p<String,  Object>();
        122  
        123           fi lters.put( "Start Dat e", this.g etReportHe lper().get FormattedD ate((Date)  startDate Str));
        124           fi lters.put( "End Date" , this.get ReportHelp er().getFo rmattedDat e((Date) e ndDateStr) );
        125           fi lters.put( "SSN", ses sion.getAt tribute("p atientDisc overyQuery SSN"));
        126           fi lters.put( "Last Name ", session .getAttrib ute("patie ntDiscover yQueryLast Name"));
        127           fi lters.put( "First Nam e", sessio n.getAttri bute("pati entDiscove ryQueryFir stName"));
        128           fi lters.put( "User ID",  session.g etAttribut e("patient DiscoveryQ ueryUserId "));
        129           fi lters.put( "MPI Resul ts", Excel Exporter.g etFilterVa lue(patien tMpiResPmp i));
        130           fi lters.put( "eHealth E xchange Or g", ExcelE xporter.ge tFilterVal ue(session .getAttrib ute("patie ntDiscover yQueryOrgN ame")));
        131           Ex celExporte r.populate FilterMapF orExport(r equest, fi lters, fil terMap, se ssion.getA ttribute(" patientTyp es").toStr ing());
        132           ex GenThread. setFilterM ap(filterM ap);
        133  
        134           pa tientDisco veryMap.pu t("auditTi meFormatte d", "Date  Received ( CT)");
        135           pa tientDisco veryMap.pu t("ssn", " SSN");
        136           pa tientDisco veryMap.pu t("lastNam e", "Patie nt Last Na me");
        137           pa tientDisco veryMap.pu t("firstNa me", "Pati ent First  Name");
        138           pa tientDisco veryMap.pu t("middleN ame", "Pat ient Middl e Name");
        139           pa tientDisco veryMap.pu t("purpose OfUse", "P urpose of  Use");
        140           pa tientDisco veryMap.pu t("facilit y", "Sende r");
        141           pa tientDisco veryMap.pu t("facilit yOid", "Se nder OID") ;
        142           pa tientDisco veryMap.pu t("remoteF acility",  "Receiver" );
        143           pa tientDisco veryMap.pu t("remoteF acilityOid ", "Receiv er OID");
        144           pa tientDisco veryMap.pu t("message ", "Messag e");
        145           pa tientDisco veryMap.pu t("failure Explanatio n", "Expla nation of  Failure");
        146           pa tientDisco veryMap.pu t("details ", "Detail s");
        147           ex GenThread. setReportM ap(patient DiscoveryM ap);
        148  
        149           ex GenThread. setHasOpti onalRows(t rue);
        150           ex GenThread. setOptiona lRowsMap(c reateOptio nalRowsMap (Integer.v alueOf(
        151                    sess ion.getAtt ribute("pa tientTypes ").toStrin g())));
        152  
        153           //  Set names  for Excel  generator  thread
        154           ex GenThread. setTitle(" Patient Di scovery Au dit Detail ed Report" );
        155  
        156           ex GenThread. setExcelEx porter(thi s.getExcel Exporter() );
        157           ex GenThread. setAdapter AuditManag er(adapter AuditManag er);
        158           ex GenThread. setReportH elper(getR eportHelpe r());
        159           ex GenThread. setUserId( UserHelper .getUserNa me(request ));
        160           ex GenThread. setUserDoc umentDao(g etUserDocu mentDAO()) ;
        161  
        162           //  Set searc h attribut es for get ting audit  results
        163           ex GenThread. setAttribu tes(mapSes sionAttrib utes(sessi on));
        164  
        165           ex GenThread. start();
        166  
        167           th is.forward (request,  response,  "show");
        168       }
        169  
        170       privat e Map<Stri ng, Object > mapSessi onAttribut es(HttpSes sion sessi on) {
        171           Ma p<String,  Object> at tributes =  new HashM ap<String,  Object>() ;
        172  
        173           at tributes.p ut("icn",  (String) s ession
        174                    .get Attribute( "patientDi scoveryQue ryICN"));
        175           at tributes.p ut("ssn",  (String) s ession
        176                    .get Attribute( "patientDi scoveryQue rySSN"));
        177           at tributes.p ut("lastNa me", (Stri ng) sessio n
        178                    .get Attribute( "patientDi scoveryQue ryLastName "));
        179           at tributes.p ut("firstN ame", (Str ing) sessi on
        180                    .get Attribute( "patientDi scoveryQue ryFirstNam e"));
        181           at tributes.p ut("userId ", (String ) session
        182                    .get Attribute( "patientDi scoveryQue ryUserId") );
        183  
        184           //  Add 24 ho urs to end  date if s ame as sta rt date
        185           Da te startDa te = (Date ) session. getAttribu te("patien tDiscovery QueryStart Date");
        186           Da te endDate  = (Date)  session.ge tAttribute ("patientD iscoveryQu eryEndDate ");
        187           if  (NullChec ker.isNotE mpty(endDa te)) {
        188                if (endD ate.equals (startDate )) {
        189                    endD ate = Date Util.addTi me(endDate , Calendar .HOUR, 24) ;
        190                }
        191           }
        192           at tributes.p ut("startD ate", star tDate);
        193           at tributes.p ut("endDat e", endDat e);
        194  
        195           //  Set both  sender and  receiver  org to the  organizat ion entere d
        196           at tributes.p ut("organi zation", ( String) se ssion
        197                    .get Attribute( "patientDi scoveryQue ryOrganiza tion"));
        198           at tributes.p ut("remote Organizati on", (Stri ng) sessio n
        199                    .get Attribute( "patientDi scoveryQue ryOrganiza tion"));
        200  
        201           at tributes.p ut("mpiMat ch", (Stri ng) sessio n
        202                    .get Attribute( "patientDi scoveryMPI Results")) ;
        203           at tributes.p ut("patien tTypes", ( Integer) s ession.get Attribute( "patientTy pes"));
        204           //  sort
        205           at tributes.p ut("sortVa lue", (Str ing) sessi on
        206                    .get Attribute( "patientDi scoverySor tValue"));
        207           at tributes.p ut("sortDi rection",  (String) s ession
        208                    .get Attribute( "patientDi scoverySor tDirection "));
        209  
        210           //  Set Actio n Types
        211           fi nal Action ValuesType  actionsTy pe = new A ctionValue sType();
        212           ac tionsType. getValue() .add(Actio nType.ANNO UNCE);
        213           ac tionsType. getValue() .add(Actio nType.CHEC K_POLICY);
        214           ac tionsType. getValue() .add(Actio nType.MPI_ FIND_MATCH );
        215           ac tionsType. getValue() .add(Actio nType.ADD_ PATIENT_CO RRELATION) ;
        216           ac tionsType. setNotIn(f alse);
        217           at tributes.p ut("action sType", ac tionsType) ;
        218  
        219           re turn attri butes;
        220       }
        221  
        222       Map<St ring, Stri ng> create OptionalRo wsMap(int  patientTyp es) {
        223           Ma p<String,  String> op tionalRows Map = new  LinkedHash Map<String , String>( );
        224  
        225           if  (patientT ypes == 1)  {
        226                optional RowsMap.pu t("uniqueR ealPatient s", "Uniqu e patients ");
        227                optional RowsMap.pu t("realPat ientMessag es", "Tota l messages ");
        228                optional RowsMap.pu t("realPat ientFails" , "Match f ailures");
        229                optional RowsMap.pu t("realPat ientMatche s", "Match es found") ;
        230           }  else if (p atientType s == 2) {
        231                optional RowsMap.pu t("uniqueT estPatient s", "Uniqu e patients ");
        232                optional RowsMap.pu t("testPat ientMessag es", "Tota l messages ");
        233                optional RowsMap.pu t("testPat ientFails" , "Match f ailures");
        234                optional RowsMap.pu t("testPat ientMatche s", "Match es found") ;
        235           }  else {
        236                optional RowsMap.pu t("uniqueR ealPatient s", "Uniqu e real pat ients");
        237                optional RowsMap.pu t("realPat ientMessag es", "Tota l messages  for real  patients") ;
        238                optional RowsMap.pu t("realPat ientFails" , "Match f ailures fo r real pat ients");
        239                optional RowsMap.pu t("realPat ientMatche s", "Match es found f or real pa tients");
        240  
        241                optional RowsMap.pu t("", "");
        242  
        243                optional RowsMap.pu t("uniqueT estPatient s", "Uniqu e test pat ients");
        244                optional RowsMap.pu t("testPat ientMessag es", "Tota l messages  for test  patients") ;
        245                optional RowsMap.pu t("testPat ientFails" , "Match f ailures fo r test pat ients");
        246                optional RowsMap.pu t("testPat ientMatche s", "Match es found f or test pa tients");
        247           }
        248  
        249           re turn optio nalRowsMap ;
        250       }
        251  
        252       public  ConsentMa nagementHe lper getCm sHelper()  {
        253           fi nal Consen tManagemen tHelper cm sHelper =  this.getBe an("cmsHel per",
        254                    Cons entManagem entHelper. class);
        255           re turn cmsHe lper;
        256       }
        257  
        258       /**
        259        * Get  the excel  exporter  class from  Spring.
        260        *
        261        * @re turn the e xcel expor ter object
        262        */
        263       public  ExcelExpo rter getEx celExporte r() {
        264           fi nal ExcelE xporter ex celExporte r = this.g etBean("ex celExporte r",
        265                    Exce lExporter. class);
        266           re turn excel Exporter;
        267       }
        268  
        269       public  ReportHel per getRep ortHelper( ) {
        270           fi nal Report Helper rep ortHelper  = this.get Bean("repo rtHelper",
        271                    Repo rtHelper.c lass);
        272           re turn repor tHelper;
        273       }
        274  
        275       public  List<Map< String, Ob ject>> get Results(fi nal HttpSe ssion sess ion,
        276                final Pa ginator pa ginator) t hrows Audi tException  {
        277           fi nal String  icn = (St ring) sess ion
        278                    .get Attribute( "patientDi scoveryQue ryICN");
        279           fi nal String  ssn = (St ring) sess ion
        280                    .get Attribute( "patientDi scoveryQue rySSN");
        281           fi nal String  lastName  = (String)  session
        282                    .get Attribute( "patientDi scoveryQue ryLastName ");
        283           fi nal String  firstName  = (String ) session
        284                    .get Attribute( "patientDi scoveryQue ryFirstNam e");
        285           fi nal String  patientDi scoveryUse rId = (Str ing) sessi on
        286                    .get Attribute( "patientDi scoveryQue ryUserId") ;
        287           fi nal Date s d = (Date)  session
        288                    .get Attribute( "patientDi scoveryQue ryStartDat e");
        289           Da te ed = (D ate) sessi on.getAttr ibute("pat ientDiscov eryQueryEn dDate");
        290           fi nal String  organizat ion = (Str ing) sessi on
        291                    .get Attribute( "patientDi scoveryQue ryOrganiza tion");
        292           St ring mpiMa tch = (Str ing) sessi on
        293                    .get Attribute( "patientDi scoveryMPI Results");
        294           fi nal int pa tientTypes  = (Intege r) session .getAttrib ute("patie ntTypes");
        295           //  sort
        296           fi nal String  patientDi scoverySor tValue = ( String) se ssion
        297                    .get Attribute( "patientDi scoverySor tValue");
        298           fi nal String  patientDi scoverySor tDirection  = (String ) session
        299                    .get Attribute( "patientDi scoverySor tDirection ");
        300  
        301           if  (mpiMatch .equalsIgn oreCase("a ll")) {
        302                mpiMatch  = null;
        303           }
        304  
        305           fi nal GetAud its getAud itsRequest  = new Get Audits();
        306           if  (NullChec ker.isNotE mpty(sd))  {
        307                getAudit sRequest.s etFromDate (Gregorian DateUtil
        308                         .getGregor ianCalenda rByDate(sd ));
        309           }
        310           if  (NullChec ker.isNotE mpty(ed))  {
        311                if (ed.e quals(sd))  {
        312                    ed =  DateUtil. addTime(ed , Calendar .HOUR, 24) ;
        313                }
        314                getAudit sRequest.s etToDate(G regorianDa teUtil
        315                         .getGregor ianCalenda rByDate(ed ));
        316           }
        317  
        318           //  Set Patie nt Types
        319           ge tAuditsReq uest.setPa tientTypes (patientTy pes);
        320  
        321           //  Set Patie nt Ids
        322           if  (NullChec ker.isNotE mpty(icn))  {
        323                final St ringValues Type patie ntIds = ne w StringVa luesType() ;
        324                patientI ds.getValu e().add(ic n);
        325                patientI ds.setNotI n(false);
        326                getAudit sRequest.s etPatientI ds(patient Ids);
        327           }
        328           //  Set SSN
        329           if  (NullChec ker.isNotE mpty(ssn))  {
        330                String[]  ssns = ss n.split(", ");
        331                final St ringValues Type patie ntSSNs = n ew StringV aluesType( );
        332                for (Str ing ssnEnt ry : ssns)  {
        333                    pati entSSNs.ge tValue().a dd(ssnEntr y);
        334                }
        335                patientS SNs.setNot In(false);
        336                getAudit sRequest.s etPatientS SNs(patien tSSNs);
        337           }
        338           //  Set Last  Name
        339           if  (NullChec ker.isNotE mpty(lastN ame)) {
        340                final St ringValues Type patie ntLastName s = new St ringValues Type();
        341                patientL astNames.g etValue(). add(lastNa me);
        342                patientL astNames.s etNotIn(fa lse);
        343                getAudit sRequest.s etPatientL astNames(p atientLast Names);
        344           }
        345           //  Set First  Name
        346           if  (NullChec ker.isNotE mpty(first Name)) {
        347                final St ringValues Type patie ntFirstNam es = new S tringValue sType();
        348                patientF irstNames. getValue() .add(first Name);
        349                patientF irstNames. setNotIn(f alse);
        350                getAudit sRequest.s etPatientG ivenNames( patientFir stNames);
        351           }
        352           //  Set User  ID
        353           if  (NullChec ker.isNotE mpty(patie ntDiscover yUserId))  {
        354                final St ringValues Type userI d = new St ringValues Type();
        355                userId.g etValue(). add(patien tDiscovery UserId);
        356                userId.s etNotIn(fa lse);
        357                getAudit sRequest.s etUserIds( userId);
        358           }
        359           //  Set Organ ization Id s
        360           fi nal String ValuesType  orgTypes  = new Stri ngValuesTy pe();
        361           if  (NullChec ker.isNotE mpty(organ ization))  {
        362                orgTypes .getValue( ).add(orga nization);
        363           }
        364           or gTypes.set NotIn(fals e);
        365           ge tAuditsReq uest.setRe moteOrgani zationIds( orgTypes);
        366           ge tAuditsReq uest.setOr ganization Ids(orgTyp es);
        367  
        368           //  sorting
        369           if  (NullChec ker.isNotE mpty(patie ntDiscover ySortValue )) {
        370                final So rtFieldTyp e sortFiel d = new So rtFieldTyp e();
        371                sortFiel d.setField (FieldType .fromValue (patientDi scoverySor tValue));
        372                if ("DES C".equalsI gnoreCase( patientDis coverySort Direction) ) {
        373                    sort Field.setD irection(S ortDirecti on.DESC);
        374                } else {
        375                    sort Field.setD irection(S ortDirecti on.ASC);
        376                }
        377                final So rtFieldsTy pe sortFie ldsType =  new SortFi eldsType() ;
        378                sortFiel dsType.get SortField( ).add(sort Field);
        379                getAudit sRequest.s etSortFiel ds(sortFie ldsType);
        380           }
        381  
        382           //  Set Actio n Types
        383           fi nal Action ValuesType  actionsTy pe = new A ctionValue sType();
        384           ac tionsType. getValue() .add(Actio nType.ANNO UNCE);
        385           ac tionsType. getValue() .add(Actio nType.CHEC K_POLICY);
        386           ac tionsType. getValue() .add(Actio nType.MPI_ FIND_MATCH );
        387           ac tionsType. getValue() .add(Actio nType.ADD_ PATIENT_CO RRELATION) ;
        388           ac tionsType. setNotIn(f alse);
        389           ge tAuditsReq uest.setAc tions(acti onsType);
        390           //  Set MPI M atch
        391           if  ("all".eq uals(mpiMa tch) || Nu llChecker. isEmpty(mp iMatch)) {
        392                getAudit sRequest.s etDetails( null);
        393           }  else {
        394                getAudit sRequest.s etDetails( mpiMatch);
        395           }
        396           //  Set Page  Informatio n
        397           fi nal PageIn foType pag eInfoType  = new Page InfoType() ;
        398           pa geInfoType .setPageNu mber(pagin ator.getCu rrentPage( ));
        399           pa geInfoType .setPageSi ze(paginat or.getReco rdsPerPage ());
        400           ge tAuditsReq uest.setPa geInfo(pag eInfoType) ;
        401           //  TODO: Ana nd Sastry  / Weimin S hi - FIX I NTEGRATION  08/29/201 1 - END
        402           fi nal List<M ap<String,  Object>>  results =  new ArrayL ist<Map<St ring, Obje ct>>();
        403           tr y {
        404                final Ge tAuditsRes ponse quer yResponse  = this.ada pterAuditM anager
        405                         .getAudits (getAudits Request);
        406                int real PatientMes sages = 0;
        407                int real PatientFai ls = 0;
        408                int real PatientMat ches = 0;
        409                int test PatientMes sages = 0;
        410                int test PatientFai ls = 0;
        411                int test PatientMat ches = 0;
        412                HashSet< String> un iqueRealPa tients = n ew HashSet <String>() ;
        413                HashSet< String> un iqueTestPa tients = n ew HashSet <String>() ;
        414  
        415                if (Null Checker.is NotEmpty(q ueryRespon se)
        416                         && NullChe cker.isNot Empty(quer yResponse. getAudits( ))
        417                         && NullChe cker.isNot Empty(quer yResponse. getAudits( ).getAudit ())) {
        418                    fina l List<Aud itType> au ditTypeLis t = queryR esponse.ge tAudits(). getAudit() ;
        419                    int  pageSize =  paginator .getRecord sPerPage() ;
        420                    for  (final Aud itType aud itType : a uditTypeLi st) {
        421                         final Map< String, Ob ject> resu ltMap = ne w HashMap< String, Ob ject>();
        422                         String exp lanationOf Failure =  "N/A";
        423                         String pat ientFirstN ame = "";
        424                         String pat ientLastNa me = "";
        425                         String pat ientMiddle Name = "";
        426                         String pat ientSSN =  "";
        427                         Boolean mv iFindMatch Failed = n ull;
        428  
        429                         String det ails = Rep ortDataPro cessor.nul lEmptyRepl aceWithUnk nown(audit Type.getDe tails());
        430                         if (detail s.startsWi th("QUERY  FAILED"))  {
        431                             explan ationOfFai lure = "MV I: Query F ailed";
        432                             mviFin dMatchFail ed = true;
        433                         } else if  (details.s tartsWith( "MATCH FAI LED")) {
        434                             explan ationOfFai lure = "MV I: Match N ot Found";
        435                             mviFin dMatchFail ed = true;
        436                         } else if  (details.s tartsWith( "AMBIGUOUS  FAILED"))  {
        437                             explan ationOfFai lure = "MV I: Ambiguo us Match";
        438                             mviFin dMatchFail ed = true;
        439                         } else if  (details.s tartsWith( "MATCH FOU ND")) {
        440                             mviFin dMatchFail ed = false ;
        441                         }
        442                         resultMap. put("failu reExplanat ion", expl anationOfF ailure);
        443  
        444                         ReportHelp er reportH elper = ge tReportHel per();
        445                         if (Boolea n.TRUE.equ als(mviFin dMatchFail ed)) {
        446                             patien tFirstName  = getRepo rtHelper() .extractFr omDetails( details, " FIRSTNAME" );
        447                             patien tLastName  = reportHe lper.extra ctFromDeta ils(detail s, "LASTNA ME");
        448                             patien tMiddleNam e = report Helper.ext ractFromDe tails(deta ils, "MIDD LENAME");
        449                             patien tSSN = rep ortHelper. extractFro mDetails(d etails, "S SN");
        450                         }
        451                         if (patien tSSN.lengt h() == 0)  {
        452                             patien tSSN = aud itType.get PatientSSN ();
        453                         }
        454  
        455                         // SSN
        456                         ReportData Processor. addSsnToRe sultMap(re sultMap, p atientSSN) ;
        457  
        458                         boolean is TestPatien t = this.g etReportHe lper().isT estPatient (resultMap .get("ssn" ).toString ());
        459  
        460                         if (NullCh ecker.isNo tEmpty(pat ientSSN))  {
        461                             if (is TestPatien t) {
        462                                 if  (!uniqueT estPatient s.contains (patientSS N)) {
        463                                      uniqueTe stPatients .add(patie ntSSN);
        464                                 }
        465                             } else  {
        466                                 if  (!uniqueR ealPatient s.contains (patientSS N)) {
        467                                      uniqueRe alPatients .add(patie ntSSN);
        468                                 }
        469                             }
        470                         }
        471  
        472                         if (pageSi ze == -1 | | (testPat ientMessag es + realP atientMess ages) < pa geSize) {
        473                             if (is TestPatien t) {
        474                                 te stPatientM essages++;
        475                                 if  (Boolean. TRUE.equal s(mviFindM atchFailed )) {
        476                                      testPati entFails++ ;
        477                                 }  else if (B oolean.FAL SE.equals( mviFindMat chFailed))  {
        478                                      testPati entMatches ++;
        479                                 }
        480                             } else  {
        481                                 re alPatientM essages++;
        482                                 if  (Boolean. TRUE.equal s(mviFindM atchFailed )) {
        483                                      realPati entFails++ ;
        484                                 }  else if (B oolean.FAL SE.equals( mviFindMat chFailed))  {
        485                                      realPati entMatches ++;
        486                                 }
        487                             }
        488                         }
        489  
        490                         // First n ame.
        491                         if (patien tFirstName .length()  == 0) {
        492                             patien tFirstName  = ReportD ataProcess or.nullEmp tyReplaceW ithUnknown (auditType .getPatien tGivenName ());
        493                         }
        494                         resultMap. put("first Name", pat ientFirstN ame);
        495  
        496                         // Middle  name.
        497                         if (patien tMiddleNam e.length()  == 0) {
        498                             patien tMiddleNam e =  Repor tDataProce ssor.nullE mptyReplac eWithUnkno wn(auditTy pe.getPati entMiddleN ame());
        499                         }
        500                         if ("Unkno wn".equals IgnoreCase (patientMi ddleName))  {
        501                             patien tMiddleNam e = "";
        502                         }
        503                         resultMap. put("middl eName", pa tientMiddl eName);
        504  
        505                         // Last na me.
        506                         if (patien tLastName. length() = = 0) {
        507                             patien tLastName  = ReportDa taProcesso r.nullEmpt yReplaceWi thUnknown( auditType. getPatient LastName() );
        508                         }
        509                         resultMap. put("lastN ame", pati entLastNam e);
        510  
        511                         resultMap. put("icn",  ReportDat aProcessor .nullEmpty ReplaceWit hUnknown(a uditType.g etPatientI d()));
        512                         resultMap. put("audit Time", Gre gorianDate Util.getDa teFromGreg orianCalen dar(auditT ype.getAud itTime())) ;
        513                         resultMap. put("audit TimeFormat ted",
        514                                 th is.getRepo rtHelper()
        515                                 .g etFormatte dDateTime(
        516                                 Gr egorianDat eUtil
        517                                 .g etDateFrom GregorianC alendar(au ditType
        518                                 .g etAuditTim e())));
        519                         resultMap. put("userI d", Report DataProces sor
        520                                 .n ullEmptyRe placeWithU nknown(aud itType
        521                                 .g etUserId() ));
        522                         resultMap. put("purpo seOfUse",  ReportData Processor
        523                                 .n ullEmptyRe placeWithU nknown(aud itType
        524                                 .g etPurposeF orUse()));
        525                         resultMap. put("facil ityOid", R eportDataP rocessor.n ullEmptyRe placeWithU nknown(aud itType.get Organizati onId()));
        526                         resultMap. put("facil ity", Repo rtDataProc essor
        527                                 .n ullEmptyRe placeWithU nknown(aud itType
        528                                 .g etOrganiza tionName() ));
        529                         // if
        530                         // (NullCh ecker.isNu llOrEmpty( auditType. getOrganiz ationId()) )
        531                         // {
        532                         // logger. warning("R emoteOrgan izationId  Id is null /empty for  audit rec ord["
        533                         // + audit Type.getAu ditId() +  "], audit  details["+
        534                         // auditTy pe.getDeta ils() + "] ");
        535                         // }
        536                         resultMap. put("remot eFacilityO id", Repor tDataProce ssor.nullE mptyReplac eWithUnkno wn(auditTy pe.getRemo teOrganiza tionId())) ;
        537                         resultMap. put("remot eFacility" , ReportDa taProcesso r
        538                                 .n ullEmptyRe placeWithU nknown(aud itType
        539                                 .g etRemoteOr ganization Name()));
        540                         /*
        541                          * if
        542                          * (NullCh ecker.isNu llOrEmpty( auditType. getOrganiz ationId(
        543                          * ))) { L ogger.warn ing(
        544                          * "Organi zation Id  is null/em pty for au dit record [" +
        545                          * auditTy pe.getAudi tId() + "] , audit de tails["+
        546                          * auditTy pe.getDeta ils() + "] "); } resu ltMap.put(
        547                          * "facili ty", this. getCmsHelp er()
        548                          * .getOrg anizationB yHomeCommu nityId(
        549                          * auditTy pe.getOrga nizationId ())); if
        550                          * (NullCh ecker.isNu llOrEmpty
        551                          * (auditT ype.getOrg anizationI d())) { Lo gger.warni ng(
        552                          * "Remote Organizati onId Id is  null/empt y for audi t record["
        553                          * + audit Type.getAu ditId() +  "], audit  details["+
        554                          * auditTy pe.getDeta ils() + "] "); } resu ltMap.put(
        555                          * "remote Facility",  this.getC msHelper()
        556                          * .getOrg anizationB yHomeCommu nityId(
        557                          * auditTy pe.getRemo teOrganiza tionId())) ;
        558                          */
        559                         if (NullCh ecker.isNo tEmpty(aud itType.get Action()))  {
        560                             result Map.put("m essage", a uditType.g etAction() .name());
        561                         }
        562  
        563                         details =  processDat ails(detai ls);
        564  
        565                         resultMap. put("detai ls", detai ls);
        566  
        567                         results.ad d(resultMa p);
        568                    }
        569  
        570                    /*
        571                     * i f (NullChe cker.isNul lOrEmpty(a uditType.g etOrganiza tionId(
        572                     * ) )) { Logge r.warning(
        573                     * " Organizati on Id is n ull/empty  for audit  record[" +
        574                     * a uditType.g etAuditId( ) + "], au dit detail s["+
        575                     * a uditType.g etDetails( ) + "]");  } resultMa p.put( "fa cility",
        576                     * t his.getCms Helper() . getOrganiz ationByHom eCommunity Id(
        577                     * a uditType.g etOrganiza tionId())) ; if
        578                     * ( NullChecke r.isNullOr Empty (aud itType.get Organizati onId())) {
        579                     * L ogger.warn ing(
        580                     * " RemoteOrga nizationId  Id is nul l/empty fo r audit re cord[" +
        581                     * a uditType.g etAuditId( ) + "], au dit detail s["+
        582                     * a uditType.g etDetails( ) + "]");  } resultMa p.put(
        583                     * " remoteFaci lity", thi s.getCmsHe lper()
        584                     * . getOrganiz ationByHom eCommunity Id(
        585                     * a uditType.g etRemoteOr ganization Id()));
        586                     */
        587                }
        588                //set th ese outsid e of the n ull checke r just in  case we ge t an empty  response  we still d isplay cou nts
        589                session. setAttribu te("realPa tientMessa ges", real PatientMes sages);
        590                session. setAttribu te("realPa tientFails ", realPat ientFails) ;
        591                session. setAttribu te("realPa tientMatch es", realP atientMatc hes);
        592                session. setAttribu te("testPa tientMessa ges", test PatientMes sages);
        593                session. setAttribu te("testPa tientFails ", testPat ientFails) ;
        594                session. setAttribu te("testPa tientMatch es", testP atientMatc hes);
        595                session. setAttribu te("unique RealPatien ts", uniqu eRealPatie nts.size() );
        596                session. setAttribu te("unique TestPatien ts", uniqu eTestPatie nts.size() );
        597                return r esults;
        598  
        599           }  catch (fin al AuditEx ception ex ) {
        600                throw ne w AuditExc eption(ex) ;
        601           }
        602  
        603       }
        604  
        605       /**
        606        * Pro cesses Det ails prope rty as fol lows:
        607        * - M asks SSN
        608        * - R eplaces "M OTHERSMAID ENNAME" wi th "MMN"
        609        * @pa ram detail s Details  property o f AuditTyp e
        610        * @re turn Proce ssed Detai ls propert y string
        611        */
        612       privat e String p rocessData ils(String  details)  {
        613           //  Mask SSN
        614           in t pos1 = d etails.ind exOf("SSN= ");
        615           in t pos2;
        616           St ring ssn;
        617           if  (pos1 !=   -1) {
        618                pos2 = d etails.ind exOf(",",  pos1);
        619                if (pos2  != -1) {
        620                    ssn  = details. substring( pos1 + 4,  pos2).trim ();
        621                    if ( ssn.length () > 0) {
        622                         details =  details.su bstring(0,  pos1 + 4)  + ReportD ataProcess or.maskSsn (ssn) + de tails.subs tring(pos2 );
        623                    }
        624                }
        625           }
        626           //  Replace " MOTHERSMAI DENNAME" w ith "MMN"
        627           if  (details. contains(" MOTHERSMAI DENNAME=") ) {
        628                details  = details. replace("M OTHERSMAID ENNAME=",  "MMN=");
        629           }
        630           re turn detai ls;
        631       }
        632  
        633       privat e boolean  isPaginato rPresent(f inal HttpS ession ses sion) {
        634           re turn !Null Checker.is NullOrEmpt y(session. getAttribu te("pagina tor"));
        635       }
        636  
        637       public  void next (final Htt pServletRe quest requ est,
        638                final Ht tpServletR esponse re sponse) th rows Servl etExceptio n,
        639                IOExcept ion {
        640           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        641           if  (this.isP aginatorPr esent(sess ion)) {
        642                final Pa ginator pa ginator =  (Paginator ) session
        643                         .getAttrib ute("pagin ator");
        644                paginato r.next(req uest);
        645                session. setAttribu te("pagina tor", pagi nator);
        646                session. setAttribu te("patien tDiscovery Results",
        647                         this.getRe sults(sess ion, pagin ator));
        648                this.for ward(reque st, respon se, "show" );
        649           }  else {
        650                this.for ward(reque st, respon se, "nosho w");
        651           }
        652       }
        653  
        654       public  void prev (final Htt pServletRe quest requ est,
        655                final Ht tpServletR esponse re sponse) th rows Servl etExceptio n,
        656                IOExcept ion {
        657           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        658           if  (this.isP aginatorPr esent(sess ion)) {
        659                final Pa ginator pa ginator =  (Paginator ) session
        660                         .getAttrib ute("pagin ator");
        661                paginato r.previous (request);
        662                session. setAttribu te("pagina tor", pagi nator);
        663                session. setAttribu te("patien tDiscovery Results",
        664                         this.getRe sults(sess ion, pagin ator));
        665                this.for ward(reque st, respon se, "show" );
        666           }  else {
        667                this.for ward(reque st, respon se, "nosho w");
        668           }
        669       }
        670  
        671       @EJB(b eanInterfa ce = Adapt erAuditMan ager.class , mappedNa me = "Adap terAuditMa nager")
        672       public  void setA dapterAudi tManager(
        673                final Ad apterAudit Manager ad apterAudit Manager) {
        674           th is.adapter AuditManag er = adapt erAuditMan ager;
        675       }
        676  
        677       @Overr ide
        678       protec ted void u nspecified (final Htt pServletRe quest requ est,
        679                final Ht tpServletR esponse re sponse) th rows Servl etExceptio n,
        680                IOExcept ion {
        681           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        682  
        683           //  sort
        684           fi nal String  patientDi scoverySor tValue = r equest
        685                    .get Parameter( "patientDi scoverySor tValue");
        686           fi nal String  patientDi scoverySor tDirection  = request
        687                    .get Parameter( "patientDi scoverySor tDirection ");
        688           se ssion.setA ttribute(" patientDis coverySort Value",
        689                    pati entDiscove rySortValu e);
        690           se ssion.setA ttribute(" patientDis coverySort Direction" ,
        691                    pati entDiscove rySortDire ction);
        692  
        693           if  (this.isP aginatorPr esent(sess ion)) {
        694                Paginato r paginato r = (Pagin ator) sess ion.getAtt ribute("pa ginator");
        695                if (Null Checker.is Empty(pagi nator)) {
        696                    pagi nator = ne w Paginato r(0);
        697                    sess ion.setAtt ribute("pa ginator",  paginator) ;
        698                }
        699                paginato r.reset();
        700                session. setAttribu te("patien tDiscovery Results",
        701                         this.getRe sults(sess ion, pagin ator));
        702                this.for ward(reque st, respon se, "show" );
        703           }  else {
        704                this.for ward(reque st, respon se, "nosho w");
        705           }
        706       }
        707  
        708       privat e UserDocu mentDAO ge tUserDocum entDAO() {
        709           re turn this. getBean("U serDocumen tDAO", Use rDocumentD AO.class);
        710       }
        711   }