123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- var crfSetup={};
- crfSetup.print=
- function(msg){
- console.log(msg);
- }
- crfSetup.init=
- function(cb=null){
- let fName="[crfSetup(DORA):init]";
- this.print(fName);
- let that=this;
- let action=function(){that.afterScripts(cb);}
- LABKEY.requiresScript(["crfDORA/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(){
- return this.getObject('maps');
- }
- crfSetup.getEntryMaps=
- function(){
- return this.getObject('entryMaps');
- }
- crfSetup.getMap=
- function(queryName){
- let maps=this.getMaps();
- if (!(queryName in maps))
- this.parseMap(queryName);
- return maps[queryName];
- }
- crfSetup.getEntryMap=
- function(queryName){
- this.print('[getEntryMap]: '+queryName);
- let entryMaps=this.getEntryMaps();
- this.print('[getEntryMap]: maps '+Object.keys(entryMaps).length);
- if (!(queryName in entryMaps))
- this.parseEntryMap(queryName);
- return entryMaps[queryName];
- }
- crfSetup.getAdditionalDataObject=
- function(){
- return this.getObject('additionalData');
- }
- crfSetup.getAdditionalData=
- function(queryName){
- let adObject=this.getAdditionalDataObject();
- if (queryName in adObject){
- this.print(fName+': Returning preset value');
- return adObject[queryName];
- }
- return null;
- }
- crfSetup.getTargetStatus=
- function(action){
- return this.getObject('targetStatus')[action];
- }
- crfSetup.getTargetRecipient=
- function(action){
- return this.getObject('targetRecipient')[action];
- }
- crfSetup.getActionSettings=
- function(action){
- return this.getObject('actionSettings')[action];
- }
- crfSetup.getObject=
- function(name){
- if (!(name in this))
- this[name]=new Object;
- return this[name];
- }
- crfSetup.addObject=
- function(masterObject,objectName,object){
- let obj=this.getObject(masterObject);
- obj[objectName]=object;
- }
- crfSetup.invertMap=
- function(qMap){
- let qInverseMap=new Object();
- for (let q in qMap){
- qInverseMap[qMap[q]]=q;
- }
- return qInverseMap;
- }
- crfSetup.getStudyIdLabel
- =function(){
- return 'participantStudyId';
- }
- crfSetup.getLocalIdLabel
- =function(){
- return 'participantLocalId';
- }
- crfSetup.getParticipantLabel=
- function(entry){
- let pid=entry[this.getStudyIdLabel()];
- let loc=entry[this.getLocalIdLabel()];
- let label='';
- if (pid) {
- label+=pid;
- if (loc) label+=' ';
- }
- if (loc) label+='(Local: '+loc+')';
- if (label.length==0) label="NONE";
- return label;
-
- }
- crfSetup.getStudyId=
- function(label){
- this.print('getStudyId: label ['+label+']');
- return label.replace(/ ?\([^\)]*\)/,"");
- }
- crfSetup.getLocalId=
- function(label){
- return label.replace(/^.*\(Local: ([^\)]*)\)$/,"$1");
- }
- 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',[]));
- //also formData
- //users
- queryArray.push(runQuery.makeQuery(targetObject,'data','users','users',[]));
- queryArray[queryArray.length-1].schemaName='core';
- //also userData
- //inputLists
- queryArray.push(runQuery.makeQuery(targetObject,'config','inputLists','inputLists',[]));
- //crfEditors
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfEditors','crfEditors',[]));
- //crfEditorData
- //crfMonitors
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfMonitors','crfMonitors',[]));
- //crfMonitorData
- //crfSponsors
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfSponsors','crfSponsors',[]));
- //crfSponsorData
- //crfManagers
- queryArray.push(runQuery.makeQuery(targetObject,'config','crfManagers','crfManagers',[]));
- //FormStatus
- //
- queryArray.push(runQuery.makeQuery(targetObject,'config','FormStatus','formStatusAll',[]));
- let statusFilter=[];
- if ("formStatus" in this)
- statusFilter.push(LABKEY.Filter.create('Key',this.formStatus));
- queryArray.push(runQuery.makeQuery(targetObject,'config','FormStatus','formStatus',statusFilter));
- //crfButtons
- let statusButtonFilter=[];
- if ("formStatus" in this)
- statusButtonFilter.push(LABKEY.Filter.create('sourceFormStatus',this.formStatus));
- queryArray.push(
- runQuery.makeQuery(targetObject,'config','crfButtons','crfButtons',statusButtonFilter));
- //site
- queryArray.push(runQuery.makeQuery(targetObject,'config','site','siteData',[]));
- //crfEntry
- queryArray.push(runQuery.makeQuery(targetObject,'data','crfEntry','crfEntries',[]));
- //specialFields
- queryArray.push(runQuery.makeQuery(targetObject,'data','specialFields','specialFields',[]));
- //FormSetup
- queryArray.push(runQuery.makeQuery(targetObject,'config','FormSetup','formSetup',[]));
- //generateConfig
- queryArray.push(
- runQuery.makeQuery(targetObject,'config','generateConfig','generateConfigData',[]));
- //parentCrf
- if ("parentCrf" in this){
- let crfFilter=LABKEY.Filter.create('entryId',this.parentCrf);
- queryArray.push(runQuery.makeQuery(targetObject,'data','crfEntry','parentCrfData',[crfFilter]));
- }
- 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',[]));
- //also studyDataAll1
- 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.findSetupRow=
- function(sectionId){
- let key=sectionId.replace('section','');
- return this.getEntryMap('formSetup')[key];
- }
- 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){
- //queryMap can be a combination of queryName:key where key is an override of standard keys given below
- let fName='[parseEntryMap/'+queryName+']';
- let tA=queryName.split(':');
- let q=tA[0];
- let rows=this.getRows(q);
- this.entryMaps[queryName]=new Object();
- let qMap=this.entryMaps[queryName];
- let key='Key';
- if (q=='users') key='UserId';
- if (q=='siteData') key='siteNumber';
- if (tA.length>1) key=tA[1];
- for (let i=0;i<rows.length;i++){
- let r=rows[i];
- qMap[r[key]]=r;
- this.print(fName+' ['+r[key]+'] '+r);
- }
- }
-
- crfSetup.printMap=
- function(queryName){
- let fName='[printMap]';
- let qMap=this.getMap(queryName);
- for (let x in qMap){
- this.print(fName+' ['+x+'] '+qMap[x]);
- }
- }
- crfSetup.setAdditionalData=
- function(crfRef,formId){
- let formRows=this.selectFormSetupRows(formId);
- for (let i=0;i<formRows.length;i++){
- this.setAdditionalDataEntry(crfRef,formRows[i]);
- }
- }
- crfSetup.setAdditionalDataEntry=
- function(crfRef,formSetupEntry){
- //return information on additional data associated with the form
- //additionalData is a sub-list with multiple entries per patient/visit
-
- //argument is the row of the formSetup setup list
- let queryName=this.getMap('inputLists')[formSetupEntry['queryName']];
- let fName='[getAdditionalData/'+queryName+']';
- this.print(fName);
-
- //additionalData holds a reference to all queries already parsed
- //this helps in reducing number of calls to the database (I assume)a
- let adObject=this.getAdditionalDataObject();
- //first time we see this query, so we have to do the setup
- this.print(fName+': generating');
- adObject[queryName]=new Object();
-
- //takes address, so further changes will be to the newly created object
- //in fact, ad is just a short alias of the long variable name on the right
- let ad=adObject[queryName];
- //no additional data
- if (formSetupEntry["showFlag"]==="NONE") {
- this.print(fName+": empty");
- return ad;
- }
- //use showFlag to setup report section of the CRF list
- if (formSetupEntry["showFlag"]==="REVIEW") {
- //abuse additionalData to signal different segment
- this.print(fName+": generateReport");
- ad.isReview=true;
- return ad;
- }
- //setup the additionalData memory object
- this.print(fName+': setting values');
- ad.showFlag=formSetupEntry["showFlag"];
- ad.showFlagValue=formSetupEntry["showFlagValue"];
- ad.queryName=formSetupEntry["showQuery"];
- //for data queries, limit to present CRF only
- ad.filters=new Object();
- ad.filters['crfRef']=crfRef;
- //compose a long debug message
- let msg=fName+": flag "+ad.showFlag;
- msg+=" value "+ad.showFlagValue;
- msg+=" query "+ad.queryName;
- this.print(msg);
- return ad;
- }
- crfSetup.findTitle=
- function(queryId){
- let entry=this.getEntryMap('inputLists')[queryId];
- if (entry)
- return entry['title'];
- return "NONE";
- }
- crfSetup.parseButtons=
- function(){
- let rows=this.getRows('crfButtons');
- for (let i=0; i<rows.length; i++){
- let action=rows[i].action;//String
- let tstatus=rows[i].targetFormStatus;
- let trecip=rows[i].targetRecipient;
- this.addTargetStatus(action,tstatus);
- this.addTargetRecipient(action,trecip);
- //allow for settings to be promoted with each action (and potentially parsed and acted upon)
- //config.formConfig.actionSettings[action]=undefined;
- let aSet=rows[i].actionSettings;
- if (aSet){
- this.addActionSettings(action,variableList.parseVariables(aSet));
- variableList.printVariables(this,this.getActionSettings(action));
- }
- }
- }
- crfSetup.addTargetStatus=
- function(action,tstatus){
- this.addObject('targetStatus',action,tstatus);
- }
- crfSetup.addTargetRecipient=
- function(action,x){
- this.addObject('targetRecipient',action,x);
- }
- crfSetup.addActionSettings=
- function(action,x){
- this.addObject('actionSettings',action,x);
- }
|