123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- //namespace
- var formGenerator={};
- formGenerator.set=
- function(parentClass){
- this.parent=parentClass;
- }
- formGenerator.addFormGenerator=
- function(){
- //parentClass should provide config and print and getContainer
- let config=this.parent.config;
-
- let fName='[addFormGenerator]';
- this.parent.print(fName);
- //layout
- let table=config.document.createElement("table");
- table.className="t2";
- config.document.getElementById(config.div).appendChild(table);
- //this is a form manipulator
- let fgForm=new Object();
- fgForm.formSelect=this.addInputRow(table,'Select form',"select");
- fgForm.crfSelect=this.addInputRow(table,'Select CRF',"select");
- fgForm.comment=this.addInputRow(table,'Enter comment','text');
- fgForm.details=this.addInputRow(table,'Details','label');
- fgForm.warnings=this.addInputRow(table,'Warnings','label');
- fgForm.warnings.innerHTML='formGenerator version 2.1.0';
- this.addOption(fgForm.formSelect,'<Select>',-1);
- let formRows=config.formConfig.generateConfigData.rows;
- for (let i=0;i<formRows.length;i++){
- let formId=formRows[i]["formId"];
- let formName=this.getFormName(formId);
- this.parent.print(fName+' '+formRows[i]["formId"]+'/'+formName);
- this.addOption(fgForm.formSelect,formName,formId);
- }
- //callbacks should be called on copy of this
- let that=this;
- fgForm.formSelect.onchange=function(){that.updateIdList(fgForm);};
- fgForm.crfSelect.onchange=function(){that.updateLabel(fgForm);};
- fgForm.generateButton=this.addInputRow(table,'Generate Form','button');
- fgForm.generateButton.value="Generate Form";
- fgForm.generateButton.onclick=function(){that.createFormWithId(fgForm);};
-
- }
- formGenerator.insertRow=
- function(schemaName,queryName,row,cb=null,containerPath=null){
- let fName='[fgInsertRow]';
- this.parent.print(fName);
- //cb=function(data){....}
- let qconfig=new Object();
- if (containerPath)
- qconfig.containerPath=containerPath;
- qconfig.schemaName=schemaName;
- qconfig.queryName=queryName;
- qconfig.success=function(data){;};
- if (cb) qconfig.success=cb;
- qconfig.rows=[row];
- this.parent.print(fName+' qconfig '+qconfig);
- LABKEY.Query.insertRows(qconfig);
- }
- formGenerator.addInputRow=
- function(table,header,type){
- let config=this.parent.config;
- let fName='[addInputRow]';
- this.parent.print(fName);
- let row=table.insertRow();
- let cell=config.document.createElement('th');
- let text=config.document.createTextNode(header);
- cell.appendChild(text);
- row.appendChild(cell);
- let input=null;
-
- if (type=="select")
- input=config.document.createElement(type);
- if (type=="button"){
- input=config.document.createElement("input");
- input.type="button";
- }
- if (type=="text"){
- input=config.document.createElement('textarea');
- input.cols="65";
- input.rows="5";
- }
- if (type=="label")
- input=config.document.createElement(type);
- let cell1=row.insertCell();
- cell1.appendChild(input);
- return input;
- }
- formGenerator.getFormName=
- function(formId){
- let config=this.parent.config;
- let rows=config.formConfig.dataForms.rows;
- for (let i=0;i<rows.length;i++){
- if (rows[i]['Key']==formId){
- return rows[i]['formName'];
- }
- }
- return "NONE";
- }
- formGenerator.getQueryName=
- function(queryId){
- let config=this.parent.config;
- let rows=config.formConfig.inputLists.rows;
- for (let i=0;i<rows.length;i++){
- if (rows[i]['Key']==queryId){
- return rows[i]['queryName'];
- }
- }
- return "NONE";
- }
- formGenerator.getGCRow=
- function(formId){
- let config=this.parent.config;
- let formRows=config.formConfig.generateConfigData.rows;
- for (let i=0;i<formRows.length;i++){
- if (formRows[i]['formId']==formId){
- return formRows[i];
- }
- }
- return Object();
- }
- formGenerator.getCrfSelectRow=
- function(crfRef){
- let config=this.parent.config;
- let rows=config.formConfig.crfSelectRows;
- for (let i=0;i<rows.length;i++){
- if (rows[i]['crfRef']==crfRef)
- return rows[i];
- }
- return Object();
- }
- formGenerator.addOption=
- function(input,name,value){
- let config=this.parent.config;
- let opt=config.document.createElement("option");
- opt.text=name;
- opt.value=value;
- input.options[input.options.length]=opt;
- }
- formGenerator.clearOptions=
- function(input){
- for(let i = input.options.length; i >= 0; i--) {
- input.remove(i);
- }
- }
- formGenerator.createFormWithId=
- function(fgForm){
- //get form id and entry id from select and create form as above
- let fName='[createFormWithId]';
- this.parent.print(fName);
- let config=this.parent.config;
- let formId=fgForm.formSelect.options[fgForm.formSelect.selectedIndex].value;
- let crfRef=fgForm.crfSelect.options[fgForm.crfSelect.selectedIndex].text;
- let configRow=this.getGCRow(formId);
- let crfSelectRow=this.getCrfSelectRow(crfRef);
- let formConfig=config.formConfig;
- this.parent.print("Create form w/id "+formId);
-
- let crfEntry=new Object();
- crfEntry.entryId=Date.now();
- crfEntry["Date"]=new Date();
- crfEntry["View"]="[VIEW]";
- crfEntry['participantStudyId']=crfSelectRow['participantStudyId'];
- crfEntry['participantLocalId']=crfSelectRow['participantLocalId'];
- crfEntry.formStatus=configRow['formStatus'];//In progress
- //set other variables
- //requires studyData as part of formConfig
- let studyData=formConfig.studyData.rows[0];
- 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;
- crfEntry.Site=config.formConfig.currentSites[0].siteNumber;
- this.parent.print("Setting site to id="+crfEntry.Site);
- //from argument list
- crfEntry.Form=formId;
- crfEntry.parentCrf=crfRef;
-
- //
- //compose a reviewComments entry
- let reviewComment=new Object();
- reviewComment['submissionDate']=crfEntry['Date'];
- reviewComment['crfRef']=crfRef;
- //comment length
- let x=fgForm.comment.value;
- this.parent.print(fName+' comment length '+x.length);
- if (x.length==0){
- fgForm.warnings.innerHTML='Supply a comment';
- return;
- }
- reviewComment['reviewComment']=fgForm.comment.value;
- reviewComment['queryName']=configRow['queryId'];
- let crfStatus=new Object();
- crfStatus.entryId=crfEntry.entryId;
- crfStatus.submissionDate=new Date();
- crfStatus.FormStatus=crfEntry.formStatus;
- crfStatus.User=crfEntry.UserId;
- crfStatus.Form=crfEntry.Form;
- crfStatus.operator=config.role;
- crfStatus.action='createFormWithId';
- let that=this;
- let containerPath=this.parent.getContainer('data');
- let rd=function(data){that.redirect();};
- let pass1=function(data){that.insertRow('lists','crfStatus',crfStatus,rd,containerPath);};
- let pass=function(data){that.insertRow('lists','reviewComments',reviewComment,pass1,containerPath);};
- this.insertRow('lists','crfEntry',crfEntry,pass,this.parent.getContainer('data'));
- }
- formGenerator.updateIdList=
- function(fgForm){
- let fName='[updateIdList]';
- let formId=fgForm.formSelect.options[fgForm.formSelect.selectedIndex].value;
- this.parent.print(fName+' id '+formId);
- //remove old options
- this.clearOptions(fgForm.crfSelect);
- this.parent.print(fName+' options cleared');
- //get query associated with form
- let configRow=this.getGCRow(formId);
- let queryId=configRow['queryId'];
- this.parent.print(fName+' queryId '+queryId);
- if (!queryId || queryId<0)
- return;
- let qselect=new Object();
- qselect.containerPath=this.parent.getContainer('data');
- qselect.schemaName='lists';
- qselect.queryName=this.getQueryName(queryId);
- let that=this;
- qselect.success=function(data){that.updateIdListWithData(fgForm,data);};
- LABKEY.Query.selectRows(qselect);
- }
- formGenerator.updateIdListWithData=
- function(fgForm,data){
- let config=this.parent.config;
- let rows=data.rows;
- config.formConfig.crfSelectRows=data.rows;
- for (let i=0;i<rows.length;i++){
- this.addOption(fgForm.crfSelect,rows[i]['crfRef'],i);
- }
- let event=new Event('change');
- fgForm.crfSelect.dispatchEvent(event);
- }
- formGenerator.updateLabel=
- function(fgForm){
- let crfRef=fgForm.crfSelect.options[fgForm.crfSelect.selectedIndex].text;
- let crfSelectRow=this.getCrfSelectRow(crfRef);
- fgForm.details.innerHTML='Generating for Study:'+crfSelectRow['participantStudyId']+' / Local:'+crfSelectRow['participantLocalId'];
- }
- formGenerator.redirect=
- function(){
- let debug=false;
- let formUrl="begin";
- let params=new Object();
- params.name=formUrl;
- params.pageId="CRF";
- //points to crf container
- let containerPath=this.parent.getContainer('data');
-
- // This changes the page after building the URL.
- //Note that the wiki page destination name is set in params.
-
- var homeURL = LABKEY.ActionURL.buildURL(
- "project", formUrl , containerPath, params);
- this.parent.print("Redirecting to "+homeURL);
- if (debug) return;
- window.location = homeURL;
-
- }
|