52. EPMO Open Source Coordination Office Redaction File Detail Report

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

52.1 Files compared

# Location File Last Modified
1 VCCM.zip\VCCM\CRM_solutions\VCCMResources\VCCMResources_1_0_0_15.zip\WebResources ftp_VistAMultiNoteFormScriptVistACPRSAdditionalSig5AA4AA98-943C-E711-944F-0050568D743D Fri May 19 20:29:42 2017 UTC
2 VCCM.zip\VCCM\CRM_solutions\VCCMResources\VCCMResources_1_0_0_15.zip\WebResources ftp_VistAMultiNoteFormScriptVistACPRSAdditionalSig5AA4AA98-943C-E711-944F-0050568D743D Thu Nov 30 17:19:05 2017 UTC

52.2 Comparison summary

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

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

52.4 Active regular expressions

No regular expressions were active.

52.5 Comparison detail

  1   var _retri evedSettin gs = null;
  2   var _addlS ignersAPIU rl = null;
  3  
  4   function f orm_onLoad (){
  5           tr y{
  6                    laun chSignerSe arch();
  7                    
  8                    _ret rievedSett ings = nul l;
  9                    var  queryStrin g = "$sele ct=*&$filt er=mcs_nam e eq 'Acti ve Setting s'";
  10                    SDK. REST.retri eveMultipl eRecords(
  11                             "mcs_s etting",
  12                             queryS tring,
  13                             functi on (retrie vedRecords ) {
  14                                      if (type of retriev edRecords  != "undefi ned" && !! retrievedR ecords &&  retrievedR ecords.len gth == 1)  _retrieved Settings =  retrieved Records[0] ;
  15                             },
  16                             functi on(e){
  17                                      //silent ly error
  18                             },
  19                             functi on () {
  20                                      if (!!_r etrievedSe ttings &&  !!_retriev edSettings .ftp_DACUR L && !!_re trievedSet tings.hasO wnProperty ("ftp_VIAA dditionalS ignersURL" ) && !!_re trievedSet tings.ftp_ VIAAdditio nalSigners URL) {
  21                                               _addlSigne rsAPIUrl =  _retrieve dSettings. ftp_DACURL  + _retrie vedSetting s.ftp_VIAA dditionalS ignersURL;
  22                                      }
  23                                      else{
  24                                               //missing  settings
  25                                      }
  26                             }
  27                    );
  28           }
  29           ca tch(e){
  30                    aler t("VistACP RSAddition alSignersF ormScript. form_onLoa d() error:  " + e.mes sage);
  31           }
  32   }
  33  
  34   function v cmn_initVi aDropdownC ontrols(){
  35           /* do not del ete this f unction! O dd's code  calls it f rom the VI A Login Co ntrol.*/
  36           la unchSigner Search();
  37   }
  38  
  39   function l aunchSigne rSearch()  {
  40       try {
  41           // Refresh th e web reso urce URL
  42           va r SignerSe archWRUrl  = Xrm.Page .getContro l("WebReso urce_Signe rSearch"). getSrc();
  43           Xr m.Page.get Control("W ebResource _SignerSea rch").setS rc(SignerS earchWRUrl );
  44           // Prep the t ab
  45           if  (Xrm.Page .ui.tabs.g et("Tab_Ad ditionalSi gners").ge tVisible()  == false)  {;
  46                Xrm.Page .ui.tabs.g et("Tab_Ad ditionalSi gners").se tVisible(t rue);
  47           }
  48           if  (Xrm.Page .ui.tabs.g et("Tab_Ad ditionalSi gners").ge tDisplaySt ate() != " expanded")  {
  49                Xrm.Page .ui.tabs.g et("Tab_Ad ditionalSi gners").se tDisplaySt ate("expan ded");
  50           }
  51           // Set focus  to the sig ners tab
  52           Xr m.Page.ui. tabs.get(" Tab_Additi onalSigner s").setFoc us();
  53       }
  54       catch  (err) {
  55           al ert("VistA CPRSAdditi onalSigner sFormScrip t.launchSi gnerSearch () error:  " + err.me ssage);
  56       }
  57   }
  58  
  59   function i ntegrateAd ditionalSi gners(){
  60           tr y{
  61                    Xrm. Page.ui.cl earFormNot ification( "preIntegr ationError ");
  62                    Xrm. Page.ui.cl earFormNot ification( "postInteg rationErro r");
  63                    if(! Xrm.Page.d ata.entity .getId()){
  64                             alert( "Save the  record fir st.");
  65                             return ;
  66                    }
  67                    if(X rm.Page.ge tAttribute ("ftp_inte grationsta tus").getV alue() ==  "OK"){
  68                             alert( "These sig ners have  already be en integra ted.  Open  a new Add itional Si gners reco rd in orde r to add m ore signer s.");
  69                             return ;
  70                    }
  71                    /*ma ke sure we  have the  additional  signers a pi URL, se t in form_ onLoad*/
  72                    if(! !_addlSign ersAPIUrl) {
  73                             /*chec k for requ ired field s on form:
  74                             ftp_vi starecordi d - filled  by SDK.RE ST.createR ecord code  on Vetera n Charts w eb resourc e
  75                             ftp_se lectedsign ers - fill ed by Prog ressNoteSi gnerSearch .html web  resource o n this for m
  76                             */
  77                             var vi staRecordI d = Xrm.Pa ge.getAttr ibute("ftp _vistareco rdid").get Value();
  78                             if(!!v istaRecord Id){
  79                                      /*get IE N array br owser loca l storage  (previousl y set by P rogressNot eSignerSea rch.html w eb resourc e),
  80                                      then par se into si ngle strin g for POST ing to VIA */
  81                                      var sign ersIENArra yAsString  = "";
  82                                      //Get No te's Brows er Local S torage Val ues
  83                                      var stor edIENArray AsString =  localStor age.getIte m("PN" + X rm.Page.da ta.entity. getId());
  84                                      if (!!st oredIENArr ayAsString ) {
  85                                               var signer sIENArray  = storedIE NArrayAsSt ring.split ('~~~');
  86                                               if (signer sIENArray. length > 1 ) {
  87                                                       fo r(var a =  0; a < sig nersIENArr ay.length;  a++){
  88                                                                sign ersIENArra yAsString  += (signer sIENArray[ a] + " ");
  89                                                       }
  90                                                       si gnersIENAr rayAsStrin g = signer sIENArrayA sString.tr im();
  91                                                       
  92                                                       /* check VIA  login cook ie and req uire login  first if  necessary* /
  93                                                       va r viaLogin Cookie = d ocCookies. getItem("v iasessionl ink");
  94                                                       if (!!viaLogi nCookie){
  95                                                                var  viaLoginCo okieAsArra y = viaLog inCookie.s plit("~~~~ ", 2);
  96                                                                if(v iaLoginCoo kieAsArray .length ==  2){
  97                                                                         var du zFromCooki e = viaLog inCookieAs Array[0];
  98                                                                         var us erNameFrom Cookie = v iaLoginCoo kieAsArray [1];
  99                                                                         if(!!d uzFromCook ie && !!us erNameFrom Cookie){
  100                                                                                  /*get cu rrent user 's facilit y code*/
  101                                                                                  SDK.REST .retrieveR ecord(
  102                                                                                           Xrm.Page.c ontext.get UserId(),
  103                                                                                           "SystemUse r",
  104                                                                                           "FirstName ,LastName, ftp_ftp_fa cility_sys temuser/ft p_facility code",
  105                                                                                           "ftp_ftp_f acility_sy stemuser",
  106                                                                                           function(r etrievedUs er){
  107                                                                                                   if (retrieved User.hasOw nProperty( "ftp_ftp_f acility_sy stemuser")  && !!retr ievedUser. ftp_ftp_fa cility_sys temuser &&  retrieved User.ftp_f tp_facilit y_systemus er.hasOwnP roperty("f tp_facilit ycode") &&  !!retriev edUser.ftp _ftp_facil ity_system user.ftp_f acilitycod e){
  108                                                                                                            //Cr eate the A dditional  Signers JS ON oject
  109                                                                                                            var  signersObj ect = {
  110                                                                                                                     Provid erName: us erNameFrom Cookie,
  111                                                                                                                     Duz: d uzFromCook ie,
  112                                                                                                                     LoginS iteCode: r etrievedUs er.ftp_ftp _facility_ systemuser .ftp_facil itycode,
  113                                                                                                                     Target : vistaRec ordId,
  114                                                                                                                     Supple mentalPara meters: si gnersIENAr rayAsStrin g
  115                                                                                                            };
  116                                                                                                            
  117                                                                                                            $.aj ax({
  118                                                                                                                     type:  "POST",
  119                                                                                                                     url: _ addlSigner sAPIUrl,
  120                                                                                                                     data:  JSON.strin gify(signe rsObject),
  121                                                                                                                     conten tType: "ap plication/ json; char set=utf-8" ,
  122                                                                                                                     dataTy pe: "json" ,
  123                                                                                                                     succes s: functio n (data) {
  124                                                                                                                              var resp onseData =  JSON.stri ngify(data .Data);
  125                                                                                                                              if (!res ponseData. ErrorOccur red) {
  126                                                                                                                                       //successf ul signer  integratio n
  127                                                                                                                                       Xrm.Page.g etAttribut e("ftp_int egrationda te").setVa lue(new Da te());
  128                                                                                                                                       Xrm.Page.g etAttribut e("ftp_int egrationda te").setSu bmitMode(" always");
  129                                                                                                                                       Xrm.Page.g etAttribut e("ftp_int egrationst atus").set Value("OK" );
  130                                                                                                                                       Xrm.Page.g etAttribut e("ftp_int egrationst atus").set SubmitMode ("always") ;
  131                                                                                                                                      
  132                                                                                                                                       //close th e activity
  133                                                                                                                              }
  134                                                                                                                              else{
  135                                                                                                                                       var msg =  "Unable to  add the a dditional  signers se lected to  this note.  Please re view the s igners in  your Vista /CPRS appl ication!";
  136                                                                                                                                       Xrm.Page.u i.setFormN otificatio n(msg, "ER ROR", "pos tIntegrati onError");
  137                                                                                                                              }
  138                                                                                                                     },
  139                                                                                                                     error:  function  (jqXHR, te xtStatus,  errorThrow n) {
  140                                                                                                                              //System  Error
  141                                                                                                                              alert("E rror: Unab le to add  the additi onal signe rs selecte d to this  note.\n\nP lease revi ew the not e and sign ers in you r Vista/CP RS applica tion!");
  142                                                                                                                     },
  143                                                                                                                     async:  false,
  144                                                                                                                     cache:  false
  145                                                                                                            });
  146                                                                                                   }
  147                                                                                                   el se{
  148                                                                                                            //mi ssing user  facility  code
  149                                                                                                            var  msg = "You r CRM user  record is  missing a  designate d Site, or  its desig nated Site  does not  have a Fac ility Code .";
  150                                                                                                            Xrm. Page.ui.se tFormNotif ication(ms g, "ERROR" , "preInte grationErr or");
  151                                                                                                   }
  152                                                                                                   
  153                                                                                           },
  154                                                                                           errorHandl er
  155                                                                                  );
  156                                                                         }
  157                                                                         else{
  158                                                                                  //viaLog inCookie i s incomple te, prompt  for login  and instr uct to re- integrate  after logg ing in
  159                                                                                  var msg  = "Your te mporarily  stored Vis tA credent ials are m issing som e informat ion. In or der to add  additiona l signers,  please lo gin to Vis tA again." ;
  160                                                                                  Xrm.Page .ui.setFor mNotificat ion(msg, " INFO", "pr eIntegrati onError");
  161                                                                                  promptFo rVIALogin( msg);
  162                                                                         }
  163                                                                }
  164                                                                else {
  165                                                                         //viaL oginCookie  is incomp lete, prom pt for log in and ins truct to r e-integrat e after lo gging in
  166                                                                         var ms g = "Your  temporaril y stored V istA crede ntials are  missing s ome inform ation. In  order to a dd additio nal signer s, please  login to V istA again .";
  167                                                                         Xrm.Pa ge.ui.setF ormNotific ation(msg,  "INFO", " preIntegra tionError" );
  168                                                                         prompt ForVIALogi n(msg);
  169                                                                }
  170                                                       }
  171                                                       el se{
  172                                                                //mi ssing viaL oginCookie , prompt f or login a nd instruc t to re-in tegrate af ter loggin g in
  173                                                                var  msg = "You r VISTA se ssion has  expired. I n order to  add addit ional sign ers, you m ust be log ged into V istA";
  174                                                                Xrm. Page.ui.se tFormNotif ication(ms g, "INFO",  "preInteg rationErro r");
  175                                                                prom ptForVIALo gin(msg);
  176                                                       }
  177                                               }
  178                                               else{
  179                                                       // select and  apply sig ners befor e trying t o integrat e
  180                                                       va r msg = "U se the sig ner search  control t o select a nd apply a dditional  signers be fore tryin g to Save  to VsitA/C PRS";
  181                                                       Xr m.Page.ui. setFormNot ification( msg, "ERRO R", "preIn tegrationE rror");
  182                                               }
  183                                      }
  184                                      else{
  185                                               //select a nd apply s igners bef ore trying  to integr ate
  186                                               var msg =  "Use the s igner sear ch control  to select  and apply  additiona l signers  before try ing to Sav e to VsitA /CPRS";
  187                                               Xrm.Page.u i.setFormN otificatio n(msg, "ER ROR", "pre Integratio nError");
  188                                      }
  189                             }
  190                             else{
  191                                      //missin g required  values on  form, use r must clo se form an d try agai n
  192                                      var msg  = "Your fo rm is miss ing requir ed data.   Close this  form and  try adding  signers a gain from  the Medica l Charts t ab.";
  193                                      Xrm.Page .ui.setFor mNotificat ion(msg, " ERROR", "p reIntegrat ionError") ;
  194                             }
  195                    }
  196                    else {
  197                             //miss ing settin gs
  198                             var ms g = "API U RLs missin g from Act ive Settin gs record.  Contact y our admini strator";
  199                             Xrm.Pa ge.ui.setF ormNotific ation(msg,  "ERROR",  "preIntegr ationError ");
  200                    }
  201           }
  202           ca tch(e){
  203                    aler t("VistACP RSAddition alSignersF ormScript. integrateA dditionalS igners() e rror: " +  err.messag e);
  204           }
  205   }
  206  
  207   function p romptForVI ALogin(pMe ssage){
  208           // alert(pMes sage);
  209           Xr m.Page.ui. tabs.get(' Tab_VistAL ogin').set Visible(tr ue);
  210           Xr m.Page.ui. tabs.get(' Tab_VistAL ogin').set Focus();
  211   }
  212  
  213   function v cmn_finali zeNoteCrea tion(vcmn_ integratio nStatus, v cmn_integr ationNoteI d, vcmn_no teDescript ion) {
  214           // kknab
  215           re turn;
  216           
  217       var vc mn_selecte dSigners =  Xrm.Page. getAttribu te('ftp_se lectedsign ers').getV alue();
  218           if  (vcmn_sel ectedSigne rs != null  && vcmn_s electedSig ners != '' ) {
  219                    //Ad ditional S igners exi st in CRM,  verify se ssion vari ables
  220                    var  vcmn_selec tedArray =  vcmn_sele ctedSigner s.split('~ ~~');
  221                    var  vcmn_selec tedArrayRe cordCount  = vcmn_sel ectedArray .length;
  222                    if ( vcmn_selec tedArrayRe cordCount  > 1) {
  223                             vcmn_A ddlSigners NameArray  = vcmn_sel ectedArray ;
  224                    }
  225  
  226                    var  vcmn_selec tedIENArra y = '';
  227                    var  vcmn_selec tedIENArra yRecordCou nt = 0;
  228                    var  vcmn_progr essNoteId  = Xrm.Page .data.enti ty.getId() ;
  229  
  230                    var  vcmn_array Mismatch =  false;
  231  
  232                    //Ge t Note's B rowser Loc al Storage  Values
  233                    if ( vcmn_progr essNoteId  != null &&  vcmn_prog ressNoteId  != '') {
  234                             vcmn_l ocalStorag eVarName =  "PN" + vc mn_progres sNoteId;
  235                             var vc mn_localSt orageStrin gValue = l ocalStorag e.getItem( vcmn_local StorageVar Name);
  236                             if (vc mn_localSt orageStrin gValue !=  null && vc mn_localSt orageStrin gValue !=  '') {
  237                                      vcmn_sel ectedIENAr ray = vcmn _localStor ageStringV alue.split ('~~~');
  238                                      vcmn_sel ectedIENAr rayRecordC ount = vcm n_selected IENArray.l ength;
  239                                      if (vcmn _selectedI ENArrayRec ordCount >  1) {
  240                                               vcmn_AddlS ignersIenA rray = vcm n_selected IENArray;
  241                                      }
  242                             }
  243                    }
  244                    //Co mpare CRM  signer arr ay length  with Local Storage ar ray length
  245                    if ( vcmn_selec tedArrayRe cordCount  != vcmn_se lectedIENA rrayRecord Count) { v cmn_arrayM ismatch =  true; }
  246  
  247                    if ( vcmn_array Mismatch = = true) {
  248                             alert( "The count  of Additi onal Signe rs selecte d in CRM,  does not m atch the c ount of Ad ditional S igners in  VISTA!\n\n Please rem ove all th e addition al signers  on this P rogress No te and per form the s election p rocess aga in!\n\nThi s note can not be int egrated wi th VISTA/C PRS until  this has b een resolv ed.");
  249                             vcmn_s ignThisNot eFailure =  true;
  250                    }
  251                    else  {
  252                             //Chec k if VIA L ogin cooki e exist (n ot expired )
  253                             var vc mn_ViaLogi nCookie =  vcmn_getCo okie("vias essionlink ");
  254                             if (vc mn_ViaLogi nCookie ==  "") {
  255                                      alert("Y our VISTA  session ha s expired.  In order  to process  a note wi th additio nal signer s, you mus t be logge d into VIS TA!");
  256                                      Xrm.Page .ui.tabs.g et('Tab_Vi stALogin') .setVisibl e(true);
  257                                      Xrm.Page .ui.tabs.g et('Tab_Vi stALogin') .setFocus( );
  258                                      vcmn_sig nThisNoteF ailure = t rue;
  259                                      return;
  260                             }
  261                    }
  262           }
  263           
  264       try {
  265           // Determine  if additio nal signer s exists
  266           if  (vcmn_Add lSignersNa meArray !=  null && v cmn_AddlSi gnersIenAr ray != nul l) {
  267                //Get th e current  CRM User's  assigned  site/facil ity
  268                var vcmn _userSiteI d = "";
  269                var vcmn _UserSiteN o = "";
  270                var vcmn _duz = "";
  271                var vcmn _providern ame = "";
  272  
  273                var vcmn _userData  = vcmn_get SingleEnti tyDataSync ('SystemUs erSet', 'f tp_Facilit ySiteId',  Xrm.Page.c ontext.get UserId());
  274                if (vcmn _userData  != null) {
  275                    if ( vcmn_userD ata.d.ftp_ FacilitySi teId != nu ll) {
  276                         vcmn_userS iteId = vc mn_userDat a.d.ftp_Fa cilitySite Id.Id;
  277                    }
  278                }
  279  
  280                //Lookup  the Facil ity/Site #
  281                if (vcmn _userSiteI d != null  && vcmn_us erSiteId ! = '') {
  282                    var  vcmn_facil ityData =  vcmn_getSi ngleEntity DataSync(' ftp_facili tySet', 'f tp_facilit ycode', vc mn_userSit eId);
  283                    if ( vcmn_facil ityData !=  null) {
  284                         if (vcmn_f acilityDat a.d.ftp_fa cilitycode  != null)  { vcmn_Use rSiteNo =  vcmn_facil ityData.d. ftp_facili tycode; }
  285                    }
  286                }
  287  
  288                //Check  if VIA Log in cookie  exist (not  expired)
  289                var vcmn _ViaLoginC ookie = vc mn_getCook ie("viases sionlink") ;
  290                if (vcmn _ViaLoginC ookie != n ull && vcm n_ViaLogin Cookie !=  '') {
  291                    var  vcmn_cooki earray = v cmn_ViaLog inCookie.s plit("~~~~ ", 2);
  292                    vcmn _duz = vcm n_cookiear ray[0];
  293                    vcmn _providern ame = vcmn _cookiearr ay[1];
  294                }
  295  
  296                //Create  text stri ngs from a dditional  signers ar ray
  297                var vcmn _SignerIEN  = "";
  298                for (var  i = 0; i  <= vcmn_Ad dlSignersI enArray.le ngth - 1;  i++) {
  299                    if ( i == 1) {  vcmn_Signe rIEN = vcm n_AddlSign ersIenArra y[i]; }
  300                    if ( i > 1) { v cmn_Signer IEN = vcmn _SignerIEN  + " " + v cmn_AddlSi gnersIenAr ray[i]; }
  301                }
  302  
  303                //Create  the Addit ional Sign ers
  304                var vcmn _viaSigner s = new Ob ject();
  305                vcmn_via Signers.Pr oviderName  = vcmn_pr ovidername ;
  306                vcmn_via Signers.Du z = vcmn_d uz;
  307                vcmn_via Signers.Lo ginSiteCod e = vcmn_U serSiteNo;
  308                vcmn_via Signers.Ta rget = vcm n_integrat ionNoteId;
  309                vcmn_via Signers.Su pplemental Parameters  = vcmn_Si gnerIEN;
  310  
  311                $.ajax({
  312                    type : "POST",
  313                    url:  vcmn_AddS ignersUrl,
  314                    data : JSON.str ingify(vcm n_viaSigne rs),
  315                    cont entType: " applicatio n/json; ch arset=utf- 8",
  316                    data Type: "jso n",
  317                    succ ess: funct ion (data)  {
  318                         vcmn_viaSi gnersRespo nse = JSON .stringify (data.Data );
  319                         //Test for  Failure
  320                         if (vcmn_v iaSignersR esponse.Er rorOccurre d == true)  {
  321                             alert( "Error: Un able to ad d the addi tional sig ners selec ted to thi s note.\n\ nPlease re view the n ote and si gners in y our Vista/ CPRS appli cation!");
  322                         }
  323                    },
  324                    erro r: functio n (jqXHR,  textStatus , errorThr own) {
  325                         //System E rror
  326                         alert("Err or: Unable  to add th e addition al signers  selected  to this no te.\n\nPle ase review  the note  and signer s in your  Vista/CPRS  applicati on!");
  327                    },
  328                    asyn c: false,
  329                    cach e: false
  330                });
  331  
  332                if (vcmn _localStor ageVarName  != "" &&  vcmn_local StorageVar Name != nu ll) {
  333                    //Cl ear existi ng session  storage v ariable.
  334                    loca lStorage.r emoveItem( vcmn_local StorageVar Name);
  335                }
  336           }
  337  
  338           // Perform st andard for m updates  to signify  completio n
  339           // Write Succ ess entry
  340           Xr m.Page.get Attribute( 'ftp_noted etail').se tValue(vcm n_noteDesc ription);
  341           Xr m.Page.get Attribute( 'ftp_noted etail').se tSubmitMod e('always' );
  342           Xr m.Page.get Attribute( 'ftp_integ rationstat us').setVa lue(vcmn_i ntegration Status);
  343           Xr m.Page.get Attribute( 'ftp_integ rationstat us').setSu bmitMode(' always');
  344           Xr m.Page.get Attribute( 'ftp_integ rationerro r').setVal ue(null);
  345           Xr m.Page.get Attribute( 'ftp_integ rationerro r').setSub mitMode('a lways');
  346           Xr m.Page.get Attribute( 'ftp_integ rationdate ').setValu e(new Date ());
  347           Xr m.Page.get Attribute( 'ftp_integ rationdate ').setSubm itMode('al ways');
  348           Xr m.Page.get Attribute( 'ftp_integ rationnote id').setVa lue(vcmn_i ntegration NoteId);
  349           Xr m.Page.get Attribute( 'ftp_integ rationnote id').setSu bmitMode(' always');
  350           Xr m.Page.get Control('f tp_integra tionstatus ').setFocu s();
  351           al ert('The n ote creati on in Vist A/CPRS was  successfu l, this no te will no w be marke d as compl eted. \n\n Please exi t this not e record a fter click ing OK to  this promp t!');
  352           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  353           Xr m.Page.dat a.entity.s ave();
  354       }
  355       catch  (err) {
  356           al ert('Progr ess Note R ibbon Func tion Error (vcmn_fina lizeNoteCr eation): '  + err.mes sage);
  357           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  358       }
  359   }
  360  
  361   function v cmn_ribbon ButtonSave ToVistA()  {
  362           // kknab
  363           re turn;
  364           
  365       try {
  366           // Check the  value of t he Integra tion Statu s Field, i f = 'OK',  stop and e xit this s cript
  367           va r vcmn_int egrationSt atus = Xrm .Page.getA ttribute(' ftp_integr ationstatu s').getVal ue();
  368           if  (vcmn_int egrationSt atus == 'O K') { retu rn false;  }
  369  
  370           // Prompt use r to sign  the note
  371           va r vcmn_sig nThisNote  = Xrm.Page .getAttrib ute('ftp_s ignthisnot e').getVal ue();
  372           va r vcmn_sig nThisNoteF ailure = f alse;
  373           if  (vcmn_sig nThisNote  == null) {
  374                Xrm.Util ity.confir mDialog(
  375                    "Do  you need t o sign thi s note?, S elect OK i f Yes, oth erwise CAN CEL.",
  376                    func tion () {
  377                         //Check if  VIA Login  cookie ex ist (not e xpired)
  378                         var vcmn_V iaLoginCoo kie = vcmn _getCookie ("viasessi onlink");
  379                         //Prompt u ser to log in to VIA
  380                         if (vcmn_V iaLoginCoo kie == "")  {
  381                             alert( "Your VIST A session  has expire d. In orde r to sign  this note,  you must  be logged  into VISTA !");
  382                             Xrm.Pa ge.ui.tabs .get('Tab_ VistALogin ').setVisi ble(true);
  383                             Xrm.Pa ge.ui.tabs .get('Tab_ VistALogin ').setFocu s();
  384                             vcmn_s ignThisNot eFailure =  true;
  385                             return ;
  386                         }
  387                         Xrm.Page.g etAttribut e('ftp_sig nthisnote' ).setValue (100000001 );
  388                    },
  389                    func tion () {
  390                         Xrm.Page.g etAttribut e('ftp_sig nthisnote' ).setValue (100000000 );
  391                    }
  392                );
  393                Xrm.Page .getAttrib ute('ftp_s ignthisnot e').setSub mitMode('a lways');
  394           }
  395  
  396           // Check for  additional  signers,  if they ex ist, the u ser must b e logged i nto VIA to  continue  process.
  397           // Additional  Signature s must als o be in sy nc with ma tching Ses sion varia bles
  398  
  399           vc mn_AddlSig nersNameAr ray = null ;
  400           vc mn_AddlSig nersIenArr ay = null;
  401  
  402           va r vcmn_sel ectedSigne rs = Xrm.P age.getAtt ribute('ft p_selected signers'). getValue() ;
  403           if  (vcmn_sel ectedSigne rs != null  && vcmn_s electedSig ners != '' ) {
  404                //Additi onal Signe rs exist i n CRM, ver ify sessio n variable s
  405                var vcmn _selectedA rray = vcm n_selected Signers.sp lit('~~~') ;
  406                var vcmn _selectedA rrayRecord Count = vc mn_selecte dArray.len gth;
  407                if (vcmn _selectedA rrayRecord Count > 1)  {
  408                    vcmn _AddlSigne rsNameArra y = vcmn_s electedArr ay;
  409                }
  410  
  411                var vcmn _selectedI ENArray =  '';
  412                var vcmn _selectedI ENArrayRec ordCount =  0;
  413                var vcmn _progressN oteId = Xr m.Page.dat a.entity.g etId();
  414  
  415                var vcmn _arrayMism atch = fal se;
  416  
  417                //Get No te's Brows er Local S torage Val ues
  418                if (vcmn _progressN oteId != n ull && vcm n_progress NoteId !=  '') {
  419                    vcmn _localStor ageVarName  = "PN" +  vcmn_progr essNoteId;
  420                    var  vcmn_local StorageStr ingValue =  localStor age.getIte m(vcmn_loc alStorageV arName);
  421                    if ( vcmn_local StorageStr ingValue ! = null &&  vcmn_local StorageStr ingValue ! = '') {
  422                         vcmn_selec tedIENArra y = vcmn_l ocalStorag eStringVal ue.split(' ~~~');
  423                         vcmn_selec tedIENArra yRecordCou nt = vcmn_ selectedIE NArray.len gth;
  424                         if (vcmn_s electedIEN ArrayRecor dCount > 1 ) {
  425                             vcmn_A ddlSigners IenArray =  vcmn_sele ctedIENArr ay;
  426                         }
  427                    }
  428                }
  429                //Compar e CRM sign er array l ength with  LocalStor age array  length
  430                if (vcmn _selectedA rrayRecord Count != v cmn_select edIENArray RecordCoun t) { vcmn_ arrayMisma tch = true ; }
  431  
  432                if (vcmn _arrayMism atch == tr ue) {
  433                    aler t("The cou nt of Addi tional Sig ners selec ted in CRM , does not  match the  count of  Additional  Signers i n VISTA!\n \nPlease r emove all  the additi onal signe rs on this  Progress  Note and p erform the  selection  process a gain!\n\nT his note c annot be i ntegrated  with VISTA /CPRS unti l this has  been reso lved.");
  434                    vcmn _signThisN oteFailure  = true;
  435                }
  436                else {
  437                    //Ch eck if VIA  Login coo kie exist  (not expir ed)
  438                    var  vcmn_ViaLo ginCookie  = vcmn_get Cookie("vi asessionli nk");
  439                    if ( vcmn_ViaLo ginCookie  == "") {
  440                         alert("You r VISTA se ssion has  expired. I n order to  process a  note with  additiona l signers,  you must  be logged  into VISTA !");
  441                         Xrm.Page.u i.tabs.get ('Tab_Vist ALogin').s etVisible( true);
  442                         Xrm.Page.u i.tabs.get ('Tab_Vist ALogin').s etFocus();
  443                         vcmn_signT hisNoteFai lure = tru e;
  444                         return;
  445                    }
  446                }
  447           }
  448  
  449           // Check if m arked as a  workload  encounter  and if so  enforce VI A Login
  450           if  (Xrm.Page .getAttrib ute('ftp_i sworkloade ncounter') .getValue( ) == true)  {
  451                //Check  if VIA Log in cookie  exist (not  expired)
  452                var vcmn _ViaLoginC ookie = vc mn_getCook ie("viases sionlink") ;
  453                if (vcmn _ViaLoginC ookie == " ") {
  454                    aler t("Your VI STA sessio n has expi red. In or der to pro cess a wor kload enco unter note , you must  be logged  into VIST A!");
  455                    Xrm. Page.ui.ta bs.get('Ta b_VistALog in').setVi sible(true );
  456                    Xrm. Page.ui.ta bs.get('Ta b_VistALog in').setFo cus();
  457                    vcmn _signThisN oteFailure  = true;
  458                    retu rn;
  459                }
  460           }
  461  
  462           if  (vcmn_sig nThisNoteF ailure ==  true) {
  463                //****** Developer  Bypass for  no VISTA  authentica tion******
  464                if ((Xrm .Page.cont ext.getUse rId()).toU pperCase()  == "{CA50 0504-CBC5- E511-8173- 000C2941CE 19}" || (X rm.Page.co ntext.getU serId()).t oUpperCase () == "{EB 21BC63-81B F-E511-942 C-0050568D 743D}") {
  465                    aler t("Develop er VISTA a uthenticat ion bypass  applied!" );
  466                    Xrm. Page.getAt tribute('f tp_signthi snote').se tValue(100 000001);
  467                    Xrm. Page.getAt tribute('f tp_signthi snote').se tSubmitMod e('always' );
  468                }
  469                else {
  470                    retu rn false;
  471                }
  472           }
  473  
  474           // Save the c urrent CRM  data
  475           Xr m.Page.dat a.entity.s ave();
  476           // Display YE LLOW Progr ess....
  477           Xr m.Page.ui. setFormNot ification( "Verifying  progress  note data,  please wa it..", "IN FO", "SAVE VISTA");
  478  
  479           va r vcmn_con firmSaveTo Vista = co nfirm('Are  you sure  you want t o save thi s note to  VistA/CPRS ?\nThis ac tion canno t be cance lled!\n\nU pon comple tion of th is process , the prog ress note  will autom atically b e marked a s complete d and you  will be pr ompted to  exit the r ecord!');
  480           if  (vcmn_con firmSaveTo Vista == f alse) {
  481                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  482                return f alse;
  483           }
  484           // Get regard ing data
  485           va r vcmn_req uestId = X rm.Page.ge tAttribute ('regardin gobjectid' ).getValue ();
  486           if  (vcmn_req uestId ==  null) {
  487                alert('T he current  progress  note does  not have a  related r equest ass igned in t he Regardi ng field,  the note c annot be c reated in  VistA/CPRS !');
  488                Xrm.Page .getContro l('regardi ngobjectid ').setFocu s();
  489                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  490                return f alse;
  491           }
  492           // Verify tha t the rega rdingid is  of type ' incident'
  493           if  (vcmn_req uestId[0]. entityType  != 'incid ent') {
  494                alert('T he current  progress  note has a n invalid  regarding  type, it m ust be of  the type r equest/inc ident, the  note cann ot be crea ted in Vis tA/CPRS!') ;
  495                Xrm.Page .getContro l('regardi ngobjectid ').setFocu s();
  496                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  497                return f alse;
  498           }
  499  
  500           // Preserved  Variables
  501           va r vcmn_vet eranId = n ull;  //Fr om request  customeri d
  502           va r vcmn_vet eranFirstN ame = '';
  503           va r vcmn_vet eranLastNa me = '';
  504           va r vcmn_SSN  = '';
  505           va r vcmn_DOB  = '';
  506  
  507           va r vcmn_req uestData =  vcmn_getS ingleEntit yDataSync( 'IncidentS et', 'Cust omerId', v cmn_reques tId[0].id) ;
  508           if  (vcmn_req uestData ! = null) {
  509                if (vcmn _requestDa ta.d.Custo merId != n ull) {
  510                    vcmn _veteranId  = vcmn_re questData. d.Customer Id;
  511                    //Ve rify that  the custom erid is of  type cont act
  512                    if ( vcmn_veter anId.Logic alName !=  'contact')  {
  513                         alert('The  related r equest has  an invali d customer  type, it  must be of  the type  veteran/co ntact, the  note cann ot be crea ted in Vis tA/CPRS!') ;
  514                         Xrm.Page.u i.clearFor mNotificat ion("SAVEV ISTA");
  515                         return fal se;
  516                    }
  517                }
  518           }
  519           if  (vcmn_vet eranId ==  null) {
  520                alert('T he related  request d oes not ha ve a veter an/contact  assigned,  the note  cannot be  created in  VistA/CPR S!');
  521                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  522                return f alse;
  523           }
  524  
  525           va r vcmn_con tactData =  vcmn_getS ingleEntit yDataSync( 'ContactSe t', 'First Name, Last Name, ftp_ DateofBirt h, Governm entId', vc mn_veteran Id.Id);
  526           if  (vcmn_con tactData ! = null) {
  527                if (vcmn _contactDa ta.d.First Name != nu ll) { vcmn _veteranFi rstName =  vcmn_conta ctData.d.F irstName;  }
  528                if (vcmn _contactDa ta.d.LastN ame != nul l) { vcmn_ veteranLas tName = vc mn_contact Data.d.Las tName; }
  529                if (vcmn _contactDa ta.d.ftp_D ateofBirth  != null)  { vcmn_DOB  = vcmn_co ntactData. d.ftp_Date ofBirth; }
  530                if (vcmn _contactDa ta.d.Gover nmentId !=  null) { v cmn_SSN =  vcmn_conta ctData.d.G overnmentI d; }
  531           }
  532  
  533           // **WORKLOAD  ENCOUNTER **
  534           vc mn_matchLo okupId = v cmn_SSN;
  535           // ********** ********** ***
  536  
  537           // Perform MV I Search
  538           vc mn_unatten dedMviSear ch(vcmn_ve teranFirst Name, vcmn _veteranLa stName, vc mn_DOB, vc mn_SSN);
  539       }
  540       catch  (err) {
  541           al ert('Progr ess Note R ibbon Func tion Error (vcmn_ribb onButtonSa veToVistA) : ' + err. message);
  542           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  543       }
  544   }
  545  
  546   function v cmn_ribbon ButtonSave ToVistA_wi th_ICN(vcm n_patientI CN) {
  547           // kknab
  548           re turn;
  549           
  550       try {
  551           // ******Deve loper Bypa ss for mis sing ICN** ****
  552           if  (vcmn_pat ientICN ==  '' || vcm n_patientI CN == null ) {
  553                if ((Xrm .Page.cont ext.getUse rId()).toU pperCase()  == "{CA50 0504-CBC5- E511-8173- 000C2941CE 19}") {
  554                    aler t("Develop er ICN byp ass applie d!");
  555                    vcmn _patientIC N = "12345 6V123456";
  556                }
  557           }
  558  
  559           // Verify Pat ient ICN
  560           if  (vcmn_pat ientICN ==  '' || vcm n_patientI CN == null ) {
  561                alert('T he assigne d veteran  does not h ave a pati ent ICN, t he note ca nnot be cr eated in V istA/CPRS! ');
  562                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  563                return f alse;
  564           }
  565  
  566           // Get regard ing data
  567           va r vcmn_req uestId = X rm.Page.ge tAttribute ('regardin gobjectid' ).getValue ();
  568  
  569           // Preserved  Variables
  570           va r vcmn_vet eranId = n ull;  //Fr om request  customeri d
  571           va r vcmn_vet eranName =  '';
  572           va r vcmn_vet eranFirstN ame = '';
  573           va r vcmn_vet eranLastNa me = '';
  574           va r vcmn_vet eranMiddle Name = '';
  575  
  576           va r vcmn_req uestData =  vcmn_getS ingleEntit yDataSync( 'IncidentS et', 'Cust omerId', v cmn_reques tId[0].id) ;
  577           if  (vcmn_req uestData ! = null) {
  578                if (vcmn _requestDa ta.d.Custo merId != n ull) {
  579                    vcmn _veteranId  = vcmn_re questData. d.Customer Id;
  580                    //Ve rify that  the custom erid is of  type cont act
  581                    if ( vcmn_veter anId.Logic alName !=  'contact')  {
  582                         alert('The  related r equest has  an invali d customer  type, it  must be of  the type  veteran/co ntact, the  note cann ot be crea ted in Vis tA/CPRS!') ;
  583                         Xrm.Page.u i.clearFor mNotificat ion("SAVEV ISTA");
  584                         return fal se;
  585                    }
  586                }
  587           }
  588           if  (vcmn_vet eranId ==  null) {
  589                alert('T he related  request d oes not ha ve a veter an/contact  assigned,  the note  cannot be  created in  VistA/CPR S!');
  590                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  591                return f alse;
  592           }
  593  
  594           va r vcmn_con tactData =  vcmn_getS ingleEntit yDataSync( 'ContactSe t', 'FullN ame, First Name, Last Name, Midd leName', v cmn_vetera nId.Id);
  595           if  (vcmn_con tactData ! = null) {
  596                if (vcmn _contactDa ta.d.FullN ame != nul l) { vcmn_ veteranNam e = vcmn_c ontactData .d.FullNam e; }
  597                if (vcmn _contactDa ta.d.First Name != nu ll) { vcmn _veteranFi rstName =  vcmn_conta ctData.d.F irstName;  }
  598                if (vcmn _contactDa ta.d.LastN ame != nul l) { vcmn_ veteranLas tName = vc mn_contact Data.d.Las tName; }
  599                if (vcmn _contactDa ta.d.Middl eName != n ull) { vcm n_veteranM iddleName  = vcmn_con tactData.d .MiddleNam e; }
  600           }
  601  
  602           // Get user d ata
  603           va r vcmn_crm UserId = X rm.Page.ge tAttribute ('ownerid' ).getValue ();
  604           va r vcmn_use rDomainId  = '';
  605           va r vcmn_use rFirstName  = '';
  606           va r vcmn_use rLastName  = '';
  607           va r vcmn_use rMiddleNam e = '';
  608           va r vcmn_use rSiteId =  '';
  609  
  610           if  (vcmn_crm UserId !=  null) {
  611                //Verify  the owner  type
  612                if (vcmn _crmUserId [0].entity Type != 's ystemuser' ) {
  613                    aler t('The pro gress note  owner mus t be an in dividual u ser and no t a team,  the note c annot be c reated in  VistA/CPRS !');
  614                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  615                    retu rn false;
  616                }
  617  
  618                var vcmn _userData  = vcmn_get SingleEnti tyDataSync ('SystemUs erSet', 'D omainName,  FirstName , LastName , MiddleNa me, ftp_Fa cilitySite Id', vcmn_ crmUserId[ 0].id);
  619                if (vcmn _userData  != null) {
  620                    if ( vcmn_userD ata.d.Doma inName !=  null) { vc mn_userDom ainId = vc mn_userDat a.d.Domain Name; }
  621                    if ( vcmn_userD ata.d.Firs tName != n ull) { vcm n_userFirs tName = vc mn_userDat a.d.FirstN ame; }
  622                    if ( vcmn_userD ata.d.Last Name != nu ll) { vcmn _userLastN ame = vcmn _userData. d.LastName ; }
  623                    if ( vcmn_userD ata.d.Midd leName !=  null) { vc mn_userMid dleName =  vcmn_userD ata.d.Midd leName; }
  624                    if ( vcmn_userD ata.d.ftp_ FacilitySi teId != nu ll) { vcmn _userSiteI d = vcmn_u serData.d. ftp_Facili tySiteId.I d; }
  625                }
  626           }
  627           el se {
  628                alert('U nable to v erify the  user accou nt for the  current a uthor/owne r assigned  to this n ote, the n ote cannot  be create d in VistA /CPRS!');
  629                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  630                return f alse;
  631           }
  632  
  633           // Verify tha t the curr ent owner  and the cu rrent user  is the sa me person,  if not do  not proce ed
  634           if  ((vcmn_cr mUserId[0] .id).toUpp erCase() ! = (Xrm.Pag e.context. getUserId( )).toUpper Case()) {
  635                alert('T he current  author/ow ner does n ot match t he current  CRM user,  the note  cannot be  created in  VistA/CPR S!');
  636                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  637                return f alse;
  638           }
  639           va r vcmn_Not eUserTeam  = "NONE";
  640           // Check Team  membershi p
  641           if  (vcmn_Use rHasTeam(" Pharmacy",  Xrm.Page. context.ge tUserId()) ) { vcmn_N oteUserTea m = "PHARM ACY"; }
  642           if  (vcmn_Use rHasTeam(" CCA Team",  Xrm.Page. context.ge tUserId()) ) { vcmn_N oteUserTea m = "CCA";  }
  643           if  (vcmn_Use rHasTeam(" TAN", Xrm. Page.conte xt.getUser Id())) { v cmn_NoteUs erTeam = " TAN"; }
  644           // **TEMP, ve rify these  team valu es that th ey are cor rect **FUT URE NEED**
  645           if  (vcmn_Use rHasTeam(" PACT User" , Xrm.Page .context.g etUserId() )) { vcmn_ NoteUserTe am = "PACT "; }
  646           if  (vcmn_Use rHasTeam(" MSA User",  Xrm.Page. context.ge tUserId()) ) { vcmn_N oteUserTea m = "MSA";  }
  647  
  648           // Verify Tea m Value, t hat one ha s been ass igned
  649           if  (vcmn_Not eUserTeam  == "NONE")  {
  650                alert('T he current  author/ow ner does n ot belong  to a CRM t eam that c an integra te notes,  the note c annot be c reated in  VistA/CPRS !');
  651                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  652                return f alse;
  653           }
  654  
  655           // Get reques t form con tent
  656           va r vcmn_not eDescripti on = Xrm.P age.getAtt ribute('ft p_notedeta il').getVa lue();
  657           if  (vcmn_not eDescripti on == null  || vcmn_n oteDescrip tion == '' ) {
  658                alert('T he note de scription  field is e mpty, the  note canno t be creat ed in Vist A/CPRS!');
  659                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  660                return f alse;
  661           }
  662  
  663           if  (Xrm.Page .getAttrib ute('ftp_i sworkloade ncounter') .getValue( ) != true)  {
  664                //Using  new hospit al locatio n and loca l notes lo okup field s
  665                var vcmn _localTitl e = Xrm.Pa ge.getAttr ibute('ftp _localnote title').ge tValue();
  666                if (vcmn _localTitl e == null)  {
  667                    aler t('The loc al note ti tle field  is empty,  the note c annot be c reated in  VistA/CPRS !');
  668                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  669                    retu rn false;
  670                }
  671                else { v cmn_localT itle = vcm n_localTit le[0].name ; }
  672  
  673                vcmn_pat ientAssign edLocation  = Xrm.Pag e.getAttri bute('ftp_ notehospit allocation ').getValu e();
  674                if (vcmn _patientAs signedLoca tion == nu ll) {
  675                    aler t('The hos pital loca tion field  is empty,  the note  cannot be  created in  VistA/CPR S!');
  676                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  677                    retu rn false;
  678                }
  679                else { v cmn_patien tAssignedL ocation =  vcmn_patie ntAssigned Location[0 ].name; }
  680           }
  681  
  682           va r vcmn_cal lbackNumbe r = Xrm.Pa ge.getAttr ibute('ftp _callbackn umber').ge tValue();
  683           if  (vcmn_cal lbackNumbe r == null  || vcmn_ca llbackNumb er == '')  {
  684                alert('T he callbac k number f ield is em pty, the n ote cannot  be create d in VistA /CPRS!');
  685                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  686                return f alse;
  687           }
  688           va r vcmn_rea sonForRequ est = Xrm. Page.getAt tribute('f tp_reasonf orrequest' ).getValue ();
  689           if  (vcmn_rea sonForRequ est == nul l) {
  690                alert('T he reason  for reques t field is  empty, th e note can not be cre ated in Vi stA/CPRS!' );
  691                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  692                return f alse;
  693           }
  694  
  695           va r vcmn_enc ounterCode  = 'NEW';
  696  
  697           va r vcmn_sig nThisNote  = Xrm.Page .getAttrib ute('ftp_s ignthisnot e').getVal ue();
  698           if  (vcmn_sig nThisNote  == 1000000 01) { vcmn _signThisN ote = true ; } else {  vcmn_sign ThisNote =  false; }
  699  
  700           // Get Progre ss Note Gu id/Id
  701           va r vcmn_not eId = Xrm. Page.data. entity.get Id();
  702  
  703           // Get Create d On Date  & Convert  format
  704           va r vcmn_cre atedOnDate  = vcmn_co nvertCrmDa teToVistAD ate(Xrm.Pa ge.getAttr ibute('cre atedon').g etValue()) ;
  705           if  (vcmn_cre atedOnDate  == null)  {
  706                alert('T he CRM cre atedon fie ld is empt y, the not e cannot b e created  in VistA/C PRS!');
  707                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  708                return f alse;
  709           }
  710  
  711           // Get User E ntry Date
  712           va r vcmn_use rEntryDate  = vcmn_co nvertCrmDa teToVistAD ate(Xrm.Pa ge.getAttr ibute('ftp _userentry date').get Value());
  713           if  (vcmn_use rEntryDate  == null)  { vcmn_use rEntryDate  = vcmn_cr eatedOnDat e; }
  714  
  715           // Get Facili ty and loo kup facili ty number  and HL7 UR L
  716           va r vcmn_fac ilityCode  = '';
  717           va r vcmn_sit eHL7Listen erAddress  = '';
  718           va r vcmn_pat ientFacili ty = Xrm.P age.getAtt ribute('ft p_patientf acility'). getValue() ;
  719           if  (vcmn_pat ientFacili ty == null ) {
  720                alert('T he CRM pat ient facil ity field  is empty,  the note c annot be c reated in  VistA/CPRS !');
  721                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  722                return f alse;
  723           }
  724           el se {
  725                var vcmn _facilityD ata = vcmn _getSingle EntityData Sync('ftp_ facilitySe t', 'ftp_f acilitycod e, ftp_hl7 listener',  vcmn_pati entFacilit y[0].id);
  726                if (vcmn _facilityD ata.d.ftp_ facilityco de != null ) {
  727                    vcmn _facilityC ode = vcmn _facilityD ata.d.ftp_ facilityco de;
  728                }
  729                else {
  730                    aler t('The CRM  patient f acility co de is miss ing in the  Facility  setup, the  note cann ot be crea ted in Vis tA/CPRS!') ;
  731                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  732                    retu rn false;
  733                }
  734  
  735                if (vcmn _facilityD ata.d.ftp_ hl7listene r != null)  {
  736                    var  vcmn_siteH L7Listener Address =  vcmn_facil ityData.d. ftp_hl7lis tener;
  737                }
  738                else {
  739                    aler t('The CRM  HL7 liste ner addres s is missi ng in the  Facility s etup, the  note canno t be creat ed in Vist A/CPRS!');
  740                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  741                    retu rn false;
  742                }
  743           }
  744  
  745           va r vcmn_ori ginatorID  = '';
  746           va r vcmn_use rSiteNo =  '';
  747  
  748           // Lookup the  Facility/ Site #
  749           if  (vcmn_use rSiteId !=  null && v cmn_userSi teId != '' ) {
  750                var vcmn _facilityD ata = vcmn _getSingle EntityData Sync('ftp_ facilitySe t', 'ftp_f acilitycod e', vcmn_u serSiteId) ;
  751                if (vcmn _facilityD ata != nul l) {
  752                    if ( vcmn_facil ityData.d. ftp_facili tycode !=  null) { vc mn_userSit eNo = vcmn _facilityD ata.d.ftp_ facilityco de; }
  753                }
  754           }
  755  
  756           // Validate r equired Vi sta Lookup  info
  757           if  (vcmn_use rSiteNo ==  '' || vcm n_userSite No == null  || vcmn_u serFirstNa me == '' | | vcmn_use rFirstName  == null | | vcmn_use rLastName  == '' || v cmn_userLa stName ==  null) {
  758                //Abort  process, m issing inf o
  759                alert('O ne of the  following  required C RM user da ta fields  are missin g: Facilty  No, First  Name or L ast Name,  the note c annot be c reated in  VistA/CPRS !');
  760                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  761                return f alse;
  762           }
  763  
  764           if  (Xrm.Page .getAttrib ute('ftp_i sworkloade ncounter') .getValue( ) != true)  {
  765                if (vcmn _IsProduct ionEnviron ment == fa lse) {
  766                    //Pr ovide the  option to  search for  Lori Nich olls, site # 613
  767                    var  vcmn_imper sonateProm ptString =  "**THIS I S A VISTA  USER SEARC H TEST PRO MPT** \n"  +
  768                         "If you wo uld like t o imperson ate the us er: \n" +
  769                         "Lori Nich olls (613)  \n" +
  770                         "Select OK .  Otherwi se, select  CANCEL.";
  771                    var  vcmn_confi rmImperson ateVistaUs er = confi rm(vcmn_im personateP romptStrin g);
  772                    if ( vcmn_confi rmImperson ateVistaUs er == true ) {
  773                         vcmn_userF irstName =  "Lori";
  774                         vcmn_userL astName =  "Nicholls" ;
  775                         vcmn_userS iteNo = "6 13";
  776                    }
  777                }
  778  
  779                var vcmn _vistauser sData = vc mn_getVist aUsersData (vcmn_user FirstName,  vcmn_user LastName,  vcmn_userS iteNo, fal se);
  780  
  781                //Check  vista user s data con tent
  782                if (vcmn _vistauser sData == n ull || vcm n_vistause rsData.Dat a == null  || vcmn_vi stausersDa ta.Data.le ngth == nu ll || vcmn _vistauser sData.Data .length ==  0) {
  783                    //Ab ort proces s, missing  info
  784                    aler t('Unable  to obtain  Vista User  Data, the  note cann ot be crea ted in Vis tA/CPRS!') ;
  785                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  786                    retu rn false;
  787                }
  788  
  789                var vcmn _selectedU serFirstNa me = '';
  790                var vcmn _selectedU serMiddleN ame = '';
  791                var vcmn _selectedU serLastNam e = '';
  792                var vcmn _selectedU serSuffix  = '';
  793                var vcmn _selectedU serDisplay Name = '';
  794                var vcmn _selectedU serTitle =  '';
  795                var vcmn _userIsSel ected = fa lse;
  796  
  797                if (vcmn _vistauser sData.Data .length >  1) {
  798                    aler t("The Vis ta User li st, contai ns more th an one use r, please  select the  Vista Use r you want  to use fr om the nex t prompt(s ), a total  of " + vc mn_vistaus ersData.Da ta.length  + " users! ");
  799                    for  (var i = 0 ; i <= vcm n_vistause rsData.Dat a.length -  1; i++) {
  800                         var vcmn_c urrentUser FirstName  = '';
  801                         var vcmn_c urrentUser MiddleName  = '';
  802                         var vcmn_c urrentUser LastName =  '';
  803                         var vcmn_c urrentUser Suffix = ' ';
  804                         var vcmn_c urrentUser DisplayNam e = '';
  805                         var vcmn_c urrentUser Title = '' ;
  806                         if (vcmn_v istausersD ata.Data[i ].FirstNam e != null)  { vcmn_cu rrentUserF irstName =  vcmn_vist ausersData .Data[i].F irstName;  }
  807                         if (vcmn_v istausersD ata.Data[i ].MiddleNa me != null ) { vcmn_c urrentUser MiddleName  = vcmn_vi stausersDa ta.Data[i] .MiddleNam e; }
  808                         if (vcmn_v istausersD ata.Data[i ].LastName  != null)  { vcmn_cur rentUserLa stName = v cmn_vistau sersData.D ata[i].Las tName; }
  809                         if (vcmn_v istausersD ata.Data[i ].Suffix ! = null) {  vcmn_curre ntUserSuff ix = vcmn_ vistausers Data.Data[ i].Suffix;  }
  810                         if (vcmn_v istausersD ata.Data[i ].DisplayN ame != nul l) { vcmn_ currentUse rDisplayNa me = vcmn_ vistausers Data.Data[ i].Display Name; }
  811                         if (vcmn_v istausersD ata.Data[i ].Title !=  null) { v cmn_curren tUserTitle  = vcmn_vi stausersDa ta.Data[i] .Title; }
  812                         //Prompt u ser about  this vista  user reco rd
  813                         var vcmn_u serPromptS tring = "C lick OK, t o select t his user.   Otherwise  CANCEL \n " +
  814                             "\n Fi rst Name:  " + vcmn_c urrentUser FirstName  +
  815                             "\n Mi ddle Name:  " + vcmn_ currentUse rMiddleNam e +
  816                             "\n La st Name: "  + vcmn_cu rrentUserL astName +
  817                             "\n Su ffix: " +  vcmn_curre ntUserSuff ix +
  818                             "\n Di splay Name : " + vcmn _currentUs erDisplayN ame +
  819                             "\n Ti tle: " + v cmn_curren tUserTitle ;
  820  
  821                         var vcmn_c onfirmSele ctVistaUse r = confir m(vcmn_use rPromptStr ing);
  822                         if (vcmn_c onfirmSele ctVistaUse r == true)  {
  823                             vcmn_u serIsSelec ted = true ;
  824                             vcmn_s electedUse rFirstName  = vcmn_cu rrentUserF irstName;
  825                             vcmn_s electedUse rMiddleNam e = vcmn_c urrentUser MiddleName ;
  826                             vcmn_s electedUse rLastName  = vcmn_cur rentUserLa stName;
  827                             vcmn_s electedUse rSuffix =  vcmn_curre ntUserSuff ix;
  828                             vcmn_s electedUse rDisplayNa me = vcmn_ currentUse rDisplayNa me;
  829                             vcmn_s electedUse rTitle = v cmn_curren tUserTitle ;
  830                             break;
  831                         }
  832                    }
  833                }
  834                else {
  835                    //Se lect data  from the f irst recor d
  836                    vcmn _userIsSel ected = tr ue;
  837                    if ( vcmn_vista usersData. Data[0].Fi rstName !=  null) { v cmn_select edUserFirs tName = vc mn_vistaus ersData.Da ta[0].Firs tName; }
  838                    if ( vcmn_vista usersData. Data[0].Mi ddleName ! = null) {  vcmn_selec tedUserMid dleName =  vcmn_vista usersData. Data[0].Mi ddleName;  }
  839                    if ( vcmn_vista usersData. Data[0].La stName !=  null) { vc mn_selecte dUserLastN ame = vcmn _vistauser sData.Data [0].LastNa me; }
  840                    if ( vcmn_vista usersData. Data[0].Su ffix != nu ll) { vcmn _selectedU serSuffix  = vcmn_vis tausersDat a.Data[0]. Suffix; }
  841                    if ( vcmn_vista usersData. Data[0].Di splayName  != null) {  vcmn_sele ctedUserDi splayName  = vcmn_vis tausersDat a.Data[0]. DisplayNam e; }
  842                    if ( vcmn_vista usersData. Data[0].Ti tle != nul l) { vcmn_ selectedUs erTitle =  vcmn_vista usersData. Data[0].Ti tle; }
  843                }
  844  
  845                //Check  if a user  was select ed
  846                if (vcmn _userIsSel ected == f alse) {
  847                    aler t('A user  was not se lected fro m the prev ious promp ts, the no te cannot  be created  in VistA/ CPRS!');
  848                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  849                    retu rn false;
  850                }
  851  
  852                //Execut e Integrat ion
  853                vcmn_exe cuteVistAI ntegration Request(vc mn_noteId,  vcmn_note Descriptio n, vcmn_pa tientICN,  vcmn_userD omainId, v cmn_localT itle, vcmn _callbackN umber, vcm n_reasonFo rRequest[0 ].name, vc mn_encount erCode, vc mn_signThi sNote, vcm n_veteranF irstName,  vcmn_veter anLastName , vcmn_use rEntryDate , vcmn_cre atedOnDate , vcmn_sel ectedUserF irstName,  vcmn_selec tedUserMid dleName, v cmn_select edUserLast Name, vcmn _selectedU serSuffix,  vcmn_faci lityCode,  vcmn_origi natorID, v cmn_siteHL 7ListenerA ddress, vc mn_patient AssignedLo cation);
  854  
  855           }
  856           el se {
  857                //Execut e workload  encounter  note inte gration st eps
  858                vcmn_pre pWorkloadE ncounterIn tegrationS tep01();
  859           }
  860       }
  861       catch  (err) {
  862           al ert('Progr ess Note R ibbon Func tion Error (vcmn_ribb onButtonSa veToVistA_ with_ICN):  ' + err.m essage);
  863           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  864       }
  865   }
  866  
  867   var docCoo kies = {
  868       getIte m: functio n (sKey) {
  869           // return dec odeURIComp onent(docu ment.cooki e.replace( new RegExp ("(?:(?:^| .*;)s*" +  encodeURIC omponent(s Key).repla ce(/[-.+*] /g, "$&")  + "s*=s*([ ^;]*).*$)| ^.*$"), "$ 1")) || nu ll;
  870           if  (!sKey) r eturn null ;
  871           va r keys = t his.keys() ;
  872           fo r (var i =  0, l = ke ys.length;  i < l; i+ +) {
  873                if (keys [i].name = = sKey) re turn keys[ i].value;
  874           }
  875       },
  876       setIte m: functio n (sKey, s Value, vEn d, sPath,  sDomain, b Secure) {
  877           if  (!sKey ||  /^(?:expi res|max-ag e|path|dom ain|secure )$/i.test( sKey)) { r eturn fals e; }
  878           va r sExpires  = "";
  879           if  (vEnd) {
  880                switch ( vEnd.const ructor) {
  881                    case  Number:
  882                          sExpires =  vEnd ===  Infinity ?  "; expire s=Fri, 31  Dec  PORT  23:59:59  GMT" : ";  max-age="  + vEnd;
  883                         break;
  884                    case  String:
  885                         sExpires =  "; expire s=" + vEnd ;
  886                         break;
  887                    case  Date:
  888                         sExpires =  "; expire s=" + vEnd .toUTCStri ng();
  889                         break;
  890                }
  891           }
  892           va r newCooki e = encode URICompone nt(sKey) +  "=" + enc odeURIComp onent(sVal ue) + sExp ires + (sD omain ? ";  domain="  + sDomain  : "") + (s Path ? ";  path=" + s Path : "")  + (bSecur e ? "; sec ure" : "") ;
  893           do cument.coo kie = newC ookie;
  894           re turn true;
  895       },
  896       remove Item: func tion (sKey , sPath, s Domain) {
  897           if  (!sKey ||  !this.has Item(sKey) ) { return  false; }
  898           va r removalC ookie = en codeURICom ponent(sKe y) + "=; e xpires=Thu , 01 Jan 1 970 00:00: 00 GMT"/*  + (sDomain  ? "; doma in=" + sDo main : "")  + (sPath  ? "; path= " + sPath  : "")*/;
  899           do cument.coo kie = remo valCookie;
  900           re turn true;
  901       },
  902       hasIte m: functio n (sKey) {
  903           // return (ne w RegExp(" (?:^|;s*)"  + encodeU RIComponen t(sKey).re place(/[-. +*]/g, "$& ") + "s*=" )).test(do cument.coo kie);
  904           if  (!sKey) r eturn fals e;
  905           va r keys = t his.keys() ;
  906           fo r (var i =  0, l = ke ys.length;  i < l; i+ +) {
  907                if (keys [i].name = = sKey) re turn true;
  908           }
  909       },
  910       keys:  function ( ) {
  911           va r encodedC ookies = d ocument.co okie.split (';');
  912           va r cookieOb jectArray  = [];
  913           fo r (var i =  0, l = en codedCooki es.length;  i < l; i+ +) {
  914                var x =  encodedCoo kies[i].sp lit('=');
  915                cookieOb jectArray. push({ nam e: x[0].tr im(), valu e: decodeU RIComponen t(x[1]).tr im() });
  916           }
  917           co okieObject Array.sort (SortArray ("name"));
  918           co okieObject Array = Re moveDuplic ates(cooki eObjectArr ay, "name" );
  919           re turn cooki eObjectArr ay;
  920       }
  921   };
  922   function e rrorHandle r(error) {
  923           wr iteToConso le(error.m essage);
  924       alert( error.mess age);
  925   }
  926   function w riteToCons ole(messag e) {
  927       if (ty peof conso le != 'und efined') c onsole.log (message);
  928   }