formPortal.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. //global config variable
  2. const config=new Object();
  3. function print(msg){
  4. config.document.getElementById(config.debugArea).value+="\n"+msg;
  5. }
  6. function clear(){
  7. config.document.getElementById(config.debugArea).value="";
  8. }
  9. function getMode(){
  10. if ("role" in config){
  11. return config.role;
  12. }
  13. return "crfEditor";
  14. }
  15. function doNothing(){
  16. print('doNothing called');
  17. }
  18. function makeQuery(containerName,queryName,fieldName,filterArray){
  19. //queryArray should contain elements with
  20. //- fieldName to set the data variable
  21. //- containerName to select container (data,config,CRF)
  22. //- queryName to select query
  23. //- filterArray to perform filtering, empty array works
  24. //- callback cb to be called with no arguments
  25. let e=new Object();
  26. e.containerName=containerName;
  27. e.queryName=queryName;
  28. e.fieldName=fieldName;
  29. e.filterArray=filterArray;
  30. return e;
  31. }
  32. function getDataFromQueries(queryArray,cb){
  33. afterQuery(new Object(),-1,queryArray,cb);
  34. }
  35. function afterQuery(data,id,queryArray,cb){
  36. print('afterQuery['+id+']: ');
  37. if (id>-1){
  38. let fieldName=queryArray[id].fieldName;
  39. print('afterQuery['+fieldName+']: '+data.rows.length);
  40. //uses config.formConfig
  41. config.formConfig[fieldName]=data;
  42. }
  43. id+=1;
  44. if (id==queryArray.length) {
  45. cb();
  46. return;
  47. }
  48. let e=queryArray[id];
  49. let qconfig=new Object();
  50. qconfig.containerPath=getContainer(e.containerName);
  51. qconfig.schemaName="lists";
  52. if ("schemaName" in e){
  53. print('afterQuery: schemaName='+e.schemaName);
  54. qconfig.schemaName=e.schemaName;
  55. }
  56. if ("columns" in e){
  57. print('afterQuery: columns='+e.columns);
  58. qconfig.columns=e.columns;
  59. }
  60. qconfig.queryName=e.queryName;
  61. //this should point to configuration container
  62. //don't filter -> so we can pick up other forms (say registration) later on
  63. //qconfig.filterArray=[LABKEY.Filter.create('Key',config.formId)];
  64. if ("filterArray" in e)
  65. qconfig.filterArray=e.filterArray;
  66. //qconfig.filterArray=[LABKEY.Filter.create('formStatus',1)]
  67. qconfig.success=function(data){afterQuery(data,id,queryArray,cb);};
  68. qconfig.failure=doNothing;
  69. LABKEY.Query.selectRows(qconfig);
  70. }
  71. function printMessage(msg){
  72. let txt=config.document.createElement("p");
  73. config.document.getElementById(config.div).appendChild(txt);
  74. txt.innerText=msg;
  75. }
  76. function userName(id){
  77. let formConfig=config.formConfig;
  78. for (let i=0;i<formConfig.users.rows.length;i++){
  79. if (formConfig.users.rows[i].UserId!=id)
  80. continue;
  81. return formConfig.users.rows[i].DisplayName;
  82. }
  83. return "NONE";
  84. }
  85. function setContainer(label,container){
  86. if (!(config.formConfig.hasOwnProperty('container'))){
  87. config.formConfig.container=new Array();
  88. }
  89. config.formConfig.container[label]=container;
  90. }
  91. function getContainer(label){
  92. return config.formConfig.container[label];
  93. }
  94. function generateFormArray(){
  95. print("generateFormArray "+getMode());
  96. config.formConfig=new Object();
  97. config.formConfig.softwareVersion='T.1.12';
  98. //report software version
  99. config.document.getElementById('version').innerText=config.formConfig.softwareVersion;
  100. setContainer('data',LABKEY.ActionURL.getContainer());
  101. setContainer('config',LABKEY.ActionURL.getContainer());
  102. setContainer('CRF',LABKEY.ActionURL.getContainer());
  103. let selectRows=new Object();
  104. //this is local data
  105. selectRows.containerPath=getContainer('CRF');
  106. selectRows.schemaName='lists';
  107. selectRows.queryName='crfSettings';
  108. //store form related data to this object
  109. selectRows.success=afterSettings;
  110. LABKEY.Query.selectRows(selectRows);
  111. }
  112. function afterSettings(data){
  113. config.formConfig.settings=new Array();
  114. for (let i=0;i<data.rows.length;i++){
  115. let n=data.rows[i]['name'];
  116. let v=data.rows[i]['value'];
  117. config.formConfig.settings[n]=v;
  118. }
  119. let st=config.formConfig.settings;
  120. print('afterSettings');
  121. for (let k in st){
  122. print('\t'+k+'='+st[k]);
  123. }
  124. //if ('dataContainer' in st){
  125. // setContainer('data',st['dataContainer']);
  126. //}
  127. let vname='configContainer';
  128. if (vname in st){
  129. setContainer('config',st[vname]);
  130. }
  131. print('Config: '+getContainer('config'));
  132. print('Data: '+getContainer('data'));
  133. //setup queryArray
  134. let queryArray=new Array();
  135. //static variables
  136. queryArray.push(makeQuery('data','crfStaticVariables','crfStaticVariables',[]));
  137. //Forms
  138. queryArray.push(makeQuery('config','Forms','dataForms',[]));
  139. //users
  140. queryArray.push(makeQuery('data','users','users',[]));
  141. queryArray[queryArray.length-1].schemaName='core';
  142. //inputLists
  143. queryArray.push(makeQuery('config','inputLists','inputLists',[]));
  144. //crfEditors
  145. queryArray.push(makeQuery('config','crfEditors','crfEditors',[]));
  146. //crfMonitors
  147. queryArray.push(makeQuery('config','crfMonitors','crfMonitors',[]));
  148. //crfSponsors
  149. queryArray.push(makeQuery('config','crfSponsors','crfSponsors',[]));
  150. //crfManagers
  151. queryArray.push(makeQuery('config','crfManagers','crfManagers',[]));
  152. //FormStatus
  153. queryArray.push(makeQuery('config','FormStatus','formStatusg',[]));
  154. //site
  155. queryArray.push(makeQuery('config','site','siteData',[]));
  156. //crfEntry
  157. queryArray.push(makeQuery('data','crfEntry','crfEntries',[]));
  158. queryArray.push(
  159. makeQuery('config','generateConfig','generateConfigData',[]));
  160. getDataFromQueries(queryArray,addStudyData);
  161. //getDataFromQueries(queryArray,fcontinue);
  162. }
  163. function addStudyData(){
  164. //setup queryArray
  165. let queryArray=new Array();
  166. queryArray.push(makeQuery('data','StudyProperties','studyData',[]));
  167. let e=queryArray[queryArray.length-1];
  168. e.schemaName='study';
  169. let columnModel="";
  170. let varRows=config.formConfig['crfStaticVariables'].rows;
  171. for (let i=0;i<varRows.length;i++){
  172. if (i>0) columnModel+=',';
  173. columnModel+=varRows[i]['staticVariable'];
  174. }
  175. e.columns=columnModel;
  176. getDataFromQueries(queryArray,fcontinue);
  177. }
  178. function filterEntry(entry,filter,settings){
  179. if (entry.Form!=filter.form)
  180. return false;
  181. //only select forms where status matches the target status
  182. if (entry.FormStatus!=filter.formStatus){
  183. return false;
  184. }
  185. print('Candidate '+entry.entryId);
  186. //TODO: smart filter on user (now we get to see all)
  187. //
  188. //for editors
  189. if ("filterUser" in settings && filter.role=='crfEditor' && entry.UserId!=filter.userId){
  190. print('Skipping identity mismatch: '+entry.UserId+'/'+filter.userId);
  191. return false;
  192. }
  193. //for others
  194. let matchingSite=-1;
  195. let potentialSiteNumbers="[";
  196. for (let k=0;k<filter.sites.length;k++){
  197. if (k>0) potentialSiteNumbers+=',';
  198. potentialSiteNumbers+=filter.sites[k].siteNumber;
  199. //skip mismatching sites
  200. if (entry.Site!=filter.sites[k].siteNumber) continue;
  201. matchingSite=filter.sites[k].siteNumber;
  202. break;
  203. }
  204. potentialSiteNumbers+=']';
  205. if (matchingSite==-1){
  206. print('Skipping wrong site: '+entry.Site+'/'+potentialSiteNumbers);
  207. return false;
  208. }
  209. return true;
  210. }
  211. function fcontinue(){
  212. let fName='[fcontinue]';
  213. let formConfig=config.formConfig;
  214. print("Number of study data entries: "+formConfig.studyData.rows.length);
  215. print("ParticipantId: "+formConfig.studyData.rows[0].SubjectColumnName);
  216. let dataForms=formConfig.dataForms.rows;
  217. formConfig.table=config.document.createElement("table");
  218. config.document.getElementById(config.div).appendChild(formConfig.table);
  219. let accessModeColumn=getMode()+'Status';
  220. print('accessModeColumn '+accessModeColumn);
  221. //cutting down on number of fields
  222. //let creatorModeColumn=getMode()+'Creator';
  223. //switch from status based to form based access
  224. print("Forms: "+dataForms.length);
  225. print("Entries: "+formConfig.crfEntries.rows.length);
  226. let fEntries=formConfig.crfEntries.rows;
  227. let users=formConfig.users.rows;
  228. let currentUserId=LABKEY.Security.currentUser.id;
  229. let currentUser=undefined;
  230. for (let i=0;i<users.length;i++){
  231. if (users[i].UserId!=currentUserId) continue;
  232. currentUser=users[i];
  233. }
  234. //determine the role filter
  235. let fList=config.role+'s';
  236. //check for users that fit the role,
  237. //fRows lists all users for role
  238. let fRows=config.formConfig[fList].rows;
  239. print(fName+' candidates: '+fRows.length)
  240. //current user must be in the list
  241. let currentUserRoles=new Array();
  242. //the same user can act for multiple sites
  243. for (let i=0;i<fRows.length;i++){
  244. if (fRows[i].User!=currentUser.UserId) continue;
  245. currentUserRoles.push(fRows[i]);
  246. }
  247. //cludge for public sites where all users can act as anything
  248. let sts=config.formConfig.settings;
  249. let vName='allowAllForSite';
  250. if (vName in sts){
  251. let tempUserRole=new Object();
  252. tempUserRole.User=currentUser.UserId;
  253. tempUserRole.Site=parseInt(sts[vName]);
  254. currentUserRoles.push(tempUserRole);
  255. }
  256. //currentUser was not matched in fRows
  257. if (currentUserRoles.length==0){
  258. printMessage('User '+currentUser.DisplayName+" can't act as "+config.role);
  259. return;
  260. }
  261. //currentUser should be also attached to the site of the document
  262. let currentSites=new Array();
  263. let siteRows=config.formConfig.siteData.rows;
  264. for (let i=0;i<siteRows.length;i++){
  265. for (let j=0;j<currentUserRoles.length;j++){
  266. if (siteRows[i].siteNumber!=currentUserRoles[j].Site) continue;
  267. currentSites.push(siteRows[i]);
  268. }
  269. }
  270. config.formConfig.currentSites=currentSites;
  271. let msg='User '+currentUser.DisplayName+' acting as '+config.role+' for (';
  272. for (let i=0;i<currentSites.length;i++){
  273. if (i>0) msg+=', ';
  274. msg+=currentSites[i].siteName;
  275. }
  276. msg+=')';
  277. printMessage(msg);
  278. let filter=new Object();
  279. filter.role=config.role;
  280. filter.userId=currentUser.UserId;
  281. filter.sites=currentSites;
  282. //browse through forms
  283. for (let i=0;i<dataForms.length;i++){
  284. //dataForms is Forms
  285. let qForm=dataForms[i];
  286. let formKey=qForm.Key;
  287. filter.form=qForm.Key;
  288. //add row for each form
  289. let row=formConfig.table.insertRow(i);
  290. let formName=qForm.formName;
  291. print("["+i+"/"+formKey+']: '+formName);
  292. //column counter
  293. let k=0;
  294. //get the target status
  295. let formStatus=qForm[accessModeColumn];
  296. filter.formStatus=qForm[accessModeColumn];
  297. print('target formStatus '+formStatus);
  298. for (let j=0;j<fEntries.length;j++){
  299. let entry=fEntries[j];
  300. if (!filterEntry(entry,filter,config.formConfig.settings))
  301. continue;
  302. //insert form
  303. //
  304. let fbox=config.document.createElement("div");
  305. fbox.classList.add("box","gold");
  306. let fp=config.document.createElement("p");
  307. let id=entry.entryId;
  308. fp.innerHTML=id;
  309. //it would be great if this were patientId if available
  310. //fp.classList.add("large","center");
  311. fp.classList.add("center");
  312. fbox.appendChild(fp);
  313. let fp1=config.document.createElement("p");
  314. let user="NONE";
  315. for (let ii=0;ii<users.length;ii++){
  316. if (users[ii].UserId!=entry.UserId)
  317. continue;
  318. user=users[ii].DisplayName;
  319. break;
  320. }
  321. fp1.innerHTML=user;
  322. fp1.classList.add("center");
  323. fbox.appendChild(fp1);
  324. let fp2=config.document.createElement("p");
  325. fp2.innerHTML=formName;
  326. fp2.classList.add("center");
  327. fbox.appendChild(fp2);
  328. let fp3=config.document.createElement("p");
  329. fp3.id="pid"+id;
  330. let pid=entry['participantStudyId'];
  331. let loc=entry['participantLocalId'];
  332. let label='';
  333. if (pid) label+=pid+' ';
  334. if (loc) label+='(Local: '+loc+')';
  335. if (label.length==0) label="NONE";
  336. fp3.innerHTML=label;
  337. fp3.classList.add("center");
  338. fbox.appendChild(fp3);
  339. let cell=row.insertCell(k);
  340. cell.classList.add("stretch");
  341. cell.id="box"+entry.crfRef;
  342. let button=config.document.createElement("button");
  343. button.appendChild(fbox);
  344. button.onclick=function(){openForm(entry)};
  345. cell.appendChild(button);
  346. k++;
  347. }
  348. print('finished checking existing forms');
  349. //only those that are allowed to create forms
  350. //print('Status: '+qForm[creatorModeColumn]);
  351. let creator=qForm['creator'];
  352. if (!creator) continue;
  353. if (creator!=getMode()) continue;
  354. //if (qForm[creatorModeColumn]!='TRUE') continue;
  355. let fbox=config.document.createElement("div");
  356. fbox.classList.add("box","red");
  357. let fp=config.document.createElement("p");
  358. fp.innerHTML="Create new";
  359. fbox.appendChild(fp);
  360. let fp2=config.document.createElement("p");
  361. fp2.innerHTML=formName;
  362. fp2.classList.add("center");
  363. fbox.appendChild(fp2);
  364. let cell=row.insertCell(k);
  365. cell.classList.add("stretch");
  366. let button=config.document.createElement("button");
  367. button.appendChild(fbox);
  368. button.onclick=function(){createForm(formKey)};
  369. cell.appendChild(button);
  370. }
  371. if (config.role=='crfManager')
  372. addFormGenerator();
  373. }
  374. function openForm(crfEntry){
  375. let formConfig=config.formConfig;
  376. let crfRef=crfEntry.entryId;
  377. print("Clicked for "+crfRef);
  378. let formId=crfEntry.Form;
  379. for (let i=0;i<formConfig.dataForms.rows.length;i++){
  380. if (formConfig.dataForms.rows[i].Key!=formId) continue;
  381. print("Setting form "+formConfig.dataForms.rows[i].formName);
  382. formEntry=formConfig.dataForms.rows[i];
  383. break;
  384. }
  385. if (formEntry==undefined) return;
  386. //select between review and view
  387. //let formUrl=formEntry["formUrl"];
  388. //if ("reviewMode" in config) formUrl=formEntry["reviewFormUrl"];
  389. //print("Setting url "+formUrl);
  390. //direct all to the same html
  391. let formUrl="visit";
  392. reviewMode="EDIT";
  393. if ("reviewMode" in config) reviewMode=config.reviewMode;
  394. let params = {
  395. "name": formUrl,
  396. // The destination wiki page. The name of this parameter is not arbitrary.
  397. "entryId": crfRef,
  398. "formId":formId,
  399. "role" : config.role
  400. };
  401. //"formSetupQuery":formEntry["setupQuery"],
  402. let containerPath= LABKEY.ActionURL.getContainer();
  403. // This changes the page after building the URL.
  404. //Note that the wiki page destination name is set in params.
  405. var wikiURL = LABKEY.ActionURL.buildURL("crf_tecant", formUrl , containerPath, params);
  406. print("Redirecting to "+wikiURL);
  407. window.location = wikiURL;
  408. }
  409. function createForm(formId){
  410. let formConfig=config.formConfig;
  411. print("Create form w/id "+formId);
  412. let crfEntry=new Object();
  413. crfEntry.entryId=Date.now();
  414. crfEntry["Date"]=new Date();
  415. crfEntry["View"]="[VIEW]";
  416. crfEntry.formStatus=1;//In progress
  417. //set other variables
  418. //requires studyData as part of formConfig
  419. let studyData=formConfig.studyData.rows[0];
  420. let varRows=formConfig['crfStaticVariables'].rows;
  421. for (let i=0;i<varRows.length;i++){
  422. let varName=varRows[i].staticVariable;
  423. crfEntry[varName]=studyData[varName];
  424. }
  425. crfEntry.UserId=LABKEY.Security.currentUser.id;
  426. crfEntry.Site=config.formConfig.currentSites[0].siteNumber;
  427. print("Setting site to id="+crfEntry.Site);
  428. //from argument list
  429. crfEntry.Form=formId;
  430. let qconfig=new Object();
  431. qconfig.containerPath=getContainer('data');
  432. qconfig.schemaName='lists';
  433. qconfig.queryName='crfEntry';
  434. qconfig.success=function(data){openForm(crfEntry)};
  435. qconfig.rows=[crfEntry];
  436. LABKEY.Query.insertRows(qconfig);
  437. }
  438. function addInputRow(table,header,type){
  439. let fName='[addInputRow]';
  440. print(fName);
  441. let row=table.insertRow();
  442. let cell=config.document.createElement('th');
  443. let text=config.document.createTextNode(header);
  444. cell.appendChild(text);
  445. row.appendChild(cell);
  446. let input=null;
  447. if (type=="select")
  448. input=config.document.createElement(type);
  449. if (type=="button"){
  450. input=config.document.createElement("input");
  451. input.type="button";
  452. }
  453. let cell1=row.insertCell();
  454. cell1.appendChild(input);
  455. return input;
  456. }
  457. function getFormName(formId){
  458. let rows=config.formConfig.dataForms.rows;
  459. for (let i=0;i<rows.length;i++){
  460. if (rows[i]['Key']==formId){
  461. return rows[i]['formName'];
  462. }
  463. }
  464. return "NONE";
  465. }
  466. function getQueryName(queryId){
  467. let rows=config.formConfig.inputLists.rows;
  468. for (let i=0;i<rows.length;i++){
  469. if (rows[i]['Key']==queryId){
  470. return rows[i]['queryName'];
  471. }
  472. }
  473. return "NONE";
  474. }
  475. function getGCRow(formId){
  476. let formRows=config.formConfig.generateConfigData.rows;
  477. for (let i=0;i<formRows.length;i++){
  478. if (formRows[i]['formId']==formId){
  479. return formRows[i];
  480. }
  481. }
  482. return Object();
  483. }
  484. function getIdSelectRow(crfRef){
  485. let rows=config.formConfig.idSelectRows;
  486. for (let i=0;i<rows.length;i++){
  487. if (rows[i]['crfRef']==crfRef)
  488. return rows[i];
  489. }
  490. return Object();
  491. }
  492. function addOption(input,name,value){
  493. let opt=config.document.createElement("option");
  494. opt.text=name;
  495. opt.value=value;
  496. input.options[input.options.length]=opt;
  497. }
  498. function clearOptions(input){
  499. for(let i = input.options.length; i >= 0; i--) {
  500. input.remove(i);
  501. }
  502. }
  503. function addFormGenerator(){
  504. let fName='[addFormGenerator]';
  505. print(fName);
  506. //layout
  507. let table=config.document.createElement("table");
  508. config.document.getElementById(config.div).appendChild(table);
  509. let formSelect=addInputRow(table,'Select form',"select");
  510. let idSelect=addInputRow(table,'Selecct id',"select");
  511. addOption(formSelect,'<Select>',-1);
  512. let formRows=config.formConfig.generateConfigData.rows;
  513. for (let i=0;i<formRows.length;i++){
  514. let formId=formRows[i]["formId"];
  515. let formName=getFormName(formId);
  516. print(fName+' '+formRows[i]["formId"]+'/'+formName);
  517. addOption(formSelect,formName,formId);
  518. }
  519. formSelect.onchange=function(){updateIdList(formSelect,idSelect,formRows);};
  520. let generateButton=addInputRow(table,'Generate Form','button');
  521. generateButton.onclick=function(){createFormWithId(formSelect,idSelect);};
  522. }
  523. function createFormWithId(formSelect,idSelect){
  524. //get form id and entry id from select and create form as above
  525. let fName='[createFormWithId]';
  526. print(fName);
  527. let formId=formSelect.options[formSelect.selectedIndex].value;
  528. let crfRef=idSelect.options[idSelect.selectedIndex].text;
  529. let configRow=getGCRow(formId);
  530. let idSelectRow=getIdSelectRow(crfRef);
  531. let formConfig=config.formConfig;
  532. print("Create form w/id "+formId);
  533. let crfEntry=new Object();
  534. crfEntry.entryId=Date.now();
  535. crfEntry["Date"]=new Date();
  536. crfEntry["View"]="[VIEW]";
  537. crfEntry['participantStudyId']=idSelectRow['participantStudyId'];
  538. crfEntry['participantLocalId']=idSelectRow['participantLocalId'];
  539. crfEntry.formStatus=configRow['formStatus'];//In progress
  540. //set other variables
  541. //requires studyData as part of formConfig
  542. let studyData=formConfig.studyData.rows[0];
  543. let varRows=formConfig['crfStaticVariables'].rows;
  544. for (let i=0;i<varRows.length;i++){
  545. let varName=varRows[i].staticVariable;
  546. crfEntry[varName]=studyData[varName];
  547. }
  548. crfEntry.UserId=LABKEY.Security.currentUser.id;
  549. crfEntry.Site=config.formConfig.currentSites[0].siteNumber;
  550. print("Setting site to id="+crfEntry.Site);
  551. //from argument list
  552. crfEntry.Form=formId;
  553. crfEntry.parentCrf=crfRef;
  554. let qconfig=new Object();
  555. qconfig.containerPath=getContainer('data');
  556. qconfig.schemaName='lists';
  557. qconfig.queryName='crfEntry';
  558. qconfig.success=function(data){redirect()};
  559. qconfig.rows=[crfEntry];
  560. LABKEY.Query.insertRows(qconfig);
  561. }
  562. function updateIdList(formSelect,idSelect,formRows){
  563. let fName='[updateIdList]';
  564. let formId=formSelect.options[formSelect.selectedIndex].value;
  565. print(fName+' id '+formId);
  566. //remove old options
  567. clearOptions(idSelect);
  568. print(fName+' options cleared');
  569. //get query associated with form
  570. let queryId=-1;
  571. for (let i=0;i<formRows.length;i++){
  572. if (formRows[i]['formId']==formId){
  573. queryId=formRows[i]['queryId'];
  574. break;
  575. }
  576. }
  577. print(fName+' queryId '+queryId);
  578. if (queryId<0)
  579. return;
  580. let qselect=new Object();
  581. qselect.containerPath=getContainer('data');
  582. qselect.schemaName='lists';
  583. qselect.queryName=getQueryName(queryId);
  584. qselect.success=function(data){updateIdListWithData(idSelect,data);};
  585. LABKEY.Query.selectRows(qselect);
  586. }
  587. function updateIdListWithData(idSelect,data){
  588. let rows=data.rows;
  589. config.formConfig.idSelectRows=data.rows;
  590. for (let i=0;i<rows.length;i++){
  591. addOption(idSelect,rows[i]['crfRef'],i);
  592. }
  593. }
  594. function redirect(){
  595. let debug=false;
  596. let formUrl="begin";
  597. let params=new Object();
  598. params.name=formUrl;
  599. params.pageId="CRF";
  600. //points to crf container
  601. let containerPath=getContainer('data');
  602. // This changes the page after building the URL.
  603. //Note that the wiki page destination name is set in params.
  604. var homeURL = LABKEY.ActionURL.buildURL(
  605. "project", formUrl , containerPath, params);
  606. print("Redirecting to "+homeURL);
  607. if (debug) return;
  608. window.location = homeURL;
  609. }