//loadFile is in fileManager.js var crfReviewSection={}; crfReviewSection.set= function(parentClass){ if ("parent" in this) return; this.parent=parentClass; } crfReviewSection.generateErrorMessage= function (id,listName,msg){ this.parent.print('generateErrorMessage:'); let eid=listName+"_errorMsg"; let el=config.document.getElementById(eid); if (el===null){ el=config.document.createElement("p"); config.document.getElementById(id).appendChild(el); } el.innerHTML=msg; } crfReviewSection.clearErrorMessage= function(listName){ let eid=listName+"_errorMsg"; let el=config.document.getElementById(eid); if (el===null) return; el.remove(); } crfReviewSection.generateSection= function(listName,id,callback){ let that=this; let action=function(){that.fcontinue(listName,id,callback);}; LABKEY.requiresScript(["crfTecant/fileManager.js"],action); } crfReviewSection.fcontinue= function(listName,id,callback){ //callback should be generateReviewSectionCB and it takes no arguments this.parent.print("generateReviewSection"); let config=this.parent.config; //need base path config.loadFileConfig=new Object(); config.loadFileConfig.cb=callback; config.loadFileConfig.id=id; config.loadFileConfig.url=fileManager.getBasePath()+'/@files/reportSetup/'+listName+'.json'; fileManager.loadFile(); //load file and continue in the next function } crfReviewSection.getParticipantCode= function(pid){ let filters=[LABKEY.Filter.create("crfRef",this.parent.getCRFref())]; let config=this.parent.config; let mfId=config.formConfig.form['masterQuery']; let queryName=config.formConfig.queryMap[mfId]; let that=this; pid.afterId=function(id){that.setParticipantCode(id);}; pid.participantField=config.formConfig.studyData["SubjectColumnName"]; let cb=function(data){that.afterRegistration(pid,data);} //untested this.parent.selectRows('lists',queryName,filters,cb,this.parent.getContainer('data')); } crfReviewSection.visitCodeFromVisitId= function(visitId){ if (visitId<0) return "NONE"; let project=this.parent.getContainer('data'); this.parent.print('visitCodeFromVisitId: '+project.search('retro')); if (project.search('retro')>-1) visitId-=1; return 'VISIT_'+visitId.toString(); } crfReviewSection.replaceSlash= function(x){ return x.replace(/\//,'_'); } crfReviewSection.setParticipantCode= function(pid){ let fName='[setParticipantCode]'; let rows=pid.registration.rows; let config=this.parent.config; //pick from study let participantField=config.formConfig.studyData["SubjectColumnName"]; if (rows.length==1){ this.parent.print(fName+': '+rows[0][participantField]+'/'+rows[0].visitId); let visitCode=this.visitCodeFromVisitId(rows[0].visitId); this.parent.print('setParticipantCode: '+pid.participantId+'/'+visitCode); pid.participantCode=this.replaceSlash(pid.participantId); pid.visitCode=visitCode; } this.generateReviewSection2(pid); } crfReviewSection.CB= function(){ let config=this.parent.config; let listName=config.loadFileConfig.listName; let id=config.loadFileConfig.id; this.parent.clearErrorMessage(listName); let pid=new Object(); pid.participantCode="NONE"; pid.visitCode="NONE"; this.getParticipantCode(pid); this.parent.print('Get participant code sent'); //involves database search, continue after callback } crfReviewSection.getValueFromElement= function(id,defaultValue){ let config=this.parent.config; let e=config.document.getElementById(id); if (e!=null){ defaultValue=e.innerHTML; } return defaultValue; } crfReviewSection.pickParticipantCodeFromPage= function(){ let pid=new Object(); pid.participantCode=this.getValueFromElement("participantCode","NIX-LJU-D2002-IRAE-A000"); pid.visitCode=this.getValueFromElement("visitCode","VISIT_1"); this.generateReviewSection2(pid); } crfReviewSection.patternReplace= function(src,replacements,values){ for (rep in replacements){ let txt1=src.replace(new RegExp(rep),values[replacements[rep]]); src=txt1; } return src; } crfReviewSection.plotImage= function(cell,k,row,rowVariable,obj,pid){ let config=this.parent.config; let baseDir=this.patternReplace(obj.imageDir,obj.replacements,pid); this.parent.print('Base dir: '+pid.basePath); pid[obj.variable]=obj.values[k]; cell.id=pid[obj.variable]+"_"+rowVariable+pid[rowVariable]; let img=null; let imgId=cell.id+'_img_'; img=config.document.getElementById(imgId); if (img===null){ img=config.document.createElement('img'); img.id=imgId; cell.appendChild(img); } let imgSrc=patternReplace(obj.file,obj.replacements,pid); this.parent.print('Image: '+imgSrc); let imagePath=pid.basePath+'/'+baseDir+'/'+imgSrc; img.src=imagePath; img.width="300"; } crfReviewSection.showReport= function(cell,k,row,rowVariable,obj,pid){ cell.width="300px"; cell.id='report_'+obj.values[k]+"_"+rowVariable+pid[rowVariable]; let reportConfig=new Object(); reportConfig.partName="Report"; reportConfig.renderTo=cell.id; //reportConfig.showFrame=false; //reportConfig.width="300"; reportConfig.frame="none"; reportConfig.partConfig=new Object(); reportConfig.partConfig.width="300"; reportConfig.partConfig.title="R Report"; reportConfig.partConfig.reportName=obj.values[k]; for (f in obj.parameters){ reportConfig.partConfig[f]=pid[f]; } reportConfig.partConfig.showSection="myscatterplot"; let reportWebPartRenderer = new LABKEY.WebPart(reportConfig); this.parent.print('Render to: '+reportConfig.renderTo); reportWebPartRenderer.render(); } crfReviewSection.showProbability= function(cell,k,row,rowSetup,j,obj,pid){ this.parent.print('showProbability: '+rowSetup); let rowVariable=rowSetup.variable; cell.id='prob_'+obj.values[k]+"_"+rowVariable+pid[rowVariable]; let probDensity=new Object(); probDensity.mean=rowSetup.mean[j]; probDensity.sigma=rowSetup.sigma[j]; this.parent.print('showProbability: mean '+probDensity.mean+' sigma '+probDensity.sigma); probDensity.func=obj.values[k]; probDensity.organCode=pid.organCode; pid[obj.variable]=rowSetup[obj.variable][j]; probDensity.percentile=pid.percentile; let selectRows=new Object(); selectRows.queryName=obj.queryName; selectRows.schemaName="study"; selectRows.filterArray=[]; selectRows.containerPath=getContainer('data'); for (let f in obj.filters){ selectRows.filterArray.push( LABKEY.Filter.create(f,pid[obj.filters[f]])); this.parent.print('Filter ['+f+']: '+pid[obj.filters[f]]); } selectRows.success=function(data){ this.drawProbability(data,cell,obj,pid,probDensity);} LABKEY.Query.selectRows(selectRows); } crfReviewSection.erf= function(x){ let fx=[0,0.02,0.04,0.06,0.08,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9, 1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2, 2.1,2.2,2.3,2.4,2.5,3,3.5]; let fy=[0,0.222702589,0.328626759,0.428392355,0.520499878, 0.603856091,0.677801194,0.742100965,0.796908212, 0.842700793,0.880205070,0.910313978,0.934007945, 0.952285120,0.966105146,0.976348383, 0.983790459,0.989090502,0.992790429,0.995322265, 0.997020533,0.998137154,0.998856823,0.999311486, 0.999593048,0.999977910,0.999999257]; let n=32; let i0=n-1; for (let i=1;ifx[i]) continue; i0=i-1; break; } let fval=1; if (i0obj.intervals.zlimits[i]) continue; color=obj.intervals.colors[i-1]; break; } let fboxId=cell.id+'_fbox_'; let fbox=config.document.getElementById(fboxId); if (fbox===null){ fbox=config.document.createElement("div"); fbox.id=fboxId; cell.appendChild(fbox); } fbox.style.backgroundColor=color; fbox.style.width="180px"; fbox.style.height="180px"; this.parent.print('organCode '+probDensity.organCode); let organName="Lung"; if (probDensity.organCode==4){ organName="Thyroid"; } if (probDensity.organCode==5){ organName="Bowel"; } this.setLine(fbox,'_fp4_',organName,"16px"); this.setLine(fbox,'_fp_',val.toPrecision(3),"25px"); this.setLine(fbox,'_fp1_',"SUV("+probDensity.percentile+"%)","16px"); this.setLine(fbox,'_fp2_',fzx.toPrecision(3),"25px"); this.setLine(fbox,'_fp3_',"z-value","16px"); } crfReviewSection.generateReviewSection2= function(pid){ let config=this.parent.config; let listName=config.loadFileConfig.listName; let id=config.loadFileConfig.id; this.parent.print('generateReviewSection2: '+pid.participantCode+'/'+ pid.visitCode); if (pid.participantCode=="NONE" || pid.visitCode=="NONE"){ this.generateErrorMessage(id,listName, "ParticipantId/visitId not set"); return; } this.parent.print('JSON: '+config.loadFileConfig.json); let json=config.loadFileConfig.json; let nrows=json.rows.values.length; let ncol=json.columns.length; pid.basePath=fileManager.getBasePath()+"/@files"; let el=config.document.getElementById(id); let tableId=id+'_Table'; let table=config.document.getElementById(tableId); if (table==null){ table=config.document.createElement('table'); table.id=tableId; el.appendChild(table); } table.style.tableLayout="fixed"; table.style.columnWidth="300px"; for (let i=0;i>>>>>>>>>>>>>end of reviewSection(REPORT) crfReviewSection.afterRegistration= function(data,fc){ let fName='[afterRegistration/'+data.queryName+']'; this.parent.print(fName+": rows:"+data.rows.length); fc.registration=data; let registrationData=fc.registration; this.parent.clearErr(); if (registrationData.rows.length!=1){ let msg=fName+": ERROR: Found "+registrationData.rows.length; msg+=" registration entries for crfrefid "+this.parent.getCRFref(); this.parent.print(msg); fc.afterId(fc); return; } this.parent.print(fName+'registration participant field: '+fc.participantField); fc.participantId=registrationData.rows[0][fc.participantField]; //could be a lookup field (particularly for studies) this.parent.print('ID: '+fc.participantId); let fields=registrationData.metaData.fields; let field="NONE"; for (f in fields){ if (fields[f]["name"]==fc.participantField) field=fields[f]; } if ("lookup" in field){ let pid=fc.participantId; this.parent.print("Using lookup for participantId: "+pid); let lookup=field["lookup"]; this.parent.print("Lookup: ["+lookup.schemaName+','+lookup.queryName+']'); //load lookup let that=this; let cb=function(data){that.afterRegistrationLookup(data,lookup.displayColumn,fc)}; let filters=[LABKEY.Filter.create(lookup.keyColumn,pid)]; this.parent.selectRows(lookup.schemaName,lookup.queryName,filters,cb,lookup.containerPath); } else{ //afterParticipantId(configUpload); fc.afterId(fc); } } crfReviewSection.afterRegistrationLookup= function(data,displayColumn,fc){ this.parent.print("afterRegistrationLookup"); let entry=data.rows[0]; fc.participantId=entry[displayColumn]; this.parent.print('Setting to '+fc.participantId); fc.afterId(fc); //afterParticipantId(configUpload); }