20. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/1/2018 12:13:14 PM Central Standard 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.

20.1 Files compared

# Location File Last Modified
1 ehealth_xchange_cif.zip\NHIN_adapter\AdapterEJB\src\archive\java\gov\va\med\nhin\adapter\adaptergateway\docquery AdapterGatewayDocQueryBean.java Thu Feb 22 14:25:44 2018 UTC
2 ehealth_xchange_cif.zip\NHIN_adapter\AdapterEJB\src\archive\java\gov\va\med\nhin\adapter\adaptergateway\docquery AdapterGatewayDocQueryBean.java Tue Feb 27 14:23:54 2018 UTC

20.2 Comparison summary

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

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

20.4 Active regular expressions

No regular expressions were active.

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