web stats
Mirth Community - View Single Post - Mirth Tools: User defined functions
View Single Post
Old 05-31-2013, 12:18 AM
adsseoalpha adsseoalpha is offline
What's HL7?
Join Date: May 2013
Location: delhi
Posts: 3
adsseoalpha is on a distinguished road
Default hi...here is some info for you

User Defined Java Class in Mirth

In this tutorial we are going to see how to use an Userdefined Java class in Mirth. In this example, i have created a java class named Utility under org.amar.mirth package. My java class contains two userdefined functions.

UpperCase – To convert a String to UpperCase String

ConvertDOB – To convert date of birth to specified format (Ex: 19910518 to 18 May 1991)


package org.amar.mirth;

public class Utility
//Convert String to Upper Case
public String UpperCase(String str)
return str.toUpperCase();

//Convert DOB
//Example: 19910518 to 18 May 1991
public String ConvertDOB(String str)
String[] months={“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”, ”Aug”,”Sep”,”Oct”,”Nov”,”Dec”};
String format;
int mon=Integer.parseInt(str.substring(4,6));
format=str.substring(6)+’ ‘+months[mon-1]+’ ‘+str.substring(0,4);
return format;

Create a jar file with the same class name(Utility.jar). Copy the Utility.jar file to $MIRTH_HOME/lib/ directory. Now restart the mirth server so that the jar file can be recognized as a valid file by mirth next time.

In the source transformer, create a new step with JavaScript type and use the userdefined functions wherever necessary.

//Import the package
var util = new Packages.org.amar.mirth.Utility();
//Message Modifications

The variable util is the object reference to the Utility Class. Using this object you can access the methods defined in that class. The above code converts the patient name to uppercase name,date of birth to userdefined format and replaces the old one.

Last edited by narupley; 09-30-2013 at 07:35 AM.
Reply With Quote