Writing Java in Editor...

Hi,

We get patient clinic data from the hospital: the data comes over via an HL7 feed and narrative reports are in a table in which each ‘line’ of the report is one record. One report will often have hundreds of lines of text and each one of those is one record. Thus to recreate the full report one has to concatenate that column from each record.

It is possible to do it via SQL but there are some issues with that. A colleague of mine who’s a Java developer has a method whereby he “loads all the line child records for the parent OrderProc in a “OrderProc.getDocument()” method which loops over all its child OrderNarrative line records as ordered by line # in the query and concatenates them dynamically.” He uses this in a Java app that is used for a different application but has offered to help me set it up in Servoy. I know one can use Java directly in Servoy methods but I’ve no idea how that is done and searching in the Forum I couldn’t find any examples. I’m sure I’ve seen examples here before but to be honest I couldn’t figure out a way to search for it: everything I tried either gave me hundreds of results or none! My guy is a good Java developer and I’d like to use this as an opportunity to get him more involved. So any pointers would be gratefully received!

You can use java.lang.System directly, however I’m not sure how much of a good idea that is. I certainly was warned off using it in the webclient.

It might be safer to wrap your Java stuff into a plugin and use it that way, there are tutorials on how to do this and your Java guy should be able to do that.

Thanks Alan. Shoot I thought it was pretty straight forward just embedding a Java function directly within the method editor itself. I guess maybe I’ll just try looping through the foundset with javaScript and putting it in a form variable. I was partly hoping to do it in Java to get this guy more involved. Somehow building a plugin for just this seems more complicated than it is worth

I can’t say much about the performance penalty but is really easy to use Java directly from Servoy.

Just put the necessary jars in your plugins/beans folder and access the classes with Packages.path.to.class. For example:

 var javaDate = new Packages.java.util.GregorianCalendar();
application.output(javaDate.getTimeInMillis());

(I think all the packages in java you can access directly without the “Packages.” but it was just a quick example)

Servoy uses Rhino to do that, you should check documentation for Rhino and it should work with Servoy (sometimes they could be one version before)

I use Java on Servoy to make my own rtf reports with itext and works in webclient and smartclient.

/**
 * @properties={typeid:24,uuid:"7112E411-DD9E-475C-971F-ECED1F9F9BDF"}
 * 
 * @return {Array <byte>}
 */
function test(){
	
	var jBaos = Packages.java.io.ByteArrayOutputStream;
	var jRtfWriter2 = Packages.com.lowagie.text.rtf.RtfWriter2;
	var jUtils = Packages.com.lowagie.text.Utilities;
	var jDoc = Packages.com.lowagie.text.Document;
	var jPar = Packages.com.lowagie.text.Paragraph;
	var jFont = Packages.com.lowagie.text.Font;
	
	var font1 = new jFont();
	font1.setStyle(jFont.BOLD);
	font1.setFamily("Helvetica");
	font1.setSize(12);
	
	var baos = new jBaos;
	var doc = new jDoc;
	jRtfWriter2.getInstance(doc,baos);
	
	doc.setMargins(
		jUtils.millimetersToPoints(10),
		jUtils.millimetersToPoints(10),
		jUtils.millimetersToPoints(10),
		jUtils.millimetersToPoints(10)
	);
	doc.open();
	doc.add(new jPar("Hello World", font1));
	doc.close();
	
	var bytes = baos.toByteArray();
	return bytes;
}

Best regards. Roberto Blasco.

Thanks guys! That was very useful. In fact for the example I gave I ended up using the “dataset.getAsText(‘’,‘\n’,‘’,false)” to concatenate the column results partly because of a time crunch (I needed to demo it) and partly because it worked very well for this as I was just pulling back on ‘report’ at a time. But moving forward I am going to start working on big datasets and having this to get my Java going will be very useful.