Wednesday, 27 May 2015

Deleting files problem after reading with MIRTH Connect File Reader channel


I have set up a file reader channel as part of my architecture for an inbound HL7 system. It receives HL7 messages in text files to an FTP folder and is configured to pass the messages to a database writer staging channel before moving the file to a processed files folder




Except it wasn't working properly. The files were appearing in the Processed folder, but were not being removed from the FTP folder. Instead a file with the same name and a .ignore extension was appearing in the FTP folder. This worked in that the file was subsequently ignored, but was untidy...


After researching this issue I found that it is a permissions problem. I granted the Users group Full Control in the FTP folder (they only had Read and Execute) and the files are now deleted after processing.

Monday, 20 April 2015

Handling incoming repeating PID internal identifier fields using MIRTH Connect

Having previously explored how you can handle repeating segments in MIRTH Connect, I found that you can also handle repeating fields in the same way.

Suppose you have a PID segment with an internal patient ID list field containing 3 IDs, as in this example data:

PID|1|9081717170830.105031|9081717170830.105031~9081717170830.105032~9081717170830.105033||VELD^MOSHE^JESSIE^^^AE||19750626|M|||1954 WINTER PK  48^FRESNO^CLOVIS^CA^93612^USA|||||||731-31-6668|731-31-6668


You can use the same 'for each' code structure in the destination transformer that you use for repeating segments:


This will create an object in the channel map which you can use in a javascript destination step to write to the database...


Three records will be created for the above HL7 segment...


Monday, 13 April 2015

Writing repeating HL7 Segments using MIRTH Connect

I am posting this because it has taken me nearly 5 days of internet searching to paste together a working set of code from the Snippets I have found on the internet. I am using the MIRTH Connect Integration Engine to process incoming MLLP messages (from a test tool called HL7Spy) and write them to a SQL Server database.

The messages are hospital patient event messages, and are made up of segments, some of which may be repeated. In the example test message below, the NK1 (next of kin) segment is repeated, with two entries in the set (for the patient's father and mother).


It is easy to map and insert the non-repeating segments, but much harder to map and insert the repeating blocks. As I said, it took me a while to work out how to do it from the code snippets I found on the internet.

I had previously set up my Channel with a source to listen for the messages...


I then added a database writer destination specifically for testing my Javascript code. I added a step of type Javascript called NextofKin in the destination transformer and wrote the code shown to iterate through the NK1 segments and write the contents to an array called NokArray containing a set of objects called NoK.



$c('NoKArray',[]);

for each (seg in msg.NK1)
{
var NoK = {};
NoK.SetID = seg['NK1.1']['NK1.1.1'].toString();
NoK.Surname = seg['NK1.2']['NK1.2.1'].toString();
NoK.Firstname = seg['NK1.2']['NK1.2.2'].toString();
NoK.Relationship = seg['NK1.3']['NK1.3.1'].toString();

$c('NoKArray').push(NoK);
}

The code makes the NoKArray visible to the Channel Map (see it in the Destination Mappings on the right), so I can access it in the DatabaseWriter destination as follows...


// INSERT into NK1 repeating segment table
var sql3 = "INSERT INTO HL7_NK1_JAVA (source_message_id, source_message_type, set_id, nok_first_name, nok_surname, nok_relationship) VALUES (?, ?, ?, ?, ?, ?)";

for each (NoK in $('NoKArray'))
{
//logger.info('SetID: ['+NoK.SetID+'] Firstname: ['+NoK.Firstname+'] Surname: ['+NoK.Surname+'] Relationship: ['+NoK.Relationship+']');

var params3 = new Packages.java.util.ArrayList();
params3.add(connectorMessage.getMessageId());
params3.add($('mirth_type'));
params3.add(NoK.SetID);
params3.add(NoK.Firstname);
params3.add(NoK.Surname);
params3.add(NoK.Relationship);

var result3 = dbConn.executeUpdate(sql3, params3);
}

This will write one record for each next of kin for every message I filter through the channel.