Thursday, December 8, 2022
Home Integration/Interfaces Why You Must Understand the Difference Between Mirth's Channel Map, Global Channel...

Why You Must Understand the Difference Between Mirth’s Channel Map, Global Channel Map, and Global Map Right Now


  • Familiarity with map data structures
  • Knowledge of Mirth Connect

If you’ve worked with Mirth for any significant period of time, you know that Mirth uses various maps for developers to utilize at different scopes. The three maps that often get confused are the Channel Map, the Global Channel Map, and the Global Map.

The only difference between these three maps is their scope. Functionally, they all behave the same way. The names of the maps actually describe the scope fairly accurately. Nevertheless, we have summarized the maps and their scopes below.

Map NameChannel ScopeMessage Scope
Channel MapExists per channelMap is cleared for each subsequent message
Global Channel MapExists per channelMap is not cleared for each subsequent message
Global MapExists across all channelsMap is not cleared for each subsequent message

To understand the above you need to understand Channel Scope and Message Scope. These two important concepts demonstrate the levels and locations that maps operate.

Channel Scope: Does this map exist for each channel or is just one map used across all channels?

When a map exists for each channel it means that there is an instance of that map for every deployed channel. For example, you could have an ADT Inbound channel and a Materials Inbound channel. Both would have their own channel map with a different set of key-value pairs. Both of these channels would also have their own global channel map.

Furthermore, there is only one global map in a Mirth instance. This singular map exists for all deployed channels. This means that, for example, a key-value pair could be created in one channel, and then that same value could be changed by a different channel.

Message Scope: Does Mirth start with an empty map at the beginning of each message?

Channel maps get cleared (all key-value pairs removed) at the start of every new message. For example, an A01 comes into your ADT Inbound channel, which populates variables in the channel map. At a later time, an A08 comes in. When the A08 comes in, none of the values in the channel map from the A01 will be present. In fact, nothing will be inside the channel map when the source connector begins processing the A08. Again, the channel map is cleared out for each subsequent message.

The key-value pairs for global channel maps and the global map persist across multiple messages. In other words, these maps are not cleared when subsequent messages come in. For example, The first message that comes in could create a key-value pair, and the next message that comes in could update the value for that same variable (key) without re-creating the key-value pair entirely. If you are working with the global map, this could happen across multiple channels and if you are working with the global channel map, this could occur with the same channel.

Example Cases

Channel Map

  • Logging status messages to track program execution
  • Key data values for HL7 fields
  • Debugging
  • Counting the number of iterations in an important loop
  • Storing the binary data of a file in variable so that it can be sent out via a destination connector
  • Viewing data returned by a SQL query
  • Formatting the name of a file to be used in a destination connector

Global Channel Map

  • Running count of A08s for one ADT channel
  • Running count of A03s for one ADT channel
  • Adding up the total cost of case materials for a material use channel
  • Running count of messages that come from a particular system (i.e. SCM) for one channel
  • Keeping a running average of the height and weight for patients coming through an ADT channel

Global Map

  • Running count of all ORU messages across all channels
  • Running count of all ADT messages across all channels
  • Running count of messages that come from a particular system (i.e. SCM) across all channels
  • Adding up the number of cases that come in for each procedure date across all channels
  • Running count of messages that come from a particular facility across all channels

Getting and Putting Variables in Maps

Map NameJavaScript Put StatementJavaScript Get Statement
Channel MapchannelMap.put(key, value);channelMap.get(key);
Global Channel MapglobalChannelMap.put(key, value);globalChannelMap.get(key);
Global MapglobalMap.put(key, value);globalMap.get(key);


 * Channel Map
var fileName = "CSVExport";
channelMap.put('fileName',fileName + '_' + DateUtil.getCurrentDate('yyyyMMdd'));

var fileName = channelMap.get('fileName');

 * Global Channel Map
var messageType = msg['MSH']['MSH.9']['MSH.9.2'].toString();
if (messageType == "A08") {
globalChannelMap.put('A08 Count', countA08);

var count = globalChannelMap.get('A08 Count');

 * Global Map
var sendingFac = msg['MSH']['MSH.4']['MSH.4.1'].toString();
if (sendingFac == "University Hospital") {
globalMap.put('UH Count', countUH);

var count = globalChannelMap.get('UH Count');

Why You Must Learn Mirth Connect’s User API Now

Prerequisites Basic knowledge of Mirth ConnectBasic knowledge of JavaScriptBasic knowledge of software documentation and APIsBasic knowledge of Java development NextGen provides several different APIs (Application Programming...

Leverage Mirth’s Channel Scripts Now

Prerequisites Basic knowledge of Mirth ConnectBasic knowledge of JavaScript Each Mirth Connect channel gives you the ability to leverage four different scripts that have different triggers,...

Reference a Custom Jar File in Mirth Connect Now

Prerequisites Knowledge of Java developmentKnowledge of Eclipse or another Java IDEKnowledge of Mirth Connect Many Mirth professionals are unaware that they can write their own custom...

Most Popular

Mirth Connect Extensions: What You Need to Know

Prerequisistes Basic Knowledge of Mirth Connect Overview Users can navigate to Mirth Connect's Extensions screen by selecting Extensions on the left-hand side. You should now see the following...

Take a Tour of System Settings in Mirth Connect Now

Prerequisites Basic Knowledge of Mirth Connect Introduction Mirth Connect has a multitude of system settings that are available for configuration. In larger companies, there will often be...

Why You Must Master Mirth’s Message Template Tool Today

Prerequisuites Basic Knowledge of Mirth ConnectKnowledge of Programming in Mirth Connect Introduction When writing scripts in Mirth Connect, you have a message template tool that allows you...

Make Sense of HL7 v2 Messages Effortlessly Now

Prerequisites Beginner Knowledge of HL7 Introduction If you've been in Healthcare Information Technology for any period of time, you have definitely heard of HL7 (Health Level 7)....

Recent Comments