123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- var crfSetup={};
- crfSetup.print=
- function(msg){
- console.log(msg);
- }
- crfSetup.init=
- function(cb=null){
- let fName="[crfSetup:init]";
- this.print(fName);
- let that=this;
- let action=function(){that.afterScripts(cb);}
- LABKEY.requiresScript(["crfTecant/runQuery.js"],action);
- }
- crfSetup.afterScripts=
- function(cb=null){
- if (cb) cb();
- }
- crfSetup.setContainer=
- function(label,container){
- if (!(this.hasOwnProperty('container'))){
- this.container=new Array();
- }
- this.container[label]=container;
- }
- crfSetup.getContainer=
- function(label){
- return this.container[label];
- }
- crfSetup.getSettings=
- function(variable){
- if (variable in this.settings){
- return this.settings[variable];
- }
- return null;
- }
- crfSetup.getRows=
- function(objectName){
- if (objectName in this)
- return this[objectName].rows;
- return new Array();
- }
- crfSetup.getMaps=
- function(){
- if (!("maps" in this))
- this.maps=new Object();
- return this.maps;
- }
- crfSetup.getEntryMaps=
- function(){
- if (!("entryMaps" in this))
- this.entryMaps=new Object();
- return this.entryMaps;
- }
- crfSetup.getMap=
- function(queryName){
- let maps=this.getMaps();
- if (!(queryName in maps))
- this.parseMap(queryName);
- return maps[queryName];
- }
- crfSetup.getEntryMap=
- function(queryName){
- let entryMaps=this.getEntryMaps();
- if (!(queryName in entryMaps))
- this.parseEntryMap(queryName);
- return entryMaps[queryName];
- }
- crfSetup.setContainers=
- function(cb=null){
- this.setContainer('data',LABKEY.ActionURL.getContainer());
- this.setContainer('config',LABKEY.ActionURL.getContainer());
- this.setContainer('CRF',LABKEY.ActionURL.getContainer());
- let selectRows=new Object();
- //this is local data
- selectRows.containerPath=this.getContainer('CRF');
- selectRows.schemaName='lists';
- selectRows.queryName='crfSettings';
- //store form related data to this object
- let that=this;
- selectRows.success=function(data){that.parseSettings(data,cb);};
- LABKEY.Query.selectRows(selectRows);
- }
- crfSetup.parseSettings=
- function(data,cb){
- let fName="[parseSettings]";
- this.settings=new Array();
- for (let i=0;i<data.rows.length;i++){
- let n=data.rows[i]['name'];
- let v=data.rows[i]['value'];
- this.settings[n]=v;
- }
- this.print(fName);
- for (let k in this.settings){
- this.print(fName+'\t'+k+'='+this.settings[k]);
- }
- //if ('dataContainer' in st){
- // setContainer('data',st['dataContainer']);
- //}
- let vname='configContainer';
- if (vname in this.settings){
- this.setContainer('config',this.settings[vname]);
- }
- this.print(fName+' config: '+this.getContainer('config'));
- this.print(fName+' data: '+this.getContainer('data'));
- if (cb) cb();
- }
- crfSetup.parseSetup=
- function(cb=null){
- //setup queryArray
- let queryArray=new Array();
- //targetObject
- let targetObject=this;
- //static variables
- queryArray.push(runQuery.makeQuery(targetObject,'data','crfStaticVariables','crfStaticVariables',[]));
- //Forms
- queryArray.push(runQuery.makeQuery(targetObject,'config','Forms','dataForms',[]));
- //users
- queryArray.push(runQuery.makeQuery(targetObject,'data','users','users',[]));
- queryArray[queryArray.length-1].schemaName='core';
- //inputLists
- queryArray.push(runQuery.makeQuery(targetObject,'config','inputLists','inputLists',[]));
- //crfEditors
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfEditors','crfEditors',[]));
- //crfMonitors
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfMonitors','crfMonitors',[]));
- //crfSponsors
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfSponsors','crfSponsors',[]));
- //crfManagers
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfManagers','crfManagers',[]));
- //FormStatus
- queryArray.push(runQuery.makeQuery(targetObject,'config','FormStatus','formStatus',[]));
- //site
- queryArray.push(runQuery.makeQuery(targetObject,'config','site','siteData',[]));
- //crfEntry
- queryArray.push(runQuery.makeQuery(targetObject,'data','crfEntry','crfEntries',[]));
-
- queryArray.push(
- runQuery.makeQuery(targetObject,'config','generateConfig','generateConfigData',[]));
- let that=this;
- let action=function(){that.addStudyProperties(cb);};
- runQuery.getDataFromQueries(this,queryArray,action);
- }
- crfSetup.addStudyProperties=
- function(cb){
- //setup queryArray
- let queryArray=new Array();
- let targetObject=this;
-
- queryArray.push(runQuery.makeQuery(targetObject,'data','StudyProperties','studyData',[]));
- let e=queryArray[queryArray.length-1];
- e.schemaName='study';
- let columnModel="";
- let varRows=this.getRows('crfStaticVariables');
- for (let i=0;i<varRows.length;i++){
- if (i>0) columnModel+=',';
- columnModel+=varRows[i]['staticVariable'];
- }
- e.columns=columnModel;
- let that=this;
- //let action=function(){that.fcontinue();};
- //let action=function(){that.parseQueryMap(cb);};
- let action=cb;
- runQuery.getDataFromQueries(this,queryArray,action);
- }
- crfSetup.selectFormSetupRows=
- function(formId){
- let formSetupRows=new Array();
- let config=this.config;
- let allRows=this.getRows("formSetup");
- for (let i=0;i<allRows.length;i++){
- let formEntry=allRows[i];
- if (formEntry.formName==formId)
- formSetupRows.push(formEntry);
- }
- return formSetupRows;
- }
- crfSetup.parseMap=
- function(queryName){
- let fName='[parseMap/'+queryName+']';
- let key="Key";
- let value="value";
- if (queryName=="inputLists")
- value="queryName";
- if (queryName=="users"){
- key="UserId";
- value="DisplayName";
- }
- if (queryName=='dataForms')
- value='formName';
- if (queryName=='formStatus')
- value='formStatus';
- this.print(fName);
- let rows=this.getRows(queryName);
- this.maps[queryName]=new Object();
- let qMap=this.maps[queryName];
- for (let i=0;i<rows.length;i++){
- let r=rows[i];
- qMap[r[key]]=r[value];
- //this.print(fName+' ['+r[key]+'] '+r[value]);
- }
-
- }
- crfSetup.parseEntryMap=
- function(queryName){
- let rows=this.getRows(queryName);
- this.entryMaps[queryName]=new Object();
- let qMap=this.entryMaps[queryName];
- let key='Key';
- if (queryName=='Users') key='UserId';
- for (let i=0;i<rows.length;i++){
- let r=rows[i];
- qMap[r[key]]=r;
- //this.print(fName+' ['+r[key]+'] '+r[value]);
- }
- }
-
- crfSetup.printMap=
- function(queryName){
- let fName='[printMap]';
- let qMap=this.getMap(queryName);
- for (let x in qMap){
- this.print(fName+' ['+x+'] '+qMap[x]);
- }
- }
|