Creating SQL based reports in PatientOS EMR - Part 2
Saturday, December 12th, 2009So now that we have our base query we are challenged with converting the most of the rows to report on a single line. For example we want all the vitals to display on one line but the query returns them as multiple rows. The ‘print when’ expression worked to a certain degree for some fields but the vitals remained a challenge.
It turns out iReport has a nice feature that allows you to write a ’scriptlet’ - essentially a single java file which is called at different times during the report execution and can return values to text expressions for display on the report.
So were were example to create in the java file a couple of helper methods and then the following code which is called with each row and collects the vital sign values.
String hval = getDoubleValue("HEIGHT", 0);
if (hval != null) {
height = hval;
}
String wval = getDoubleValue("WEIGHTMEASURED", 0);
if (wval != null) {
weight = wval;
}
And then we create a standalone method which returns the formatted vital signs
public String getVitals() {
StringBuffer sb = new StringBuffer(256);
sb.append("Height: ");
sb.append(height);
sb.append(" Weight: ");
sb.append(weight);
return sb.toString();
}
This is very handy but even more so for the symptoms as there were a mix of record items and controls capturing the symptoms - but all of these are gathered together as a single comma delimeted line. It would have probably have been near impossible to do that with normal report writer features.
We export our project as a jar file which needs to be in the lib (C:\Program Files\PatientOS\0.99\server\appserver\server\default\lib) directory for runtime and added to the iReport design tool using Tools->Options–>Add Jar

So now our report design, adding a image looks like this.

The last thing we need was the medications. This is a little trickier as we did not include the meds in query and adding a subreport is a pain in any report designer. So we will use the scriptlet. We could setup all the properties need to call the application server ejb service to get orders for this visit. But even simpler is to add a custom controller. We’ll save that for another post though.
We also alter the SQL in the report to replace the hardcoded visit id with $P{visit_id} and create a parameter called visit_id. In version 0.99 user_ref_id, visit_id, patient_id are passed to the program.
Finally we need to incorporate the report into the UI. For both the thin client and the web client we can add a button (in 0.99) which displays a report with the following properties
Action: System Display PDF Report
Report Output: Your Report
For the report we add a new one which uses the custom controller Report Default Jasper SQL Output.
We browse and select the jasper file.

Thats it. 0.99 has some new jar files to support iReport 3.7 so as long as those were deployed correctly everything should work fine.




