'Mirth - basic HL7 to HL7 transformation question

new to Mirth, not new to engines... finding it a bit challenging to do a basic source to destination HL7v2 transformation.

I've set up my Channel to read from a file as the source, and spit out the destination to a file as well. My output template is ${message.encodedData}. The channel seems to be reading the source correctly, and generating an output. But what I'm struggling with is how cumbersome this is.

I'm playing with an HL7 SIU message, my source has a lot more fields than the destination wants to receive, just need a simple way to map the few fields that are required.

I inserted the source system message template into the Destination Transformer Inbound Message Templates, then I'm doing the following which seems to work:

//MSH Segment
if (msg['MSH'][0]){
    var MSH1 = msg['MSH']['MSH.1'];
    var MSH2 = msg['MSH']['MSH.2'];
    var MSH7 = msg['MSH']['MSH.7'];
    var MSH9 = msg['MSH']['MSH.9'];
    
    msg['MSH'] = '';
    msg['MSH']['MSH.1']=MSH1;
    msg['MSH']['MSH.2']=MSH2;
    msg['MSH']['MSH.7']=MSH7;
    msg['MSH']['MSH.9']=MSH9;

}

Rinse and repeat for the segments that I need, seems very painful to me.

On a second destination, I'm trying to leverage the Inbound and Outbound Message Template. Inserted the source system template as above, inserted the destination system template in Outbound Message Template. My Javascript for that one looks something like this:

//MSH Segment
if (msg['MSH'][0]){
    tmp['MSH'] = "";
    tmp['MSH']['MSH.1'] = msg['MSH']['MSH.1'];
    tmp['MSH']['MSH.2'] = msg['MSH']['MSH.2'];
    tmp['MSH']['MSH.7'] = msg['MSH']['MSH.7'];
    tmp['MSH']['MSH.9'] = msg['MSH']['MSH.9'];
}

It's cleaner, but doesn't seem to work properly, in some messages, my source doesn't have a PV1 segment, but the output contains the sample PV1 segment in the Output Message Template. Do I need to have an initial statement that is tmp = "";

There has to be a easier way to accomplish what I'm trying here, any advise is appreciated!

M



Solution 1:[1]

Eventually figured out a different route. Removed the outbound template entirely and built the outbound message from scratch. Here's a snapshot of what it looks like.

    var output = <HL7Message/>;

//MSH Segment
createSegment('MSH',output);
output.MSH['MSH.1'] = msg['MSH']['MSH.1'];
output.MSH['MSH.2'] = msg['MSH']['MSH.2'];
output.MSH['MSH.7'] = msg['MSH']['MSH.7'];
output.MSH['MSH.9'] = msg['MSH']['MSH.9'];

//SCH Segment
if (msg['SCH'][0]){
    createSegment('SCH',output);
    output.SCH['SCH.1'] = msg['SCH']['SCH.1'];
    output.SCH['SCH.2'] = msg['SCH']['SCH.2'];
    output.SCH['SCH.6'] = msg['SCH']['SCH.6'];
    output.SCH['SCH.7'] = msg['SCH']['SCH.7'];
    output.SCH['SCH.8'] = msg['SCH']['SCH.8'];
    output.SCH['SCH.11'] = msg['SCH']['SCH.11'];
    output.SCH['SCH.12'] = msg['SCH']['SCH.12'];
    output.SCH['SCH.16'] = msg['SCH']['SCH.16'];
    output.SCH['SCH.25'] = msg['SCH']['SCH.25'];
}

var message = SerializerFactory.getSerializer('HL7V2').fromXML(output);
channelMap.put('outmsg',message);

And then in my destination, I use ${outmsg} for the Template.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mtaa_hl7