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

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

/**
 * @projectDescription	(GUI-only) Controller for CRC Query Tool's Lab Values constraint dialog box.
 * @inherits 	i2b2.CRC.view
 * @namespace	i2b2.CRC.view.modalLabValues
 * @author		Nick Benik, Griffin Weber MD PhD, Shawn Murphy
 * @version 	1.6
 * ----------------------------------------------------------------------------------------
 * updated 9-15-08: 1.3 RC4 launch [Nick Benik] 
 * updated 7-28-12  1.6 [Shawn Murphy]
 */

// Known Bugs:
// double value to right of concept name when populate previous query

i2b2.CRC.view.modalLabValues = {
	formdata: {},
	cfgTestInfo: {
		name: 'RND-TEST',
		flagType: 'NA',
		flags: [{name:'Abnormal', value:'A'},{name:'Normal', value:'@'}],
		valueValidate: {
			onlyPos: true,
			onlyInt: true,
			maxString: 0 
		},
		valueType: 'PosFloat',
		valueUnitsCurrent: 0, // index into Units[]
		valueUnits: {},
		rangeInfo: {},
		enumInfo: {}
	},

// snm0
//===================================================================================
// Gets called when a click occurs on the value bar graphic and the operator and 
// values are set.
//
	updateValue: function(e) {
		// The method is to embed the reference to the value label of the bar
		// in the anchor of the href and then get it and extract the value and
		// place it in the select drop down and text box.
		try {
			var targ; // href of bar item that was clicked
			if (!e) var e = window.event;
			if (e.target) targ = e.target;
			else if (e.srcElement) targ = e.srcElement;
			if (targ.nodeType == 3) // defeat Safari bug
				targ = targ.parentNode;
			// make href into a string and get the anchor of it
			var sTarg = targ.toString();
			var iTargAnchor = sTarg.lastIndexOf("#");
			if (iTargAnchor < 0) return; // no anchor
			var sTargAnchor = sTarg.substring(iTargAnchor+1);
			if (sTargAnchor.length <= 1) return; //no anchor
			//alert(sTargAnchor);
			var sTargNumber = $(sTargAnchor).innerHTML;
			// after getting the bar label get the value and put it in the slots
			if ((sTargAnchor == 'lblToxL') || (sTargAnchor == 'lblLofL') || (sTargAnchor == 'lblHofL')) {
				$('mlvfrmOperator').selectedIndex=1;
				//$('mlvfrmOperator').value='LE';
				i2b2.CRC.view.modalLabValues.formdata.numericOperator = 'LE';
				$('mlvfrmNumericValue').value = sTargNumber;
			}
			if ((sTargAnchor == 'lblToxH') || (sTargAnchor == 'lblLofH') || (sTargAnchor == 'lblHofH')) {
				$('mlvfrmOperator').selectedIndex=5;
				i2b2.CRC.view.modalLabValues.formdata.numericOperator = 'GE';
				$('mlvfrmNumericValue').value = sTargNumber;
			}
		}
		catch(eError) {
				alert("Error: updateValue: " + eError.description);
		}
	},
// snm0	
// ================================================================================================== //
	show: function(panelIndex, queryPanelController, key, extData, isModifier) {
		if (Object.isUndefined(i2b2.CRC.model.queryCurrent.panels[i2b2.CRC.ctrlr.QT.temporalGroup][panelIndex])) { return; }
		var fd = i2b2.CRC.view.modalLabValues.formdata;
		var dm = i2b2.CRC.model.queryCurrent.panels[i2b2.CRC.ctrlr.QT.temporalGroup][panelIndex];
		// save info for callback
		this.qpi = panelIndex;
		this.cpc = queryPanelController;
		i2b2.CRC.view.modalLabValues.isModifier = isModifier;
		i2b2.CRC.view.modalLabValues.itemNumber = extData.itemNumber;
		//this.isModifier = isMod;
		this.key = key;
		this.i2b2Data = extData;
		// Create SimpleDialog control
		if (!this.sd) {
			this.sd = new YAHOO.widget.SimpleDialog("itemLabRange", {
				zindex: 700,
				width: "600px",
				fixedcenter: true,
				constraintoviewport: true,
				modal: true,
				buttons: [{
					text: "OK",
					isDefault: true,
					handler: 
						(function() {
							var closure_qpi = i2b2.CRC.view.modalLabValues.qpi;
							var closure_cpc = i2b2.CRC.view.modalLabValues.cpc;
							var closure_key = i2b2.CRC.view.modalLabValues.key;
							var closure_number = i2b2.CRC.view.modalLabValues.itemNumber;
							// submit value(s)
							if (this.submit()) {
								var pd = i2b2.CRC.model.queryCurrent.panels[i2b2.CRC.ctrlr.QT.temporalGroup][closure_qpi];
								// find the correct item in the panel
								for (var i=0; i 0) {
			this.cfgByMetadata(mdnodes[0]);
		} else {
			// no LabValue configuration
			return false;
		}
		if (i2b2.CRC.view.modalLabValues.isModifier) {
			if (!this.i2b2Data.ModValues && this.i2b2Data.origData.ModValues) {
				// copy server delivered Lab Values to our scope
				this.i2b2Data.ModValues = this.i2b2Data.origData.ModValues;
			}
			var tmpLab = this.i2b2Data.ModValues;
		} else {	
			if (!this.i2b2Data.LabValues && this.i2b2Data.origData.LabValues) {
				// copy server delivered Lab Values to our scope
				this.i2b2Data.LabValues = this.i2b2Data.origData.LabValues;
			}
			var tmpLab = this.i2b2Data.LabValues;
		}
		// load any data already attached to the node
		if (tmpLab) {
			switch(tmpLab.MatchBy) {
				case "FLAG":
					fd.selectedType = "FLAG";
					$("mlvfrmTypeFLAG").checked = true;
					var tn = $("mlvfrmFlagValue");
					for (var i=0; i -1) {
								tn.options[i].selected = true;
							} else {
								tn.options[i].selected = false;
							}
						}
					}
					break;
			}
		} else {
// snm0
			// set the form to show value selection if available
			$("mlvfrmTypeVALUE").checked = true;
			fd.selectedType = 'VALUE';
// snm0
		}
		// show the form
		this.sd.show();
		this.Redraw();
	},
	
// ================================================================================================== //
	changeHandler: function(e) {
		var dm = i2b2.CRC.view.modalLabValues.cfgTestInfo;
		var fd = i2b2.CRC.view.modalLabValues.formdata;
		if (fd.ignoreChanges) { return true; }
		// get the DOM node that fired the event
		var tn;
		if (e.target) {
			tn = e.target;
		} else {
			if (e.srcElement) tn = e.srcElement;
			if (tn.nodeType == 3) tn = tn.parentNode;
		}
		// process
		switch(tn.id) {
			case "mlvfrmTypeNONE":
				fd.selectedType = 'NONE';
				break;
			case "mlvfrmTypeFLAG":
				fd.selectedType = 'FLAG';
				break;
			case "mlvfrmTypeVALUE":
				fd.selectedType = 'VALUE';
				break;
			case "mlvfrmFlagValue":
				fd.flagValue = tn.options[tn.selectedIndex].value;
				break;
			case "mlvfrmOperator":
				var i1 = $('mlvfrmUnits');
				fd.numericOperator = tn.options[tn.selectedIndex].value;
				fd.valueUnitsCurrent = i1.selectedIndex;
				break;
			case "mlvfrmStringOperator":
				fd.stringOperator = tn.options[tn.selectedIndex].value;	
				break;
			case "mlvfrmDbOperator":
				fd.dbOperator = tn.checked;	
				break;
			case "mlvfrmEnumValue":
				fd.enumIndex = tn.selectedIndex;
				fd.enumValue = tn.options[fd.enumIndex].innerHTML;
				break;
			case "mlvfrmUnits":
				
				var u1 = $('mlvfrmUnits');
				// convert entered values
				var cvD = dm.valueUnits[fd.unitIndex].multFactor;
				var cvM = dm.valueUnits[u1.selectedIndex].multFactor;
				var lst = [$('mlvfrmNumericValue'), $('mlvfrmNumericValueLow'), $('mlvfrmNumericValueHigh')];
				/*
				for (var i=0;i 0) {
						dm.valueValidate.maxString = t;
					} else {
						dm.valueValidate.maxString = false;
					}
					break;
				case "largestring":
					dm.valueType = "LRGSTR";
					dm.valueValidate.onlyPos = false;
					dm.valueValidate.onlyInt = false;
					// extract max string setting
					try {
						var t = refXML.getElementsByTagName('MaxStringLength')[0].firstChild.nodeValue;
						t = parseInt(t);
					} catch(e) { 
						var t = -1;
					}
					if (t > 0) {
						dm.valueValidate.maxString = t;
					} else {
						dm.valueValidate.maxString = false;
					}
					break;					
				case "Enum":
					dm.valueType = "ENUM";
					dm.valueValidate.onlyPos = false;
					dm.valueValidate.onlyInt = false;
					dm.valueValidate.maxString = false;
					// extract the enum data
					var t1 = i2b2.h.XPath(refXML,"descendant::EnumValues/Val");
					//var t = i2b2.h.XPath(refXML,"descendant::EnumValues/Val/text()");
					//var t2 = [];
					var sn = $('mlvfrmEnumValue');
					// clear the drop down
					while( sn.hasChildNodes() ) { sn.removeChild( sn.lastChild ); }			
					
					var t2 = new Array();
					for (var i=0; i section
					
					var t = i2b2.h.XPath(refXML,"descendant::CommentsDeterminingExclusion/Com/text()");
					var t2 = [];
					for (var i=0; i 0) {
						for (var i=0;i -1 ) {
									dm.enumInfo[i2] = null;
								}
							}
							// clean up the array
							dm.enumInfo = dm.enumInfo.compact();
						}
					}
					// clear & populate the Enum dropdown
					// populate values
					var count = 0;
					//for (var i in dm.enumInfo) {
					
					/*for (var i in dm.enumInfo) {
					//for (var i=0; i0) {
				//	d.excluded = true;
				//}
				
				// Equal Units
				//if (i2b2.h.XPath(refXML,"descendant::UnitValues/descendant::ExcludingUnits[text()='"+t[i]+"']").length>0) {
				//	d.excluded = true;
				//}
				
				// does unit require conversion?
				try {
					d.multFactor = i2b2.h.XPath(refXML,"descendant::UnitValues/descendant::ConvertingUnits[Units/text()='"+t[i]+"']/MultiplyingFactor/text()")[0].nodeValue;
				} catch(e) {
					d.multFactor = 1;
				}
				tProcessing.set(t[i], d);
			}
			// get our master unit (the first NormalUnits encountered that is not disabled)
			var t = i2b2.h.XPath(refXML,"descendant::UnitValues/descendant::NormalUnits/text()");
			var t2 = [];
			for (var i=0; i parseFloat(iv2))) {
							errorMsg.push(" - The low value is larger than the high value\n");
						}
//snm0						
						// CONVERT VALUES TO MASTER UNITS
						if (fd.unitIndex == -1) { // no units were in XML
							tmpLabValue.UnitsCtrl = "";
							break;
						}
						if ((dm.valueUnits[fd.unitIndex] == undefined) || (dm.valueUnits[fd.unitIndex] == "")) {
							alert('The units for this value are blank.');
							return false;
						}
// snm0
						if (dm.valueUnits[fd.unitIndex].excluded) {
							alert('You cannot set a numerical value using the current Unit Of Measure.');
							return false;
						}
						if (dm.valueUnits.find(function(o){ return ((o.masterUnit === true) && (o.excluded===true)); })) {
							alert('You cannot set a numerical value because the master Unit Of Measure is declared as invalid.');
							return false;
						}
						try {
							var convtMult = dm.valueUnits[fd.unitIndex].multFactor;
							if (tmpLabValue.ValueHigh) tmpLabValue.ValueHigh = (tmpLabValue.ValueHigh * convtMult);
							if (tmpLabValue.ValueLow) tmpLabValue.ValueLow = (tmpLabValue.ValueLow * convtMult);
							if (tmpLabValue.Value) tmpLabValue.Value = (tmpLabValue.Value * convtMult);
							for (var i=0; i dm.valueValidate.maxString)) {
							errorMsg.push(" - Input is over the "+dm.valueValidate.maxString+" character limit.\n");
						} else if (sv.length == 0) {
							errorMsg.push("The text for this value are blank.");
						} else {
							tmpLabValue.ValueString = $('mlvfrmStrValue').value;
						}
						break;						
					case "STR":
						tmpLabValue.GeneralValueType = "STRING";
						tmpLabValue.SpecificValueType = "STRING";
						tmpLabValue.StringOp = fd.stringOperator;
						var sv = $('mlvfrmStrValue').value;
						if (dm.valueValidate.maxString && (sv.length > dm.valueValidate.maxString)) {
							errorMsg.push(" - Input is over the "+dm.valueValidate.maxString+" character limit.\n");
						} else if (sv.length == 0) {
							errorMsg.push("The text for this value are blank.");
						} else {
							tmpLabValue.ValueString = $('mlvfrmStrValue').value;
						}
						break;
					case "ENUM":
						tmpLabValue.GeneralValueType = "ENUM";
						tmpLabValue.SpecificValueType = "ENUM";
						tmpLabValue.ValueEnum = [];
						tmpLabValue.NameEnum = [];
						var t = $('mlvfrmEnumValue').options;
						for (var i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy