20. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 4/5/2017 4:21:44 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

20.1 Files compared

# Location File Last Modified
1 C:\working_scrub\Unredacted\eHX Code Base\eHX_Bld2_Source Code_CIF_2017-02-14\NHIN_adapter\AdapterEJB\src\archive\java\gov\va\med\nhin\adapter\adaptergateway\docquery AdapterGatewayDocQueryBean.java Fri Feb 10 15:41:44 2017 UTC
2 eHX-CIF.zip\eHX-CIF\eHX Code Base\eHX_Bld2_Source Code_CIF_2017-02-14\NHIN_adapter\AdapterEJB\src\archive\java\gov\va\med\nhin\adapter\adaptergateway\docquery AdapterGatewayDocQueryBean.java Mon Apr 3 14:22:50 2017 UTC

20.2 Comparison summary

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