36. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 4/5/2017 4:21:45 PM Central 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.

36.1 Files compared

# Location File Last Modified
1 C:\working_scrub\Unredacted\eHX Code Base\eHX_Bld2_Source Code_CIF_2017-02-14\NHIN_adapter\AdapterEJB\src\main\java\gov\va\med\nhin\adapter\adapterxdr AdapterXDR.java Fri Feb 10 15:41:44 2017 UTC
2 eHX-CIF.zip\eHX-CIF\eHX Code Base\eHX_Bld2_Source Code_CIF_2017-02-14\NHIN_adapter\AdapterEJB\src\main\java\gov\va\med\nhin\adapter\adapterxdr AdapterXDR.java Mon Apr 3 14:23:06 2017 UTC

36.2 Comparison summary

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

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

36.4 Active regular expressions

No regular expressions were active.

36.5 Comparison detail

  1   package go v.va.med.n hin.adapte r.adapterx dr;
  2  
  3   import gov .hhs.fha.n hinc.commo n.nhinccom mon.Assert ionType;
  4   import gov .hhs.fha.n hinc.commo n.nhinccom mon.Person NameType;
  5   import gov .hhs.fha.n hinc.commo n.nhinccom monadapter .AdapterPr ovideAndRe gisterDocu mentSetReq uestType;
  6  
  7   import jav ax.ejb.Sta teless;
  8   import jav ax.jws.Web Service;
  9   import jav ax.xml.ws. BindingTyp e;
  10   import jav ax.xml.ws. soap.SOAPB inding;
  11  
  12   import gov .hhs.fha.n hinc.nhinc componentp atientcorr elation.Pa tientCorre lationPort Type;
  13   import gov .hhs.fha.n hinc.trans form.subdi sc.HL7PRPA 201309Tran sforms;
  14   import gov .va.med.nh in.adapter .audit.Aud it;
  15   import gov .va.med.nh in.adapter .audit.Aud itManager;
  16   import gov .va.med.nh in.adapter .audit.Aud itManagerL ocal;
  17   import gov .va.med.nh in.adapter .documentr epository. Document;
  18   import gov .va.med.nh in.adapter .documentr epository. DocumentRe pository;
  19   import gov .va.med.nh in.adapter .documentr epository. DocumentRe positoryLo cal;
  20   import gov .va.med.nh in.adapter .facilitym anager.Fac ility;
  21   import gov .va.med.nh in.adapter .facilitym anager.Fac ilityManag er;
  22   import gov .va.med.nh in.adapter .facilitym anager.Fac ilityManag erLocal;
  23   import gov .va.med.nh in.adapter .patientco rrelation. PatientCor relationPo rtTypeLoca l;
  24   import gov .va.med.nh in.adapter .patientco rrelation. parsers.he lpers.Conf iguration;
  25   import gov .va.med.nh in.adapter .patientdi scovery.Va pConsentMa nagementPo rtTypeLoca l;
  26   import gov .va.med.nh in.adapter .propertyl ookup.Prop ertyLookup ;
  27   import gov .va.med.nh in.adapter .propertyl ookup.Prop ertyLookup Local;
  28   import gov .va.med.nh in.adapter .utils.Nul lChecker;
  29   import gov .va.med.nh in.adapter .utils.das .DasDAO;
  30   import gov .va.med.nh in.adapter .utils.das .DasDAOHtt pImpl;
  31   import gov .va.med.nh in.adapter .utils.das .DasExcept ion;
  32   import gov .va.med.nh in.adapter .utils.das .DasOperat ionSendImm unizationD ataRequest ;
  33   import gov .va.med.nh in.adapter .utils.das .DasOperat ionSendImm unizationD ataRespons e;
  34   import gov .va.nvap.p rivacy.Org anizationT rustedSour ceRequestT ype;
  35   import gov .va.nvap.p rivacy.Org anizationT rustedSour ceResponse Type;
  36   import ihe .iti.xds_b ._2007.Pro videAndReg isterDocum entSetRequ estType;
  37   import jav a.io.ByteA rrayOutput Stream;
  38   import jav a.io.IOExc eption;
  39   import jav a.util.Dat e;
  40   import jav a.util.Lis t;
  41   import jav a.util.log ging.Level ;
  42   import jav ax.ejb.EJB ;
  43   import jav ax.xml.bin d.JAXBElem ent;
  44   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Exte rnalIdenti fierType;
  45   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Extr insicObjec tType;
  46   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Iden tifiableTy pe;
  47   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Regi stryObject ListType;
  48   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Slot ListType;
  49   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Slot Type1;
  50   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Valu eListType;
  51   import oas is.names.t c.ebxml_re grep.xsd.r s._3.Regis tryError;
  52   import oas is.names.t c.ebxml_re grep.xsd.r s._3.Regis tryErrorLi st;
  53   import oas is.names.t c.ebxml_re grep.xsd.r s._3.Regis tryRespons eType;
  54   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Regi stryPackag eType;
  55   import org .hl7.v3.II ;
  56   import org .hl7.v3.Re trievePati entCorrela tionsReque stType;
  57   import org .hl7.v3.Re trievePati entCorrela tionsRespo nseType;
  58   import org .slf4j.Log ger;
  59   import org .slf4j.Log gerFactory ;
  60   import pri vacy.servi ce.nvap. DNS     .ConsentMa nagementPo rtType;
  61   import pri vacy.servi ce.nvap. DNS     .ConsentMa nagementSe rviceFault Message;
  62  
  63   /**
  64    * This We b Service  implements  Document  Submission  functiona lity provi ded by
  65    * CONNECT  Gateway.
  66    *
  67    * @author  KazeninP
  68    */
  69   @WebServic e(serviceN ame = "Ada pterXDR_Se rvice",
  70                endpoint Interface  = "gov.hhs .fha.nhinc .adapterxd r.AdapterX DRPortType ",
  71                targetNa mespace =  "urn:gov:h hs:fha:nhi nc:adapter xdr",
  72                portName  = "Adapte rXDR_Port" /*,
  73                wsdlLoca tion = "ME TA-INF/wsd l/AdapterX DR.wsdl"*/ )
  74   @BindingTy pe(SOAPBin ding.SOAP1 2HTTP_BIND ING)
  75   @Stateless (name = "A dapterXDR" )
  76   public cla ss Adapter XDR implem ents Adapt erXDRPortT ypeLocal
  77   {
  78       public  static fi nal Logger  logger =  LoggerFact ory.getLog ger(Adapte rXDR.class .getName() );
  79  
  80       static  private f inal Strin g XDS_RETR IEVE_RESPO NSE_STATUS _FAILURE =  "urn:oasi s:names:tc :ebxml-reg rep:Respon seStatusTy pe:Failure ";
  81       static  private f inal Strin g XDS_RETR IEVE_RESPO NSE_STATUS _SUCCESS =  "urn:oasi s:names:tc :ebxml-reg rep:Respon seStatusTy pe:Success ";
  82  
  83       privat e Property Lookup pro pertyLooku p;
  84       privat e Facility Manager fa cilityMana ger;
  85       privat e AuditMan ager audit Manager;
  86       privat e PatientC orrelation PortType a dapterPati entCorrela tion;
  87       privat e Document Repository  documentR epository;
  88       privat e ConsentM anagementP ortType va pConsentMa nagement;
  89  
  90       @EJB(b eanInterfa ce = Prope rtyLookupL ocal.class , beanName  = "Proper tyLookup")
  91       public  void setP ropertyLoo kup(Proper tyLookup p ropertyLoo kup)
  92       {
  93           th is.propert yLookup =  propertyLo okup;
  94       }
  95  
  96       @EJB(b eanInterfa ce = Facil ityManager Local.clas s, beanNam e = "Facil ityManager ")
  97       public  void setF acilityMan ager(Facil ityManager  facilityM anager)
  98       {
  99           th is.facilit yManager =  facilityM anager;
  100       }
  101  
  102       @EJB(b eanInterfa ce = Audit ManagerLoc al.class,  beanName =  "AuditMan ager")
  103       public  void setA uditManage r(AuditMan ager audit Manager)
  104       {
  105           th is.auditMa nager = au ditManager ;
  106       }
  107  
  108       @EJB(b eanInterfa ce = Patie ntCorrelat ionPortTyp eLocal.cla ss, beanNa me = "Adap terPatient Correlatio n")
  109       public  void setA dapterPati entCorrela tion(Patie ntCorrelat ionPortTyp e adapterP atientCorr elation)
  110       {
  111           th is.adapter PatientCor relation =  adapterPa tientCorre lation;
  112       }
  113  
  114       @EJB(b eanInterfa ce = Docum entReposit oryLocal.c lass, bean Name = "Do cumentRepo sitory")
  115       public  void setD ocumentRep ository(Do cumentRepo sitory doc umentRepos itory)
  116       {
  117           th is.documen tRepositor y = docume ntReposito ry;
  118       }
  119  
  120       @EJB(b eanInterfa ce = VapCo nsentManag ementPortT ypeLocal.c lass, bean Name = "Va pConsentMa nagement")
  121       public  void setV apConsentM anagement( ConsentMan agementPor tType vapC onsentMana gement)
  122       {
  123           th is.vapCons entManagem ent = vapC onsentMana gement;
  124       }
  125  
  126       /*
  127        * Thi s method i mplements  provideAnd RegisterDo cumentSetb  operation  defined
  128        * in  the Adapte rXDR.wsdl.
  129        *
  130        * @pa ram reques t contains  ICN, Home CommunityI d and C32  clinical d ocument
  131        *
  132        * @re turn respo nse contai ns either  VLER BsonD ocId in ca se of succ ess or
  133        * err or descrip tion in ca se of fail ure
  134        */
  135       public  RegistryR esponseTyp e provideA ndRegister DocumentSe tb(Adapter ProvideAnd RegisterDo cumentSetR equestType  request)
  136       {
  137           //  CCR 17798 6- logger  update
  138           lo gger.debug ("provideA ndRegister DocumentSe tb() invok ed");
  139  
  140           Re gistryResp onseType r et;
  141  
  142           St ring error Msg;
  143  
  144           Pr ovideAndRe gisterDocu mentSetReq uestType b ody = requ est.getPro videAndReg isterDocum entSetRequ est();
  145  
  146           lo gger.debug ("body {}" , body);
  147  
  148           As sertionTyp e assertio n = reques t.getAsser tion();
  149  
  150           St ring reque stId = get RequestId( body);
  151  
  152           lo gger.debug ("request  id {}", re questId);
  153  
  154           //  retrieve  C32 doc fr om the mes sage
  155           by te[] c32do cument = g etC32Docum ent(body);
  156  
  157           //  CCR 17798 6
  158           lo gger.debug ("c32docum ent {}", c 32document .toString( ));
  159  
  160           if (NullCheck er.isNullO rEmpty(c32 document))  {
  161  
  162                errorMsg  = "C32 Cl inical Doc ument is m issing, re quest Id =  " + reque stId;
  163                ret = cr eateErrorR egistryRes ponseType( "XDSMissin gDocument" , errorMsg , null);
  164                ret.setR equestId(r equestId);
  165  
  166                // CCR 1 77986
  167                logger.e rror("Erro r while cr eating reg istry resp ose {}", e rrorMsg);
  168  
  169                return r et;
  170           }
  171  
  172           //  CCR 17798 6
  173           lo gger.debug ("C32 Clin ical Docum ent conten t {} :\n",  new Strin g(c32docum ent));
  174  
  175           //  retrieve  ICN from t he message
  176           St ring icn =  getICN(bo dy);
  177           lo gger.debug ("icn {}",  icn);
  178           if (NullCheck er.isNullO rEmpty(icn )) {
  179                errorMsg  = "ICN is  missing,  request Id  = " + req uestId;
  180                ret = cr eateErrorR egistryRes ponseType( "XDSUnknow nPatientId ", errorMs g, null);
  181                ret.setR equestId(r equestId);
  182  
  183                logger.e rror(error Msg);
  184  
  185                return r et;
  186           }
  187  
  188           //  CCR 17798 6
  189           lo gger.debug ("Patient  Unique Id  (ICN) {} =  ", icn);
  190  
  191           //  retrieve  Home Commu nity Id fr om the mes sage
  192           St ring homeC ommunityId  = getHome CommunityI d(assertio n);
  193           if (NullCheck er.isNullO rEmpty(hom eCommunity Id)) {
  194                errorMsg  = "Home C ommunity I d is missi ng, reques t Id = " +  requestId  + ", ICN  = " + icn;
  195                ret = cr eateErrorR egistryRes ponseType( "XDSMissin gHomeCommu nityId", e rrorMsg, n ull);
  196                ret.setR equestId(r equestId);
  197  
  198                logger.e rror(error Msg);
  199  
  200                return r et;
  201           }
  202  
  203           //  CCR 17798 6 - parame terized lo gging
  204           lo gger.info( "Home Comm unity Id { } = ", hom eCommunity Id);
  205  
  206           //  get home  facility o f the requ estor
  207           Fa cility hom eFacility  = getHomeF acility(ho meCommunit yId);
  208           if (NullCheck er.isNullO rEmpty(hom eFacility) ) {
  209                errorMsg  = "Home C ommunity I d " + home CommunityI d + " is i nvalid, re quest Id =  " + reque stId + ",  ICN = " +  icn;
  210                ret = cr eateErrorR egistryRes ponseType( "XDSMissin gHomeCommu nityId", e rrorMsg, n ull);
  211                ret.setR equestId(r equestId);
  212  
  213                // CCR 1 77986 - pa rameterize d logging
  214                logger.e rror("ICN  is not cor related to  facility" );
  215                logger.e rror(error Msg + "{}" );
  216  
  217                return r et;
  218           }
  219  
  220           // check Poli cy?
  221           Or ganization TrustedSou rceRequest Type trust Req = new  Organizati onTrustedS ourceReque stType();
  222           tr ustReq.set Organizati onId(homeC ommunityId );
  223           tr y {
  224                Organiza tionTruste dSourceRes ponseType  trustRes =  vapConsen tManagemen t.getIsOrg anizationT rustedSour ce(trustRe q);
  225                if(!trus tRes.isIsT rusted())  {
  226                    logg er.info("R equest fro m Home Com munity Id:  " + homeC ommunityId  + " faile d organiza tion trust ed policy  check, req uest Id =  " + reques tId + ", I CN = " +ic n);
  227  
  228                    erro rMsg = "Re quest fail ed a polic y check.";
  229                    ret  = createEr rorRegistr yResponseT ype("XDSRe positoryEr ror", erro rMsg, null );
  230                    ret. setRequest Id(request Id);
  231  
  232                    retu rn ret;
  233                }
  234           }  catch (Con sentManage mentServic eFaultMess age ex) {
  235                logger.e rror("Erro r during i s organiza tion trust ed policy  check.", e x);
  236  
  237                errorMsg  = "Reques t failed a  policy ch eck.";
  238                ret = cr eateErrorR egistryRes ponseType( "XDSReposi toryError" , errorMsg , null);
  239                ret.setR equestId(r equestId);
  240  
  241                return r et;
  242           }
  243  
  244           St ring facil ityNumber  = homeFaci lity.getFa cilityNumb er();
  245           lo gger.debug ("Facility  Number {}  = ", faci lityNumber );
  246  
  247           //  check if  ICN is cor related to  Home Faci lity Id
  248           II  patientId  = new II( );
  249           pa tientId.se tRoot(Conf iguration. getMyCommu nityId());  // VA OID
  250           pa tientId.se tExtension (icn);
  251  
  252           Re trievePati entCorrela tionsReque stType pat ientCorrel ationsRequ est = new  RetrievePa tientCorre lationsReq uestType() ;
  253           pa tientCorre lationsReq uest.setPR PAIN201309 UV02(HL7PR PA201309Tr ansforms.c reatePRPA2 01309(pati entId.getR oot(), pat ientId.get Extension( )));
  254  
  255           pa tientCorre lationsReq uest.setAs sertion(as sertion);
  256  
  257           Re trievePati entCorrela tionsRespo nseType pa tientCorre lations;
  258  
  259           tr y {
  260                patientC orrelation s = adapte rPatientCo rrelation. retrievePa tientCorre lations(pa tientCorre lationsReq uest);
  261           }
  262           ca tch(Except ion e) {
  263                errorMsg  = "Error  trying to  correlate  patient, H ome Commun ity Id " +  homeCommu nityId + " , request  Id = " + r equestId +  ", ICN =  " + icn +  ", excepti on = " + e .getMessag e();
  264                ret = cr eateErrorR egistryRes ponseType( "XDSRegist ryError",  errorMsg,  homeFacili ty);
  265                ret.setR equestId(r equestId);
  266  
  267                // CCR 1 77986 - pa rameterize d logging
  268                logger.e rror(error Msg + "{}" );
  269  
  270                return r et;
  271           }
  272  
  273           if (patientCo rrelations  == null | | patientC orrelation s.getPRPAI N201310UV0 2() == nul l) {
  274                errorMsg  = "ICN is  unknown t o VA, Home  Community  Id " + ho meCommunit yId + ", r equest Id  = " + requ estId + ",  ICN = " +  icn;
  275                ret = cr eateErrorR egistryRes ponseType( "XDSUnknow nPatientId ", errorMs g, homeFac ility);
  276                ret.setR equestId(r equestId);
  277  
  278                // CCR 1 77986 - pa rameterize d logging
  279                logger.e rror(error Msg + "{}" );
  280  
  281                return r et;
  282           }
  283  
  284           Li st<II> cor relatedPat ientIds =  patientCor relations. getPRPAIN2 01310UV02( ).getContr olActProce ss().getSu bject().ge t(0).getRe gistration Event().ge tSubject1( ).getPatie nt().getId ();
  285  
  286           if (NullCheck er.isNullO rEmpty(cor relatedPat ientIds) | | correlat edPatientI ds.size()  == 0) {
  287                errorMsg  = "ICN is  unknown t o VA, Home  Community  Id " + ho meCommunit yId + ", r equest Id  = " + requ estId + ",  ICN = " +  icn;
  288                ret = cr eateErrorR egistryRes ponseType( "XDSUnknow nPatientId ", errorMs g, homeFac ility);
  289                ret.setR equestId(r equestId);
  290  
  291                // CCR 1 77986 - pa rameterize d logging
  292                logger.e rror(error Msg + "{}" );
  293  
  294                return r et;
  295           }
  296  
  297           bo olean corr elated = f alse;
  298           St ring short CommunityI d;
  299  
  300           if (homeCommu nityId.sta rtsWith("u rn:oid:"))  {
  301                shortCom munityId =  homeCommu nityId.sub string(8);
  302           }  else {
  303                shortCom munityId =  homeCommu nityId;
  304           }
  305  
  306           fo r(II corre latedPatie ntId : cor relatedPat ientIds) {
  307  
  308                if(short CommunityI d.equalsIg noreCase(c orrelatedP atientId.g etRoot()))  {
  309                         correlated  = true;
  310                         break;
  311                }
  312           }
  313  
  314           if (correlate d == false ) {
  315                errorMsg  = "ICN is  not corre lated to "  + facilit yNumber +  ", Home Co mmunity Id  " + homeC ommunityId  + ", requ est Id = "  + request Id + ", IC N = " + ic n;
  316                ret = cr eateErrorR egistryRes ponseType( "XDSUnknow nPatientId ", errorMs g, homeFac ility);
  317                ret.setR equestId(r equestId);
  318  
  319                // CCR 1 77986 - pa rameterize d logging
  320                logger.e rror(error Msg + "{}" );
  321  
  322                return r et;
  323           }
  324  
  325           //  get url f rom the pr operty tab le
  326           St ring endPo int = prop ertyLookup .getProper ty("vler.d as.docsubm it.url");
  327           if (NullCheck er.isNullO rEmpty(end Point)) {
  328                errorMsg  = "VLER D AS URL vle r.das.docs ubmit.url  is not con figured in  the VA Ad apter PROP ERTIES tab le";
  329                ret = cr eateErrorR egistryRes ponseType( "XDSRegist ryError",  errorMsg,  homeFacili ty);
  330  
  331                // CCR 1 77986 - pa rameterize d logging
  332                logger.e rror(error Msg + "{}" );
  333  
  334                return r et;
  335           }
  336  
  337           lo gger.debug ("VLER DAS  URL templ ate {} = "  + endPoin t);
  338  
  339           //  instantia te Das Htt p client
  340           Da sDAO dasDA O;
  341           da sDAO = new  DasDAOHtt pImpl(endP oint);
  342  
  343           Da sOperation SendImmuni zationData Request re q;
  344           Da sOperation SendImmuni zationData Response r es;
  345  
  346           //  call VLER  DAS Immun ization pu sh
  347           tr y {
  348                req = ne w DasOpera tionSendIm munization DataReques t();
  349                req.setM essage(c32 document);
  350  
  351                req.setF acility(fa cilityNumb er);
  352                req.setI CN(icn);
  353  
  354                res = da sDAO.doOpe rationSend Immunizati onData(req );
  355  
  356                ret = cr eateRegist ryResponse Type(res.g etDocId()) ;
  357  
  358                auditDoc umentSubmi ssion(asse rtion, bod y, res);
  359           }  catch(DasE xception e ) {
  360                ret = cr eateErrorR egistryRes ponseType( e.getError Code(), e. getCodeCon text(), ho meFacility );
  361  
  362                // CCR 1 77986
  363                logger.e rror("Seve re: DAS Ex ception {} ", e.getCo deContext( ));
  364           }
  365  
  366           //  copy requ est Id fro m request
  367           re t.setReque stId(reque stId);
  368  
  369           //  CCR 17798 6 - parame terized lo gging
  370           lo gger.debug ("provideA ndRegister DocumentSe tb() exite d");
  371  
  372           re turn ret;
  373       }
  374  
  375       /*
  376        * Bui lds Regist ryResponse Type with  Bson Doc I d as a slo t content
  377        *
  378        * @pa ram docId  Bson Doc I d generate d by VLER  DAS
  379        *
  380        * @re turn respo nse Regist ryResponse Type conta ining docI d
  381        */
  382       privat e Registry ResponseTy pe createR egistryRes ponseType( String doc Id) {
  383  
  384           oa sis.names. tc.ebxml_r egrep.xsd. rs._3.Obje ctFactory  of = new o asis.names .tc.ebxml_ regrep.xsd .rs._3.Obj ectFactory ();
  385  
  386           Re gistryResp onseType r et = of.cr eateRegist ryResponse Type();
  387  
  388           Sl otListType  slotList  = new Slot ListType() ;
  389           Sl otType1 sl ot = new S lotType1() ;
  390           sl ot.setName ("Document Id");
  391  
  392           Va lueListTyp e valueLis tType = ne w ValueLis tType();
  393           va lueListTyp e.getValue ().add(doc Id);
  394           sl ot.setValu eList(valu eListType) ;
  395           sl otList.get Slot().add (slot);
  396           re t.setRespo nseSlotLis t(slotList );
  397  
  398           re t.setStatu s(XDS_RETR IEVE_RESPO NSE_STATUS _SUCCESS);
  399  
  400           //  CCR 17798 6- only if  logger is  enabled
  401           lo gger.debug ("Registry ResponseTy pe ret {}" , ret);
  402  
  403           re turn ret;
  404       }
  405  
  406       privat e Registry ResponseTy pe createE rrorRegist ryResponse Type(Strin g errorCod e, String  codeContex t, Facilit y homeFaci lity) {
  407           oa sis.names. tc.ebxml_r egrep.xsd. rs._3.Obje ctFactory  of = new o asis.names .tc.ebxml_ regrep.xsd .rs._3.Obj ectFactory ();
  408  
  409           Re gistryResp onseType r et = of.cr eateRegist ryResponse Type();
  410  
  411           Re gistryErro rList regi stryErrorL ist = crea teRegistry ErrorList( );
  412  
  413           Re gistryErro r registry Error = cr eateRegist ryError(er rorCode, c odeContext , homeFaci lity);
  414  
  415           re gistryErro rList.getR egistryErr or().add(r egistryErr or);
  416  
  417           re t.setRegis tryErrorLi st(registr yErrorList );
  418  
  419           re t.setStatu s(XDS_RETR IEVE_RESPO NSE_STATUS _FAILURE);
  420  
  421           //  CCR 17798 6- only if  logger is  enabled
  422           lo gger.debug ("Registry ResponseTy pe ret {}" , ret);
  423  
  424           re turn ret;
  425       }
  426  
  427       privat e Registry ErrorList  createRegi stryErrorL ist() {
  428           oa sis.names. tc.ebxml_r egrep.xsd. rs._3.Obje ctFactory  retObjFact ory = new  oasis.name s.tc.ebxml _regrep.xs d.rs._3.Ob jectFactor y();
  429           Re gistryErro rList ret  = retObjFa ctory.crea teRegistry ErrorList( );
  430           re t.setHighe stSeverity ("urn:oasi s:names:tc :ebxml-reg rep:ErrorS everityTyp e:Error");
  431           re turn ret;
  432       }
  433  
  434       privat e Registry Error crea teRegistry Error(Stri ng errorCo de, String  codeConte xt, Facili ty homeFac ility) {
  435           oa sis.names. tc.ebxml_r egrep.xsd. rs._3.Obje ctFactory  retObjFact ory = new  oasis.name s.tc.ebxml _regrep.xs d.rs._3.Ob jectFactor y();
  436           Re gistryErro r ret = re tObjFactor y.createRe gistryErro r();
  437           re t.setSever ity("urn:o asis:names :tc:ebxml- regrep:Err orSeverity Type:Error ");
  438           re t.setError Code(error Code);
  439           re t.setCodeC ontext(cod eContext);
  440  
  441           if (NullCheck er.isNullO rEmpty(hom eFacility) ) {
  442                ret.setL ocation("" );
  443           }  else {
  444                ret.setL ocation(ho meFacility .getFullHo meCommunit yId());
  445           }
  446  
  447           re turn ret;
  448       }
  449  
  450       /*
  451        * Loo k up Facil ity data i n the FACI LITIES tab le
  452        */
  453       privat e Facility  getHomeFa cility(Str ing homeCo mmunityId)
  454       {
  455           Fa cility fac ility = nu ll;
  456  
  457           fa cility = f acilityMan ager.getFa cilityByFu llHomeComm unityId(ho meCommunit yId);
  458  
  459           if (NullCheck er.isNotNu llOrEmpty( facility))  {
  460                return f acility;
  461           }
  462  
  463           fa cility = f acilityMan ager.getFa cilityByHo meCommunit yId(homeCo mmunityId) ;
  464  
  465           //  CCR 17798 6- only if  logger is  enabled
  466           lo gger.debug ("facility  name {}",  facility. getFacilit yName());
  467           lo gger.debug ("facility  number {} ", facilit y.getFacil ityNumber( ));
  468           lo gger.debug ("Home Com munity Id  {}", facil ity.getFul lHomeCommu nityId());
  469  
  470           re turn facil ity;
  471       }
  472  
  473       /*
  474        * ret rieve C32  document < ProvideAnd RegisterDo cumentSetR equest> <D ocument
  475        * id= "Walgreens ">UjBsR09E bGhjZ0dTQU xNQUFBUUNB RU1tQ1p0dU 1GUXhEUzhi </
  476        * Doc ument> </P rovideAndR egisterDoc umentSetRe quest>
  477        */
  478       privat e byte[] g etC32Docum ent(Provid eAndRegist erDocument SetRequest Type body)
  479       {
  480           if (NullCheck er.isNullO rEmpty(bod y.getDocum ent())) {
  481                //CCR 17 7986
  482                logger.e rror("Seve re {}", "D ocument se ction is e mpty");
  483                return n ull;
  484           }
  485  
  486           by te[] c32by tes = null ;
  487           tr y {
  488                ByteArra yOutputStr eam baos =  new ByteA rrayOutput Stream();
  489                body.get Document() .get(0).ge tValue().w riteTo(bao s);
  490                c32bytes  = baos.to ByteArray( );
  491           }  catch(IOEx ception e)  {
  492                //CCR 17 7986
  493                logger.e rror("Seve re {}", "E rror getti ng Documen t from Pro videAndReg isterDocum entSet");
  494                return n ull;
  495           }
  496  
  497           if (NullCheck er.isNullO rEmpty(c32 bytes)) {
  498                //CCR 17 7986
  499                logger.e rror("Seve re {}", "D ocument co ntent is e mpty");
  500                return n ull;
  501           }
  502  
  503           re turn c32by tes;
  504       }
  505  
  506       /*
  507        * ret rieve ICN  from Regis tryObjectL ist:
  508        */
  509       privat e String g etICN(Prov ideAndRegi sterDocume ntSetReque stType bod y)
  510       {
  511           St ring uniqu ePatientId  = getUniq uePatientI d(body);
  512  
  513           if (NullCheck er.isNotNu llOrEmpty( uniquePati entId)) {
  514                logger.d ebug("uniq uePatientI d {} : ",  uniquePati entId);
  515                return u niquePatie ntId.split ("\\^")[0] ;
  516           }
  517  
  518           re turn null;
  519       }
  520  
  521       privat e String g etUniquePa tientId(Pr ovideAndRe gisterDocu mentSetReq uestType b ody)
  522       {
  523           Re gistryPack ageType re gistryPack age;
  524  
  525           Li st<Externa lIdentifie rType> reg istryPacka geExternal Identifier List;
  526  
  527           Re gistryObje ctListType  registryO bjectList  = body.get SubmitObje ctsRequest ().getRegi stryObject List();
  528  
  529           Li st<JAXBEle ment<? ext ends Ident ifiableTyp e>> identi fiableList  = registr yObjectLis t.getIdent ifiable();
  530  
  531           fo r(JAXBElem ent<? exte nds Identi fiableType > identifi able : ide ntifiableL ist) {
  532  
  533                // check  RegistryP ackage of  the DS req uest for
  534                // XDSSu bmissionSe t.patientI d
  535                if(ident ifiable.ge tValue() i nstanceof  RegistryPa ckageType)  {
  536                    regi stryPackag e = (Regis tryPackage Type) iden tifiable.g etValue();
  537  
  538                    // g et Externa lIdentifie rs
  539                    regi stryPackag eExternalI dentifierL ist = regi stryPackag e.getExter nalIdentif ier();
  540                    for( ExternalId entifierTy pe registr yPackageEx ternalIden tifier : r egistryPac kageExtern alIdentifi erList) {
  541                         if(registr yPackageEx ternalIden tifier.get Name().get LocalizedS tring().ge t(0).getVa lue().equa lsIgnoreCa se("XDSSub missionSet .patientId ")) {
  542                             return  registryP ackageExte rnalIdenti fier.getVa lue();
  543                         }
  544                    }
  545  
  546                }
  547  
  548                // check  Extrinsic Object of  the DS req uest
  549                /*
  550                 * if (i dentifiabl e.getValue () instanc eof Extrin sicObjectT ype) {
  551                 * extri nsicObject  = (Extrin sicObjectT ype)identi fiable.get Value();
  552                 *
  553                 * extri nsicObject ExternalId entifierLi st =
  554                 * extri nsicObject .getExtern alIdentifi er(); for
  555                 * (Exte rnalIdenti fierType e xtrinsicOb jectExtern alIdentifi er:
  556                 * extri nsicObject ExternalId entifierLi st) { if
  557                 * (extr insicObjec tExternalI dentifier. getName(). getLocaliz edString()
  558                 * .get( 0).getValu e()
  559                 * .equa lsIgnoreCa se("XDSDoc umentEntry .patientId ")) { retu rn
  560                 * extri nsicObject ExternalId entifier.g etValue();  } } }
  561                 */
  562           }
  563           re turn null;
  564       }
  565  
  566       privat e String g etHomeComm unityId(As sertionTyp e assertio n)
  567       {
  568           if (NullCheck er.isNullO rEmpty(ass ertion)) {
  569                logger.e rror("Seve re {}", "A ssertion s ection is  empty");
  570  
  571                return n ull;
  572           }
  573  
  574           if (NullCheck er.isNullO rEmpty(ass ertion.get HomeCommun ity())) {
  575                logger.e rror("Seve re {}", "H omeCommuni ty section  is empty" );
  576  
  577                return n ull;
  578           }
  579  
  580           St ring homeC ommunityId  = asserti on.getHome Community( ).getHomeC ommunityId ().trim();
  581  
  582           // CCR 177986
  583           lo gger.debug ("homeComm unityId {}  :", homeC ommunityId );
  584  
  585           if (homeCommu nityId.sta rtsWith("u rn:oid:"))  {
  586                return h omeCommuni tyId;
  587           }  else {
  588                return " urn:oid:"  + homeComm unityId;
  589           }
  590       }
  591  
  592       privat e String g etRequestI d(ProvideA ndRegister DocumentSe tRequestTy pe body)
  593       {
  594           if (NullCheck er.isNullO rEmpty(bod y.getSubmi tObjectsRe quest()))  {
  595                return " ";
  596           }
  597  
  598           if (NullCheck er.isNullO rEmpty(bod y.getSubmi tObjectsRe quest().ge tId())) {
  599                return " ";
  600           }
  601  
  602           // CCR 177986
  603           lo gger.debug ("request  id {} ", b ody.getSub mitObjects Request(). getId() );
  604  
  605           re turn body. getSubmitO bjectsRequ est().getI d();
  606       }
  607  
  608       privat e void aud itDocument Submission (Assertion Type asser tion, Prov ideAndRegi sterDocume ntSetReque stType bod y, DasOper ationSendI mmunizatio nDataRespo nse respon se)
  609       {
  610  
  611           //  create re cord in th e DOCUMENT  table
  612  
  613           Do cument doc ument = ne w Document ();
  614  
  615           by te[] c32by tes = getC 32Document (body);
  616           do cument.set DocumentUn iqueId(res ponse.getD ocId());
  617           do cument.set RawData(c3 2bytes);
  618           do cument.set Size(c32by tes.length );
  619           do cument.set Availabili tyStatus(" urn:oasis: names:tc:e bxmlregrep :StatusTyp e:Approved ");
  620           do cument.set LastAccess edTime(new  Date());
  621           do cument.set CreationTi me(new Dat e());
  622           do cument.set ClassCode( "11369-6") ;
  623           do cument.set ClassCodeD isplayName ("History  of immuniz ations");
  624           do cument.set ClassCodeS cheme("2.1 6.840.1.11 3883.6.1") ;
  625           do cument.set MimeType(" text/xml") ;
  626           do cument.set PatientId( getICN(bod y));
  627           do cument.set FormatCode DisplayNam e("History  of immuni zations");
  628           do cument.set SourcePati entId(getU niquePatie ntId(body) );
  629           do cument.set PatientSSN (assertion .getSSN()) ;
  630  
  631           if (NullCheck er.isNotNu llOrEmpty( assertion. getUserInf o())) {
  632  
  633                if(NullC hecker.isN otNullOrEm pty(assert ion.getUse rInfo().ge tOrg())) {
  634                    // d ocument.se tPatientPr eferredFac ilityNumbe r(assertio n.getUserI nfo().getO rg().getHo meCommunit yId());
  635                    docu ment.setPa tientPrefe rredFacili tyName(ass ertion.get UserInfo() .getOrg(). getName()) ;
  636                }
  637  
  638                document .setPatien tGivenName (getGivenN ame(body)) ;
  639                document .setPatien tLastName( getFamilyN ame(body)) ;
  640  
  641           }
  642  
  643           // CCR 177986
  644           lo gger.debug ("Document  details { }", docume nt.toStrin g());
  645  
  646           do cumentRepo sitory.sto reDocument (document) ;
  647  
  648           //  create re cord in th e AUDIT ta ble
  649           Au dit audit  = new Audi t();
  650  
  651           au dit.setAct ion("Docum entSubmiss ionIn");
  652           au dit.setAud itTime(new  Date());
  653           au dit.setDoc umentId(do cument.get DocumentUn iqueId());
  654           au dit.setRem oteDocumen tId(docume nt.getDocu mentUnique Id());
  655           //  audit.set RemoteDocu mentReposi toryId(d.g etReposito ryUniqueId ());
  656           au dit.setRem oteOrganiz ationId(ge tHomeCommu nityId(ass ertion));
  657  
  658           if (NullCheck er.isNotNu llOrEmpty( assertion. getUserInf o())) {
  659                audit.se tUserId(as sertion.ge tUserInfo( ).getUserN ame());
  660  
  661                if(NullC hecker.isN otNullOrEm pty(assert ion.getUse rInfo().ge tRoleCoded ())) {
  662                    audi t.setUserR ole(assert ion.getUse rInfo().ge tRoleCoded ().getCode ());
  663                }
  664  
  665                if(NullC hecker.isN otNullOrEm pty(assert ion.getUse rInfo().ge tOrg())) {
  666                    audi t.setUserF acilityNum ber(assert ion.getUse rInfo().ge tOrg().get HomeCommun ityId());
  667                    audi t.setUserF acilityNam e(assertio n.getUserI nfo().getO rg().getNa me());
  668                }
  669  
  670                if(NullC hecker.isN otNullOrEm pty(assert ion.getUse rInfo().ge tPersonNam e())) {
  671                    Pers onNameType  userName  = assertio n.getUserI nfo().getP ersonName( );
  672                    if(! NullChecke r.isNullOr Empty(user Name.getFu llName()))  {
  673                         audit.setU serName(us erName.get FullName() );
  674                    } el se {
  675                         audit.setU serName(us erName.get GivenName( ) + " " +  userName.g etFamilyNa me());
  676                    }
  677                }
  678           }
  679  
  680           if (NullCheck er.isNotNu llOrEmpty( assertion. getPurpose OfDisclosu reCoded()) ) {
  681                audit.se tPurposeFo rUse(asser tion.getPu rposeOfDis closureCod ed().getCo de());
  682           }
  683  
  684           au dit.setOrg anizationI d(assertio n.getHomeC ommunity() .getHomeCo mmunityId( ));
  685           au dit.setPat ientId(get ICN(body)) ;
  686           au dit.setPat ientSSN(as sertion.ge tSSN());
  687  
  688           au dit.setPat ientGivenN ame(getGiv enName(bod y));
  689           au dit.setPat ientLastNa me(getFami lyName(bod y));
  690           au dit.setPat ientFacili tyNumber(g etHomeFaci lity(getHo meCommunit yId(assert ion)).getF acilityNum ber());
  691           au dit.setPat ientFacili tyName(get HomeFacili ty(getHome CommunityI d(assertio n)).getFac ilityName( ));
  692  
  693           au dit.setDet ails("ICN= " + audit. getPatient Id() + ",  VLER DAS D ocument Id =" + respo nse.getDoc Id());
  694  
  695           // CCR 177986
  696           lo gger.debug ("Audit de tails {}",  audit.toS tring());
  697  
  698           au ditManager .storeAudi t(audit);
  699       }
  700  
  701       privat e String g etFamilyNa me(Provide AndRegiste rDocumentS etRequestT ype body)
  702       {
  703  
  704           re turn getPa rtName(bod y, 0);
  705       }
  706  
  707       privat e String g etGivenNam e(ProvideA ndRegister DocumentSe tRequestTy pe body)
  708       {
  709  
  710           re turn getPa rtName(bod y, 1);
  711       }
  712  
  713       privat e String g etPartName (ProvideAn dRegisterD ocumentSet RequestTyp e body, in t n)
  714       {
  715  
  716           Li st<String>  sourcePat ientInfoLi st = getSo urcePatien tInfoList( body);
  717  
  718           if (NullCheck er.isNullO rEmpty(sou rcePatient InfoList))  {
  719                return n ull;
  720           }
  721  
  722           St ring patie ntFullName  = getPati entFullNam e(sourcePa tientInfoL ist);
  723  
  724           if (NullCheck er.isNullO rEmpty(pat ientFullNa me)) {
  725                return n ull;
  726           }
  727  
  728           St ring partN ame = null ;
  729  
  730           tr y {
  731                partName  = patient FullName.s plit("\\^" )[n];
  732           }  catch(Exce ption e) {
  733                //CCR 17 9231
  734                logger.e rror("Exce ption in g ettign par t name fro m the docu ment", e);
  735           }
  736  
  737           re turn partN ame;
  738       }
  739  
  740       privat e String g etPatientF ullName(Li st<String>  sourcePat ientInfoLi st)
  741       {
  742           if (NullCheck er.isNullO rEmpty(sou rcePatient InfoList))  {
  743                return n ull;
  744           }
  745  
  746           St ring patie ntFullName  = null;
  747  
  748           fo r(String s ourcePatie ntInfo : s ourcePatie ntInfoList ) {
  749                if(NullC hecker.isN ullOrEmpty (sourcePat ientInfo))  {
  750                    cont inue;
  751                }
  752  
  753                if(sourc ePatientIn fo.startsW ith("PID-5 |")) {
  754                    pati entFullNam e = source PatientInf o.substrin g(6);
  755                    brea k;
  756                }
  757           }
  758  
  759           re turn patie ntFullName ;
  760       }
  761  
  762       privat e List<Str ing> getSo urcePatien tInfoList( ProvideAnd RegisterDo cumentSetR equestType  body)
  763       {
  764           Ex trinsicObj ectType ex trinsicObj ect;
  765           Li st<SlotTyp e1> extrin sicObjectS lotList;
  766  
  767           Re gistryObje ctListType  registryO bjectList  = body.get SubmitObje ctsRequest ().getRegi stryObject List();
  768  
  769           Li st<JAXBEle ment<? ext ends Ident ifiableTyp e>> identi fiableList  = registr yObjectLis t.getIdent ifiable();
  770  
  771           fo r(JAXBElem ent<? exte nds Identi fiableType > identifi able : ide ntifiableL ist) {
  772  
  773                if(ident ifiable.ge tValue() i nstanceof  ExtrinsicO bjectType)  {
  774                    extr insicObjec t = (Extri nsicObject Type) iden tifiable.g etValue();
  775  
  776                    // g et Slots
  777                    extr insicObjec tSlotList  = extrinsi cObject.ge tSlot();
  778                    for( SlotType1  extrinsicO bjectSlot  : extrinsi cObjectSlo tList) {
  779                         // search  for slot.n ame = 'sou rcePatient Info'
  780                         if(extrins icObjectSl ot.getName ().equalsI gnoreCase( "sourcePat ientInfo") ) {
  781                             return  extrinsic ObjectSlot .getValueL ist().getV alue();
  782                         }
  783                    }
  784                }
  785           }
  786  
  787           re turn null;
  788       }
  789   }