- Understand the difference between an inbound and outbound channel
- Understand the array data type
- Understand data types in Mirth Connect
If you’ve spent any time developing in Mirth Connect, you probably remember learning how to use Mirth’s msg and tmp variables. See the table below for a quick summary comparing msg and tmp.
|msg||references the incoming message/data||var sendApp = msg[‘MSH’][‘MSH.3’][‘MSH.3.1’].toString();|
|tmp||references the outgoing message/data||tmp[‘MSH’][‘MSH.3’][‘MSH.3.1’] = “EPIC”;|
Developers need to know that a healthcare interface can either be inbound or outbound in reference to their application. An inbound interface comes from another application to your application while an outbound interface leaves your application and goes to another application.
Furthermore, when you are referencing data from an inbound interface in Mirth, you will want to use msg. Likewise, you are defining data for an outbound interface, you will want to use tmp. These concepts will be explored further in the following sections.
The first index tells Mirth that it needs to look at the MSH segment. The second index tells Mirth that it needs to look in the third field of MSH. Finally, the third index tells Mirth to look at the first component of the third field.
Note: If you are unfamiliar with how HL7 messages are structured click here to learn more.
Msg usually appears on the right-hand side of the assignment operator in code because we want to assign this data to a variable in order to use it throughout the rest of the channel code.
Additionally, msg works a bit differently with the HTTP Sender and destination connectors of that nature. When you call a web service using an HTTP Sender in Mirth, you will often get a response depending on if the web service responds with data.
This response data is returned to Mirth via the msg variable. However, this data is only available in the response transformer. That is because the destination transformer code is executed before the web service is called. Meaning, if you reference msg in the destination transformer you are referencing the original incoming message. This is important to keep in mind if you plan on using Mirth to call a web service that returns data.
Understanding how to use msg is absolutely vital because it is the data structure that allows developers to access the data needed to build an inbound interface. If developers cannot access incoming data, their inbound interface is effectively worthless.
A good practice when developing inbound interfaces is to have an initial step in your transformer where you create variables and initialize them from the data in msg. That way, you can use, reference, and manipulate these values in the remainder of your code.
Just as with msg, Mirth uses the same array indexing notation to reference the first component of MSH.3 for the outgoing message.
Tmp usually appears on the left-hand side of the assignment operator because we want to set the value of this data before Mirth sends it out to the receiving system. In other words, we are building the message to send out to the receiving system.
Understanding how to use tmp is so important because it is the data structure that allows developers to build a message for their outbound interface. If developers cannot set outgoing data, their outbound interface is worthless since there is no data to send to the receiving side.
When using tmp, it’s vital that you understand the requirements for the data types that you are using because you have to know the correct place to place data. For example, if your interface requires the HL7 data type then you need to know to place the patient account number from your system in PID.18.1.
This is also true for msg; however, when developing the interface, you only have control of what you put in the outbound message; however, the quality of the data from another system is out of your control.
Msg, Tmp, and Mirth Data Types
Mirth allows developers create channels with the following data types.
- Delimited Text
- HL7 v2.X
- HL7 v3.X
Regardless of the data type, developers can reference the data in msg or tmp using array indexing. However, this looks slightly different depending on the data type chosen.
If you are ever confused about these slight differences, take full advantage of Mirth’s message template tool. You can access this tool on the right-hand side of any transformer, filter, or response.
Paste an example message in either the inbound or outbound message template.
Next, click on the message trees tab.
Expand the elements of your message tree.
You can drag green nodes into the code editor and Mirth will form the correct reference for you. If you drag a variable from the inbound message tree then Mirth will use msg. Similarly, if you drag a variable from the outbound message tree then Mirth will use tmp.
For example, you can reference the first column in the first row of a delimited text file using the follow variable.
Take some time to change the data type on the message template and play around with msg and tmp in your channels.