Mirth: Making sure that dev/test code doesn’t get into LIVE (Is this lazy, or just accommodating reality?)

In a perfect world database connections and other things that must be changed when you migrate code between environments are neatly stored in one place where they can be easily changed.

With Mirth you can do this using global maps,  however when you do that,  they are exposed to anyone who has appropriate access to Connect.

I get around this by declaring variables at the top of the filters or transformers where I make database calls.

One of the things with my position is that I wear many hats and am the organization’s ‘go to’ for a great many things.  This means that interruptions are frequent.

This means that I when I’m doing something like preparing an interface to move from TEST to PRODUCTION that I can miss things.

Some of you might scoff,  but that is the reality of my world,  and almost 50 years on this planet has taught me that reality is often very far from ideal,   so you plan for reality.

I’m working on a project where I reach out to a couple of databases to pull data that isn’t included in the HL7 message.

Some of the transformations are complex,  and things were complicated by very tight deadlines,  and a situation where the spec “needed clarification”.  (as in I built my end to spec but they wanted a change).

Those of you familiar with this reality thing will know that this often leads to kludged together solutions.

After spending several hours making sure that our iPeople Echo downloads were moving the correct data from our test environment and copying/altering stored procedures and SQL functions I finally got to combing through my Mirth interface to make the changes there.

To give you an idea of the complexity,  I have 13 transformers in my source connector.

I realized that when I moved this to Live that there were too many potential failure points and wanted to prevent them.

So I added this code to my source filter:

var channelName = ChannelUtil.getDeployedChannelName(channelId);

if (channelName.indexOf('LIVE') > -1) {

logger.error('******************** CHECK ' + channelName + ' FOR DEV/TEST SETTINGS! ****************');
 return false;

return true;

/* Changes for Live
-remove anonymizer
-change db settings in source PID, PV1, OBR and ZDR
-change db settings in destination MR PID transformer


Hey look…a checklist of sorts!

My thinking is that if I forgot to make this very basic change that I’ll look and wonder why all my messages are being filtered!

But then I got to thinking of how many times I’ve been interrupted today and what would happen if I missed a single change…

So I wrote this:

function envcheck(sql,strTest,strLive) {

 var channelName = ChannelUtil.getDeployedChannelName(channelId);

 if (channelName.indexOf('LIVE') > -1) {

 logger.error(channelName + ' **** CHANGE SQL STATEMENT FOR LIVE ' + sql);

 sql = sql.replace(strTest,strLive);

 return sql;


Mirth: Monitor and Send Alerts every X hours


This is a very quick post as I want to link the code to someone asking a question on LinkedIn.

Any one who has dealt with Mirth alerts knows that you can get flooded by messages when there is a problem.

I wrote this channel to alert us every 3 hours if a problem occurred in a fairly important channel.

You can see in this code how I use the ChannelUtil class to collect data.

You can also use this class to control the channel and connectors.  Here’s the documentation.

Here’s the code that is in a javascript writer destination.

var olissr = '91d05f9d-6020-4ecc-b9fb-5301c77a1e0f'; //this is the target channel

var cstate = ChannelUtil.getChannelState(olissr).toString(); //declares the channel as a channel util object

//get the stats

var cQ = ChannelUtil.getQueuedCount(olissr);
var cE = ChannelUtil.getErrorCount(olissr);
var cS = ChannelUtil.getSentCount(olissr);

//get the previous stats from the globalChannelMap for comparison purposes.
var tq = globalChannelMap.get('tq');
var te = globalChannelMap.get('te');
var ts = globalChannelMap.get('ts');
var lt = globalChannelMap.get('curtime');
var ltms = globalChannelMap.get('timelastmsgsent');
var ltas = globalChannelMap.get('activitylastalert');
var ltaserror = globalChannelMap.get('errorlastalert');
var curtime = java.util.Calendar.getInstance().getTimeInMillis();
//puts the variables into the channelMap in case they're needed by the mailer.

var timediff = curtime - lt;




var errordiff = cE - te;
if (errordiff > 0) {

var leralert = ((curtime - ltaserror)/1000)/60;

if (leralert > 15) {

channelMap.put('AlertSubject','Errors on OLIS-SR Channel!');

var body = "There are errors on the OLIS-SR Channel!\nErrorCount: " + te + "\nDifference in error count since last check: " + errordiff + "\n";


ics = parseInt(cS);
its = parseInt(ts);

var ds = cS - ts;

if (ds != 0) {

ltms = curtime;

} else {
var timelag = ((curtime - ltms)/1000) / 60;

if (timelag > 60) {
var alertlag = ((curtime - ltas)/1000) / 60;

if (alertlag > 120) {


channelMap.put('AlertSubject','Inactivity on OLIS-SR Channel!');
channelMap.put('AlertBody','There has been no activity on the OLIS-SR Channel for ' + timelag + ' minutes!');



You know you should take a break from coding when…

Recently,  I was trying to get something in our Mirth Integration Engine working.  A project that was behind for a variety of reasons.

I was exhausted,  and stressed when co-workers heard me exclaim:

WTF do you mean its undeclared!   Its declared right there you stupid machine!!!

I waved my fist at the monitor in a threatening manner,  yet this infernal contraption kept telling me “variable mytpe undeclared in line 936″

I thought of EVERYTHING!   I checked to see if scope was the issue,  I was pretty sure it wasn’t.  I thought maybe its a datatype thing,  which made no sense at all…

Finally, in a fit of frustrated rage I walked away, grabbed a coffee, and paced around for a bit before going back to it.

I then took another look at the code

var mtype = msg['MSH']['MSH.10']['MSH.10.1'].toString();

if (mytpe.indexOf('D') > -1) {


I checked everything except spelling!

There’s a few minutes of my life I’ll never get back.

Javascript: Function that returns status for specified Facebook API permission

I’m working on an application where I want to use Facebook user authorization.

Being someone who is wary of over-granting permission to applications there are permissions I only want to ask for if the user is going to do something where they’re needed.

One of these is the friends list.  As the application will allow the user to invite other people as administrators and managers for their particular group,  I only want access to the friends list if this is something they want to do.

I came up with the following function to do the check for a specific permission.

Its important to remember that the user must grant you permission to access their profile,  and are logged in prior to using this function.

First you must ensure that you do initialize your Facebook connection using your application ID.

window.fbAsyncInit = function() {
appId : 'your app id here',
xfbml : true,
version : 'v2.2'

You can get your Facebook App ID here.

In testing, I called it after getting a connected status response from FB.getLoginStatus.

This is the code that calls the function.

This function is synchronous!  That means the script will NOT wait for it to return a value.

….so call it and store the values on initialization, or page load….or before you need it.

FB.getLoginStatus(function(response) {
if (response.status === 'connected') {

FB.api('/me', function(medata) {

//do stuff here


If you’re wondering what the medata object looks like…here it is:

"name":"David Rothbauer",

Now, the function itself:

function checkfbpermission(perm) {

I loop through the child objects permission and status sequentially, the found boolean will tell me when to return the status value

 var found = false;  
 for (var k in data) {
 console.log(JSON.stringify(data[k])); //this is useful for checking that the permission that you're looking for actually exists!
 for (var i=0;i<data[k].length;i++)
 for (var x in data[k][i]) {
 if (found == true) {
  return data[k][i][x];
 if (x == "permission" &&
 data[k][i][x] == perm) {

 //this will tell the script to return the value of the next object (status)
 found = true;
 else {
 found = false;
 return 'no data';

I’m still working out how to best leverage Facebook user integration into my application. I will post more solutions that I think might be helpful as I develop them.

Mirth Integration: Iterate through specific HL7 segments

Many of us in the healthcare integration community use the Mirth Integration Engine for HL7 and other integration needs.

In the past I’ve been active on the Mirth Community Forums as Bostad,  both asking and answering questions.  I haven’t been that active lately as my duties don’t leave me much time.

I do sometime receive direct requests,  and it was one of those that prompted me to start posting some of my Mirth programming tips here.

If you’re curious about healthcare integration and/or HL7 messaging, you can read about it here.

When required to iterate through repeating segments of an HL7 message,  here’s my method:

var i = 0;   //iteration variable
for each (seg in msg..ROL) {   //iterates through each ROL segment of an incoming HL7 message


if (seg['ROL.3']['ROL.3.1'].toString() != 'FAMILY DOCTOR')  {

   channelMap.put('ROL ' + i,'Not Family Doc');


In the code above,  you’ll note that the variable seg holds the current iteration of the target segment.

You’ll also note that the code above doesn’t do anything useful…I don’t want to flood you with a bunch of lines of code that aren’t helpful.

To reference specific fields within the segment,  unlike when referencing msg or tmp objects,  you do not use the initial segment name as an index!

//referencing msg and tmp

var strM = msg['ROL']['ROL.3']['ROL.3.1'].toString();
var strT = tmp['ROL']['ROL.3]['ROL.3.1'].toString();

//referencing seg (from within implied loop)

var strS = seg['ROL.3]['ROL.3.1']..toString();

If anything is unclear,  or you have further questions, feel free to ask in comments.

JQUERY: Handle a click event on an HTML element within another clickable element

Confusing title?

Let me explain:

I’m working on a project that will allow my employer’s senior team a patient census board. (I work for a hospital if the “patient” thing didn’t give it away).

As this project spans 4 different hospitals,  I present the initial data in collapsed tables,  populated by JQuery from an XML document passed from a PHP script.

In order to expand a table,  I allow the user to click the appropriate row.

Yesterday I was asked to add some new functionality that would allow the user to call up a list of patients by clicking on a column within that row.

The information in this column is wrapped in a span for display purposes,  so I hooked onto that.

Of course,  when I click on it,  both the span click event, AND the row click event fire!

I prevent this,  by placing the span click event handler above the row click event handler in the js file AND ending the span click even with return false;

This is how the table structure is set up

<th>header row</th>
<tr class="exoccclick">
<td>Another Thing</td>
<td><span class="pdcold">53</span></td>

And this is the click handling code for both the tr class (exocclick) and the span class (pdcold)


var tbid = $(this).closest('table').attr('id');

console.log('pdcclick ' + tbid);

return false;  //<--don't forget this bit!


//some stuff


As this is internal I can’t link the actual page,  but here’s a screen shot of what the row looks like:

The Pend DC Old column is the span class where I added the click handler

The Pend DC Old column is the span class where I added the click handler (click to enlarge)

JQuery/HTML: Handling events for elements created after initial page load.

My regular readers already know that I add a lot of stuff to my pages programmatically using PHP. Naturally much of this code is added after the initial page load.

I used to defeat this by loading in the scripting with the new elements, but that’s very tedious, and honestly, sloppy.

The issue is that new elements aren’t registered with the Document Object Model (DOM) set up when the page loads.

To get around that you can sort of “pre-register” these elements using JQuery’s .on method.

Here’s the syntax:

$(document).on([event],[selector],function(e) {

//do your stuff here


Here’s a working example from an actual piece of code I’m working on.

In this example I’m posting data to a php script when the target element (id=”edname_1″) loses focus, provided it doesn’t match what’s there already. I do this by loading the contents of the control into txtval on the focusin event.

var txtval = '';    //global variable.
		    	txtval = $(this).val();   //loads global
					if ($(this).val() == txtval) {
						console.log("doing nothing");
					if($(this).val().length < 1) {
						alert("This shouldn't be blank");
				$.post('PHP/updateftable.php', {field: $("#activefld").val(), val: $(this).val()}) 
                                         In order to avoid having to add the db table primary key of the row I want to update to every element I add to the div,                         
                                         I created a hidden field and placed that key as the value.

					console.log(data);   //checks the output.

This example is from a piece of actual code for a project in development, so there’s some exception handling, etc. I haven’t done yet.