How to generate two XML files from a single HL7 file and insert both into two different columns as a single record?

StackOverflow https://stackoverflow.com/questions/12721771

  •  05-07-2021
  •  | 
  •  

문제

I have Source Connector Type as 'File Reader' which is reading HL7 files and Destination Connector Type as 'Database Writer'. My database table has two columns

  1. Participant_Information
  2. SPR_Information

I want to transform a single HL7 file into two XML files one for Participant_Information column and other for SPR_Information column and need to insert both as a single record into the database table.

I'm able to insert one XML at a time but not able to find the way to insert both the XMLs as a single record into the database table.

Any help is really greatly appreciated!

도움이 되었습니까?

해결책

I'm basing this answer on both the question, and your response to me in the comments.

Please be aware that on my end, I am referencing version 1.8.2 of Mirth. If you are using something more recent, while I am confident that the techniques described here will still be valid, the user interface might deviate from my directions.

I present here two techniques for solving this problem. While I would personally lean towards Technique 1, if you are less confortable with Javascript and E4X, then Technique 2 will likely be preferential.

Technique 1.

Use a Javascript transformer instead of a Message Builder. The challenge with using a message builder is that it takes the input message, and transforms it into a single output message. Javascript give you more power, but only if you know the langauge.

a.

Use a single Javascript transformer to make two copies of the message. Transform each variable as needed using Javascript E4X notation, and then store them both in the channelMap.

// init local message variables
var messageParticipant= msg;
var messageSPR= msg.copy();

// messageParticipant transformations using E4X notation: example
messageParticipant['PID']['PID.5']['PID.5.1'][0] = 'Blah';


// messageSPR transformations using E4X notation: example
messageSPR['PID']['PID.5']['PID.5.1'][0] = 'Hey There';


// stick messages in channel map so they can be accessed in your SQL script
channelMap.put('messageParticipant', messageParticipant);
channelMap.put('messageSPR',messageSPR);

b.

Reference the two channelMap variables in your SQL code.

INSERT INTO report_queue (PARTICIPANT_IDENTIFICATION, SPR_Information)
VALUES (${'messageParticipant'}, ${'messageSPR'})

Technique 2.

If you are less comfortable with using Javascript for your transformations, you might find this technique a bit easier - though, I find it a bit trickier to explain.

Basically, you will have three destinations, and you will force them to execute in sequence. The first destination builds the XML for the PARTICIPANT_IDENTIFICATION, and the second destination builds the XML for the SPR_Information. The first two destinations don't actually send the messages anywhere other than the channelMap. The third destination utilizes the results of the first two, and runs the SQL code.

a.

On the summary tab, ensure that "Synchronize channel" is checked. This will force the three destinations to execute in sequence.

b.

On the destinations tab, in addition to the existing Database Writer, create two Javascript writers. Organize the three destinations to appear in this order:

Destination           Connector Type
---------------------------------------
Build Participant     JavaScript Writer
Build SPR             JavaScript Writer
SQL                   Database Writer

c.

Select destination "Build Participant," and in the Javascript text area, enter the following:

channelMap.put('messageParticipant', messageObject.getTransformedData());

d.

Select destination "Build SPR," and in the Javascript text area, enter the following:

 channelMap.put('messageSPR', messageObject.getTransformedData());

e.

In the Sql destination, use the same SQL code as in Technique 1.

INSERT INTO report_queue (PARTICIPANT_IDENTIFICATION, SPR_Information)
VALUES (${'messageParticipant'}, ${'messageSPR'})

f.

For each of the two Javascript destinations: i. Click "Edit Transformer" ii. Click the tab "Message Templates iii. In the section "Outbound Message Template," ensure that the datatype is set to XML. iv. Add all the transformer steps you require, and feel free to use type Message Builder. (in destination Build Participant, you will add transformer steps applicable to the Participant XML. Likewise for destination Build SPR).

g.

The SQL Destination should not have any transformers. If it does, they won't have any effect on the output.

Good Luck

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top