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)
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)
}
function setFinalColor(variableId, color)
{
for(var i=0; i<variables.length; i++)
if(variables[i].id == variableId)
}
function setPercentageThreshold(variableId, lowPercentage, lowPercentageColor, highPercentage, highPercentageColor)
{
for(var i=0; i<variables.length; i++)
if(variables[i].id == variableId)
}
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++)
// 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)
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])
// 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])
}
// ** 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)
// ** print percentage change per day **
if(variable.displayDailyChange)
{
if(deltaPercent)
else
Output.Write("<td align=\"center\"> - </td>");
}
// *** print percent change from baseline
if(variable.displayBaselineChange)
{
if(deltaPercent)
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);
}
%>