|
@@ -1,288 +1,364 @@
|
|
|
-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 printMessage(msg){
|
|
|
+ let txt=config.document.createElement("p");
|
|
|
+ config.document.getElementById(config.div).appendChild(txt);
|
|
|
+ txt.innerText=msg;
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingForms(config,formConfig,data){
|
|
|
-
|
|
|
- formConfig.dataForms=data;
|
|
|
- print(config,"afterPopulatingForms");
|
|
|
- print(config,"Number of forms: "+formConfig.dataForms.rows.length);
|
|
|
-
|
|
|
- let qconfig=new Object();
|
|
|
+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";
|
|
|
+}
|
|
|
|
|
|
- qconfig.schemaName="core";
|
|
|
- qconfig.queryName="users";
|
|
|
- qconfig.success=function(data){afterPopulatingUsers(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-
|
|
|
+function setContainer(label,container){
|
|
|
+ if (!(config.formConfig.hasOwnProperty('container'))){
|
|
|
+ config.formConfig.container=new Array();
|
|
|
+ }
|
|
|
+ config.formConfig.container[label]=container;
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingUsers(config,formConfig,data){
|
|
|
-
|
|
|
- formConfig.users=data;
|
|
|
- print(config,"afterPopulatingUsers");
|
|
|
- print(config,"Number of users: "+formConfig.users.rows.length);
|
|
|
+function getContainer(label){
|
|
|
+ return config.formConfig.container[label];
|
|
|
+}
|
|
|
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
+function generateFormArray(){
|
|
|
+ print("generateFormArray "+getMode());
|
|
|
+
|
|
|
+ config.formConfig=new Object();
|
|
|
+ config.formConfig.softwareVersion='0.1.7';
|
|
|
+ //report software version
|
|
|
+ config.document.getElementById('version').innerText=config.formConfig.softwareVersion;
|
|
|
+
|
|
|
+ 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=afterSettings;
|
|
|
+ LABKEY.Query.selectRows(selectRows);
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="inputLists";
|
|
|
- qconfig.success=function(data){afterPopulatingLists(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingLists(config,formConfig,data){
|
|
|
+function afterSettings(data){
|
|
|
|
|
|
- formConfig.inputLists=data;
|
|
|
- print(config,"afterPopulatingLists");
|
|
|
- print(config,"Number of lists: "+formConfig.inputLists.rows.length);
|
|
|
-
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
+ let st=config.formConfig.settings;
|
|
|
+ print('afterSettings');
|
|
|
+ for (let k in st){
|
|
|
+ print('\t'+k+'='+st[k]);
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
+ //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'));
|
|
|
+
|
|
|
+
|
|
|
+ //setup queryArray
|
|
|
+ let queryArray=new Array();
|
|
|
+ //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',[]));
|
|
|
+ //studyData
|
|
|
+ queryArray.push(makeQuery('data','StudyProperties','studyData',[]));
|
|
|
+ let e=queryArray[queryArray.length-1];
|
|
|
+ e.schemaName='study';
|
|
|
+ e.columns="StudySponsor,StudyCoordinator,EudraCTNumber";
|
|
|
+ e.columns+=',RegulatoryNumber,SubjectColumnName';
|
|
|
+ //crfEditors
|
|
|
+ queryArray.push(makeQuery('config','crfEditors','crfEditors',[]));
|
|
|
+ //crfMonitors
|
|
|
+ queryArray.push(makeQuery('config','crfMonitors','crfMonitors',[]));
|
|
|
+ //crfSponsors
|
|
|
+ queryArray.push(makeQuery('config','crfSponsors','crfSponsors',[]));
|
|
|
+ //FormStatus
|
|
|
+ queryArray.push(makeQuery('config','FormStatus','formStatusg',[]));
|
|
|
+ //site
|
|
|
+ queryArray.push(makeQuery('config','site','siteData',[]));
|
|
|
+ //crfEntry
|
|
|
+ queryArray.push(makeQuery('data','crfEntry','crfEntries',[]));
|
|
|
+
|
|
|
+ getDataFromQueries(queryArray,fcontinue);
|
|
|
}
|
|
|
-
|
|
|
-function afterPopulatingStudyData(config,formConfig,data){
|
|
|
|
|
|
- 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);
|
|
|
+function fcontinue(){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
|
|
|
-
|
|
|
+ print("Number of study data entries: "+formConfig.studyData.rows.length);
|
|
|
+ print("ParticipantId: "+formConfig.studyData.rows[0].SubjectColumnName);
|
|
|
|
|
|
let qconfig=new Object();
|
|
|
|
|
|
+ qconfig.containerPath=getContainer('data');
|
|
|
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);
|
|
|
+ print("inputList ["+i+"] ["+entry.Key+"] "+entry.queryName);
|
|
|
if (entry.Key==demographicDataId){
|
|
|
demographicDataQuery=entry.queryName;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- print(config,'Setting demographic query to '+demographicDataQuery);
|
|
|
+ print('Setting demographic query to '+demographicDataQuery);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
qconfig.queryName=demographicDataQuery;
|
|
|
//qconfig.queryName="demographicData";
|
|
|
|
|
|
- qconfig.success=function(data){afterPopulatingDemographicData(config,formConfig,data)};
|
|
|
+ qconfig.success=afterPopulatingDemographicData;
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function afterPopulatingDemographicData(config,formConfig,data){
|
|
|
-
|
|
|
+function afterPopulatingDemographicData(data){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
formConfig.demographicData=data;
|
|
|
- print(config,"afterPopulatingDemographic");
|
|
|
- print(config,"Number of patients: "+formConfig.demographicData.rows.length);
|
|
|
+ print("afterPopulatingDemographic");
|
|
|
+ print("Number of patients: "+formConfig.demographicData.rows.length);
|
|
|
|
|
|
+ fcontinue2();
|
|
|
|
|
|
- let qconfig=new Object();
|
|
|
+}
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="crfEditors";
|
|
|
- qconfig.success=function(data){afterPopulatingCrfEditors(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
+function fcontinue2(){
|
|
|
|
|
|
-function afterPopulatingCrfEditors(config,formConfig,data){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
+ let dataForms=formConfig.dataForms.rows;
|
|
|
|
|
|
- formConfig.crfEditors=data;
|
|
|
- print(config,"afterPopulatingCrfEditors");
|
|
|
- print(config,"Number of CRF editors: "+formConfig.crfEditors.rows.length);
|
|
|
-
|
|
|
-
|
|
|
- let qconfig=new Object();
|
|
|
-
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="crfReviewers";
|
|
|
- qconfig.success=function(data){afterPopulatingCrfReviewers(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
-
|
|
|
-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();
|
|
|
-
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="crfManagers";
|
|
|
- qconfig.success=function(data){afterPopulatingCrfManagers(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
+ formConfig.table=config.document.createElement("table");
|
|
|
+ config.document.getElementById(config.div).appendChild(formConfig.table);
|
|
|
|
|
|
-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();
|
|
|
+ let accessModeColumn=getMode()+'Status';
|
|
|
+ print('accessModeColumn '+accessModeColumn);
|
|
|
+ let creatorModeColumn=getMode()+'Creator';
|
|
|
|
|
|
- qconfig.schemaName="lists";
|
|
|
- qconfig.queryName="FormStatus";
|
|
|
- qconfig.success=function(data){afterPopulatingFormStatus(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
|
|
|
-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);
|
|
|
+ //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;
|
|
|
|
|
|
- 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";
|
|
|
+ for (let i=0;i<users.length;i++){
|
|
|
+ if (users[i].UserId!=currentUserId) continue;
|
|
|
+ currentUser=users[i];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
+ let fList=config.role+'s';
|
|
|
+ let fRows=config.formConfig[fList].rows;
|
|
|
+ //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]);
|
|
|
}
|
|
|
-
|
|
|
- //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;
|
|
|
- }
|
|
|
- print(config,"reviewer "+reviewer);
|
|
|
- if (reviewer==0) return;
|
|
|
+ if (currentUserRoles.length==0){
|
|
|
+ printMessage('User '+currentUser.DisplayName+" can't act as "+config.role);
|
|
|
+ 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));
|
|
|
-
|
|
|
|
|
|
+ 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]);
|
|
|
+ }
|
|
|
}
|
|
|
- qconfig.success=function(data){afterPopulatingEntries(config,formConfig,data)};
|
|
|
- LABKEY.Query.selectRows(qconfig);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-function afterPopulatingEntries(config,formConfig,data){
|
|
|
-
|
|
|
- formConfig.formData=data;
|
|
|
- let dataForms=formConfig.dataForms;
|
|
|
- let table=formConfig.table;
|
|
|
- print(config,"afterPopulatingEntries");
|
|
|
-
|
|
|
- print(config,"Forms: "+dataForms.rows.length);
|
|
|
- print(config,"InProgress: "+data.rows.length);
|
|
|
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ msg+=')';
|
|
|
+ printMessage(msg);
|
|
|
|
|
|
-
|
|
|
- for (let i=0;i<dataForms.rows.length; i++){
|
|
|
-
|
|
|
- let formKey=dataForms.rows[i].Key;
|
|
|
- print(config,"Key["+i+"]: "+formKey);
|
|
|
+ for (let i=0;i<dataForms.length;i++){
|
|
|
+ let qForm=dataForms[i];
|
|
|
+ let formKey=qForm.Key;
|
|
|
|
|
|
//figure out master query name
|
|
|
let masterQuery="NONE";
|
|
|
- let mID=dataForms.rows[i].masterQuery;
|
|
|
- print(config,"Setting master query: "+mID);
|
|
|
+ let mID=qForm.masterQuery;
|
|
|
for (let i2=0;i2<formConfig.inputLists.rows.length;i2++){
|
|
|
//queryName
|
|
|
if (formConfig.inputLists.rows[i2].Key!=mID)
|
|
|
continue;
|
|
|
|
|
|
masterQuery=formConfig.inputLists.rows[i2].queryName;
|
|
|
- print(config,"Setting master query "+masterQuery);
|
|
|
+ print("Setting master query "+masterQuery);
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- let row=table.insertRow(i);
|
|
|
- let formName=dataForms.rows[i].formName;
|
|
|
+ //add row for each form
|
|
|
+ let row=formConfig.table.insertRow(i);
|
|
|
+ let formName=qForm.formName;
|
|
|
+ print("["+i+"/"+formKey+']: '+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);
|
|
|
+ let formStatus=qForm[accessModeColumn];
|
|
|
+ print('target formStatus '+formStatus);
|
|
|
+
|
|
|
+ for (let j=0;j<fEntries.length;j++){
|
|
|
+ let entry=fEntries[j];
|
|
|
+ let formId=entry.Form;
|
|
|
+ //print("Row["+j+"] formId: "+formId);
|
|
|
if (formId!=formKey)
|
|
|
continue;
|
|
|
+ //should we consider this form
|
|
|
+
|
|
|
+ if (entry.FormStatus!=formStatus){
|
|
|
+ //print('Form status mismatch :'+entry.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;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 +367,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;
|
|
@@ -310,13 +386,13 @@ 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);
|
|
|
+ print('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);}
|
|
|
+ qconfig.success=function(data){setPatientId(data,fp3.id);}
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
fp3.classList.add("center");
|
|
@@ -327,16 +403,18 @@ 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 formsa
|
|
|
+ if (qForm[creatorModeColumn]!='TRUE') continue;
|
|
|
|
|
|
let fbox=config.document.createElement("div");
|
|
|
fbox.classList.add("box","red");
|
|
@@ -357,7 +435,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,20 +444,25 @@ function afterPopulatingEntries(config,formConfig,data){
|
|
|
|
|
|
}
|
|
|
|
|
|
-function setPatientId(config,formConfig,data,id){
|
|
|
+function setPatientId(data,id){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
+
|
|
|
if (data.rows.length==0) return;
|
|
|
|
|
|
+ //every masterQuery must have participantCode
|
|
|
let participantCode=data.rows[0].participantCode;
|
|
|
let participantField=formConfig.studyData.rows[0].SubjectColumnName;
|
|
|
|
|
|
-
|
|
|
- print(config,'participantCode: '+participantCode);
|
|
|
- print(config,'participantField: '+participantCode);
|
|
|
+ print('setPatientId: '+data.queryName);
|
|
|
+ print('participantCode: '+participantCode);
|
|
|
+ print('participantField: '+participantField);
|
|
|
+ //equates to registration
|
|
|
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);
|
|
|
+ print('Comparing to: '+key);
|
|
|
if (key!=participantCode) continue;
|
|
|
+ print('Setting: ');
|
|
|
let participantId=entry[participantField];
|
|
|
config.document.getElementById(id).innerHTML=participantId;
|
|
|
break;
|
|
@@ -388,24 +471,16 @@ function setPatientId(config,formConfig,data,id){
|
|
|
|
|
|
}
|
|
|
|
|
|
-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;
|
|
|
+function openForm(crfEntry){
|
|
|
+ let formConfig=config.formConfig;
|
|
|
+ let crfRef=crfEntry.entryId;
|
|
|
+
|
|
|
+ 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 +489,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,12 +499,9 @@ 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"],
|
|
@@ -437,14 +509,16 @@ function openForm(config,formConfig,crfRef, crfEntry){
|
|
|
// 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);
|
|
|
+ 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();
|
|
@@ -461,20 +535,21 @@ function createForm(config,formConfig,formId){
|
|
|
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);
|
|
|
+ print("Checking user "+formConfig.crfEditors.rows[i].User);
|
|
|
if (formConfig.crfEditors.rows[i].User!=crfEntry.UserId) continue;
|
|
|
- print(config,"Found user");
|
|
|
+ print("Found user");
|
|
|
crfEntry.Site=formConfig.crfEditors.rows[i].Site;
|
|
|
- print(config,"Setting site to id="+crfEntry.Site);
|
|
|
+ print("Setting site to id="+crfEntry.Site);
|
|
|
break;
|
|
|
}
|
|
|
//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);
|
|
|
}
|