Implementing Mirth HL7 transformer to conditionally change a field

Matt Gutting picture Matt Gutting · May 1, 2012 · Viewed 7.1k times · Source

I'm using Mirth to read HL7 messages in. the EMR provider has requested that for physicians in a specified practice, we should insert a practice code in MSH field 6. I have a list of the physician codes; what I need is to say "If the physician code (ORC.12.1) is in this list, then change MSH.6 to this value." I'm not entirely sure how to do this, and unfortunately the Mirth documentation is (to put it lightly) rather sparse in this area.

I can get the transformer to extract the physician code - but how do I do the conditional update?

Answer

dividius picture dividius · May 1, 2012

You'll have to use a JavaScript Transformer Step.

Basically, it will look like:

var code = msg['ORC']['ORC.12']['ORC.12.1'].toString();
var msh6 = msg['MSH']['MSH.6'].toString();
if (isInMyList(code))
    msh6 = 'MySpecialReceivingFacility';

tmp['MSH']['MSH.6'] = msh6;

Recommend saving a transformer with a simple variable mapper out to file and inspecting the javascript for a jumpstart at basic error handling, etc.