Browse Source

Recent updates to NIX-CRF and associated participant view

Andrej Studen @ ONKO-NIX 4 years ago
parent
commit
542127619d

+ 7 - 6
views/approvedPortal.html

@@ -20,13 +20,14 @@ height:120px;
 }
 </style>
 
-<div id="formDiv"/>
+<div id="formDiv">
+</div>
 
-	<div id="debugDiv" style="display:none">
-		<textarea cols="95" rows="5" id="formStatus">
-			Hello
-		</textarea>
-	</div>
+<div id="debugDiv" style="display:block">
+	<h3>Debug notes</h3>
+	<textarea cols="95" rows="5" id="formStatus">
+	</textarea>
+</div>
 
 <script type "text/javascript">
 window.onload=init;

+ 8 - 6
views/formPortal.html

@@ -20,13 +20,15 @@ height:120px;
 }
 </style>
 
-<div id="formDiv"/>
+<div id="formDiv">
+</div>
+
+<div id="debugDiv" style="display:block">
+	<h3>Debug notes</h3>
+	<textarea cols="95" rows="5" id="formStatus">
+	</textarea>
+</div>
 
-	<div id="debugDiv" style="display:none">
-		<textarea cols="95" rows="5" id="formStatus">
-			Hello
-		</textarea>
-	</div>
 
 <script type "text/javascript">
 window.onload=init;

+ 33 - 0
views/participant.html

@@ -0,0 +1,33 @@
+<style type="text/css">
+table {margin-bottom:20px;table-layout:fixed; border-collapse:collapse;
+	border-spacing:10px}
+th {font-weight:bold}
+table.t1 {width:900px}
+
+</style>
+
+<div id="participant-view">
+	<table id="participantData" class="t1"></table>
+	<textarea id="PID" style="display:none"></textarea>
+</div>
+
+<script type="text/javascript">
+
+let config=new Object();
+config.id=LABKEY.ActionURL.getParameter('participantId');
+config.document=document;
+config.debugId="PID";
+print(config,"Test");
+config.table=config.document.getElementById("participantData");
+config.setup="participantView";
+config.headerStyle=new Object();
+config.headerStyle.background="#d0e8f8";
+config.headerStyle.borderBottom="thin solid";
+config.missingStyle=new Object();
+config.missingStyle.background="#f8e8d0";
+
+buildTable(config);
+print(config,"Test: "+config.table);
+print(config,"Participant: "+id);
+
+</script>

+ 6 - 0
views/participant.view.xml

@@ -0,0 +1,6 @@
+<view xmlns="http://labkey.org/data/xml/view" title="Participant view">
+	<dependencies>
+			<dependency path="crf/crfParticipant.js"/>
+	</dependencies>
+</view>
+<!-- need to restart labkey to add new files -->

+ 7 - 6
views/reviewPortal.html

@@ -20,13 +20,14 @@ height:120px;
 }
 </style>
 
-<div id="formDiv"/>
+<div id="formDiv">
+</div>
 
-	<div id="debugDiv" style="display:none">
-		<textarea cols="95" rows="5" id="formStatus">
-			Hello
-		</textarea>
-	</div>
+<div id="debugDiv" style="display:block">
+	<h3> Debug notes</h3>
+	<textarea cols="95" rows="5" id="formStatus">
+	</textarea>
+</div>
 
 <script type "text/javascript">
 window.onload=init;

+ 2 - 2
views/visit.html

@@ -50,7 +50,7 @@ function init(){
 	
 	//update this to pick crfRef from url
 	let crfRef=searchParams.get('entryId');
-	let formSetupQuery=searchParams.get('formSetupQuery');	
+	//let formSetupQuery=searchParams.get('formSetupQuery');	
 	let registrationQueryId=searchParams.get('registrationQueryId');
 	document.getElementById("crfRefId").innerHTML=crfRef;
 
@@ -71,7 +71,7 @@ function init(){
 	config.debugId="formStatus";
 	config.crfRefId="crfRefId";
 	config.containerPath= LABKEY.ActionURL.getContainer();
-	config.setupQueryName=formSetupQuery;
+	//config.setupQueryName=formSetupQuery;
 	config.formName=searchParams.get("formName");
 	config.formId=searchParams.get("formId");
 	config.submitReportId="submitReport";

+ 217 - 0
web/crf/crfParticipant.js

@@ -0,0 +1,217 @@
+function print(config,msg){
+	let el=config.document.getElementById(config.debugId);
+	if (el===null) {
+		//alert("Debug section not initialized. Message: "+msg);
+		return;
+	}
+	el.value+="\n"+msg;
+}
+
+function clear(config){
+	let el=config.document.getElementById(config.debugId);
+	if (el===null) {
+		//alert("Debug section not initialized");
+		return;
+	}
+	config.document.getElementById(config.debugId).value="";
+}
+
+function createRowSelector(schemaName,queryName){
+	let selectRows=new Object();
+	selectRows.schemaName=schemaName;
+	selectRows.queryName=queryName;
+	return selectRows;
+}
+
+
+function buildTable(config){
+	//print(config,'buildTable');
+	addRow(config,'ParticipantId',[config.id]);
+	let selectRows=createRowSelector('lists',config.setup);
+	selectRows.success=function (data){afterSetup(config,data);}
+	LABKEY.Query.selectRows(selectRows);
+}
+
+function afterSetup(config,data){
+	//print(config,'afterSetup ['+data.rows.length+']');
+	config.setupRows=data.rows;
+	let selectRows=createRowSelector('study','DataSets');
+	selectRows.success=function (data){afterDatasets(config,data);}
+	LABKEY.Query.selectRows(selectRows);
+}
+
+//build a local copy of enum's
+function afterDatasets(config,data){
+	//print(config,'afterDatasets ['+data.rows.length+']');
+	config.datasets=data.rows;
+	//debug mode -> jump ahead
+	//afterEnumValues(config);
+	let selectRows=createRowSelector('ListManager','ListManager');
+	selectRows.filterArray=[LABKEY.Filter.create('Name','enum',
+		LABKEY.Filter.Types.STARTS_WITH)];
+	selectRows.success=function (data){afterEnums(config,data);}
+	LABKEY.Query.selectRows(selectRows);
+	//print(config,'enums');
+}
+
+//parse list of lists; get values
+function afterEnums(config,data){
+	//print(config,'afterEnums: '+data.rows.length);
+	config.enums=data.rows;
+	config.enumValues=new Object();
+	for (row of config.enums){
+		//print(config,'afterEnums: '+row.Name);
+		config.enumValues[row.Name]=new Object();
+	}
+	for (lst in config.enumValues){
+		let selectRows=createRowSelector('lists',lst);
+		selectRows.success=function (data){addEnumValues(config,data);}
+		LABKEY.Query.selectRows(selectRows);
+	}
+}
+
+function addEnumValues(config, data){
+	//find out the variable name
+	//
+	let varName="NONE";
+	for (field of data.metaData.fields){
+		if (field.name=="Key")
+			continue;
+		varName=field.name;
+	}
+
+	//print(config,'addEnumValues ['+data.queryName+']: '+varName);
+
+	config.enumValues[data.queryName].map=new Object();
+	for (row of data.rows)
+		config.enumValues[data.queryName].map[row["Key"]]=row[varName];
+	waitForEnumCompleted(config);
+
+}
+
+function waitForEnumCompleted(config){
+	for (lst in config.enumValues){
+		if (!("map" in config.enumValues[lst]))
+			return;
+		//print(config,'['+lst+']: '+
+		//	Object.keys(config.enumValues[lst].map).length);
+	}
+	//print(config,"Enum completed");
+	afterEnumValues(config);
+	
+
+}
+
+function datasetName(config,id){
+	for (let i=0;i<config.datasets.length;i++){
+		if (config.datasets[i].DataSetId==id)
+			return config.datasets[i].Name;
+	}
+	return "NONE";
+}
+
+function afterEnumValues(config){
+	
+	config.entries=new Object();
+	for (let i=0;i<config.setupRows.length;i++){
+		//print(config,'['+i+']: '+config.setupRows[i].dataset);
+		let queryName=datasetName(config,config.setupRows[i].dataset);
+
+		//print(config,"Adding dataset: "+queryName);
+		config.entries[queryName]=new Object();
+		config.setupRows[i].datasetName=queryName;
+	}
+	
+	for (let ds in config.entries){
+		//print(config,"Querying dataset: "+ds);
+		let selectRows=createRowSelector('study',ds);
+		selectRows.filterArray=[LABKEY.Filter.create('ParticipantId',config.id)];
+		selectRows.success=function (data){afterQuery(config,data);}
+		LABKEY.Query.selectRows(selectRows);
+	}
+	//print(config,'afterDatasets: Done');
+}
+
+function afterQuery(config,data){
+	//print(config,'afterQuery ['+data.queryName+']: '+data.rows.length);
+	config.entries[data.queryName].rows=data.rows;
+	config.entries[data.queryName].metaData=data.metaData;
+	waitForAll(config);
+}
+
+function waitForAll(config){
+	//print(config,'waitForAll');
+	for (let ds in config.entries){
+		if (!("rows" in config.entries[ds])) 
+			return;
+		//print(config,ds+': '+config.entries[ds].rows.length);
+	}
+	//only get here if all rows are set
+	//print(config,'waitForAll: Done');
+	updateValues(config);
+}
+
+function getField(fields,name){
+	for (field of fields){
+		if (field.name==name) 
+			return field;
+	}
+	return undefined;
+}
+
+
+function updateValues(config){
+	//print(config,'updateValues');
+	for (let row of config.setupRows){
+		let ds=row.datasetName;
+		let vars=row.variables.split(';');
+		//print(config,'Dataset: '+row.datasetName+' Vars: '+vars);
+		if (config.entries[ds].rows.length==0){
+			addRow(config,ds,["no events"],config.missingStyle);
+			continue;
+		}
+		addRow(config,ds,vars,config.headerStyle);
+		let md=config.entries[ds].metaData;
+		for (let dataRow of config.entries[ds].rows){
+			let displayRow=new Array();
+			for (let v of vars){
+				//print(config,ds+'['+v+']: '+ dataRow[v]);
+				//check if it is a lookup
+				let field=getField(md.fields,v);
+				let value=dataRow[v];
+				if ("lookup" in field){
+					//print(config,"Lookup: "+field.lookup.table);
+					let lut=config.enumValues[field.lookup.table];
+					value=lut.map[value];
+				}
+				displayRow.push(value);
+			}
+			addRow(config,'',displayRow);
+		}
+	}
+	E
+}	
+
+function setStyle(object,style){
+	if (style!=undefined)
+		for (attr in style)
+			object.style[attr]=style[attr];
+}
+
+function addRow(config,header,values,style){
+	//let headerColor="#d0e8f8";
+	let row=config.table.insertRow();
+	let cell=config.document.createElement('th');
+	setStyle(cell,style);
+	row.appendChild(cell);
+	let cellData=config.document.createTextNode(header);
+	//print(config,'Adding header '+header);
+	cell.appendChild(cellData);
+	//new cell
+	for (v of values){
+		cell=row.insertCell();
+		setStyle(cell,style);
+		cellData=config.document.createTextNode(v);
+		cell.appendChild(cellData);
+	}
+}

+ 1 - 0
web/crf/crfVisit.js

@@ -1074,6 +1074,7 @@ function afterStudyData(config,configUpload,data){
 		configUpload.queries[configUpload.queryId].queryStatus="DONE";
 		configUpload.queryId+=1;
 		copyToDataset(config,configUpload);
+		return;
 	}
 	
 

+ 13 - 6
web/crf/formPortal.js

@@ -6,6 +6,13 @@ function clear(config){
 	config.document.getElementById(config.debugArea).value="";
 }
 
+function getMode(config){
+	if ("reviewMode" in config){
+		return config.reviewMode;
+	}
+	return "EDIT";
+}
+
 function userName(formConfig,id){
 	for (let i=0;i<formConfig.users.rows.length;i++){
 		if (formConfig.users.rows[i].UserId!=id)
@@ -16,7 +23,7 @@ function userName(formConfig,id){
 }
 
 function generateFormArray(config){
-	print(config,"generateFormArray");
+	print(config,"generateFormArray "+getMode(config));
 
 	let formConfig=new Object();
 
@@ -380,12 +387,12 @@ function openForm(config,formConfig,crfRef, crfEntry){
 	if (formEntry==undefined) return;
 
 	//select between review and view
-	let formUrl=formEntry["formUrl"];
-	if ("reviewMode" in config) formUrl=formEntry["reviewFormUrl"];
-	print(config,"Setting url "+formUrl);
+	//let formUrl=formEntry["formUrl"];
+	//if ("reviewMode" in config) formUrl=formEntry["reviewFormUrl"];
+	//print(config,"Setting url "+formUrl);
 
 	//direct all to the same html
-	formUrl="visit";
+	let formUrl="visit";
 
 	reviewMode="EDIT";
 	if ("reviewMode" in config) reviewMode=config.reviewMode;
@@ -394,13 +401,13 @@ function openForm(config,formConfig,crfRef, crfEntry){
 		// The destination wiki page. The name of this parameter is not arbitrary.
 		"userid": crfEntry.UserId, 
 		"entryId": crfRef,
-		"formSetupQuery":formEntry["setupQuery"],
 		"registrationQueryId":formEntry["masterQuery"],
 		"reviewMode":reviewMode,
 		"formId":formId,
 		"formName":formEntry["formName"]
 	};
 
+	//"formSetupQuery":formEntry["setupQuery"],
 	let containerPath= LABKEY.ActionURL.getContainer();
         // This changes the page after building the URL. 
 	//Note that the wiki page destination name is set in params.