198. EPMO Open Source Coordination Office Redaction File Detail Report

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

198.1 Files compared

# Location File Last Modified
1 eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\eHXE_Build3_2017-05-04.zip\NHIN_adapter\AdapterEJB\src\archive\java\gov\va\med\nhin\adapter\adaptergateway\docquery AdapterGatewayDocQueryBean.java Wed Apr 5 01:13:54 2017 UTC
2 eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\eHXE_Build3_2017-05-04.zip\NHIN_adapter\AdapterEJB\src\archive\java\gov\va\med\nhin\adapter\adaptergateway\docquery AdapterGatewayDocQueryBean.java Thu Jun 1 21:33:50 2017 UTC

198.2 Comparison summary

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

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

198.4 Active regular expressions

No regular expressions were active.

198.5 Comparison detail

  1   package go v.va.med.n hin.adapte r.adapterg ateway.doc query;
  2  
  3   import jav a.math.Big Integer;
  4   import jav a.text.Dat eFormat;
  5   import jav a.text.Par seExceptio n;
  6   import jav a.text.Sim pleDateFor mat;
  7   import jav a.util.Arr ayList;
  8   import jav a.util.Dat e;
  9   import jav a.util.Has hMap;
  10   import jav a.util.Lis t;
  11   import jav a.util.Map ;
  12   import jav a.util.Tim eZone;
  13   import jav a.util.UUI D;
  14  
  15   import jav ax.ejb.EJB ;
  16   import jav ax.ejb.*;
  17   import jav ax.jws.Web Service;
  18   import jav ax.xml.bin d.JAXBElem ent;
  19  
  20   import org .slf4j.Log ger;
  21   import org .slf4j.Log gerFactory ;
  22  
  23   import gov .hhs.fha.n hinc.adapt erpolicyen gine.Adapt erPolicyEn ginePortTy pe;
  24   import gov .hhs.fha.n hinc.commo n.nhinccom mon.Assert ionType;
  25   import gov .hhs.fha.n hinc.commo n.nhinccom mon.CeType ;
  26   import gov .hhs.fha.n hinc.commo n.nhinccom mon.HomeCo mmunityTyp e;
  27   import gov .hhs.fha.n hinc.commo n.nhinccom mon.NhinTa rgetCommun ityType;
  28   import gov .hhs.fha.n hinc.commo n.nhinccom mon.Person NameType;
  29   import gov .hhs.fha.n hinc.commo n.nhinccom mon.SamlIs suerType;
  30   import gov .hhs.fha.n hinc.commo n.nhinccom mon.UserTy pe;
  31   import gov .hhs.fha.n hinc.commo n.nhinccom monadapter .CheckPoli cyRequestT ype;
  32   import gov .hhs.fha.n hinc.commo n.nhinccom monadapter .CheckPoli cyResponse Type;
  33   import gov .va.med.nh in.adapter .datamanag er.DataMan ager;
  34   import gov .va.med.nh in.adapter .datamanag er.DataQue ry;
  35   import gov .va.med.nh in.adapter .datamanag er.ejb.Dat aManagerLo cal;
  36   import gov .va.med.nh in.adapter .documentr epository. Document;
  37   import gov .va.med.nh in.adapter .documentr epository. DocumentRe pository;
  38   import gov .va.med.nh in.adapter .documentr epository. DocumentRe positoryLo cal;
  39   import gov .va.med.nh in.adapter .facilitym anager.Fac ility;
  40   import gov .va.med.nh in.adapter .facilitym anager.Fac ilityManag er;
  41   import gov .va.med.nh in.adapter .facilitym anager.Fac ilityManag erLocal;
  42   import gov .va.med.nh in.adapter .logging.C heckPolicy ;
  43   import gov .va.med.nh in.adapter .logging.E rrorMessag e;
  44   import gov .va.med.nh in.adapter .logging.M aintLog;
  45   import gov .va.med.nh in.adapter .policyeng ine.Adapte rPolicyEng inePortTyp eLocal;
  46   import gov .va.med.nh in.adapter .policyeng ine.CheckP olicyReque stBuilder;
  47   import gov .va.med.nh in.adapter .propertyl ookup.Prop ertyLookup ;
  48   import gov .va.med.nh in.adapter .propertyl ookup.Prop ertyLookup Local;
  49   import gov .va.med.nh in.adapter .utils.Nul lChecker;
  50   import oas is.names.t c.ebxml_re grep.xsd.q uery._3.Ad hocQueryRe quest;
  51   import oas is.names.t c.ebxml_re grep.xsd.q uery._3.Ad hocQueryRe sponse;
  52   import oas is.names.t c.ebxml_re grep.xsd.q uery._3.Re sponseOpti onType;
  53   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Adho cQueryType ;
  54   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Clas sification Type;
  55   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Exte rnalIdenti fierType;
  56   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Extr insicObjec tType;
  57   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Iden tifiableTy pe;
  58   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Loca lizedStrin gType;
  59   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Regi stryObject ListType;
  60   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Slot Type1;
  61   import oas is.names.t c.ebxml_re grep.xsd.r im._3.Valu eListType;
  62   import oas is.names.t c.ebxml_re grep.xsd.r s._3.Regis tryError;
  63   import oas is.names.t c.ebxml_re grep.xsd.r s._3.Regis tryErrorLi st;
  64   import oas is.names.t c.xacml._2 _0.context .schema.os .RequestTy pe;
  65  
  66   /**
  67    *
  68    * @author  
D NS    
  69    */
  70   @WebServic e(serviceN ame = "Ada pterGatewa yDocQuery" , portName  = "Adapte rGatewayDo cQueryPort Soap", end pointInter face = "go v.va.med.n hin.adapte r.adapterg ateway.doc query.Adap terGateway DocQueryPo rtType", t argetNames pace = "ur n:gov:va:m ed:nhin:ad apter:adap tergateway :docquery" , wsdlLoca tion = "ME TA-INF/wsd l/AdapterG atewayDocQ uery.wsdl" )
  71   @Transacti onAttribut e(value =  Transactio nAttribute Type.SUPPO RTS)
  72   @Stateless
  73   public cla ss Adapter GatewayDoc QueryBean  implements  AdapterGa tewayDocQu eryPortTyp e
  74   {
  75           pr ivate stat ic final L ogger logg er = Logge rFactory.g etLogger(A dapterGate wayDocQuer yBean.clas s.getName( )); // CCR
  76                                                                                                                                                                                                                                                         // 177 986
  77  
  78           pr ivate stat ic final S tring EBXM L_DOCENTRY _PATIENT_I D = "$XDSD ocumentEnt ryPatientI d";
  79           pr ivate stat ic final S tring EBXM L_DOCENTRY _CLASS_COD E = "$XDSD ocumentEnt ryClassCod e";
  80           pr ivate stat ic final S tring EBXM L_DOCENTRY _SERVICE_S TART_TIME_ FROM = "$X DSDocument EntryServi ceStartTim eFrom";
  81           pr ivate stat ic final S tring EBXM L_DOCENTRY _SERVICE_S TART_TIME_ TO = "$XDS DocumentEn tryService StartTimeT o";
  82           pr ivate stat ic final S tring EBXM L_DOCENTRY _SERVICE_S TOP_TIME_F ROM = "$XD SDocumentE ntryServic eStopTimeF rom";
  83           pr ivate stat ic final S tring EBXM L_DOCENTRY _SERVICE_S TOP_TIME_T O = "$XDSD ocumentEnt ryServiceS topTimeTo" ;
  84           pr ivate stat ic final S tring EBXM L_DOCENTRY _STATUS =  "$XDSDocum entEntrySt atus";
  85           pr ivate stat ic final S tring EBXM L_DOCENTRY _FORMAT_CO DE = "$XDS DocumentEn tryFormatC ode";
  86  
  87           pr ivate stat ic final S tring EBXM L_RESPONSE _REPOSITOR Y_UNIQUE_I D_SLOTNAME  = "reposi toryUnique Id";
  88           pr ivate stat ic final S tring EBXM L_RESPONSE _DOCID_IDE NTIFICATIO N_SCHEME =  "urn:uuid :2e82c1f6- a085-4c72- 9da3-8640a 32e42ab";
  89           pr ivate stat ic final S tring EBXM L_RESPONSE _DOCID_NAM E = "XDSDo cumentEntr y.uniqueId ";
  90           pr ivate stat ic final S tring EBXM L_RESPONSE _PATIENTID _IDENTIFIC ATION_SCHE ME = "urn: uuid:58a6f 841-87b3-4 a3e-92fd-a 8ffeff9842 7";
  91           pr ivate stat ic final S tring EBXM L_RESPONSE _CLASSCODE _CLASS_SCH EME = "urn :uuid:41a5 887f-8865- 4c09-adf7- e362475b14 3a";
  92           pr ivate stat ic final S tring EBXM L_RESPONSE _FORMATCOD E_CLASS_SC HEME = "ur n:uuid:a09 d5840-386c -46f2-b5ad -9c3699a43 09d";
  93           pr ivate stat ic final S tring EBXM L_RESPONSE _CREATIONT IME_SLOTNA ME = "crea tionTime";
  94           pr ivate stat ic final S tring EBXM L_RESPONSE _HASH_SLOT NAME = "ha sh";
  95           pr ivate stat ic final S tring EBXM L_RESPONSE _SERVICEST ARTTIME_SL OTNAME = " serviceSta rtTime";
  96           pr ivate stat ic final S tring EBXM L_RESPONSE _SERVICEST OPTIME_SLO TNAME = "s erviceStop Time";
  97           pr ivate stat ic final S tring EBXM L_RESPONSE _SIZE_SLOT NAME = "si ze";
  98           pr ivate stat ic final S tring DATE _FORMAT_SE RVICE = "y yyyMMdd";
  99           
  100           pr ivate Prop ertyLookup  propertyL ookup;
  101           pr ivate Faci lityManage r facility Manager;
  102           pr ivate Adap terPolicyE nginePortT ype adapte rPolicyEng ine;
  103           pr ivate Docu mentReposi tory docum entReposit ory;
  104           pr ivate Data Manager da taManager;
  105           pr ivate Adap terGateway DocQueryPo rtType ada pterGatewa yDocQuery;
  106  
  107           @E JB(beanInt erface = P ropertyLoo kupLocal.c lass, bean Name = "Pr opertyFile Lookup")
  108           pu blic void  setPropert yLookup(Pr opertyLook up propert yLookup)
  109           {
  110                    this .propertyL ookup = pr opertyLook up;
  111           }
  112  
  113           @E JB(beanInt erface = F acilityMan agerLocal. class, bea nName = "F acilityMan ager")
  114           pu blic void  setFacilit yManager(F acilityMan ager facil ityManager )
  115           {
  116                    this .facilityM anager = f acilityMan ager;
  117           }
  118  
  119           @E JB(beanInt erface = D ocumentRep ositoryLoc al.class,  beanName =  "Document Repository ")
  120           pu blic void  setDocumen tRepositor y(Document Repository  documentR epository)
  121           {
  122                    this .documentR epository  = document Repository ;
  123           }
  124  
  125           @E JB(beanInt erface = A dapterPoli cyEnginePo rtTypeLoca l.class, b eanName =  "AdapterPo licyEngine ")
  126           pu blic void  setAdapter PolicyEngi ne(Adapter PolicyEngi nePortType  adapterPo licyEngine )
  127           {
  128                    this .adapterPo licyEngine  = adapter PolicyEngi ne;
  129           }
  130  
  131           @E JB(beanInt erface = A dapterGate wayDocQuer yPortTypeL ocal.class , beanName  = "Adapte rGatewayDo cQueryOrch ")
  132           pu blic void  setAdapter GatewayDoc Query(Adap terGateway DocQueryPo rtType ada pterGatewa yDocQuery)
  133           {
  134                    this .adapterGa tewayDocQu ery = adap terGateway DocQuery;
  135           }
  136  
  137           @E JB(beanInt erface = D ataManager Local.clas s, beanNam e = "DataM anager")
  138           pu blic void  setDataMan ager(DataM anager dat aManager)
  139           {
  140                    this .dataManag er = dataM anager;
  141           }
  142  
  143           pu blic Respo ndingGatew ayCrossGat ewayQueryR esponseTyp e respondi ngGatewayC rossGatewa yQuery(Res pondingGat ewayCrossG atewayQuer yRequestTy pe respond ingGateway CrossGatew ayQueryReq uest)
  144           {
  145                    Resp ondingGate wayCrossGa tewayQuery ResponseTy pe ret;
  146                    Adho cQueryRequ est body =  respondin gGatewayCr ossGateway QueryReque st.getAdho cQueryRequ est();
  147                    Asse rtionType  assertion  = respondi ngGatewayC rossGatewa yQueryRequ est.getAss ertion();
  148  
  149                    try
  150                    {
  151                             if(che ckPolicy(a ssertion))
  152                             {
  153                                      gov.va.m ed.nhin.ad apter.adap tergateway .docquery. ObjectFact ory objFac tory = new  gov.va.me d.nhin.ada pter.adapt ergateway. docquery.O bjectFacto ry();
  154                                      Respondi ngGatewayC rossGatewa yQueryRequ estType re quest = ob jFactory.c reateRespo ndingGatew ayCrossGat ewayQueryR equestType ();
  155                                      Map<Stri ng, List<S tring>> sl otMap = ge tMapFromSl ots(body.g etAdhocQue ry().getSl ot());
  156                                      String p atientId =  slotMap.g et(EBXML_D OCENTRY_PA TIENT_ID). get(0);
  157                                      request. setAdhocQu eryRequest (createAdh ocQueryReq uest(slotM ap));
  158                                      request. setAsserti on(createA ssertion(a ssertion,  patientId) );
  159  
  160                                      Respondi ngGatewayC rossGatewa yQueryResp onseType r esult = ad apterGatew ayDocQuery .respondin gGatewayCr ossGateway Query(requ est);
  161  
  162                                      ret = cr eateRespon dingGatewa yCrossGate wayQueryRe sponse(bod y, result,  patientId );
  163                             }
  164                             else
  165                             {
  166                                      ret = cr eateRespon dingGatewa yCrossGate wayQueryRe sponseErro r(body);
  167                             }
  168                    }
  169                    catc h(RuntimeE xception r e)
  170                    { 
  171                             // CCR  179231
  172                             logger .error("Ru ntime exce ption occu rred while  performin g outbound  Doc Query  in respon dingGatewa yCrossGate wayQuery() ", re);
  173                             ret =  createResp ondingGate wayCrossGa tewayQuery ResponseEr ror(body);
  174                             
  175                             // CCR  177986- a dded logge r as a par ameter , / /error for  outbound  QD
  176                             MaintL og.queryEr ror(respon dingGatewa yCrossGate wayQueryRe quest, Err orMessage. OUT_DQ_UNK NOWN, re.g etMessage( ), logger) ;
  177                    }
  178                    catc h(Exceptio n e)
  179                    { 
  180                             // CCR  179231
  181                             logger .error("Th ere was an  error whi le perform ing outbou nd Doc Que ry in resp ondingGate wayCrossGa tewayQuery ()", e);
  182                             ret =  createResp ondingGate wayCrossGa tewayQuery ResponseEr ror(body);
  183                             
  184                             // CCR  177986- a dded logge r as a par ameter , / /error for  outbound  QD
  185                             MaintL og.queryEr ror(respon dingGatewa yCrossGate wayQueryRe quest, Err orMessage. OUT_DQ_UNK NOWN, e.ge tMessage() , logger);
  186                    }
  187  
  188                    retu rn ret;
  189           }
  190  
  191           pr ivate Adho cQueryRequ est create AdhocQuery Request(Ma p<String,  List<Strin g>> params )
  192           {
  193                    Adho cQueryRequ est ret =  new AdhocQ ueryReques t();
  194                    ret. setFederat ed(false);
  195                    ret. setStartIn dex(BigInt eger.value Of(0));
  196                    ret. setMaxResu lts(BigInt eger.value Of(-1));
  197                    ret. setAdhocQu ery(create AdhocQuery (params));
  198                    ret. setRespons eOption(cr eateRespon seOption() );
  199                    retu rn ret;
  200           }
  201  
  202           pr ivate Adho cQueryType  createAdh ocQuery(Ma p<String,  List<Strin g>> params )
  203           {
  204                    Adho cQueryType  ret = new  AdhocQuer yType();
  205                    ret. setHome("u rn:oid:" +  propertyL ookup.getP roperty("H omeCommuni tyId"));
  206                    ret. setId("urn :uuid:14d4 debf-8f97- 4251-9a74- a90016b0af 0d");
  207                    ret. getSlot(). addAll(cre ateSlots(p arams));
  208                    retu rn ret;
  209           }
  210  
  211           pr ivate List <SlotType1 > createSl ots(Map<St ring, List <String>>  params)
  212           {
  213                    Arra yList<Slot Type1> ret  = new Arr ayList<Slo tType1>();
  214  
  215                    Stri ng patient Id = param s.get(EBXM L_DOCENTRY _PATIENT_I D).get(0);
  216                    Slot Type1 xdsE ntryPatien tId = new  SlotType1( );
  217                    xdsE ntryPatien tId.setNam e(EBXML_DO CENTRY_PAT IENT_ID);
  218                    xdsE ntryPatien tId.setVal ueList(cre ateValueLi st("'" + p atientId +  "'"));
  219                    ret. add(xdsEnt ryPatientI d);
  220  
  221                    List <String> c lassCodes  = params.g et(EBXML_D OCENTRY_CL ASS_CODE);
  222                    Slot Type1 xdsE ntryClassC ode = new  SlotType1( );
  223                    xdsE ntryClassC ode.setNam e(EBXML_DO CENTRY_CLA SS_CODE);
  224                    xdsE ntryClassC ode.setVal ueList(cre ateValueLi st(qualify ClassCodes (classCode s)));
  225                    ret. add(xdsEnt ryClassCod e);
  226  
  227                    if(p arams.get( EBXML_DOCE NTRY_SERVI CE_START_T IME_FROM)  != null)
  228                    {
  229                             String  startTime  = params. get(EBXML_ DOCENTRY_S ERVICE_STA RT_TIME_FR OM).get(0) ;
  230                             SlotTy pe1 xdsEnt ryServiceS tartTimeFr om = new S lotType1() ;
  231                             xdsEnt ryServiceS tartTimeFr om.setName (EBXML_DOC ENTRY_SERV ICE_START_ TIME_FROM) ;
  232                             xdsEnt ryServiceS tartTimeFr om.setValu eList(crea teValueLis t(startTim e));
  233                             ret.ad d(xdsEntry ServiceSta rtTimeFrom );
  234                    }
  235  
  236                    if(p arams.get( EBXML_DOCE NTRY_SERVI CE_START_T IME_TO) !=  null)
  237                    {
  238                             String  endTime =  params.ge t(EBXML_DO CENTRY_SER VICE_START _TIME_TO). get(0);
  239                             SlotTy pe1 xdsEnt ryServiceS topTimeTo  = new Slot Type1();
  240                             xdsEnt ryServiceS topTimeTo. setName(EB XML_DOCENT RY_SERVICE _START_TIM E_TO);
  241                             xdsEnt ryServiceS topTimeTo. setValueLi st(createV alueList(e ndTime));
  242                             ret.ad d(xdsEntry ServiceSto pTimeTo);
  243                    }
  244  
  245                    if(p arams.get( EBXML_DOCE NTRY_SERVI CE_STOP_TI ME_FROM) ! = null)
  246                    {
  247                             String  startTime  = params. get(EBXML_ DOCENTRY_S ERVICE_STO P_TIME_FRO M).get(0);
  248                             SlotTy pe1 xdsEnt ryServiceS tartTimeFr om = new S lotType1() ;
  249                             xdsEnt ryServiceS tartTimeFr om.setName (EBXML_DOC ENTRY_SERV ICE_STOP_T IME_FROM);
  250                             xdsEnt ryServiceS tartTimeFr om.setValu eList(crea teValueLis t(startTim e));
  251                             ret.ad d(xdsEntry ServiceSta rtTimeFrom );
  252                    }
  253  
  254                    if(p arams.get( EBXML_DOCE NTRY_SERVI CE_STOP_TI ME_TO) !=  null)
  255                    {
  256                             String  endTime =  params.ge t(EBXML_DO CENTRY_SER VICE_STOP_ TIME_TO).g et(0);
  257                             SlotTy pe1 xdsEnt ryServiceS topTimeTo  = new Slot Type1();
  258                             xdsEnt ryServiceS topTimeTo. setName(EB XML_DOCENT RY_SERVICE _STOP_TIME _TO);
  259                             xdsEnt ryServiceS topTimeTo. setValueLi st(createV alueList(e ndTime));
  260                             ret.ad d(xdsEntry ServiceSto pTimeTo);
  261                    }
  262  
  263                    if(p arams.get( EBXML_DOCE NTRY_FORMA T_CODE) !=  null)
  264                    {
  265                             List<S tring> for matCode =  params.get (EBXML_DOC ENTRY_FORM AT_CODE);
  266                             SlotTy pe1 xdsEnt ryFormatCo de = new S lotType1() ;
  267                             xdsEnt ryFormatCo de.setName (EBXML_DOC ENTRY_FORM AT_CODE);
  268                             xdsEnt ryFormatCo de.setValu eList(crea teValueLis t(qualifyF ormatCodes (formatCod e)));
  269                             ret.ad d(xdsEntry FormatCode );
  270                    }
  271  
  272                    Slot Type1 xdsD ocEntrySta tus = new  SlotType1( );
  273                    xdsD ocEntrySta tus.setNam e(EBXML_DO CENTRY_STA TUS);
  274                    xdsD ocEntrySta tus.setVal ueList(cre ateValueLi st("('urn: oasis:name s:tc:ebxml -regrep:St atusType:A pproved',' urn:ihe:it i:2010:Sta tusType:De ferredCrea tion')"));
  275                    ret. add(xdsDoc EntryStatu s);
  276  
  277                    retu rn ret;
  278           }
  279  
  280           pr ivate Valu eListType  createValu eList(Stri ng fromStr ing)
  281           {
  282                    Valu eListType  ret = new  ValueListT ype();
  283                    ret. getValue() .add(fromS tring);
  284                    retu rn ret;
  285           }
  286  
  287           pr ivate Valu eListType  createValu eList(List <String> f romStrings )
  288           {
  289                    Valu eListType  ret = new  ValueListT ype();
  290                    Stri ngBuffer s toreString  = new Str ingBuffer( );
  291                    for( String s :  fromStrin gs)
  292                    {
  293                             if(sto reString.l ength() !=  0)
  294                             {
  295                                      storeStr ing.append (',');
  296                             }
  297                             storeS tring.appe nd(s);
  298                    }
  299                    ret. getValue() .add("(" +  storeStri ng.toStrin g() + ")") ;
  300                    retu rn ret;
  301           }
  302  
  303           pr ivate List <String> q ualifyClas sCodes(Lis t<String>  classCodes )
  304           {
  305                    List <String> r et = new A rrayList<S tring>();
  306                    Stri ng docQuer yClassCode Scheme = p ropertyLoo kup.getPro perty("doc QueryClass CodeScheme ");
  307                    for( String cla ssCode : c lassCodes)
  308                    {
  309                             if(!Nu llChecker. isNullOrEm pty(docQue ryClassCod eScheme) & & !classCo de.endsWit h("^^" + d ocQueryCla ssCodeSche me))
  310                             {
  311                                      ret.add( "'" + clas sCode + "^ ^" + docQu eryClassCo deScheme +  "'");
  312                             }
  313                             else
  314                             {
  315                                      ret.add( "'" + clas sCode + "' ");
  316                             }
  317                    }
  318                    retu rn ret;
  319           }
  320  
  321           pr ivate List <String> q ualifyForm atCodes(Li st<String>  formatCod es)
  322           {
  323                    List <String> r et = new A rrayList<S tring>();
  324                    Stri ng docQuer yFormatCod eScheme =  propertyLo okup.getPr operty("do cQueryForm atCodeSche me");
  325                    for( String for matCode :  formatCode s)
  326                    {
  327                             if(!Nu llChecker. isNullOrEm pty(docQue ryFormatCo deScheme)  && !format Code.endsW ith("^^" +  docQueryF ormatCodeS cheme))
  328                             {
  329                                      ret.add( "'" + form atCode + " ^^" + docQ ueryFormat CodeScheme  + "'");
  330                             }
  331                             else
  332                             {
  333                                      ret.add( "'" + form atCode + " '");
  334                             }
  335                    }
  336                    retu rn ret;
  337           }
  338  
  339           pr ivate Resp onseOption Type creat eResponseO ption()
  340           {
  341                    Resp onseOption Type ret =  new Respo nseOptionT ype();
  342                    ret. setReturnC omposedObj ects(true) ;
  343                    ret. setReturnT ype("LeafC lass");
  344                    retu rn ret;
  345           }
  346  
  347           pr ivate Asse rtionType  createAsse rtion(Asse rtionType  fromAssert ion, Strin g patientI d)
  348           {
  349                    Asse rtionType  ret = new  AssertionT ype();
  350                    Faci lity homeF acility =  facilityMa nager.getF acilityByF acilityNum ber("VA");
  351  
  352                    ret. setAuthori zed(true);
  353  
  354                    Home CommunityT ype homeCo mmunity =  new HomeCo mmunityTyp e();
  355                    home Community. setHomeCom munityId(h omeFacilit y.getFullH omeCommuni tyId());
  356                    home Community. setName(ho meFacility .getFacili tyName());
  357                    ret. setHomeCom munity(hom eCommunity );
  358  
  359                    User Type user  = new User Type();
  360                    CeTy pe roleCod ed = new C eType();
  361                    role Coded.setC ode("22460 8005");
  362                    if(f romAsserti on.getUser Info() !=  null)
  363                    {
  364                             user.s etUserName (fromAsser tion.getUs erInfo().g etUserName ());
  365                             user.s etPersonNa me(fromAss ertion.get UserInfo() .getPerson Name());
  366                             user.s etOrg(from Assertion. getUserInf o().getOrg ());
  367                             if(fro mAssertion .getUserIn fo().getRo leCoded()  != null)
  368                             {
  369                                      roleCode d.setCode( fromAssert ion.getUse rInfo().ge tRoleCoded ().getCode ());
  370                             }
  371                    }
  372                    else
  373                    {
  374                             user.s etUserName ("VA_USER" );
  375                             Person NameType p ersonName  = new Pers onNameType ();
  376                             person Name.setGi venName("V A");
  377                             person Name.setFa milyName(" User");
  378                             user.s etPersonNa me(personN ame);
  379                    }
  380  
  381                    if(u ser.getPer sonName()  != null &&  (NullChec ker.isNotN ullOrEmpty (user.getP ersonName( ).getFamil yName()) | | NullChec ker.isNotN ullOrEmpty (user.getP ersonName( ).getSecon dNameOrIni tials()) | | NullChec ker.isNotN ullOrEmpty (user.getP ersonName( ).getGiven Name())))
  382                    {
  383                             user.s etUserName (user.getU serName()  + ", CN="  + createFu llName(use r.getPerso nName()) +  ", O=" +  homeFacili ty.getFaci lityName() );
  384                    }
  385                    else
  386                    {
  387                             user.s etUserName (user.getU serName()  + ", CN="  + user.get UserName()  + ", O="  + homeFaci lity.getFa cilityName ());
  388                    }
  389  
  390                    role Coded.setC odeSystem( "2.16.840. 1.113883.6 .96");
  391                    role Coded.setC odeSystemN ame("SNOME D_CT");
  392                    Data Query quer y = dataMa nager.getQ uery("STS. lookupSNOM ED");
  393                    quer y.setParam eter("code ", roleCod ed.getCode ());
  394                    List <Map> resu lts = quer y.getResul ts();
  395                    role Coded.setD isplayName ((String)  results.ge t(0).get(" name"));
  396                    user .setRoleCo ded(roleCo ded);
  397                    // i f (user.ge tOrg() ==  null) {
  398                    user .setOrg(ho meCommunit y);
  399                    // }
  400                    ret. setUserInf o(user);
  401  
  402                    ret. getUniqueP atientId() .add(patie ntId);
  403  
  404                    CeTy pe p = new  CeType();
  405                    p.se tCodeSyste m("2.16.84 0.1.113883 .3.18.7.1" );
  406                    p.se tCodeSyste mName("nhi n-purpose" );
  407                    p.se tDisplayNa me("Treatm ent");
  408                    if(f romAsserti on.getPurp oseOfDiscl osureCoded () != null )
  409                    {
  410                             p.setC ode(fromAs sertion.ge tPurposeOf Disclosure Coded().ge tCode());
  411                    }
  412                    else
  413                    {
  414                             p.setC ode("TREAT MENT");
  415                    }
  416                    ret. setPurpose OfDisclosu reCoded(p) ;
  417  
  418                    Saml IssuerType  sit = new  SamlIssue rType();
  419                    sit. setIssuer( propertyLo okup.getPr operty("As sertionIss uer"));
  420                    sit. setIssuerF ormat(prop ertyLookup .getProper ty("Assert ionIssuerF ormat"));
  421                    ret. setSamlIss uer(sit);
  422  
  423                    ret. setMessage Id("urn:uu id:" + UUI D.randomUU ID().toStr ing());
  424  
  425                    retu rn ret;
  426           }
  427  
  428           pr ivate Map< String, Li st<String> > getMapFr omSlots(Li st<SlotTyp e1> slots)
  429           {
  430                    Hash Map<String , List<Str ing>> ret  = new Hash Map<String , List<Str ing>>();
  431  
  432                    for( SlotType1  slot : slo ts)
  433                    {
  434                             if(!Nu llChecker. isNullOrEm pty(slot.g etName())  && !NullCh ecker.isNu llOrEmpty( slot.getVa lueList())  && !NullC hecker.isN ullOrEmpty (slot.getV alueList() .getValue( )))
  435                             {
  436                                      List<Str ing> value s = ret.ge t(slot.get Name());
  437                                      if(value s == null)
  438                                      {
  439                                               values = n ew ArrayLi st<String> ();
  440                                               ret.put(sl ot.getName (), values );
  441                                      }
  442                                      values.a ddAll(pars eParamForm attedStrin gs(slot.ge tValueList ().getValu e()));
  443                             }
  444                    }
  445  
  446                    retu rn ret;
  447           }
  448  
  449           pr ivate Resp ondingGate wayCrossGa tewayQuery ResponseTy pe createR espondingG atewayCros sGatewayQu eryRespons e(AdhocQue ryRequest  fromAdhocQ ueryReques t, Respond ingGateway CrossGatew ayQueryRes ponseType  fromRespon se, String  patientId )
  450           {
  451                    Resp ondingGate wayCrossGa tewayQuery ResponseTy pe ret = n ew Respond ingGateway CrossGatew ayQueryRes ponseType( );
  452  
  453                    Comm unityAdhoc QueryRespo nsesType c ommunityRe sponses =  new Commun ityAdhocQu eryRespons esType();
  454                    ret. setCommuni tyResponse s(communit yResponses );
  455  
  456                    for( CommunityA dhocQueryR esponseTyp e fromComm unityRespo nse : from Response.g etCommunit yResponses ().getComm unityRespo nse())
  457                    {
  458                             commun ityRespons es.getComm unityRespo nse().add( createComm unityRespo nse(fromCo mmunityRes ponse, fro mAdhocQuer yRequest,  patientId) );
  459                    }
  460  
  461                    retu rn ret;
  462           }
  463  
  464           pr ivate Comm unityAdhoc QueryRespo nseType cr eateCommun ityRespons e(Communit yAdhocQuer yResponseT ype fromCo mmunityRes ponse, Adh ocQueryReq uest fromA dhocQueryR equest, St ring patie ntId)
  465           {
  466                    Comm unityAdhoc QueryRespo nseType re t = new Co mmunityAdh ocQueryRes ponseType( );
  467                    ret. setAdhocQu eryRespons e(createAd hocQueryRe sponse(fro mAdhocQuer yRequest,  fromCommun ityRespons e.getAdhoc QueryRespo nse(), pat ientId));
  468                    ret. setNhinTar getCommuni ty(fromCom munityResp onse.getNh inTargetCo mmunity()) ;
  469                    retu rn ret;
  470           }
  471  
  472           pr ivate Adho cQueryResp onse creat eAdhocQuer yResponse( AdhocQuery Request fr omAdhocQue ryRequest,  AdhocQuer yResponse  fromAdhocQ ueryRespon se, String  patientId )
  473           {
  474                    oasi s.names.tc .ebxml_reg rep.xsd.qu ery._3.Obj ectFactory  objFactor y = new oa sis.names. tc.ebxml_r egrep.xsd. query._3.O bjectFacto ry();
  475                    Adho cQueryResp onse ret =  objFactor y.createAd hocQueryRe sponse();
  476                    ret. setRequest Id(fromAdh ocQueryReq uest.getId ());
  477                    ret. setStatus( fromAdhocQ ueryRespon se.getStat us());
  478                    ret. setRegistr yErrorList (fromAdhoc QueryRespo nse.getReg istryError List());
  479                    ret. setRespons eSlotList( fromAdhocQ ueryRespon se.getResp onseSlotLi st());
  480                    ret. setStartIn dex(fromAd hocQueryRe sponse.get StartIndex ());
  481                    ret. setTotalRe sultCount( fromAdhocQ ueryRespon se.getTota lResultCou nt());
  482                    ret. setRegistr yObjectLis t(createRe gistryObje ctList(fro mAdhocQuer yResponse. getRegistr yObjectLis t(), patie ntId));
  483                    ret. setRegistr yErrorList (createReg istryError List(fromA dhocQueryR esponse.ge tRegistryE rrorList() ));
  484                    retu rn ret;
  485           }
  486  
  487           pr ivate Regi stryObject ListType c reateRegis tryObjectL ist(Regist ryObjectLi stType fro mRegistryO bjectList,  String pa tientId)
  488           {
  489                    Regi stryObject ListType r et = null;
  490  
  491                    if(f romRegistr yObjectLis t != null)
  492                    {
  493                             ret =  new Regist ryObjectLi stType();
  494                             ret.ge tIdentifia ble().addA ll(createI dentifiabl es(fromReg istryObjec tList.getI dentifiabl e(), patie ntId));
  495                    }
  496  
  497                    retu rn ret;
  498           }
  499  
  500           pr ivate List <JAXBEleme nt<? exten ds Identif iableType> > createId entifiable s(List<JAX BElement<?  extends I dentifiabl eType>> fr omIdentifi ables, Str ing patien tId)
  501           {
  502                    List <JAXBEleme nt<? exten ds Identif iableType> > ret = ne w ArrayLis t<JAXBElem ent<? exte nds Identi fiableType >>();
  503  
  504                    for( JAXBElemen t<? extend s Identifi ableType>  identifiab le : fromI dentifiabl es)
  505                    {
  506                             if(ide ntifiable. getValue()  instanceo f Extrinsi cObjectTyp e)
  507                             {
  508                                      ret.add( createExtr insicObjec t((Extrins icObjectTy pe) identi fiable.get Value(), p atientId)) ;
  509                             }
  510                             else
  511                             {
  512                                      ret.add( identifiab le);
  513                             }
  514                    }
  515  
  516                    retu rn ret;
  517           }
  518  
  519           pr ivate JAXB Element<?  extends Id entifiable Type> crea teExtrinsi cObject(Ex trinsicObj ectType fr omExtrinsi cObject, S tring pati entId)
  520           {
  521                    oasi s.names.tc .ebxml_reg rep.xsd.ri m._3.Objec tFactory o bjFactory  = new oasi s.names.tc .ebxml_reg rep.xsd.ri m._3.Objec tFactory() ;
  522                    Extr insicObjec tType ret  = new Extr insicObjec tType();
  523                    ret. setContent VersionInf o(fromExtr insicObjec t.getConte ntVersionI nfo());
  524                    ret. setDescrip tion(fromE xtrinsicOb ject.getDe scription( ));
  525                    ret. setHome(fr omExtrinsi cObject.ge tHome());
  526                    ret. setId(from ExtrinsicO bject.getI d());
  527                    ret. setIsOpaqu e(fromExtr insicObjec t.isIsOpaq ue());
  528                    ret. setLid(fro mExtrinsic Object.get Lid());
  529                    ret. setMimeTyp e(fromExtr insicObjec t.getMimeT ype());
  530                    ret. setName(fr omExtrinsi cObject.ge tName());
  531                    ret. setObjectT ype(fromEx trinsicObj ect.getObj ectType()) ;
  532                    ret. setStatus( fromExtrin sicObject. getStatus( ));
  533                    ret. setVersion Info(fromE xtrinsicOb ject.getVe rsionInfo( ));
  534                    ret. getClassif ication(). addAll(fro mExtrinsic Object.get Classifica tion());
  535                    ret. getSlot(). addAll(fro mExtrinsic Object.get Slot());
  536                    Docu ment doc =  createDoc ument(from ExtrinsicO bject, pat ientId);
  537                    ret. getExterna lIdentifie r().addAll (createExt ernalIdent ifiers(fro mExtrinsic Object.get ExternalId entifier() , doc));
  538                    retu rn objFact ory.create ExtrinsicO bject(ret) ;
  539           }
  540  
  541           pr ivate Docu ment creat eDocument( ExtrinsicO bjectType  fromExtrin sicObject,  String pa tientId)
  542           {
  543                    Docu ment ret =  new Docum ent();
  544                    Map< String, Li st<String> > slots =  getMapFrom Slots(from ExtrinsicO bject.getS lot());
  545  
  546                    Data Query quer y = dataMa nager.getQ uery("Comp osite.find Demographi cs2");
  547                    quer y.setParam eter("icn" , patientI d);
  548                    List <Map> resu lts = quer y.getResul ts();
  549                    if(! NullChecke r.isNullOr Empty(resu lts))
  550                    {
  551                             Map re sult = res ults.get(0 );
  552                             Map de mographics  = (Map) r esult.get( "demograph ics");
  553                             ret.se tPatientLa stName((St ring) demo graphics.g et("nameFa mily"));
  554                             ret.se tPatientGi venName((S tring) dem ographics. get("nameG iven"));
  555                             ret.se tPatientSS N((String)  demograph ics.get("S SN"));
  556                             ret.se tPatientPr eferredFac ilityNumbe r((String)  result.ge t("patient PreferredF acilityNum ber"));
  557                             ret.se tPatientPr eferredFac ilityName( (String) r esult.get( "patientPr eferredFac ilityName" ));
  558                    }
  559  
  560                    ret. setPatient Id(patient Id.substri ng(0, 17)) ;
  561                    ret. setSourceP atientId(g etExternal Identifier (fromExtri nsicObject .getExtern alIdentifi er(), EBXM L_RESPONSE _PATIENTID _IDENTIFIC ATION_SCHE ME).getVal ue());
  562  
  563                    if(! NullChecke r.isNullOr Empty(slot s.get(EBXM L_RESPONSE _SIZE_SLOT NAME)))
  564                    {
  565                             ret.se tSize(Inte ger.parseI nt(slots.g et(EBXML_R ESPONSE_SI ZE_SLOTNAM E).get(0)) );
  566                    }
  567  
  568                    if(! NullChecke r.isNullOr Empty(slot s.get(EBXM L_RESPONSE _HASH_SLOT NAME)))
  569                    {
  570                             ret.se tHash(slot s.get(EBXM L_RESPONSE _HASH_SLOT NAME).get( 0));
  571                    }
  572  
  573                    if(! NullChecke r.isNullOr Empty(slot s.get(EBXM L_RESPONSE _SERVICEST ARTTIME_SL OTNAME)))
  574                    {
  575                             ret.se tBeginDate (parseDate (slots.get (EBXML_RES PONSE_SERV ICESTARTTI ME_SLOTNAM E).get(0),  DATE_FORM AT_SERVICE ));
  576                    }
  577  
  578                    if(! NullChecke r.isNullOr Empty(slot s.get(EBXM L_RESPONSE _SERVICEST OPTIME_SLO TNAME)))
  579                    {
  580                             ret.se tEndDate(p arseDate(s lots.get(E BXML_RESPO NSE_SERVIC ESTOPTIME_ SLOTNAME). get(0), DA TE_FORMAT_ SERVICE));
  581                    }
  582  
  583                    if(! NullChecke r.isNullOr Empty(slot s.get(EBXM L_RESPONSE _CREATIONT IME_SLOTNA ME)))
  584                    {
  585                             ret.se tCreationT ime(new Da te());
  586                    }
  587  
  588                    ret. setMimeTyp e(fromExtr insicObjec t.getMimeT ype());
  589                    ret. setAvailab ilityStatu s("urn:ihe :iti:2010: StatusType :DeferredC reation");
  590  
  591                    if(f romExtrins icObject.g etName() ! = null &&  !NullCheck er.isNullO rEmpty(fro mExtrinsic Object.get Name().get LocalizedS tring()))
  592                    {
  593                             ret.se tTitle(fro mExtrinsic Object.get Name().get LocalizedS tring().ge t(0).getVa lue());
  594                    }
  595  
  596                    ret. setDocumen tUniqueId( UUID.rando mUUID().to String());
  597  
  598                    Clas sification Type class ification  = getClass ification( fromExtrin sicObject. getClassif ication(),  EBXML_RES PONSE_CLAS SCODE_CLAS S_SCHEME);
  599                    if(c lassificat ion != nul l)
  600                    {
  601                             ret.se tClassCode (classific ation.getN odeReprese ntation()) ;
  602                             ret.se tClassCode Scheme(get MapFromSlo ts(classif ication.ge tSlot()).g et("coding Scheme").g et(0));
  603                             ret.se tClassCode DisplayNam e(classifi cation.get Name().get LocalizedS tring().ge t(0).getVa lue());
  604                    }
  605  
  606                    clas sification  = getClas sification (fromExtri nsicObject .getClassi fication() , EBXML_RE SPONSE_FOR MATCODE_CL ASS_SCHEME );
  607                    if(c lassificat ion != nul l)
  608                    {
  609                             ret.se tFormatCod e(classifi cation.get NodeRepres entation() );
  610                             ret.se tFormatCod eScheme(ge tMapFromSl ots(classi fication.g etSlot()). get("codin gScheme"). get(0));
  611                             ret.se tFormatCod eDisplayNa me(classif ication.ge tName().ge tLocalized String().g et(0).getV alue());
  612                    }
  613  
  614                    Stri ng homeCom munityId =  fromExtri nsicObject .getHome() ;
  615                    Stri ng documen tRepositor yId = slot s.get(EBXM L_RESPONSE _REPOSITOR Y_UNIQUE_I D_SLOTNAME ).get(0);
  616                    Stri ng documen tUniqueId  = getExter nalIdentif ier(fromEx trinsicObj ect.getExt ernalIdent ifier(), E BXML_RESPO NSE_DOCID_ IDENTIFICA TION_SCHEM E).getValu e();
  617                    ret. setDocGenQ ueryName(" Remote");
  618                    ret. setDocGenQ ueryParams ("homeComm unityId="  + homeComm unityId +  ",document Repository Id=" + doc umentRepos itoryId +  ",document UniqueId="  + documen tUniqueId) ;
  619  
  620                    docu mentReposi tory.store Document(r et);
  621  
  622                    retu rn ret;
  623           }
  624  
  625           pr ivate Date  parseDate (String da teString,  String for matString)
  626           {
  627                    Date  ret = nul l;
  628                    Simp leDateForm at formatt er = (Simp leDateForm at) DateFo rmat.getDa teTimeInst ance();
  629                    form atter.appl yPattern(f ormatStrin g);
  630                    form atter.setT imeZone(Ti meZone.get TimeZone(" UTC"));
  631                    try
  632                    {
  633                             /* ret  = */ form atter.pars e(dateStri ng);
  634                    }
  635                    catc h(ParseExc eption pe)
  636                    {
  637                             ret =  null;
  638                    }
  639  
  640                    retu rn ret;
  641           }
  642  
  643           pr ivate Exte rnalIdenti fierType g etExternal Identifier (List<Exte rnalIdenti fierType>  externalId entifiers,  String id entificati onScheme)
  644           {
  645                    Exte rnalIdenti fierType r et = null;
  646  
  647                    for( ExternalId entifierTy pe id : ex ternalIden tifiers)
  648                    {
  649                             if(id. getIdentif icationSch eme().equa ls(identif icationSch eme))
  650                             {
  651                                      ret = id ;
  652                                      break;
  653                             }
  654                    }
  655  
  656                    retu rn ret;
  657           }
  658  
  659           pr ivate List <ExternalI dentifierT ype> creat eExternalI dentifiers (List<Exte rnalIdenti fierType>  fromExtern alIdentifi ers, Docum ent docume nt)
  660           {
  661                    List <ExternalI dentifierT ype> ret =  new Array List<Exter nalIdentif ierType>() ;
  662                    for( ExternalId entifierTy pe id : fr omExternal Identifier s)
  663                    {
  664                             for(Lo calizedStr ingType na me : id.ge tName().ge tLocalized String())
  665                             {
  666                                      if(name. getValue() .equals(EB XML_RESPON SE_DOCID_N AME))
  667                                      {
  668                                               ret.add(cr eateExtern alIdentifi er(id, doc ument));
  669                                      }
  670                                      else
  671                                      {
  672                                               ret.add(id );
  673                                      }
  674                             }
  675                    }
  676  
  677                    retu rn ret;
  678           }
  679  
  680           pr ivate Clas sification Type getCl assificati on(List<Cl assificati onType> fr omClassifi cations, S tring clas sScheme)
  681           {
  682                    Clas sification Type ret =  null;
  683  
  684                    for( Classifica tionType c ls : fromC lassificat ions)
  685                    {
  686                             if(cls .getClassi ficationSc heme().equ als(classS cheme))
  687                             {
  688                                      ret = cl s;
  689                                      break;
  690                             }
  691                    }
  692  
  693                    retu rn ret;
  694           }
  695  
  696           pr ivate Exte rnalIdenti fierType c reateExter nalIdentif ier(Extern alIdentifi erType fro mId, Docum ent docume nt)
  697           {
  698                    Exte rnalIdenti fierType r et = new E xternalIde ntifierTyp e();
  699                    ret. setDescrip tion(fromI d.getDescr iption());
  700                    ret. setHome(fr omId.getHo me());
  701                    ret. setId(from Id.getId() );
  702                    ret. setIdentif icationSch eme(fromId .getIdenti ficationSc heme());
  703                    ret. setLid(fro mId.getLid ());
  704                    ret. setName(fr omId.getNa me());
  705                    ret. setObjectT ype(fromId .getObject Type());
  706                    ret. setRegistr yObject(fr omId.getRe gistryObje ct());
  707                    ret. setStatus( fromId.get Status());
  708                    ret. setValue(d ocument.ge tDocumentU niqueId()) ;
  709                    ret. setVersion Info(fromI d.getVersi onInfo());
  710                    retu rn ret;
  711           }
  712  
  713           pr ivate Regi stryErrorL ist create RegistryEr rorList(Re gistryErro rList from RegistryEr rorList)
  714           {
  715                    Regi stryErrorL ist ret =  null;
  716  
  717                    if(f romRegistr yErrorList  != null)
  718                    {
  719                             ret =  new Regist ryErrorLis t();
  720                             ret.se tHighestSe verity(fro mRegistryE rrorList.g etHighestS everity()) ;
  721                             ret.ge tRegistryE rror().add All(create RegistryEr rors(fromR egistryErr orList.get RegistryEr ror()));
  722                    }
  723  
  724                    retu rn ret;
  725           }
  726  
  727           pr ivate List <RegistryE rror> crea teRegistry Errors(Lis t<Registry Error> fro mRegistryE rrors)
  728           {
  729                    List <RegistryE rror> ret  = new Arra yList<Regi stryError> ();
  730  
  731                    for( RegistryEr ror regist ryError :  fromRegist ryErrors)
  732                    {
  733                             ret.ad d(createRe gistryErro r(registry Error));
  734                    }
  735  
  736                    retu rn ret;
  737           }
  738  
  739           pr ivate Regi stryError  createRegi stryError( RegistryEr ror fromRe gistryErro r)
  740           {
  741                    Regi stryError  ret = new  RegistryEr ror();
  742                    ret. setCodeCon text(fromR egistryErr or.getCode Context()) ;
  743                    ret. setErrorCo de(fromReg istryError .getErrorC ode());
  744                    ret. setLocatio n(fromRegi stryError. getLocatio n());
  745                    ret. setSeverit y(fromRegi stryError. getSeverit y());
  746                    ret. setValue(f romRegistr yError.get Value());
  747                    retu rn ret;
  748           }
  749  
  750           pr ivate Resp ondingGate wayCrossGa tewayQuery ResponseTy pe createR espondingG atewayCros sGatewayQu eryRespons eError(Adh ocQueryReq uest fromA dhocQueryR equest)
  751           {
  752                    Resp ondingGate wayCrossGa tewayQuery ResponseTy pe ret = n ew Respond ingGateway CrossGatew ayQueryRes ponseType( );
  753                    Comm unityAdhoc QueryRespo nsesType c ommunityRe sponses =  new Commun ityAdhocQu eryRespons esType();
  754                    ret. setCommuni tyResponse s(communit yResponses );
  755                    comm unityRespo nses.getCo mmunityRes ponse().ad d(createCo mmunityAdh ocQueryRes ponseError (fromAdhoc QueryReque st));
  756                    retu rn ret;
  757           }
  758  
  759           pr ivate Comm unityAdhoc QueryRespo nseType cr eateCommun ityAdhocQu eryRespons eError(Adh ocQueryReq uest fromA dhocQueryR equest)
  760           {
  761                    Comm unityAdhoc QueryRespo nseType re t = new Co mmunityAdh ocQueryRes ponseType( );
  762                    ret. setAdhocQu eryRespons e(createAd hocQueryRe sponseErro r(fromAdho cQueryRequ est));
  763                    ret. setNhinTar getCommuni ty(createD efaultNhin TargetComm unity());
  764                    retu rn ret;
  765           }
  766  
  767           pr ivate Adho cQueryResp onse creat eAdhocQuer yResponseE rror(Adhoc QueryReque st fromAdh ocQueryReq uest)
  768           {
  769                    oasi s.names.tc .ebxml_reg rep.xsd.qu ery._3.Obj ectFactory  objFactor y = new oa sis.names. tc.ebxml_r egrep.xsd. query._3.O bjectFacto ry();
  770                    Adho cQueryResp onse ret =  objFactor y.createAd hocQueryRe sponse();
  771                    ret. setStatus( "urn:oasis :names:tc: ebxml-regr ep:Respons eStatusTyp e:Failure" );
  772                    ret. setRegistr yErrorList (createDef aultRegist ryErrorLis t());
  773                    ret. setRequest Id(fromAdh ocQueryReq uest.getId ());
  774                    retu rn ret;
  775           }
  776  
  777           pr ivate Regi stryErrorL ist create DefaultReg istryError List()
  778           {
  779                    Regi stryErrorL ist ret =  new Regist ryErrorLis t();
  780                    ret. getRegistr yError().a dd(createD efaultRegi stryError( ));
  781                    ret. setHighest Severity(" urn:oasis: names:tc:e bxml-regre p:ErrorSev erityType: Error");
  782                    retu rn ret;
  783           }
  784  
  785           pr ivate Regi stryError  createDefa ultRegistr yError()
  786           {
  787                    Regi stryError  ret = new  RegistryEr ror();
  788                    ret. setErrorCo de("XDSReg istryError ");
  789                    ret. setCodeCon text("Inte rnal Regis try/Reposi tory Error ");
  790                    ret. setSeverit y("urn:oas is:names:t c:ebxml-re grep:Error SeverityTy pe:Error") ;
  791                    retu rn ret;
  792           }
  793  
  794           pr ivate Nhin TargetComm unityType  createDefa ultNhinTar getCommuni ty()
  795           {
  796                    Nhin TargetComm unityType  ret = new  NhinTarget CommunityT ype();
  797                    Home CommunityT ype homeCo mmunity =  new HomeCo mmunityTyp e();
  798                    Faci lity homeF acility =  getHomeFac ility();
  799                    home Community. setHomeCom munityId(h omeFacilit y.getHomeC ommunityId ());
  800                    home Community. setName(ho meFacility .getFacili tyName());
  801                    ret. setHomeCom munity(hom eCommunity );
  802                    retu rn ret;
  803           }
  804  
  805           pu blic List< String> pa rseParamFo rmattedStr ings(List< String> pa ramFormatt edStrings)
  806           {
  807                    List <String> r et = new A rrayList<S tring>();
  808  
  809                    for( String par amFormatte dString :  paramForma ttedString s)
  810                    {
  811                             parseP aramFormat tedString( paramForma ttedString , ret);
  812                    }
  813  
  814                    retu rn ret;
  815           }
  816  
  817           pu blic void  parseParam FormattedS tring(Stri ng paramFo rmattedStr ing, List< String> re sultCollec tion)
  818           {
  819                    if(( paramForma ttedString  != null)  && (result Collection  != null))
  820                    {
  821                             String  working =  paramForm attedStrin g;
  822                             if(par amFormatte dString.st artsWith(" ("))
  823                             {
  824                                      working  = paramFor mattedStri ng.substri ng(1);
  825                                      int endI ndex = wor king.index Of(")");
  826                                      if(endIn dex != -1)
  827                                      {
  828                                               working =  working.su bstring(0,  endIndex) ;
  829                                      }
  830                             }
  831                             String [] multiVa lueString  = working. split(",") ;
  832                             if(mul tiValueStr ing != nul l)
  833                             {
  834                                      for(int  i = 0; i <  multiValu eString.le ngth; i++)
  835                                      {
  836                                               String sin gleValue =  multiValu eString[i] ;
  837                                               if(singleV alue != nu ll)
  838                                               {
  839                                                       si ngleValue  = singleVa lue.trim() ;
  840                                               }
  841                                               if(singleV alue.start sWith("'") )
  842                                               {
  843                                                       si ngleValue  = singleVa lue.substr ing(1);
  844                                                       in t endTickI ndex = sin gleValue.i ndexOf("'" );
  845                                                       if (endTickIn dex != -1)
  846                                                       {
  847                                                                sing leValue =  singleValu e.substrin g(0, endTi ckIndex);
  848                                                       }
  849                                               }
  850                                               resultColl ection.add (singleVal ue);
  851                                      }
  852                             }
  853                    }
  854           }
  855  
  856           pr ivate bool ean checkP olicy(Asse rtionType  assertion)
  857           {
  858                    bool ean ret =  false;
  859  
  860                    if(a ssertion.g etUserInfo () != null  && !NullC hecker.isN ullOrEmpty (assertion .getUserIn fo().getUs erName()))
  861                    {
  862                             Reques tType requ est = Chec kPolicyReq uestBuilde r.buildNHI NOutCheckP olicyReque st(asserti on.getUser Info().get UserName() , getFullH omeCommuni tyId());
  863                             CheckP olicyReque stType che ckPolicyRe quest = ne w CheckPol icyRequest Type();
  864                             checkP olicyReque st.setRequ est(reques t);
  865                             CheckP olicyRespo nseType ch eckPolicyR esponse =  adapterPol icyEngine. checkPolic y(checkPol icyRequest );
  866                             return  CheckPoli cy.checkPo licy(check PolicyRequ est, check PolicyResp onse);
  867                    }
  868  
  869                    retu rn ret;
  870           }
  871  
  872           pr ivate Faci lity getHo meFacility ()
  873           {
  874                    retu rn facilit yManager.g etFacility ByFacility Number("VA ");
  875           }
  876  
  877           pr ivate Stri ng getFull HomeCommun ityId()
  878           {
  879                    Stri ng ret = n ull;
  880                    Faci lity facil ity = faci lityManage r.getFacil ityByFacil ityNumber( "VA");
  881                    if(f acility !=  null)
  882                    {
  883                             ret =  facility.g etFullHome CommunityI d();
  884                    }
  885                    retu rn ret;
  886           }
  887  
  888           pr ivate Stri ng createF ullName(Pe rsonNameTy pe personN ame)
  889           {
  890                    Stri ngBuffer r et = new S tringBuffe r();
  891  
  892                    if(N ullChecker .isNotNull OrEmpty(pe rsonName.g etGivenNam e()))
  893                    {
  894                             ret.ap pend(perso nName.getG ivenName() );
  895                    }
  896  
  897                    if(N ullChecker .isNotNull OrEmpty(pe rsonName.g etSecondNa meOrInitia ls()))
  898                    {
  899                             if(ret .length()  > 0)
  900                             {
  901                                      ret.appe nd(' ');
  902                             }
  903                             ret.ap pend(perso nName.getS econdNameO rInitials( ));
  904                    }
  905  
  906                    if(N ullChecker .isNotNull OrEmpty(pe rsonName.g etFamilyNa me()))
  907                    {
  908                             if(ret .length()  > 0)
  909                             {
  910                                      ret.appe nd(' ');
  911                             }
  912                             ret.ap pend(perso nName.getF amilyName( ));
  913                    }
  914  
  915                    retu rn ret.toS tring();
  916           }
  917   }