Wiki Markup |
---|
h3. Color-coded example Some Header Stuff <% /\* Multivariate Trigger Report To use this report: 1) Add a variable to a the list of variables to be charted addVariable(variableID, variableName, displayTriggerText, displayPercentageChangeSinceEncounter, displayPercentageChangePerDaySinceEncounter, displayPercentageChangeFromBaseline) 2) Add thresholds addThreshold(variableID, thresholdValue, thresholdBelowText, thresholdAboveText, thresholdBelowColor) 3) Set the final color, i.e the color that will be displayed if value is above ALL thresholds addFinalColor(variableID, aColor) 4) Set thresholds for percentage thresholds to flag, along with their colors setPercentageThreshold(variableID, lowPercentage, lowPercentageColor, highPercentage, highPercentageColor) \*/ // sort our encounters by date var encounters = ENCOUNTERS.Sort(#EncounterDate.ID, true); // the set of intervals we want to ignore var intervalsToIgnore = new Array(); // a boolean value that determines if we want to display the date var printDate = true; // the number of variables printed in a single table. var variablesPerTable = 2; // function to add a new variable var variables = new Array(); function addVariable(variableId, variableName, displayTriggerText, displayEncounterChange, displayDailyChange, displayBaselineChange) { displayTriggerText = typeof(displayTriggerText) === undefined ? false : displayTriggerText; displayEncounterChange = typeof(displayEncounterChange) === undefined ? false : displayEncounterChange; displayDailyChange = typeof(displayDailyChange) === undefined ? false : displayDailyChange; displayBaselineChange = typeof(displayBaselineChange) === undefined ? false : displayBaselineChange; variables\[variables.length\] = {"id":variableId, "name":variableName, "thresholdValues":new Array(), "thresholdBelowText":new Array(), "thresholdAboveText":new Array(), "thresholdColors":new Array(), "lowTriggerPercentage":-1.0, "lowPercentageColor": "#ffffff", "highTriggerPercentage":1.0, "highPercentageColor": "#ffffff", "displayTriggerText":displayTriggerText, "displayEncounterChange":displayEncounterChange, "displayDailyChange":displayDailyChange, "displayBaselineChange":displayBaselineChange }; } function addIntervalToIgnore(intervalName) { intervalsToIgnore.push(intervalName); } // now adding new values to a variable function addThreshold(variableId, thresholdValue, thresholdBelowText, thresholdAboveText, thresholdBelowColor) { for(var i=0; i<variables.length; i++) if( variables\[i\].id == variableId) { variables[i].thresholdValues.push(thresholdValue); variables[i].thresholdBelowText.push(thresholdBelowText); variables[i].thresholdAboveText.push(thresholdAboveText); variables[i].thresholdColors.push(thresholdBelowColor); } } function setFinalColor(variableId, color) { for(var i=0; i<variables.length; i++) if(variables\[i\].id == variableId) { variables[i].thresholdColors.push(color); } } function setPercentageThreshold(variableId, lowPercentage, lowPercentageColor, highPercentage, highPercentageColor) { for(var i=0; i<variables.length; i++) if(variables\[i\].id == variableId) { variables[i].lowTriggerPercentage = lowPercentage; variables[i].lowPercentageColor = lowPercentageColor; variables[i].highTriggerPercentage = highPercentage; variables[i].highPercentageColor = highPercentageColor; } } function encounterTimeDifference(encounter1, encounter2) { //first turn these into dates var dateStr1 = encounter1.EncounterDate; var dateStr2 = encounter2.EncounterDate; // tokenize by '/' var tokens1 = dateStr1.split("/"); var tokens2 = dateStr2.split("/"); // convert to a date object var date1 = new Date(tokens1\[2\], tokens1\[0\], tokens1\[1\]); var date2 = new Date(tokens2\[2\], tokens2\[0\], tokens2\[1\]); // Length of a day in milliseconds var one_day = 86400000; // Take millisecond difference and divide by the length of a day return Math.abs((date1.getTime() - date2.getTime())/one_day); } function findIntervalName(intervalName) { for(var i=0; i<intervalsToIgnore.length; i++) if(intervalsToIgnore\[i\] == intervalName) return i; return \-1; } function drawTable(a,b) { // if b is outside of the number of variables, set it down if(b > variables.length) b = variables.length; // could write some header stuff later... Output.Write("<table border=\"1\">"); // print the header Output.Write("<tr>"); if(printDate) Output.Write("<th>Date</th>"); for(var i=a; i<b; i++) { Output.Write("<th align="center">" + variables[i].name + "</th>"); if(variables[i].displayTriggerText) Output.Write("<th align="center"> Trigger Type </th>"); if(variables[i].displayEncounterChange) Output.Write("<th align="center"> Percentage Change Per Encounter</th>"); if(variables[i].displayDailyChange) Output.Write("<th align="center"> Percentage Change Per Day </th>"); if(variables[i].displayBaselineChange) Output.Write("<th align="center"> Percentage Change From Baseline </th>"); } // end the header Output.Write("</tr>"); // start writing values for(var i=0; i<encounters.length; i++) { Output.Write("<tr>"); var encounter = encounters.GetEncounter\(i); if( findIntervalName(encounter.#IntervalName) \!= \-1) continue; // \**\* print date \**\* if(printDate) Output.Write("<td align=\"center\">" + encounter.EncounterDate + "</td>"); for(var j=a; j<b; j++) { var variable = variables\[j\]; // now check and see if variable value crossed a threshold in the past step var color = "#ffffff"; var thresholdText = "-"; var variableValue = encounter.GetVariableValue(variable.id); // ascending now, checking only above cases (so we catch the highest one last) // also, we'll go ahead and also calculate percentage stuff too var percentageColor = "#ffffff"; var deltaPercent = null; var previousIndex = null; if (i > 0 && variableValue) { // grab the first NON-NULL value var k = i-1; var previousValue = null; while( k >= 0 && \!previousValue) { previousValue = encounters.GetEncounter(k).GetVariableValue(variable.id); previousIndex = k; k--; } if(previousValue) { // find the correct upper threshold and update the text for(var k=1; k<=variable.thresholdValues.length; k++) if(variableValue > variable.thresholdValues\[k-1\] && previousValue <= variable.thresholdValues\[k-1\]) { color = variable.thresholdColors[k]; thresholdText = variable.thresholdAboveText[k-1]; } // calculate the highest percentage as well deltaPercent = (variableValue-previousValue)/previousValue * 100; if(deltaPercent > variable.highTriggerPercentage) percentageColor = variable.highPercentageColor; else if(deltaPercent < variable.lowTriggerPercentage) percentageColor = variable.lowPercentageColor; deltaPercent = deltaPercent.toFixed(2); } } // Descending now, catching the lowest last. if (i < encounters.length - 1 && variableValue) { var nextValue = encounters.GetEncounter(i+1).GetVariableValue(variable.id); for(var k=variable.thresholdValues.length-1; k>=0; k--) if(variableValue < variable.thresholdValues\[k\] && previousValue >= variable.thresholdValues\[k\]) { color = variable.thresholdColors[k]; thresholdText = variable.thresholdBelowText[k]; } } // \**\* Print the variable's value \**\* if(variableValue) Output.Write("<td bgcolor = \"" + color + "\" align=\"center\">"\+ variableValue \+"</td>"); else Output.Write("<td align=\"center\"> - </td>"); // \**\* Print the text for crossing thresholds \**\* if( variable.displayTriggerText ) Output.Write("<td align=\"center\">" + thresholdText + "</td>"); // \**\* print percentage change since last entry \**\* if(variable.displayEncounterChange) { if(deltaPercent) Output.Write("<td align = "center" bgcolor="" + percentageColor + "">" + deltaPercent + "% </td>"); else Output.Write("<td align="center"> - </td>"); } // \**\* print percentage change per day \**\* if(variable.displayDailyChange) { if(deltaPercent) { var deltaTime = encounterTimeDifference(encounters.GetEncounter(i), encounters.GetEncounter(previousIndex)); var percentChangePerDay = deltaPercent/deltaTime; percentageColor = "#ffffff"; if(percentChangePerDay > variable.highTriggerPercentage) percentageColor = variable.highPercentageColor; else if(percentChangePerDay < variable.lowTriggerPercentage) percentageColor = variable.lowPercentageColor; Output.Write("<td align="center" bgcolor = "" + percentageColor + "">" + percentChangePerDay.toFixed(2) + "% </td>"); } else Output.Write("<td align=\"center\"> - </td>"); } // \**\* print percent change from baseline if(variable.displayBaselineChange) { if(deltaPercent) { var startValue = encounters.GetEncounter(0).GetVariableValue(variable.id); var baselineChange = (variableValue - startValue)/startValue * 100; percentColor = "#ffffff"; if(baselineChange > variable.highTriggerPercentage) percentageColor = variable.highPercentageColor; else if(baselineChange < variable.lowTriggerPercentage) percentColor = variable.lowPercentageColor; Output.Write("<td align="center" bgcolor = "" + percentageColor + "">" + baselineChange.toFixed(2) + "% </td>"); } else Output.Write("<td align=\"center\"> - </td>"); } } Output.Write("</tr>"); } Output.Write("</table>"); Output.Write("<br/><br/>"); } // A Variable Add looks like the following: // addVariable(variableID, variableName, displayTriggerText, displayPercentageChangeSinceEncounter, // displayPercentageChangePerDaySinceEncounter, displayPercentageChangeFromBaseline var ID = #rangezerohun.ID; addVariable(ID, "Test Scores", true, false, true, true); addThreshold(ID, 60, "below 60", "above 60", "#668CC7"); addThreshold(ID, 70, "below 70", "above 70", "#ff3300"); addThreshold(ID, 80, "below 80", "above 80", "#000066"); addThreshold(ID, 90, "moderate issues", "Grades rose to an A", "#3333ff"); setPercentageThreshold(ID, \-10.50, "#ffff00", 10.5, "ff6600"); setFinalColor(ID, "#ff0000"); addVariable(ID, "Test Scores", true, false, true, true); addVariable(ID, "Test Scores", true, false, true, true); for(var i=0; i<variables.length; i \+= variablesPerTable) { drawTable(i, i+variablesPerTable); } %> |
Page Comparison
General
Content
Integrations