//not tested yet. //to use, add crfTecant/crfData.js to requiresScript and in the call-back, run init //will work with crfSetup as setup object var crfData={}; crfData.init= function(cb=null){ this.print('[crfData(DORA):init]'); let that=this; let action=function(){that.afterScripts(cb);}; LABKEY.requiresScript(["crfDORA/runQuery.js","crfDORA/variableList.js"],action); } crfData.afterScripts= function(cb=null){ if (cb) cb(); } crfData.setSetup= function(setup){ this.setup=setup; } crfData.getContainer= function(label){ return this.setup.getContainer(label); } crfData.print= function(msg){ console.log(msg); } //getters crfData.getSnapshotObject= function(){ if (!("dataQueriesSnapshot" in this)) this.dataQueriesSnapshot=new Object(); return this.dataQueriesSnapshot; } crfData.getQuerySnapshot= function(queryName){ //check whether queryName is in snapshotObject? return this.getSnapshotObject()[queryName]; } crfData.getLayoutObject= function(){ if (!("dataQueriesLayout" in this)) this.dataQueriesLayout=new Object(); return this.dataQueriesLayout; } crfData.getQueryLayout= function(queryName){ //check whether queryName is in snapshotObject? return this.getLayoutObject()[queryName]; } crfData.getLookupObject= function(){ if (!("lookup" in this)) this.lookup=new Object(); return this.lookup; } crfData.getLookup= function(queryName){ let x=this.getLookupObject(); if (queryName in x) return x[queryName]; return null; } crfData.getRegistration= function(){ let fName='[getRegistration]'; let regQueryPars=variableList.parseVariables(this.setup.getSettings('registrationQuery')); let query=regQueryPars['query']; //this.print(fName+' query '+query); return this.getQuerySnapshot(query).rows; } crfData.getCrfEntry= function(){ return this.getQuerySnapshot('crfEntry').rows[0]; } crfData.getActiveQueries= function(){ if (!("activeQueries" in this)) this.activeQueries=new Object(); return this.activeQueries; } crfData.getActiveQuery= function(queryName){ let aq=this.getActiveQueries(); if (queryName in aq) return aq[queryName]; return null; } crfData.getRegistrationMap= function(value=null){ let rows=this.getRegistration(); let qMap=new Object(); let key='Key'; if (!value) value='participantStudyId'; for (let i=0;i1){ entry.SequenceNum+=i/100; } this.print( "Adding sequence number "+entry.SequenceNum); insRows.push(entry); } if (modRows.length>0) modArray.push(runQuery.makeModification('update',containerName,schemaName,q,modRows)); //determine rows that need to be inserted from querySnapshot if (insRows.length>0) modArray.push(runQuery.makeModification('insert',containerName,schemaName,q,insRows)); } //do the whole batch runQuery.modifyDataFromQueries(this,modArray,cb); } crfData.removeData= function(cb=null){ let qList=this.getActiveQueries(); let modArray=new Array(); for (let qId in qList){ let entry=qList[qId]; let q=entry['queryName']; //determine rows that need to be updated form querySnapshot let studyRows=this.getQuerySnapshot(q+'Study').rows; if (studyRows.length>0) modArray.push(runQuery.makeModification('delete','data','study',q,studyRows)); let listRows=this.getQuerySnapshot(q).rows; if (listRows.length>0) modArray.push(runQuery.makeModification('delete','data','lists',q,listRows)); } //do the whole batch runQuery.modifyDataFromQueries(this,modArray,cb); } crfData.setRegistration= function(cb=null){ let regQuerySettings=this.setup.getSettings('registrationQuery'); let regQueryPars=variableList.parseVariables(regQuerySettings); let q=regQueryPars['query']; if (!q){ this.print('Registration query not set, got ['+regQuerySettings+'] for settings, should have query=X format'); return; } let queryArray=new Array(); let targetObject=this.getSnapshotObject(); let filters=[]; queryArray.push(runQuery.makeQuery(targetObject,'data',q,q,filters)); runQuery.getDataFromQueries(this,queryArray,cb); } crfData.setCrfEntry= function(crfRef,cb=null){ let q='crfEntry'; let queryArray=new Array(); let targetObject=this.getSnapshotObject(); let filters=[LABKEY.Filter.create('entryId',crfRef)]; queryArray.push(runQuery.makeQuery(targetObject,'data',q,q,filters)); runQuery.getDataFromQueries(this,queryArray,cb); } crfData.createCrfStatus= function(crfEntry){ let crfStatus=new Object(); crfStatus.entryId=crfEntry.entryId; crfStatus.submissionDate=new Date(); crfStatus.FormStatus=crfEntry.FormStatus; crfStatus.User=crfEntry.UserId; crfStatus.Form=crfEntry.Form; return crfStatus; } crfData.addActiveQuery= function(entry){ let aq=this.getActiveQueries(); let qName=entry['queryName']; if (qName in aq) return; aq[qName]=entry; return; } crfData.clearActiveQueries= function(){ let aq=this.getActiveQueries(); for (q in aq){ delete aq[q]; } }