387. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/22/2018 1:29:32 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.

387.1 Files compared

# Location File Last Modified
1 v1603_release_60.zip\CRM_solutions\VCCMResources.zip\WebResources ftp_WebServiceTesterjsWebServiceTesterjs47F629F2-4B57-E711-9450-0050568D743D Tue May 22 14:39:24 2018 UTC
2 v1603_release_60.zip\CRM_solutions\VCCMResources.zip\WebResources ftp_WebServiceTesterjsWebServiceTesterjs47F629F2-4B57-E711-9450-0050568D743D Wed Jun 20 16:38:27 2018 UTC

387.2 Comparison summary

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

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

387.4 Active regular expressions

No regular expressions were active.

387.5 Comparison detail

  1   var mhvPre scriptionT estData =  {"ErrorOcc urred":fal se,"ErrorM essage":nu ll,"Status ":null,"De bugInfo":n ull,"Data" :{"failedS tationList ":"","last UpdatedTim e":"Fri, 1 2 Jan 2018  15:43:01  EST","pres criptionLi st":[{"dis pensedDate ":null,"ex pirationDa te":"Sat,  10 Mar 201 8 00:00:00  EST","fac ilityName" :"DAYT3"," isRefillab le":true," isTrackabl e":false," orderedDat e":"Thu, 0 9 Mar 2017  00:00:00  EST","pres criptionId ":1827565, "prescript ionName":" METHOCARBA MOL 500MG  TAB","pres criptionNu mber":2719 381,"quant ity":1,"re fillDate": "Fri, 24 M ar 2017 00 :00:00 EDT ","refillR emaining": 3,"refillS tatus":"ac tive","ref illSubmitD ate":"Fri,  24 Mar 20 17 16:03:3 0 EDT","st ationNumbe r":994},{" dispensedD ate":null, "expiratio nDate":"Sa t, 10 Mar  2018 00:00 :00 EST"," facilityNa me":"DAYT3 ","isRefil lable":fal se,"isTrac kable":fal se,"ordere dDate":"Th u, 09 Mar  2017 00:00 :00 EST"," prescripti onId":1827 566,"presc riptionNam e":"AMINOP HYLLINE 10 0 MG TAB", "prescript ionNumber" :2719382," quantity": 1,"refillD ate":"Fri,  24 Mar 20 17 00:00:0 0 EDT","re fillRemain ing":3,"re fillStatus ":"submitt ed","refil lSubmitDat e":"Fri, 0 5 Jan 2018  13:21:21  EST","stat ionNumber" :994}]}};
  2   var config Data = nul l,
  3           co ntext = nu ll,
  4           re trievedSet tings = nu ll;
  5   var _ICN =  null,
  6           _n ationalId  = null,
  7           _E DIPI = nul l,
  8           _M HVID = nul l,
  9           _M HVSessionT oken = nul l,
  10           _M HVPrescrip tionList =  [],
  11           _M HVSelected Prescripti onID = nul l,
  12           _f acilityCod eFromMVI =  null,
  13           _f acilityCod eFromMVIDF N = null,
  14           _f acilityCod eFromESR =  null,
  15           _f acilityCod eFromESRDF N = null,
  16           _c urrentSett ing = null ,
  17       _curre ntSettingI sAPI = fal se,
  18       _curre ntSettingI sSecureAPI  = false;
  19   var _stati onList = [ ];
  20   var _userF irstName =  null,
  21           _u serLastNam e = null,
  22           _u serFacilit yCode = nu ll,
  23           _u serIENAtFa cilityCode  = null,
  24       _freeB uilderMode  = false;
  25  
  26   $(document ).ready(fu nction ()  {
  27           co ntext = ge tContext() ;
  28           _I CN = null;
  29           _E DIPI = nul l;
  30           _M HVID = nul l;
  31           _M HVSessionT oken = nul l;
  32           _M HVPrecript ionIDList  = [];
  33           _M HVSelected Prescripti onID = nul l;
  34           _n ationalId  = null;
  35           _f acilityCod eFromMVI =  null;
  36           _f acilityCod eFromMVIDF N = null;
  37           _f acilityCod eFromESR =  null;
  38           _f acilityCod eFromESRDF N = null;
  39           _c urrentSett ing = null ;
  40           _c urrentSett ingIsAPI =  false;
  41       _curre ntSettingI sSecureAPI  = false;
  42           _s tationList  = [];
  43           _u serFirstNa me = null;
  44           _u serLastNam e = null;
  45           _u serFacilit yCode = nu ll;
  46           _u serIENAtFa cilityCode  = null;
  47           co nfigData =  parseData Parameters FromUrl(lo cation.sea rch);
  48           
  49           ge tActiveSet tings();
  50           ge tUserFromC RM();
  51           
  52           $( "#displayf rame").loa d(function (){
  53                    /*$( "#loadingG ifDiv").hi de();
  54                    writ eToConsole ("hide loa dingGifDiv ");*/
  55           }) ;
  56           wi ndow.onscr oll = func tion(){$(" #loadingGi fDiv").css ("top", wi ndow.pageY Offset);}
  57           $( "#loadingG ifDiv").hi de();
  58   });
  59   function c heckSubmit MVI(event)  {
  60           if  (event.ke yCode ===  13) {
  61                    sear chMVI();
  62           }
  63   }
  64   function s earchMVI() {
  65           va r firstNam e = $("#mv iFirstName ").val();
  66           va r lastName  = $("#mvi LastName") .val();
  67           if (!!firstNa me && !!la stName){
  68                    var  ssn = $("# mviSSN").v al();
  69                    var  dobM = $(" #mviDOBMon th").val() ;
  70                    var  dobD = $(" #mviDOBDat e").val();
  71                    var  dobY = $(" #mviDOBYea r").val();
  72                    var  dob = "";
  73                    if(! !dobM && ! !dobD && ! !dobY){
  74                             dob =  dobM + "/"  + dobD +  "/" + dobY ;
  75                    }
  76                    if(! !ssn || !! dob){
  77                             $("#IC N").val("" );
  78                             $("#na tionalId") .val("");
  79                             $("#ed ipi").val( "");
  80                             $("#mh vid").val( "");
  81                             $("#mh vtoken").v al("");
  82                             $("#se lectedMVIF acilityCod e").val("" );
  83                             $("#se lectedMVIF acilityCod eDFN").val ("");
  84                             $("#pr eferredFac ilityCodeF romESR").v al("");
  85                             $("#pr eferredFac ilityCodeF romESRDFN" ).val("");
  86                             
  87                             showLo adingMessa ge("queryi ng MVI for  veteran") ;
  88                             var qu eryString  = "$select =*&$filter =crme_IsAt tended eq  true and c rme_Search Type eq 'S earchByFil ter'";
  89                             queryS tring += "  and crme_ LastName e q '" + las tName + "' ";
  90                             queryS tring += "  and crme_ FirstName  eq '" + fi rstName +  "'";
  91                             queryS tring += ! !ssn ? " a nd crme_SS N eq '" +  ssn + "'"  : "";
  92                             queryS tring += ! !dob ? " a nd crme_DO BString eq  '" + dob  + "'" : "" ;
  93                             var re trievedVet erans = [] ;
  94                             SDK.RE ST.retriev eMultipleR ecords(
  95                                      "crme_pe rson",
  96                                      queryStr ing,
  97                                      function (retrieved Records){
  98                                               if (typeof  retrieved Records !=  "undefine d" && !!re trievedRec ords) retr ievedVeter ans = retr ievedVeter ans.concat (retrieved Records);
  99                                      },
  100                                      errorHan dler,
  101                                      function (){
  102                                               if(retriev edVeterans .length >  0 && retri evedVetera ns[0].crme _ReturnMes sage != "Y our search  in MVI di d not find  any recor ds matchin g the sear ch criteri a."){
  103                                                       if  (retrieve dVeterans[ 0].crme_Ex ceptionOcc ured || (r etrievedVe terans[0]. crme_Retur nMessage ! = null &&  retrievedV eterans[0] .crme_Retu rnMessage  == "An une xpected er ror occure d during t he MVI sea rch. Pleas e try agai n or conta ct your sy stem admin istrator i f the prob lem persis ts.")) {
  104                                                                aler t("Error s earching M VI: \n" +  (!!(retrie vedVeteran s[0].crme_ ExceptionM essage) ?  retrievedV eterans[0] .crme_Exce ptionMessa ge : retri evedVetera ns[0].crme _ReturnMes sage));
  105                                                                $("# loadingGif Div").hide ();
  106                                                                retu rn;
  107                                                       }
  108                                                       $( "#MVISearc hResultsTa ble").html ("<thead>< th></th><t h>Name</th ><th>DOB</ th><th>Sta tions</th> </thead>") ;
  109                                                       va r veteranC ountFromMV I = 0;
  110                                                       fo r (var i =  0; i < re trievedVet erans.leng th; i++) {
  111                                                                vete ranCountFr omMVI++;
  112                                                                var  thisVet =  retrievedV eterans[i] ;
  113                                                                var  vetName =  !!thisVet. crme_FullN ame ? this Vet.crme_F ullName :  thisVet.cr me_FirstNa me + " " +  thisVet.c rme_LastNa me;
  114                                                                var  buttonId =  "btn_" +  thisVet.cr me_ICN;
  115                                                                var  buttonHTML  = "<butto n id='" +   buttonId  + "' oncli ck='select Veteran(th is);'>Sele ct Vet</bu tton>";
  116                                                                var  rowId = "r ow_" + thi sVet.crme_ ICN;
  117                                                                var  stationCel lId = "sta tions_" +  thisVet.cr me_ICN;
  118                                                                var  entryHTML  = "<tr id= ' " + rowI d + "'><td >" +  butt onHTML + " </td><td>"  + vetName  + "</td>< td>" + thi sVet.crme_ DOBString  + "</td><t d id='" +  stationCel lId + "'/> </tr>";
  119                                                                $("# MVISearchR esultsTabl e").append (entryHTML );
  120                                                                $("# " + button Id).attr(" patientMvi Identifier ", thisVet .crme_Pati entMviIden tifier);
  121                                                       }
  122                                                       $( "#loadingG ifDiv").hi de();
  123                                                       if (veteranCo untFromMVI  == 1){
  124                                                                $("# btn_" + re trievedVet erans[0].c rme_ICN).c lick();
  125                                                       }
  126                                               }
  127                                               else{
  128                                                       $( "#loadingG ifDiv").hi de();
  129                                                       // 0 results
  130                                                       al ert("0 vet erans from  MVI.");
  131                                               }
  132                                      }
  133                             );
  134                    }
  135           }
  136   }
  137   function s electVeter an(pButton ){
  138           va r thisICN  = pButton. id.replace ("btn_","" );
  139           if (!!thisICN ){
  140                    $("# ICN").val( thisICN);
  141                    icn_ onChange() ;
  142                    
  143                    var  MVIID = pB utton.getA ttribute(" patientMvi Identifier ");
  144                    if(! !MVIID){
  145                             getSta tions(this ICN, MVIID );
  146                    }
  147           }
  148   }
  149   function g etStations (pICN, pMV IIdentifie r){
  150           sh owLoadingM essage("qu erying MVI  for stati ons");
  151           va r stationC ellId = "s tations_"  + pICN;
  152           $( "#" + stat ionCellId) .html("");
  153           va r retrieve dStations  = [];
  154           va r queryStr ing = "$se lect=*&$fi lter=crme_ PatientMvi Identifier  eq '" + p MVIIdentif ier + "' a nd crme_Se archType e q 'Selecte dPersonSea rch'";
  155           qu eryString  += "and cr me_ICN eq  '" + pICN  + "'";
  156           SD K.REST.ret rieveMulti pleRecords (
  157                    "crm e_person",
  158                    quer yString,
  159                    func tion(retri evedRecord s){
  160                             if (ty peof retri evedRecord s != "unde fined" &&  !!retrieve dRecords)  retrievedS tations =  retrievedS tations.co ncat(retri evedRecord s);
  161                    },
  162                    erro rHandler,
  163                    func tion () {
  164                             if(ret rievedStat ions.lengt h > 0){
  165                                      _station List = [];
  166                                      _station List = _st ationList. concat(ret rievedStat ions);
  167                                      //getPre ferredFaci lityFromES R(pICN);
  168                                      getPrefe rredFacili tyFromSecu reESR(pICN );
  169                                      var stat ionCount =  0;
  170                                      for(var  i = 0; i <  retrieved Stations.l ength; i++ ){
  171                                               var thisSt ation = re trievedSta tions[i];
  172                                               if(!!thisS tation.crm e_SiteId){
  173                                                       va r facility Code = thi sStation.c rme_SiteId ;
  174                                                       va r identifi erAtThisSt ation = th isStation. crme_Patie ntId;
  175                                                       if  (facility Code == "2 00DOD") {
  176                                                                //20 0DOD conta ins EDIPI  value
  177                                                                $("# edipi").va l(identifi erAtThisSt ation);
  178                                                                edip i_onChange (false);
  179                                                       }
  180                                                       if (facilityC ode == "20 0MHI"){
  181                                                                //20 0MHI conta ins MHV ID  value
  182                                                                $("# mhvid").va l(identifi erAtThisSt ation);
  183                                                                mhvi d_onChange (false);
  184                                                       }
  185                                                       if (containsO nlyNumbers (facilityC ode)){
  186                                                                stat ionCount++ ;
  187                                                                var  stationNam e = thisSt ation.crme _SiteName. split("&") [0];
  188                                                                var  stationLis tEntry = ( (stationCo unt > 1 ?  ",<br/>" :  "") + "<a  id='stati on_" + fac ilityCode  + "' href= '#' onclic k='selectF acility(th is);' titl e='pick'>"  + station Name + "</ a>");
  189                                                                $("# " + statio nCellId).a ppend(stat ionListEnt ry);
  190                                                                $("# station_"  + facility Code).attr ("DFN", id entifierAt ThisStatio n);
  191                                                       }
  192                                               }
  193                                      }
  194                                      $("#load ingGifDiv" ).hide();
  195                             }
  196                             else{
  197                                      $("#load ingGifDiv" ).hide();
  198                                      alert("0  stations  from MVI") ;
  199                             }
  200                    }
  201           );
  202   }
  203   function g etPreferre dFacilityF romESR(pIC N) {
  204       //depr ecated in  favor of g etPreferre dFacilityF romSecureE SR();
  205       return ;
  206           $( "#preferre dFacilityC odeFromESR ").val("lo ading...") ;
  207           if (!!retriev edSettings  && !!retr ievedSetti ngs.ftp_ES RAPIURL){
  208                    var  esrJsonUrl  = retriev edSettings .ftp_ESRAP IURL.repla ce("xml",  "json");
  209                    var  esrURL = r etrievedSe ttings.ftp _DACURL +  esrJsonUrl  + "000000 " + _ICN +  "000000";
  210                    //qu ery ESR us ing jquery
  211                    jQue ry.support .cors = tr ue;
  212                    $.aj ax({
  213                             type:  "GET",
  214                             conten tType: "ap plication/ json; char set=utf-8" ,
  215                             dataty pe: "json" ,
  216                             url: e srURL,
  217                             before Send: func tion (XMLH ttpRequest ) {
  218                                      //Specif ying this  header ens ures that  the result s will be  returned a s JSON.
  219                                      //XMLHtt pRequest.s etRequestH eader("Acc ept", "app lication/j son");
  220                             },
  221                             succes s: functio n (respons e, textSta tus, XmlHt tpRequest)  {
  222                                      writeToC onsole("in side ESR q uery succe ss callbac k");
  223                                      var pref erredFacil ity = getD eepPropert y("SOAP-EN V:Envelope .SOAP-ENV: Body.getEE SummaryRes ponse.summ ary.demogr aphics.pre ferredFaci lity", res ponse);
  224                                      var faci lityCodeFr omESR = pr eferredFac ility.spli t("-")[0]. trim();
  225                                      $("#pref erredFacil ityCodeFro mESR").val (facilityC odeFromESR );
  226                                      preferre dFacilityC odeFromESR _onChange( );
  227                                      
  228                                      if(_stat ionList.le ngth > 0){
  229                                               for(var i  = 0; i < _ stationLis t.length;  i++){
  230                                                       if (_stationL ist[i].crm e_SiteId = = facility CodeFromES R){
  231                                                                $("# preferredF acilityCod eFromESRDF N").val(_s tationList [i].crme_P atientId);
  232                                                                pref erredFacil ityCodeFro mESRDFN_on Change();
  233                                                                brea k;
  234                                                       }
  235                                               }
  236                                      }
  237                             },
  238                             error:  function  (XMLHttpRe quest, tex tStatus, e rrorThrown ) {
  239                                      writeToC onsole("Er ror queryi ng ESR: "  + errorThr own + ".",  XMLHttpRe quest.resp onseText,  "Error que rying ESR  for vetera n data");
  240                                      //setTim eout(query ESR, 2000) ;
  241                                      $("#pref erredFacil ityCodeFro mESR").val ("error in  query");
  242                             },
  243                             async:  true,/*ch anged 6/9/ 17*/
  244                             cache:  false
  245                    });
  246           }
  247   }
  248   function g etPreferre dFacilityF romSecureE SR(pICN) {
  249       $("#pr eferredFac ilityCodeF romESR").v al("loadin g...");
  250       if (!! retrievedS ettings &&  !!retriev edSettings .ftp_ESREn rollmentEl igibilityS ummaryAPIU RL) {
  251           va r secureES RURL = ret rievedSett ings.ftp_D ACURL + re trievedSet tings.ftp_ ESREnrollm entEligibi litySummar yAPIURL;
  252           va r secureES RParams =  [{ key: "i dentifier" , type: "c :string",  value: JSO N.stringif y({ Nation alId: "000 000" + _IC N + "00000 0" }) }];
  253           Cr mSecurityT okenEncryp tion(
  254                secureES RURL,
  255                secureES RParams,
  256                context. getClientU rl(),
  257                function  (pError,  pResponse)  {
  258                    writ eToConsole ("inside E SR query s uccess cal lback");
  259                    var  preferredF acility =  getDeepPro perty("Dat a.Demograp hics.Prefe rredFacili ty", pResp onse);
  260                    if ( preferredF acility !=  undefined ) {
  261                         var facili tyCodeFrom ESR = pref erredFacil ity.split( "-")[0].tr im();
  262                         $("#prefer redFacilit yCodeFromE SR").val(f acilityCod eFromESR);
  263                         preferredF acilityCod eFromESR_o nChange();
  264  
  265                         if (_stati onList.len gth > 0) {
  266                             for (v ar i = 0;  i < _stati onList.len gth; i++)  {
  267                                 if  (_station List[i].cr me_SiteId  == facilit yCodeFromE SR) {
  268                                      $("#pref erredFacil ityCodeFro mESRDFN"). val(_stati onList[i]. crme_Patie ntId);
  269                                      preferre dFacilityC odeFromESR DFN_onChan ge();
  270                                      break;
  271                                 }
  272                             }
  273                         }
  274                    }
  275                }
  276           );
  277       }
  278   }
  279   function s electFacil ity(pEleme nt){
  280           va r facility Code = pEl ement.id.r eplace("st ation_", " ");
  281           $( "#selected MVIFacilit yCode").va l(facility Code);
  282           se lectedMVIF acilityCod e_onChange ();
  283           
  284           va r dfn = pE lement.get Attribute( "DFN");
  285           $( "#selected MVIFacilit yCodeDFN") .val(dfn);
  286           se lectedMVIF acilityCod eDFN_onCha nge();
  287   }
  288   function p opStationL ist(){
  289           va r msg = "S tations an d Correlat ing IDs:\n \n";
  290           _s tationList .forEach(f unction(s,  i){msg +=  "site: "  + s.crme_S iteId + "  | patienti d: " + s.c rme_Patien tId + "\n\ n";});
  291           al ert(msg);
  292   }
  293   function g etMHVToken (){
  294           $( "#btn_getM HVToken"). attr("disa bled", "di sabled")
  295           $( "#mhvtoken ").val("") ;
  296           $( "#mhvtoken ").attr("p laceholder ", "queryi ng API..." );
  297           va r dacURL =  $("#ftp_D ACURL_sett ing").val( );
  298           va r apiURL =  $("#ftp_M HVSessionA PIURL_sett ing").val( );
  299           va r mhvID =  _MHVID;
  300           va r fullUrl  = dacURL +  apiURL +  "/" + _MHV ID + "/jso n";
  301           va r dType =  fullUrl.to LowerCase( ).indexOf( "json") >  -1 ? "json " : "text" ;
  302           va r cType =  dType == " json" ? "a pplication /json; cha rset=utf-8 " : "chars et=utf-8";
  303           $. ajax({
  304                    type : "GET",
  305                    cont entType: c Type,
  306                    data type: dTyp e,
  307                    url:  fullUrl,
  308                    befo reSend: fu nction (XM LHttpReque st) {
  309                             //Spec ifying thi s header e nsures tha t the resu lts will b e returned  as JSON.
  310                             if (dT ype == "js on") XMLHt tpRequest. setRequest Header("Ac cept", "ap plication/ json");
  311                    },
  312                    succ ess: funct ion (pResp onse, text Status, Xm lHttpReque st) {
  313                         if (!!pRes ponse) {
  314                                      $("#mhvt oken").val (getDeepPr operty("Da ta[0].Toke n", pRespo nse));
  315                                      mhvtoken _onChange( false);
  316                                      $("#btn_ getMHVToke n").remove Attr("disa bled");
  317                                      $("#mhvt oken").att r("placeho lder", "MH V Token go es here");
  318                             }
  319                    },
  320                    erro r: functio n (XMLHttp Request, t extStatus,  errorThro wn) {
  321                             $("#mh vtoken").v al("error! ");
  322                             mhvtok en_onChang e(false);
  323                             $("#bt n_getMHVTo ken").remo veAttr("di sabled");
  324                             $("#mh vtoken").a ttr("place holder", " MHV Token  goes here" );
  325                    },
  326                    asyn c: true,
  327                    cach e: false
  328           }) ;
  329   }
  330  
  331   function g etActiveSe ttings(){
  332           va r queryStr ing = "$se lect=*&$fi lter=mcs_n ame eq 'Ac tive Setti ngs'";
  333           SD K.REST.ret rieveMulti pleRecords (
  334                    "mcs _setting",
  335                    quer yString,
  336                    func tion (retr ievedRecor ds) {
  337                             if (ty peof retri evedRecord s != "unde fined" &&  !!retrieve dRecords & & retrieve dRecords.l ength == 1 ) retrieve dSettings  = retrieve dRecords[0 ];
  338                    },
  339                    erro rHandler,
  340                    func tion () {
  341                             if (!! retrievedS ettings) {
  342                                      $("#retr ievedSetti ngsContain er h2").ht ml("Active  Settings,  last modi fied on "  + retrieve dSettings. ModifiedOn .toLocaleS tring());
  343                                      
  344                                      $("#retr ievedSetti ngsTable") .html("");
  345                                      $("#retr ievedSetti ngsTable") .append("< tr><td/><t d>Setting< /td><td>Co nfigured V alue</td>" );
  346                                      Object.k eys(retrie vedSetting s).sort(). forEach(fu nction(pro p,i){
  347                                               if((prop.i ndexOf("ft p_") > -1  || prop.in dexOf("vre _") > -1 | | prop.ind exOf("bah_ ") > -1) & & prop.ind exOf("mcs_ setting_")  == -1 &&  prop.index Of("_mcs_s etting") = = -1){
  348                                                       co nsole.log( prop + " ( " + typeof  retrieved Settings[p rop] + "):  " + retri evedSettin gs[prop]);
  349                                                       va r entryHTM L = "<tr>"
  350                                                       +  "<td><butt on id='btn _" + prop  + "' title ='Test' on click='set upQueryBui lder(this, true)'>Tes t</button> </td>"
  351                                                       +  "<td>" + p rop + " ["  + typeof  retrievedS ettings[pr op] + "]</ td>"
  352                                                       +  "<td class ='autoWidt h'><input  class='aut oWidth' ty pe='text'  id='" + pr op + "_set ting' valu e='" + ret rievedSett ings[prop]  + "'></td >"
  353                                                       +  "</tr>";
  354                                                       $( "#retrieve dSettingsT able").app end(entryH TML);
  355                                               }
  356                                      });
  357                             } //en d if !!ret rievedSett ings                            
  358                    }
  359           );
  360   }
  361   function s etupImpers onation(){
  362           // retrieveVi staUsers(" Lori", "Ni cholls", " 613", fals e);
  363           $( "#userFirs tName").va l("Lori");
  364           us erFirstNam e_onChange (false);
  365           $( "#userLast Name").val ("Nicholls ");
  366           us erLastName _onChange( false);
  367           $( "#userFaci lityCode") .val("613" );
  368           us erFacility Code_onCha nge(true);
  369           re trieveVist aUsers();
  370   }
  371   function g etUserFrom CRM(){
  372           SD K.REST.ret rieveRecor d(
  373                    cont ext.getUse rId(),
  374                    "Sys temUser",
  375                    "Fir stName,Las tName,ftp_ ftp_facili ty_systemu ser/ftp_fa cilitycode ",
  376                    "ftp _ftp_facil ity_system user",
  377                    func tion(retri evedUser){
  378                             if(ret rievedUser .hasOwnPro perty("ftp _ftp_facil ity_system user") &&  !!retrieve dUser.ftp_ ftp_facili ty_systemu ser && ret rievedUser .ftp_ftp_f acility_sy stemuser.h asOwnPrope rty("ftp_f acilitycod e") && ret rievedUser .hasOwnPro perty("Fir stName") & & !!retrie vedUser.Fi rstName &&  retrieved User.hasOw nProperty( "LastName" ) && !!ret rievedUser .LastName) {
  379                                      $("#user FirstName" ).val(retr ievedUser. FirstName) ;
  380                                      userFirs tName_onCh ange(false );
  381                                      $("#user LastName") .val(retri evedUser.L astName);
  382                                      userLast Name_onCha nge(false) ;
  383                                      $("#user FacilityCo de").val(r etrievedUs er.ftp_ftp _facility_ systemuser .ftp_facil itycode);
  384                                      userFaci lityCode_o nChange(tr ue);
  385                                      
  386                                      //retrie veVistaUse rs(retriev edUser.Fir stName, re trievedUse r.LastName , retrieve dUser.ftp_ ftp_facili ty_systemu ser.ftp_fa cilitycode , false);
  387                             }
  388                             else{
  389                                      //showEr rorMessage ("Your CRM  user reco rd is miss ing some i nformation .", "Make  sure it ha s your fir st name, l ast name,  and a desi gnated Sit e. The ide ntified Si te should  in turn ha ve a value  for Facil ity Code",  "Configur ation Erro r");
  390                             }
  391                    },
  392                    erro rHandler
  393           );
  394   }
  395  
  396   function r etrieveVis taUsers()  {
  397           $( "#vistaUse rsListForm Container" ).hide();
  398           va r dacURL =  $("#ftp_D ACURL_sett ing").val( );
  399           va r vistaUrl  = $("#ftp _VistaUser sAPIURL_se tting").va l();
  400           if (!!dacURL  && !!vista Url && !!_ userFirstN ame && !!_ userLastNa me && !!_u serFacilit yCode){
  401                    var  fullUrl =  dacURL + v istaUrl +  _userFirst Name + "/"  + _userLa stName + " /" + _user FacilityCo de;
  402                    show LoadingMes sage("Look ing up you r IEN in V istA...");
  403                    var  filter = $ ("#ftp_Fil ter_settin g").val(). replace("t rue", "fal se");
  404                    try  {
  405                             $.ajax ({
  406                                      type: "G ET",
  407                                      url: ful lUrl,
  408                                      
  409                                       //https:// URL /WebParts/ DEV/api/Vi staUsers/1 .0/json/Ft PCRM/kyle/ knab/991
  410                                      contentT ype: "appl ication/js on; charse t=utf-8",
  411                                      dataType : "json",
  412                                      success:  function  (response)  {
  413                                               if(respons e.hasOwnPr operty("Da ta") && !! response.D ata && res ponse.Data .length >  0){
  414                                                       va r retrieve dVistaUser s = respon se.Data;
  415                                                       if  (retrieve dVistaUser s.length >  1) {
  416                                                                //sh ow selecti on of Vist A users, t hen post t o HDR usin g IEN of s election
  417                                                                rend erVistAMul tipleUsers AsButtons( retrievedV istaUsers) ;
  418                                                       }
  419                                                       el se {
  420                                                                //po st to HDR  using the  first Vist A record
  421                                                                btn_ vistaSelec t_click($( "<div user IEN=\"" +  retrievedV istaUsers[ 0].Ien + " \"></div>" ));
  422                                                       }
  423                                               }
  424                                               else{
  425                                                       va r debugMes sage = "Se arch crite ria: \nFir st Name: "  + _userFi rstName +  "\nLast Na me: " + _u serLastNam e + "\nFac ility Code : " + _use rFacilityC ode;
  426                                                       if (response. hasOwnProp erty("Debu gInfo")) d ebugMessag e += "<br/ >DebugInfo :<br/>" +  response.D ebugInfo;
  427                                                       al ert("Could  not find  your corre sponding u ser in Vis tA. VistA  may be dow n at the m oment...."  + debugMe ssage);
  428                                                       $( "#loadingG ifDiv").hi de()
  429                                               }
  430                                      },
  431                                      error: f unction (j qXHR, text Status, er rorThrown)  {
  432                                               alert("Cou ld not fin d your cor responding  user in V istA... "  + errorThr own);
  433                                               $("#loadin gGifDiv"). hide()
  434                                      },
  435                                      async: t rue,
  436                                      cache: f alse
  437                             });
  438                    }
  439                    catc h (err) {
  440                             alert( "Error ret rieving Vi stA user(s ): " +  er r.message) ;
  441                             $("#lo adingGifDi v").hide()
  442                    }
  443           }
  444   }
  445   function r enderVistA MultipleUs ersAsButto ns(pVistaU sers){
  446           $( "#vistaUse rsListForm Container" ).html("<b r/><p>Vist A returned  multiple  users; sel ect the co rrect one  that repre sents YOU. </p>");
  447           if (!!pVistaU sers){
  448                    for( var u = 0;  u < pVist aUsers.len gth; u++){
  449                             var th isVistaUse r = pVista Users[u];
  450                             var ne wButton =  $("<button  tabindex= \"" + u +" \" class=\ "ms-crm-Re freshDialo g-Button\"  style=\"m argin-left : 8px;\" o nclick=\"b tn_vistaSe lect_click (this)\" t ype=\"butt on\">SELEC T</button> ");
  451                             var ne wLabelHTML  = $("<lab el id=\"vi staUserLab el" + u +  "\">" + th isVistaUse r.DisplayN ame +": "  + thisVist aUser.Titl e + "</lab el><br/>") ;
  452                             $(newB utton).att r("userIEN ", thisVis taUser.Ien );
  453                             $("#vi staUsersLi stFormCont ainer").ap pend(newBu tton);
  454                             $("#vi staUsersLi stFormCont ainer").ap pend(newLa belHTML);
  455                    }
  456                    $("# vistaUsers ListFormCo ntainer"). show();
  457                    $("# loadingGif Div").hide ()
  458           }
  459   }
  460   function b tn_vistaSe lect_click (pObject){
  461           // this funct ion is ent ered by th e user sel ecting a V istA user  record, or  automatic ally when  VistA only  returns 1  user reco rd
  462           wr iteToConso le("inside  btn_vista Select_cli ck()");
  463           $( "#userIEN" ).val($(pO bject).att r("userIEN "));
  464           us erIEN_onCh ange();
  465           $( "#loadingG ifDiv").hi de()
  466   }
  467  
  468   function s etupQueryB uilder(pNe wSetting,  pFocus) {
  469       //mode  switch
  470       _freeB uilderMode  = $("inpu t[name=url BuilderMod eSelection ]:checked" ).val() ==  "free" ?  true : fal se;
  471       if (_f reeBuilder Mode) {
  472           $( "#facility SelectionD iv").hide( );
  473           $( "#userFaci lityInfo") .hide();
  474           $( "#secureAP IIntegrati onParamete rsTableCon tainer").h tml("");
  475           $( "#secureAP IIntegrati onParamete rsTableCon tainer").h ide();
  476           $( "#secureAP IIntegrati onParamete rsStringif iedContain er").hide( );
  477           $( "#postAPII ntegration Parameters TableConta iner").htm l("");
  478           $( "#postAPII ntegration Parameters TableConta iner").hid e();
  479           $( "#postAPII ntegration Parameters Stringifie dContainer ").hide();
  480  
  481           $( "#postData ObjectBuil der").html (
  482                "<button  id='postD ataTableAd dRowButton ' onclick= 'postDataT ableAddRow Button_onC lick()'>Ad d post dat a property </button>"  +
  483                    "<ta ble id='po stDataTabl e'>" +
  484                         "<thead>"  +
  485                             "<tr>"  +
  486                                 "< th>Name</t h>" +
  487                                 "< th>Value</ th>" +
  488                             "</tr> " +
  489                         "</thead>"  +
  490                         "<tbody>"  +
  491                             "<tr>"  +
  492                                 "< td><input  type='text ' id='post APIParamIn putLabel_F ormat' cla ss='postAP IParamInpu tLabel' va lue='Forma t' onchang e='postAPI ParamInput Label_onCh ange(this) ;'/></td>"  +
  493                                 "< td><input  type='text ' id='post APIParamIn put_Format ' class='p ostAPIPara mInput' va lue='json' /></td>" +
  494                             "</tr> " +
  495                         "</tbody>"  +
  496                    "</t able>"
  497           );
  498           $( "#postData ObjectBuil der").show ();
  499       }
  500       else {
  501           $( "#postData ObjectBuil der").hide ();
  502           $( "#postData ObjectBuil der").html (
  503                "<button  id='postD ataTableAd dRowButton ' onclick= 'postDataT ableAddRow Button_onC lick()'>Ad d post dat a property </button>"  +
  504                    "<ta ble id='po stDataTabl e'>" +
  505                         "<thead>"  +
  506                             "<tr>"  +
  507                                 "< th>Name</t h>" +
  508                                 "< th>Value</ th>" +
  509                             "</tr> " +
  510                         "</thead>"  +
  511                         "<tbody>"  +
  512                             "<tr>"  +
  513                                 "< td><input  type='text ' id='post APIParamIn putLabel_F ormat' cla ss='postAP IParamInpu tLabel' va lue='Forma t' onchang e='postAPI ParamInput Label_onCh ange(this) ;'/></td>"  +
  514                                 "< td><input  type='text ' id='post APIParamIn put_Format ' class='p ostAPIPara mInput' va lue='json' /></td>" +
  515                             "</tr> " +
  516                         "</tbody>"  +
  517                    "</t able>"
  518           );
  519           $( "#facility SelectionD iv").hide( );
  520           $( "#userFaci lityInfo") .hide();
  521           $( "#secureAP IIntegrati onParamete rsTableCon tainer").h tml("");
  522           $( "#postAPII ntegration Parameters TableConta iner").htm l("");
  523           _c urrentSett ing = (!!p NewSetting  && pNewSe tting.id ! = "") ? pN ewSetting. id.substr( 4) : _curr entSetting ;
  524           if  (!!!_curr entSetting ) {
  525                $("#urlT oTest").va l("select  a setting  from the l ist above" );
  526                return;
  527           }
  528           $( "#queryBui lderCurren tSettingLa bel").html (_currentS etting);
  529           $( "#queryBui lderCurren tSettingLa bel").show ();
  530           va r settingV alue = $(" #" + _curr entSetting  + "_setti ng").val() ;
  531           _c urrentSett ingIsAPI =  settingVa lue.toLowe rCase().in dexOf("api ") > -1 ||  _currentS etting ==  "ftp_MHVSe ssionAPIUR L";
  532           _c urrentSett ingIsSecur eAPI = _cu rrentSetti ngIsAPI &&  (settingV alue.toLow erCase().i ndexOf("2. 0/json") >  -1 || set tingValue. toLowerCas e().indexO f("2.0/xml ") > -1);
  533           _c urrentSett ingIsPOSTA PI = _curr entSetting IsAPI && [ "ftp_MHVAc tivePrescr iptionAPIU RL", "ftp_ MHVTrackin gAPIURL",  "ftp_MHVRe fillAPIURL ", "ftp_MH VRegistrat ionAPIURL" ].indexOf( _currentSe tting) > - 1;
  534  
  535           if  (_current SettingIsS ecureAPI)  {
  536                $("#secu reAPIInteg rationPara metersTabl eContainer ").show();
  537                $("#secu reAPIInteg rationPara metersStri ngifiedCon tainer").s how();
  538           }
  539           el se {
  540                $("#secu reAPIInteg rationPara metersTabl eContainer ").hide();
  541                $("#secu reAPIInteg rationPara metersStri ngifiedCon tainer").h ide();
  542           }
  543  
  544           if  (_current SettingIsP OSTAPI) {
  545                $("#post APIIntegra tionParame tersTableC ontainer") .show();
  546                $("#post APIIntegra tionParame tersString ifiedConta iner").sho w();
  547           }
  548           el se {
  549                $("#post APIIntegra tionParame tersTableC ontainer") .hide();
  550                $("#post APIIntegra tionParame tersString ifiedConta iner").hid e();
  551           }
  552  
  553           va r useMVISe lectedFaci lity = $(" input[name =facilityS election]: checked"). val() == " mvi" ? tru e : false;
  554           va r selected VeteranFac ilityCode  = useMVISe lectedFaci lity ? _fa cilityCode FromMVI :  _facilityC odeFromESR ;
  555           se lectedVete ranFacilit yCode = !! selectedVe teranFacil ityCode ?  selectedVe teranFacil ityCode :  "[[FACILIT YCODE]]";
  556           va r selected VeteranDFN  = useMVIS electedFac ility ? _f acilityCod eFromMVIDF N : _facil ityCodeFro mESRDFN;
  557           se lectedVete ranDFN = ! !selectedV eteranDFN  ? selected VeteranDFN  : "[[DFN] ]";
  558  
  559           va r fullUrl  = "";
  560           va r dacURL =  $("#ftp_D ACURL_sett ing").val( );
  561           va r filter =  $("#ftp_F ilter_sett ing").val( );
  562  
  563           // reveal ser vice-speci fic fields
  564           sw itch (_cur rentSettin g) {
  565                case "ft p_ESRAPIUR L":
  566                    full Url = dacU RL + setti ngValue +  "000000" +  _ICN + "0 00000";
  567                    brea k;
  568                case "ft p_ESREnrol lmentEligi bilitySumm aryAPIURL" :
  569                    full Url = dacU RL + setti ngValue;
  570                    $("# secureAPII ntegration Parameters TableConta iner").app end($(
  571                         "<table id ='secureAP IIntegrati onParamete rsTable_"  + _current Setting +  "'>" +
  572                             "<tr i d='secureA PIParam_Na tionalId'> " +
  573                                 "< td>Nationa lId</td>"  +
  574                                 "< td><input  type='text ' id='secu reAPIParam Input_Nati onalId' cl ass='secur eAPIParamI nput' valu e='" + _IC N + "'/></ td>" +
  575                             "</tr> " +
  576                         "</table>"
  577                         )
  578                    );
  579                    brea k;
  580                case "ft p_PatientS ummaryAPIU RL":
  581                    $("# facilitySe lectionDiv ").show();
  582                    if ( !_currentS ettingIsSe cureAPI) {
  583                         fullUrl =  dacURL + s ettingValu e + select edVeteranF acilityCod e + "/" +  _ICN + "?i dType=ICN" ;
  584                    }
  585                    else  {
  586                         fullUrl =  dacURL + s ettingValu e;
  587                         $("#secure APIIntegra tionParame tersTableC ontainer") .append($(
  588                             "<tabl e id='secu reAPIInteg rationPara metersTabl e_" + _cur rentSettin g + "'>" +
  589                                 "< tr id='sec ureAPIPara m_stationN umber'>" +
  590                                      "<td>sta tionNumber </td>" +
  591                                      "<td><in put type=' text' id=' secureAPIP aramInput_ stationNum ber' class ='secureAP IParamInpu t' value=' " + select edVeteranF acilityCod e + "'/></ td>" +
  592                                 "< /tr>" +
  593                                 "< tr id='sec ureAPIPara m_stationD FN'>" +
  594                                      "<td>Vet eran DFN a t selected  station</ td>" +
  595                                      "<td><in put type=' text' id=' secureAPIP aramInput_ dfnNum' cl ass='secur eAPIParamI nput' valu e='" + sel ectedVeter anDFN + "' /></td>" +
  596                                 "< /tr>" +
  597                             "</tab le>"
  598                             )
  599                         );
  600                    }
  601                    brea k;
  602                case "ft p_FlagsAPI URL":
  603                    full Url = dacU RL + setti ngValue +  _nationalI d;
  604                    brea k;
  605                case "ft p_Sensitiv ePatientAP IURL":
  606                    $("# facilitySe lectionDiv ").show();
  607                    $("# userFacili tyInfo").s how();
  608                    $("# btn_getVis taUsers"). show();
  609                    $("# vistaUsers ListFormCo ntainer"). show();
  610                    $("# userIENDiv ").show();
  611                    var  ien = _use rIENAtFaci lityCode;
  612                    full Url = dacU RL + setti ngValue +  ien + "/US VHA/" + df n + "/" +  facilityCo de;
  613                    brea k;
  614                case "ft p_VistaUse rsAPIURL":
  615                    $("# userFacili tyInfo").s how();
  616                    $("# btn_getVis taUsers"). hide();
  617                    $("# vistaUsers ListFormCo ntainer"). hide();
  618                    $("# userIENDiv ").hide();
  619                    full Url = dacU RL + setti ngValue +  _userFirst Name + "/"  + _userLa stName + " /" + _user FacilityCo de;
  620                    brea k;
  621                case "ft p_MHVSessi onAPIURL":
  622                    full Url = dacU RL + setti ngValue +  "/" + _MHV ID + "/jso n";
  623                    brea k;
  624                case "ft p_MHVActiv ePrescript ionAPIURL" :
  625                    full Url = dacU RL + setti ngValue;
  626                    $("# postAPIInt egrationPa rametersTa bleContain er").appen d($(
  627                         "<table id ='postAPII ntegration Parameters Table_" +  _currentSe tting + "' >" +
  628                             "<tr i d='postAPI Param_MHVS essionToke n'>" +
  629                                 "< td>MHV Ses sion Token </td>" +
  630                                 "< td><input  type='text ' id='post APIParamIn put_token'  class='po stAPIParam Input' val ue='" + _M HVSessionT oken + "'/ ></td>" +
  631                             "</tr> " +
  632                             "<tr i d='postAPI Param_form at'>" +
  633                                 "< td>format< /td>" +
  634                                 "< td><input  type='text ' id='post APIParamIn put_format ' class='p ostAPIPara mInput' va lue='json' /></td>" +
  635                             "</tr> " +
  636                         "</table>"
  637                         )
  638                    );
  639                    brea k;
  640                case "ft p_MHVTrack ingAPIURL" :
  641                    full Url = dacU RL + setti ngValue;
  642                    var  trackingAP IRadios =  "";
  643                    _MHV Prescripti onList.for Each(funct ion (thisP rescriptio n, i) {
  644                         var prescr iptionId =  getDeepPr operty("pr escription Id", thisP rescriptio n);
  645                         var prescr iptionName  = getDeep Property(" prescripti onName", t hisPrescri ption);
  646                         var elemen tId = pres criptionId  + prescri ptionName;
  647                         trackingAP IRadios +=  "<input i d='" + ele mentId + " ' name='pr escription Selection'  type='rad io' value= '" + presc riptionId  + "' check ed onchang e='prescri ptionSelec ted(this)' /><label f or='" + el ementId +  "'>" + pre scriptionN ame + "</l abel><br/> ";
  648                    });
  649  
  650                    $("# postAPIInt egrationPa rametersTa bleContain er").appen d($(
  651                         "<table id ='postAPII ntegration Parameters Table_" +  _currentSe tting + "' >" +
  652                             "<tr i d='postAPI Param_MHVS essionToke n'>" +
  653                                 "< td>MHV Ses sion Token </td>" +
  654                                 "< td><input  type='text ' id='post APIParamIn put_token'  class='po stAPIParam Input' val ue='" + _M HVSessionT oken + "'/ ></td>" +
  655                             "</tr> " +
  656                             "<tr i d='postAPI Param_form at'>" +
  657                                 "< td>format< /td>" +
  658                                 "< td><input  type='text ' id='post APIParamIn put_format ' class='p ostAPIPara mInput' va lue='json' /></td>" +
  659                             "</tr> " +
  660                             "<tr i d='postAPI Param_MHVP rescriptio nID'>" +
  661                                 "< td>MHV Pre scription  ID</td>" +
  662                                 "< td><input  type='text ' id='post APIParamIn put_rxid'  class='pos tAPIParamI nput' valu e='" + _MH VSelectedP rescriptio nID + "'/> </td>" +
  663                             "</tr> " +
  664                             "<tr i d='postAPI Param_MHVR efillPresc riptionPic kerRow'>"  +
  665                                 "< td>MHV Pre scription  ID Picker< /td>" +
  666                                 // insert tab le cell wi th radio b utton sele ction for  prescripti on IDs in  _MHVPrecri ptionIDLis t array
  667                                 "< td>" + tra ckingAPIRa dios + "</ td>" +
  668                             "</tr> " +
  669                         "</table>"
  670                         )
  671                    );
  672                    brea k;
  673                case "ft p_MHVRefil lAPIURL":
  674                    full Url = dacU RL + setti ngValue;
  675                    var  trackingAP IRadios =  "";
  676                    _MHV Prescripti onList.for Each(funct ion (thisP rescriptio n, i) {
  677                         var prescr iptionId =  getDeepPr operty("pr escription Id", thisP rescriptio n);
  678                         var prescr iptionName  = getDeep Property(" prescripti onName", t hisPrescri ption);
  679                         var elemen tId = pres criptionId  + prescri ptionName;
  680                         var toolti p = "<pre> " + JSON.s tringify(t hisPrescri ption, und efined, 2)  + "</pre> ";
  681                         trackingAP IRadios +=  "<input i d='" + ele mentId + " ' name='pr escription Selection'  type='rad io' value= '" + presc riptionId  + "' check ed onchang e='prescri ptionSelec ted(this)' /><label f or='" + el ementId +  "' tooltip ='" + tool tip + "'>"  + prescri ptionName  + "</label ><br/>";
  682                    });
  683                    $("# postAPIInt egrationPa rametersTa bleContain er").appen d($(
  684                         "<table id ='postAPII ntegration Parameters Table_" +  _currentSe tting + "' >" +
  685                             "<tr i d='postAPI Param_MHVS essionToke n'>" +
  686                                 "< td>MHV Ses sion Token </td>" +
  687                                 "< td><input  type='text ' id='post APIParamIn put_token'  class='po stAPIParam Input' val ue='" + _M HVSessionT oken + "'/ ></td>" +
  688                             "</tr> " +
  689                             "<tr i d='postAPI Param_form at'>" +
  690                                 "< td>format< /td>" +
  691                                 "< td><input  type='text ' id='post APIParamIn put_format ' class='p ostAPIPara mInput' va lue='json' /></td>" +
  692                             "</tr> " +
  693                             "<tr i d='postAPI Param_MHVP rescriptio nID'>" +
  694                                 "< td>MHV Pre scription  ID</td>" +
  695                                 "< td><input  type='text ' id='post APIParamIn put_rxid'  class='pos tAPIParamI nput' valu e='" + _MH VSelectedP rescriptio nID + "'/> </td>" +
  696                             "</tr> " +
  697                             "<tr i d='postAPI Param_MHVR efillPresc riptionPic kerRow'>"  +
  698                                 "< td>MHV Pre scription  ID Picker< /td>" +
  699                                 // insert tab le cell wi th radio b utton sele ction for  prescripti on IDs in  _MHVPrecri ptionIDLis t array
  700                                 "< td>" + tra ckingAPIRa dios + "</ td>" +
  701                             "</tr> " +
  702                         "</table>"
  703                         )
  704                    );
  705                    brea k;
  706                case "ft p_MHVRegis trationAPI URL":
  707                    full Url = dacU RL + setti ngValue;
  708                    $("# postAPIInt egrationPa rametersTa bleContain er").appen d($(
  709                         "<table id ='postAPII ntegration Parameters Table_" +  _currentSe tting + "' >" +
  710                             "<tr i d='postAPI Param_ICN' >" +
  711                                 "< td>ICN</td >" +
  712                                 "< td><input  type='text ' id='post APIParamIn put_ICN' c lass='post APIParamIn put' value ='" + _ICN  + "'/></t d>" +
  713                             "</tr> " +
  714                             /*"<tr  id='postA PIParam_Ad dressStree t'>" +
  715                                 "< td>Address  Street Ad dress</td> " +
  716                                 "< td><input  type='text ' id='post APIParamIn put_addres s1' class= 'postAPIPa ramInput'  value='" +  "[[addres s street]] " + "'/></ td>" +
  717                             "</tr> " +
  718                             "<tr i d='postAPI Param_Addr essCity'>"  +
  719                                 "< td>Address  Street Ci ty</td>" +
  720                                 "< td><input  type='text ' id='post APIParamIn put_city'  class='pos tAPIParamI nput' valu e='" + "[[ address ci ty]]" + "' /></td>" +
  721                             "</tr> " +
  722                             "<tr i d='postAPI Param_Addr essStreet' >" +
  723                                 "< td>Address  Street Ad dress</td> " +
  724                                 "< td><input  type='text ' id='post APIParamIn put_provin ce' class= 'postAPIPa ramInput'  value='" +  "[[addres s state/pr ovince]]"  + "'/></td >" +
  725                             "</tr> " +
  726                             "<tr i d='postAPI Param_Addr essPostalC ode'>" +
  727                                 "< td>Address  Street Po stal Code< /td>" +
  728                                 "< td><input  type='text ' id='post APIParamIn put_zip' c lass='post APIParamIn put' value ='" + "[[a ddress pos tal code]] " + "'/></ td>" +
  729                             "</tr> " +*/
  730                             "<tr>< td>Select  at least o ne checkbo x.</td></t r>" +
  731                             "<tr i d='postAPI Param_IsPa tient'>" +
  732                                 "< td>Is Pati ent</td>"  +
  733                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is Patient' c lass='post APIParamIn put'/></td >" +
  734                             "</tr> " +
  735                             "<tr i d='postAPI Param_IsPa tientAdvoc ate'>" +
  736                                 "< td>Is Pati ent Advoca te</td>" +
  737                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is PatientAdv ocate' cla ss='postAP IParamInpu t'/></td>"  +
  738                             "</tr> " +
  739                             "<tr i d='postAPI Param_IsVe teran'>" +
  740                                 "< td>Is Vete ran</td>"  +
  741                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is Veteran' c lass='post APIParamIn put'/></td >" +
  742                             "</tr> " +
  743                             "<tr i d='postAPI Param_IsCh ampVABenef iciary'>"  +
  744                                 "< td>Is Cham p VA Benef iciary</td >" +
  745                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is ChampVABen eficiary'  class='pos tAPIParamI nput'/></t d>" +
  746                             "</tr> " +
  747                             "<tr i d='postAPI Param_IsSe rviceMembe r'>" +
  748                                 "< td>Is Serv ice Member </td>" +
  749                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is ServiceMem ber' class ='postAPIP aramInput' /></td>" +
  750                             "</tr> " +
  751                             "<tr i d='postAPI Param_IsEm ployee'>"  +
  752                                 "< td>Is Empl oyee</td>"  +
  753                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is Employee'  class='pos tAPIParamI nput'/></t d>" +
  754                             "</tr> " +
  755                             "<tr i d='postAPI Param_IsHe althcarePr ovider'>"  +
  756                                 "< td>Is Heal thcare Pro vider</td> " +
  757                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is Healthcare Provider'  class='pos tAPIParamI nput'/></t d>" +
  758                             "</tr> " +
  759                             "<tr i d='postAPI Param_IsOt her'>" +
  760                                 "< td>Is Othe r</td>" +
  761                                 "< td><input  type='chec kbox' id=' postAPIPar amInput_is Other' cla ss='postAP IParamInpu t'/></td>"  +
  762                             "</tr> " +
  763                             "<tr i d='postAPI Param_Sign InPartners '>" +
  764                                 "< td>Sign In  Partners< /td>" +
  765                                 "< td><input  type='text ' id='post APIParamIn put_signIn Partners'  class='pos tAPIParamI nput' valu e='" + "VE TS.VA.GOV"  + "'/></t d>" +
  766                             "</tr> " +
  767                             "<tr i d='postAPI Param_Cont actMethod' >" +
  768                                 "< td>Contact  Method</t d>" +
  769                                 "< td><input  type='text ' id='post APIParamIn put_contac tMethod' c lass='post APIParamIn put' value ='" + "Mob ilePhone"  + "'/></td >" +
  770                             "</tr> " +
  771                             "<tr i d='postAPI Param_Mobi lePhone'>"  +
  772                                 "< td>Mobile  Phone</td> " +
  773                                 "< td><input  type='text ' id='post APIParamIn put_mobile Phone' cla ss='postAP IParamInpu t' value=' " + "777-8 88-9999" +  "'/></td> " +
  774                             "</tr> " +
  775                             "<tr i d='postAPI Param_Term sVersion'> " +
  776                                 "< td>Terms V ersion</td >" +
  777                                 "< td><input  type='text ' id='post APIParamIn put_termsV ersion' cl ass='postA PIParamInp ut' value= '" + "v3.2 " + "'/></ td>" +
  778                             "</tr> " +
  779                             "<tr i d='postAPI Param_Term sAcceptedD ate'>" +
  780                                 "< td>Terms A cepted Dat e</td>" +
  781                                 "< td><input  type='text ' id='post APIParamIn put_termsA cceptedDat e' class=' postAPIPar amInput' v alue='" +  new Date() .toUTCStri ng() + "'/ ></td>" +
  782                             "</tr> " +
  783                             "<tr i d='postAPI Param_Form at'>" +
  784                                 "< td>Format< /td>" +
  785                                 "< td><input  type='text ' id='post APIParamIn put_format ' class='p ostAPIPara mInput' va lue='" + " json" + "' /></td>" +
  786                             "</tr> " +
  787                         "</table>"
  788                         )
  789                    );
  790                    brea k;
  791                default:
  792                    //No tes, Order s, Appoint ments, Med ications,  Postings,  Allergies,  Labs, Con sults, Non -VA Meds,  Vitals, Ra diology, D ischarges
  793                    full Url = dacU RL + setti ngValue +  _nationalI d + filter ;
  794                    brea k;
  795           }
  796           // SC Disabil ities
  797           // fullUrl =  context.ge tClientUrl () + "/Web Resources/ ftp_/ServC onnDisabil itiesGrid/ ServConnDi sabilities Grid.html? data=" + i cn;
  798  
  799           $( "#urlToTes t").val(fu llUrl);
  800           if  (pFocus)  { $("#urlT oTest").fo cus(); }
  801       }
  802   }
  803  
  804   function p ostDataTab leAddRowBu tton_onCli ck() {
  805       try{
  806           va r table =  document.g etElementB yId("postD ataTable") ;
  807           if  (!!table)  {
  808                var newR ow = table .insertRow (table.row s.length);
  809                var name Cell = new Row.insert Cell(0);
  810                var valu eCell = ne wRow.inser tCell(1);
  811           }
  812  
  813           $( "#postData Table").ap pend(
  814                "<tr>" +
  815                    "<td ><input ty pe='text'  class='pos tAPIParamI nputLabel'  value=''  onchange=' postAPIPar amInputLab el_onChang e(this);'/ ></td>" +
  816                    "<td ><input ty pe='text'  class='pos tAPIParamI nput' valu e=''/></td >" +
  817                "</tr>"
  818           );
  819       }
  820       catch  (e) {
  821           al ert(e.mess age);
  822       }
  823   }
  824  
  825   //function  freeModeP OSTTestBut ton_onClic k() {
  826  
  827   //}
  828  
  829   function p ostAPIPara mInputLabe l_onChange (pElement)  {
  830       $(pEle ment).attr ("id", "po stAPIParam InputLabel _" + pElem ent.value) ;
  831       var va lueInput =  $(pElemen t).closest ("td").nex t().find(" input");
  832       valueI nput.attr( "id", "pos tAPIParamI nput_" + p Element.va lue);
  833   }
  834  
  835   function c heckSubmit Test(event ){
  836           if  (event.ke yCode ===  13) {
  837                    begi nTest();
  838           }
  839   }
  840   function b eginTest() {
  841           sh owLoadingM essage("Lo ading test  result... ");
  842           se tTestResul tContainer HTML();
  843   }
  844   function s etTestResu ltContaine rHTML(){
  845           $( "#displayf rame").loa d(function (){return; });
  846           re setTestRes ultContain er();
  847           va r fullUrl  = $("#urlT oTest").va l();
  848  
  849           if  (_freeBui lderMode)  {
  850                _current SettingIsA PI = true;
  851                _current SettingIsS ecureAPI =  false;
  852                _current SettingIsP OSTAPI = t rue;
  853           }
  854           
  855           if  (_current SettingIsA PI) {
  856                //for AP Is, query  the API an d then for mat result s in an HT ML page in  the iFram e
  857                var dTyp e = fullUr l.toLowerC ase().inde xOf("json" ) > -1 ? " json" : "t ext";
  858                var cTyp e = dType  == "json"  ? "applica tion/json;  charset=u tf-8" : "c harset=utf -8";
  859                if (!_cu rrentSetti ngIsSecure API && !_c urrentSett ingIsPOSTA PI) {
  860                    $.aj ax({
  861                         type: "GET ",
  862                         contentTyp e: cType,
  863                         datatype:  dType,
  864                         url: fullU rl,
  865                         beforeSend : function  (XMLHttpR equest) {
  866                             //Spec ifying thi s header e nsures tha t the resu lts will b e returned  as JSON.
  867                             if (dT ype == "js on") XMLHt tpRequest. setRequest Header("Ac cept", "ap plication/ json");
  868                         },
  869                         success: f unction (p Response,  textStatus , XmlHttpR equest) {
  870                             showLo adingMessa ge("Loadin g test res ult...");
  871                             writeT oConsole(" inside set TestResult ContainerH TML() API  query succ ess callba ck");
  872                         if (!!pRes ponse) {
  873                             if (_c urrentSett ing == "ft p_MHVSessi onAPIURL")  {
  874                                 va r newFrame Content =  "<pre>" +  JSON.strin gify(pResp onse, unde fined, 2)  + "</pre>" ;
  875                                 se tIFrame(ne wFrameCont ent, true) ;
  876                                 $( "#mhvtoken ").val(pRe sponse);
  877                                 mh vtoken_onC hange(fals e);
  878                             }
  879                             else i f (dType = = "json")  {
  880                                 va r newFrame Content =  "<pre>" +  JSON.strin gify(pResp onse, unde fined, 2)  + "</pre>" ;
  881                                 se tIFrame(ne wFrameCont ent, true) ;
  882                             }
  883                             else {
  884                                 tr y {
  885                                      var seri alizedCont ent = new  XMLSeriali zer().seri alizeToStr ing(pRespo nse);
  886                                      var newF rameConten t = "<text area cols= '200' rows ='200'>" +  serialize dContent +  "</textar ea>";
  887                                      setIFram e(newFrame Content, t rue);
  888                                 }
  889                                 ca tch (e) {
  890                                      console. log(e);
  891                                      alert("C ontent mig ht not be  XML...\n\n " + e.mess age);
  892                                      hideLoad ingGif();
  893                                 }
  894                             }
  895                         }
  896                         else {
  897                             var ne wFrameCont ent = "<pr e>Empty re sponse fro m API</pre >";
  898                             setIFr ame(newFra meContent,  true);
  899                         }
  900                         },
  901                         error: fun ction (XML HttpReques t, textSta tus, error Thrown) {
  902                             alert( "error que rying API.  use devel oper conso le.");
  903                             var ne wFrameCont ent = "<p> error quer ying API.  use develo per consol e.</p><pre >" + JSON. stringify( XMLHttpReq uest.respo nseJSON, u ndefined,  2) + "</pr e>";
  904                             setIFr ame(newFra meContent,  true);
  905                             $("#lo adingGifDi v").hide() ;
  906                         },
  907                         async: tru e,/*change d 6/9/17*/
  908                         cache: fal se
  909                    });
  910                }
  911                else {
  912                             if(_cu rrentSetti ngIsSecure API){
  913                                      fullUrl  = fullUrl. toLowerCas e().replac e("/ftpcrm /", ""); / /remove or g name fro m secure A PI urls
  914                                      var inte grationPar ameters =  {};
  915                                      $(".secu reAPIParam Input").ea ch(
  916                                               function ( i, elem) {
  917                                                       va r paramNam e = $(this ).prop("id ").split(" _")[1];
  918                                                       va r paramVal ue = $(thi s).val();
  919                                                       in tegrationP arameters[ paramName]  = paramVa lue;
  920                                               }
  921                                      );
  922  
  923                                      var acti onParamete rs = [{ ke y: "identi fier", typ e: "c:stri ng", value : JSON.str ingify(int egrationPa rameters)  }];
  924                                      $("#secu reAPIInteg rationPara metersStri ngifiedTex t").html(J SON.string ify(integr ationParam eters));
  925                                      dType =  "json";
  926                                      CrmSecur ityTokenEn cryption(
  927                                               fullUrl,
  928                                               actionPara meters,
  929                                               context.ge tClientUrl (),
  930                                               function ( pError, pR esponse) {
  931                                                       if  (!!pError ) {
  932                                                                aler t("error q uerying AP I. use dev eloper con sole.");
  933                                                                cons ole.error( "error que rying secu re API: "  + pError);
  934                                                                var  newFrameCo ntent = "< p>error qu erying API . use deve loper cons ole.</p><p re>" + JSO N.stringif y(pError)  + "</pre>" ;
  935                                                                setI Frame(newF rameConten t, true);
  936                                                                $("# loadingGif Div").hide ();
  937                                                       }
  938                                                       el se {
  939                                                                show LoadingMes sage("Load ing test r esult...") ;
  940                                                                writ eToConsole ("inside s etTestResu ltContaine rHTML() se cure API q uery succe ss callbac k");
  941  
  942                                                                if ( !!pRespons e) {
  943                                                                         if (dT ype == "js on") {
  944                                                                                  var newF rameConten t = "<pre> " + JSON.s tringify(p Response,  undefined,  2) + "</p re>";
  945                                                                                  setIFram e(newFrame Content, t rue);
  946                                                                         }
  947                                                                         else { /*xml*/
  948                                                                                  try{
  949                                                                                           var serial izedConten t = new XM LSerialize r().serial izeToStrin g(pRespons e);
  950                                                                                           var newFra meContent  = "<textar ea cols='2 00' rows=' 200'>" + s erializedC ontent + " </textarea >";
  951                                                                                           setIFrame( newFrameCo ntent, tru e);
  952                                                                                  }
  953                                                                                  catch(e) {
  954                                                                                           console.lo g(e);
  955                                                                                           alert("Con tent might  not be XM L...\n\n"  + e.messag e);
  956                                                                                           hideLoadin gGif();
  957                                                                                  }
  958                                                                         }
  959                                                                }
  960                                                       }
  961                                               }
  962                                      );
  963                             }
  964                             else i f(_current SettingIsP OSTAPI){
  965                                      var post Data = {};
  966                                      $(".post APIParamIn put").each (
  967                                               function ( i, elem) {
  968                                                       va r paramNam e = $(this ).prop("id ").split(" _")[1];
  969                                                       va r paramVal ue = $(thi s).prop("t ype") == " checkbox"  ? $(this). is(":check ed") : $(t his).val() ;
  970                             postDa ta[paramNa me] = para mValue;
  971                             if (pa ramName.to LowerCase( ) == "form at") {
  972                                 dT ype = para mValue ==  "json" ? " json" : "t ext";
  973                             }
  974                                               }
  975                                      );
  976                                      $("#post APIIntegra tionParame tersString ifiedText" ).html(JSO N.stringif y(postData ));
  977                                      $("#post APIIntegra tionParame tersString ifiedText" ).show();
  978                                      
  979                                      $.ajax({
  980                                               type: "POS T",
  981                                               data: post Data,//JSO N.stringif y(postData ),
  982                                               url: fullU rl,
  983                                               timeout: 1 0000,
  984                                               error: fun ction (jqX HR, textSt atus, pErr or) {
  985                                                       al ert("error  POSTing t o API. Use r develope r console. ");
  986                                                       co nsole.erro r("error P OSTing to   API: " +  pError);
  987                                                       va r newFrame Content =  "<p>error  querying A PI. use de veloper co nsole.</p> <pre>" + J SON.string ify(pError ) + "<br/> " + JSON.s tringify(j qXHR.respo nseJSON, u ndefined,  2) + "</pr e>";
  988                                                       se tIFrame(ne wFrameCont ent, true) ;
  989                                                       $( "#loadingG ifDiv").hi de();
  990                                                       
  991                                                       if (_currentS etting ==  "ftp_MHVAc tivePrescr iptionAPIU RL"){
  992                                                                _MHV Prescripti onList = [ ];
  993                                                       }
  994                                               },
  995                                               success: f unction (p Response)  {
  996                                                       sh owLoadingM essage("Lo ading test  result... ");
  997                                                       wr iteToConso le("inside  setTestRe sultContai nerHTML()  POST API q uery succe ss callbac k");
  998                                                       if (!!pRespon se){
  999                                                                if(d Type == "j son"){
  1000                                                                         var ne wFrameCont ent = "<pr e>" + JSON .stringify (pResponse , undefine d, 2) + "< /pre>";
  1001                                                                         setIFr ame(newFra meContent,  true);
  1002                                                                         
  1003                                      if (_cur rentSettin g == "ftp_ MHVActiveP rescriptio nAPIURL")  {
  1004                                          var  retrievedP rescriptio ns = getDe epProperty ("Data.pre scriptionL ist", pRes ponse);
  1005                                          _MHV Prescripti onList = ! !retrieved Prescripti ons ? retr ievedPresc riptions :  [];
  1006                                                                         }
  1007                                                                }
  1008                                                                else  {
  1009                                                                         try{
  1010                                                                                  var seri alizedCont ent = new  XMLSeriali zer().seri alizeToStr ing(pRespo nse);
  1011                                                                                  var newF rameConten t = "<text area cols= '200' rows ='200'>" +  serialize dContent +  "</textar ea>";
  1012                                                                                  setIFram e(newFrame Content, t rue);
  1013                                                                         }
  1014                                                                         catch( e){
  1015                                                                                  console. log(e);
  1016                                                                                  alert("C ontent mig ht not be  XML...\n\n " + e.mess age);
  1017                                                                                  hideLoad ingGif();
  1018                                                                         }
  1019                                                                }
  1020                                                       }
  1021                                               }
  1022                                      });
  1023                                      
  1024                             }
  1025                }
  1026           }
  1027           el se{
  1028                    $("# displayfra me").load( function() {
  1029                             $("#lo adingGifDi v").hide() ;
  1030                             writeT oConsole(" hide loadi ngGifDiv") ;
  1031                             $("#di splayframe ").load(fu nction(){r eturn;});
  1032                    });
  1033                    //fo r web part s, just qu ery the we b part url
  1034                    setI Frame(full Url, false );
  1035           }
  1036   }
  1037   function s etIFrame(p Source, pI sText){
  1038           if (!!pSource ){
  1039                    if(p IsText){
  1040                             $('#di splayframe ')[0].cont entWindow. document.w rite(pSour ce);
  1041                             writeT oConsole(" set displa yFrame HTM L content  directly") ;
  1042                             $("#lo adingGifDi v").hide() ;
  1043                    }
  1044                    else {
  1045                             $('#di splayframe ').attr({
  1046                                      src: pSo urce,
  1047                                      title: _ currentSet ting
  1048                             });
  1049                             writeT oConsole(" set displa yFrame src  attribute ");
  1050                    }
  1051           }
  1052   }
  1053  
  1054   function r esetTestRe sultContai ner(){
  1055           $( '#displayf rame').att r({
  1056                    src:  "",
  1057                    titl e: ""/*set tingName*/
  1058           }) ;
  1059           
  1060   }
  1061   function h ideLoading Gif(){
  1062           wr iteToConso le("begin  hideLoadin gGif()");
  1063           $( "#loadingG ifDiv").hi de();
  1064   }
  1065  
  1066   function p rescriptio nSelected( pElement)  {
  1067       var se lectedPres cription =  $("input[ name=presc riptionSel ection]:ch ecked").va l();
  1068       try {
  1069           $( "#postAPIP aramInput_ rxid").val (selectedP rescriptio n);
  1070       }
  1071       catch  (e) {
  1072  
  1073       }
  1074   }
  1075   function i cn_onChang e(){
  1076           _I CN = $("#I CN").val() ;
  1077           $( "#national Id").val(_ ICN.substr ing(0,10)) ;
  1078           na tionalId_o nChange(fa lse);
  1079           se tupQueryBu ilder(null , false);
  1080   }
  1081   function n ationalId_ onChange(p FireSetupQ ueryBuilde r){
  1082           _n ationalId  = $("#nati onalId").v al();
  1083           if (pFireSetu pQueryBuil der == nul l || pFire SetupQuery Builder ==  true){
  1084                    setu pQueryBuil der(null,  false);
  1085           }
  1086   }
  1087   function e dipi_onCha nge(pFireS etupQueryB uilder){
  1088           _E DIPI = $(" #edipi").v al();
  1089           if (pFireSetu pQueryBuil der == nul l || pFire SetupQuery Builder ==  true){
  1090                    setu pQueryBuil der(null,  false);
  1091           }
  1092   }
  1093   function m hvid_onCha nge(pFireS etupQueryB uilder){
  1094           _M HVID = $(" #mhvid").v al();
  1095           if (pFireSetu pQueryBuil der == nul l || pFire SetupQuery Builder ==  true){
  1096                    setu pQueryBuil der(null,  false);
  1097           }
  1098   }
  1099   function m hvtoken_on Change(pFi reSetupQue ryBuilder) {
  1100           _M HVSessionT oken = $(" #mhvtoken" ).val();
  1101           va r size = ! !_MHVSessi onToken ?  _MHVSessio nToken.len gth : 40;
  1102           $( "#mhvtoken ").attr("s ize", size );
  1103           if (pFireSetu pQueryBuil der == nul l || pFire SetupQuery Builder ==  true){
  1104                    setu pQueryBuil der(null,  false);
  1105           }
  1106   }
  1107   function s electedMVI FacilityCo de_onChang e(){
  1108           _f acilityCod eFromMVI =  $("#selec tedMVIFaci lityCode") .val();
  1109           $( "label[for =useMVISel ectedFacil ity]").tex t("Use vet eran facil ity from M VI (" + _f acilityCod eFromMVI +  ")");
  1110           se tupQueryBu ilder(null , false);
  1111   }
  1112   function s electedMVI FacilityCo deDFN_onCh ange(){
  1113           _f acilityCod eFromMVIDF N = $("#se lectedMVIF acilityCod eDFN").val ();
  1114           se tupQueryBu ilder(null , false);
  1115   }
  1116   function p referredFa cilityCode FromESR_on Change(){
  1117           _f acilityCod eFromESR =  $("#prefe rredFacili tyCodeFrom ESR").val( );
  1118           $( "label[for =useESRPre ferredFaci lity]").te xt("Use ve teran pref erred faci lity from  ESR (" + _ facilityCo deFromESR  + ")");
  1119           se tupQueryBu ilder(null , false);
  1120   }
  1121   function p referredFa cilityCode FromESRDFN _onChange( ){
  1122           _f acilityCod eFromESRDF N = $("#pr eferredFac ilityCodeF romESRDFN" ).val();
  1123           se tupQueryBu ilder(null , false);
  1124   }
  1125   function u serFirstNa me_onChang e(pFireSet upQueryBui lder){
  1126           _u serFirstNa me = $("#u serFirstNa me").val() ;
  1127           if (pFireSetu pQueryBuil der == nul l || pFire SetupQuery Builder ==  true){
  1128                    setu pQueryBuil der(null,  false);
  1129           }
  1130   }
  1131   function u serLastNam e_onChange (pFireSetu pQueryBuil der){
  1132           _u serLastNam e = $("#us erLastName ").val();
  1133           if (pFireSetu pQueryBuil der == nul l || pFire SetupQuery Builder ==  true){
  1134                    setu pQueryBuil der(null,  false);
  1135           }
  1136   }
  1137   function u serFacilit yCode_onCh ange(pFire SetupQuery Builder){
  1138           _u serFacilit yCode = $( "#userFaci lityCode") .val();
  1139           if (pFireSetu pQueryBuil der == nul l || pFire SetupQuery Builder ==  true){
  1140                    setu pQueryBuil der(null,  false);
  1141           }
  1142   }
  1143   function u serIEN_onC hange(){
  1144           _u serIENAtFa cilityCode  = $("#use rIEN").val ();
  1145           se tupQueryBu ilder(null , false);
  1146   }
  1147  
  1148  
  1149   function g etContext( ) {
  1150           re turn (type of GetGlob alContext  != "undefi ned") ? Ge tGlobalCon text() : n ull;
  1151   }
  1152   function s howLoading Message(pM essage){
  1153           $( "#progress Text").htm l(pMessage );
  1154           $( "#loadingG ifDiv").sh ow();
  1155   }
  1156  
  1157   function s howDiv(pDi vToShow){
  1158           va r knownDiv s = [
  1159                    "#lo adingGifDi v",
  1160                    "#MV ISearchCon tainer",
  1161                    "#re trievedSet tingsConta iner",
  1162                    "#te stQueryBui lderContai ner",
  1163                    "#te stResultCo ntainer"
  1164           ];
  1165           fo r(var d =  0; d < kno wnDivs.len gth; d++){
  1166                    if(k nownDivs[d ] == pDivT oShow) {
  1167                             $(know nDivs[d]). show();
  1168                    }
  1169                    else {
  1170                             $(know nDivs[d]). hide();
  1171                    }
  1172           }
  1173   }
  1174  
  1175   function p arseDataPa rametersFr omUrl(pQue ryString)  {
  1176           // example qu ery string  (unencode d): contac tid={32CA1 B55-DC81-E 611-9445-0 050568D743 D}&fullnam e=TIFINKLE , ANDREW&s ensitivity =true&IsUS D=true
  1177           va r fullPara meterArray  = pQueryS tring.subs tr(1).spli t("&");
  1178  
  1179           // clean up t he URL que ry string  and split  each membe r into a k ey/value p air
  1180           fo r (var i i n fullPara meterArray ) {
  1181                    full ParameterA rray[i] =  fullParame terArray[i ].replace( /\+/g, " " ).split("= ");
  1182           }
  1183  
  1184           va r customDa taString =  "";
  1185           fo r (var i i n fullPara meterArray ) {
  1186                    if ( fullParame terArray[i ][0].toLow erCase() = = "data")  {
  1187                             custom DataString  = fullPar ameterArra y[i][1];
  1188                             break;
  1189                    }
  1190           }
  1191  
  1192           va r customDa taArray =  decodeURIC omponent(c ustomDataS tring).spl it("&");
  1193           fo r (var i i n customDa taArray) {
  1194                    cust omDataArra y[i] = cus tomDataArr ay[i].repl ace(/\+/g,  " ").spli t("=");
  1195           }
  1196  
  1197           va r configOb ject = {};
  1198           fo r (var i i n customDa taArray) {
  1199                    conf igObject[c ustomDataA rray[i][0] ] = custom DataArray[ i][1];
  1200           }
  1201  
  1202           // optionally , put code  here to s how body o nce we hav e the conf ig object,  if it's t aking too  long
  1203           re turn confi gObject;
  1204   }
  1205   function b uildQueryF ilter(fiel d, value,  and) {
  1206       return  !!field ?  ((and ? "  and " : " ") + field  + " eq "  + (value = = '' ? "nu ll" : "'"  + value +  "'")) : "" ;
  1207   }
  1208   function e rrorHandle r(error) {
  1209           wr iteToConso le(error.m essage);
  1210       //show ErrorMessa ge("Error" , error.me ssage, "Er ror");
  1211   }
  1212   function w riteToCons ole(messag e) {
  1213       if (ty peof conso le != 'und efined') c onsole.log (message);
  1214   }
  1215   function x mlParser(t xt){
  1216           // cross brow ser respon seXml to r eturn a XM L object
  1217           va r xmlDoc =  null;
  1218           tr y{
  1219                    xmlD oc = new A ctiveXObje ct("Micros oft.XMLDOM ");
  1220                    xmlD oc.async =  false;
  1221                    xmlD oc.loadXML (txt);
  1222           }
  1223           ca tch(e){
  1224                    if(w indow.DOMP arser){
  1225                             var pa rser = new  DOMParser ();
  1226                             xmlDoc  = parser. parseFromS tring(txt,  "text/xml ");
  1227                    }
  1228                    else {
  1229                             showEr rorMessage ("Cannot c onvert str ing to a c ross-brows er XML obj ect.",""," Error pars ing XML");
  1230                    }
  1231           }
  1232           re turn xmlDo c;
  1233   }
  1234   function g etDeepProp erty(pPath , pObject)  {
  1235       if (!! pPath) {
  1236           va r pathAsAr ray = pPat h.split(". ");
  1237           va r returnOb j = !!pObj ect ? pObj ect : wind ow[pathAsA rray.shift ()];
  1238           if  (typeof r eturnObj ! = "undefin ed") {
  1239                while (! !returnObj  && pathAs Array.leng th > 0) {
  1240                    var  nextLevel  = pathAsAr ray.shift( );
  1241                    var  isArrayQue ry = nextL evel.index Of("[") >  -1 && next Level.inde xOf("]") = = nextLeve l.indexOf( "[") + 2;
  1242                    var  nextLevelN ame = !isA rrayQuery  ? nextLeve l : nextLe vel.split( "[")[0];
  1243                    var  nextLevelA rrayMember  = !isArra yQuery ? n ull : pars eInt((next Level.spli t("[")[1]) .substr(0,  (nextLeve l.split("[ ")[1].leng th)));
  1244  
  1245                    retu rnObj = is ArrayQuery  ? returnO bj[nextLev elName][ne xtLevelArr ayMember]  : returnOb j[nextLeve lName];
  1246  
  1247                }
  1248                return r eturnObj;
  1249           }
  1250           el se {
  1251                return u ndefined;
  1252           }
  1253       }
  1254       else {
  1255           re turn undef ined;
  1256       }
  1257   }
  1258   function c ontainsOnl yNumbers(p String){
  1259           re turn !/\D/ .test(pStr ing);
  1260   }