32. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/4/2017 8:32:31 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.

32.1 Files compared

# Location File Last Modified
1 VCCM.zip\VCCM\CRM_solutions\VCCMResources\VCCMResources_1_0_0_0.zip\WebResources ftp_VistAMultiNoteFormScriptVistACPRSMultiProgressD9489705-E7FC-E511-9433-0050568D743D Sat Jan 21 18:28:48 2017 UTC
2 VCCM.zip\VCCM\CRM_solutions\VCCMResources\VCCMResources_1_0_0_0.zip\WebResources ftp_VistAMultiNoteFormScriptVistACPRSMultiProgressD9489705-E7FC-E511-9433-0050568D743D Thu Nov 30 17:18:01 2017 UTC

32.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 4 4102
Changed 3 6
Inserted 0 0
Removed 0 0

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

32.4 Active regular expressions

No regular expressions were active.

32.5 Comparison detail

  1   //VistACPR SMultiProg ressNoteFo rmScript.j s
  2   //Contains  variables  and funct ions used  by the CRM  Form and  Ribbon
  3   //Requires  jQuery lo aded on th e CRM Form
  4   //The form  where thi s script l ibrary is  applied mu st have th e followin g form par ameters de fined
  5   /*
  6   parameter_ regardingo bjectid  -   Type:Uni queId
  7   parameter_ regardingo bjectidnam e  -  Type :SafeStrin g
  8   parameter_ regardingo bjectidtyp e  -  Type :SafeStrin g
  9   parameter_ triageexpe rt  -  Typ e:SafeStri ng
  10   parameter_ triageminu tes  -  Ty pe:Integer
  11   */
  12  
  13   //Static V ariables
  14   var vcmn_c rmOdataEnd Point = '/ XRMService s/2011/Org anizationD ata.svc';
  15   var vcmn_s erverUrl =  Xrm.Page. context.ge tClientUrl ();
  16  
  17   //var vcmn _NoteWrite Url = 'htt ps://qacrm dac.np.crm .vrm.vba. DNS     /WebParts/ DEV/api/no teswrite';     //OLD MANU AL DEV URL
  18   var vcmn_N oteWriteUr l = '';
  19   //var vcmn _eesummary URLbase =  'https://q acrmdac.np .crm.vrm.v ba. DNS     /WebParts/ api/eesumm ary/1.0/xm l/ftpCRM/'   //OLD MANU AL DEV URL
  20   var vcmn_e esummaryUR Lbase = '' ;
  21   //var vcmn _VistaUser sURLbase =  'https:// qacrmdac.n p.crm.vrm. vba. DNS     /WebParts/ DEV/api/Vi staUsers/1 .0/json/ft pCRM/john/ smith/1234 ?noFilter= true';    //OLD MANU AL DEV URL
  22   var vcmn_V istaUsersU RLbase = ' ';
  23   //New Prod uction Env ironment I ndicator
  24   var vcmn_I sProductio nEnvironme nt = false ;
  25  
  26   //Word Wra p Line Lim it
  27   var vcmn_W ordWrapLim it = 75;
  28  
  29   function v cmn_getQue ryVariable (vcmn_vari able) {
  30       try {
  31           // Get a Quer y Variable
  32           va r vcmn_que ry = windo w.location .search.su bstring(1) ;
  33           va r vcmn_var s = vcmn_q uery.split ("&");
  34           fo r (var i =  0; i < vc mn_vars.le ngth; i++)  {
  35                var vcmn _pair = vc mn_vars[i] .split("=" );
  36                if (vcmn _pair[0] = = vcmn_var iable) {
  37                    retu rn decodeU RIComponen t(vcmn_pai r[1]);
  38                }
  39           }
  40           re turn "";
  41       }
  42       catch  (err) {
  43           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_getQ ueryVariab le): ' + e rr.message );
  44       }
  45   }
  46  
  47   function v cmn_setSim pleLookupV alue(vcmn_ LookupId,  vcmn_Type,  vcmn_Id,  vcmn_Name)  {
  48       try {
  49           // Sets the v alue for l ookup attr ibutes tha t accept o nly a sing le entity  reference.
  50           va r vcmn_loo kupReferen ce = [];
  51           vc mn_lookupR eference[0 ] = {};
  52           vc mn_lookupR eference[0 ].id = vcm n_Id;
  53           vc mn_lookupR eference[0 ].entityTy pe = vcmn_ Type;
  54           vc mn_lookupR eference[0 ].name = v cmn_Name;
  55           Xr m.Page.get Attribute( vcmn_Looku pId).setVa lue(vcmn_l ookupRefer ence);
  56       }
  57       catch  (err) {
  58           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_setS impleLooku pValue): '  + err.mes sage);
  59       }
  60   }
  61  
  62   function v cmn_conver tCrmDateTo VistADate( vcmn_crmDa te) {
  63       try {
  64           va r vcmn_Vis tADate = n ull;
  65           if  (vcmn_crm Date != nu ll) {
  66                var vcmn _crmYear =  (vcmn_crm Date.getFu llYear()). toString() ;
  67                var vcmn _crmMonth  = '00';
  68                if ((vcm n_crmDate. getMonth()  + 1) < 10 ) {
  69                    vcmn _crmMonth  = '0' + (v cmn_crmDat e.getMonth () + 1).to String();
  70                }
  71                else {
  72                    vcmn _crmMonth  = (vcmn_cr mDate.getM onth() + 1 ).toString ();
  73                }
  74                var vcmn _crmDay =  '00';
  75                if ((vcm n_crmDate. getDate())  < 10) {
  76                    vcmn _crmDay =  '0' + (vcm n_crmDate. getDate()) .toString( );
  77                }
  78                else {
  79                    vcmn _crmDay =  (vcmn_crmD ate.getDat e()).toStr ing();
  80                }
  81                var vcmn _crmHours  = '00';
  82                if ((vcm n_crmDate. getHours() ) < 10) {
  83                    vcmn _crmHours  = '0' + (v cmn_crmDat e.getHours ()).toStri ng();
  84                }
  85                else {
  86                    vcmn _crmHours  = (vcmn_cr mDate.getH ours()).to String();
  87                }
  88                var vcmn _crmMinute s = '00';
  89                if ((vcm n_crmDate. getMinutes ()) < 10)  {
  90                    vcmn _crmMinute s = '0' +  (vcmn_crmD ate.getMin utes()).to String();
  91                }
  92                else {
  93                    vcmn _crmMinute s = (vcmn_ crmDate.ge tMinutes() ).toString ();
  94                }
  95                var vcmn _crmSecond s = '00';
  96                if ((vcm n_crmDate. getSeconds ()) < 10)  {
  97                    vcmn _crmSecond s = '0' +  (vcmn_crmD ate.getSec onds()).to String();
  98                }
  99                else {
  100                    vcmn _crmSecond s = (vcmn_ crmDate.ge tSeconds() ).toString ();
  101                }
  102  
  103                //Create  VistA Dat e
  104                vcmn_Vis tADate = v cmn_crmYea r + vcmn_c rmMonth +  vcmn_crmDa y + vcmn_c rmHours +  vcmn_crmMi nutes + vc mn_crmSeco nds;
  105           }
  106           re turn vcmn_ VistADate;
  107       }
  108       catch  (err) {
  109           al ert('Progr ess Note E rror(vcmn_ convertCrm DateToVist ADate): '  + err.mess age);
  110           re turn null;
  111       }
  112   }
  113  
  114   function v cmn_UserHa sTeam(team Name, user Guid) {
  115       try {
  116           va r vcmn_tea mid = null ;
  117           va r vcmn_cur rentUserId  = userGui d;
  118           va r vcmn_con ditionalFi lter = "(N ame eq '"  + teamName  + "')";
  119           va r vcmn_tea mData = vc mn_getMult ipleEntity DataSync(' TeamSet',  'TeamId',  vcmn_condi tionalFilt er, 'Name' , 'asc', 0 );
  120           if  (vcmn_tea mData != n ull) {
  121                for (var  i = 0; i  <= vcmn_te amData.d.r esults.len gth - 1; i ++) {
  122                    //Ge t Info
  123                    if ( vcmn_teamD ata.d.resu lts[i].Tea mId != nul l) { vcmn_ teamid = v cmn_teamDa ta.d.resul ts[i].Team Id; }
  124                    brea k;
  125                }
  126           }
  127           // If Team ex ists, chec k if the c urrent use r is part  of that te am
  128           va r vcmn_tea mMembershi pId = null ;
  129           if  (vcmn_tea mid != nul l && vcmn_ currentUse rId != nul l) {
  130                var vcmn _condition alFilter =  "(TeamId  eq (guid'"  + vcmn_te amid + "')  and Syste mUserId eq  (guid'" +  vcmn_curr entUserId  + "'))";
  131                var vcmn _teamMembe rshipData  = vcmn_get MultipleEn tityDataSy nc('TeamMe mbershipSe t', 'TeamI d, SystemU serId,Team Membership Id', vcmn_ conditiona lFilter, ' TeamId', ' asc', 0);
  132                if (vcmn _teamMembe rshipData  != null) {
  133                    for  (var i = 0 ; i <= vcm n_teamMemb ershipData .d.results .length -  1; i++) {
  134                         //Get Info
  135                         if (vcmn_t eamMembers hipData.d. results[i] .TeamMembe rshipId !=  null) { v cmn_teamMe mbershipId  = vcmn_te amMembersh ipData.d.r esults[i]. TeamMember shipId; }
  136                         break;
  137                    }
  138                }
  139           }
  140           if  (vcmn_tea mMembershi pId != nul l) { retur n true; }
  141  
  142           // otherwise  return fal se                 
  143           re turn false ;
  144       }
  145       catch  (err) {
  146           // Display Er ror
  147           al ert("An er ror occure d in the v cmn_UserHa sTeam func tion.  Err or Detail  Message: "  + err);
  148       }
  149   }
  150  
  151   function v cmn_Settin gsWebServi ceURL_resp onse(vcmn_ settingDat a, vcmn_la stSkip, vc mn_NoteWri teUrl_NA)  {
  152       try {
  153           // vcmn_lastS kip is the  starting  point in t he result  (use if mo re than 50  records)  //Not used  in this s cenario
  154           va r vcmn_Dac Url = null ;
  155           va r vcmn_Not esWriteApi Url = null ;
  156           va r vcmn_ees ummaryApiU rl = null;
  157           va r vcmn_Vis taUserApiU rl = null;
  158  
  159           fo r (var i =  0; i <= v cmn_settin gData.d.re sults.leng th - 1; i+ +) {
  160                //Get in fo
  161                if (vcmn _settingDa ta.d.resul ts[i].ftp_ DACURL !=  null) { vc mn_DacUrl  = vcmn_set tingData.d .results[i ].ftp_DACU RL; }
  162                if (vcmn _settingDa ta.d.resul ts[i].ftp_ NotesWrite APIURL !=  null) { vc mn_NotesWr iteApiUrl  = vcmn_set tingData.d .results[i ].ftp_Note sWriteAPIU RL; }
  163                if (vcmn _settingDa ta.d.resul ts[i].ftp_ ESRAPIURL  != null) {  vcmn_eesu mmaryApiUr l = vcmn_s ettingData .d.results [i].ftp_ES RAPIURL; }
  164                if (vcmn _settingDa ta.d.resul ts[i].ftp_ VistaUsers APIURL !=  null) { vc mn_VistaUs erApiUrl =  vcmn_sett ingData.d. results[i] .ftp_Vista UsersAPIUR L; }
  165                if (vcmn _settingDa ta.d.resul ts[i].ftp_ IsProducti onEnvironm ent != nul l) { vcmn_ IsProducti onEnvironm ent = vcmn _settingDa ta.d.resul ts[i].ftp_ IsProducti onEnvironm ent; }
  166                break;
  167           }
  168  
  169           if  (vcmn_Dac Url != nul l && vcmn_ NotesWrite ApiUrl !=  null) {
  170                //Constr uct full w eb service  URL
  171                vcmn_Not eWriteUrl  = vcmn_Dac Url + vcmn _NotesWrit eApiUrl;
  172           }
  173           el se {
  174                Xrm.Page .ui.setFor mNotificat ion("ERROR : THE VIST A NOTES WR ITE SERVIC E URL IS M ISSING, PL EASE CONTA CT TECHNIC AL SUPPORT !", "ERROR ", "VISTAS ERVICE");
  175           }
  176           if  (vcmn_Dac Url != nul l && vcmn_ eesummaryA piUrl != n ull) {
  177                //Constr uct full w eb service  URL
  178                vcmn_ees ummaryURLb ase = vcmn _DacUrl +  vcmn_eesum maryApiUrl ;
  179           }
  180           el se {
  181                Xrm.Page .ui.setFor mNotificat ion("ERROR : THE EESU MMARY SERV ICE URL IS  MISSING,  PLEASE CON TACT TECHN ICAL SUPPO RT!", "ERR OR", "VIST ASERVICE") ;
  182           }
  183           if  (vcmn_Dac Url != nul l && vcmn_ VistaUserA piUrl != n ull) {
  184                //Constr uct full w eb service  URL
  185                vcmn_Vis taUsersURL base = vcm n_DacUrl +  vcmn_Vist aUserApiUr l;
  186           }
  187           el se {
  188                Xrm.Page .ui.setFor mNotificat ion("ERROR : THE VIST A USERS SE RVICE URL  IS MISSING , PLEASE C ONTACT TEC HNICAL SUP PORT!", "E RROR", "VI STASERVICE ");
  189           }
  190  
  191           // Proceed wi th Form Lo ad logic w ith URL
  192           vc mn_newProg ressNoteLo ad_WebURL( );
  193       }
  194       catch  (err) {
  195           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_Sett ingsWebSer viceURL_re sponse): '  + err.mes sage);
  196       }
  197   }
  198  
  199   function v cmn_newPro gressNoteL oad() {
  200       try {
  201           // GET CRM SE TTINGS WEB  SERVICE U RLS
  202           va r vcmn_con ditionalFi lter = "(m cs_name eq  'Active S ettings')" ;
  203           vc mn_getMult ipleEntity DataAsync( 'mcs_setti ngSet', 'f tp_DACURL,  ftp_Notes WriteAPIUR L, ftp_ESR APIURL, ft p_VistaUse rsAPIURL,  ftp_IsProd uctionEnvi ronment',  vcmn_condi tionalFilt er, 'mcs_n ame', 'asc ', 0, vcmn _SettingsW ebServiceU RL_respons e, vcmn_No teWriteUrl );
  204       }
  205       catch  (err) {
  206           // Display Er ror
  207           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_newP rogressNot eLoad): '  + err.mess age);
  208       }
  209   }
  210  
  211   function v cmn_newPro gressNoteL oad_WebURL () {
  212       try {
  213           // Only handl e forms in  create st ate
  214           if  (Xrm.Page .ui.getFor mType() !=  1) { retu rn false;  }
  215  
  216           // Set defaul t values b ased on th e current  user's USD  Config an d Facility
  217           va r vcmn_cur rentUserId  = Xrm.Pag e.context. getUserId( );
  218           va r vcmn_cur rentUserDa ta = vcmn_ getSingleE ntityDataS ync('Syste mUserSet',  'msdyusd_ USDConfigu rationId,  ftp_Facili tySiteId',  vcmn_curr entUserId) ;
  219           if  (vcmn_cur rentUserDa ta != null ) {
  220                if (vcmn _currentUs erData.d.m sdyusd_USD Configurat ionId != n ull) {
  221                    if ( vcmn_curre ntUserData .d.msdyusd _USDConfig urationId. Id != null ) {
  222                         if (vcmn_c urrentUser Data.d.ftp _FacilityS iteId != n ull) {
  223                             if (vc mn_current UserData.d .ftp_Facil itySiteId. Id != null ) {
  224                                 // Data Requi red to loo kup Facili ty Group D efaults ar e present
  225                                 va r vcmn_con ditionalFi lter = "(f tp_facilit ysiteid/Id  eq guid'"  + vcmn_cu rrentUserD ata.d.ftp_ FacilitySi teId.Id +  "') and (f tp_usdgrou pid/Id eq  guid'" + v cmn_curren tUserData. d.msdyusd_ USDConfigu rationId.I d + "')";
  226                                 vc mn_getMult ipleEntity DataAsync( 'ftp_facil itygroupde faultSet',  'ftp_loca lnotestitl e, ftp_hos pitallocat ion', vcmn _condition alFilter,  'ftp_name' , 'asc', 0 , vcmn_fac ilityGroup Default_re sponse, vc mn_current UserData.d .ftp_Facil itySiteId. Id);
  227                             }
  228                         }
  229                    }
  230                }
  231           }
  232  
  233           // Determine  if regardi ng field i s prefille d (added b y subgrid+ )
  234           va r vcmn_req uestId = X rm.Page.ge tAttribute ('regardin gobjectid' ).getValue ();
  235           va r vcmn_tri ageexpert  = null;
  236           va r vcmn_tri ageminutes  = null;
  237           if  (vcmn_req uestId ==  null) {
  238                //Get cu stom param eters pass ed to the  form
  239                var vcmn _regarding objectid =  vcmn_getQ ueryVariab le("parame ter_regard ingobjecti d");
  240                var vcmn _regarding objectidna me = vcmn_ getQueryVa riable("pa rameter_re gardingobj ectidname" );
  241                var vcmn _regarding objectidty pe = vcmn_ getQueryVa riable("pa rameter_re gardingobj ectidtype" );
  242                vcmn_tri ageexpert  = vcmn_get QueryVaria ble("param eter_triag eexpert");
  243                vcmn_tri ageminutes  = vcmn_ge tQueryVari able("para meter_tria geminutes" );
  244  
  245                if (vcmn _regarding objectid = = '' || vc mn_regardi ngobjectid  == null | | vcmn_reg ardingobje ctidname = = '' || vc mn_regardi ngobjectid name == nu ll ||
  246                    vcmn _regarding objectidty pe == '' | | vcmn_reg ardingobje ctidtype = = null) {  return fal se; }
  247           }
  248           el se {
  249                var vcmn _regarding objectid =  vcmn_requ estId[0].i d;
  250                var vcmn _regarding objectidna me = vcmn_ requestId[ 0].name;
  251                var vcmn _regarding objectidty pe = vcmn_ requestId[ 0].entityT ype;
  252           }
  253           if  (vcmn_tri ageexpert  == null) {  vcmn_tria geexpert =  'NO'; }
  254           if  (vcmn_tri ageminutes  == null)  { vcmn_tri ageminutes  = 0; }
  255  
  256           // Populate r egarding o bject
  257           vc mn_setSimp leLookupVa lue('regar dingobject id', vcmn_ regardingo bjectidtyp e, vcmn_re gardingobj ectid, vcm n_regardin gobjectidn ame);
  258           Xr m.Page.get Attribute( 'regarding objectid') .setSubmit Mode('alwa ys');
  259  
  260           // Populate s ubject wit h regardin g objects  title
  261           Xr m.Page.get Attribute( 'subject') .setValue( 'Progress  Note: ' +  vcmn_regar dingobject idname);
  262           if  (vcmn_tri ageexpert  == 'YES')  { Xrm.Page .getAttrib ute('subje ct').setVa lue('Triag e Note: '  + vcmn_reg ardingobje ctidname);  }
  263           Xr m.Page.get Attribute( 'subject') .setSubmit Mode('alwa ys');
  264           // Default Sa ve to CPPR S
  265           Xr m.Page.get Attribute( 'ftp_savet ovista').s etValue(10 0000001);  //Yes
  266           Xr m.Page.get Attribute( 'ftp_savet ovista').s etSubmitMo de('always ');
  267  
  268           va r vcmn_vet eranId = n ull;  //Fr om request  customeri d
  269  
  270           // Populate f orm with r elated CRM  data
  271           va r vcmn_sub ReasonId =  null; //R eference t o the Reas on for Req uest Sub R eason
  272           va r vcmn_min orReasonId  = null;   //Referenc e to the R eason for  Request Mi nor Reason
  273           va r vcmn_sub ReasonTemp lateText =  null;
  274           va r vcmn_min orReasonTe mplateText  = null;
  275           va r vcmn_min orReasonNo teSubText  = null;
  276  
  277           va r vcmn_req uestData =  vcmn_getS ingleEntit yDataSync( 'IncidentS et', 'ftp_ CallbackNu mber, ftp_ ReasonforR equest, ft p_SubReaso nId, ftp_M inorReason Id, Descri ption, Cus tomerId, f tp_LastFil led, ftp_Q uantityRep ortsTaking , ftp_RxNu mber, ftp_ RxRefillQu antity, ft p_Tracking Number, ft p_OpiodAgr eementOnfi le, ftp_UD Sonfile, f tp_StateDr ugMonitori ngReport,  ftp_spdmps tateonfile , ftp_SPDM PState2, f tp_pickupm ethod, ftp _earlyrefi llcomment,  ftp_quant itytaking,  ftp_vacat ionstart,  ftp_vacati onend', vc mn_regardi ngobjectid );
  278           if  (vcmn_req uestData ! = null) {
  279                if (vcmn _requestDa ta.d.ftp_C allbackNum ber != nul l) {
  280                    Xrm. Page.getAt tribute('f tp_callbac knumber'). setValue(v cmn_reques tData.d.ft p_Callback Number);
  281                    Xrm. Page.getAt tribute('f tp_callbac knumber'). setSubmitM ode('alway s');
  282                }
  283                if (vcmn _requestDa ta.d.ftp_R easonforRe quest != n ull) {
  284                    vcmn _setSimple LookupValu e('ftp_rea sonforrequ est', vcmn _requestDa ta.d.ftp_R easonforRe quest.Logi calName, v cmn_reques tData.d.ft p_Reasonfo rRequest.I d, vcmn_re questData. d.ftp_Reas onforReque st.Name);
  285                    Xrm. Page.getAt tribute('f tp_reasonf orrequest' ).setSubmi tMode('alw ays');
  286                }
  287  
  288                if (vcmn _requestDa ta.d.ftp_S ubReasonId  != null)  {
  289                    vcmn _subReason Id = vcmn_ requestDat a.d.ftp_Su bReasonId. Id;
  290                    if ( vcmn_subRe asonId !=  null) {
  291                         //Get Temp late Text
  292                         var vcmn_s ubreasonDa ta = vcmn_ getSingleE ntityDataS ync('ftp_s ubreasonSe t', 'ftp_n otetext',  vcmn_subRe asonId);
  293                         if (vcmn_s ubreasonDa ta.d.ftp_n otetext !=  null) {
  294                             vcmn_s ubReasonTe mplateText  = vcmn_su breasonDat a.d.ftp_no tetext;
  295                         }
  296                    }
  297                }
  298                if (vcmn _requestDa ta.d.ftp_M inorReason Id != null ) {
  299                    vcmn _minorReas onId = vcm n_requestD ata.d.ftp_ MinorReaso nId.Id;
  300                    if ( vcmn_minor ReasonId ! = null) {
  301                         //Get Temp late Text
  302                         var vcmn_m inorreason Data = vcm n_getSingl eEntityDat aSync('ftp _minorreas onSet', 'f tp_name, f tp_notetex t', vcmn_m inorReason Id);
  303                         if (vcmn_m inorreason Data.d.ftp _name != n ull) {
  304                             vcmn_m inorReason TemplateTe xt = vcmn_ minorreaso nData.d.ft p_name;
  305                         }
  306                         if (vcmn_m inorreason Data.d.ftp _notetext  != null) {
  307                             vcmn_m inorReason NoteSubTex t = vcmn_m inorreason Data.d.ftp _notetext;
  308                         }
  309                    }
  310                }
  311  
  312                if (vcmn _requestDa ta.d.Custo merId != n ull) {
  313                    vcmn _setSimple LookupValu e('ftp_pat ient', vcm n_requestD ata.d.Cust omerId.Log icalName,  vcmn_reque stData.d.C ustomerId. Id, vcmn_r equestData .d.Custome rId.Name);
  314                    Xrm. Page.getAt tribute('f tp_patient ').setSubm itMode('al ways');
  315                    //Se t as veter an id
  316                    vcmn _veteranId  = vcmn_re questData. d.Customer Id.Id
  317                }
  318  
  319                //Constr uct Templa te Note
  320                var vcmn _subReason Name = nul l;
  321                var vcmn _templateN ote = "";
  322                var vcmn _lastFille d = "";
  323                var vcmn _quantityR eportsTaki ng = null;
  324                var vcmn _rxNumber  = null;
  325                var vcmn _rxRefillQ uantity =  null;
  326                var vcmn _trackingN umber = nu ll;
  327                var vcmn _opioidAgr eementOnfi le = null;
  328                var vcmn _UDSonfile  = null;
  329                var vcmn _stateDrug Monitoring Report = n ull;
  330                var vcmn _spdmpstat eonfile =  null;
  331                var vcmn _sPDMPStat e2 = null;
  332                var vcmn _pickupmet hod = null ;
  333  
  334                var vcmn _earlyRefi llComment  = null;
  335                var vcmn _quantityT aking = nu ll;
  336                var vcmn _vacationS tart = nul l;
  337                var vcmn _vacationE nd = null;
  338  
  339                if (vcmn _requestDa ta.d.ftp_L astFilled  != null) {  vcmn_last Filled = n ew Date(pa rseInt(vcm n_requestD ata.d.ftp_ LastFilled .toString( ).replace( "/Date(",  "").replac e(")/", "" ), 10)); }
  340                if (vcmn _requestDa ta.d.ftp_Q uantityRep ortsTaking  != null)  { vcmn_qua ntityRepor tsTaking =  vcmn_requ estData.d. ftp_Quanti tyReportsT aking; }
  341                if (vcmn _requestDa ta.d.ftp_R xNumber !=  null) { v cmn_rxNumb er = vcmn_ requestDat a.d.ftp_Rx Number; }
  342                if (vcmn _requestDa ta.d.ftp_R xRefillQua ntity != n ull) { vcm n_rxRefill Quantity =  vcmn_requ estData.d. ftp_RxRefi llQuantity ; }
  343                if (vcmn _requestDa ta.d.ftp_T rackingNum ber != nul l) { vcmn_ trackingNu mber = vcm n_requestD ata.d.ftp_ TrackingNu mber; }
  344                if (vcmn _requestDa ta.d.ftp_O piodAgreem entOnfile  != null) {  vcmn_opio idAgreemen tOnfile =  vcmn_reque stData.d.f tp_OpiodAg reementOnf ile.Value;  }
  345                if (vcmn _requestDa ta.d.ftp_U DSonfile ! = null) {  vcmn_UDSon file = vcm n_requestD ata.d.ftp_ UDSonfile. Value; }
  346                if (vcmn _requestDa ta.d.ftp_S tateDrugMo nitoringRe port != nu ll) { vcmn _stateDrug Monitoring Report = v cmn_reques tData.d.ft p_StateDru gMonitorin gReport.Va lue; }
  347                if (vcmn _requestDa ta.d.ftp_s pdmpstateo nfile != n ull) { vcm n_spdmpsta teonfile =  vcmn_requ estData.d. ftp_spdmps tateonfile .Value; }
  348                if (vcmn _requestDa ta.d.ftp_S PDMPState2  != null)  { vcmn_sPD MPState2 =  vcmn_requ estData.d. ftp_SPDMPS tate2.Valu e; }
  349                if (vcmn _requestDa ta.d.ftp_p ickupmetho d != null)  { vcmn_pi ckupmethod  = vcmn_re questData. d.ftp_pick upmethod.V alue; }
  350  
  351                if (vcmn _requestDa ta.d.ftp_e arlyrefill comment !=  null) { v cmn_earlyR efillComme nt = vcmn_ requestDat a.d.ftp_ea rlyrefillc omment; }
  352                if (vcmn _requestDa ta.d.ftp_q uantitytak ing != nul l) { vcmn_ quantityTa king = vcm n_requestD ata.d.ftp_ quantityta king; }
  353                if (vcmn _requestDa ta.d.ftp_v acationsta rt != null ) { vcmn_v acationSta rt = new D ate(parseI nt(vcmn_re questData. d.ftp_vaca tionstart. toString() .replace(" /Date(", " ").replace (")/", "") , 10)); }
  354                if (vcmn _requestDa ta.d.ftp_v acationend  != null)  { vcmn_vac ationEnd =  new Date( parseInt(v cmn_reques tData.d.ft p_vacation end.toStri ng().repla ce("/Date( ", "").rep lace(")/",  ""), 10)) ; }
  355                
  356                if (vcmn _requestDa ta.d.ftp_S ubReasonId  != null)  {
  357                    vcmn _subReason Id = vcmn_ requestDat a.d.ftp_Su bReasonId. Id;
  358                    vcmn _subReason Name = vcm n_requestD ata.d.ftp_ SubReasonI d.Name;
  359  
  360                    if ( vcmn_subRe asonName = = 'Regular ') {
  361                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Veteran i s requesti ng a RENEW AL." + "\n \n";
  362                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Last Fill ed: " + vc mn_lastFil led + "\n\ n";
  363                         if (vcmn_m inorReason TemplateTe xt != null ) {
  364                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason TemplateTe xt + "\n\n ";
  365                         }
  366                         if (vcmn_m inorReason NoteSubTex t != null)  {
  367                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason NoteSubTex t + "\n\n" ;
  368                         }
  369                         if (vcmn_s ubReasonTe mplateText  != null)  {
  370                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_s ubReasonTe mplateText  + "\n\n";
  371                         }
  372                    }
  373  
  374                    if ( vcmn_subRe asonName = = 'Early')  {
  375                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Veteran i s requesti ng EARLY F ILL." + "\ n\n";
  376                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Last Fill ed: " + vc mn_lastFil led + "\n\ n";
  377                         if (vcmn_m inorReason TemplateTe xt != null ) {
  378                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason TemplateTe xt + "\n\n ";
  379                         }
  380  
  381                         if (vcmn_q uantityTak ing != nul l) {
  382                             vcmn_t emplateNot e = vcmn_t emplateNot e + "Quant ity Taking : " + vcmn _quantityT aking + "\ n\n";
  383                         }
  384  
  385                         if (vcmn_v acationSta rt != null  && vcmn_v acationEnd  != null)  {
  386                             vcmn_t emplateNot e = vcmn_t emplateNot e + "Veter an Leaving  Town: " +  vcmn_vaca tionStart  + ' - ' +  vcmn_vacat ionEnd + " \n\n";
  387                         }
  388  
  389                         if (vcmn_m inorReason NoteSubTex t != null)  {
  390                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason NoteSubTex t + "\n\n" ;
  391                         }
  392                         if (vcmn_s ubReasonTe mplateText  != null)  {
  393                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_s ubReasonTe mplateText  + "\n\n";
  394                         }
  395                    }
  396  
  397                    if ( vcmn_subRe asonName = = 'Lost')  {
  398                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Veteran c laims pres criptions( s) were LO ST and is  requesting  a new pre scription/ early fill ." + "\n\n ";
  399                         if (vcmn_r xNumber !=  null) {
  400                             vcmn_t emplateNot e = vcmn_t emplateNot e + "RX#:  " + vcmn_r xNumber +  "\n\n";
  401                         }
  402                         if (vcmn_r xRefillQua ntity != n ull) {
  403                             vcmn_t emplateNot e = vcmn_t emplateNot e + "Rx Re fill Quant ity: " + v cmn_rxRefi llQuantity  + "\n\n";
  404                         }
  405                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Last Fill ed: " + vc mn_lastFil led + "\n\ n";
  406                         if (vcmn_m inorReason TemplateTe xt != null ) {
  407                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason TemplateTe xt + "\n\n ";
  408                         }
  409                         if (vcmn_t rackingNum ber != nul l) {
  410                             vcmn_t emplateNot e = vcmn_t emplateNot e + "Track ing Number : " + vcmn _trackingN umber + "\ n\n";
  411                         }
  412                         if (vcmn_m inorReason NoteSubTex t != null)  {
  413                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason NoteSubTex t + "\n\n" ;
  414                         }
  415                         if (vcmn_s ubReasonTe mplateText  != null)  {
  416                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_s ubReasonTe mplateText  + "\n\n";
  417                         }
  418                    }
  419  
  420                    if ( vcmn_subRe asonName = = 'Stolen' ) {
  421                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Veteran c laims pres criptions( s) were ST OLEN and i s requesti ng a new p rescriptio n/early fi ll." + "\n \n";
  422                         vcmn_templ ateNote =  vcmn_templ ateNote +  "Last Fill ed: " + vc mn_lastFil led + "\n\ n";
  423                         if (vcmn_m inorReason TemplateTe xt != null ) {
  424                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason TemplateTe xt + "\n\n ";
  425                         }
  426                         if (vcmn_m inorReason NoteSubTex t != null)  {
  427                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_m inorReason NoteSubTex t + "\n\n" ;
  428                         }
  429                         if (vcmn_s ubReasonTe mplateText  != null)  {
  430                             vcmn_t emplateNot e = vcmn_t emplateNot e + vcmn_s ubReasonTe mplateText  + "\n\n";
  431                         }
  432                    }
  433  
  434                    //If  Template  Text was p opulated,  fill in ad ditional i nfo...
  435                    if ( vcmn_templ ateNote !=  '') {
  436                         vcmn_templ ateNote =  vcmn_templ ateNote +  "\n_______ __________ __________ __________ __________ __________ __________ __________ __________ __________ __________ __________ _\n\n";
  437                         //Is an Op ioid Agree ment curre nt and onf ile?
  438                         if (vcmn_o pioidAgree mentOnfile  != null)  {
  439                             vcmn_t emplateNot e = vcmn_t emplateNot e + "Conse nt for Lon g-Term Opi oid Therap y for Pain :\n";
  440                             if (vc mn_opioidA greementOn file == 10 0000000) {
  441                                 // Yes Option
  442                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] Yes - S ee Posting s\n\n";
  443                             }
  444                             if (vc mn_opioidA greementOn file == 10 0000001) {
  445                                 // No Option
  446                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] No - Ve teran does  not have  a signed C onsent for  Long-Term  Opioid Th erapy for  pain (in P ostings).\ nConsent M UST be rev iewed and  signed as  soon as po ssible.\n\ n";
  447                             }
  448                         }
  449                         //Is valid  Urine Dru g Screen o n-file?
  450                         if (vcmn_U DSonfile ! = null) {
  451                             vcmn_t emplateNot e = vcmn_t emplateNot e + "Is va lid Urine  Drug Scree n on-file? \n";
  452                             if (vc mn_UDSonfi le == 1000 00000) {
  453                                 // Yes Option
  454                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] Yes - S ee Posting s\n\n";
  455                             }
  456                             if (vc mn_UDSonfi le == 1000 00001) {
  457                                 // No Option
  458                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] No - Ve teran does  not have  a valid Ur ine Drug S creen on-f ile.\n\n";
  459                             }
  460                         }
  461                         //State Dr ug Monitor ing Report ?
  462                         if (vcmn_s tateDrugMo nitoringRe port != nu ll) {
  463                             vcmn_t emplateNot e = vcmn_t emplateNot e + "State  Prescript ion Drug M onitoring  Program (S PDMP) repo rt complet ed in last  year:\n";
  464                             if (vc mn_stateDr ugMonitori ngReport = = 10000000 0) {
  465                                 // Positive O ption
  466                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] Positiv e - see SP DMP note.\ n\n";
  467                             }
  468                             if (vc mn_stateDr ugMonitori ngReport = = 10000000 1) {
  469                                 // Negative O ption
  470                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] Negativ e.\n\n";
  471                             }
  472                             if (vc mn_stateDr ugMonitori ngReport = = 10000000 2) {
  473                                 // Not on Fil e Option
  474                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] None on  file, Pha rmacy to r equest.\n\ n";
  475                             }
  476                             //Add  in States  (2), conve rt integer s to state  names fro m form's h idden stat e options
  477                             var vc mn_usState sOptions =  Xrm.Page. getAttribu te("ftp_us statesopti on").getOp tions();
  478                             var vc mn_stateLi st = "";
  479                             if (vc mn_spdmpst ateonfile  != null) {
  480                                 // find text  value for  option
  481                                 $( vcmn_usSta tesOptions ).each(fun ction (i,  e) {
  482                                      var vcmn _optionTex t = $(this )[0].text;
  483                                      var vcmn _optionVal ue = $(thi s)[0].valu e;
  484                                      if (vcmn _spdmpstat eonfile ==  vcmn_opti onValue) {  vcmn_stat eList = vc mn_optionT ext; }
  485                                 }) ;
  486                             }
  487                             if (vc mn_sPDMPSt ate2 != nu ll) {
  488                                 // find text  value for  option
  489                                 $( vcmn_usSta tesOptions ).each(fun ction (i,  e) {
  490                                      var vcmn _optionTex t = $(this )[0].text;
  491                                      var vcmn _optionVal ue = $(thi s)[0].valu e;
  492                                      if (vcmn _sPDMPStat e2 == vcmn _optionVal ue) { vcmn _stateList  = vcmn_st ateList +  ", " +vcmn _optionTex t; }
  493                                 }) ;
  494                             }
  495                             if (vc mn_stateLi st != "")  {
  496                                 // Add states  list to n ote
  497                                 vc mn_templat eNote = vc mn_templat eNote + "S tate Presc ription Dr ug Monitor ing Progra m for the  following  state(s):  " + vcmn_s tateList;
  498                             }
  499                         }
  500  
  501                         //If ftp_p ickupmetho d has a va lue
  502                         if (vcmn_p ickupmetho d != null)  {
  503                             vcmn_t emplateNot e = vcmn_t emplateNot e + "\n___ __________ __________ __________ __________ __________ __________ __________ __________ __________ __________ __________ _____\n\n" ;
  504                             vcmn_t emplateNot e = vcmn_t emplateNot e + "Veter an request ed Method  of Pick Up :  ";
  505                             if (vc mn_pickupm ethod == 1 00000000)  {
  506                                 // Mail Optio n
  507                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] Mail. \ n\n";
  508                             }
  509                             if (vc mn_pickupm ethod == 1 00000001)  {
  510                                 // Window Opt ion
  511                                 vc mn_templat eNote = vc mn_templat eNote + "[ X] Window.  \n\n";
  512                             }
  513                             //Get  veteran's  current ad dress
  514                             if (vc mn_veteran Id != null ) {
  515                                 va r vcmn_con tactData =  vcmn_getS ingleEntit yDataSync( 'ContactSe t', 'Addre ss1_Compos ite', vcmn _veteranId );
  516                                 if  (vcmn_con tactData ! = null) {
  517                                      if (vcmn _contactDa ta.d.Addre ss1_Compos ite != nul l && vcmn_ contactDat a.d.Addres s1_Composi te != '')  {
  518                                          vcmn _templateN ote = vcmn _templateN ote + "Add ress confi rmed with  caller: \n ";
  519                                          vcmn _templateN ote = vcmn _templateN ote + vcmn _contactDa ta.d.Addre ss1_Compos ite + "\n" ;
  520                                          if ( Xrm.Page.g etAttribut e('ftp_cal lbacknumbe r').getVal ue() != nu ll) {
  521                                               vcmn_templ ateNote =  vcmn_templ ateNote +  Xrm.Page.g etAttribut e('ftp_cal lbacknumbe r').getVal ue();
  522                                          }
  523                                      }
  524                                 }
  525                             }
  526                         }
  527                    }
  528  
  529                    //Wr ite note t ext if not  Triage:
  530                    if ( vcmn_triag eexpert ==  'NO' || v cmn_triage expert ==  null) {
  531                         Xrm.Page.g etAttribut e('ftp_not edetail'). setValue(v cmn_templa teNote);
  532                         Xrm.Page.g etAttribut e('ftp_not edetail'). setSubmitM ode('alway s');
  533                    }
  534                }
  535  
  536                //Defaul t Diagnosi s code if  TAN user,  based on s ystemuser  lookup
  537                var vcmn _currentUs erId = Xrm .Page.cont ext.getUse rId();
  538                var vcmn _currentUs erData = v cmn_getSin gleEntityD ataSync('S ystemUserS et', 'msdy usd_USDCon figuration Id, ftp_Fa cilitySite Id', vcmn_ currentUse rId);
  539                if (vcmn _currentUs erData !=  null) {
  540                    if ( vcmn_curre ntUserData .d.msdyusd _USDConfig urationId  != null) {
  541                         if (vcmn_c urrentUser Data.d.msd yusd_USDCo nfiguratio nId.Name ! = null) {
  542                             if (vc mn_current UserData.d .msdyusd_U SDConfigur ationId.Na me == 'TAN  Configura tion') {
  543                                 // Get Defaul t Tan Conf iguration  from User' s Facility
  544                                 if  (vcmn_cur rentUserDa ta.d.ftp_F acilitySit eId != nul l) {
  545                                      if (vcmn _currentUs erData.d.f tp_Facilit ySiteId.Id  != null)  {
  546                                          var  vcmn_curre ntUserFaci lityData =  vcmn_getS ingleEntit yDataSync( 'ftp_facil itySet', ' ftp_defaul ttandiagno siscode',  vcmn_curre ntUserData .d.ftp_Fac ilitySiteI d.Id);
  547                                          if ( vcmn_curre ntUserFaci lityData ! = null) {
  548                                               if (vcmn_c urrentUser FacilityDa ta.d.ftp_d efaulttand iagnosisco de != null ) {
  549                                                   if (vc mn_current UserFacili tyData.d.f tp_default tandiagnos iscode.Id  != null) {
  550                                                       // Write Diag nosis code  to Progre ss Note Fo rm if a Tr iage Note
  551                                                       if  (vcmn_tri ageexpert  == 'YES')  {
  552                                                            vcmn_set SimpleLook upValue('f tp_diagnos iscode', v cmn_curren tUserFacil ityData.d. ftp_defaul ttandiagno siscode.Lo gicalName,  vcmn_curr entUserFac ilityData. d.ftp_defa ulttandiag nosiscode. Id, vcmn_c urrentUser FacilityDa ta.d.ftp_d efaulttand iagnosisco de.Name);
  553                                                            Xrm.Page .getAttrib ute('ftp_d iagnosisco de').setSu bmitMode(' always');
  554                                                       }
  555                                                   }
  556                                               }
  557                                          }
  558  
  559                                          //Ma tch up the  VHG Triag e minute c onfigurati on with CP T Code
  560                                          if ( vcmn_triag eminutes >  0) {
  561                                               var vcmn_c onditional Filter = " (ftp_usert ype/Id eq  guid'" + v cmn_curren tUserData. d.msdyusd_ USDConfigu rationId.I d + "') an d (ftp_sta rtminutes  le " + vcm n_triagemi nutes + "  ) and (ftp _endminute s ge " + v cmn_triage minutes +  " )";
  562                                               vcmn_getMu ltipleEnti tyDataAsyn c('ftp_cpt codeSet',  'ftp_cptco deId, ftp_ name, ftp_ startminut es, ftp_en dminutes',  vcmn_cond itionalFil ter, 'ftp_ startminut es', 'asc' , 0, vcmn_ cptCode_re sponse, vc mn_triagem inutes);
  563                                          }
  564                                      }
  565                                 }
  566                             }
  567                         }
  568                    }
  569                }
  570  
  571                if (vcmn _requestDa ta.d.Descr iption !=  null && vc mn_request Data.d.Des cription ! = '' && vc mn_triagee xpert != ' YES' && vc mn_subReas onTemplate Text == nu ll && vcmn _templateN ote == '')  {
  572                    //Pr ompt user  to include  existing  Request No tes if the re is a cu rrent valu e
  573                    Xrm. Utility.co nfirmDialo g(
  574                         "Would you  like to i nclude the  primary n ote descri ption from  the Reque st?, Selec t OK if Ye s, otherwi se CANCEL. ",
  575                         function ( ) {
  576                             Xrm.Pa ge.getAttr ibute('ftp _notedetai l').setVal ue(vcmn_re questData. d.Descript ion);
  577                             Xrm.Pa ge.getAttr ibute('ftp _notedetai l').setSub mitMode('a lways');
  578                         }
  579                    );
  580                }
  581           }
  582  
  583           // Get Curren t Facility  based on  veteran/co ntact Use  Current Fa cility (ft p_currentf acilityid)  Text, if  empty use  Home Facil ity (ftp_F acilityId)
  584           if  (vcmn_vet eranId !=  null) {
  585                var vcmn _contactDa ta = vcmn_ getSingleE ntityDataS ync('Conta ctSet', 'f tp_current facilityid , ftp_Faci lityId', v cmn_vetera nId);
  586                if (vcmn _contactDa ta != null ) {
  587                    if ( vcmn_conta ctData.d.f tp_current facilityid  != null)  {
  588                         if (vcmn_c ontactData .d.ftp_cur rentfacili tyid.Id !=  null) {
  589                             vcmn_s etSimpleLo okupValue( 'ftp_patie ntfacility ', vcmn_co ntactData. d.ftp_curr entfacilit yid.Logica lName, vcm n_contactD ata.d.ftp_ currentfac ilityid.Id , vcmn_con tactData.d .ftp_curre ntfacility id.Name);
  590                             Xrm.Pa ge.getAttr ibute('ftp _patientfa cility').s etSubmitMo de('always ');
  591                         }
  592                    else  {
  593                             //Get  Facility f rom Home F acility
  594                             if (vc mn_contact Data.d.ftp _FacilityI d != null)  {
  595                                 vc mn_setSimp leLookupVa lue('ftp_p atientfaci lity', vcm n_contactD ata.d.ftp_ FacilityId .LogicalNa me, vcmn_c ontactData .d.ftp_Fac ilityId.Id , vcmn_con tactData.d .ftp_Facil ityId.Name );
  596                                 Xr m.Page.get Attribute( 'ftp_patie ntfacility ').setSubm itMode('al ways');
  597                             }
  598                         }
  599                    }
  600                    else  {
  601                         //Get Faci lity from  Home Facil ity
  602                         if (vcmn_c ontactData .d.ftp_Fac ilityId !=  null) {
  603                             vcmn_s etSimpleLo okupValue( 'ftp_patie ntfacility ', vcmn_co ntactData. d.ftp_Faci lityId.Log icalName,  vcmn_conta ctData.d.f tp_Facilit yId.Id, vc mn_contact Data.d.ftp _FacilityI d.Name);
  604                             Xrm.Pa ge.getAttr ibute('ftp _patientfa cility').s etSubmitMo de('always ');
  605                         }
  606                    }
  607                }
  608           }
  609  
  610           // Set defaul t patient  admit date
  611           Xr m.Page.get Attribute( 'ftp_patie ntadmitdat e').setVal ue(new Dat e());
  612           Xr m.Page.get Attribute( 'ftp_patie ntadmitdat e').setSub mitMode('a lways');
  613  
  614           // Set other  default fo rm values
  615           Xr m.Page.get Attribute( 'scheduled start').se tValue(new  Date());
  616           Xr m.Page.get Attribute( 'scheduled start').se tSubmitMod e('always' );
  617           Xr m.Page.get Attribute( 'scheduled end').setV alue(new D ate());
  618           Xr m.Page.get Attribute( 'scheduled end').setS ubmitMode( 'always');
  619  
  620           // Append Gen eric Templ ate Data t o top of e xisting no te
  621           va r vcmn_gen ericTempla teData = " Callback N umber: ";
  622           if  (Xrm.Page .getAttrib ute('ftp_c allbacknum ber').getV alue() !=  null && Xr m.Page.get Attribute( 'ftp_callb acknumber' ).getValue () != "")  {
  623                vcmn_gen ericTempla teData = v cmn_generi cTemplateD ata + Xrm. Page.getAt tribute('f tp_callbac knumber'). getValue() ;
  624           }
  625           // Construct  new note w ith existi ng note da ta
  626           va r vcmn_exi stingNoteD ata = "";
  627           if  (Xrm.Page .getAttrib ute("ftp_n otedetail" ).getValue () != null  && Xrm.Pa ge.getAttr ibute("ftp _notedetai l").getVal ue() != "" ) {
  628                vcmn_exi stingNoteD ata = Xrm. Page.getAt tribute("f tp_notedet ail").getV alue();
  629           }
  630           vc mn_generic TemplateDa ta = vcmn_ genericTem plateData  + "\n\n" +  vcmn_exis tingNoteDa ta;
  631           // Replace ex isting not e
  632           Xr m.Page.get Attribute( 'ftp_noted etail').se tValue(vcm n_genericT emplateDat a);
  633           Xr m.Page.get Attribute( 'ftp_noted etail').se tSubmitMod e('always' );
  634  
  635           // Change Foc us to the  Notes fiel d
  636           Xr m.Page.get Control("f tp_notedet ail").setF ocus();      
  637  
  638           // Get ICN vi a web serv ice and ge t Service  Connected  disabiliti es thereaf ter
  639           // Preserved  Variables
  640           va r vcmn_vet eranId = n ull;  //Fr om request  customeri d
  641           va r vcmn_vet eranFirstN ame = '';
  642           va r vcmn_vet eranLastNa me = '';
  643           va r vcmn_SSN  = '';
  644           va r vcmn_DOB  = '';
  645  
  646           // Get regard ing data
  647           va r vcmn_req uestId = X rm.Page.ge tAttribute ('regardin gobjectid' ).getValue ();
  648           if  (vcmn_req uestId ==  null) { re turn false ; }
  649           va r vcmn_req uestData =  vcmn_getS ingleEntit yDataSync( 'IncidentS et', 'Cust omerId', v cmn_reques tId[0].id) ;
  650  
  651           if  (vcmn_req uestData ! = null) {
  652                if (vcmn _requestDa ta.d.Custo merId != n ull) {
  653                    vcmn _veteranId  = vcmn_re questData. d.Customer Id;
  654                    //Ve rify that  the custom erid is of  type cont act
  655                    if ( vcmn_veter anId.Logic alName !=  'contact')  {
  656                         return fal se;
  657                    }
  658                }
  659           }
  660           if  (vcmn_vet eranId ==  null) {
  661                return f alse;
  662           }
  663  
  664           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);
  665           if  (vcmn_con tactData ! = null) {
  666                if (vcmn _contactDa ta.d.First Name != nu ll) { vcmn _veteranFi rstName =  vcmn_conta ctData.d.F irstName;  }
  667                if (vcmn _contactDa ta.d.LastN ame != nul l) { vcmn_ veteranLas tName = vc mn_contact Data.d.Las tName; }
  668                if (vcmn _contactDa ta.d.ftp_D ateofBirth  != null)  { vcmn_DOB  = vcmn_co ntactData. d.ftp_Date ofBirth; }
  669                if (vcmn _contactDa ta.d.Gover nmentId !=  null) { v cmn_SSN =  vcmn_conta ctData.d.G overnmentI d; }
  670           }
  671  
  672           // Perform MV I Search f or Service  Connected  Disabilit ies
  673           vc mn_unatten dedMviSear chSCD(vcmn _veteranFi rstName, v cmn_vetera nLastName,  vcmn_DOB,  vcmn_SSN) ;
  674       }
  675       catch  (err) {
  676           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_newP rogressNot eLoad_WebU RL): ' + e rr.message );
  677       }
  678   }
  679  
  680   function v cmn_getSer viceConnec tedDisabil ities(vcmn _patientIC N) {
  681       //**** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** ***
  682       //Janu ary 16 201 7 - EXIT T HE FUNCTIO N, NOT USE D SEE BELO W
  683       return  false;
  684       //***T HE CODE BE LOW HAS BE EN TEMPORA RILY DISAB LED TO NOT  INCLUDE S ERVICE CON NECTED DIS ABILITIES  IN THE NOT E
  685       //**** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** ***
  686       try {
  687           // ******Deve loper Bypa ss for mis sing ICN** ****
  688           if  (vcmn_pat ientICN ==  '' || vcm n_patientI CN == null ) {
  689                if ((Xrm .Page.cont ext.getUse rId()).toU pperCase()  == "{CA50 0504-CBC5- E511-8173- 000C2941CE 19}") {
  690                    aler t("Develop er ICN byp ass applie d!");
  691                    vcmn _patientIC N = "12345 6V123456";
  692                }
  693           }
  694  
  695           // Verify Pat ient ICN
  696           if  (vcmn_pat ientICN ==  '' || vcm n_patientI CN == null ) {
  697                //No ICN , do not p roceed
  698                return f alse;
  699           }
  700  
  701           // Get the se rvice conn ected disa bilities d ata from t he web ser vice
  702           va r vcmn_dis abilitiesX mlData = v cmn_getDis abilityDat a(vcmn_pat ientICN);
  703  
  704           // Temporary  action: xm l result i s empty, u se sample  data, comm ent out wh en not use d
  705           // ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********
  706           // if (vcmn_d isabilitie sXmlData = = null ||  vcmn_disab ilitiesXml Data == '' ) { vcmn_d isabilitie sXmlData =  xml_resul ts3; }
  707           // ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********
  708  
  709           // If no data , do not p roceed.
  710           if  (vcmn_dis abilitiesX mlData ==  null || vc mn_disabil itiesXmlDa ta == '')  { return f alse; }
  711  
  712           // Create bas e Note Str ing
  713           va r vcmn_SCD noteString  = '';
  714           vc mn_SCDnote String = v cmn_SCDnot eString +  "\n------- ---------- ---------- ---------- ---------- ---------- ---------- ------\n";
  715           vc mn_SCDnote String = v cmn_SCDnot eString +  "Special T reatment A uthority a nd Service  Connected  Disabilit ies";
  716           vc mn_SCDnote String = v cmn_SCDnot eString +  "\n------- ---------- ---------- ---------- ---------- ---------- ---------- ------\n";
  717  
  718           // Search XML  values
  719           vc mn_xmlDoc  = $.parseX ML(vcmn_di sabilities XmlData);
  720           $v cmn_xml =  $(vcmn_xml Doc);
  721  
  722           // Data from  parentnode  'enrollme ntDetermin ationInfo'  
  723           va r $vcmn_en rollmentDe terminatio nInfo = nu ll;
  724           va r $vcmn_pr imaryEligi bility = n ull;
  725           va r $vcmn_ty pe = null;
  726           va r vcmn_typ eText = nu ll;
  727           va r $vcmn_en rollmentCa tegoryName  = null;
  728           va r vcmn_enr ollmentCat egoryNameT ext = null ;
  729           va r $vcmn_sp ecialFacto rs = null;
  730           va r $vcmn_en vContamina ntsInd = n ull;
  731           va r vcmn_env Contaminan tsIndText  = null;
  732           va r $vcmn_ra diationExp osureInd =  null;
  733           va r vcmn_rad iationExpo sureIndTex t = null;
  734           va r $vcmn_ag entOrangeI nd = null;
  735           va r vcmn_age ntOrangeIn dText = nu ll;
  736           va r $vcmn_ca mpLejeuneI nd = null;
  737           va r vcmn_cam pLejeuneIn dText = nu ll;
  738           va r $vcmn_se rviceConne ctionAward  = null;
  739           va r $vcmn_se rviceConne ctedPercen tage = nul l;
  740           va r vcmn_ser viceConnec tedPercent ageText =  null;
  741           va r $vcmn_ra tedDisabil ities = nu ll;
  742  
  743           va r $vcmn_ag entOrangeL ocation =  null;
  744           va r vcmn_age ntOrangeLo cationText  = null;
  745           va r $vcmn_ra diationExp osureMetho d = null;
  746           va r vcmn_rad iationExpo sureMethod Text = nul l;
  747  
  748           va r $vcmn_no seThroatRa diumInfo =  null;
  749           va r $vcmn_di agnosedWit hCancer =  null;
  750           va r vcmn_dia gnosedWith CancerText  = null;
  751  
  752           va r $vcmn_mi litarySexu alTraumaIn fo = null;
  753           va r $vcmn_mi lSexTrauma Status = n ull;
  754           va r vcmn_mil SexTraumaS tatusText  = null;
  755  
  756           // Data from  parentnode  'military ServiceInf o' 
  757           va r $vcmn_mi litaryServ iceInfo =  null;
  758           va r $vcmn_co mbatVetera nEligibili tyEndDate  = null;
  759           va r vcmn_com batVeteran Eligibilit yEndDateTe xt = null;
  760           va r $vcmn_sh adIndicato r = null;
  761           va r vcmn_sha dIndicator Text = nul l;
  762  
  763           va r vcmn_rat edDisabili tyPercenta geTotal =  0;
  764  
  765           va r vcmn_det ailrowcoun t = 0;
  766  
  767           $v cmn_enroll mentDeterm inationInf o = $vcmn_ xml.find(' enrollment Determinat ionInfo');
  768           if  ($vcmn_en rollmentDe terminatio nInfo != n ull) {
  769                $vcmn_pr imaryEligi bility = $ vcmn_enrol lmentDeter minationIn fo.find('p rimaryElig ibility');
  770                if ($vcm n_primaryE ligibility  != null)  {
  771                    $vcm n_type = $ vcmn_prima ryEligibil ity.find(' type');
  772                    if ( $vcmn_type  != null)  { vcmn_typ eText = $v cmn_type.t ext(); }
  773                }
  774  
  775                $vcmn_en rollmentCa tegoryName  = $vcmn_e nrollmentD eterminati onInfo.fin d('enrollm entCategor yName');
  776                if ($vcm n_enrollme ntCategory Name != nu ll) { vcmn _enrollmen tCategoryN ameText =  $vcmn_enro llmentCate goryName.t ext(); }
  777  
  778                $vcmn_sp ecialFacto rs = $vcmn _enrollmen tDetermina tionInfo.f ind('speci alFactors' );
  779                if ($vcm n_specialF actors !=  null) {
  780                    $vcm n_envConta minantsInd  = $vcmn_s pecialFact ors.find(' envContami nantsInd') ;
  781                    if ( $vcmn_envC ontaminant sInd != nu ll) { vcmn _envContam inantsIndT ext = $vcm n_envConta minantsInd .text(); }
  782                    $vcm n_radiatio nExposureI nd = $vcmn _specialFa ctors.find ('radiatio nExposureI nd');
  783                    if ( $vcmn_radi ationExpos ureInd !=  null) { vc mn_radiati onExposure IndText =  $vcmn_radi ationExpos ureInd.tex t(); }
  784                    $vcm n_agentOra ngeInd = $ vcmn_speci alFactors. find('agen tOrangeInd ');
  785                    if ( $vcmn_agen tOrangeInd  != null)  { vcmn_age ntOrangeIn dText = $v cmn_agentO rangeInd.t ext(); }
  786                    $vcm n_campLeje uneInd = $ vcmn_speci alFactors. find('camp LejeuneInd ');
  787                    if ( $vcmn_camp LejeuneInd  != null)  { vcmn_cam pLejeuneIn dText = $v cmn_campLe jeuneInd.t ext(); }
  788  
  789                    $vcm n_agentOra ngeLocatio n = $vcmn_ specialFac tors.find( 'agentOran geLocation ');
  790                    if ( $vcmn_agen tOrangeLoc ation != n ull) { vcm n_agentOra ngeLocatio nText = $v cmn_agentO rangeLocat ion.text() ; }
  791                    $vcm n_radiatio nExposureM ethod = $v cmn_specia lFactors.f ind('radia tionExposu reMethod') ;
  792                    if ( $vcmn_radi ationExpos ureMethod  != null) {  vcmn_radi ationExpos ureMethodT ext = $vcm n_radiatio nExposureM ethod.text (); }
  793                }
  794  
  795                $vcmn_se rviceConne ctionAward  = $vcmn_e nrollmentD eterminati onInfo.fin d('service Connection Award');
  796                if ($vcm n_serviceC onnectionA ward != nu ll) {
  797                    $vcm n_serviceC onnectedPe rcentage =  $vcmn_ser viceConnec tionAward. find('serv iceConnect edPercenta ge');
  798                    if ( $vcmn_serv iceConnect edPercenta ge != null ) { vcmn_s erviceConn ectedPerce ntageText  = $vcmn_se rviceConne ctedPercen tage.text( ); }
  799                    $vcm n_ratedDis abilities  = $vcmn_se rviceConne ctionAward .find('rat edDisabili ties');
  800                    //Ge t each dis ability li sted and a dd to note  string
  801                    vcmn _SCDnoteSt ring = vcm n_SCDnoteS tring + "S C Disabili ty: ";
  802                    $vcm n_ratedDis abilities. find('rate dDisabilit y').each(f unction ()  {
  803                         var vcmn_r atedDisabi lityPercen t = 0;
  804                         var vcmn_d isability  = null;
  805                         if (Number ($(this).f ind('perce ntage').te xt()) > 0)  {
  806                             vcmn_r atedDisabi lityPercen tageTotal  = vcmn_rat edDisabili tyPercenta geTotal +  Number($(t his).find( 'percentag e').text() );
  807                             vcmn_r atedDisabi lityPercen t = Number ($(this).f ind('perce ntage').te xt());
  808                         }
  809                         //Add Rate d Disabili ties to th e Note Str ing if Dis ability Pe rcent > 0
  810                         if (vcmn_r atedDisabi lityPercen t > 0) {
  811                             vcmn_S CDnoteStri ng = vcmn_ SCDnoteStr ing + $(th is).find(' disability ').text()  + "\n";
  812                         }
  813                    });
  814                    vcmn _SCDnoteSt ring = vcm n_SCDnoteS tring + "\ n";
  815                }
  816  
  817                $vcmn_no seThroatRa diumInfo =  $vcmn_enr ollmentDet ermination Info.find( 'noseThroa tRadiumInf o');
  818                if ($vcm n_noseThro atRadiumIn fo != null ) {
  819                    $vcm n_diagnose dWithCance r = $vcmn_ noseThroat RadiumInfo .find('dia gnosedWith Cancer');
  820                    if ( $vcmn_diag nosedWithC ancer != n ull) { vcm n_diagnose dWithCance rText = $v cmn_diagno sedWithCan cer.text() ; }
  821                }
  822  
  823                $vcmn_mi litarySexu alTraumaIn fo = $vcmn _enrollmen tDetermina tionInfo.f ind('milit arySexualT raumaInfo' );
  824                if ($vcm n_military SexualTrau maInfo !=  null) {
  825                    $vcm n_milSexTr aumaStatus  = $vcmn_m ilitarySex ualTraumaI nfo.find(' status');
  826                    if ( $vcmn_milS exTraumaSt atus != nu ll) { vcmn _milSexTra umaStatusT ext = $vcm n_milSexTr aumaStatus .text(); }
  827                }
  828           }
  829  
  830           $v cmn_milita ryServiceI nfo = $vcm n_xml.find ('military ServiceInf o');
  831           if  ($vcmn_mi litaryServ iceInfo !=  null) {
  832                $vcmn_co mbatVetera nEligibili tyEndDate  = $vcmn_mi litaryServ iceInfo.fi nd('combat VeteranEli gibilityEn dDate');
  833                if ($vcm n_combatVe teranEligi bilityEndD ate != nul l) {
  834                    vcmn _combatVet eranEligib ilityEndDa teText = v cmn_combat VeteranEli gibilityEn dDateText  = $vcmn_co mbatVetera nEligibili tyEndDate. text();
  835                }
  836                $vcmn_sh adIndicato r = $vcmn_ militarySe rviceInfo. find('shad Indicator' );
  837                if ($vcm n_shadIndi cator != n ull) { vcm n_shadIndi catorText  = $vcmn_sh adIndicato r.text();  }
  838           }
  839  
  840           // If no elig ibility sp ecified, s et to fals e
  841           if  (vcmn_typ eText == n ull || vcm n_typeText  == '') {  vcmn_typeT ext = fals e; }
  842  
  843           // Change boo lean value s to false  if not ma rked true
  844           if  (vcmn_env Contaminan tsIndText  != 'true')  { vcmn_en vContamina ntsIndText  = false;  }
  845           if  (vcmn_rad iationExpo sureIndTex t != 'true ') { vcmn_ radiationE xposureInd Text = fal se; }
  846           if  (vcmn_age ntOrangeIn dText != ' true') { v cmn_agentO rangeIndTe xt = false ; }
  847           if  (vcmn_cam pLejeuneIn dText != ' true') { v cmn_campLe jeuneIndTe xt = false ; }
  848  
  849           if  (vcmn_dia gnosedWith CancerText  != 'true' ) { vcmn_d iagnosedWi thCancerTe xt = false ; }
  850           if  (vcmn_sha dIndicator Text != 't rue') { vc mn_shadInd icatorText  = false;  }
  851  
  852           // Change all  True/Fals e to Yes/N o
  853           if  (vcmn_typ eText == f alse) { vc mn_typeTex t = 'No';  }
  854  
  855           if  (vcmn_env Contaminan tsIndText  == "true")  { vcmn_en vContamina ntsIndText  = "Yes";  } else { v cmn_envCon taminantsI ndText = " No"; }
  856           if  (vcmn_rad iationExpo sureIndTex t == "true ") {
  857                vcmn_rad iationExpo sureIndTex t = "Yes";
  858                if (vcmn _radiation ExposureMe thodText ! = null) {  vcmn_radia tionExposu reIndText  = vcmn_rad iationExpo sureIndTex t + " - "  + vcmn_rad iationExpo sureMethod Text; }
  859           }  else {
  860                vcmn_rad iationExpo sureIndTex t = "No"; 
  861           }
  862           if  (vcmn_age ntOrangeIn dText == " true") {
  863                vcmn_age ntOrangeIn dText = "Y es";
  864                if (vcmn _agentOran geLocation Text != nu ll) { vcmn _agentOran geIndText  = vcmn_age ntOrangeIn dText + "  - " + vcmn _agentOran geLocation Text; }
  865           }
  866           el se {
  867                vcmn_age ntOrangeIn dText = "N o"; 
  868           }
  869           if  (vcmn_cam pLejeuneIn dText == " true") { v cmn_campLe jeuneIndTe xt = "Yes" ; } else {  vcmn_camp LejeuneInd Text = "No "; }
  870  
  871           if  (vcmn_dia gnosedWith CancerText  == "true" ) { vcmn_d iagnosedWi thCancerTe xt = "Yes" ; } else {  vcmn_diag nosedWithC ancerText  = "No"; }
  872  
  873           if  (vcmn_com batVeteran Eligibilit yEndDateTe xt != null  && vcmn_c ombatVeter anEligibil ityEndDate Text != '' ) { vcmn_c ombatVeter anEligibil ityEndDate Text = 'Ye s'; } 
  874  
  875           if  (vcmn_sha dIndicator Text == "t rue") { vc mn_shadInd icatorText  = "Yes";  } else { v cmn_shadIn dicatorTex t = "No";  }
  876           
  877           // Construct  summary no te part
  878           if  (vcmn_env Contaminan tsIndText  != null &&  vcmn_envC ontaminant sIndText ! = '') { vc mn_SCDnote String = v cmn_SCDnot eString +  "Environme ntal Conta minant: "  + vcmn_env Contaminan tsIndText  + "\n"; }
  879           if  (vcmn_com batVeteran Eligibilit yEndDateTe xt != null  && vcmn_c ombatVeter anEligibil ityEndDate Text != '' ) { vcmn_S CDnoteStri ng = vcmn_ SCDnoteStr ing + "Com bat Vetera n: " + vcm n_combatVe teranEligi bilityEndD ateText +  "\n"; }
  880           if  (vcmn_rad iationExpo sureIndTex t != null  && vcmn_ra diationExp osureIndTe xt != '')  { vcmn_SCD noteString  = vcmn_SC DnoteStrin g + "Radia tion Expos ure: " + v cmn_radiat ionExposur eIndText +  "\n"; }
  881           if  (vcmn_age ntOrangeIn dText != n ull && vcm n_agentOra ngeIndText  != '') {  vcmn_SCDno teString =  vcmn_SCDn oteString  + "Agent O range: " +  vcmn_agen tOrangeInd Text + "\n "; }
  882           if  (vcmn_sha dIndicator Text != nu ll && vcmn _shadIndic atorText ! = '') { vc mn_SCDnote String = v cmn_SCDnot eString +  "Shipboard  Hazard &  Defense: "  + vcmn_sh adIndicato rText + "\ n"; }
  883           if  (vcmn_dia gnosedWith CancerText  != null & & vcmn_dia gnosedWith CancerText  != '') {  vcmn_SCDno teString =  vcmn_SCDn oteString  + "Head/Ne ck Cancer:  " + vcmn_ diagnosedW ithCancerT ext + "\n" ; }
  884           if  (vcmn_mil SexTraumaS tatusText  != null &&  vcmn_milS exTraumaSt atusText ! = '') { vc mn_SCDnote String = v cmn_SCDnot eString +  "Military  Sexual Tra uma: " + v cmn_milSex TraumaStat usText + " \n"; }
  885           if  (vcmn_cam pLejeuneIn dText != n ull && vcm n_campLeje uneIndText  != '') {  vcmn_SCDno teString =  vcmn_SCDn oteString  + "Camp Le jeune: " +  vcmn_camp LejeuneInd Text + "\n "; }
  886  
  887           // Update not e with new  SCD note  data
  888           va r vcmn_exi stingNoteD ata = "";
  889           if  (Xrm.Page .getAttrib ute("ftp_n otedetail" ).getValue () != null  && Xrm.Pa ge.getAttr ibute("ftp _notedetai l").getVal ue() != "" ) {
  890                vcmn_exi stingNoteD ata = Xrm. Page.getAt tribute("f tp_notedet ail").getV alue();
  891           }
  892           vc mn_extende dTemplateD ata = vcmn _existingN oteData +  vcmn_SCDno teString;
  893           // Replace ex isting not e
  894           Xr m.Page.get Attribute( 'ftp_noted etail').se tValue(vcm n_extended TemplateDa ta);
  895           Xr m.Page.get Attribute( 'ftp_noted etail').se tSubmitMod e('always' );
  896       }
  897       catch  (err) {
  898           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_getS erviceConn ectedDisab ilities):  ' + err.me ssage);
  899       }
  900   }
  901  
  902   function v cmn_getDis abilityDat a(vcmn_nat ionalId) {
  903       try {
  904           va r vcmn_ees ummaryURL  = vcmn_ees ummaryURLb ase + '000 000' + vcm n_national Id + '0000 00';
  905           va r vcmn_xml Data = nul l;
  906  
  907           $. ajax({
  908                type: "G ET",
  909                url: vcm n_eesummar yURL,
  910                contentT ype: "appl ication/xm l; charset =utf-8",
  911                dataType : "text",
  912                success:  function  (xmlTextda ta) {
  913                    vcmn _xmlData =  xmlTextda ta;
  914                },
  915                error: f unction (j qXHR, text Status, er rorThrown)  {
  916                    //Sy stem Error
  917                    vcmn _xmlData =  null;
  918                },
  919                async: f alse,
  920                cache: f alse
  921           }) ;
  922           re turn vcmn_ xmlData;
  923       }
  924       catch  (err) {
  925           al ert("Progr ess Note F orm Load S cript Func tion Error (vcmn_getD isabilityD ata): " +  err.messag e);
  926           re turn null;
  927       }
  928   }
  929  
  930   function v cmn_facili tyByCode_r esponse(vc mn_facilit yData, vcm n_lastSkip , vcmn_fac ilityCode)  {
  931       try {
  932           // vcmn_lastS kip is the  starting  point in t he result  (use if mo re than 50  records)  //Not used  in this s cenario
  933           // ***REVISED  NOT USED,  KEEP FOR  FUTURE UPD ATE***
  934           /*
  935           va r vcmn_fac ilityid =  null;
  936           va r vcmn_fac ilityname  = null;
  937           fo r (var i =  0; i <= v cmn_facili tyData.d.r esults.len gth - 1; i ++) {
  938                //Get in fo
  939                if (vcmn _facilityD ata.d.resu lts[i].ftp _facilityI d != null)  { vcmn_fa cilityid =  vcmn_faci lityData.d .results[i ].ftp_faci lityId; }
  940                if (vcmn _facilityD ata.d.resu lts[i].ftp _name != n ull) { vcm n_facility name = vcm n_facility Data.d.res ults[i].ft p_name; }
  941                break;
  942           }
  943           if  (vcmn_fac ilityid !=  null) {
  944                vcmn_set SimpleLook upValue('f tp_patient facility',  'ftp_faci lity', vcm n_facility id, vcmn_f acilitynam e);
  945                Xrm.Page .getAttrib ute('ftp_p atientfaci lity').set SubmitMode ('always') ;
  946           }
  947           */
  948       }
  949       catch  (err) {
  950           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_faci lityByCode _response) : ' + err. message);
  951       }
  952   }
  953  
  954   function v cmn_cptCod e_response (vcmn_cptC odeData, v cmn_lastSk ip, vcmn_t riageminut es) {
  955       try {
  956           // vcmn_lastS kip is the  starting  point in t he result  (use if mo re than 50  records)  //Not used  in this s cenario
  957           fo r (var i =  0; i <= v cmn_cptCod eData.d.re sults.leng th - 1; i+ +) {
  958                //Write  to CRM pro gress note  form
  959                vcmn_set SimpleLook upValue('f tp_cptcode ', 'ftp_cp tcode', vc mn_cptCode Data.d.res ults[i].ft p_cptcodeI d, vcmn_cp tCodeData. d.results[ i].ftp_nam e);
  960                Xrm.Page .getAttrib ute('ftp_c ptcode').s etSubmitMo de('always ');
  961                break;
  962           }
  963       }
  964       catch  (err) {
  965           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_cptC ode_respon se): ' + e rr.message );
  966       }
  967   }
  968  
  969   function v cmn_ribbon ButtonSave () {
  970       try {
  971           // Save the c urrent CRM  data
  972           Xr m.Page.dat a.entity.s ave();
  973       }
  974       catch  (err) {
  975           al ert('Progr ess Note R ibbon Func tion Error (vcmn_ribb onButtonSa ve): ' + e rr.message );
  976       }
  977   }
  978  
  979   function v cmn_getCoo kie(cname)  {
  980       try {
  981           va r name = c name + "=" ;
  982           va r ca = doc ument.cook ie.split(' ;');
  983           fo r (var i =  0; i < ca .length; i ++) {
  984                var c =  ca[i];
  985                while (c .charAt(0)  == ' ') {
  986                    c =  c.substrin g(1);
  987                }
  988                if (c.in dexOf(name ) == 0) {
  989                    retu rn c.subst ring(name. length, c. length);
  990                }
  991           }
  992           re turn "";
  993       }
  994       catch  (err) {
  995           al ert('Progr ess Note R ibbon Func tion Error (vcmn_getC ookie): '  + err.mess age);
  996       }
  997   }
  998  
  999   function v cmn_wordWr ap(str, in tWidth, st rBreak, cu t) {
  1000       try {
  1001           // Takes a st ring that  exceeds a  set length  and inser ts word wr ap
  1002           va r m = ((ar guments.le ngth >= 2)  ? argumen ts[1] : 75 )
  1003           va r b = ((ar guments.le ngth >= 3)  ? argumen ts[2] : '\ n')
  1004           va r c = ((ar guments.le ngth >= 4)  ? argumen ts[3] : fa lse)
  1005  
  1006           va r i, j, l,  s, r
  1007  
  1008           st r += ''
  1009  
  1010           if  (m < 1) {
  1011                return s tr
  1012           }
  1013  
  1014           fo r (i = -1,  l = (r =  str.split( /\r\n|\n|\ r/)).lengt h; ++i < l ; r[i] +=  s) {
  1015                for (s =  r[i], r[i ] = '';
  1016                  s.leng th > m;
  1017                  r[i] + = s.slice( 0, j) + (( s = s.slic e(j)).leng th ? b : ' ')) {
  1018                    j =  c === 2 ||  (j = s.sl ice(0, m +  1).match( /\S*(\s)?$ /))[1]
  1019                      ?  m
  1020                      :  j.input.le ngth - j[0 ].length | | c === tr ue && m ||
  1021                         j.input.le ngth + (j  = s.slice( m).match(/ ^\S*/))[0] .length
  1022                }
  1023           }
  1024  
  1025           re turn r.joi n('\n')
  1026       }
  1027       catch  (err) {
  1028           al ert('Progr ess Note R ibbon Func tion Error (vcmn_word Wrap): ' +  err.messa ge);
  1029       }
  1030   }
  1031  
  1032   function v cmn_ribbon ButtonSave ToVistA()  {
  1033       try {
  1034           // Check the  value of t he Integra tion Statu s Field, i f = 'OK',  stop and e xit this s cript
  1035           va r vcmn_int egrationSt atus = Xrm .Page.getA ttribute(' ftp_integr ationstatu s').getVal ue();
  1036           if  (vcmn_int egrationSt atus == 'O K') { retu rn false;  }
  1037  
  1038           // Prompt use r to sign  the note
  1039           va r vcmn_sig nThisNote  = Xrm.Page .getAttrib ute('ftp_s ignthisnot e').getVal ue();
  1040           va r vcmn_sig nThisNoteF ailure = f alse;
  1041           if  (vcmn_sig nThisNote  == null) {
  1042                Xrm.Util ity.confir mDialog(
  1043                    "Do  you need t o sign thi s note?, S elect OK i f Yes, oth erwise CAN CEL.",
  1044                    func tion () {
  1045                         //Check if  VIA Login  cookie ex ist (not e xpired)
  1046                         var vcmn_V iaLoginCoo kie = vcmn _getCookie ("viasessi onlink");
  1047                         //Prompt u ser to log in to VIA
  1048                         if (vcmn_V iaLoginCoo kie == "")  {
  1049                             alert( "Your VIST A session  has expire d. In orde r to sign  this note,  you must  be logged  into VISTA !");
  1050                             Xrm.Pa ge.ui.tabs .get('Tab_ VistALogin ').setVisi ble(false) ;
  1051                             Xrm.Pa ge.ui.tabs .get('Tab_ VistALogin ').setFocu s();
  1052                             vcmn_s ignThisNot eFailure =  true;
  1053                             return ;
  1054                         }
  1055                         Xrm.Page.g etAttribut e('ftp_sig nthisnote' ).setValue (100000001 );
  1056                    },
  1057                    func tion () {
  1058                         Xrm.Page.g etAttribut e('ftp_sig nthisnote' ).setValue (100000000 );
  1059                    }
  1060                );
  1061                Xrm.Page .getAttrib ute('ftp_s ignthisnot e').setSub mitMode('a lways');
  1062           }
  1063           if  (vcmn_sig nThisNoteF ailure ==  true) {
  1064                //****** Developer  Bypass for  no VISTA  authentica tion******
  1065                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}") {
  1066                    aler t("Develop er VISTA a uthenticat ion bypass  applied!" );
  1067                    Xrm. Page.getAt tribute('f tp_signthi snote').se tValue(100 000001);
  1068                    Xrm. Page.getAt tribute('f tp_signthi snote').se tSubmitMod e('always' );
  1069                }
  1070                else {
  1071                    retu rn false;
  1072                }
  1073           }
  1074  
  1075           // Save the c urrent CRM  data
  1076           Xr m.Page.dat a.entity.s ave();
  1077           // Display YE LLOW Progr ess....
  1078           Xr m.Page.ui. setFormNot ification( "Verifying  progress  note data,  please wa it..", "IN FO", "SAVE VISTA");
  1079  
  1080           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!');
  1081           if  (vcmn_con firmSaveTo Vista == f alse) {
  1082                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1083                return f alse;
  1084           }
  1085           // Get regard ing data
  1086           va r vcmn_req uestId = X rm.Page.ge tAttribute ('regardin gobjectid' ).getValue ();
  1087           if  (vcmn_req uestId ==  null) {
  1088                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 !');
  1089                Xrm.Page .getContro l('regardi ngobjectid ').setFocu s();
  1090                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1091                return f alse;
  1092           }
  1093           // Verify tha t the rega rdingid is  of type ' incident'
  1094           if  (vcmn_req uestId[0]. entityType  != 'incid ent') {
  1095                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!') ;
  1096                Xrm.Page .getContro l('regardi ngobjectid ').setFocu s();
  1097                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1098                return f alse;
  1099           }
  1100  
  1101           // Preserved  Variables
  1102           va r vcmn_vet eranId = n ull;  //Fr om request  customeri d
  1103           va r vcmn_vet eranFirstN ame = '';
  1104           va r vcmn_vet eranLastNa me = '';
  1105           va r vcmn_SSN  = '';
  1106           va r vcmn_DOB  = '';
  1107  
  1108           va r vcmn_req uestData =  vcmn_getS ingleEntit yDataSync( 'IncidentS et', 'Cust omerId', v cmn_reques tId[0].id) ;
  1109           if  (vcmn_req uestData ! = null) {
  1110                if (vcmn _requestDa ta.d.Custo merId != n ull) {
  1111                    vcmn _veteranId  = vcmn_re questData. d.Customer Id;
  1112                    //Ve rify that  the custom erid is of  type cont act
  1113                    if ( vcmn_veter anId.Logic alName !=  'contact')  {
  1114                         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!') ;
  1115                         Xrm.Page.u i.clearFor mNotificat ion("SAVEV ISTA");
  1116                         return fal se;
  1117                    }
  1118                }
  1119           }
  1120           if  (vcmn_vet eranId ==  null) {
  1121                alert('T he related  request d oes not ha ve a veter an/contact  assigned,  the note  cannot be  created in  VistA/CPR S!');
  1122                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1123                return f alse;
  1124           }
  1125  
  1126           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);
  1127           if  (vcmn_con tactData ! = null) {
  1128                if (vcmn _contactDa ta.d.First Name != nu ll) { vcmn _veteranFi rstName =  vcmn_conta ctData.d.F irstName;  }
  1129                if (vcmn _contactDa ta.d.LastN ame != nul l) { vcmn_ veteranLas tName = vc mn_contact Data.d.Las tName; }
  1130                if (vcmn _contactDa ta.d.ftp_D ateofBirth  != null)  { vcmn_DOB  = vcmn_co ntactData. d.ftp_Date ofBirth; }
  1131                if (vcmn _contactDa ta.d.Gover nmentId !=  null) { v cmn_SSN =  vcmn_conta ctData.d.G overnmentI d; }
  1132           }
  1133  
  1134           // Perform MV I Search
  1135           vc mn_unatten dedMviSear ch(vcmn_ve teranFirst Name, vcmn _veteranLa stName, vc mn_DOB, vc mn_SSN);
  1136       }
  1137       catch  (err) {
  1138           al ert('Progr ess Note R ibbon Func tion Error (vcmn_ribb onButtonSa veToVistA) : ' + err. message);
  1139           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1140       }
  1141   }
  1142  
  1143   function v cmn_ribbon ButtonSave ToVistA_wi th_ICN(vcm n_patientI CN) {
  1144       try {
  1145           // ******Deve loper Bypa ss for mis sing ICN** ****
  1146           if  (vcmn_pat ientICN ==  '' || vcm n_patientI CN == null ) {
  1147                if ((Xrm .Page.cont ext.getUse rId()).toU pperCase()  == "{CA50 0504-CBC5- E511-8173- 000C2941CE 19}") {
  1148                    aler t("Develop er ICN byp ass applie d!");
  1149                    vcmn _patientIC N = "12345 6V123456";
  1150                }
  1151           }
  1152  
  1153           // Verify Pat ient ICN
  1154           if  (vcmn_pat ientICN ==  '' || vcm n_patientI CN == null ) {
  1155                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! ');
  1156                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1157                return f alse;
  1158           }
  1159           
  1160           // Get regard ing data
  1161           va r vcmn_req uestId = X rm.Page.ge tAttribute ('regardin gobjectid' ).getValue ();
  1162  
  1163           // Preserved  Variables
  1164           va r vcmn_vet eranId = n ull;  //Fr om request  customeri d
  1165           va r vcmn_vet eranName =  '';
  1166           va r vcmn_vet eranFirstN ame = '';
  1167           va r vcmn_vet eranLastNa me = '';
  1168           va r vcmn_vet eranMiddle Name = '';
  1169  
  1170           va r vcmn_req uestData =  vcmn_getS ingleEntit yDataSync( 'IncidentS et', 'Cust omerId', v cmn_reques tId[0].id) ;
  1171           if  (vcmn_req uestData ! = null) {
  1172                if (vcmn _requestDa ta.d.Custo merId != n ull) {
  1173                    vcmn _veteranId  = vcmn_re questData. d.Customer Id;
  1174                    //Ve rify that  the custom erid is of  type cont act
  1175                    if ( vcmn_veter anId.Logic alName !=  'contact')  {
  1176                         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!') ;
  1177                         Xrm.Page.u i.clearFor mNotificat ion("SAVEV ISTA");
  1178                         return fal se;
  1179                    }
  1180                }
  1181           }
  1182           if  (vcmn_vet eranId ==  null) {
  1183                alert('T he related  request d oes not ha ve a veter an/contact  assigned,  the note  cannot be  created in  VistA/CPR S!');
  1184                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1185                return f alse;
  1186           }
  1187  
  1188           va r vcmn_con tactData =  vcmn_getS ingleEntit yDataSync( 'ContactSe t', 'FullN ame, First Name, Last Name, Midd leName', v cmn_vetera nId.Id);
  1189           if  (vcmn_con tactData ! = null) {
  1190                if (vcmn _contactDa ta.d.FullN ame != nul l) { vcmn_ veteranNam e = vcmn_c ontactData .d.FullNam e; }
  1191                if (vcmn _contactDa ta.d.First Name != nu ll) { vcmn _veteranFi rstName =  vcmn_conta ctData.d.F irstName;  }
  1192                if (vcmn _contactDa ta.d.LastN ame != nul l) { vcmn_ veteranLas tName = vc mn_contact Data.d.Las tName; }
  1193                if (vcmn _contactDa ta.d.Middl eName != n ull) { vcm n_veteranM iddleName  = vcmn_con tactData.d .MiddleNam e; }
  1194           }
  1195  
  1196           // Get user d ata
  1197           va r vcmn_crm UserId = X rm.Page.ge tAttribute ('ownerid' ).getValue ();
  1198           va r vcmn_use rDomainId  = '';
  1199           va r vcmn_use rFirstName  = '';
  1200           va r vcmn_use rLastName  = '';
  1201           va r vcmn_use rMiddleNam e = '';
  1202           va r vcmn_use rSiteId =  '';
  1203  
  1204           if  (vcmn_crm UserId !=  null) {
  1205                //Verify  the owner  type
  1206                if (vcmn _crmUserId [0].entity Type != 's ystemuser' ) {
  1207                    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 !');
  1208                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  1209                    retu rn false;
  1210                }
  1211  
  1212                var vcmn _userData  = vcmn_get SingleEnti tyDataSync ('SystemUs erSet', 'D omainName,  FirstName , LastName , MiddleNa me, ftp_Fa cilitySite Id', vcmn_ crmUserId[ 0].id);
  1213                if (vcmn _userData  != null) {
  1214                    if ( vcmn_userD ata.d.Doma inName !=  null) { vc mn_userDom ainId = vc mn_userDat a.d.Domain Name; }
  1215                    if ( vcmn_userD ata.d.Firs tName != n ull) { vcm n_userFirs tName = vc mn_userDat a.d.FirstN ame; }
  1216                    if ( vcmn_userD ata.d.Last Name != nu ll) { vcmn _userLastN ame = vcmn _userData. d.LastName ; }
  1217                    if ( vcmn_userD ata.d.Midd leName !=  null) { vc mn_userMid dleName =  vcmn_userD ata.d.Midd leName; }
  1218                    if ( vcmn_userD ata.d.ftp_ FacilitySi teId != nu ll) { vcmn _userSiteI d = vcmn_u serData.d. ftp_Facili tySiteId.I d; }
  1219                }
  1220           }
  1221           el se {
  1222                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!');
  1223                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1224                return f alse;
  1225           }
  1226  
  1227           // Verify tha t the curr ent owner  and the cu rrent user  is the sa me person,  if not do  not proce ed
  1228           if  ((vcmn_cr mUserId[0] .id).toUpp erCase() ! = (Xrm.Pag e.context. getUserId( )).toUpper Case()) {
  1229                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!');
  1230                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1231                return f alse;
  1232           }
  1233           va r vcmn_Not eUserTeam  = "NONE";
  1234           // Check Team  membershi p
  1235           if  (vcmn_Use rHasTeam(" Pharmacy",  Xrm.Page. context.ge tUserId()) ) { vcmn_N oteUserTea m = "PHARM ACY"; }
  1236           if  (vcmn_Use rHasTeam(" CCA Team",  Xrm.Page. context.ge tUserId()) ) { vcmn_N oteUserTea m = "CCA";  }
  1237           if  (vcmn_Use rHasTeam(" TAN", Xrm. Page.conte xt.getUser Id())) { v cmn_NoteUs erTeam = " TAN"; }
  1238           // **TEMP, ve rify these  team valu es that th ey are cor rect **FUT URE NEED**
  1239           if  (vcmn_Use rHasTeam(" PACT User" , Xrm.Page .context.g etUserId() )) { vcmn_ NoteUserTe am = "PACT "; }
  1240           if  (vcmn_Use rHasTeam(" MSA User",  Xrm.Page. context.ge tUserId()) ) { vcmn_N oteUserTea m = "MSA";  }
  1241  
  1242           // Verify Tea m Value, t hat one ha s been ass igned
  1243           if  (vcmn_Not eUserTeam  == "NONE")  {
  1244                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 !');
  1245                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1246                return f alse;
  1247           }
  1248  
  1249           // Get reques t form con tent
  1250           va r vcmn_not eDescripti on = Xrm.P age.getAtt ribute('ft p_notedeta il').getVa lue();
  1251           if  (vcmn_not eDescripti on == null  || vcmn_n oteDescrip tion == '' ) {
  1252                alert('T he note de scription  field is e mpty, the  note canno t be creat ed in Vist A/CPRS!');
  1253                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1254                return f alse;
  1255           }
  1256  
  1257           // Using new  hospital l ocation an d local no tes lookup  fields
  1258           va r vcmn_loc alTitle =  Xrm.Page.g etAttribut e('ftp_loc alnotetitl e').getVal ue();
  1259           if  (vcmn_loc alTitle ==  null) {
  1260                alert('T he local n ote title  field is e mpty, the  note canno t be creat ed in Vist A/CPRS!');
  1261                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1262                return f alse;
  1263           }
  1264           el se { vcmn_ localTitle  = vcmn_lo calTitle[0 ].name; }
  1265  
  1266           vc mn_patient AssignedLo cation = X rm.Page.ge tAttribute ('ftp_note hospitallo cation').g etValue();
  1267           if  (vcmn_pat ientAssign edLocation  == null)  {
  1268                alert('T he hospita l location  field is  empty, the  note cann ot be crea ted in Vis tA/CPRS!') ;
  1269                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1270                return f alse;
  1271           }
  1272           el se { vcmn_ patientAss ignedLocat ion = vcmn _patientAs signedLoca tion[0].na me; }
  1273           
  1274           va r vcmn_cal lbackNumbe r = Xrm.Pa ge.getAttr ibute('ftp _callbackn umber').ge tValue();
  1275           if  (vcmn_cal lbackNumbe r == null  || vcmn_ca llbackNumb er == '')  {
  1276                alert('T he callbac k number f ield is em pty, the n ote cannot  be create d in VistA /CPRS!');
  1277                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1278                return f alse;
  1279           }
  1280           va r vcmn_rea sonForRequ est = Xrm. Page.getAt tribute('f tp_reasonf orrequest' ).getValue ();
  1281           if  (vcmn_rea sonForRequ est == nul l) {
  1282                alert('T he reason  for reques t field is  empty, th e note can not be cre ated in Vi stA/CPRS!' );
  1283                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1284                return f alse;
  1285           }
  1286  
  1287           va r vcmn_enc ounterCode  = 'NEW';
  1288  
  1289           va r vcmn_sig nThisNote  = Xrm.Page .getAttrib ute('ftp_s ignthisnot e').getVal ue();
  1290           if  (vcmn_sig nThisNote  == 1000000 01) { vcmn _signThisN ote = true ; } else {  vcmn_sign ThisNote =  false; }
  1291           va r vcmn_cre atedDateTi me = Xrm.P age.getAtt ribute('sc heduledsta rt').getVa lue();
  1292  
  1293           // Get Progre ss Note Gu id/Id
  1294           va r vcmn_not eId = Xrm. Page.data. entity.get Id();
  1295  
  1296           // Get Create d On Date  & Convert  format
  1297           va r vcmn_cre atedOnDate  = vcmn_co nvertCrmDa teToVistAD ate(Xrm.Pa ge.getAttr ibute('cre atedon').g etValue()) ;
  1298           if  (vcmn_cre atedOnDate  == null)  {
  1299                alert('T he CRM cre atedon fie ld is empt y, the not e cannot b e created  in VistA/C PRS!');
  1300                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1301                return f alse;
  1302           }     
  1303  
  1304           // Get Patien t Admit Da te & Conve rt format
  1305           va r vcmn_pat ientAdmitD ate = vcmn _convertCr mDateToVis tADate(Xrm .Page.getA ttribute(' ftp_patien tadmitdate ').getValu e());
  1306  
  1307           if  (vcmn_pat ientAdmitD ate == nul l) {
  1308                alert('T he CRM pat ient admit  date fiel d is empty , the note  cannot be  created i n VistA/CP RS!');
  1309                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1310                return f alse;
  1311           }
  1312  
  1313           // Get Facili ty and loo kup facili ty number  and HL7 UR L
  1314           va r vcmn_fac ilityCode  = '';
  1315           va r vcmn_sit eHL7Listen erAddress  = '';
  1316           va r vcmn_pat ientFacili ty = Xrm.P age.getAtt ribute('ft p_patientf acility'). getValue() ;
  1317           if  (vcmn_pat ientFacili ty == null ) {
  1318                alert('T he CRM pat ient facil ity field  is empty,  the note c annot be c reated in  VistA/CPRS !');
  1319                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1320                return f alse;
  1321           }
  1322           el se {
  1323                var vcmn _facilityD ata = vcmn _getSingle EntityData Sync('ftp_ facilitySe t', 'ftp_f acilitycod e, ftp_hl7 listener',  vcmn_pati entFacilit y[0].id);
  1324                if (vcmn _facilityD ata.d.ftp_ facilityco de != null ) {
  1325                    vcmn _facilityC ode = vcmn _facilityD ata.d.ftp_ facilityco de;
  1326                }
  1327                else {
  1328                    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!') ;
  1329                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  1330                    retu rn false;
  1331                }
  1332  
  1333                if (vcmn _facilityD ata.d.ftp_ hl7listene r != null)  {
  1334                    var  vcmn_siteH L7Listener Address =  vcmn_facil ityData.d. ftp_hl7lis tener;
  1335                }
  1336                else {
  1337                    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!');
  1338                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  1339                    retu rn false;
  1340                }
  1341           }
  1342  
  1343           va r vcmn_ori ginatorID  = '';
  1344           va r vcmn_use rSiteNo =  '';
  1345  
  1346           // Lookup the  Facility/ Site #
  1347           if  (vcmn_use rSiteId !=  null && v cmn_userSi teId != '' ) {
  1348                var vcmn _facilityD ata = vcmn _getSingle EntityData Sync('ftp_ facilitySe t', 'ftp_f acilitycod e', vcmn_u serSiteId) ;
  1349                if (vcmn _facilityD ata != nul l) {
  1350                    if ( vcmn_facil ityData.d. ftp_facili tycode !=  null) { vc mn_userSit eNo = vcmn _facilityD ata.d.ftp_ facilityco de; }
  1351                }
  1352           }
  1353  
  1354           // Validate r equired Vi sta Lookup  info
  1355           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) {
  1356                //Abort  process, m issing inf o
  1357                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 !');
  1358                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1359                return f alse;
  1360           }
  1361  
  1362           // ***Tempora ry Test Us er Search* *******
  1363           if  (vcmn_IsP roductionE nvironment  == false)  {
  1364                //Provid e the opti on to sear ch for Lor i Nicholls , site# 61 3
  1365                var vcmn _impersona tePromptSt ring = "** THIS IS A  VISTA USER  SEARCH TE ST PROMPT* * \n" +
  1366                    "If  you would  like to im personate  the user:  \n" +
  1367                    "Lor i Nicholls  (613) \n"  +
  1368                    "Sel ect OK.  O therwise,  select CAN CEL.";
  1369                var vcmn _confirmIm personateV istaUser =  confirm(v cmn_impers onatePromp tString);
  1370                if (vcmn _confirmIm personateV istaUser = = true) {
  1371                    vcmn _userFirst Name = "Lo ri";
  1372                    vcmn _userLastN ame = "Nic holls";
  1373                    vcmn _userSiteN o = "613";
  1374                }
  1375           }
  1376           // ********** ********** ********** *******
  1377  
  1378           va r vcmn_vis tausersDat a = vcmn_g etVistaUse rsData(vcm n_userFirs tName, vcm n_userLast Name, vcmn _userSiteN o, false);
  1379  
  1380           // ********** ********** ********** *********
  1381           // Temporary  JSON TEST  DATA, comm ent out wh en not nee ded
  1382           /*
  1383           vc mn_vistaus ersData =  {
  1384                "ErrorOc curred": f alse,
  1385                "ErrorMe ssage": nu ll,
  1386                "Status" : null,
  1387                "DebugIn fo": null,
  1388                "Data":  [
  1389                         {
  1390                             "First Name": "LO RI",
  1391                             "Middl eName": "E ",
  1392                             "LastN ame": "NIC HOLLS",
  1393                             "Suffi x": "JR",
  1394                             "Displ ayName": " NICHOLLS,L ORI E JR",
  1395                             "Title ": "HDR Sr . Develope r"
  1396                          },
  1397                          {
  1398                              "Firs tName": "F IVE",
  1399                              "Midd leName": " ",
  1400                              "Last Name": "PR OVIDER",
  1401                              "Titl e": "Schol ar Extraor dinaire"
  1402                          },
  1403                          {
  1404                              "Firs tName": "F IVEHUNDRED ONE",
  1405                              "Midd leName": " ",
  1406                              "Last Name": "PR OVIDER",
  1407                              "Titl e": "Schol ar Extraor dinaire"
  1408                          },
  1409                          {
  1410                              "Firs tName": "F IVEHUNDRED TWO",
  1411                              "Midd leName": " ",
  1412                              "Last Name": "PR OVIDER",
  1413                              "Titl e": "Schol ar Extraor dinaire"
  1414                          }
  1415                ]
  1416           };
  1417           */
  1418           // ********** ********** ********** *********
  1419  
  1420           // Check vist a users da ta content
  1421           if  (vcmn_vis tausersDat a == null  || vcmn_vi stausersDa ta.Data ==  null || v cmn_vistau sersData.D ata.length  == null | | vcmn_vis tausersDat a.Data.len gth == 0)  {
  1422                //Abort  process, m issing inf o
  1423                alert('U nable to o btain Vist a User Dat a, the not e cannot b e created  in VistA/C PRS!');
  1424                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1425                return f alse;
  1426           }
  1427  
  1428           va r vcmn_sel ectedUserF irstName =  '';
  1429           va r vcmn_sel ectedUserM iddleName  = '';
  1430           va r vcmn_sel ectedUserL astName =  '';
  1431           va r vcmn_sel ectedUserS uffix = '' ;
  1432           va r vcmn_sel ectedUserD isplayName  = '';
  1433           va r vcmn_sel ectedUserT itle = '';
  1434           va r vcmn_use rIsSelecte d = false;
  1435  
  1436           if  (vcmn_vis tausersDat a.Data.len gth > 1) {
  1437                alert("T he Vista U ser list,  contains m ore than o ne user, p lease sele ct the Vis ta User yo u want to  use from t he next pr ompt(s), a  total of  " + vcmn_v istausersD ata.Data.l ength + "  users!");
  1438                for (var  i = 0; i  <= vcmn_vi stausersDa ta.Data.le ngth - 1;  i++) {
  1439                    var  vcmn_curre ntUserFirs tName = '' ;
  1440                    var  vcmn_curre ntUserMidd leName = ' ';
  1441                    var  vcmn_curre ntUserLast Name = '';
  1442                    var  vcmn_curre ntUserSuff ix = '';
  1443                    var  vcmn_curre ntUserDisp layName =  '';
  1444                    var  vcmn_curre ntUserTitl e = '';
  1445                    if ( vcmn_vista usersData. Data[i].Fi rstName !=  null) { v cmn_curren tUserFirst Name = vcm n_vistause rsData.Dat a[i].First Name; }
  1446                    if ( vcmn_vista usersData. Data[i].Mi ddleName ! = null) {  vcmn_curre ntUserMidd leName = v cmn_vistau sersData.D ata[i].Mid dleName; }
  1447                    if ( vcmn_vista usersData. Data[i].La stName !=  null) { vc mn_current UserLastNa me = vcmn_ vistausers Data.Data[ i].LastNam e; }
  1448                    if ( vcmn_vista usersData. Data[i].Su ffix != nu ll) { vcmn _currentUs erSuffix =  vcmn_vist ausersData .Data[i].S uffix; }
  1449                    if ( vcmn_vista usersData. Data[i].Di splayName  != null) {  vcmn_curr entUserDis playName =  vcmn_vist ausersData .Data[i].D isplayName ; }
  1450                    if ( vcmn_vista usersData. Data[i].Ti tle != nul l) { vcmn_ currentUse rTitle = v cmn_vistau sersData.D ata[i].Tit le; }
  1451                    //Pr ompt user  about this  vista use r record
  1452                    var  vcmn_userP romptStrin g = "Click  OK, to se lect this  user.  Oth erwise CAN CEL \n" +
  1453                         "\n First  Name: " +  vcmn_curre ntUserFirs tName +
  1454                         "\n Middle  Name: " +  vcmn_curr entUserMid dleName +
  1455                         "\n Last N ame: " + v cmn_curren tUserLastN ame +
  1456                         "\n Suffix : " + vcmn _currentUs erSuffix +
  1457                         "\n Displa y Name: "  + vcmn_cur rentUserDi splayName  +
  1458                         "\n Title:  " + vcmn_ currentUse rTitle;
  1459  
  1460                    var  vcmn_confi rmSelectVi staUser =  confirm(vc mn_userPro mptString) ;
  1461                    if ( vcmn_confi rmSelectVi staUser ==  true) {
  1462                         vcmn_userI sSelected  = true;
  1463                         vcmn_selec tedUserFir stName = v cmn_curren tUserFirst Name;
  1464                         vcmn_selec tedUserMid dleName =  vcmn_curre ntUserMidd leName;
  1465                         vcmn_selec tedUserLas tName = vc mn_current UserLastNa me;
  1466                         vcmn_selec tedUserSuf fix = vcmn _currentUs erSuffix;
  1467                         vcmn_selec tedUserDis playName =  vcmn_curr entUserDis playName;
  1468                         vcmn_selec tedUserTit le = vcmn_ currentUse rTitle;
  1469                         break;
  1470                    }
  1471                }
  1472           }
  1473           el se {
  1474                //Select  data from  the first  record
  1475                vcmn_use rIsSelecte d = true;
  1476                if (vcmn _vistauser sData.Data [0].FirstN ame != nul l) { vcmn_ selectedUs erFirstNam e = vcmn_v istausersD ata.Data[0 ].FirstNam e; }
  1477                if (vcmn _vistauser sData.Data [0].Middle Name != nu ll) { vcmn _selectedU serMiddleN ame = vcmn _vistauser sData.Data [0].Middle Name; }
  1478                if (vcmn _vistauser sData.Data [0].LastNa me != null ) { vcmn_s electedUse rLastName  = vcmn_vis tausersDat a.Data[0]. LastName;  }
  1479                if (vcmn _vistauser sData.Data [0].Suffix  != null)  { vcmn_sel ectedUserS uffix = vc mn_vistaus ersData.Da ta[0].Suff ix; }
  1480                if (vcmn _vistauser sData.Data [0].Displa yName != n ull) { vcm n_selected UserDispla yName = vc mn_vistaus ersData.Da ta[0].Disp layName; }
  1481                if (vcmn _vistauser sData.Data [0].Title  != null) {  vcmn_sele ctedUserTi tle = vcmn _vistauser sData.Data [0].Title;  }
  1482           }
  1483  
  1484           // Check if a  user was  selected
  1485           if  (vcmn_use rIsSelecte d == false ) {
  1486                alert('A  user was  not select ed from th e previous  prompts,  the note c annot be c reated in  VistA/CPRS !');
  1487                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1488                return f alse;
  1489           }
  1490  
  1491           // Execute In tegration
  1492           vc mn_execute VistAInteg rationRequ est(vcmn_n oteId, vcm n_noteDesc ription, v cmn_patien tICN, vcmn _userDomai nId, vcmn_ localTitle , vcmn_cal lbackNumbe r, vcmn_re asonForReq uest[0].na me, vcmn_e ncounterCo de, vcmn_s ignThisNot e, vcmn_ve teranFirst Name, vcmn _veteranLa stName, vc mn_created OnDate, vc mn_patient AdmitDate,  vcmn_sele ctedUserFi rstName, v cmn_select edUserMidd leName, vc mn_selecte dUserLastN ame, vcmn_ selectedUs erSuffix,  vcmn_facil ityCode, v cmn_origin atorID, vc mn_siteHL7 ListenerAd dress, vcm n_patientA ssignedLoc ation);
  1493  
  1494       }
  1495       catch  (err) {
  1496           al ert('Progr ess Note R ibbon Func tion Error (vcmn_ribb onButtonSa veToVistA_ with_ICN):  ' + err.m essage);
  1497           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1498       }
  1499   }
  1500  
  1501   function v cmn_getVis taUsersDat a(vcmn_use rFirstName , vcmn_use rLastName,  vcmn_user SiteNo, vc mn_noFilte r) {
  1502       try {
  1503           va r vcmn_jso nData = nu ll;
  1504           $. ajax({
  1505                type: "G ET",
  1506                url: vcm n_VistaUse rsURLbase  + vcmn_use rFirstName  + "/" + v cmn_userLa stName + " /" + vcmn_ userSiteNo  + "?noFil ter=" + vc mn_noFilte r,
  1507                contentT ype: "appl ication/js on; charse t=utf-8",
  1508                dataType : "json",
  1509                success:  function  (data) {
  1510                    vcmn _jsonData  = data;
  1511                },
  1512                error: f unction (j qXHR, text Status, er rorThrown)  {
  1513                    //Sy stem Error
  1514                    vcmn _jsonData  = null;
  1515                },
  1516                async: f alse,
  1517                cache: f alse
  1518           }) ;
  1519           re turn vcmn_ jsonData;
  1520       }
  1521       catch  (err) {
  1522           al ert('Progr ess Note R ibbon Func tion Error (vcmn_getV istaUsersD ata): ' +  err.messag e);
  1523           re turn null;
  1524       }
  1525   }
  1526  
  1527   function v cmn_execut eVistAInte grationReq uest(vcmn_ noteId, vc mn_noteDes cription,  vcmn_patie ntICN, vcm n_userDoma inId, vcmn _localTitl e, vcmn_ca llbackNumb er, vcmn_r easonForRe quest, vcm n_encounte rCode, vcm n_signThis Note, vcmn _patientFi rstName, v cmn_patien tLastName,  vcmn_acti vityDate,  vcmn_patie ntAdmitDat e, vcmn_or iginatorFi rstName, v cmn_origin atorMiddle Name, vcmn _originato rLastName,  vcmn_orig inatorSuff ix, vcmn_f acilitySit eId, vcmn_ originator ID, vcmn_s iteHL7List enerAddres s, vcmn_pa tientAssig nedLocatio n) {
  1528       try {
  1529           // Reformat N ote Descri ption as n eeded to h andle long  lines of  text (Word Wrap)
  1530           va r vcmn_Not eText = vc mn_noteDes cription;
  1531           va r vcmn_Rev isedNoteTe xt = "";
  1532           // Do Breakdo wn of line s
  1533           va r vcmn_Tex tLines = v cmn_NoteTe xt.split(' \n');
  1534           if  (vcmn_Tex tLines.len gth > 0) {
  1535                //Reform at text
  1536                for (var  i = 0; i  < vcmn_Tex tLines.len gth; i++)  {
  1537                    //Te st for a l ong line
  1538                    if ( vcmn_TextL ines[i].le ngth > vcm n_WordWrap Limit) {
  1539                         //Break do wn line
  1540                         var vcmn_N ewString =  vcmn_word Wrap(vcmn_ TextLines[ i], vcmn_W ordWrapLim it, '\n');
  1541                         //Add revi sed text b ack
  1542                         vcmn_Revis edNoteText  = vcmn_Re visedNoteT ext + vcmn _NewString  + "\n";   //Add back  the CR/LF  used to s plit on
  1543                    }
  1544                    else  {
  1545                         //Add text  to new no te
  1546                         vcmn_Revis edNoteText  = vcmn_Re visedNoteT ext + vcmn _TextLines [i] + "\n" ; //Add ba ck the CR/ LF used to  split on
  1547                    }
  1548                }
  1549           }
  1550           if  (vcmn_Rev isedNoteTe xt != "" & & vcmn_Rev isedNoteTe xt != null ) {
  1551                vcmn_not eDescripti on = vcmn_ RevisedNot eText;
  1552           }
  1553  
  1554           va r vcmn_vis itNumber =  'NEW';
  1555           va r vcmn_cli entName =  "FTPCRM";
  1556           va r vcmn_For mat = "JSO N";
  1557           va r vcmn_pat ientIdenti fierType =  "ICN";
  1558           va r vcmn_doc umentAvail abilitySta tus = "AV" ;  //Histo rical Note  only at t his time
  1559           va r vcmn_ori ginatorCom binedMiddl e = "";
  1560           if  (vcmn_ori ginatorMid dleName !=  '' && vcm n_originat orMiddleNa me != null ) { vcmn_o riginatorC ombinedMid dle = vcmn _originato rMiddleNam e; }
  1561           if  (vcmn_ori ginatorSuf fix != ''  && vcmn_or iginatorSu ffix != nu ll) {
  1562                if (vcmn _originato rCombinedM iddle != ' ') {
  1563                    vcmn _originato rCombinedM iddle = vc mn_origina torCombine dMiddle +  " " + vcmn _originato rSuffix;
  1564                }
  1565                else {
  1566                    vcmn _originato rCombinedM iddle = vc mn_origina torSuffix;
  1567                }
  1568           }
  1569  
  1570           va r vcmn_req uestJSON =  {
  1571                "ClientN ame": vcmn _clientNam e,
  1572                "Format" : vcmn_For mat,
  1573                "Facilit ySiteID":  vcmn_facil itySiteId,
  1574                "SiteHL7 ListenerAd dress": vc mn_siteHL7 ListenerAd dress,
  1575                "VisitNu mber": vcm n_visitNum ber,
  1576                "IsSigne dNote": vc mn_signThi sNote,
  1577                "Patient AdmitDate" : vcmn_pat ientAdmitD ate,
  1578                "Patient LastName":  vcmn_pati entLastNam e,
  1579                "Patient FirstName" : vcmn_pat ientFirstN ame,
  1580                "Patient Identifier ": vcmn_pa tientICN,
  1581                "Patient Identifier Type": vcm n_patientI dentifierT ype,
  1582                "Patient AssignedLo cation": v cmn_patien tAssignedL ocation,
  1583                "NoteTex t": vcmn_n oteDescrip tion,
  1584                "Origina torID": vc mn_origina torID,
  1585                "Origina torFirstNa me": vcmn_ originator FirstName,
  1586                "Origina torMiddleN ame": vcmn _originato rCombinedM iddle,
  1587                "Origina torLastNam e": vcmn_o riginatorL astName,
  1588                "Documen tFileName" : vcmn_loc alTitle,
  1589                "Documen tAvailabil ityStatus" : vcmn_doc umentAvail abilitySta tus,
  1590                "Activit yDate": vc mn_activit yDate
  1591           };
  1592  
  1593           va r vcmn_req uestRespon se = "";
  1594  
  1595           $. ajax({
  1596                type: "P OST",
  1597                url: vcm n_NoteWrit eUrl,
  1598                data: JS ON.stringi fy(vcmn_re questJSON) ,
  1599                contentT ype: "appl ication/js on; charse t=utf-8",
  1600                dataType : "json",
  1601                success:  function  (data) {
  1602                    var  vcmn_newda ta = data;
  1603                    vcmn _requestRe sponse = v cmn_newdat a;
  1604                    vcmn _vistAInte grationReq uest_respo nse(null,  vcmn_reque stResponse );
  1605                },
  1606                error: f unction (j qXHR, text Status, er rorThrown)  {
  1607                    //Sy stem Error
  1608                    vcmn _vistAInte grationReq uest_respo nse(errorT hrown, nul l);
  1609                },
  1610                async: f alse,
  1611                cache: f alse
  1612           }) ;
  1613       }
  1614       catch  (err) {
  1615           al ert('Progr ess Note R ibbon Func tion Error (vcmn_exec uteVistAIn tegrationR equest): '  + err.mes sage);
  1616           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1617       }
  1618   }
  1619  
  1620   function v cmn_vistAI ntegration Request_re sponse(vcm n_errorThr own, vcmn_ requestRes ponse) {
  1621       try {
  1622           // Process In tegration  Request Re sponse
  1623           if  (vcmn_err orThrown ! = null) {
  1624                //Write  Error
  1625                Xrm.Page .getAttrib ute('ftp_i ntegration status').s etValue('E RROR');
  1626                Xrm.Page .getAttrib ute('ftp_i ntegration status').s etSubmitMo de('always ');
  1627                Xrm.Page .getAttrib ute('ftp_i ntegration error').se tValue(Str ing(vcmn_e rrorThrown ));
  1628                Xrm.Page .getAttrib ute('ftp_i ntegration error').se tSubmitMod e('always' );
  1629                Xrm.Page .getAttrib ute('ftp_i ntegration date').set Value(new  Date());
  1630                Xrm.Page .getAttrib ute('ftp_i ntegration date').set SubmitMode ('always') ;
  1631                Xrm.Page .getAttrib ute('ftp_i ntegration noteid').s etValue('' );
  1632                Xrm.Page .getAttrib ute('ftp_i ntegration noteid').s etSubmitMo de('always ');
  1633                alert('T he note cr eation in  VistA/CPRS  failed!\n Please see  the integ ration err or field f or details .');
  1634                Xrm.Page .getContro l('ftp_int egrationer ror').setF ocus();
  1635                Xrm.Page .data.enti ty.save();
  1636                Xrm.Page .ui.clearF ormNotific ation("SAV EVISTA");
  1637                return f alse;
  1638           }
  1639           el se {
  1640                //Write  web servic e response  Success o r Failure
  1641                if (vcmn _requestRe sponse.Err orOccurred  == false)  {
  1642                    //Wr ite Succes s entry
  1643                    Xrm. Page.getAt tribute('f tp_integra tionstatus ').setValu e(vcmn_req uestRespon se.Status) ;
  1644                    Xrm. Page.getAt tribute('f tp_integra tionstatus ').setSubm itMode('al ways');
  1645                    Xrm. Page.getAt tribute('f tp_integra tionerror' ).setValue (null);
  1646                    Xrm. Page.getAt tribute('f tp_integra tionerror' ).setSubmi tMode('alw ays');
  1647                    Xrm. Page.getAt tribute('f tp_integra tiondate') .setValue( new Date() );
  1648                    Xrm. Page.getAt tribute('f tp_integra tiondate') .setSubmit Mode('alwa ys');
  1649                    Xrm. Page.getAt tribute('f tp_integra tionnoteid ').setValu e(vcmn_req uestRespon se.Data);
  1650                    Xrm. Page.getAt tribute('f tp_integra tionnoteid ').setSubm itMode('al ways');
  1651                    Xrm. Page.getCo ntrol('ftp _integrati onstatus') .setFocus( );
  1652                    aler t('The not e creation  in VistA/ CPRS was s uccessful,  this note  will now  be marked  as complet ed. \n\nPl ease exit  this note  record aft er clickin g OK to th is prompt! ');
  1653                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  1654                    Xrm. Page.data. entity.sav e();
  1655                }
  1656                else {
  1657                    //Wr ite Failur e entry
  1658                    Xrm. Page.getAt tribute('f tp_integra tionstatus ').setValu e(vcmn_req uestRespon se.Status) ;
  1659                    Xrm. Page.getAt tribute('f tp_integra tionstatus ').setSubm itMode('al ways');
  1660                    Xrm. Page.getAt tribute('f tp_integra tionerror' ).setValue (vcmn_requ estRespons e.ErrorMes sage + "   DebugInfo: " + vcmn_r equestResp onse.Debug Info);
  1661                    Xrm. Page.getAt tribute('f tp_integra tionerror' ).setSubmi tMode('alw ays');
  1662                    Xrm. Page.getAt tribute('f tp_integra tiondate') .setValue( new Date() );
  1663                    Xrm. Page.getAt tribute('f tp_integra tiondate') .setSubmit Mode('alwa ys');
  1664                    Xrm. Page.getAt tribute('f tp_integra tionnoteid ').setValu e('');
  1665                    Xrm. Page.getAt tribute('f tp_integra tionnoteid ').setSubm itMode('al ways');
  1666                    aler t('The not e creation  in VistA/ CPRS faile d!\nPlease  see the i ntegration  error fie ld for det ails.');
  1667                    Xrm. Page.getCo ntrol('ftp _integrati onerror'). setFocus() ;
  1668                    Xrm. Page.data. entity.sav e();
  1669                    Xrm. Page.ui.cl earFormNot ification( "SAVEVISTA ");
  1670                    retu rn false;
  1671  
  1672                }
  1673           }
  1674       }
  1675       catch  (err) {
  1676           al ert('Progr ess Note R ibbon Func tion Error (vcmn_vist AIntegrati onRequest_ response):  ' + err.m essage);
  1677           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1678       }
  1679   }
  1680  
  1681   function v cmn_initVi aDropdownC ontrols()  {
  1682       //Init ialize VIA  DropDown  Controls
  1683       //Func tion is tr iggered by  The VistA  Login Con trol and o nchange of  Facility  attribute
  1684       try {
  1685           Xr m.Page.get Control("W ebResource _HospitalL ocation"). setSrc(Xrm .Page.getC ontrol("We bResource_ HospitalLo cation").g etSrc());
  1686           Xr m.Page.get Control("W ebResource _LocalNote sTitle").s etSrc(Xrm. Page.getCo ntrol("Web Resource_L ocalNotesT itle").get Src());
  1687       }
  1688       catch  (err) {
  1689           al ert('Progr ess Note V IA Login F unction Er ror(vcmn_i nitViaDrop downContro ls): ' + e rr.message );
  1690       }
  1691   }
  1692  
  1693   function v cmn_facili tyGroupDef ault_respo nse(vcmn_f acilityGro upData, vc mn_lastSki p, vcmn_fa cilitySite Id) {
  1694       try {
  1695           // vcmn_lastS kip is the  starting  point in t he result  (use if mo re than 50  records)  //Not used  in this s cenario
  1696           fo r (var i =  0; i <= v cmn_facili tyGroupDat a.d.result s.length -  1; i++) {
  1697                //Get Va lues and W rite to Pr ogress Not e
  1698                if (vcmn _facilityG roupData.d .results[i ].ftp_loca lnotestitl e != null)  {
  1699                    Xrm. Page.getAt tribute("f tp_localno testitle") .setValue( vcmn_facil ityGroupDa ta.d.resul ts[i].ftp_ localnotes title);
  1700                    Xrm. Page.getAt tribute('f tp_localno testitle') .setSubmit Mode('alwa ys');
  1701                }
  1702                if (vcmn _facilityG roupData.d .results[i ].ftp_hosp itallocati on != null ) {
  1703                    Xrm. Page.getAt tribute("f tp_hospita llocation" ).setValue (vcmn_faci lityGroupD ata.d.resu lts[i].ftp _hospitall ocation);
  1704                    Xrm. Page.getAt tribute('f tp_hospita llocation' ).setSubmi tMode('alw ays');
  1705                }
  1706                break;
  1707           }
  1708       }
  1709       catch  (err) {
  1710           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_faci lityGroupD efault_res ponse): '  + err.mess age);
  1711       }
  1712   }
  1713  
  1714  
  1715   function v cmn_buildQ ueryFilter (field, va lue, and)  {
  1716       try {
  1717           if  (value ==  '') {
  1718                if (and)  {
  1719                    retu rn " and "  + field +  " eq null ";
  1720                } else {
  1721                    retu rn field +  " eq null ";
  1722                }
  1723           }
  1724           el se {
  1725                if (and)  {
  1726                    retu rn " and "  + field +  " eq '" +  value + " '";
  1727                } else {
  1728                    retu rn field +  " eq '" +  value + " '";
  1729                }
  1730           }
  1731       }
  1732       catch  (err) {
  1733           al ert('Progr ess Note R ibbon Func tion Error (vcmn_buil dQueryFilt er): ' + e rr.message );
  1734           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1735       }
  1736   }
  1737  
  1738   function v cmn_unatte ndedMviSea rch(firstn ame, lastn ame, dobda te, ssn) {
  1739       try {
  1740           va r filter =  "";
  1741           va r filterPr efix = "$s elect=*&$f ilter=";
  1742           va r edipi =  "";
  1743           va r dobstrin g = "";
  1744           if  (dobdate  != null) {
  1745                dobstrin g = dobdat e;
  1746           }
  1747  
  1748           if  (ssn != " " && ssn ! = null) {
  1749                ssn = ss n.replace( /-/g, "");
  1750           }
  1751  
  1752           // if we have  edipi, se arch using  just it
  1753           if  (edipi !=  "") {
  1754                filter =  vcmn_buil dQueryFilt er("crme_E DIPI", edi pi, false) ;
  1755                filter + = vcmn_bui ldQueryFil ter("crme_ ClassCode" , 'MIL', t rue);
  1756                filter + = vcmn_bui ldQueryFil ter("crme_ SearchType ", 'Search ByIdentifi er', true) ;
  1757  
  1758                //set se arch type  as unatten ded
  1759                filter + = " and cr me_IsAtten ded eq fal se";
  1760           }
  1761           el se {
  1762                //otherw ise search  using las tname, fir stname, ss n, dob
  1763                filter =  vcmn_buil dQueryFilt er("crme_L astName",  lastname,  false); // assuming l astname wi ll never b e blank
  1764  
  1765                if (firs tname != " " && first name != nu ll) {
  1766                    filt er += vcmn _buildQuer yFilter("c rme_FirstN ame", firs tname, tru e);
  1767                }
  1768  
  1769                if (ssn  != "" && s sn != null ) {
  1770                    filt er += vcmn _buildQuer yFilter("c rme_SSN",  ssn, true) ;
  1771                }
  1772  
  1773                if (dobs tring != " ") {
  1774                    filt er += " an d crme_DOB String eq  '" + dobst ring + "'" ;
  1775                }
  1776                filter + = vcmn_bui ldQueryFil ter("crme_ SearchType ", 'Search ByFilter',  true);
  1777  
  1778                //set se arch type  as attende d (for now )
  1779                filter + = " and cr me_IsAtten ded eq tru e";
  1780           }
  1781  
  1782           fi lter = enc odeURIComp onent(filt er);
  1783           fi lter = fil terPrefix  + filter;
  1784           SD K.REST.ret rieveMulti pleRecords ("crme_per son", filt er, vcmn_u nattendedM viSearchCa llback, fu nction (er ror) { ale rt(error.m essage); v cmn_ribbon ButtonSave ToVistA_wi th_ICN("") ; }, vcmn_ unattended MviSearchC omplete);
  1785       }
  1786       catch  (err) {
  1787           al ert('Progr ess Note R ibbon Func tion Error (vcmn_unat tendedMviS earch): '  + err.mess age);
  1788           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1789       }
  1790   }
  1791  
  1792   function v cmn_unatte ndedMviSea rchCallbac k(returnDa ta) {
  1793       try {
  1794           if  (returnDa ta != null  && return Data.lengt h >= 1) {
  1795                // check  for excep tions 1st
  1796                if (retu rnData[0]. crme_Excep tionOccure d || (retu rnData[0]. crme_Retur nMessage ! = null &&  returnData [0].crme_R eturnMessa ge == "An  unexpected  error occ ured durin g the MVI  search. Pl ease try a gain or co ntact your  system ad ministrato r if the p roblem per sists."))  {
  1797                    //do  nothing,  pass empty  ICN
  1798                    vcmn _ribbonBut tonSaveToV istA_with_ ICN("");
  1799                }
  1800                else {
  1801                    var  patientMvi Identifier  = returnD ata[0].crm e_PatientM viIdentifi er == null  ? "" : re turnData[0 ].crme_Pat ientMviIde ntifier;
  1802                    if ( patientMvi Identifier  != "") {
  1803                         var idpart s = patien tMviIdenti fier.split ("^");
  1804  
  1805                         if (idpart s.length >  0) {
  1806                             var na tionalId =  idparts[0 ];
  1807                             _icn =  nationalI d;
  1808                             //Pass  on the IC N and cont inue valid ation
  1809                             vcmn_r ibbonButto nSaveToVis tA_with_IC N(_icn);
  1810                         }
  1811                    }
  1812                }
  1813           }
  1814           el se {
  1815                //Return  empty ICN
  1816                vcmn_rib bonButtonS aveToVistA _with_ICN( "");
  1817           }
  1818       }
  1819       catch  (err) {
  1820           al ert('Progr ess Note R ibbon Func tion Error (vcmn_unat tendedMviS earchCallb ack): ' +  err.messag e);
  1821           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1822       }
  1823   }
  1824  
  1825   function v cmn_unatte ndedMviSea rchComplet e() {
  1826       //do n othing
  1827   }
  1828  
  1829  
  1830   function v cmn_buildQ ueryFilter SCD(field,  value, an d) {
  1831       try {
  1832           if  (value ==  '') {
  1833                if (and)  {
  1834                    retu rn " and "  + field +  " eq null ";
  1835                } else {
  1836                    retu rn field +  " eq null ";
  1837                }
  1838           }
  1839           el se {
  1840                if (and)  {
  1841                    retu rn " and "  + field +  " eq '" +  value + " '";
  1842                } else {
  1843                    retu rn field +  " eq '" +  value + " '";
  1844                }
  1845           }
  1846       }
  1847       catch  (err) {
  1848           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_buil dQueryFilt erSCD): '  + err.mess age);
  1849           Xr m.Page.ui. clearFormN otificatio n("SAVEVIS TA");
  1850       }
  1851   }
  1852  
  1853   function v cmn_unatte ndedMviSea rchSCD(fir stname, la stname, do bdate, ssn ) {
  1854       try {
  1855           va r filter =  "";
  1856           va r filterPr efix = "$s elect=*&$f ilter=";
  1857           va r edipi =  "";
  1858           va r dobstrin g = "";
  1859           if  (dobdate  != null) {
  1860                dobstrin g = dobdat e;
  1861           }
  1862  
  1863           if  (ssn != " " && ssn ! = null) {
  1864                ssn = ss n.replace( /-/g, "");
  1865           }
  1866  
  1867           // if we have  edipi, se arch using  just it
  1868           if  (edipi !=  "") {
  1869                filter =  vcmn_buil dQueryFilt erSCD("crm e_EDIPI",  edipi, fal se);
  1870                filter + = vcmn_bui ldQueryFil terSCD("cr me_ClassCo de", 'MIL' , true);
  1871                filter + = vcmn_bui ldQueryFil terSCD("cr me_SearchT ype", 'Sea rchByIdent ifier', tr ue);
  1872  
  1873                //set se arch type  as unatten ded
  1874                filter + = " and cr me_IsAtten ded eq fal se";
  1875           }
  1876           el se {
  1877                //otherw ise search  using las tname, fir stname, ss n, dob
  1878                filter =  vcmn_buil dQueryFilt erSCD("crm e_LastName ", lastnam e, false);  //assumin g lastname  will neve r be blank
  1879  
  1880                if (firs tname != " " && first name != nu ll) {
  1881                    filt er += vcmn _buildQuer yFilterSCD ("crme_Fir stName", f irstname,  true);
  1882                }
  1883  
  1884                if (ssn  != "" && s sn != null ) {
  1885                    filt er += vcmn _buildQuer yFilterSCD ("crme_SSN ", ssn, tr ue);
  1886                }
  1887  
  1888                if (dobs tring != " ") {
  1889                    filt er += " an d crme_DOB String eq  '" + dobst ring + "'" ;
  1890                }
  1891                filter + = vcmn_bui ldQueryFil terSCD("cr me_SearchT ype", 'Sea rchByFilte r', true);
  1892  
  1893                //set se arch type  as attende d (for now )
  1894                filter + = " and cr me_IsAtten ded eq tru e";
  1895           }
  1896  
  1897           fi lter = enc odeURIComp onent(filt er);
  1898           fi lter = fil terPrefix  + filter;
  1899           SD K.REST.ret rieveMulti pleRecords ("crme_per son", filt er, vcmn_u nattendedM viSearchCa llbackSCD,  function  (error) {  alert(erro r.message) ; vcmn_get ServiceCon nectedDisa bilities(" "); }, vcm n_unattend edMviSearc hComplete) ;
  1900       }
  1901       catch  (err) {
  1902           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_unat tendedMviS earchSCD):  ' + err.m essage);
  1903       }
  1904   }
  1905  
  1906   function v cmn_unatte ndedMviSea rchCallbac kSCD(retur nData) {
  1907       try {
  1908           if  (returnDa ta != null  && return Data.lengt h >= 1) {
  1909                // check  for excep tions 1st
  1910                if (retu rnData[0]. crme_Excep tionOccure d || (retu rnData[0]. crme_Retur nMessage ! = null &&  returnData [0].crme_R eturnMessa ge == "An  unexpected  error occ ured durin g the MVI  search. Pl ease try a gain or co ntact your  system ad ministrato r if the p roblem per sists."))  {
  1911                    //do  nothing,  pass empty  ICN
  1912                    vcmn _getServic eConnected Disabiliti es("");
  1913                }
  1914                else {
  1915                    var  patientMvi Identifier  = returnD ata[0].crm e_PatientM viIdentifi er == null  ? "" : re turnData[0 ].crme_Pat ientMviIde ntifier;
  1916                    if ( patientMvi Identifier  != "") {
  1917                         var idpart s = patien tMviIdenti fier.split ("^");
  1918  
  1919                         if (idpart s.length >  0) {
  1920                             var na tionalId =  idparts[0 ];
  1921                             _icn =  nationalI d;
  1922                             //Pass  on the IC N and cont inue with  SCD
  1923                             vcmn_g etServiceC onnectedDi sabilities (_icn);
  1924                         }
  1925                    }
  1926                }
  1927           }
  1928           el se {
  1929                //Return  empty ICN
  1930                vcmn_get ServiceCon nectedDisa bilities(" ");
  1931           }
  1932       }
  1933       catch  (err) {
  1934           al ert('Progr ess Note F orm Load S cript Func tion Error (vcmn_unat tendedMviS earchCallb ackSCD): '  + err.mes sage);
  1935       }
  1936   }
  1937  
  1938   //Standalo ne form lo ad functio n
  1939   function v cmn_secure ProgressNo te() {
  1940       try {
  1941           // Disable al l form att ributes if  form is o pened by a  user who  does not o wn the pro gress note
  1942           // Only handl e forms in  create st ate
  1943           if  (Xrm.Page .ui.getFor mType() !=  2) { retu rn false;  } //2 = CR M Update S tatus
  1944           // Get the cu rrent owne r of the r ecord and  compare to  the curre nt user
  1945           va r vcmn_rec ordOwnerId  = Xrm.Pag e.getAttri bute('owne rid').getV alue();
  1946           // Verify tha t the curr ent owner  and the cu rrent user  is the sa me person,  if not lo ck down th e form
  1947           if  ((vcmn_re cordOwnerI d[0].id).t oUpperCase () != (Xrm .Page.cont ext.getUse rId()).toU pperCase() ) {
  1948                Xrm.Page .data.enti ty.attribu tes.forEac h(function  (attribut e, index)  {
  1949                    var  control =  Xrm.Page.g etControl( attribute. getName()) ;
  1950                    if ( control) {
  1951                         control.se tDisabled( true)
  1952                    }
  1953                });
  1954           }
  1955       }
  1956       catch  (err) {
  1957           al ert('Progr ess Note F orm Load F unction Er ror(vcmn_s ecureProgr essNote):  ' + err.me ssage);
  1958       }
  1959   }
  1960  
  1961  
  1962   function v cmn_execut eCrmOdataG etRequest( vcmn_jsonQ uery, vcmn _aSync, vc mn_aSyncCa llback, vc mn_skipCou nt, vcmn_o ptionArray ) {
  1963       //This  function  executes a  CRM Odata  web servi ce call to  retrieve  Crm data
  1964       //*vcm n_jsonQuer y* - a pro perly form atted CRM  Odata Quer y string ( required)
  1965       //*vcm n_aSync* -  specify ' true' to e xecute asy nchronousl y otherwis e 'false'  (required)
  1966       //*vcm n_aSyncCal lback* - s pecify the  name of t he return  function t o call upo n completi on (requir ed if vcmn _aSync = t rue.  Othe rwise '')
  1967       //*vcm n_skipCoun t* - Initi al setting  is always  '0', incr ements by  50 per CRM  SDK Odata  standards  (required )
  1968       //*vcm n_optionAr ray* - is  an optiona l array or  single va lue, that  contains a dditional  task speci fic variab les that c an be pass ed between  functions  (pass 'nu ll' if not  used)
  1969       try {
  1970           va r vcmn_ent ityData =  null;
  1971           $. ajax({
  1972                type: 'G ET',
  1973                contentT ype: 'appl ication/js on; charse t=utf-8',
  1974                datatype : 'json',
  1975                url: vcm n_jsonQuer y,
  1976                beforeSe nd: functi on (XMLHtt pRequest)  {
  1977                    XMLH ttpRequest .setReques tHeader('A ccept', 'a pplication /json');
  1978                },
  1979                success:  function  (data, tex tStatus, X mlHttpRequ est) {
  1980                    vcmn _entityDat a = data;
  1981                    if ( vcmn_aSync  == true)  {
  1982                         vcmn_aSync Callback(v cmn_entity Data, vcmn _skipCount , vcmn_opt ionArray);
  1983                    }
  1984                },
  1985                error: f unction (X MLHttpRequ est, textS tatus, err orThrown)  {
  1986                    aler t('Fail: A jax Error  in vcmn_ex ecuteCrmOd ataGetRequ est: ' + e rrorThrown  + " Reque st: " + vc mn_jsonQue ry);
  1987                },
  1988                async: v cmn_aSync,
  1989                cache: f alse
  1990           }) ;
  1991           re turn vcmn_ entityData ;
  1992       }
  1993       catch  (err) {
  1994           al ert('An er ror occure d in the v cmn_execut eCrmOdataG etRequest  function.   Error Det ail Messag e: ' + err );
  1995       }
  1996   }
  1997  
  1998   function v cmn_getMul tipleEntit yDataAsync (vcmn_enti tySetName,  vcmn_attr ibuteSet,  vcmn_condi tionalFilt er, vcmn_s ortAttribu te, vcmn_s ortDirecti on, vcmn_s kipCount,  vcmn_aSync Callback,  vcmn_optio nArray) {
  1999       //This  function  returns a  CRM JSON d ataset for  all entit y records  matching c riteria pr ovided Asy ncronously
  2000       //*vcm n_entitySe tName* - i s the name  of the en tity set e .g 'Contac tSet'
  2001       //*vcm n_attribut eSet* -  i s a string  containin g the Crm  Attributes  to retrie ve e.g. 'F irstName,  LastName,  Telephone1 , EMailAdd ress1'
  2002       //*vcm n_conditio nalFilter*  - is the  conditiona l filter v alue place d on the d ata values  retrived  e.g. 'Stat eCode/Valu e eq 0'  t o retrieve  active co ntact reco rds only
  2003       //*vcm n_sortAttr ibute* - i s a string  containin g the name  of the at tribute to  sort the  result set  by e.g. ' LastName'
  2004       //*vcm n_sortDire ction* - i s a string  specifyin g the sort  as Ascend ing or Des cending e. g. 'asc' o r 'desc'
  2005       //*vcm n_skipCoun t* - is th e starting  point in  the result  (use if m ore than 5 0), (Put 0  if not us ed)
  2006       //*vcm n_aSyncCal lback* - i s the name  of the fu nction to  call when  returning  the result
  2007       //*vcm n_optionAr ray* - is  an optiona l array, t hat contai ns additio nal task s pecific va riables th at can be  passed bet ween funct ions
  2008  
  2009       try {
  2010           va r vcmn_jso nQuery = v cmn_server Url + vcmn _crmOdataE ndPoint +  '/' + vcmn _entitySet Name + '?$ select=' +  vcmn_attr ibuteSet +  '&$filter =' + vcmn_ conditiona lFilter +  '&$orderby =' + vcmn_ sortAttrib ute + ' '  + vcmn_sor tDirection  + '&$skip =' + vcmn_ skipCount;
  2011           vc mn_execute CrmOdataGe tRequest(v cmn_jsonQu ery, true,  vcmn_aSyn cCallback,  vcmn_skip Count, vcm n_optionAr ray);
  2012       }
  2013       catch  (err) {
  2014           al ert('An er ror occure d in the v cmn_getMul tipleEntit yDataAsync  function.   Error De tail Messa ge: ' + er r);
  2015       }
  2016   }
  2017  
  2018   function v cmn_getSin gleEntityD ataSync(vc mn_entityS etName, vc mn_attribu teSet, vcm n_entityId ) {
  2019       //This  function  returns a  CRM JSON d ataset for  a single  entity rec ord based  on the ent ity id pro vided Sync ronously
  2020       //*vcm n_entitySe tName* - i s the name  of the en tity set e .g 'Contac tSet'
  2021       //*vcm n_attribut eSet* -  i s a string  containin g the Crm  Attributes  to retrie ve e.g. 'F irstName,  LastName,  Telephone1 , EMailAdd ress1'
  2022       //*vcm n_entityId * - is the  Guid for  the entity  record
  2023  
  2024       try {
  2025           va r vcmn_ent ityIdNoBra cket = vcm n_entityId .replace(/ ({|})/g, ' ');
  2026           va r vcmn_sel ectString  = '(guid'  + "'" + vc mn_entityI dNoBracket  + "'" + ' )?$select= ' + vcmn_a ttributeSe t;
  2027           va r vcmn_jso nQuery = v cmn_server Url + vcmn _crmOdataE ndPoint +  '/' + vcmn _entitySet Name + vcm n_selectSt ring;
  2028           va r vcmn_ent ityData =  vcmn_execu teCrmOdata GetRequest (vcmn_json Query, fal se, '', 0,  null);
  2029           re turn vcmn_ entityData ;
  2030       }
  2031       catch  (err) {
  2032           al ert('An er ror occure d in the v cmn_getSin gleEntityD ataSync fu nction.  E rror Detai l Message:  ' + err);
  2033       }
  2034   }
  2035  
  2036   function v cmn_getMul tipleEntit yDataSync( vcmn_entit ySetName,  vcmn_attri buteSet, v cmn_condit ionalFilte r, vcmn_so rtAttribut e, vcmn_so rtDirectio n, vcmn_sk ipCount) {
  2037       //This  function  returns a  CRM JSON d ataset for  all entit y records  matching c riteria pr ovided Syn cronously
  2038       //*vcm n_entitySe tName* - i s the name  of the en tity set e .g 'Contac tSet'
  2039       //*vcm n_attribut eSet* -  i s a string  containin g the Crm  Attributes  to retrie ve e.g. 'F irstName,  LastName,  Telephone1 , EMailAdd ress1'
  2040       //*vcm n_conditio nalFilter*  - is the  conditiona l filter v alue place d on the d ata values  retrived  e.g. 'Stat eCode/Valu e eq 0'  t o retrieve  active co ntact reco rds only
  2041       //*vcm n_sortAttr ibute* - i s a string  containin g the name  of the at tribute to  sort the  result set  by e.g. ' LastName'
  2042       //*vcm n_sortDire ction* - i s a string  specifyin g the sort  as Ascend ing or Des cending e. g. 'asc' o r 'desc'
  2043       //*vcm n_skipCoun t* - is th e starting  point in  the result  (use if m ore than 5 0), (Put 0  if not us ed)
  2044  
  2045       try {
  2046           va r vcmn_jso nQuery = v cmn_server Url + vcmn _crmOdataE ndPoint +  '/' + vcmn _entitySet Name + '?$ select=' +  vcmn_attr ibuteSet +  '&$filter =' + vcmn_ conditiona lFilter +  '&$orderby =' + vcmn_ sortAttrib ute + ' '  + vcmn_sor tDirection  + '&$skip =' + vcmn_ skipCount;
  2047           va r vcmn_ent ityData =  vcmn_execu teCrmOdata GetRequest (vcmn_json Query, fal se, '', vc mn_skipCou nt, null);
  2048           re turn vcmn_ entityData ;
  2049       }
  2050       catch  (err) {
  2051           al ert('An er ror occure d in the v cmn_getMul tipleEntit yDataSync  function.   Error Det ail Messag e: ' + err );
  2052       }
  2053   }
  2054