Programming Subject Reports

Overview

In terms of functionality, anything that is available in the JavaScript programming language is available for use in Subject Reports. Thus, there is considerable power that can be leveraged by Subject Reports (e.g., automated clinic note generator).

How It's Done

Referencing Variables
To reference a variable value enter the following into the body of the report: <%= #VariableCode %>

If the variable is categorical (e.g., picklist), adding .name will insert the label associated with the numeric value: <%=#VariableCode.name %>

Alternately, use the Add/edit Expression button to select the variable. Adding .name onto the variable can be done in the Expression Builder.

If Statement

The if statement is helpful when you only want text to appear under specific conditions


<% indicates begin JavaScript and %> indicates end JavaScript

<% if (#VariableCode == 0) %>Text if true <% else %>Text if false

An alternate way of writing the same code is to keep the entire statement in JavaScript

<% if (#VariableCode.value.value==0) Output.Write("Text if true");

      else Output.Write("Text if false"):

%> 

You can also reference other variable values within the if statement

<% if (#VariableCode.value.value == 0) { %> <% =#VariableCode2 %> <% }else { %>Text if false <% }%>

Example Basic Report


Patient Name: <%= #FirstName %> <%=#LastName %>
MRN: <%= #ReferenceId %>
Sex: <%= #sex.name %>
Dob: <%= #birth %>
Age: <%= ageAsOf(#birth, #EncounterDate) %>
Race: <%= #race.name %>

Referral Reason:
<%= #FName %> <%= #LName %> is a <%= ageAsOf(#birth, #EncounterDate) %> year old active
<%= #sex.name %> outpatient <%= #height %> inches tall, weighing <%= #weight %> lbs, who underwent neuropsychological testing on <%= #EncounterDate %> for assessment of Attention Deficit Disorder......

Test Results

Test 1
Section A subscore <%= #section_a_subscore %>
Section B subscore <%= #section_b_subscore %>
Section C subscore <%= #section_c_subscore %>


Where To Place The Code

Code blocks (begin and end with <% and %>, respectively) can be entered within the body of the report (as shown below). However, it is best to put the script  into the Script window.


<%

var srgiResult;
var beckResult;

if (#cgi_s_sr.displayValue.value==1) srgiResult="Normal; not at all ill";
else if (#cgi_s_sr.displayValue.value==2) srgiResult="Borderline mentally ill";
else if (#cgi_s_sr.displayValue.value==3) srgiResult="Mildly ill";
else if (#cgi_s_sr.displayValue.value==4) srgiResult="Moderately ill";
else if (#cgi_s_sr.displayValue.value==5) srgiResult="Markedly ill";
if (#bditot.displayValue.value>=0 && #bditot.displayValue.value<=13) beckResult="Minimal depression";
else if (#bditot.displayValue.value<=19) beckResult="Mild depression";
else if (#bditot.displayValue.value<=28) beckResult="Moderate depression";
else if (#bditot.displayValue.value<=63) beckResult="Severe depression";

var Tcog1 = 0;
var Tcog2 = 0;
var Zcog1 = 0;
var Zcog2 = 0;

Tcog1 = (#cog1.displayValue.value) / 2;
Tcog1 = Math.round(Tcog1*100) / 100;
Tcog2 = (#cog2.displayValue.value) / 2;
Tcog2 = Math.round(Tcog2*100) / 100;

Zcog1 = (Tcog1 - 50) / 10;
Zcog1 = Math.round(Zcog1*100) / 100;
Zcog2 = (Tcog2 - 50) / 10;
Zcog2 = Math.round(Zcog2*100) / 100;

%>

Patient Name: <%= #FirstName %> <%= #LastName %>
<% Tcog1 %>


Referencing More Than One Encounter

You can display data values from more than one variable by using the ENCOUNTERS method as in the example below which generates a table with values from multiple encounters. This method allows users with knowledge of JavaScript to create any custom report. Another option is to use the Repeater function to generate a table from multiple encounters.


<%
Output.Write("<table style=cellspacing='5' cellpadding='0' border='1'>");
Output.Write("<tr><th> Encounter Name </th><th> Encounter Date </th> <th> Score 1</th> <th> Score 2</th> <th> Score 3</th> <th> Score 4</th></tr>");

for (var index=0; index < ENCOUNTERS.Count; index++) {
   var encounter = ENCOUNTERS.GetEncounter(index);
   var encounterName = encounter.#IntervalName.displayValue.toString();
   var encounterDate = encounter.#EncounterDate.displayValue.toString();
   var encounterScore1 = encounter.#score1.displayValue.value;  
   var encounterScore2 = encounter.#score2.displayValue.value;
   var encounterScore3 = encounter.#score3.displayValue.value;
   var encounterScore4 = encounter.#score4.displayValue.value;
   Output.Write("<tr><td>" + encounterName + "</td>");
   Output.Write("<td>" + encounterDate + "</td>");
   Output.Write("<td>" + encounterScore1 + "</td>");
   Output.Write("<td>" + encounterScore2 + "</td>");
   Output.Write("<td>" + encounterScore3 + "</td>");
   Output.Write("<td>" + encounterScore4 + "</td></tr>");
}
Output.Write("</table>");
%>