All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webclient.js-i2b2.cells.CRC.CRC_ctrlr_QryStatus.js Maven / Gradle / Ivy

/**
 * @projectDescription	The Asynchronous Query Status controller (GUI-only controller).
 * @inherits 	i2b2.CRC.ctrlr
 * @namespace	i2b2.CRC.ctrlr.QueryStatus
 * @author		Nick Benik, Griffin Weber MD PhD
 * @version 	1.0
 * ----------------------------------------------------------------------------------------
 * updated 8-10-09: Initial Creation [Nick Benik] 
 */

i2b2.CRC.ctrlr.QueryStatus = function(dispDIV) { this.dispDIV = dispDIV; };

i2b2.CRC.ctrlr.QueryStatus._GetTitle = function(resultType, oRecord, oXML) {
	var title = "";
	switch (resultType) {
		case "PATIENT_ENCOUNTER_SET":
			// use given title if it exist otherwise generate a title
			try {
				var t = i2b2.h.XPath(oXML,'self::query_result_instance/description')[0].firstChild.nodeValue;
			} catch(e) {
				var t = null;
			}
			if (!t) { t = "Encounter Set"; }
			// create the title using shrine setting
			if (oRecord.size >= 10) {
				if (i2b2.PM.model.isObfuscated) {
					title = t+" - "+oRecord.size+"±"+i2b2.UI.cfg.obfuscatedDisplayNumber.toString()+" encounters";
				} else {
					title = t; //+" - "+oRecord.size+" encounters";
				}
			} else {
				if (i2b2.PM.model.isObfuscated) {
					title = t+" - 10 encounters or less";
				} else {
					title = t; //+" - "+oRecord.size+" encounters";
				}
			}
			break;		
		case "PATIENTSET":
			// use given title if it exist otherwise generate a title
			try {
				var t = i2b2.h.XPath(oXML,'self::query_result_instance/description')[0].firstChild.nodeValue;
			} catch(e) {
				var t = null;
			}
			if (!t) { t = "Patient Set"; }
			// create the title using shrine setting
			if (oRecord.size >= 10) {
				if (i2b2.PM.model.isObfuscated) {
					title = t+" - "+oRecord.size+"±"+i2b2.UI.cfg.obfuscatedDisplayNumber.toString()+" patients";
				} else {
					title = t; //+" - "+oRecord.size+" patients";
				}
			} else {
				if (i2b2.PM.model.isObfuscated) {
					title = t+" - 10 patients or less";
				} else {
					title = t; //+" - "+oRecord.size+" patients";
				}
			}
			break;
		case "PATIENT_COUNT_XML":
			// use given title if it exist otherwise generate a title
			try {
				var t = i2b2.h.XPath(oXML,'self::query_result_instance/description')[0].firstChild.nodeValue;
			} catch(e) {
				var t = null;
			}
			if (!t) { t="Patient Count"; }
			// create the title using shrine setting
			if (oRecord.size >= 10) {
				if (i2b2.PM.model.isObfuscated) {
					title = t+" - "+oRecord.size+"±"+i2b2.UI.cfg.obfuscatedDisplayNumber.toString()+" patients";
				} else {
					title = t+" - "+oRecord.size+" patients";
				}
			} else {
				if (i2b2.PM.model.isObfuscated) {
					title = t+" - 10 patients or less";
				} else {
					title = t+" - "+oRecord.size+" patients";
				}
			}
			break;
		default : 
			try {
				title = i2b2.h.XPath(oXML,'self::query_result_instance/query_result_type/description')[0].firstChild.nodeValue;
			} catch(e) {
			}		
			break;
	}

	return title;
};


function trim(sString)
{
while (sString.substring(0,1) == '\n')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == '\n')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
} 

i2b2.CRC.ctrlr.QueryStatus.prototype = function() {
	var private_singleton_isRunning = false;
	var private_startTime = false; 
	var private_refreshInterrupt = false;
		
	function private_pollStatus() {
		var self = i2b2.CRC.ctrlr.currentQueryStatus;
		// this is a private function that is used by all QueryStatus object instances to check their status
		// callback processor to check the Query Instance
		var scopedCallbackQI = new i2b2_scopedCallback();
		scopedCallbackQI.scope = self;
		scopedCallbackQI.callback = function(results) {
			if (results.error) {
				alert(results.errorMsg);
				return;
			} else {
				// find our query instance
				var qi_list = results.refXML.getElementsByTagName('query_instance');
				var l = qi_list.length;
				for (var i=0; i" + description + "
"; // Query Report BG sCompiledResultsTest += description + '\n'; //snm0 } var crc_xml = results.refXML.getElementsByTagName('crc_xml_result'); l = crc_xml.length; for (var i=0; i" + params[i2].getAttribute("column") + ": " + value + ""; //Query Report BG sCompiledResultsTest += params[i2].getAttribute("column").substring(0,20) + " : " + value + "\n"; //snm0 } var ri_id = i2b2.h.XPath(temp, 'descendant-or-self::result_instance_id')[0].firstChild.nodeValue; } //alert(sCompiledResultsTest); //snm0 i2b2.CRC.view.graphs.createGraphs("infoQueryStatusChart", sCompiledResultsTest, i2b2.CRC.view.graphs.bIsSHRINE); if (i2b2.CRC.view.graphs.bisGTIE8) i2b2.CRC.view.status.selectTab('graphs'); //self.dispDIV.innerHTML += this.dispMsg; } } var self = i2b2.CRC.ctrlr.currentQueryStatus; // this private function refreshes the display DIV var d = new Date(); var t = Math.floor((d.getTime() - private_startTime)/100)/10; var s = t.toString(); if (s.indexOf('.') < 0) { s += '.0'; } if (private_singleton_isRunning) { self.dispDIV.innerHTML = '
Running Query: "'+self.QM.name+'"
'; // display the current run duration self.dispDIV.innerHTML += '
['+s+' secs]
'; } else { self.dispDIV.innerHTML = '
Finished Query: "'+self.QM.name+'"
'; self.dispDIV.innerHTML += '
['+s+' secs]
'; //Query Report BG if((!Object.isUndefined(self.QI.start_date)) && (!Object.isUndefined(self.QI.end_date))) { var startDateElem = ""; var startDateMillsecElem = ""; var endDateElem = ""; var endDateMillisecElem = ""; self.dispDIV.innerHTML += startDateElem + startDateMillsecElem + endDateElem + endDateMillisecElem; } //End Query Report BG // self.dispDIV.innerHTML += '
Compute Time: ' + (Math.floor((self.QI.end_date - self.QI.start_date)/100))/10 + ' secs
'; // self.dispDIV.innerHTML += '
'; $('runBoxText').innerHTML = "Run Query"; } self.dispDIV.innerHTML += '
'; if ((!private_singleton_isRunning) && (undefined != self.QI.end_date)){ self.dispDIV.innerHTML += '
Compute Time: '+ (Math.floor((self.QI.end_date - self.QI.start_date)/100))/10 +' secs
'; } var foundError = false; for (var i in self.QRS) { var rec = self.QRS[i]; if (rec.QRS_time) { var t = '
ERROR
'; // self.dispDIV.innerHTML += '
ERROR
'; //['+rec.QRS_time+' secs]'; foundError = true; break; case "COMPLETED": case "FINISHED": foundError = false; //t += '#0000dd">'+rec.QRS_Status; break; case "INCOMPLETE": case "WAITTOPROCESS": case "PROCESSING": self.dispDIV.innerHTML += '
'+rec.title+'
PROCESSING
'; // self.dispDIV.innerHTML += '
PROCESSING
'; //['+rec.QRS_time+' secs]
'; alert('Your query has timed out and has been rescheduled to run in the background. The results will appear in "Previous Queries"'); foundError = true; //t += '#00dd00">'+rec.QRS_Status; break; } t += '
'; //self.dispDIV.innerHTML += '
'+t+'['+rec.QRS_time+' secs]
'; } self.dispDIV.innerHTML += ''; if (foundError == false) { if (rec.QRS_DisplayType == "CATNUM") { i2b2.CRC.ajax.getQueryResultInstanceList_fromQueryResultInstanceId("CRC:QueryStatus", {qr_key_value: rec.QRS_ID}, scopedCallbackQRSI); } else if ((rec.QRS_DisplayType == "LIST") && (foundError == false)) { self.dispDIV.innerHTML += "
" + rec.QRS_Description + "
"; } if (rec.QRS_Type == "PATIENTSET") { // Check to see if timeline is checked off, if so switch to timeline var t2 = $('dialogQryRun').select('INPUT.chkQueryType'); for (var i=0;i 0) && (curItem == " timeline") && !(i2b2.h.isBadObjPath('i2b2.Timeline.cfg.config.plugin')) ) { i2b2.hive.MasterView.setViewMode('Analysis'); i2b2.PLUGINMGR.ctrlr.main.selectPlugin("Timeline"); //Process PatientSet rec.QM_id = self.QM.id; rec.QI_id = self.QI.id; rec.PRS_id = rec.QRS_ID; rec.result_instance_id = rec.PRS_id; var sdxData = {}; sdxData[0] = i2b2.sdx.Master.EncapsulateData('PRS', rec); i2b2.Timeline.prsDropped(sdxData); i2b2.Timeline.setShowMetadataDialog(false); //Process Concepts, put all concepts in one large set sdxData = {}; for (var j2 = 0; j2 < i2b2.CRC.model.queryCurrent.panels.length; j2++) { var panel_list = i2b2.CRC.model.queryCurrent.panels[j2] var panel_cnt = panel_list.length; for (var p2 = 0; p2 < panel_cnt; p2++) { // Concepts for (var i2=0; i2 < panel_list[p2].items.length; i2++) { sdxData[0] = panel_list[p2].items[i2]; if (sdxData[0].sdxInfo.sdxType == "CONCPT") i2b2.Timeline.conceptDropped(sdxData, false); // nw096 - turn off dialogs when auto-generating timeline } } } //$('Timeline-pgstart').value = '1'; //$('Timeline-pgsize').value = '10'; //i2b2.Timeline.pgGo(0); i2b2.Timeline.yuiTabs.set('activeIndex', 1); i2b2.Timeline.setShowMetadataDialog(true); } } } } } if ((undefined != self.QI.message) && (foundError == false)) { self.dispDIV.innerHTML += '
Status
'; var mySplitResult = self.QI.message.split("' + i2b2.h.XPath(xml_v, 'descendant::name/text()/..')[i2].firstChild.nodeValue + ': ' + value + ' secs'; //snm0 //alert('
' + i2b2.h.XPath(xml_v, 'descendant::name/text()/..')[i2].firstChild.nodeValue + ': ' + value + ' secs
'); //self.dispDIV.innerHTML += '
: ' + i2b2.h.XPath(xml_v, 'descendant::total_time_second/text()/..')[i2].firstChild.nodeValue + ' secs
'; } catch (e) {} } } } // self.QI.message = null; //mm self.dispDIV.innerHTML = dispMsg; //self.dispDIV.style.backgroundColor = '#F00'; self.dispDIV.style.display = 'none'; self.dispDIV.style.display = 'block'; if (!private_singleton_isRunning && private_refreshInterrupt) { // make sure our refresh interrupt is turned off try { clearInterval(private_refreshInterrupt); private_refreshInterrupt = false; } catch (e) {} } } function private_cancelQuery() { if (private_singleton_isRunning) { try { var self = i2b2.CRC.ctrlr.currentQueryStatus; //if(i2b2.CRC.ctrlr.deleteCurrentQuery.QM !== false){ // WEBCLIENT-211 if (i2b2.CRC.ctrlr.deleteCurrentQuery && i2b2.CRC.ctrlr.deleteCurrentQuery.QM !== false) { // BD2K/BD2K-79 & I2B2/WEBCLIENT-211 i2b2.CRC.ctrlr.history.queryDeleteNoPrompt(i2b2.CRC.ctrlr.deleteCurrentQuery.QM); } clearInterval(private_refreshInterrupt); private_refreshInterrupt = false; private_singleton_isRunning = false; $('runBoxText').innerHTML = "Run Query"; self.dispDIV.innerHTML += '
QUERY CANCELLED
'; i2b2.CRC.ctrlr.currentQueryStatus = false; } catch (e) {} } } function private_startQuery() { var self = i2b2.CRC.ctrlr.currentQueryStatus; if (private_singleton_isRunning) { return false; } private_singleton_isRunning = true; self.dispDIV.innerHTML = 'Processing Query: "'+this.name+'"'; i2b2.CRC.ctrlr.deleteCurrentQuery.QM = false; // WEBCLIENT-211 i2b2.CRC.ctrlr.deleteCurrentQuery.cancelled = false; self.QM.name = this.name; self.QRS = {}; self.QI = {}; // callback processor to run the query from definition this.callbackQueryDef = new i2b2_scopedCallback(); this.callbackQueryDef.scope = this; this.callbackQueryDef.callback = function(results) { try{ if (results.error) { var temp = results.refXML.getElementsByTagName('response_header')[0]; if (undefined != temp) { results.errorMsg = i2b2.h.XPath(temp, 'descendant-or-self::result_status/status')[0].firstChild.nodeValue; if (results.errorMsg.substring(0,9) == "LOCKEDOUT") { results.errorMsg = 'As an "obfuscated user" you have exceeded the allowed query repeat and are now LOCKED OUT, please notify your system administrator.'; } } alert(results.errorMsg); private_cancelQuery(); return; } else { // "results" object contains the following attributes: // refXML: xmlDomObject <--- for data processing // msgRequest: xml (string) // msgResponse: xml (string) // error: boolean // errorStatus: string [only with error=true] // errorMsg: string [only with error=true] // save the query master //Check to see if condition failed var condition = results.refXML.getElementsByTagName('condition')[0]; if (condition.getAttribute("type") == "ERROR") { results.errorMsg = 'ERROR: ' + condition.firstChild.nodeValue; alert(results.errorMsg); private_cancelQuery(); return; } var temp = results.refXML.getElementsByTagName('query_master')[0]; self.QM.id = i2b2.h.getXNodeVal(temp, 'query_master_id'); i2b2.CRC.ctrlr.deleteCurrentQuery.QM = self.QM.id; // Check if user cancelled query // WEBCLIENT-211 if((i2b2.CRC.ctrlr.deleteCurrentQuery.QM !== false) && i2b2.CRC.ctrlr.deleteCurrentQuery.cancelled){ i2b2.CRC.ctrlr.history.queryDeleteNoPrompt(i2b2.CRC.ctrlr.deleteCurrentQuery.QM); } //Query Report BG //Update the userid element when query is run first time var userId = i2b2.h.getXNodeVal(temp,'user_id'); if(userId) { var existingUserIdElemList = $$("#userIdElem"); if(existingUserIdElemList) { existingUserIdElemList.each(function(existingUserIdElem){ existingUserIdElem.remove(); }); } $("crcQueryToolBox.bodyBox").insert(new Element('input',{'type':'hidden','id':'userIdElem','value':userId})); } //End Query Report BG self.QM.name = i2b2.h.XPath(temp, 'descendant-or-self::name')[0].firstChild.nodeValue; // save the query instance var temp = results.refXML.getElementsByTagName('query_instance')[0]; self.QI.id = i2b2.h.XPath(temp, 'descendant-or-self::query_instance_id')[0].firstChild.nodeValue; self.QI.start_date = i2b2.h.XPath(temp, 'descendant-or-self::start_date')[0].firstChild.nodeValue; //Query Report BG var temp = i2b2.h.XPath(temp, 'descendant-or-self::end_date')[0]; if (undefined != temp) { self.QI.end_date = i2b2.h.XPath(temp, 'descendant-or-self::end_date')[0].firstChild.nodeValue; //Query Report BG } var temp = self.QI.status = i2b2.h.XPath(temp, 'descendant-or-self::query_status_type/name')[0]; if (undefined != temp) { self.QI.status = i2b2.h.XPath(temp, 'descendant-or-self::query_status_type/name')[0].firstChild.nodeValue; } var temp = self.QI.statusID = i2b2.h.XPath(temp, 'descendant-or-self::query_status_type/status_type_id')[0]; if (undefined != temp) { self.QI.statusID = i2b2.h.XPath(temp, 'descendant-or-self::query_status_type/status_type_id')[0].firstChild.nodeValue; } // we don't need to poll, all Result instances are listed in this message if (false && (self.QI.status == "INCOMPLETE" || self.QI.status == "COMPLETED" || self.QI.status == "ERROR")) { // create execution time string var d = new Date(); var t = Math.floor((d.getTime() - private_startTime)/100)/10; var exetime = t.toString(); if (exetime.indexOf('.') < 0) { exetime += '.0'; } var qi_list = results.refXML.getElementsByTagName('query_result_instance'); var l = qi_list.length; for (var i=0; i