|
@@ -1,288 +1,367 @@
|
|
|
-function print(config, msg){
|
|
|
+//global config variable
|
|
|
+const config=new Object();
|
|
|
+
|
|
|
+function print(msg){
|
|
|
config.document.getElementById(config.debugArea).value+="\n"+msg;
|
|
|
}
|
|
|
|
|
|
-function clear(config){
|
|
|
+function clear(){
|
|
|
config.document.getElementById(config.debugArea).value="";
|
|
|
}
|
|
|
|
|
|
-function getMode(config){
|
|
|
- if ("reviewMode" in config){
|
|
|
- return config.reviewMode;
|
|
|
+function getMode(){
|
|
|
+ if ("role" in config){
|
|
|
+ return config.role;
|
|
|
}
|
|
|
- return "EDIT";
|
|
|
+ return "crfEditor";
|
|
|
}
|
|
|
|
|
|
-function userName(formConfig,id){
|
|
|
- for (let i=0;i<formConfig.users.rows.length;i++){
|
|
|
- if (formConfig.users.rows[i].UserId!=id)
|
|
|
- continue;
|
|
|
- return formConfig.users.rows[i].DisplayName;
|
|
|
- }
|
|
|
- return "NONE";
|
|
|
+function doNothing(){
|
|
|
+ print('doNothing called');
|
|
|
+}
|
|
|
+
|
|
|
+function makeQuery(containerName,queryName,fieldName,filterArray){
|
|
|
+ //queryArray should contain elements with
|
|
|
+ //- fieldName to set the data variable
|
|
|
+ //- containerName to select container (data,config,CRF)
|
|
|
+ //- queryName to select query
|
|
|
+ //- filterArray to perform filtering, empty array works
|
|
|
+ //- callback cb to be called with no arguments
|
|
|
+
|
|
|
+ let e=new Object();
|
|
|
+ e.containerName=containerName;
|
|
|
+ e.queryName=queryName;
|
|
|
+ e.fieldName=fieldName;
|
|
|
+ e.filterArray=filterArray;
|
|
|
+ return e;
|
|
|
}
|
|
|
|
|
|
-function generateFormArray(config){
|
|
|
- print(config,"generateFormArray "+getMode(config));
|
|
|
+function getDataFromQueries(queryArray,cb){
|
|
|
+ afterQuery(new Object(),-1,queryArray,cb);
|
|
|
+}
|
|
|
|
|
|
- let formConfig=new Object();
|
|
|
+function afterQuery(data,id,queryArray,cb){
|
|
|
+
|
|
|
+ print('afterQuery['+id+']: ');
|
|
|
+
|
|
|
+ if (id>-1){
|
|
|
+ let fieldName=queryArray[id].fieldName;
|
|
|
+ print('afterQuery['+fieldName+']: '+data.rows.length);
|
|
|
+ //uses config.formConfig
|
|
|
+ config.formConfig[fieldName]=data;
|
|
|
+ }
|
|
|
+ id+=1;
|
|
|
+ if (id==queryArray.length) {
|
|
|
+ cb();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
|
|
|
+ let e=queryArray[id];
|
|
|
+ let qconfig=new Object();
|
|
|
+ qconfig.containerPath=getContainer(e.containerName);
|
|
|
qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="Forms";
|
|
|
+ if ("schemaName" in e){
|
|
|
+ print('afterQuery: schemaName='+e.schemaName);
|
|
|
+ qconfig.schemaName=e.schemaName;
|
|
|
+ }
|
|
|
|
|
|
+ if ("columns" in e){
|
|
|
+ print('afterQuery: columns='+e.columns);
|
|
|
+ qconfig.columns=e.columns;
|
|
|
+ }
|
|
|
+ qconfig.queryName=e.queryName;
|
|
|
+ //this should point to configuration container
|
|
|
+ //don't filter -> so we can pick up other forms (say registration) later on
|
|
|
+ //qconfig.filterArray=[LABKEY.Filter.create('Key',config.formId)];
|
|
|
+ if ("filterArray" in e)
|
|
|
+ qconfig.filterArray=e.filterArray;
|
|
|
+
|
|
|
//qconfig.filterArray=[LABKEY.Filter.create('formStatus',1)]
|
|
|
- qconfig.success=function(data){afterPopulatingForms(config,formConfig,data)};
|
|
|
+ qconfig.success=function(data){afterQuery(data,id,queryArray,cb);};
|
|
|
+ qconfig.failure=doNothing;
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingForms(config,formConfig,data){
|
|
|
-
|
|
|
- formConfig.dataForms=data;
|
|
|
- print(config,"afterPopulatingForms");
|
|
|
- print(config,"Number of forms: "+formConfig.dataForms.rows.length);
|
|
|
-
|
|
|
- let qconfig=new Object();
|
|
|
|
|
|
- qconfig.schemaName="core";
|
|
|
- qconfig.queryName="users";
|
|
|
- qconfig.success=function(data){afterPopulatingUsers(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-
|
|
|
+function printMessage(msg){
|
|
|
+ let txt=config.document.createElement("p");
|
|
|
+ config.document.getElementById(config.div).appendChild(txt);
|
|
|
+ txt.innerText=msg;
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingUsers(config,formConfig,data){
|
|
|
-
|
|
|
- formConfig.users=data;
|
|
|
- print(config,"afterPopulatingUsers");
|
|
|
- print(config,"Number of users: "+formConfig.users.rows.length);
|
|
|
-
|
|
|
+function userName(id){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
+ for (let i=0;i<formConfig.users.rows.length;i++){
|
|
|
+ if (formConfig.users.rows[i].UserId!=id)
|
|
|
+ continue;
|
|
|
+ return formConfig.users.rows[i].DisplayName;
|
|
|
+ }
|
|
|
+ return "NONE";
|
|
|
+}
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
+function setContainer(label,container){
|
|
|
+ if (!(config.formConfig.hasOwnProperty('container'))){
|
|
|
+ config.formConfig.container=new Array();
|
|
|
+ }
|
|
|
+ config.formConfig.container[label]=container;
|
|
|
+}
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="inputLists";
|
|
|
- qconfig.success=function(data){afterPopulatingLists(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
+function getContainer(label){
|
|
|
+ return config.formConfig.container[label];
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingLists(config,formConfig,data){
|
|
|
|
|
|
- formConfig.inputLists=data;
|
|
|
- print(config,"afterPopulatingLists");
|
|
|
- print(config,"Number of lists: "+formConfig.inputLists.rows.length);
|
|
|
+function generateFormArray(){
|
|
|
+ print("generateFormArray "+getMode());
|
|
|
|
|
|
-
|
|
|
- let qconfig=new Object();
|
|
|
-
|
|
|
- qconfig.schemaName="study";
|
|
|
- qconfig.queryName="StudyProperties";
|
|
|
- qconfig.columns="StudySponsor,StudyCoordinator,EudraCTNumber,RegulatoryNumber,SubjectColumnName"
|
|
|
- //make sure SubjectColumnName is part of the view
|
|
|
- qconfig.success=function(data){afterPopulatingStudyData(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
+ config.formConfig=new Object();
|
|
|
+ config.formConfig.softwareVersion='0.1.9';
|
|
|
+ //report software version
|
|
|
+ config.document.getElementById('version').innerText=config.formConfig.softwareVersion;
|
|
|
|
|
|
-function afterPopulatingStudyData(config,formConfig,data){
|
|
|
+ setContainer('data',LABKEY.ActionURL.getContainer());
|
|
|
+ setContainer('config',LABKEY.ActionURL.getContainer());
|
|
|
+ setContainer('CRF',LABKEY.ActionURL.getContainer());
|
|
|
+
|
|
|
+ let selectRows=new Object();
|
|
|
+ //this is local data
|
|
|
+ selectRows.containerPath=getContainer('CRF');
|
|
|
+ selectRows.schemaName='lists';
|
|
|
+ selectRows.queryName='crfSettings';
|
|
|
+ //store form related data to this object
|
|
|
+ selectRows.success=function(data){afterSettings(data,collectData);};
|
|
|
+ LABKEY.Query.selectRows(selectRows);
|
|
|
|
|
|
- formConfig.studyData=data;
|
|
|
- print(config,"afterPopulatingStudyData");
|
|
|
- print(config,"Number of study data entries: "+formConfig.studyData.rows.length);
|
|
|
- print(config,"ParticipantId: "+formConfig.studyData.rows[0].SubjectColumnName);
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
+//also used by crfManager
|
|
|
+function afterSettings(data,cb){
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
+ config.formConfig.settings=new Array();
|
|
|
+ for (let i=0;i<data.rows.length;i++){
|
|
|
+ let n=data.rows[i]['name'];
|
|
|
+ let v=data.rows[i]['value'];
|
|
|
+ config.formConfig.settings[n]=v;
|
|
|
+ }
|
|
|
|
|
|
- qconfig.schemaName="study";
|
|
|
- let demographicDataId=formConfig.dataForms.rows[0].masterQuery;
|
|
|
- let demographicDataQuery="NONE";
|
|
|
- for (let i=0;i<formConfig.inputLists.rows.length;i++){
|
|
|
- let entry=formConfig.inputLists.rows[i];
|
|
|
- print(config,"inputList ["+i+"] ["+entry.Key+"] "+entry.queryName);
|
|
|
- if (entry.Key==demographicDataId){
|
|
|
- demographicDataQuery=entry.queryName;
|
|
|
- break;
|
|
|
- }
|
|
|
+ let st=config.formConfig.settings;
|
|
|
+ print('afterSettings');
|
|
|
+ for (let k in st){
|
|
|
+ print('\t'+k+'='+st[k]);
|
|
|
}
|
|
|
- print(config,'Setting demographic query to '+demographicDataQuery);
|
|
|
|
|
|
- qconfig.queryName=demographicDataQuery;
|
|
|
- //qconfig.queryName="demographicData";
|
|
|
-
|
|
|
- qconfig.success=function(data){afterPopulatingDemographicData(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
+ //if ('dataContainer' in st){
|
|
|
+ // setContainer('data',st['dataContainer']);
|
|
|
+ //}
|
|
|
+ let vname='configContainer';
|
|
|
+ if (vname in st){
|
|
|
+ setContainer('config',st[vname]);
|
|
|
+ }
|
|
|
+ print('Config: '+getContainer('config'));
|
|
|
+ print('Data: '+getContainer('data'));
|
|
|
+ //collectData();
|
|
|
+ cb();
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingDemographicData(config,formConfig,data){
|
|
|
+function collectData(){
|
|
|
+ //setup queryArray
|
|
|
+ let queryArray=new Array();
|
|
|
+
|
|
|
+ //static variables
|
|
|
+ queryArray.push(makeQuery('data','crfStaticVariables','crfStaticVariables',[]));
|
|
|
+ //Forms
|
|
|
+ queryArray.push(makeQuery('config','Forms','dataForms',[]));
|
|
|
+ //users
|
|
|
+ queryArray.push(makeQuery('data','users','users',[]));
|
|
|
+ queryArray[queryArray.length-1].schemaName='core';
|
|
|
+ //inputLists
|
|
|
+ queryArray.push(makeQuery('config','inputLists','inputLists',[]));
|
|
|
+ //crfEditors
|
|
|
+ queryArray.push(makeQuery('config','crfEditors','crfEditors',[]));
|
|
|
+ //crfMonitors
|
|
|
+ queryArray.push(makeQuery('config','crfMonitors','crfMonitors',[]));
|
|
|
+ //crfSponsors
|
|
|
+ queryArray.push(makeQuery('config','crfSponsors','crfSponsors',[]));
|
|
|
+ //crfManagers
|
|
|
+ queryArray.push(makeQuery('config','crfManagers','crfManagers',[]));
|
|
|
+ //FormStatus
|
|
|
+ queryArray.push(makeQuery('config','FormStatus','formStatusg',[]));
|
|
|
+ //site
|
|
|
+ queryArray.push(makeQuery('config','site','siteData',[]));
|
|
|
+ //crfEntry
|
|
|
+ queryArray.push(makeQuery('data','crfEntry','crfEntries',[]));
|
|
|
+
|
|
|
+ getDataFromQueries(queryArray,addStudyData);
|
|
|
+ //getDataFromQueries(queryArray,fcontinue);
|
|
|
+}
|
|
|
|
|
|
- formConfig.demographicData=data;
|
|
|
- print(config,"afterPopulatingDemographic");
|
|
|
- print(config,"Number of patients: "+formConfig.demographicData.rows.length);
|
|
|
+function addStudyData(){
|
|
|
+ //setup queryArray
|
|
|
+ let queryArray=new Array();
|
|
|
|
|
|
+ queryArray.push(makeQuery('data','StudyProperties','studyData',[]));
|
|
|
+ let e=queryArray[queryArray.length-1];
|
|
|
+ e.schemaName='study';
|
|
|
+ let columnModel="";
|
|
|
+ let varRows=config.formConfig['crfStaticVariables'].rows;
|
|
|
+ for (let i=0;i<varRows.length;i++){
|
|
|
+ if (i>0) columnModel+=',';
|
|
|
+ columnModel+=varRows[i]['staticVariable'];
|
|
|
+ }
|
|
|
+ e.columns=columnModel;
|
|
|
+ getDataFromQueries(queryArray,generateWidgets);
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="crfEditors";
|
|
|
- qconfig.success=function(data){afterPopulatingCrfEditors(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingCrfEditors(config,formConfig,data){
|
|
|
|
|
|
- formConfig.crfEditors=data;
|
|
|
- print(config,"afterPopulatingCrfEditors");
|
|
|
- print(config,"Number of CRF editors: "+formConfig.crfEditors.rows.length);
|
|
|
-
|
|
|
+function generateWidgets(){
|
|
|
+ let fName='[generateWidgets]';
|
|
|
+ let formConfig=config.formConfig;
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
+ print("Number of study data entries: "+formConfig.studyData.rows.length);
|
|
|
+ print("ParticipantId: "+formConfig.studyData.rows[0].SubjectColumnName);
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="crfReviewers";
|
|
|
- qconfig.success=function(data){afterPopulatingCrfReviewers(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
+ let dataForms=formConfig.dataForms.rows;
|
|
|
|
|
|
-function afterPopulatingCrfReviewers(config,formConfig,data){
|
|
|
- formConfig.crfReviewers=data;
|
|
|
- print(config,"afterPopulatingCrfReviewers");
|
|
|
- print(config,"Number of CRF reviewerrs: "+formConfig.crfReviewers.rows.length);
|
|
|
- let qconfig=new Object();
|
|
|
+ formConfig.table=config.document.createElement("table");
|
|
|
+ config.document.getElementById(config.div).appendChild(formConfig.table);
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="crfManagers";
|
|
|
- qconfig.success=function(data){afterPopulatingCrfManagers(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
+ let accessModeColumn=getMode()+'Status';
|
|
|
+ print('accessModeColumn '+accessModeColumn);
|
|
|
+ //cutting down on number of fields
|
|
|
+ //let creatorModeColumn=getMode()+'Creator';
|
|
|
|
|
|
-function afterPopulatingCrfManagers(config,formConfig,data){
|
|
|
- formConfig.crfManagers=data;
|
|
|
- print(config,"afterPopulatingCrfManagers");
|
|
|
- print(config,"Number of CRF managers: "+formConfig.crfManagers.rows.length);
|
|
|
- let qconfig=new Object();
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="FormStatus";
|
|
|
- qconfig.success=function(data){afterPopulatingFormStatus(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
+ //switch from status based to form based access
|
|
|
+ print("Forms: "+dataForms.length);
|
|
|
+ print("Entries: "+formConfig.crfEntries.rows.length);
|
|
|
+ let fEntries=formConfig.crfEntries.rows;
|
|
|
+ let users=formConfig.users.rows;
|
|
|
+ let currentUserId=LABKEY.Security.currentUser.id;
|
|
|
+ let currentUser=undefined;
|
|
|
|
|
|
-function afterPopulatingFormStatus(config,formConfig,data){
|
|
|
- formConfig.formStatus=data;
|
|
|
- print(config,"afterPopulatingFormStatus");
|
|
|
- print(config,"Number of states in FormStatus: "+formConfig.formStatus.rows.length);
|
|
|
-
|
|
|
- formConfig.table=config.document.createElement("table");
|
|
|
- config.document.getElementById(config.div).appendChild(formConfig.table);
|
|
|
+ for (let i=0;i<users.length;i++){
|
|
|
+ if (users[i].UserId!=currentUserId) continue;
|
|
|
+ currentUser=users[i];
|
|
|
+ }
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="crfEntry";
|
|
|
-
|
|
|
- let visibleLevel="crfEditor";
|
|
|
- if ("reviewMode" in config) {
|
|
|
- if (config.reviewMode=="REVIEW")
|
|
|
- visibleLevel="crfReviewer";
|
|
|
- else
|
|
|
- visibleLevel="crfManager";
|
|
|
+ //determine the role filter
|
|
|
+ let fList=config.role+'s';
|
|
|
+ //check for users that fit the role,
|
|
|
+ //fRows lists all users for role
|
|
|
+ let fRows=config.formConfig[fList].rows;
|
|
|
+ print(fName+' candidates: '+fRows.length)
|
|
|
+ //current user must be in the list
|
|
|
+
|
|
|
+ let currentUserRoles=new Array();
|
|
|
+ //the same user can act for multiple sites
|
|
|
+ for (let i=0;i<fRows.length;i++){
|
|
|
+ if (fRows[i].User!=currentUser.UserId) continue;
|
|
|
+ currentUserRoles.push(fRows[i]);
|
|
|
}
|
|
|
|
|
|
+ //cludge for public sites where all users can act as anything
|
|
|
+ let sts=config.formConfig.settings;
|
|
|
+ let vName='allowAllForSite';
|
|
|
+ if (vName in sts){
|
|
|
+ let tempUserRole=new Object();
|
|
|
+ tempUserRole.User=currentUser.UserId;
|
|
|
+ tempUserRole.Site=parseInt(sts[vName]);
|
|
|
+ currentUserRoles.push(tempUserRole);
|
|
|
+ }
|
|
|
|
|
|
- let formStatusValue="";
|
|
|
- for (let i=0;i<formConfig.formStatus.rows.length;i++){
|
|
|
- if (formConfig.formStatus.rows[i].visibleLevel==visibleLevel){
|
|
|
- if (formStatusValue.length>0) formStatusValue+=";";
|
|
|
- formStatusValue+=String(formConfig.formStatus.rows[i].Key);
|
|
|
- }
|
|
|
+ //currentUser was not matched in fRows
|
|
|
+ if (currentUserRoles.length==0){
|
|
|
+ printMessage('User '+currentUser.DisplayName+" can't act as "+config.role);
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- //if ("review" in config) formStatusValue="2";//Submitted
|
|
|
- qconfig.filterArray=[LABKEY.Filter.create('formStatus',formStatusValue,LABKEY.Filter.Types.IN)];
|
|
|
- let currentUser=LABKEY.Security.currentUser.id;
|
|
|
- if ("reviewMode" in config){
|
|
|
- let userList=formConfig.crfReviewers;
|
|
|
- if (config.reviewMode=="APPROVED")
|
|
|
- userList=formConfig.crfManagers;
|
|
|
-
|
|
|
- let reviewer=0;
|
|
|
- for (let i=0;i<userList.rows.length;i++){
|
|
|
- if (userList.rows[i].User!=currentUser)
|
|
|
- continue;
|
|
|
- reviewer=1;
|
|
|
- break;
|
|
|
+
|
|
|
+ //currentUser should be also attached to the site of the document
|
|
|
+ let currentSites=new Array();
|
|
|
+ let siteRows=config.formConfig.siteData.rows;
|
|
|
+ for (let i=0;i<siteRows.length;i++){
|
|
|
+ for (let j=0;j<currentUserRoles.length;j++){
|
|
|
+ if (siteRows[i].siteNumber!=currentUserRoles[j].Site) continue;
|
|
|
+ currentSites.push(siteRows[i]);
|
|
|
}
|
|
|
- print(config,"reviewer "+reviewer);
|
|
|
- if (reviewer==0) return;
|
|
|
}
|
|
|
- else{
|
|
|
- //this only allows users to modify forms they have created
|
|
|
- //qconfig.filterArray.push(LABKEY.Filter.create('UserId',currentUser));
|
|
|
- //sometimes all people from reviewer list are allowed to complete each other's forms interchangeably
|
|
|
- let userListX="";
|
|
|
- for (let i=0;i<formConfig.crfEditors.rows.length;i++){
|
|
|
- userId=formConfig.crfEditors.rows[i]['User'];
|
|
|
- if (i>0) userListX+=";";
|
|
|
- userListX+=String(userId);
|
|
|
- }
|
|
|
- qconfig.filterArray.push(
|
|
|
- LABKEY.Filter.create('UserId',userListX,LABKEY.Filter.Types.IN));
|
|
|
-
|
|
|
|
|
|
+ config.formConfig.currentSites=currentSites;
|
|
|
+ let msg='User '+currentUser.DisplayName+' acting as '+config.role+' for (';
|
|
|
+ for (let i=0;i<currentSites.length;i++){
|
|
|
+ if (i>0) msg+=', ';
|
|
|
+ msg+=currentSites[i].siteName;
|
|
|
}
|
|
|
- qconfig.success=function(data){afterPopulatingEntries(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
+ msg+=')';
|
|
|
+ printMessage(msg);
|
|
|
|
|
|
+ //browse through forms
|
|
|
+ for (let i=0;i<dataForms.length;i++){
|
|
|
|
|
|
-function afterPopulatingEntries(config,formConfig,data){
|
|
|
-
|
|
|
- formConfig.formData=data;
|
|
|
- let dataForms=formConfig.dataForms;
|
|
|
- let table=formConfig.table;
|
|
|
- print(config,"afterPopulatingEntries");
|
|
|
+ //dataForms is Forms
|
|
|
+ let qForm=dataForms[i];
|
|
|
+ let formKey=qForm.Key;
|
|
|
+
|
|
|
+ //add row for each form
|
|
|
+ let row=formConfig.table.insertRow(i);
|
|
|
+ let formName=qForm.formName;
|
|
|
+ print("["+i+"/"+formKey+']: '+formName);
|
|
|
|
|
|
- print(config,"Forms: "+dataForms.rows.length);
|
|
|
- print(config,"InProgress: "+data.rows.length);
|
|
|
+ //column counter
|
|
|
+ let k=0;
|
|
|
|
|
|
+ //get the target status
|
|
|
+ let formStatus=qForm[accessModeColumn];
|
|
|
+ print('target formStatus '+formStatus);
|
|
|
|
|
|
-
|
|
|
- for (let i=0;i<dataForms.rows.length; i++){
|
|
|
-
|
|
|
- let formKey=dataForms.rows[i].Key;
|
|
|
- print(config,"Key["+i+"]: "+formKey);
|
|
|
-
|
|
|
- //figure out master query name
|
|
|
- let masterQuery="NONE";
|
|
|
- let mID=dataForms.rows[i].masterQuery;
|
|
|
- print(config,"Setting master query: "+mID);
|
|
|
- for (let i2=0;i2<formConfig.inputLists.rows.length;i2++){
|
|
|
- //queryName
|
|
|
- if (formConfig.inputLists.rows[i2].Key!=mID)
|
|
|
+ for (let j=0;j<fEntries.length;j++){
|
|
|
+ let entry=fEntries[j];
|
|
|
+ let formId=entry.Form;
|
|
|
+
|
|
|
+ if (formId!=formKey)
|
|
|
continue;
|
|
|
|
|
|
- masterQuery=formConfig.inputLists.rows[i2].queryName;
|
|
|
- print(config,"Setting master query "+masterQuery);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- let row=table.insertRow(i);
|
|
|
- let formName=dataForms.rows[i].formName;
|
|
|
- let k=0;
|
|
|
- for (let j=0;j<data.rows.length;j++){
|
|
|
- let formId=data.rows[j].Form;
|
|
|
- //print(config,"Row["+j+"] formId: "+formId);
|
|
|
- if (formId!=formKey)
|
|
|
+ //only select forms where status matches the target status
|
|
|
+ if (entry.FormStatus!=formStatus){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ print('Candidate '+entry.entryId);
|
|
|
+ //TODO: smart filter on user (now we get to see all)
|
|
|
+ //
|
|
|
+ //for editors
|
|
|
+ if (config.role=='crfEditor' && entry.UserId!=currentUser.UserId){
|
|
|
+ print('Skipping identity mismatch: '+entry.UserId+'/'+currentUser.UserId);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //for others
|
|
|
+ let matchingSite=-1;
|
|
|
+ let potentialSiteNumbers="[";
|
|
|
+ for (let k=0;k<currentSites.length;k++){
|
|
|
+ if (k>0) potentialSiteNumbers+=',';
|
|
|
+ potentialSiteNumbers+=currentSites[k].siteNumber;
|
|
|
+ if (entry.Site!=currentSites[k].siteNumber) continue;
|
|
|
+ matchingSite=currentSites[k].siteNumber;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ potentialSiteNumbers+=']';
|
|
|
+ if (matchingSite==-1){
|
|
|
+ print('Skipping wrong site: '+entry.Site+'/'+potentialSiteNumbers);
|
|
|
continue;
|
|
|
+ }
|
|
|
+
|
|
|
//insert form
|
|
|
+ //
|
|
|
+
|
|
|
let fbox=config.document.createElement("div");
|
|
|
fbox.classList.add("box","gold");
|
|
|
|
|
|
let fp=config.document.createElement("p");
|
|
|
- let id=data.rows[j].entryId;
|
|
|
+ let id=entry.entryId;
|
|
|
fp.innerHTML=id;
|
|
|
//it would be great if this were patientId if available
|
|
|
//fp.classList.add("large","center");
|
|
@@ -291,10 +370,10 @@ function afterPopulatingEntries(config,formConfig,data){
|
|
|
|
|
|
let fp1=config.document.createElement("p");
|
|
|
let user="NONE";
|
|
|
- for (let ii=0;ii<formConfig.users.rows.length;ii++){
|
|
|
- if (formConfig.users.rows[ii].UserId!=data.rows[j].UserId)
|
|
|
+ for (let ii=0;ii<users.length;ii++){
|
|
|
+ if (users[ii].UserId!=entry.UserId)
|
|
|
continue;
|
|
|
- user=formConfig.users.rows[ii].DisplayName;
|
|
|
+ user=users[ii].DisplayName;
|
|
|
break;
|
|
|
}
|
|
|
fp1.innerHTML=user;
|
|
@@ -309,16 +388,14 @@ function afterPopulatingEntries(config,formConfig,data){
|
|
|
|
|
|
let fp3=config.document.createElement("p");
|
|
|
fp3.id="pid"+id;
|
|
|
- fp3.innerHTML="NONE";
|
|
|
- print(config,'Setting participant id from query: '+masterQuery);
|
|
|
- if (masterQuery!="NONE"){
|
|
|
- let qconfig=new Object();
|
|
|
- qconfig.schemaName='lists';
|
|
|
- qconfig.queryName=masterQuery;
|
|
|
- qconfig.filterArray=[LABKEY.Filter.create('crfRef',id)];
|
|
|
- qconfig.success=function(data){setPatientId(config,formConfig,data,fp3.id);}
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
- }
|
|
|
+ let pid=entry['participantStudyId'];
|
|
|
+ let loc=entry['participantLocalId'];
|
|
|
+ let label='';
|
|
|
+ if (pid) label+=pid+' ';
|
|
|
+ if (loc) label+='(Local: '+loc+')';
|
|
|
+ if (label.length==0) label="NONE";
|
|
|
+ fp3.innerHTML=label;
|
|
|
+
|
|
|
fp3.classList.add("center");
|
|
|
fbox.appendChild(fp3);
|
|
|
|
|
@@ -327,16 +404,24 @@ function afterPopulatingEntries(config,formConfig,data){
|
|
|
|
|
|
let cell=row.insertCell(k);
|
|
|
cell.classList.add("stretch");
|
|
|
- cell.id="box"+data.rows[j].crfRef;
|
|
|
+ cell.id="box"+entry.crfRef;
|
|
|
|
|
|
let button=config.document.createElement("button");
|
|
|
button.appendChild(fbox);
|
|
|
- button.onclick=function(){openForm(config,formConfig,id,undefined)};
|
|
|
+ button.onclick=function(){openForm(entry)};
|
|
|
|
|
|
cell.appendChild(button);
|
|
|
k++;
|
|
|
}
|
|
|
- if ("reviewMode" in config) continue;
|
|
|
+ print('finished checking existing forms');
|
|
|
+
|
|
|
+ //only those that are allowed to create forms
|
|
|
+ //print('Status: '+qForm[creatorModeColumn]);
|
|
|
+
|
|
|
+ let creator=qForm['creator'];
|
|
|
+ if (!creator) continue;
|
|
|
+ if (creator!=getMode()) continue;
|
|
|
+ //if (qForm[creatorModeColumn]!='TRUE') continue;
|
|
|
|
|
|
let fbox=config.document.createElement("div");
|
|
|
fbox.classList.add("box","red");
|
|
@@ -357,7 +442,7 @@ function afterPopulatingEntries(config,formConfig,data){
|
|
|
|
|
|
let button=config.document.createElement("button");
|
|
|
button.appendChild(fbox);
|
|
|
- button.onclick=function(){createForm(config,formConfig,formKey)};
|
|
|
+ button.onclick=function(){createForm(formKey)};
|
|
|
|
|
|
cell.appendChild(button);
|
|
|
|
|
@@ -366,46 +451,16 @@ function afterPopulatingEntries(config,formConfig,data){
|
|
|
|
|
|
}
|
|
|
|
|
|
-function setPatientId(config,formConfig,data,id){
|
|
|
- if (data.rows.length==0) return;
|
|
|
-
|
|
|
- let participantCode=data.rows[0].participantCode;
|
|
|
- let participantField=formConfig.studyData.rows[0].SubjectColumnName;
|
|
|
-
|
|
|
-
|
|
|
- print(config,'participantCode: '+participantCode);
|
|
|
- print(config,'participantField: '+participantCode);
|
|
|
- for (let i=0;i<formConfig.demographicData.rows.length;i++){
|
|
|
- let entry=formConfig.demographicData.rows[i];
|
|
|
- let key=entry.lsid;
|
|
|
- print(config,'Comparing to: '+key);
|
|
|
- if (key!=participantCode) continue;
|
|
|
- let participantId=entry[participantField];
|
|
|
- config.document.getElementById(id).innerHTML=participantId;
|
|
|
- break;
|
|
|
- }
|
|
|
+function openForm(crfEntry){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
+ let crfRef=crfEntry.entryId;
|
|
|
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-function openForm(config,formConfig,crfRef, crfEntry){
|
|
|
- print(config,"Clicked for "+crfRef);
|
|
|
- if (crfEntry==undefined){
|
|
|
- for (let i=0;i<formConfig.formData.rows.length;i++){
|
|
|
- if (formConfig.formData.rows[i].entryId!=crfRef) continue;
|
|
|
- print(config,"Setting "+formConfig.formData.rows[i].entryId);
|
|
|
- crfEntry=formConfig.formData.rows[i];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (crfEntry==undefined) return;
|
|
|
-
|
|
|
- let formEntry=undefined;
|
|
|
+ print("Clicked for "+crfRef);
|
|
|
|
|
|
let formId=crfEntry.Form;
|
|
|
for (let i=0;i<formConfig.dataForms.rows.length;i++){
|
|
|
if (formConfig.dataForms.rows[i].Key!=formId) continue;
|
|
|
- print(config,"Setting form "+formConfig.dataForms.rows[i].formName);
|
|
|
+ print("Setting form "+formConfig.dataForms.rows[i].formName);
|
|
|
formEntry=formConfig.dataForms.rows[i];
|
|
|
break;
|
|
|
}
|
|
@@ -414,7 +469,7 @@ function openForm(config,formConfig,crfRef, crfEntry){
|
|
|
//select between review and view
|
|
|
//let formUrl=formEntry["formUrl"];
|
|
|
//if ("reviewMode" in config) formUrl=formEntry["reviewFormUrl"];
|
|
|
- //print(config,"Setting url "+formUrl);
|
|
|
+ //print("Setting url "+formUrl);
|
|
|
|
|
|
//direct all to the same html
|
|
|
let formUrl="visit";
|
|
@@ -424,27 +479,26 @@ function openForm(config,formConfig,crfRef, crfEntry){
|
|
|
let params = {
|
|
|
"name": formUrl,
|
|
|
// The destination wiki page. The name of this parameter is not arbitrary.
|
|
|
- "userid": crfEntry.UserId,
|
|
|
"entryId": crfRef,
|
|
|
- "registrationQueryId":"NOT USED",
|
|
|
- "reviewMode":reviewMode,
|
|
|
"formId":formId,
|
|
|
- "formName":"NOT USED"
|
|
|
+ "role" : config.role
|
|
|
};
|
|
|
|
|
|
//"formSetupQuery":formEntry["setupQuery"],
|
|
|
let containerPath= LABKEY.ActionURL.getContainer();
|
|
|
- // This changes the page after building the URL.
|
|
|
+ // This changes the page after building the URL.
|
|
|
//Note that the wiki page destination name is set in params.
|
|
|
- var wikiURL = LABKEY.ActionURL.buildURL("crf", formUrl , containerPath, params);
|
|
|
- print(config,"Redirecting to "+wikiURL);
|
|
|
+ var wikiURL = LABKEY.ActionURL.buildURL("crf", formUrl , containerPath, params);
|
|
|
+ print("Redirecting to "+wikiURL);
|
|
|
|
|
|
|
|
|
window.location = wikiURL;
|
|
|
}
|
|
|
|
|
|
-function createForm(config,formConfig,formId){
|
|
|
- print(config,"Create form w/id "+formId);
|
|
|
+function createForm(formId){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
+
|
|
|
+ print("Create form w/id "+formId);
|
|
|
|
|
|
let crfEntry=new Object();
|
|
|
crfEntry.entryId=Date.now();
|
|
@@ -454,27 +508,22 @@ function createForm(config,formConfig,formId){
|
|
|
//set other variables
|
|
|
//requires studyData as part of formConfig
|
|
|
let studyData=formConfig.studyData.rows[0];
|
|
|
- crfEntry.EudraCTNumber=studyData.EudraCTNumber;
|
|
|
- crfEntry.StudyCoordinator=studyData.StudyCoordinator;
|
|
|
- crfEntry.StudySponsor=studyData.StudySponsor;
|
|
|
- crfEntry.RegulatoryNumber=studyData.RegulatoryNumber;
|
|
|
+ let varRows=formConfig['crfStaticVariables'].rows;
|
|
|
+ for (let i=0;i<varRows.length;i++){
|
|
|
+ let varName=varRows[i].staticVariable;
|
|
|
+ crfEntry[varName]=studyData[varName];
|
|
|
+ }
|
|
|
crfEntry.UserId=LABKEY.Security.currentUser.id;
|
|
|
- //requires crfEditors as part of formConfig
|
|
|
- for (let i=0;i<formConfig.crfEditors.rows.length;i++){
|
|
|
- print(config,"Checking user "+formConfig.crfEditors.rows[i].User);
|
|
|
- if (formConfig.crfEditors.rows[i].User!=crfEntry.UserId) continue;
|
|
|
- print(config,"Found user");
|
|
|
- crfEntry.Site=formConfig.crfEditors.rows[i].Site;
|
|
|
- print(config,"Setting site to id="+crfEntry.Site);
|
|
|
- break;
|
|
|
- }
|
|
|
+ crfEntry.Site=config.formConfig.currentSites[0].siteNumber;
|
|
|
+ print("Setting site to id="+crfEntry.Site);
|
|
|
//from argument list
|
|
|
crfEntry.Form=formId;
|
|
|
|
|
|
let qconfig=new Object();
|
|
|
+ qconfig.containerPath=getContainer('data');
|
|
|
qconfig.schemaName='lists';
|
|
|
qconfig.queryName='crfEntry';
|
|
|
- qconfig.success=function(data){openForm(config,formConfig,crfEntry.entryId,crfEntry)};
|
|
|
+ qconfig.success=function(data){openForm(crfEntry)};
|
|
|
qconfig.rows=[crfEntry];
|
|
|
LABKEY.Query.insertRows(qconfig);
|
|
|
}
|