3897. EPMO Open Source Coordination Office Redaction File Detail Report

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

3897.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:50:58 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-server\src\main\java\gov\va\nvap\server\service\pdq PdqServiceImpl.java Fri Apr 21 20:03:28 2017 UTC

3897.2 Comparison summary

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

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

3897.4 Active regular expressions

No regular expressions were active.

3897.5 Comparison detail

        1   package go v.va.nvap. server.ser vice.pdq;
        2  
        3   import gov .va.nvap.c ommon.aggr egator.Agg regator;
        4   import gov .va.nvap.c ommon.aggr egator.Agg regatorExc eption;
        5   import gov .va.nvap.c ommon.date .hl7.HL7Da teUtil;
        6   import gov .va.nvap.c ommon.endp oint.Endpo int;
        7   import gov .va.nvap.c ommon.endp oint.Endpo intExcepti on;
        8   import gov .va.nvap.c ommon.filt er.Filter;
        9   import gov .va.nvap.c ommon.filt er.FilterE xception;
        10   import gov .va.nvap.c ommon.inte rceptor.In terceptor;
        11   import gov .va.nvap.c ommon.inte rceptor.In terceptorE xception;
        12   import gov .va.nvap.c ommon.jaxb .JaxbUtil;
        13   import gov .va.nvap.c ommon.spli tter.Split ter;
        14   import gov .va.nvap.c ommon.spli tter.Split terExcepti on;
        15   import gov .va.nvap.c ommon.tran sformer.Tr ansformer;
        16   import gov .va.nvap.c ommon.tran sformer.Tr ansformerE xception;
        17   import gov .va.nvap.c ommon.tran sformer.xm l.XMLToStr ing;
        18   import gov .va.nvap.c ommon.uuid .UUIDUtil;
        19   import gov .va.nvap.c ommon.vali dation.Ass ert;
        20   import gov .va.nvap.c ommon.vali dation.Nul lChecker;
        21   import gov .va.nvap.p rivacy.Con sentDirect iveOptOutR easonType;
        22   import gov .va.nvap.p rivacy.Con sentDirect iveQueryPa ramType;
        23   import gov .va.nvap.p rivacy.Con sentDirect iveQueryRe quest;
        24   import gov .va.nvap.p rivacy.Con sentDirect iveQueryRe sponse;
        25   import gov .va.nvap.p rivacy.Con sentDirect iveReferen ceType;
        26   import gov .va.nvap.p rivacy.Con sentDirect iveRevocat ionRequest ;
        27   import gov .va.nvap.p rivacy.Con sentType;
        28   import gov .va.nvap.p rivacy.Ser viceConsum er;
        29   import gov .va.nvap.p rivacy.Ser viceConsum erContextT ype;
        30   import gov .va.nvap.p rivacy.dat a.ConsentD irectiveDa ta;
        31   import gov .va.nvap.s ervice.aud it.AuditSe rvice;
        32   import gov .va.nvap.s ervice.aud it.data.Co nsentAudit ;
        33   import gov .va.nvap.s ervice.pdq .Facility;
        34   import gov .va.nvap.s ervice.pdq .PatientCo rrelations Query;
        35   import gov .va.nvap.s ervice.pdq .PatientCo rrelations Response;
        36   import gov .va.nvap.s ervice.pdq .PatientDe mographics ;
        37   import gov .va.nvap.s ervice.pdq .PatientDe mographics Query;
        38   import gov .va.nvap.s ervice.pdq .PatientDe mographics Response;
        39   import gov .va.nvap.s ervice.pdq .PatientMa tchQuery;
        40   import gov .va.nvap.s ervice.pdq .PatientMa tchRespons e;
        41   import gov .va.nvap.s ervice.pdq .PdqExcept ion;
        42   import gov .va.nvap.s ervice.pdq .PdqServic e;
        43   import gov .va.nvap.s ervice.pdq .RemovePat ientCorrel ationReque st;
        44   import gov .va.nvap.s ervice.pri vacy.Conse ntManageme ntService;
        45   import gov .va.nvap.s ervice.pri vacy.Conse ntManageme ntServiceE xception;
        46   import jav a.text.Par seExceptio n;
        47   import jav a.util.Arr ayList;
        48   import jav a.util.Dat e;
        49   import jav a.util.Lis t;
        50   import jav a.util.Map ;
        51   import jav a.util.log ging.Level ;
        52   import jav a.util.log ging.Logge r;
        53   import jav ax.xml.bin d.JAXBExce ption;
        54   import net .sf.ehcach e.Cache;
        55   import net .sf.ehcach e.CacheMan ager;
        56   import net .sf.ehcach e.Element;
        57   import org .springfra mework.bea ns.factory .annotatio n.Required ;
        58   import org .w3c.dom.D ocument;
        59  
        60   /**
        61    * The pdq  preferenc e implemen tation, wh ich will b e the faca de for the  GUI.
        62    * 
        63    * @author  Asha Amri traj
        64    * @author  Zack Pete rson
        65    */
        66   public cla ss PdqServ iceImpl im plements P dqService  {
        67  
        68           pr ivate stat ic final L ogger logg er = Logge r.getLogge r(PdqServi ceImpl.cla ss
        69                             .getNa me());
        70           pr ivate stat ic final S tring PDQ_ CORRELATIO NS_CACHE_N AME = "gov .va.nvap.s ervice.pdq .PdqServic e.Correlat ions";
        71           pr ivate stat ic final S tring PDQ_ DEMOGPHICS _CACHE_NAM E = "gov.v a.nvap.ser vice.pdq.P dqService. Demographi cs";
        72  
        73           pr ivate stat ic final S tring PDQ_ PATIENT_MA TCH_CACHE_ NAME = "go v.va.nvap. service.pd q.PdqServi ce.Patient Match";
        74           //  Cache Man ager
        75           Ca cheManager  cacheMana ger;
        76           //  Endpoints
        77           pr ivate Endp oint<Docum ent, Docum ent> mviSo cketEndpoi nt;
        78  
        79           pr ivate Tran sformer<St ring, Map< String, Ob ject>> pat ientExtend edViewRpcR esponseToP ropertyMap ;
        80           pr ivate Tran sformer<Do cument, Do cument> pa tientMatch QueryToQBP Q22Transfo rmer;
        81           pr ivate Tran sformer<St ring, Map< String, Ob ject>> pat ientPrimar yViewRpcRe sponseToPr opertyMap;
        82       /**
        83            *  Transform er to tran sform from  the value  object to  CDA R2 XM L document .
        84            * /
        85           pr ivate Tran sformer<Do cument, Do cument> da taToConsen tDirective Document;
        86           //  Intercept or
        87           pr ivate Inte rceptor<Ob ject, Obje ct> pdqAud itIntercep tor;
        88           //  Transform ers
        89           pr ivate Jaxb Util pdqJa xbHelper;
        90       /**
        91            *  To conver t from Con sentDirect iveData to  XML for t ransformat ion into t he
        92            *  CDA XML.
        93            * /
        94           pr ivate Jaxb Util conse ntDirectiv eDataJaxbH elper;
        95           //  Aggregato rs
        96           pr ivate Aggr egator<Map <String, O bject>, Ma p<String,  ?>> proper tyMapAggre gator;
        97           pr ivate Tran sformer<Do cument, Do cument> re movePatien tCorrelati onRequestT oADTA37;
        98           //  Splitter
        99           pr ivate Spli tter<Strin g, Map<Str ing, Strin g>> rpcExt endedRespo nseSplitte r;
        100           //  Filter
        101           pr ivate Filt er<Map<Str ing, Map<S tring, Obj ect>>, Str ing> rpcRe sponsesRec entDateFil ter;
        102           pr ivate Tran sformer<St ring, Pati entCorrela tionsRespo nse> rpcRe sponsesToP atientCorr elationRes ponse;
        103           pr ivate Tran sformer<Ma p<String,  Object>, D ocument> r pcResponse sToPatient Demographi csResponse ;
        104           pr ivate Tran sformer<Ma p<String,  String>, M ap<String,  Map<Strin g, Object> >> rpcResp onsesToPro pertyMapRe cordTwoPas s;
        105           pr ivate Tran sformer<Do cument, Do cument> rs pK22ToPati entMatchRe sponseTran sformer;
        106           pr ivate Filt er<Map<Str ing, Strin g>, Map<St ring, Stri ng>> vaFac ilityNumbe rFilter;
        107           pr ivate Endp oint<Objec t, String>  vistaPati entExtende dViewEndpo int;
        108  
        109           pr ivate Endp oint<Objec t, String>  vistaPati entPrimary ViewEndpoi nt;
        110           //
        111           pr ivate XMLT oString xm l2String;
        112       
        113           pr ivate Cons entManagem entService  cms;
        114           
        115           pr ivate Audi tService a uditServic e;
        116  
        117           @O verride
        118           pu blic Patie ntCorrelat ionsRespon se getCorr elatedFaci lities(
        119                             final  PatientCor relationsQ uery query ) throws P dqExceptio n {
        120                    Asse rt.assertN otEmpty(qu ery.getPat ientId(),
        121                                      "Patient  Id cannot  be empty! ");
        122                    try  {
        123                             // Cac he lives f or 5 mins.  Check the  ehCache.x ml for mor e
        124                             // inf ormation.
        125                             if (Ca cheManager .getInstan ce().cache Exists(
        126                                               PdqService Impl.PDQ_C ORRELATION S_CACHE_NA ME)) {
        127                                      final Ca che cache  = CacheMan ager.getIn stance().g etCache(
        128                                                       Pd qServiceIm pl.PDQ_COR RELATIONS_ CACHE_NAME );
        129                                      if (cach e.isKeyInC ache(query .getPatien tId())) {
        130                                               final Elem ent elemen t = cache. get(query. getPatient Id());
        131                                               if (NullCh ecker.isNo tEmpty(ele ment)) {
        132                                                       if  (PdqServi ceImpl.log ger.isLogg able(Level .INFO)) {
        133                                                                //Pd qServiceIm pl.logger. log(Level. INFO,
        134                                                                //                "Obtaini ng cached  correlatio ns for pat ient, "
        135                                                                //                                 +  query.getP atientId() );
        136                                                                PdqS erviceImpl .logger.lo g(Level.IN FO,
        137                                                                                  "Obtaini ng cached  correlatio ns for pat ient ");
        138                                                       }
        139                                                       re turn (Pati entCorrela tionsRespo nse) eleme nt
        140                                                                         .getOb jectValue( );
        141                                               }
        142                                      }
        143                             }
        144                             // Exe cute the E xtended Vi ew RPC
        145                             final  long start Time = Sys tem.curren tTimeMilli s();
        146                             final  String ext endedRpcRe sponse = t his.vistaP atientExte ndedViewEn dpoint
        147                                               .invoke(qu ery.getPat ientId());
        148                             final  long endTi me = Syste m.currentT imeMillis( );
        149                             Assert .assertNot Empty(
        150                                               extendedRp cResponse,
        151                                               "Extended  RPC Respon se from MP I is empty  for "
        152                                                                + qu ery.getPat ientId() +  "!");
        153                             // Ret urn respon se
        154                             final  PatientCor relationsR esponse re sponse = t his.rpcRes ponsesToPa tientCorre lationResp onse
        155                                               .transform (extendedR pcResponse );
        156                             if (Pd qServiceIm pl.logger. isLoggable (Level.INF O)) {
        157                                      //PdqSer viceImpl.l ogger.log( Level.INFO ,
        158                                      //               "O btaining c orrelation s (Extende d View RPC ) for pati ent, "
        159                                      //                                 + quer y.getPatie ntId());
        160                                      final Li st<String>  facilityC oordinates  = new Arr ayList<Str ing>();
        161                                      final Li st<Facilit y> facs =  response.g etFaciliti es();
        162                                      for (fin al Facilit y fac : fa cs) {
        163                                               facilityCo ordinates. add(fac.ge tFacilityN umber() +  ":"
        164                                                                + fa c.getFacil ityName()) ;
        165                                      }
        166                                      PdqServi ceImpl.log ger.log(Le vel.INFO,  "Facilitie s in Respo nse["
        167                                                       +  facilityCo ordinates  + "]. Time  elapsed =  "
        168                                                       +  ((endTime  - startTim e) / 1000)  + "s");
        169                             }
        170                             // Sto re in cach e
        171                             if (Ca cheManager .getInstan ce().cache Exists(
        172                                               PdqService Impl.PDQ_C ORRELATION S_CACHE_NA ME)) {
        173                                      final Ca che cache  = CacheMan ager.getIn stance().g etCache(
        174                                                       Pd qServiceIm pl.PDQ_COR RELATIONS_ CACHE_NAME );
        175                                      cache.pu t(new Elem ent(query. getPatient Id(), resp onse));
        176                             }
        177                             return  response;
        178  
        179                    } ca tch (final  Transform erExceptio n ex) {
        180                             throw  new PdqExc eption(ex) ;
        181                    } ca tch (final  EndpointE xception e x) {
        182                             throw  new PdqExc eption(ex) ;
        183                    }
        184           }
        185  
        186       /**
        187            *  Retrieves  the demog raphics fo r the pati ent contai ned in the  patient d emographic s
        188        * req uest. If t he patient  is found  to be dece ased, a co nsent revo cation is  processed
        189        * for  all conse nt directi ves.
        190        * 
        191        * @pa ram query  query obje ct contain ing patien t for whic h to retri eve demogr aphics
        192        * 
        193        * @re turn the r esponse ob ject conta ining the  requested  demographi cs if they  exist
        194        * 
        195        * @th rows gov.v a.nvap.ser vice.pdq.P dqExceptio n
        196            * /
        197           @O verride
        198           pu blic Patie ntDemograp hicsRespon se getPati entDemogra phics(
        199                             final  PatientDem ographicsQ uery query ) throws P dqExceptio n {
        200                    Asse rt.assertN otEmpty(qu ery.getPat ientId(),
        201                                      "Patient  identiife r cannot b e null!");
        202                    try  {
        203                             if (Ca cheManager .getInstan ce().cache Exists(
        204                                               PdqService Impl.PDQ_D EMOGPHICS_ CACHE_NAME )) {
        205                                      final Ca che cache  = CacheMan ager.getIn stance().g etCache(
        206                                                       Pd qServiceIm pl.PDQ_DEM OGPHICS_CA CHE_NAME);
        207                                      if (cach e.isKeyInC ache(query .getPatien tId())) {
        208                                               final Elem ent elemen t = cache. get(query. getPatient Id());
        209                                               if (NullCh ecker.isNo tEmpty(ele ment)) {
        210                                                       // if (PdqSer viceImpl.l ogger.isLo ggable(Lev el.INFO))  {
        211                                                                //Pd qServiceIm pl.logger. log(Level. INFO,
        212                                                                //                "Obtaini ng cached  demographi cs for pat ient, "
        213                                                                //                                 +  query.getP atientId() );
        214                                                       // }
        215                                                       re turn (Pati entDemogra phicsRespo nse) eleme nt
        216                                                                         .getOb jectValue( );
        217                                               }
        218                                      }
        219                             }
        220                             // Exe cute Prima ry View RP C
        221                             long s tartTime =  System.cu rrentTimeM illis();
        222                             final  String pri maryRpcRes ponse = th is.vistaPa tientPrima ryViewEndp oint
        223                                               .invoke(qu ery.getPat ientId());
        224                             long e ndTime = S ystem.curr entTimeMil lis();
        225                             if (Pd qServiceIm pl.logger. isLoggable (Level.INF O)) {
        226                                      //PdqSer viceImpl.l ogger.log( Level.INFO ,
        227                                      //               "O btaining d emographic s (Primary  View RPC)  for patie nt, "
        228                                      //                                 + quer y.getPatie ntId() + " . Time ela psed = "
        229                                      //                                 + ((en dTime - st artTime) /  1000) + " s");
        230                                      // logge r.log(Leve l.INFO, "R esponse["  + primaryR pcResponse  +
        231                                      // "]");
        232                             }
        233                             Assert .assertNot Empty(
        234                                               primaryRpc Response,
        235                                               "Primary R PC Respons e from MPI  is empty  for "
        236                                                                + qu ery.getPat ientId() +  "!");
        237                             // Cre ate a map  of propert ies from t he primary  rpc respo nse
        238                             final  Map<String , Object>  patientPri maryViewPr opertyMap  = this.pat ientPrimar yViewRpcRe sponseToPr opertyMap
        239                                               .transform (primaryRp cResponse) ;
        240                             // Exe cute the E xtended Vi ew RPC
        241                             startT ime = Syst em.current TimeMillis ();
        242                             final  String ext endedRpcRe sponse = t his.vistaP atientExte ndedViewEn dpoint
        243                                               .invoke(qu ery.getPat ientId());
        244                             endTim e = System .currentTi meMillis() ;
        245                             if (Pd qServiceIm pl.logger. isLoggable (Level.INF O)) {
        246           //                         PdqServi ceImpl.log ger.log(Le vel.INFO,
        247           //                                          "O btaining d emographic s (Extende d View RPC ) for pati ent, "
        248           //                                                            + quer y.getPatie ntId() + " . Time ela psed = "
        249           //                                                            + ((en dTime - st artTime) /  1000) + " s");
        250                                      // logge r.log(Leve l.INFO, "R esponse["  + extended RpcRespons e +
        251                                      // "]");
        252                             }
        253                             Assert .assertNot Empty(
        254                                               extendedRp cResponse,
        255                                               "Extended  RPC Respon se from MP I is empty  for "
        256                                                                + qu ery.getPat ientId() +  "!");
        257                             // Spl it the res ponses for  each faci lity
        258                             final  Map<String , String>  splitRpcRe sponses =  this.rpcEx tendedResp onseSplitt er
        259                                               .split(ext endedRpcRe sponse);
        260                             // Fil ter by kno wn VA faci lity if pr esent
        261                             final  Map<String , String>  splitRpcRe sponsesFil tered = th is.vaFacil ityNumberF ilter
        262                                               .filter(sp litRpcResp onses);
        263  
        264                             final  Map<String , Map<Stri ng, Object >> rpcResp onsesMapRe cord = thi s.rpcRespo nsesToProp ertyMapRec ordTwoPass
        265                                               .transform (splitRpcR esponsesFi ltered);
        266                             // Get  the most  recent upd ated facil ity to wor k with fro m the
        267                             // res ponse
        268                             final  String ext endedRecen tRpcRespon se = this. rpcRespons esRecentDa teFilter
        269                                               .filter(rp cResponses MapRecord) ;
        270                             Assert .assertNot Empty(
        271                                               extendedRe centRpcRes ponse,
        272                                               "Extended  Filtered R esponse ca nnot be nu ll for "
        273                                                                + qu ery.getPat ientId() +  "!");
        274                             // Cre ate a map  of propert ies from t he extende d rpc resp nse
        275                             final  Map<String , Object>  patientExt endedViewP ropertyMap  = this.pa tientExten dedViewRpc ResponseTo PropertyMa p
        276                                               .transform (extendedR ecentRpcRe sponse);
        277                             // Agg regate the  primary,  extended a nd sites m aps
        278                             final  Map<String , Object>  patientVie wPropertyM ap = this. propertyMa pAggregato r
        279                                               .aggregate (patientEx tendedView PropertyMa p,
        280                                                                pati entPrimary ViewProper tyMap);
        281  
        282                             // Con struct the  patient d emographic s response  return va lue docume nt
        283                             final  Document p atientDemo graphicsRe sponseDocu ment = thi s.rpcRespo nsesToPati entDemogra phicsRespo nse
        284                                               .transform (patientVi ewProperty Map);
        285                             // Unm arshal doc ument
        286                             final  PatientDem ographicsR esponse pa tientDemog raphicsRes ponse = (P atientDemo graphicsRe sponse) th is.pdqJaxb Helper
        287                                               .unmarshal (patientDe mographics ResponseDo cument);
        288  
        289                // Store  demograph ics inform ation in c ache
        290                             if (Ca cheManager .getInstan ce().cache Exists(
        291                                               PdqService Impl.PDQ_D EMOGPHICS_ CACHE_NAME )) {
        292                                      final Ca che cache  = CacheMan ager.getIn stance().g etCache(
        293                                                       Pd qServiceIm pl.PDQ_DEM OGPHICS_CA CHE_NAME);
        294                                      cache.pu t(new Elem ent(query. getPatient Id(),
        295                                                       pa tientDemog raphicsRes ponse));
        296                             }
        297                
        298                // Opt o ut patient  if deceas ed
        299                Date dat eOfDeath =  patientDe mographics Response.g etPatientD emographic s().getDat eOfDeath() ;
        300                
        301                if (date OfDeath !=  null) {
        302                    // l ook up the  records t hat need t o be opted  out.
        303                    Cons entDirecti veQueryRes ponse cons entDirecti veQueryRes ponse = nu ll;
        304                    try  {
        305                         // Constru ct request
        306                         final Cons entDirecti veQueryReq uest conse ntDirectiv eQueryRequ est = 
        307                                 ne w ConsentD irectiveQu eryRequest ();
        308                         // Set the  patient i d
        309                         consentDir ectiveQuer yRequest.s etPatientI d(query.ge tPatientId ());
        310                         // Query o nly for ac tive
        311                         consentDir ectiveQuer yRequest
        312                                 .s etQueryPar am(Consent DirectiveQ ueryParamT ype.ACTIVE );
        313                         consentDir ectiveQuer yResponse  = this.cms
        314                                 .g etConsentD irectives( consentDir ectiveQuer yRequest);
        315                    } ca tch (final  ConsentMa nagementSe rviceExcep tion ex) {
        316                         throw new  RuntimeExc eption(ex) ;
        317                    }
        318                    
        319                    for  (ConsentDi rectiveRef erenceType  consentDi rective : 
        320                             consen tDirective QueryRespo nse.getCon sentDirect iveReferen ce()) {
        321                         if (NullCh ecker.isEm pty(consen tDirective )) {
        322                             throw  new Runtim eException (
        323                                      "There h as to be o ne active  consent di rective to  process r evocation! ");
        324                         }
        325                         // Create  a consent  directive  data objec t
        326                         ConsentDir ectiveData  data = ne w ConsentD irectiveDa ta();
        327                         data.setIc n(query.ge tPatientId ());
        328                         PatientDem ographics  demographi cs = patie ntDemograp hicsRespon se.getPati entDemogra phics();
        329                         if (NullCh ecker.isNo tEmpty(dem ographics) ) {
        330                             data.s etPatientR oleCity(de mographics .getReside nceCity()) ;
        331                             data.s etPatientR oleState(d emographic s.getResid enceState( ));
        332                             data.s etPatientR oleGivenNa me(demogra phics.getF irstName() );
        333                             data.s etPatientR oleFamilyN ame(demogr aphics.get LastName() );
        334                             data.s etPatientR oleFamilyN ameAlias(d emographic s.getAlias 1());
        335                             data.s etPatientR oleMiddleN ame(demogr aphics.get MiddleName ());
        336                             data.s etPatientR oleMiddleN ameAlias(d emographic s.getAlias 2());
        337                             data.s etPatientR oleEthnicG roupCodeDi splayText( demographi cs
        338                                      .getEthn icityDescr iption());
        339                             data.s etPatientR oleSsn(dem ographics. getSsn());
        340                             data.s etPatientR oleGenderC ode(demogr aphics.get Gender());
        341                             data.s etPatientR oleGenderD isplayText (demograph ics
        342                                      .getGend erDescript ion());
        343                             data.s etPatientR oleMarital StatusCode (demograph ics
        344                                      .getMari talStatus( ));
        345                             data.s etPatientR oleMarital StatusDisp layText(de mographics
        346                                      .getMari talStatusD escription ());
        347                             data.s etPatientR olePostalC ode(demogr aphics.get ResidenceZ ip4());
        348                             data.s etPatientR olePrefix( demographi cs.getPref ix());
        349                             data.s etPatientR oleStreetA ddressLine (demograph ics
        350                                      .getStre etAddressL ine1());
        351                             data.s etPatientR oleSuffix( demographi cs.getSuff ix());
        352                             data.s etPatientR oleTelecom (demograph ics.getRes idencePhon eNumber()) ;
        353                             data.s etPatientR oleProvide rOrganizat ionName(de mographics
        354                                      .getFaci lityName() );
        355                             data.s etPatientR oleProvide rOrganizat ionNumber( demographi cs
        356                                      .getFaci lityNumber ());
        357                             if (Nu llChecker. isNotEmpty (demograph ics.getDob ())) {
        358                                 tr y {
        359                                      // Need  to use the  HL7 date,  because t he CDA R2  needs it
        360                                      data.set PatientRol eDob(HL7Da teUtil
        361                                               .yyyyMMddh hmmssZ(dem ographics. getDob())) ;
        362                                 }  catch (fin al ParseEx ception ex ) {
        363                                      throw ne w RuntimeE xception(e x);
        364                                 }
        365                             }
        366                         }
        367                         // Set a u nique id p er documen t
        368                         data.setDo cId(UUIDUt il.generat eUUID());
        369  
        370                         // Set the  status co de to abor ted
        371                         data.setCo mponentSta tusCode("a borted");
        372                        
        373                         // Set doc ument date s and time s to now
        374                         try {
        375                             final  String sig natureDate String = H L7DateUtil
        376                                      .yyyyMMd dhhmmssZ(n ew Date()) ;
        377                             // Set  the effec tive date
        378                             data.s etEffectiv eDateTime( HL7DateUti l.yyyyMMdd hhmmssZ(ne w Date())) ;
        379                             // Cre ate the be gin and en d date
        380                             data.s etDocument ationBegin Time(signa tureDateSt ring);
        381                             // Sta rt and end  time are  required
        382                             data.s etDocument ationEndTi me(signatu reDateStri ng);
        383                         } catch (f inal Parse Exception  ex) {
        384                             throw  new Runtim eException (ex);
        385                         }
        386                        
        387                         // Set the  consent d irective
        388                         data.setPr eviousCons entDirecti veId(conse ntDirectiv e.getConse ntDirId()) ;
        389                         data.setOp toutReason ("Patient  Deceased") ;
        390                        
        391                         // For now  sets user  to an aut omatic ser vice
        392                         data.setAu thorPerson Oid("Autom atic Servi ce");
        393                         data.setAu thorPerson OrgOid("Au tomatic Se rvice");
        394                        
        395                         // Make th e request  to revoke
        396                         final Serv iceConsume rContextTy pe sc = ne w ServiceC onsumerCon textType() ;
        397                         sc.setUser ("Automati c Service" );
        398                         ConsentAud it ca = au ditService .getLatest Audit(cons entDirecti ve.getPati entIen(),  consentDir ective.get OptinConse ntType().g etValue()) ;
        399                         if(ca != n ull){
        400                             sc.set Facility(c a.getFacil ity());
        401                         }
        402                         sc.setServ iceConsume rType(Serv iceConsume r.ADMINIST RATOR_PORT AL);
        403  
        404                         if (consen tDirective .getPurpos eOfUse() ! = null) {
        405                             data.s etComponen tPurposeOf UseDisplay Name(conse ntDirectiv e.getPurpo seOfUse(). name());
        406                         }
        407                         String deA uthName =  consentDir ective.get OptinConse ntType().n ame().
        408                                 su bstring(0,  consentDi rective.ge tOptinCons entType(). name().las tIndexOf(" _")) + 
        409                                 "_ REVOCATION ";
        410                         sc.setCons entType(Co nsentType. valueOf(de AuthName)) ;
        411                        
        412                         // Convert  the PDF i nto byte s tring
        413                         // Convert  the Conse ntDirectiv eData to X ML documen t
        414                         final Docu ment conse ntDirectiv eDataDoc =  this.cons entDirecti veDataJaxb Helper
        415                                 .m arshal(dat a);
        416                         // Convert  ConsentDi rectiveDat a XML to C DA R2 XML
        417                         final Docu ment conse ntDirectiv eDocument  = this.dat aToConsent DirectiveD ocument
        418                                 .t ransform(c onsentDire ctiveDataD oc);
        419                         // Convert  CDA R2 XM L to strin g
        420                         final Stri ng consent DirectiveD ocumentStr ing = 
        421                                 th is.xml2Str ing.transf orm(consen tDirective Document);
        422                         final byte [] consent DirectiveD ocumentByt es = conse ntDirectiv eDocumentS tring.getB ytes();
        423                        
        424                         final Cons entDirecti veRevocati onRequest  request =  new Consen tDirective Revocation Request();
        425                         request.se tServiceCo nsumerCont ext(sc);
        426                         request.se tOptoutRea son(Consen tDirective OptOutReas onType
        427                                 .f romValue(" Patient De ceased"));
        428                         request.se tDocument( consentDir ectiveDocu mentBytes) ;
        429  
        430                         try {
        431                             // Pro cess revok e
        432                             this.c ms.process ConsentDir ectiveRevo cation(req uest);
        433                         } catch (f inal Conse ntManageme ntServiceE xception e x) {
        434                             throw  new Runtim eException (ex);
        435                         }
        436                    }
        437                }
        438                
        439                             return  patientDe mographics Response;
        440                    } ca tch (final  SplitterE xception e x) {
        441                             throw  new PdqExc eption(ex) ;
        442                    } ca tch (final  Aggregato rException  ex) {
        443                             throw  new PdqExc eption(ex) ;
        444                    } ca tch (final  JAXBExcep tion ex) {
        445                             throw  new PdqExc eption(ex) ;
        446                    } ca tch (final  FilterExc eption ex)  {
        447                             throw  new PdqExc eption(ex) ;
        448                    } ca tch (final  Transform erExceptio n ex) {
        449                             throw  new PdqExc eption(ex) ;
        450                    } ca tch (final  EndpointE xception e x) {
        451                             throw  new PdqExc eption(ex) ;
        452                    }
        453           }
        454  
        455           @O verride
        456           pu blic Remov ePatientCo rrelationR equest rem ovePatient Correlatio n(
        457                             final  RemovePati entCorrela tionReques t request)  throws Pd qException  {
        458                    Asse rt.assertN otEmpty(re quest,
        459                                      "Remove  patient co rrelation  request ca nnot be nu ll!");
        460                    Asse rt.assertN otEmpty(re quest.getC orrelatedA ssigningAu thorityNam e(),
        461                                      "Correla ted assign ing author ity name c annot be n ull!");
        462                    Asse rt.assertN otEmpty(re quest.getC orrelatedP atientId() ,
        463                                      "Correla ted patien t id canno t be null! ");
        464                    Asse rt.assertN otEmpty(re quest.getP atientId() , "Patient  id is req uired!");
        465                    try  {
        466                             // Con struct ADT _A37 for t he MPI.
        467                             final  Document r equestDocu ment = thi s.pdqJaxbH elper
        468                                               .marshal(r equest);
        469                             final  Document a dtA37Doc =  this.remo vePatientC orrelation RequestToA DTA37
        470                                               .transform (requestDo cument);
        471                             // Sen d to MVI
        472                             this.m viSocketEn dpoint.inv oke(adtA37 Doc);
        473                             // Aud it the req uest sent
        474                             Remove PatientCor relationRe quest r =  (RemovePat ientCorrel ationReque st)this.pd qAuditInte rceptor.in tercept(re quest);
        475                             
        476                             return  r;
        477                    } ca tch (final  Intercept orExceptio n ex) {
        478                             throw  new PdqExc eption(ex) ;
        479                    } ca tch (final  JAXBExcep tion ex) {
        480                             throw  new PdqExc eption(ex) ;
        481                    } ca tch (final  Transform erExceptio n ex) {
        482                             throw  new PdqExc eption(ex) ;
        483                    } ca tch (final  EndpointE xception e x) {
        484                             throw  new PdqExc eption(ex) ;
        485                    }
        486           }
        487  
        488           @O verride
        489           pu blic Patie ntMatchRes ponse sear chPatient(
        490                             final  PatientMat chQuery pa tientMatch Query) thr ows PdqExc eption {
        491                    Asse rt.assertN otEmpty(pa tientMatch Query,
        492                                      "Patient  search re quest cann ot be null !");
        493                    Asse rt.assertN otEmpty(pa tientMatch Query.getP atientProf ile(),
        494                                      "Patient  in the pa tient sear ch request  cannot be  null!");
        495                    Asse rt.assertN otEmpty(pa tientMatch Query.getP atientProf ile()
        496                                      .getFirs tName(), " First name  cannot be  null!");
        497                    Asse rt.assertN otEmpty(pa tientMatch Query.getP atientProf ile()
        498                                      .getLast Name(), "L ast name i s required !");
        499                    Asse rt.assertN otEmpty(pa tientMatch Query.getP atientProf ile().getS sn(),
        500                                      "SSN is  required!" );
        501  
        502                    fina l String f irstName =  patientMa tchQuery.g etPatientP rofile()
        503                                      .getFirs tName();
        504                    fina l String l astName =  patientMat chQuery.ge tPatientPr ofile()
        505                                      .getLast Name();
        506                    fina l String s sn = patie ntMatchQue ry.getPati entProfile ().getSsn( );
        507                    Stri ng cacheKe y = "ssn="  + ssn + " &firstname =" + first Name
        508                                      + "&last name=" + l astName;
        509                    cach eKey = cac heKey.toLo werCase();
        510  
        511                    // G o to the M PI and mat ch the pat ient using  a match q uery and r eturn
        512                    // t he results  in Patien t objects.  There cou ld be Sing le Match,  Multiple
        513                    // M atch or No  Matches w ith the MP I.
        514                    try  {
        515  
        516                             // Cac he lives f or 5 mins.  Check the  ehCache.x ml for mor e
        517                             // inf ormation.
        518                             if (Ca cheManager .getInstan ce().cache Exists(
        519                                               PdqService Impl.PDQ_P ATIENT_MAT CH_CACHE_N AME)) {
        520                                      final Ca che cache  = CacheMan ager.getIn stance().g etCache(
        521                                                       Pd qServiceIm pl.PDQ_PAT IENT_MATCH _CACHE_NAM E);
        522                                      if (cach e.isKeyInC ache(cache Key)) {
        523                                               final Elem ent elemen t = cache. get(cacheK ey);
        524                                               if (NullCh ecker.isNo tEmpty(ele ment)) {
        525                                                       // if (PdqSer viceImpl.l ogger.isLo ggable(Lev el.INFO))  {
        526                                                                //Pd qServiceIm pl.logger. log(Level. INFO,
        527                                                                //                "Obtaini ng cached  matches fo r patient,  "
        528                                                                //                                 +  cacheKey);
        529                                                       // }
        530                                                       re turn (Pati entMatchRe sponse) el ement.getO bjectValue ();
        531                                               }
        532                                      }
        533                             }
        534  
        535                             // 1.  Construct  a patient  search req uest objec t
        536                             // 2.  Use JAXB t o make pat ient searc h request  object int o XML
        537                             final  Document p atientMatc hQueryDocu ment = thi s.pdqJaxbH elper
        538                                               .marshal(p atientMatc hQuery);
        539                             // 3.  Get the pa tient sear ch request  xml docum ent and co nvert it t o
        540                             // a Q BP_Q22 MPI
        541                             // que ry - Refer  to MPI Te chnical Ma nual
        542                             Assert .assertNot Empty(pati entMatchQu eryDocumen t,
        543                                               "PatientMa tchQuery d ocument ca nnot be nu ll!");
        544                             final  Document q bpQ22Docum ent = this .patientMa tchQueryTo QBPQ22Tran sformer
        545                                               .transform (patientMa tchQueryDo cument);
        546                             if (Pd qServiceIm pl.logger. isLoggable (Level.FIN E)) {
        547                                      PdqServi ceImpl.log ger.log(
        548                                                       Le vel.FINE,
        549                                                       "S earch Pati ent Reques t["
        550                                                                         + (qbp Q22Documen t != null  ? this.xml 2String
        551                                                                                           .transform (qbpQ22Doc ument) : " null")
        552                                                                         + "]") ;
        553                             }
        554                             // 4.  Get the RS P_K22 xml  document f rom the MP I
        555                             Assert .assertNot Empty(qbpQ 22Document ,
        556                                               "QBP_Q22 d ocument ca nnot be nu ll!");
        557                             final  long start Time = Sys tem.curren tTimeMilli s();
        558                             final  Document r spK22Docum ent = this .mviSocket Endpoint
        559                                               .invoke(qb pQ22Docume nt);
        560                             final  long endTi me = Syste m.currentT imeMillis( );
        561                             if (Pd qServiceIm pl.logger. isLoggable (Level.FIN E)) {
        562                                      PdqServi ceImpl.log ger.log(
        563                                                       Le vel.FINE,
        564                                                       "S earch Pati ent Respon se["
        565                                                                         + (rsp K22Documen t != null  ? this.xml 2String
        566                                                                                           .transform (rspK22Doc ument) : " null")
        567                                                                         + "]"  + ". Time  elapsed =  "
        568                                                                         + ((en dTime - st artTime) /  1000) + " s");
        569                             }
        570                             // 5.  Convert fr om RSP_K22  to Patien t search r esponse xm l document
        571                             Assert .assertNot Empty(rspK 22Document ,
        572                                               "RSP_K22 d ocument ca nnot be nu ll!");
        573  
        574                             final  Document p atientMatc hResponseD ocument =  this.rspK2 2ToPatient MatchRespo nseTransfo rmer
        575                                               .transform (rspK22Doc ument);
        576                             Assert .assertNot Empty(pati entMatchRe sponseDocu ment,
        577                                               "PatientMa tchRespons e document  cannot be  null!");
        578                             // 6.  Use JAXB t o unmarsha ll the pat ient searc h response  xml
        579                             // doc ument into  a java ob ject
        580                             final  PatientMat chResponse  patientMa tchRespons e = (Patie ntMatchRes ponse) thi s.pdqJaxbH elper
        581                                               .unmarshal (patientMa tchRespons eDocument) ;
        582                             Assert .assertNot Empty(pati entMatchRe sponse,
        583                                               "PatientMa tchRespons e object c annot be n ull!");
        584  
        585                             // Sto re in cach e
        586                             if (Ca cheManager .getInstan ce().cache Exists(
        587                                               PdqService Impl.PDQ_P ATIENT_MAT CH_CACHE_N AME)) {
        588                                      final Ca che cache  = CacheMan ager.getIn stance().g etCache(
        589                                                       Pd qServiceIm pl.PDQ_PAT IENT_MATCH _CACHE_NAM E);
        590                                      cache.pu t(new Elem ent(cacheK ey, patien tMatchResp onse));
        591                             }
        592                             // 7.  Return the  patient s earch resp onse
        593                             return  patientMa tchRespons e;
        594                    } ca tch (final  EndpointE xception e x) {
        595                             throw  new PdqExc eption(ex) ;
        596                    } ca tch (final  Transform erExceptio n ex) {
        597                             throw  new PdqExc eption(ex) ;
        598                    } ca tch (final  JAXBExcep tion ex) {
        599                             throw  new PdqExc eption(ex) ;
        600                    }
        601           }
        602  
        603           @R equired
        604           pu blic void  setCacheMa nager(fina l CacheMan ager cache Manager) {
        605                    this .cacheMana ger = cach eManager;
        606           }
        607  
        608           @R equired
        609           pu blic void  setMviSock etEndpoint (
        610                             final  Endpoint<D ocument, D ocument> m viSocketEn dpoint) {
        611                    this .mviSocket Endpoint =  mviSocket Endpoint;
        612           }
        613  
        614           @R equired
        615           pu blic void  setPatient ExtendedVi ewRpcRespo nseToPrope rtyMap(
        616                             final  Transforme r<String,  Map<String , Object>>  patientEx tendedView RpcRespons eToPropert yMap) {
        617                    this .patientEx tendedView RpcRespons eToPropert yMap = pat ientExtend edViewRpcR esponseToP ropertyMap ;
        618           }
        619  
        620           @R equired
        621           pu blic void  setPatient MatchQuery ToQBPQ22Tr ansformer(
        622                             final  Transforme r<Document , Document > patientM atchQueryT oQBPQ22Tra nsformer)  {
        623                    this .patientMa tchQueryTo QBPQ22Tran sformer =  patientMat chQueryToQ BPQ22Trans former;
        624           }
        625  
        626           @R equired
        627           pu blic void  setPatient PrimaryVie wRpcRespon seToProper tyMap(
        628                             final  Transforme r<String,  Map<String , Object>>  patientPr imaryViewR pcResponse ToProperty Map) {
        629                    this .patientPr imaryViewR pcResponse ToProperty Map = pati entPrimary ViewRpcRes ponseToPro pertyMap;
        630           }
        631  
        632           @R equired
        633           pu blic void  setPdqAudi tIntercept or(
        634                             final  Intercepto r<Object,  Object> pd qAuditInte rceptor) {
        635                    this .pdqAuditI nterceptor  = pdqAudi tIntercept or;
        636           }
        637  
        638           @R equired
        639           pu blic void  setPdqJaxb Helper(fin al JaxbUti l pdqJaxbH elper) {
        640                    this .pdqJaxbHe lper = pdq JaxbHelper ;
        641           }
        642  
        643           @R equired
        644           pu blic void  setPropert yMapAggreg ator(
        645                             final  Aggregator <Map<Strin g, Object> , Map<Stri ng, ?>> pr opertyMapA ggregator)  {
        646                    this .propertyM apAggregat or = prope rtyMapAggr egator;
        647           }
        648  
        649           @R equired
        650           pu blic void  setRemoveP atientCorr elationReq uestToADTA 37(
        651                             final  Transforme r<Document , Document > removePa tientCorre lationRequ estToADTA3 7) {
        652                    this .removePat ientCorrel ationReque stToADTA37  = removeP atientCorr elationReq uestToADTA 37;
        653           }
        654  
        655           @R equired
        656           pu blic void  setRpcExte ndedRespon seSplitter (
        657                             final  Splitter<S tring, Map <String, S tring>> rp cExtendedR esponseSpl itter) {
        658                    this .rpcExtend edResponse Splitter =  rpcExtend edResponse Splitter;
        659           }
        660  
        661           @R equired
        662           pu blic void  setRpcResp onsesRecen tDateFilte r(
        663                             final  Filter<Map <String, M ap<String,  Object>>,  String> r pcResponse sRecentDat eFilter) {
        664                    this .rpcRespon sesRecentD ateFilter  = rpcRespo nsesRecent DateFilter ;
        665           }
        666  
        667           @R equired
        668           pu blic void  setRpcResp onsesToPat ientCorrel ationRespo nse(
        669                             final  Transforme r<String,  PatientCor relationsR esponse> r pcResponse sToPatient Correlatio nResponse)  {
        670                    this .rpcRespon sesToPatie ntCorrelat ionRespons e = rpcRes ponsesToPa tientCorre lationResp onse;
        671           }
        672  
        673           @R equired
        674           pu blic void  setRpcResp onsesToPat ientDemogr aphicsResp onse(
        675                             final  Transforme r<Map<Stri ng, Object >, Documen t> rpcResp onsesToPat ientDemogr aphicsResp onse) {
        676                    this .rpcRespon sesToPatie ntDemograp hicsRespon se = rpcRe sponsesToP atientDemo graphicsRe sponse;
        677           }
        678  
        679           @R equired
        680           pu blic void  setRpcResp onsesToPro pertyMapRe cordTwoPas s(
        681                             final  Transforme r<Map<Stri ng, String >, Map<Str ing, Map<S tring, Obj ect>>> rpc ResponsesT oPropertyM apRecordTw oPass) {
        682                    this .rpcRespon sesToPrope rtyMapReco rdTwoPass  = rpcRespo nsesToProp ertyMapRec ordTwoPass ;
        683           }
        684  
        685           @R equired
        686           pu blic void  setRspK22T oPatientMa tchRespons eTransform er(
        687                             final  Transforme r<Document , Document > rspK22To PatientMat chResponse Transforme r) {
        688                    this .rspK22ToP atientMatc hResponseT ransformer  = rspK22T oPatientMa tchRespons eTransform er;
        689           }
        690  
        691           @R equired
        692           pu blic void  setVaFacil ityNumberF ilter(
        693                             final  Filter<Map <String, S tring>, Ma p<String,  String>> v aFacilityN umberFilte r) {
        694                    this .vaFacilit yNumberFil ter = vaFa cilityNumb erFilter;
        695           }
        696  
        697           @R equired
        698           pu blic void  setVistaPa tientExten dedViewEnd point(
        699                             final  Endpoint<O bject, Str ing> vista PatientExt endedViewE ndpoint) {
        700                    this .vistaPati entExtende dViewEndpo int = vist aPatientEx tendedView Endpoint;
        701           }
        702  
        703           @R equired
        704           pu blic void  setVistaPa tientPrima ryViewEndp oint(
        705                             final  Endpoint<O bject, Str ing> vista PatientPri maryViewEn dpoint) {
        706                    this .vistaPati entPrimary ViewEndpoi nt = vista PatientPri maryViewEn dpoint;
        707           }
        708  
        709           @R equired
        710           pu blic void  setXml2Str ing(final  XMLToStrin g xml2Stri ng) {
        711                    this .xml2Strin g = xml2St ring;
        712           }
        713       
        714       @Requi red
        715       public  void setD ataToConse ntDirectiv eDocument( Transforme r<Document , Document > dataToCo nsentDirec tiveDocume nt) {
        716           th is.dataToC onsentDire ctiveDocum ent = data ToConsentD irectiveDo cument;
        717       }
        718  
        719       @Requi red
        720       public  void setC onsentDire ctiveDataJ axbHelper( JaxbUtil c onsentDire ctiveDataJ axbHelper)  {
        721           th is.consent DirectiveD ataJaxbHel per = cons entDirecti veDataJaxb Helper;
        722       }
        723  
        724       @Requi red
        725       public  void setC ms(Consent Management Service cm s) {
        726           th is.cms = c ms;
        727       }
        728       @Requi red
        729           pu blic void  setAuditSe rvice(fina l AuditSer vice audit Service) {
        730                    this .auditServ ice = audi tService;
        731           }
        732   }