HL7 Starter Kit – Free Project Tools HL7 Starter School

Mirth Connect – JavaScript Reader – Database Columns to XML December 1, 2017

DB to XML


If you are here, you are probably working in Mirth and trying to retrieve data from a database THEN convert those records to XML. If so, keep reading…

So, I found this on Mirth’s forum…

http://www.mirthproject.org/community/forums/showthread.php?t=10264
It was so helpful! Then it led me to write the code below in a Mirth channel’s SOURCE > JAVASCRIPT READER…

var result = null;
var msgList = new Packages.java.util.ArrayList();
var dbConn = null;
var dbQuery = "exec usp_GetScannedImages"; //SQL Server database command to run. In this case "GetScannedImages" is a stored procedure in the db.
var msgOut = ; //create XML

try
{
dbConn = getDBConnection("MyDatabaseName"); //function in a code template that gets database connection.

if (dbConn != null && ! dbConn.getConnection().isClosed())

{
result = dbConn.executeCachedQuery(dbQuery); //MirthCachedRowSet

while (result.next())
{
logger.debug("Looping in DB Conn: " );
logger.debug("Scanning MRN: " + result.getString('chartnum'));

msgOut.AcumenMRN = result.getString('chartnum'); //add database column to XML object
msgOut.EpicRMN = result.getString('EpicMRN'); //add database column to XML object
msgList.add(msgOut); //add XML object to a list to send through to Mirth Channel
}

return(msgList); //return an XML to the Mirth Channel
}
else
throw 'Error getting db connection in channel: Acumen_1 IKDH Scanning To Acumen_2 7012.';
}
catch(ex)
{
throw 'Error in Acumen_1 IKDH Scanning To Acumen_2 7012 source connector. Error: ' + ex.toString();
}


That’s it!

close

Mirth Connect – JavaScript Reader – Database Columns to XML

Leave a Reply

ViSO Tech

ViSO Tech

Thank you for visiting! Click Facebook icon above and let's connect.

Mirth Connect – JavaScript Reader – Database Columns to XML December 1, 2017

Search