Get a channel’s state from code
Tue, Aug 10, 2010
One-minute read
Recently I had a scenario where I needed to know the state of one channel from within another in Mirth Connect. I couldn’t find anything readily available to do this, so I rolled my own Code Template to get the state.
Here’s the code for the template:
function GetChannelState(channel_id) {
var channel_status = "NA";
var channel_count = parseInt(Packages.com.webreach.mirth.server.controllers.ChannelStatusController.getInstance().getChannelStatusList().size());
for(var i=0;i<channel_count;i++) {
if (channel_id == Packages.com.webreach.mirth.server.controllers.ChannelStatusController.getInstance().getChannelStatusList().get(i).getChannelId()) {
channel_status = Packages.com.webreach.mirth.server.controllers.ChannelStatusController.getInstance().getChannelStatusList().get(i).getState();
}
}
return channel_status;
}
So you can now call the function, pass in the channel’s id that you want to check the state on, and you’ll get back one of the following (according to the ChannelStatus.java source file):
- STARTED
- STOPPED
- PAUSED
If the channel id isn’t found, the function will return an NA (or not available).
You probably already know this, but you can see all of your channel id’s on the channels page in Mirth:
Also, I’m going to try and find a cleaner way to do this eventually… but this worked in a pinch.