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

4315.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 OptInOptOutReport.java Fri Apr 21 20:15:58 2017 UTC

4315.2 Comparison summary

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

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

4315.4 Active regular expressions

No regular expressions were active.

4315.5 Comparison detail

        1   package go v.va.nvap. web.report ;
        2  
        3   import gov .va.nvap.c ommon.tran sformer.Tr ansformerE xception;
        4   import gov .va.nvap.c ommon.vali dation.Nul lChecker;
        5   import gov .va.nvap.c ommon.xpat h.XPathExc eption;
        6   import gov .va.nvap.s ervice.aud it.Consent AuditType;
        7   import gov .va.nvap.s vc.facilit y.data.Fac ility;
        8   import gov .va.nvap.w eb.app.Res ponseDispa tcherHttpS ervlet;
        9   import gov .va.nvap.w eb.consent .audit.Aud itedConsen tEx;
        10   import gov .va.nvap.w eb.consent .audit.dao .AuditedCo nsentDAO;
        11   import gov .va.nvap.w eb.dao.Fac ilityDAO;
        12   import gov .va.nvap.w eb.dao.Use rDocumentD AO;
        13   import gov .va.nvap.w eb.helper. document.D ocumentHel per;
        14   import gov .va.nvap.w eb.helper. document.M ediaType;
        15   import gov .va.nvap.w eb.helper. document.R epresentat ionType;
        16   import gov .va.nvap.w eb.helper. facility.F acilityHel per;
        17   import gov .va.nvap.w eb.helper. privacy.Co nsentManag ementHelpe r;
        18   import gov .va.nvap.w eb.helper. report.Rep ortHelper;
        19   import gov .va.nvap.w eb.patient .ExcelGene ratorThrea d;
        20   import gov .va.nvap.w eb.user.Us erHelper;
        21   import gov .va.nvap.w eb.util.Co nstants;
        22   import gov .va.nvap.w eb.util.Fi eldChecks;
        23   import gov .va.nvap.w eb.util.xl s.CsvExpor ter;
        24   import gov .va.nvap.w eb.util.xl s.ExcelExp orter;
        25   import jav a.io.IOExc eption;
        26   import jav a.io.Strin gWriter;
        27   import jav a.util.Arr ayList;
        28   import jav a.util.Col lection;
        29   import jav a.util.Dat e;
        30   import jav a.util.Has hMap;
        31   import jav a.util.Lin kedHashMap ;
        32   import jav a.util.Lis t;
        33   import jav a.util.Map ;
        34   import jav a.util.log ging.Level ;
        35   import jav a.util.log ging.Logge r;
        36   import jav ax.persist ence.Entit yManager;
        37   import jav ax.persist ence.Persi stenceCont ext;
        38   import jav ax.servlet .ServletEx ception;
        39   import jav ax.servlet .http.Http ServletReq uest;
        40   import jav ax.servlet .http.Http ServletRes ponse;
        41   import jav ax.servlet .http.Http Session;
        42   import org .apache.po i.ss.userm odel.Workb ook;
        43   import org .json.JSON Exception;
        44   import org .json.JSON Object;
        45  
        46   /**
        47    * Consent  Directive  Detail Re port searc h servlet
        48    *
        49    * @author  Asha Amri traj edite d by Steph en Miller
        50    */
        51   public cla ss OptInOp tOutReport  extends R esponseDis patcherHtt pServlet {
        52  
        53       privat e static f inal Logge r logger =  Logger.ge tLogger(Op tInOptOutR eport.clas s.getName( ));
        54  
        55       /**
        56        * Ser ial UID.
        57        */
        58       privat e static f inal long  serialVers ionUID = 3 7215033550 79491829L;
        59  
        60       /**
        61        * Ent ity Manage r instance .
        62        */
        63       @Persi stenceCont ext
        64       privat e EntityMa nager em;
        65  
        66       /**
        67        * Get  the CMS h elper from  Spring.
        68        * @re turn Conse ntManageme ntHelper
        69        */
        70       public  ConsentMa nagementHe lper getCm sHelper()  {
        71           fi nal Consen tManagemen tHelper cm sHelper =  this.getBe an("cmsHel per",
        72                ConsentM anagementH elper.clas s);
        73           re turn cmsHe lper;
        74       }
        75  
        76       /**
        77        * Get  the facil ity helper  from Spri ng.
        78        * @re turn Facil ityHelper
        79        */
        80       public  FacilityH elper getF acilityHel per() {
        81           fi nal Facili tyHelper f acilityHel per = this .getBean(" facilityHe lper",
        82                Facility Helper.cla ss);
        83           re turn facil ityHelper;
        84       }
        85  
        86       /**
        87        * Set  the entit y manager  (Injected  by Spring) .
        88        * @pa ram em Ent ity Manage r
        89        */
        90       public  void setE ntityManag er(final E ntityManag er em) {
        91           th is.em = em ;
        92       }
        93  
        94       @Overr ide
        95       protec ted void u nspecified (final Htt pServletRe quest requ est,
        96           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception,
        97           IO Exception  {
        98           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        99           se ssion.remo veAttribut e("results ");
        100  
        101           Co llection<F acility> f acilities  = this.get FacilityHe lper().get AllVistAFa cilities() ;
        102           re quest.setA ttribute(" facilities ", facilit ies);
        103           re quest.setA ttribute(" optOutReas ons", this .getCmsHel per().getO ptoutReaso ns());
        104  
        105           fi nal gov.va .nvap.svc. facility.d ata.Facili ty default UserFacili ty
        106                = (gov.v a.nvap.svc .facility. data.Facil ity) sessi on.getAttr ibute("def aultUserFa cility");
        107  
        108           Re portHelper .setDefaul tSearchDat es(session );
        109           th is.forward (request,  response,  "show");
        110       }
        111  
        112        /**
        113        * Ret urns searc h results  in JSON fo rm. JSON c ontains tw o arrays:  "data" and  "summary" .
        114        * If  no request  parameter s are pres ent, defau lt values  are used f or search.
        115        *
        116        * @pa ram reques t
        117        * @pa ram respon se
        118        * @th rows Servl etExceptio n
        119        * @th rows IOExc eption
        120        */
        121       public  void doSe arch(HttpS ervletRequ est reques t, HttpSer vletRespon se respons e) throws  ServletExc eption, IO Exception,  Transform erExceptio n, XPathEx ception {
        122           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        123  
        124           Se archPackag e results  = getResul ts(request , false);
        125           se ssion.setA ttribute(" results",  encodeInto JSON(resul ts, reques t.getParam eter("draw ")));
        126  
        127           th is.forward (request,  response,  "searchRes ultsJSON") ;
        128       }
        129  
        130       /**
        131        * Ret urns packa ged query  results.
        132        * @pa ram reques t
        133        * @pa ram getAll
        134        * @re turn
        135        * @th rows Servl etExceptio n
        136        * @th rows Trans formerExce ption
        137        * @th rows XPath Exception
        138        */
        139       privat e SearchPa ckage getR esults(fin al HttpSer vletReques t request,  boolean e xporting)  throws Ser vletExcept ion, Trans formerExce ption, XPa thExceptio n {
        140           fi nal Audite dConsentDA O auditedC onsentDAO  = this.get Bean("audi tedConsent DAO", Audi tedConsent DAO.class) ;
        141           fi nal Audite dConsentDA O.DetailRe quest req  = auditedC onsentDAO. new Detail Request();
        142  
        143           re q.patientF irstName =  request.g etParamete r("firstNa me");
        144           re q.patientL astName =  request.ge tParameter ("lastName ");
        145           re q.patientS sn = reque st.getPara meter("ssn ");
        146           re q.stationN umbers = r equest.get Parameter( "stationNu mbers");
        147           re q.consentT ype = requ est.getPar ameter("co nsentType" );
        148           re q.inactiva tionReason  = request .getParame ter("inact ivationRea son");
        149           re q.startDat e = Report Helper.get StartDate( request.ge tParameter ("startDat e"));
        150           re q.endDate  = ReportHe lper.getEn dDate(requ est.getPar ameter("en dDate"));
        151           re q.patientT ypes = Int eger.parse Int(reques t.getParam eter("pati entTypes") );
        152           re q.userId =  request.g etParamete r("entered By");
        153           re q.includeU nknownVisn  = "true". equals(req uest.getPa rameter("i ncludeUnkn ownVisn")) ;
        154           re q.sortFiel d = (reque st.getPara meter("ord er[0][colu mn]") !=nu ll)
        155                    ? ge tSortValue (request.g etParamete r("order[0 ][column]" )) : getSo rtValue(re quest.getP arameter(" sortBy"));
        156           re q.sortDire ction = (r equest.get Parameter( "order[0][ dir]") !=n ull)
        157                    ?req uest.getPa rameter("o rder[0][di r]") : req uest.getPa rameter("s ortOrder") ;
        158           re q.currentP age = (req uest.getPa rameter("s tart") !=  null)
        159                    ?Int eger.parse Int(reques t.getParam eter("star t"))/Integ er.parseIn t(request. getParamet er("length ")) : 0;
        160           re q.pageSize  = (reques t.getParam eter("leng th")!=null )
        161                    ?Int eger.parse Int(reques t.getParam eter("leng th")): -1;
        162  
        163  
        164           //  The resul t of the q uery is a  list of ar rays.
        165           //  Each arra y is a [Au ditedConse nt, Facili ty, Visn]
        166           Li st<Object>  auditedCo nsentExLis t = audite dConsentDA O.getEvent s(req);
        167  
        168           fi nal List<M ap<String,  Object>>  results =  new ArrayL ist<Map<St ring, Obje ct>>();
        169           if  (NullChec ker.isNotE mpty(audit edConsentE xList)) {
        170                for (fin al Object  o : audite dConsentEx List) {
        171                    Audi tedConsent Ex auditTy pe = (Audi tedConsent Ex) o;
        172  
        173                    fina l Map<Stri ng, Object > resultMa p = new Ha shMap<Stri ng, Object >();
        174  
        175                    // R eplace SSN  with Mask
        176                    Repo rtDataProc essor.addS snToResult Map(result Map, audit Type.getPa tientSsn() );
        177  
        178                    resu ltMap.put( "icn", aud itType.get PatientId( ));
        179                    resu ltMap.put( "auditTime ", auditTy pe.getTime OfEvent()) ;
        180                    resu ltMap.put( "auditTime Formatted" , this.get ReportHelp er()
        181                         .getFormat tedDateTim e(auditTyp e.getTimeO fEvent())) ;
        182                    resu ltMap.put( "userId",  auditType. getUserId( ));
        183                    resu ltMap.put( "actionTyp e", auditT ype.getAct ionType()) ;
        184  
        185                    Stri ng consent TypeRow =  auditType. getConsent Type();
        186                    if ( consentTyp eRow.conta ins("NwHIN ")) {
        187                         consentTyp eRow = con sentTypeRo w.replace( "NwHIN", C onstants.g etOrganiza tionName() );
        188                    }
        189                    resu ltMap.put( "consentTy pe", conse ntTypeRow) ;
        190                    resu ltMap.put( "firstName ", auditTy pe.getPati entGivenNa me());
        191                    resu ltMap.put( "lastName" , auditTyp e.getPatie ntLastName ());
        192                    resu ltMap.put( "purposeOf Use", audi tType.getP ouValue()) ;
        193  
        194                    Stri ng inactiv ationReaso nRow = aud itType.get OptoutReas on();
        195                    resu ltMap.put( "inactivat ionReason" , inactiva tionReason Row);
        196                    resu ltMap.put( "patientDa te", audit Type.getCr eatedDate( ));
        197                    resu ltMap.put( "patientDa teFormatte d", this.g etReportHe lper()
        198                         .getFormat tedDate(au ditType.ge tCreatedDa te()));
        199  
        200                                      // final  String va Facility =  this.getF acilityHel per()
        201                    // . getFacilit yNameBySta tionId(aud itType.get Facility() );
        202                    // r esultMap.p ut("facili ty",
        203                    // R eportDataP rocessor.f ixStation( vaFacility ));
        204                    resu ltMap.put( "facilityN ame", Repo rtDataProc essor
        205                         .fixStatio n(auditTyp e.getFacil ityName()) );
        206                    resu ltMap.put( "facilityI d", auditT ype.getFac ility());
        207                    resu ltMap.put( "visnName" , NullChec ker.isNull OrEmpty(au ditType.ge tVisnName( )) ? "Unkn own" : aud itType.get VisnName() );
        208  
        209                    if ( ConsentAud itType.OPT IN_AUDIT_T YPE.value( ).equals(
        210                         auditType. getActionT ype())
        211                         || Consent AuditType. OPTOUT_AUD IT_TYPE.va lue().equa ls(
        212                             auditT ype.getAct ionType()) ) {
        213                         resultMap. put("audit Id", audit Type.getCo nsentAudit Id());
        214                         if (!expor ting) {
        215                             // Get  the CDA R 2 Content  from Audit
        216                             final  String con tent = aud itedConsen tDAO
        217                                 .g etMessageC ontent(aud itType.get ConsentAud itId());
        218                             if (Nu llChecker. isNotEmpty (content))  {
        219                                 fi nal String  attachmen t = this.g etDocument Helper()
        220                                          .get PrivacyCon sentDirect iveAttachm ent(
        221                                                   conten t);
        222                                 if  (NullChec ker.isNotE mpty(attac hment)) {
        223                                      resultMa p.put("has Attachment ", true);
        224                                 }  else {
        225                                      resultMa p.put("has Attachment ", false);
        226                                 }
        227                             }
        228                         }
        229                    }
        230                    resu lts.add(Fi eldChecks. replaceEmp tyOrNullWi thSpace(re sultMap));
        231                }
        232           }
        233  
        234           //  Check if  any of the  patient m atch crite ria exists
        235           St ring resul tIcn = "";
        236           if  (NullChec ker.isNotE mpty(req.p atientSsn)  || NullCh ecker.isNo tEmpty(req .patientLa stName)
        237                || NullC hecker.isN otEmpty(re q.patientF irstName))  {
        238                // Defau lt to unkn own
        239                if (Null Checker.is NotEmpty(a uditedCons entExList) ) {
        240                    fina l AuditedC onsentEx r esult = (A uditedCons entEx) aud itedConsen tExList.ge t(0);
        241                    resu ltIcn = re sult.getPa tientId();
        242  
        243                    if ( NullChecke r.isNotEmp ty(resultI cn)) {
        244                         for (final  Object o  : auditedC onsentExLi st) {
        245                             Audite dConsentEx  consent =  (AuditedC onsentEx)  o;
        246                             if (!r esultIcn.e quals(cons ent.getPat ientId()))  {
        247                                 re sultIcn =  "Multiple  ICNs";
        248                                 br eak;
        249                             }
        250                         }
        251                    } el se if (Nul lChecker.i sNotEmpty( result.get PatientGiv enName())
        252                         && NullChe cker.isNot Empty(resu lt.getPati entLastNam e())
        253                         && NullChe cker.isNot Empty(resu lt.getPati entSsn()))  {
        254                         final Stri ng patient GivenName  = result
        255                             .getPa tientGiven Name();
        256                         final Stri ng patient LastName =  result.ge tPatientLa stName();
        257                         final Stri ng patient Ssn = resu lt.getPati entSsn();
        258                         boolean mu ltipleIcns  = false;
        259                         for (final  Object o  : auditedC onsentExLi st) {
        260                             Audite dConsentEx  consent =  (AuditedC onsentEx)  o;
        261                             if (!p atientGive nName.equa ls(consent
        262                                 .g etPatientG ivenName() )
        263                                 ||  !patientL astName.eq uals(conse nt
        264                                      .getPati entLastNam e())
        265                                 ||  !patientS sn.equals( consent.ge tPatientSs n())) {
        266                                 mu ltipleIcns  = true;
        267                                 br eak;
        268                             }
        269                         }
        270                         if (multip leIcns) {
        271                             result Icn = "Mul tiple ICNs ";
        272                         } else {
        273                             result Icn = this .getReport Helper().r esolveICN(
        274                                 re sult.getPa tientGiven Name(),
        275                                 re sult.getPa tientLastN ame(),
        276                                 re sult.getPa tientSsn() );
        277                         }
        278                    }
        279                } else i f (NullChe cker.isNot Empty(req. patientSsn )
        280                    && N ullChecker .isNotEmpt y(req.pati entLastNam e)
        281                    && N ullChecker .isNotEmpt y(req.pati entFirstNa me)) {
        282                    // T ry to get  from what  was typed
        283                    resu ltIcn = th is.getRepo rtHelper() .resolveIC N(req.pati entFirstNa me,
        284                         req.patien tLastName,  req.patie ntSsn);
        285                }
        286                // Set i n Session
        287                if (Null Checker.is Empty(resu ltIcn)) {
        288                    resu ltIcn = "U nknown";
        289                }
        290           }
        291  
        292           // Grab to to tal count  of the sea rch result s, not jus t the coun t of the c urrent bat ch but ove rall for p agination.
        293           fi nal Long t otalCount  = exportin g ? 0 : au ditedConse ntDAO.getE ventsCount (req);
        294  
        295           re turn new S earchPacka ge(results , resultIc n, totalCo unt);
        296       }
        297  
        298       /**
        299        * cha nges searc h package  into json  string for  passing t o datatabl es.
        300        * @pa ram packed Results
        301        * @re turn
        302        */
        303       privat e String e ncodeIntoJ SON(Search Package pa ckedResult s, String  draw){
        304           St ring retur nValue = " ";
        305  
        306           tr y {
        307                StringWr iter json  = new Stri ngWriter() ;
        308                JSONObje ct obj = n ew JSONObj ect();
        309                List<Lis t> data =  new ArrayL ist<List>( );
        310  
        311                for (Map <String,Ob ject> curr entRow : p ackedResul ts.getResu lts()) {
        312                    List <String> d ataItem =  new ArrayL ist<String >();
        313  
        314                    data Item.add(c urrentRow. get("ssnMa sked").toS tring());
        315                    data Item.add(c urrentRow. get("lastN ame").toSt ring());
        316                    data Item.add(c urrentRow. get("first Name").toS tring());
        317                    data Item.add(c urrentRow. get("audit TimeFormat ted").toSt ring());
        318                    data Item.add(c urrentRow. get("patie ntDateForm atted").to String());
        319                    data Item.add(c urrentRow. get("purpo seOfUse"). toString() );
        320                    data Item.add(c urrentRow. get("conse ntType").t oString()) ;
        321                    data Item.add(c urrentRow. get("inact ivationRea son").toSt ring());
        322                    data Item.add(c urrentRow. get("userI d").toStri ng());
        323                    data Item.add(c urrentRow. get("facil ityName"). toString() );
        324                    data Item.add(c urrentRow. get("facil ityId").to String());
        325                    data Item.add(c urrentRow. get("visnN ame").toSt ring());
        326                    data Item.add(c urrentRow. get("audit Id").toStr ing());
        327                    data Item.add(c urrentRow. get("ssn") .toString( ));
        328  
        329                    if(c urrentRow. containsKe y("hasAtta chment")){
        330                         dataItem.a dd(current Row.get("h asAttachme nt").toStr ing());
        331                    }
        332  
        333                    data .add(dataI tem);
        334                }
        335  
        336                obj.put( "data", da ta);
        337                obj.put( "draw", In teger.pars eInt(draw) );
        338                obj.put( "recordsTo tal", pack edResults. getResultC ount());
        339                obj.put( "recordsFi ltered", p ackedResul ts.getResu ltCount()) ;
        340                obj.put( "icn", pac kedResults .getIcn()) ;
        341  
        342                obj.writ e(json);
        343  
        344                returnVa lue = json .toString( );
        345           }  catch (JSO NException  ex) {
        346                Logger.g etLogger(O ptInOptOut Report.cla ss.getName ()).log(Le vel.SEVERE , null, ex );
        347           }
        348  
        349           re turn retur nValue;
        350  
        351       }
        352  
        353       /**
        354        * con vert colum n number i nto correc t sort val ue
        355        * @pa ram colNum ber
        356        * @re turn
        357        */
        358       privat e String g etSortValu e(String c olNumber){
        359           St ring sortV alue = "";
        360  
        361           if (null != c olNumber)  switch (In teger.pars eInt(colNu mber)) {
        362                case 0:
        363                    sort Value = "p atientSsn" ;
        364                    brea k;
        365                case 1:
        366                    sort Value = "p atientLast Name";
        367                    brea k;
        368                case 2:
        369                    sort Value = "p atientGive nName";
        370                    brea k;
        371                case 3:
        372                    sort Value = "t imeOfEvent ";
        373                    brea k;
        374                case 4:
        375                    sort Value = "c reatedDate ";
        376                    brea k;
        377                case 5:
        378                    sort Value = "p ouValue";
        379                    brea k;
        380                case 6:
        381                    sort Value = "c onsentType ";
        382                    brea k;
        383                case 7:
        384                    sort Value = "o ptoutReaso n";
        385                    brea k;
        386                case 8:
        387                    sort Value = "u serId";
        388                    brea k;
        389                case 9:
        390                    sort Value = "f acilityNam e";
        391                    brea k;
        392                case 10:
        393                    sort Value = "f acility";
        394                    brea k;
        395                case 11:
        396                    sort Value = "v isnName";
        397                    brea k;
        398           }
        399           re turn sortV alue;
        400       }
        401  
        402       /**
        403        * Exp ort to exc el - This  method is  called whe n the user  clicks on  the excel  icon in t he JSP. Re flection i s used in  the
        404        * Res ponseDispa tcherHttpS ervlet to  call this  method bas ed on the  http param eters.
        405        *
        406        * @pa ram reques t HTTP Req uest
        407        * @pa ram respon se HTTP Re sponse
        408        * @th rows Servl etExceptio n
        409        * @th rows IOExc eption
        410        */
        411       public  void expo rtToExcel( final Http ServletReq uest reque st,
        412           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception, I OException , Transfor merExcepti on, XPathE xception {
        413  
        414           //  Create a  map of key  which is  based on t he result  data key a nd the hea ding value
        415           // The headin g is used  to create  the column  headers a nd the
        416           // key is use d to pull  the data f rom the re sults
        417           fi nal Map<St ring, Stri ng> report Map = new  LinkedHash Map<String , String>( );
        418  
        419           //  Generate  filters.
        420           fi nal Map<St ring, List <Object>>  filterMap  = new Link edHashMap< String, Li st<Object> >();
        421           fi nal Linked HashMap<St ring, Obje ct> filter s = new Li nkedHashMa p<String,  Object>();
        422  
        423           fi nal Date s tartDateSt r = Report Helper.get StartDate( request.ge tParameter ("startDat e"));
        424           fi nal Date e ndDateStr  = ReportHe lper.getEn dDate(requ est.getPar ameter("en dDate"));
        425           fi nal String  consentTy pe = getCo nsentTypeF ilterText( request.ge tParameter ("consentT ype"));
        426  
        427           fi lters.put( "SSN", req uest.getPa rameter("s sn"));
        428           fi lters.put( "Last Name ", request .getParame ter("lastN ame"));
        429           fi lters.put( "First Nam e", reques t.getParam eter("firs tName"));
        430           fi lters.put( "Start Dat e", startD ateStr ==  null ? ""  : this.get ReportHelp er().getFo rmattedDat e(startDat eStr));
        431           fi lters.put( "End Date" , endDateS tr == null  ? "" : th is.getRepo rtHelper() .getFormat tedDate(en dDateStr)) ;
        432           fi lters.put( "Authentic ating Faci lity", Exc elExporter .getFacili tiesFilter (getFacili tyDAO(), r equest.get Parameter( "stationNu mbers")));
        433           fi lters.put( "Consent T ype", Exce lExporter. getFilterV alue(conse ntType));
        434           if  (consentT ype.contai ns("Revoca tion")) {
        435                filters. put("Inact ivation Re ason", Exc elExporter .getFilter Value(requ est.getPar ameter("in activation Reason"))) ;
        436           }
        437           fi lters.put( "Entered B y", reques t.getParam eter("ente redBy"));
        438           Ex celExporte r.populate FilterMapF orExport(r equest, fi lters, fil terMap, re quest.getP arameter(" patientTyp es"));
        439  
        440           re portMap.pu t("ssn", " SSN");
        441           re portMap.pu t("lastNam e", "Patie nt Last Na me");
        442           re portMap.pu t("firstNa me", "Pati ent First  Name");
        443           re portMap.pu t("auditTi meFormatte d", "Time  of Event ( CT)");
        444           re portMap.pu t("patient DateFormat ted", "Pat ient Signa ture/Patie nt Decease d Date");
        445           re portMap.pu t("purpose OfUse", "P urpose of  Use");
        446           re portMap.pu t("consent Type", "Co nsent Type ");
        447           re portMap.pu t("inactiv ationReaso n", "Inact ivation Re ason");
        448           re portMap.pu t("userId" , "Entered  By");
        449           re portMap.pu t("facilit yName", "A uthenticat ing Facili ty");
        450           re portMap.pu t("facilit yId", "Aut henticatin g Facility  Station I D");
        451           re portMap.pu t("visnNam e", "VISN" );
        452  
        453           in t minimumT hreshold =  Integer.p arseInt((S tring) thi s.getServl etContext( ).getAttri bute("sche duledExpor tMin"));
        454           in t total =  Integer.pa rseInt(req uest.getPa rameter("t otalRows") );
        455  
        456           if  (total >=  minimumTh reshold) {
        457                // Start  a schedul ed export  with its o wn thread  if number  of rows is  greater t han the mi nimum thre shold
        458                ExcelGen eratorThre ad exGenTh read = new  ExcelGene ratorThrea d("exGenTh read");
        459                exGenThr ead.setFil terMap(fil terMap);
        460                exGenThr ead.setRep ortMap(rep ortMap);
        461                // Set n ames for E xcel gener ator threa d
        462                exGenThr ead.setTit le("Consen t Directiv e Detail R eport");
        463  
        464                exGenThr ead.setExc elExporter (this.getE xcelExport er());
        465                exGenThr ead.setRep ortHelper( getReportH elper());
        466                exGenThr ead.setUse rId(UserHe lper.getUs erName(req uest));
        467                exGenThr ead.setAud itedConsen tDAO(this. getBean("a uditedCons entDAO", A uditedCons entDAO.cla ss));
        468                exGenThr ead.setDoc umentHelpe r(getDocum entHelper( ));
        469                exGenThr ead.setUse rDocumentD ao(getUser DocumentDA O());
        470  
        471                // Set s earch attr ibutes for  getting a udit resul ts
        472                exGenThr ead.setAtt ributes(ma pSessionAt tributes(r equest));
        473  
        474                exGenThr ead.start( );
        475           }  else {
        476                // Other wise gener ate and do wnload the  export di rectly
        477                logger.l og(Level.S EVERE, "EX PORT_EXCEL _CDDR_BEGI N_" + Thre ad.current Thread().g etId() + "  " + Syste m.currentT imeMillis( ));
        478                // Creat e workbook
        479                final St ring title  = "Consen t Directiv e Detail R eport";
        480  
        481                List<Map <String, O bject>> re sults;
        482                OptInOpt OutReport. SearchPack age packed Results;
        483                packedRe sults = th is.getResu lts(reques t, true);
        484                results  = packedRe sults.getR esults();
        485  
        486                final Wo rkbook wb  = this.get ExcelExpor ter().expo rtToExcel( title, tit le, report Map, resul ts, filter Map, null) ;
        487  
        488                // Write  Excel wor kbook to S tream
        489                this.get ExcelExpor ter().writ eExcelToSt ream("Cons ent_Direct ive_Detail _Report",  wb, respon se);
        490                logger.l og(Level.S EVERE, "EX PORT_EXCEL _CDDR_END_ " + Thread .currentTh read().get Id() + " "  + System. currentTim eMillis()) ;
        491           }
        492       }
        493  
        494       privat e Map<Stri ng, Object > mapSessi onAttribut es(HttpSer vletReques t request)  {
        495           Ma p<String,  Object> at tributes =  new HashM ap<String,  Object>() ;
        496  
        497           at tributes.p ut("ssn",  request.ge tParameter ("ssn"));
        498           at tributes.p ut("lastNa me", reque st.getPara meter("las tName"));
        499           at tributes.p ut("firstN ame", requ est.getPar ameter("fi rstName")) ;
        500           at tributes.p ut("userId ", request .getParame ter("enter edBy"));
        501           Da te startDa te = Repor tHelper.ge tStartDate (request.g etParamete r("startDa te"));
        502           Da te endDate  = ReportH elper.getE ndDate(req uest.getPa rameter("e ndDate"));
        503           at tributes.p ut("startD ate", star tDate);
        504           at tributes.p ut("endDat e", endDat e);
        505  
        506           // attributes .put("orga nization",  (String)  session
        507                    //.g etAttribut e("documen tDisclosur eQueryOrga nization") );
        508           at tributes.p ut("statio nNumbers",  (String)  request.ge tParameter ("stationN umbers"));
        509           at tributes.p ut("patien tTypes", I nteger.par seInt(requ est.getPar ameter("pa tientTypes ")));
        510           at tributes.p ut("consen tType", re quest.getP arameter(" consentTyp e"));
        511           at tributes.p ut("inacti vationReas on", reque st.getPara meter("ina ctivationR eason"));
        512           at tributes.p ut("includ eUnknownVi sn", "true ".equals(r equest.get Parameter( "includeUn knownVisn" )));
        513           //  sort
        514           at tributes.p ut("sortVa lue", getS ortValue(r equest.get Parameter( "sortBy")) );
        515           at tributes.p ut("sortDi rection",  request.ge tParameter ("sortOrde r"));
        516  
        517           //  Set Actio n Types
        518           Li st<String>  actionTyp es = new A rrayList<S tring>();
        519           ac tionTypes. add(Consen tAuditType .OPTIN_AUD IT_TYPE.va lue());
        520           ac tionTypes. add(Consen tAuditType .OPTOUT_AU DIT_TYPE.v alue());
        521           at tributes.p ut("action Types", ac tionTypes) ;
        522  
        523           re turn attri butes;
        524       }
        525  
        526       public  void expo rtToCsv(fi nal HttpSe rvletReque st request ,
        527           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception, I OException , Transfor merExcepti on, XPathE xception {
        528  
        529           Ma p<String,  String> cs vReportMap  = new Lin kedHashMap <String, S tring>();
        530  
        531           cs vReportMap .put("SSN" , "ssn");
        532           cs vReportMap .put("Pati ent Last N ame", "las tName");
        533           cs vReportMap .put("Pati ent First  Name", "fi rstName");
        534           cs vReportMap .put("Time  of Event  (CT)", "au ditTimeFor matted");
        535           cs vReportMap .put("Pati ent Signat ure/Patien t Deceased  Date", "p atientDate Formatted" );
        536           cs vReportMap .put("Purp ose of Use ", "purpos eOfUse");
        537           cs vReportMap .put("Cons ent Type",  "consentT ype");
        538           cs vReportMap .put("Inac tivation R eason", "i nactivatio nReason");
        539           cs vReportMap .put("Ente red By", " userId");
        540           cs vReportMap .put("Auth enticating  Facility" , "facilit yName");
        541           cs vReportMap .put("Auth enticating  Facility  Station ID ", "facili tyId");
        542           cs vReportMap .put("VISN ", "visnNa me");
        543  
        544           in t minimumT hreshold =  Integer.p arseInt((S tring) thi s.getServl etContext( ).getAttri bute("sche duledExpor tMin"));
        545           in t total =  Integer.pa rseInt(req uest.getPa rameter("t otalRows") );
        546  
        547           if  (total >=  minimumTh reshold) {
        548                // Start  a schedul ed export  with its o wn thread  if number  of rows is  greater t han the mi nimum thre shold
        549                ExcelGen eratorThre ad csvGenT hread = ne w ExcelGen eratorThre ad("csvGen Thread");
        550                csvGenTh read.setDo cumentType ("csv");
        551                csvGenTh read.setRe portMap(cs vReportMap );
        552                csvGenTh read.setTi tle("Conse nt Directi ve Detail  Report");
        553                csvGenTh read.setEx celExporte r(this.get ExcelExpor ter());
        554                csvGenTh read.setRe portHelper (getReport Helper());
        555                csvGenTh read.setUs erId(UserH elper.getU serName(re quest));
        556                csvGenTh read.setDo cumentHelp er(getDocu mentHelper ());
        557                csvGenTh read.setAu ditedConse ntDAO(this .getAudite dConsentDA O());
        558                csvGenTh read.setUs erDocument Dao(getUse rDocumentD AO());
        559  
        560                // Set s earch attr ibutes for  getting a udit resul ts
        561                csvGenTh read.setAt tributes(m apSessionA ttributes( request));
        562  
        563                csvGenTh read.start ();
        564           }  else {
        565                // Other wise gener ate and do wnload the  export di rectly
        566                logger.l og(Level.S EVERE, "EX PORT_CSV_C DDR_BEGIN_ " + Thread .currentTh read().get Id() + " "  + System. currentTim eMillis()) ;
        567                List<Map <String, O bject>> re sults;
        568                SearchPa ckage pack edResults;
        569  
        570                packedRe sults = th is.getResu lts(reques t, true);
        571                results  = packedRe sults.getR esults();
        572  
        573                CsvExpor ter csvExp orter = ne w CsvExpor ter();
        574                csvExpor ter.export ToCSV(resp onse, "Con sent_Direc tive_Detai l_Report",  results,  (LinkedHas hMap<Strin g, String> ) csvRepor tMap);
        575                logger.l og(Level.S EVERE, "EX PORT_CSV_C DDR_BEGIN_ " + Thread .currentTh read().get Id() + " "  + System. currentTim eMillis()) ;
        576           }
        577       }
        578  
        579       public  void view (final Htt pServletRe quest requ est,
        580           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception,
        581           IO Exception  {
        582           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        583           fi nal String  documentU niqueId =  request
        584                .getPara meter("doc umentUniqu eId");
        585  
        586           fi nal Audite dConsentDA O auditedC onsentDAO  = this.get Bean(
        587                "audited ConsentDAO ", Audited ConsentDAO .class);
        588           fi nal String  document  = auditedC onsentDAO. getMessage Content(Lo ng
        589                .parseLo ng(documen tUniqueId) );
        590  
        591           se ssion.setA ttribute(" document",  document) ;
        592           se ssion.setA ttribute(" documentUn iqueId", d ocumentUni queId);
        593  
        594           tr y {
        595                final St ring attac hment = th is.getDocu mentHelper ()
        596                    .get PrivacyCon sentDirect iveAttachm ent(docume nt);
        597                if (Null Checker.is NotEmpty(a ttachment) ) {
        598                    this .getDocume ntHelper()
        599                         .writeAtta chmentToSt ream(
        600                             respon se,
        601                             attach ment,
        602                             MediaT ype.fromVa lue(this.g etDocument Helper()
        603                                 .g etPrivacyC onsentDire ctiveMedia Type(
        604                                      document )),
        605                             Repres entationTy pe.B64);
        606                } else {
        607                    sess ion.setAtt ribute("in formationM essage",
        608                         "There are  no attach ments asso ciated wit h this con sent direc tive.");
        609                    this .forward(r equest, re sponse, "n oattachmen t");
        610                }
        611           }  catch (fin al Transfo rmerExcept ion ex) {
        612                throw ne w ServletE xception(e x);
        613           }  catch (fin al XPathEx ception ex ) {
        614                throw ne w ServletE xception(e x);
        615           }
        616       }
        617  
        618       privat e AuditedC onsentDAO  getAudited ConsentDAO () {
        619           re turn this. getBean("a uditedCons entDAO", A uditedCons entDAO.cla ss);
        620       }
        621  
        622       privat e String g etConsentT ypeFilterT ext(String  consentTy pe) {
        623           if  (NullChec ker.isNull OrEmpty(co nsentType) ) {
        624                return " ALL";
        625           }  else if (c onsentType .equalsIgn oreCase("a llAuthoriz ations"))  {
        626                return " ALL Author izations";
        627           }  else if (c onsentType .equalsIgn oreCase("a llRevocati ons")) {
        628                 return  "ALL Revoc ations";
        629           }  else if (c onsentType .equalsIgn oreCase("N wHINAuthor izations") ) {
        630                 return  "eHealth E xchange Au thorizatio ns";
        631           }  else if (c onsentType .equalsIgn oreCase("S SAAuthoriz ations"))  {
        632                return " SSA Author izations";
        633           }  else if (c onsentType .equalsIgn oreCase("N wHINRevoca tions")) {
        634                return " eHealth Ex change Rev ocations";
        635           }  else if (c onsentType .equalsIgn oreCase("S SARevocati ons")) {
        636                return " SSA Revoca tions";
        637           }  else if (c onsentType .equalsIgn oreCase("N wHINRestri ctions"))  {
        638                return " eHealth Ex change Res trictions" ;
        639           }  else if (c onsentType .equalsIgn oreCase("N wHINRestri ctionRevoc ations"))  {
        640                return " eHealth Ex change Res triction R evocations ";
        641           }  else {
        642                return " ";
        643           }
        644       }
        645  
        646       /**
        647        * Get  the excel  exporter  class from  Spring.
        648        *
        649        * @re turn the e xcel expor ter object
        650        */
        651       public  ExcelExpo rter getEx celExporte r() {
        652           fi nal ExcelE xporter ex celExporte r = this.g etBean("ex celExporte r",
        653                ExcelExp orter.clas s);
        654           re turn excel Exporter;
        655       }
        656  
        657       privat e Facility DAO getFac ilityDAO()  {
        658           re turn this. getBean("F acilityDAO ", Facilit yDAO.class );
        659       }
        660  
        661       privat e UserDocu mentDAO ge tUserDocum entDAO() {
        662           re turn this. getBean("U serDocumen tDAO", Use rDocumentD AO.class);
        663       }
        664  
        665       public  ReportHel per getRep ortHelper( ) {
        666           fi nal Report Helper rep ortHelper  = this.get Bean("repo rtHelper",
        667                ReportHe lper.class );
        668           re turn repor tHelper;
        669       }
        670  
        671       public  DocumentH elper getD ocumentHel per() {
        672           re turn this. getBean("a dapterDocu mentHelper ", Documen tHelper.cl ass);
        673       }
        674  
        675       /**
        676        * inn er class
        677        */
        678       privat e class Se archPackag e{
        679           Li st<Map<Str ing,Object >> results ;
        680           St ring icn;
        681           Lo ng resultC ount;
        682  
        683           pu blic Long  getResultC ount() {
        684                return r esultCount ;
        685           }
        686  
        687           pu blic void  setResultC ount(Long  resultCoun t) {
        688                this.res ultCount =  resultCou nt;
        689           }
        690  
        691           pu blic Searc hPackage(L ist<Map<St ring, Obje ct>> resul ts, String  icn, Long  count) {
        692                this.res ults = res ults;
        693                this.icn  = icn;
        694                this.res ultCount =  count;
        695           }
        696  
        697           pu blic List< Map<String , Object>>  getResult s() {
        698                return r esults;
        699           }
        700  
        701           pu blic void  setResults (List<Map< String, Ob ject>> res ults) {
        702                this.res ults = res ults;
        703           }
        704  
        705           pu blic Strin g getIcn()  {
        706                return i cn;
        707           }
        708  
        709           pu blic void  setIcn(Str ing icn) {
        710                this.icn  = icn;
        711           }
        712  
        713       }
        714  
        715   }