4307. EPMO Open Source Coordination Office Redaction File Detail Report

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

4307.1 Files compared

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

4307.2 Comparison summary

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

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

4307.4 Active regular expressions

No regular expressions were active.

4307.5 Comparison detail

        1   package go v.va.nvap. web.report ;
        2  
        3   import gov .va.med.nh in.adapter .audit.Act ionType;
        4   import gov .va.med.nh in.adapter .audit.Act ionValuesT ype;
        5   import gov .va.med.nh in.adapter .audit.Aud itType;
        6   import gov .va.med.nh in.adapter .audit.Fie ldType;
        7   import gov .va.med.nh in.adapter .audit.Get Audits;
        8   import gov .va.med.nh in.adapter .audit.Get AuditsResp onse;
        9   import gov .va.med.nh in.adapter .audit.Pag eInfoType;
        10   import gov .va.med.nh in.adapter .audit.Sor tDirection ;
        11   import gov .va.med.nh in.adapter .audit.Sor tFieldType ;
        12   import gov .va.med.nh in.adapter .audit.Sor tFieldsTyp e;
        13   import gov .va.med.nh in.adapter .audit.Str ingValuesT ype;
        14   import gov .va.nvap.c ommon.date .Gregorian DateUtil;
        15   import gov .va.nvap.c ommon.vali dation.Nul lChecker;
        16   import gov .va.nvap.s ervice.ada pter.audit .AdapterAu ditManager ;
        17   import gov .va.nvap.s ervice.ada pter.audit .DirectAud itManager;
        18   import gov .va.nvap.s ervice.ada pter.audit .DirectSer viceEndpoi nt;
        19   import gov .va.nvap.s ervice.ada pter.audit .DirectSer viceExcept ion;
        20   import gov .va.nvap.s ervice.ada pter.doc.A dapterExce ption;
        21   import gov .va.nvap.s ervice.aud it.AuditEx ception;
        22   import gov .va.nvap.w eb.dao.Fac ilityDAO;
        23   import gov .va.nvap.w eb.dao.Pur poseOfUseD AO;
        24   import gov .va.nvap.w eb.dao.Use rDocumentD AO;
        25   import gov .va.nvap.w eb.entitie s.PurposeO fUse;
        26   import gov .va.nvap.w eb.helper. document.D ocumentHel per;
        27   import gov .va.nvap.w eb.helper. facility.F acilityHel per;
        28   import gov .va.nvap.w eb.helper. privacy.Co nsentManag ementHelpe r;
        29   import gov .va.nvap.w eb.helper. report.Rep ortHelper;
        30   import gov .va.nvap.w eb.patient .ExcelGene ratorThrea d;
        31   import gov .va.nvap.w eb.user.Us erHelper;
        32   import gov .va.nvap.w eb.util.Co nstants;
        33   import gov .va.nvap.w eb.util.xl s.CsvExpor ter;
        34   import gov .va.nvap.w eb.util.xl s.ExcelExp orter;
        35  
        36   import jav a.io.IOExc eption;
        37   import jav a.io.Strin gWriter;
        38   import jav a.util.Arr ayList;
        39   import jav a.util.Col lection;
        40   import jav a.util.Dat e;
        41   import jav a.util.Has hMap;
        42   import jav a.util.Lin kedHashMap ;
        43   import jav a.util.Lis t;
        44   import jav a.util.Map ;
        45   import jav a.util.log ging.Level ;
        46   import jav a.util.log ging.Logge r;
        47   import jav ax.ejb.EJB ;
        48  
        49   import jav ax.servlet .ServletEx ception;
        50   import jav ax.servlet .http.Http ServletReq uest;
        51   import jav ax.servlet .http.Http ServletRes ponse;
        52   import jav ax.servlet .http.Http Session;
        53   import org .apache.po i.ss.userm odel.Workb ook;
        54  
        55   import org .json.JSON Exception;
        56   import org .json.JSON Object;
        57  
        58   /**
        59    * Disclos ures Detai l Report s earch serv let
        60    *
        61    * @author  David Vaz quez
        62    */
        63   public cla ss Documen tDisclosur eReport ex tends
        64       gov.va .nvap.web. app.Respon seDispatch erHttpServ let {
        65  
        66       /**
        67        * Ser ial UID.
        68        */
        69       privat e static f inal long  serialVers ionUID = - 4913924881 974107661L ;
        70       privat e AdapterA uditManage r adapterA uditManage r;
        71       privat e final Di rectAuditM anager dir ectAuditMa nager = ne w DirectSe rviceEndpo int();
        72  
        73  
        74       public  ConsentMa nagementHe lper getCm sHelper()  {
        75           fi nal Consen tManagemen tHelper cm sHelper =  this.getBe an("cmsHel per",
        76                ConsentM anagementH elper.clas s);
        77           re turn cmsHe lper;
        78       }
        79  
        80       /**
        81        * Get  the facil ity helper  from Spri ng.
        82        * @re turn Facil ityHelper
        83        */
        84       public  FacilityH elper getF acilityHel per() {
        85           fi nal Facili tyHelper f acilityHel per = this .getBean(" facilityHe lper",
        86                Facility Helper.cla ss);
        87           re turn facil ityHelper;
        88       }
        89  
        90       privat e ReportHe lper getRe portHelper () {
        91           re turn this. getBean("r eportHelpe r", Report Helper.cla ss);
        92       }
        93  
        94       @Overr ide
        95       public  void unsp ecified(fi nal HttpSe rvletReque st request ,
        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  
        100  
        101           se ssion.remo veAttribut e("results ");
        102  
        103           re quest.setA ttribute(" facilities ", this.ge tFacilityH elper()
        104                .getAllV istAFacili ties());
        105           th is.getRepo rtHelper() .getOrgLis ts(request , this.get CmsHelper( ));
        106  
        107           if  (Constant s.PURPOSE_ OF_USE_FLA G) {
        108                final Pu rposeOfUse DAO purpos eOfUseDAO  = this.get Bean("purp oseOfUseDA O", Purpos eOfUseDAO. class);
        109                Collecti on<Purpose OfUse> pou s = purpos eOfUseDAO. findPurpos eOfUse();
        110                request. setAttribu te("pous",  pous);
        111           }
        112           re quest.setA ttribute(" pouFlag",  Constants. PURPOSE_OF _USE_FLAG) ;
        113           Re portHelper .setDefaul tSearchDat es(session );
        114  
        115           th is.forward (request,  response,  "show");
        116       }
        117  
        118       public  void doSe arch(final  HttpServl etRequest  request,
        119           fi nal HttpSe rvletRespo nse respon se) throws  AuditExce ption, IOE xception,  ServletExc eption{
        120  
        121           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        122           se ssion.setA ttribute(" results",  encodeInto JSON(getRe sults(requ est, false ), request .getParame ter("draw" )));
        123           th is.forward (request,  response,  "searchRes ultsJSON") ;
        124       }
        125  
        126       privat e SearchPa ckage getR esults(Htt pServletRe quest requ est, Boole an exporti ng) throws  AuditExce ption, Dir ectService Exception  {
        127           //  Get the i nformation  entered b y the user  in the GU I
        128           fi nal String  ssn = req uest.getPa rameter("s sn");
        129           fi nal String  lastName  = request. getParamet er("lastNa me");
        130           fi nal String  firstName  = request .getParame ter("first Name");
        131           fi nal String  userId =  "";
        132           fi nal String  facility  = request. getParamet er("facili ty");
        133           fi nal String  purposeOf Use = requ est.getPar ameter("pu rposeOfUse ");
        134  
        135           fi nal Date s d = Report Helper.get StartDate( request.ge tParameter ("startDat e"));
        136           fi nal Date e d = Report Helper.get EndDate(re quest.getP arameter(" endDate")) ;
        137           fi nal String  organizat ion = requ est.getPar ameter("or ganization ");
        138           fi nal String  documentD isclosureS ource = re quest.getP arameter(" source");
        139           fi nal int pa tientTypes  = Integer .parseInt( request.ge tParameter ("patientT ypes"));
        140           // Sorting pa rameters p assed from  table, if  not its d irectly pa ssed.
        141           St ring docum entDisclos ureSortVal ue = (requ est.getPar ameter("or der[0][col umn]") !=  null)
        142                ? reques t.getParam eter("orde r[0][colum n]") : req uest.getPa rameter("s ortValue") ;
        143  
        144           do cumentDisc losureSort Value = ge tSortValue (documentD isclosureS ortValue,  documentDi sclosureSo urce);
        145           fi nal String  documentD isclosureS ortDirecti on = (requ est.getPar ameter("or der[0][dir ]") != nul l)
        146                ? reques t.getParam eter("orde r[0][dir]" ) : reques t.getParam eter("sort Order");
        147  
        148  
        149  
        150           fi nal GetAud its getAud itsRequest  = new Get Audits();
        151           if  (NullChec ker.isNotE mpty(sd))  {
        152                getAudit sRequest.s etFromDate (Gregorian DateUtil
        153                    .get GregorianC alendarByD ate(sd));
        154           }
        155           if  (NullChec ker.isNotE mpty(ed))  {
        156                getAudit sRequest.s etToDate(G regorianDa teUtil
        157                    .get GregorianC alendarByD ate(ed));
        158           }
        159  
        160           //  Set Patie nt Types
        161           ge tAuditsReq uest.setPa tientTypes (patientTy pes);
        162  
        163           /*
        164            *  // Set Pa tient Ids  StringValu esType pat ientIdsTyp e = new
        165            *  StringVal uesType();  patientId sType.setN otIn(false );
        166            *  patientId sType.getV alue().add (icn);
        167            *  getAudits Request.se tPatientId s(patientI dsType);
        168            * /
        169           /*
        170            *  // Set Pa tient Ids  if (NullCh ecker.isNo tEmpty(icn )) { final
        171            *  StringVal uesType pa tientIds =  new Strin gValuesTyp e();
        172            *  patientId s.getValue ().add(icn ); patient Ids.setNot In(false);
        173            *  getAudits Request.se tPatientId s(patientI ds); }
        174            * /
        175           //  Set SSN
        176           if  (NullChec ker.isNotE mpty(ssn))  {
        177                final St ringValues Type patie ntSSNs = n ew StringV aluesType( );
        178                patientS SNs.getVal ue().add(s sn);
        179                patientS SNs.setNot In(false);
        180                getAudit sRequest.s etPatientS SNs(patien tSSNs);
        181           }
        182           //  Set Last  Name
        183           if  (NullChec ker.isNotE mpty(lastN ame)) {
        184                final St ringValues Type patie ntLastName s = new St ringValues Type();
        185                patientL astNames.g etValue(). add(lastNa me);
        186                patientL astNames.s etNotIn(fa lse);
        187                getAudit sRequest.s etPatientL astNames(p atientLast Names);
        188           }
        189           //  Set First  Name
        190           if  (NullChec ker.isNotE mpty(first Name)) {
        191                final St ringValues Type patie ntFirstNam es = new S tringValue sType();
        192                patientF irstNames. getValue() .add(first Name);
        193                patientF irstNames. setNotIn(f alse);
        194                getAudit sRequest.s etPatientG ivenNames( patientFir stNames);
        195           }
        196           // Set User I D
        197           /*
        198           if  (NullChec ker.isNotE mpty(userI d)) {
        199                final St ringValues Type userI dValue = n ew StringV aluesType( );
        200                userIdVa lue.getVal ue().add(u serId);
        201                userIdVa lue.setNot In(false);
        202                getAudit sRequest.s etUserIds( userIdValu e);
        203           }
        204           */
        205           //  Set Purpo se of Use
        206           if  (!NullChe cker.isNul lOrEmpty(p urposeOfUs e)) {
        207                final St ringValues Type purpo seForUses  = new Stri ngValuesTy pe();
        208                purposeF orUses.get Value().ad d(purposeO fUse);
        209                purposeF orUses.set NotIn(fals e);
        210                getAudit sRequest.s etPurposeF orUses(pur poseForUse s);
        211           }
        212  
        213           //  Set Facil ity Ids
        214           if  (NullChec ker.isNotE mpty(facil ity)) {
        215                final St ringValues Type facil ityIds = n ew StringV aluesType( );
        216                facility Ids.setNot In(false);
        217                facility Ids.getVal ue().add(f acility);
        218                getAudit sRequest.s etPatientF acilityNum bers(facil ityIds);
        219           }
        220  
        221           //  Set Organ ization Ty pes
        222           if  (NullChec ker.isNotE mpty(organ ization))  {
        223                final St ringValues Type organ izationIds  = new Str ingValuesT ype();
        224                organiza tionIds.se tNotIn(fal se);
        225                organiza tionIds.ge tValue().a dd(organiz ation);
        226                getAudit sRequest.s etOrganiza tionIds(or ganization Ids);
        227           }  else {
        228                // input  orgs are  empty - in tent is to  retrieve  all orgs e xcept VA
        229                final St ringValues Type organ izationIds  = new Str ingValuesT ype();
        230                organiza tionIds.se tNotIn(tru e);
        231                organiza tionIds.ge tValue().a dd(
        232                    this .getCmsHel per().getC ompleteHom eCommunity Id());
        233                getAudit sRequest.s etOrganiza tionIds(or ganization Ids);
        234           }
        235           //  sorting
        236           if  (NullChec ker.isNotE mpty(docum entDisclos ureSortVal ue)) {
        237                final So rtFieldTyp e sortFiel d = new So rtFieldTyp e();
        238                sortFiel d
        239                    .set Field(Fiel dType.from Value(docu mentDisclo sureSortVa lue));
        240                if ("DES C".equalsI gnoreCase( documentDi sclosureSo rtDirectio n)) {
        241                    sort Field.setD irection(S ortDirecti on.DESC);
        242                } else {
        243                    sort Field.setD irection(S ortDirecti on.ASC);
        244                }
        245                final So rtFieldsTy pe sortFie ldsType =  new SortFi eldsType() ;
        246                sortFiel dsType.get SortField( ).add(sort Field);
        247                getAudit sRequest.s etSortFiel ds(sortFie ldsType);
        248           }
        249  
        250           /*
        251            *  StringVal uesType or gTypes = n ew StringV aluesType( ); if
        252            *  (NullChec ker.isNotE mpty(organ ization) & &
        253            *  "external ".equals(o rganizatio n)) { orgT ypes.getVa lue().add( "%" +
        254            *  this.getC msHelper() .getHomeCo mmunity(). getOrgOid( ));
        255            *  orgTypes. setNotIn(t rue); } el se {
        256            *  orgTypes. getValue() .add(organ ization);  orgTypes.s etNotIn(fa lse); }
        257            *  getAudits Request.se tOrganizat ionIds(org Types);
        258            *
        259            *  // Set Re mote Organ ization Ty pes String ValuesType  remoteOrg Types =
        260            *  new Strin gValuesTyp e(); remot eOrgTypes. setNotIn(f alse);
        261            *  getAudits Request.se tRemoteOrg anizationI ds(remoteO rgTypes);
        262            * /
        263           //  Set Actio n Value Ty pes
        264           fi nal Action ValuesType  actionsTy pe = new A ctionValue sType();
        265           ac tionsType. getValue() .add(Actio nType.RETR IEVE_DOCUM ENT);
        266           ac tionsType. setNotIn(f alse);
        267           ge tAuditsReq uest.setAc tions(acti onsType);
        268           //  Set Page  informatio n
        269           fi nal PageIn foType pag eInfoType  = new Page InfoType() ;
        270  
        271           pa geInfoType .setPageNu mber((requ est.getPar ameter("st art") != n ull) ? Int eger.parse Int(reques t.getParam eter("star t"))/Integ er.parseIn t(request. getParamet er("length ")) : 0);
        272           pa geInfoType .setPageSi ze((reques t.getParam eter("leng th") != nu ll) ? Inte ger.parseI nt(request .getParame ter("lengt h")): -1);
        273  
        274           ge tAuditsReq uest.setPa geInfo(pag eInfoType) ;
        275  
        276           fi nal List<M ap<String,  Object>>  results =  new ArrayL ist<Map<St ring, Obje ct>>();
        277           St ring resul tIcn = "";
        278           Lo ng totalCo unt = new  Long(0); / /default i t to zero,  but we se t it below
        279           tr y {
        280                final Ge tAuditsRes ponse quer yResponse;
        281                if (docu mentDisclo sureSource .equals("d irect")) {
        282                    quer yResponse  = this.dir ectAuditMa nager.getA udits(getA uditsReque st);
        283                    tota lCount = e xporting ?  0 : this. directAudi tManager.g etAuditsCo unt(getAud itsRequest );
        284                } else {
        285                    quer yResponse  = this.ada pterAuditM anager.get Audits(get AuditsRequ est);
        286                    if(q ueryRespon se.getPage Info() !=  null) {
        287                         totalCount  = exporti ng ? 0 : n ew Long(qu eryRespons e.getPageI nfo().getT otalSize() );
        288                    }
        289                }
        290                if (Null Checker.is NotEmpty(q ueryRespon se)
        291                    && N ullChecker .isNotEmpt y(queryRes ponse.getA udits())
        292                    && N ullChecker .isNotEmpt y(queryRes ponse.getA udits()
        293                         .getAudit( ))) {
        294                    fina l List<Aud itType> au ditTypeLis t = queryR esponse.ge tAudits()
        295                         .getAudit( );
        296                    for  (final Aud itType aud itType : a uditTypeLi st) {
        297                         final Map< String, Ob ject> resu ltMap = ne w HashMap< String, Ob ject>();
        298                         // Replace  SSN with  Mask
        299                         ReportData Processor. addSsnToRe sultMap(re sultMap, a uditType.g etPatientS SN());
        300                         resultMap. put("patie ntICN", Re portDataPr ocessor
        301                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        302                                 .g etPatientI d()));
        303                         resultMap. put("audit Time", Gre gorianDate Util
        304                             .getDa teFromGreg orianCalen dar(auditT ype
        305                                 .g etAuditTim e()));
        306                         resultMap. put("audit TimeFormat ted", this .getReport Helper().g etFormatte dDateTime( GregorianD ateUtil
        307                             .getDa teFromGreg orianCalen dar(auditT ype
        308                                 .g etAuditTim e())));
        309  
        310                         resultMap. put("purpo seForUse",  ReportDat aProcessor
        311                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        312                                 .g etPurposeF orUse()));
        313  
        314                         resultMap
        315                             .put(" userId", R eportDataP rocessor
        316                                 .n ullEmptyRe placeWithU nknown(aud itType
        317                                      .getUser Id()));
        318  
        319                         resultMap. put("lastN ame", Repo rtDataProc essor
        320                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        321                                 .g etPatientL astName()) );
        322                         resultMap. put("first Name", Rep ortDataPro cessor
        323                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        324                                 .g etPatientG ivenName() ));
        325                         resultMap. put("patie ntFacility Name", Rep ortDataPro cessor
        326                             .fixSt ation(audi tType.getP atientFaci lityName() ));
        327                         resultMap. put("patie ntFacility Number", R eportDataP rocessor
        328                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        329                                 .g etPatientF acilityNum ber()));
        330                         resultMap. put("organ izationNam e", this.g etReportHe lper().fin dOrganizat ionByOid(a uditType.g etOrganiza tionId(),  auditType. getOrganiz ationName( )));
        331                         resultMap. put("facil ityOid", R eportDataP rocessor
        332                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        333                                 .g etOrganiza tionId())) ;
        334                          resultMap .put("role Name", Rep ortDataPro cessor
        335                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        336                                 .g etRoleName ()));
        337                         /*
        338                          * resultM ap.put( "f acility",  this.getCm sHelper()
        339                          * .getOrg anizationB yHomeCommu nityId(
        340                          * auditTy pe.getOrga nizationId ()));
        341                          */
        342                         resultMap. put("docum entId", Re portDataPr ocessor
        343                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        344                                 .g etDocument Id()));
        345                         resultMap. put("docum entTitle",  ReportDat aProcessor
        346                             .nullE mptyReplac eWithUnkno wn(auditTy pe
        347                                 .g etDocument Title()));
        348                         results.ad d(resultMa p);
        349                    }
        350  
        351                    // C heck if an y of the p atient mat ch criteri a exists
        352                    if ( NullChecke r.isNotEmp ty(ssn)
        353                         || NullChe cker.isNot Empty(last Name)
        354                         || NullChe cker.isNot Empty(firs tName)) {
        355                         // Default  to unknow n
        356                         if (NullCh ecker.isNo tEmpty(aud itTypeList )) {
        357                             final  AuditType  result = a uditTypeLi st.get(0);
        358                             result Icn = resu lt.getPati entId();
        359  
        360                             if (Nu llChecker. isNotEmpty (resultIcn )) {
        361                                 fo r (final A uditType a uditType :  auditType List) {
        362                                      if (!res ultIcn.equ als(auditT ype.getPat ientId()))  {
        363                                          resu ltIcn = "M ultiple IC Ns";
        364                                          brea k;
        365                                      }
        366                                 }
        367                             } else  if (NullC hecker.isN otEmpty(re sult
        368                                 .g etPatientG ivenName() )
        369                                 &&  NullCheck er.isNotEm pty(result
        370                                      .getPati entLastNam e())
        371                                 &&  NullCheck er.isNotEm pty(result
        372                                      .getPati entSSN()))  {
        373                                 fi nal String  patientGi venName =  result
        374                                      .getPati entGivenNa me();
        375                                 fi nal String  patientLa stName = r esult
        376                                      .getPati entLastNam e();
        377                                 fi nal String  patientSs n = result .getPatien tSSN();
        378                                 bo olean mult ipleIcns =  false;
        379                                 fo r (final A uditType a uditType :  auditType List) {
        380                                      if (!pat ientGivenN ame.equals (auditType
        381                                          .get PatientGiv enName())
        382                                          || ! patientLas tName.equa ls(auditTy pe
        383                                               .getPatien tLastName( ))
        384                                          || ! patientSsn .equals(au ditType
        385                                               .getPatien tSSN())) {
        386                                          mult ipleIcns =  true;
        387                                          brea k;
        388                                      }
        389                                 }
        390                                 if  (multiple Icns) {
        391                                      resultIc n = "Multi ple ICNs";
        392                                 }  else {
        393                                      resultIc n = this.g etReportHe lper().res olveICN(
        394                                          resu lt.getPati entGivenNa me(),
        395                                          resu lt.getPati entLastNam e(),
        396                                          resu lt.getPati entSSN());
        397                                 }
        398                             }
        399                         } else if  (NullCheck er.isNotEm pty(ssn)
        400                             && Nul lChecker.i sNotEmpty( lastName)
        401                             && Nul lChecker.i sNotEmpty( firstName) ) {
        402                             // Try  to get fr om what wa s typed
        403                             result Icn = this .getReport Helper().r esolveICN(
        404                                 fi rstName, l astName, s sn);
        405                         }
        406                         // Set in  Session
        407                         if (NullCh ecker.isEm pty(result Icn)) {
        408                             result Icn = "Unk nown";
        409                         }
        410                    }
        411                }
        412  
        413           }  catch (fin al AuditEx ception ex ) {
        414                throw ne w AuditExc eption();
        415           }  catch (fin al DirectS erviceExce ption ex)  {
        416                throw ne w DirectSe rviceExcep tion();
        417           }
        418  
        419           Se archPackag e sp = new  SearchPac kage(resul ts,resultI cn, docume ntDisclosu reSource);
        420           sp .setTotalC ount(total Count);
        421           re turn sp;
        422       }
        423  
        424       /**
        425        * Cha nges the r esult pack age into a  JSON stri ng, adds t he disclos ure source  and patie nt ICN
        426        * @pa ram packag edResults
        427        * @re turn
        428        */
        429       privat e String e ncodeIntoJ SON(Search Package pa ckagedResu lts, Strin g draw){
        430           St ring retur nValue = " ";
        431  
        432           tr y {
        433                StringWr iter json  = new Stri ngWriter() ;
        434                JSONObje ct obj = n ew JSONObj ect();
        435                List<Lis t> data =  new ArrayL ist<List>( );
        436  
        437                for (Map <String,Ob ject> curr entRow : p ackagedRes ults.getSe archResult s()) {
        438                    List <String> d ataItem =  new ArrayL ist<String >();
        439  
        440                    data Item.add(c urrentRow. get("ssnMa sked").toS tring());
        441                    data Item.add(c urrentRow. get("lastN ame").toSt ring());
        442                    data Item.add(c urrentRow. get("first Name").toS tring());
        443                    data Item.add(c urrentRow. get("audit TimeFormat ted").toSt ring());
        444                    data Item.add(c urrentRow. get("docum entTitle") .toString( ));
        445  
        446                    //Co lumns vary  depending  on source
        447                    if(" exchange". equalsIgno reCase(pac kagedResul ts.getSour ce())){
        448                         dataItem.a dd(current Row.get("p atientFaci lityName") .toString( ));
        449                         dataItem.a dd(current Row.get("p atientFaci lityNumber ").toStrin g());
        450                    }
        451                    data Item.add(c urrentRow. get("organ izationNam e").toStri ng());
        452                    data Item.add(c urrentRow. get("userI d").toStri ng());
        453                    data Item.add(c urrentRow. get("purpo seForUse") .toString( ));
        454                    //Co lumns vary  depending  on source
        455                    if(" exchange". equalsIgno reCase(pac kagedResul ts.getSour ce())){
        456                         dataItem.a dd(current Row.get("r oleName"). toString() );
        457                         dataItem.a dd(current Row.get("p atientICN" ).toString ());
        458                         dataItem.a dd(current Row.get("d ocumentId" ).toString ());
        459                    }
        460  
        461                    //un masked ssn  added for  linking t o patient  search
        462                    data Item.add(c urrentRow. get("ssn") .toString( ));
        463  
        464                    data .add(dataI tem);
        465                }
        466  
        467                obj.put( "data", da ta);
        468  
        469                obj.put( "disclosur eSource",  packagedRe sults.getS ource());
        470                obj.put( "patientIC N", packag edResults. getIcn());
        471                obj.put( "recordsTo tal", pack agedResult s.getTotal Count());
        472                obj.put( "recordsFi ltered", p ackagedRes ults.getTo talCount() );
        473                obj.put( "draw", dr aw);
        474  
        475                obj.writ e(json);
        476  
        477                returnVa lue = json .toString( );
        478           }  catch (JSO NException  ex) {
        479                Logger.g etLogger(D ocumentDis closureRep ort.class. getName()) .log(Level .SEVERE, n ull, ex);
        480           }
        481  
        482           re turn retur nValue;
        483       }
        484  
        485       /**
        486        * sor t values a re passed  as column  numbers, b ased on pa rameters c orrespondi ng string  value is r eturned.
        487        * @pa ram colNum ber
        488        * @pa ram source
        489        * @re turn
        490        */
        491       privat e String g etSortValu e(String c olNumber,  String sou rce){
        492  
        493           St ring sortV alue = "";
        494           if ("exchange ".equalsIg noreCase(s ource)){
        495                if(null  != colNumb er)switch  (Integer.p arseInt(co lNumber))  {
        496                    case  0:
        497                         sortValue  = "patient SSN";
        498                         break;
        499                    case  1:
        500                         sortValue  = "patient LastName";
        501                         break;
        502                    case  2:
        503                         sortValue  = "patient GivenName" ;
        504                         break;
        505                    case  3:
        506                         sortValue  = "auditTi me";
        507                         break;
        508                    case  4:
        509                         sortValue  = "documen tTitle";
        510                         break;
        511                    case  5:
        512                         sortValue  = "patient FacilityNa me";
        513                         break;
        514                    case  6:
        515                         sortValue  = "patient FacilityNu mber";
        516                         break;
        517                    case  7:
        518                         sortValue  = "organiz ationName" ;
        519                         break;
        520                    case  8:
        521                         sortValue  = "userId" ;
        522                         break;
        523                    case  9:
        524                         sortValue  = "purpose ForUse";
        525                         break;
        526                    defa ult:
        527                         sortValue  = "patient SSN";
        528                         break;
        529                }
        530           }  else {
        531                if(null  != colNumb er) //sour ce = direc t
        532                switch ( Integer.pa rseInt(col Number)) {
        533                    case  0:
        534                         sortValue  = "patient SSN";
        535                         break;
        536                    case  1:
        537                         sortValue  = "patient LastName";
        538                         break;
        539                    case  2:
        540                         sortValue  = "patient GivenName" ;
        541                         break;
        542                    case  3:
        543                         sortValue  = "auditTi me";
        544                         break;
        545                    case  4:
        546                         sortValue  = "documen tTitle";
        547                         break;
        548                    case  5:
        549                         sortValue  = "organiz ationName" ;
        550                         break;
        551                    case  6:
        552                         sortValue  = "userId" ;
        553                         break;
        554                    case  7:
        555                         sortValue  = "purpose ForUse";
        556                         break;
        557                    defa ult:
        558                         sortValue  = "patient SSN";
        559                         break;
        560                }
        561           }
        562           re turn sortV alue;
        563       }
        564  
        565       public  void view (final Htt pServletRe quest requ est,
        566           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception,
        567           IO Exception  {
        568           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        569           fi nal String  icn = req uest.getPa rameter("d ocumentICN ");
        570           fi nal String  documentU niqueId =  request
        571                .getPara meter("doc umentUniqu eId");
        572           fi nal String  styleShee tViewType  = request
        573                .getPara meter("sty leSheetVie wType");
        574  
        575           St ring docum ent = null ;
        576           tr y {
        577                document  = this.ge tDocumentH elper().ge tDocument( icn,
        578                    docu mentUnique Id, UserHe lper.getUs erName(req uest),
        579                    this .getCmsHel per().getC ompleteHom eCommunity Id());
        580           }  catch (fin al Adapter Exception  ex) {
        581                throw ne w ServletE xception(e x);
        582           }
        583           se ssion.setA ttribute(" document",  document) ;
        584           se ssion.setA ttribute(" icn", icn) ;
        585           se ssion.setA ttribute(" documentUn iqueId", d ocumentUni queId);
        586           se ssion.setA ttribute(" isXmlViewE nabled", t his.getDoc umentHelpe r()
        587                .isXmlVi ewEnabled( ));
        588  
        589           if  ("xml".eq uals(style SheetViewT ype)) {
        590                document  = documen t
        591                    .rep laceAll(
        592                         "<?xml-sty lesheet ty pe=\"text/ xsl\" href =\"CCD.xsl \"?>",
        593                         "");
        594                response .setConten tType("tex t/xml;char set=UTF-8" );
        595                response .getWriter ().write(d ocument);
        596           }  else {
        597                // Updat e session  in the doc ument
        598                final St ring html  = this.get DocumentHe lper().get Html(docum ent,
        599                    styl eSheetView Type);
        600                session. setAttribu te("update dDocument" , html);
        601                this.for ward(reque st, respon se,
        602                    "sho wDocumentD isclosureR eportDocum ent");
        603           }
        604       }
        605  
        606       public  DocumentH elper getD ocumentHel per() {
        607           re turn this. getBean("a dapterDocu mentHelper ", Documen tHelper.cl ass);
        608       }
        609  
        610       @EJB(b eanInterfa ce = Adapt erAuditMan ager.class , mappedNa me = "Adap terAuditMa nager")
        611       public  void setA dapterAudi tManager(
        612           fi nal Adapte rAuditMana ger adapte rAuditMana ger) {
        613           th is.adapter AuditManag er = adapt erAuditMan ager;
        614       }
        615  
        616       public  void expo rtToCsv(fi nal HttpSe rvletReque st request ,
        617           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception, I OException  {
        618  
        619           Ma p<String,  String> cs vReportMap  = new Lin kedHashMap <>();
        620           cs vReportMap .put("SSN" , "ssn");
        621           cs vReportMap .put("Pati ent Last N ame", "las tName");
        622           cs vReportMap .put("Pati ent First  Name", "fi rstName");
        623           cs vReportMap .put("Date  of Disclo sures (CT) ", "auditT imeFormatt ed");
        624           cs vReportMap .put("Disc losures",  "documentT itle");
        625           cs vReportMap .put("Pati ent Prefer red Facili ty", "pati entFacilit yName");
        626           cs vReportMap .put("Pati ent Prefer red Facili ty Station  ID", "pat ientFacili tyNumber") ;
        627           cs vReportMap .put("eHea lth Exchan ge Organiz ation", "o rganizatio nName");
        628           cs vReportMap .put("OID" , "facilit yOid");
        629           cs vReportMap .put("User  ID", "use rId");
        630           cs vReportMap .put("Purp ose of Use ", "purpos eForUse");
        631           cs vReportMap .put("User  Role", "r oleName");
        632  
        633           in t minimumT hreshold =  Integer.p arseInt((S tring) thi s.getServl etContext( ).getAttri bute("sche duledExpor tMin"));
        634           in t total =  Integer.pa rseInt(req uest.getPa rameter("t otalRows") );
        635  
        636           // Start a sc heduled ex port with  its own th read if gr eater than  the minim um thresho ld
        637           if  (total >=  minimumTh reshold) {
        638                ExcelGen eratorThre ad csvGenT hread = ne w ExcelGen eratorThre ad("csvGen Thread");
        639                csvGenTh read.setDo cumentType ("csv");
        640                csvGenTh read.setRe portMap(cs vReportMap );
        641  
        642                csvGenTh read.setTi tle("Discl osures Det ail Report ");
        643                csvGenTh read.setUs erId(UserH elper.getU serName(re quest));
        644                csvGenTh read.setAd apterAudit Manager(ad apterAudit Manager);
        645                csvGenTh read.setRe portHelper (getReport Helper());
        646                csvGenTh read.setUs erDocument Dao(getUse rDocumentD AO());
        647                csvGenTh read.setCs vExport(ne w CsvExpor ter());
        648  
        649                // Set s earch attr ibutes for  getting a udit resul ts
        650                csvGenTh read.setAt tributes(m apSessionA ttributes( request));
        651  
        652                csvGenTh read.start ();
        653           }
        654           // Otherwise  generate a nd downloa d the expo rt directl y
        655           el se {
        656                List<Map <String, O bject>> re sults;
        657                SearchPa ckage pack edResults;
        658  
        659                packedRe sults = th is.getResu lts(reques t, true);
        660                results  = packedRe sults.getS earchResul ts();
        661  
        662                CsvExpor ter csvExp orter = ne w CsvExpor ter();
        663                csvExpor ter.export ToCSV(resp onse, "Dis closures_D etail_Repo rt", resul ts, (Linke dHashMap<S tring, Str ing>) csvR eportMap);
        664           }
        665       }
        666  
        667       /**
        668        * 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
        669        * Res ponseDispa tcherHttpS ervlet to  call this  method bas ed on the  http param eters.
        670        *
        671        * @pa ram reques t HTTP Req uest
        672        * @pa ram respon se HTTP Re sponse
        673        * @th rows Servl etExceptio n
        674        * @th rows IOExc eption
        675        */
        676       public  void expo rtToExcel( final Http ServletReq uest reque st,
        677           fi nal HttpSe rvletRespo nse respon se) throws  ServletEx ception,
        678           IO Exception  {
        679  
        680                    // C reate a ma p of key w hich is ba sed on the  result da ta key and  the
        681           //  heading v alue
        682           //  The headi ng is used  to create  the colum n headers  and the ke y is used
        683           //  to pull t he data fr om the res ults
        684           fi nal Map<St ring, Stri ng> disclo sureMap =  new Linked HashMap<St ring, Stri ng>();
        685  
        686           fi nal Date s tartDateSt r = Report Helper.get StartDate( request.ge tParameter ("startDat e"));
        687           fi nal Date e ndDateStr  = ReportHe lper.getEn dDate(requ est.getPar ameter("en dDate"));
        688  
        689           //  Generate  filters.
        690           fi nal Map<St ring, List <Object>>  filterMap  = new Link edHashMap< String, Li st<Object> >();
        691           fi nal Linked HashMap<St ring, Obje ct> filter s = new Li nkedHashMa p<String,  Object>();
        692  
        693           fi nal String  source =  request.ge tParameter ("source") ;
        694           fi lters.put( "Disclosur e Source",  source);
        695           fi lters.put( "SSN", req uest.getPa rameter("s sn"));
        696           fi lters.put( "Last Name ", request .getParame ter("lastN ame"));
        697           fi lters.put( "First Nam e", reques t.getParam eter("firs tName"));
        698           // filters.pu t("User ID ", request .getParame ter("userI d"));
        699           fi lters.put( "Start Dat e", this.g etReportHe lper().get FormattedD ate(startD ateStr));
        700           fi lters.put( "End Date" , this.get ReportHelp er().getFo rmattedDat e(endDateS tr));
        701           fi lters.put( "Purpose o f Use", Ex celExporte r.getFilte rValue(req uest.getPa rameter("p urposeOfUs e")));
        702           if  ("exchang e".equals( source.toL owerCase() )) {
        703                filters. put("Patie nt Preferr ed Facilit y", ExcelE xporter.ge tPatientPr eferredFac ilityFilte r(getFacil ityDAO(),  request.ge tParameter ("facility ")));
        704                filters. put("eHeal th Exchang e Organiza tion", Exc elExporter .getFilter Value(requ est.getPar ameter("or ganization Name")));
        705                ExcelExp orter.popu lateFilter MapForExpo rt(request , filters,  filterMap , request. getParamet er("patien tTypes"));
        706           }
        707           el se {
        708                ExcelExp orter.popu lateFilter MapForExpo rt(request , filters,  filterMap , "");
        709           }
        710  
        711           di sclosureMa p.put("ssn ", "SSN");
        712           di sclosureMa p.put("las tName", "P atient Las t Name");
        713           di sclosureMa p.put("fir stName", " Patient Fi rst Name") ;
        714           di sclosureMa p.put("aud itTimeForm atted", "D ate of Dis closures ( CT)");
        715           di sclosureMa p.put("doc umentTitle ", "Disclo sures");
        716           di sclosureMa p.put("pat ientFacili tyName", " Patient Pr eferred Fa cility");
        717           di sclosureMa p.put("pat ientFacili tyNumber",  "Patient  Preferred  Facility S tation ID" );
        718           di sclosureMa p.put("org anizationN ame", "eHe alth Excha nge Organi zation");
        719           di sclosureMa p.put("fac ilityOid",  "OID");
        720           di sclosureMa p.put("use rId", "Use r ID");
        721           di sclosureMa p.put("pur poseForUse ", "Purpos e of Use") ;
        722           di sclosureMa p.put("rol eName", "U ser Role") ;
        723  
        724           in t minimumT hreshold =  Integer.p arseInt((S tring) thi s.getServl etContext( ).getAttri bute("sche duledExpor tMin"));
        725           in t total =  Integer.pa rseInt(req uest.getPa rameter("t otalRows") );
        726  
        727           // Start a sc heduled ex port with  its own th read if gr eater than  the minim um thresho ld
        728           if  (total >=  minimumTh reshold) {
        729                ExcelGen eratorThre ad exGenTh read = new  ExcelGene ratorThrea d("exGenTh read");
        730  
        731                exGenThr ead.setRep ortSource( request.ge tParameter ("source") );
        732                exGenThr ead.setFil terMap(fil terMap);
        733                exGenThr ead.setRep ortMap(dis closureMap );
        734  
        735                // Set n ames for E xcel gener ator threa d
        736                exGenThr ead.setTit le("Disclo sures Deta il Report" );
        737  
        738                exGenThr ead.setExc elExporter (this.getE xcelExport er());
        739                exGenThr ead.setAda pterAuditM anager(ada pterAuditM anager);
        740                exGenThr ead.setDir ectAuditMa nager(dire ctAuditMan ager);
        741                exGenThr ead.setRep ortHelper( getReportH elper());
        742                exGenThr ead.setUse rId(UserHe lper.getUs erName(req uest));
        743                exGenThr ead.setUse rDocumentD ao(getUser DocumentDA O());
        744                exGenThr ead.setCms Helper(get CmsHelper( ));
        745  
        746                // Set s earch attr ibutes for  getting a udit resul ts
        747                exGenThr ead.setAtt ributes(ma pSessionAt tributes(r equest));
        748  
        749                exGenThr ead.start( );
        750           }
        751           // Otherwise  generate a nd downloa d the expo rt directl y
        752           el se {
        753                // Creat e workbook
        754                final St ring title  = "Disclo sures Deta il Report" ;
        755  
        756                List<Map <String, O bject>> re sults;
        757                SearchPa ckage pack edResults;
        758                packedRe sults = th is.getResu lts(reques t, true);
        759                results  = packedRe sults.getS earchResul ts();
        760  
        761                final Wo rkbook wb  = this.get ExcelExpor ter().expo rtToExcel( title, tit le, disclo sureMap, r esults, fi lterMap, n ull);
        762  
        763                // Write  Excel wor kbook to S tream
        764                this.get ExcelExpor ter().writ eExcelToSt ream("Disc losures_De tail_Repor t", wb, re sponse);
        765           }
        766  
        767       }
        768  
        769       privat e Map<Stri ng, Object > mapSessi onAttribut es(HttpSer vletReques t request)  {
        770  
        771           fi nal HttpSe ssion sess ion = requ est.getSes sion(false );
        772           Ma p<String,  Object> at tributes =  new HashM ap<String,  Object>() ;
        773  
        774           at tributes.p ut("ssn",  request.ge tParameter ("ssn"));
        775           at tributes.p ut("lastNa me", reque st.getPara meter("las tName"));
        776           at tributes.p ut("firstN ame", requ est.getPar ameter("fi rstName")) ;
        777           // attributes .put("user Id", reque st.getPara meter("use rId"));
        778  
        779           Da te startDa te = Repor tHelper.ge tStartDate (request.g etParamete r("startDa te"));
        780           Da te endDate  = ReportH elper.getE ndDate(req uest.getPa rameter("e ndDate"));
        781           at tributes.p ut("startD ate", star tDate);
        782           at tributes.p ut("endDat e", endDat e);
        783  
        784           at tributes.p ut("organi zation", ( String) se ssion
        785                    .get Attribute( "documentD isclosureQ ueryOrgani zation"));
        786           at tributes.p ut("facili ty", reque st.getPara meter("fac ility"));
        787           at tributes.p ut("purpos eOfUse", r equest.get Parameter( "purposeOf Use"));
        788           at tributes.p ut("patien tTypes", I nteger.par seInt(requ est.getPar ameter("pa tientTypes ")));
        789           //  sort
        790           at tributes.p ut("sortVa lue", getS ortValue(r equest.get Parameter( "sortValue "), reques t.getParam eter("sour ce")));
        791           at tributes.p ut("sortDi rection",  request.ge tParameter ("sortOrde r"));
        792  
        793           //  Set Actio n Types
        794           fi nal Action ValuesType  actionsTy pe = new A ctionValue sType();
        795           ac tionsType. getValue() .add(Actio nType.RETR IEVE_DOCUM ENT);
        796           ac tionsType. setNotIn(f alse);
        797           at tributes.p ut("action sType", ac tionsType) ;
        798  
        799           re turn attri butes;
        800       }
        801  
        802       /**
        803        * Get  the excel  exporter  class from  Spring.
        804        *
        805        * @re turn the e xcel expor ter object
        806        */
        807       public  ExcelExpo rter getEx celExporte r() {
        808           fi nal ExcelE xporter ex celExporte r = this.g etBean("ex celExporte r",
        809                ExcelExp orter.clas s);
        810           re turn excel Exporter;
        811       }
        812  
        813       privat e UserDocu mentDAO ge tUserDocum entDAO() {
        814           re turn this. getBean("U serDocumen tDAO", Use rDocumentD AO.class);
        815       }
        816  
        817       privat e Facility DAO getFac ilityDAO()  {
        818           re turn this. getBean("F acilityDAO ", Facilit yDAO.class );
        819       }
        820  
        821       /**
        822        * use d to organ ize parame ters into  a one. cle aner packa ging.
        823        */
        824       privat e class Se archPackag e{
        825           Li st<Map<Str ing,Object >> searchR esults;
        826           St ring icn;
        827           St ring sourc e;
        828           Lo ng totalCo unt;
        829  
        830           pu blic Searc hPackage(L ist<Map<St ring, Obje ct>> searc hResults,  String icn , String s ource) {
        831                this.sea rchResults  = searchR esults;
        832                this.icn  = icn;
        833                this.sou rce = sour ce;
        834           }
        835  
        836           pu blic List< Map<String , Object>>  getSearch Results()  {
        837                return s earchResul ts;
        838           }
        839  
        840           pu blic void  setSearchR esults(Lis t<Map<Stri ng, Object >> searchR esults) {
        841                this.sea rchResults  = searchR esults;
        842           }
        843  
        844           pu blic Strin g getIcn()  {
        845                return i cn;
        846           }
        847  
        848           pu blic void  setIcn(Str ing icn) {
        849                this.icn  = icn;
        850           }
        851  
        852           pu blic Strin g getSourc e() {
        853                return s ource;
        854           }
        855  
        856           pu blic void  setSource( String sou rce) {
        857                this.sou rce = sour ce;
        858           }
        859  
        860           pu blic Long  getTotalCo unt() {
        861                return t otalCount;
        862           }
        863  
        864           pu blic void  setTotalCo unt(Long t otalCount)  {
        865                this.tot alCount =  totalCount ;
        866           }
        867       }
        868  
        869   }