web stats
Hl7 Interface Built between Clinitek Analyzer Lab Device and an EMR System - Mirth Community

Go Back   Mirth Community > Open Source HIT > General Discussion

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2010, 12:09 PM
jcrace0001 jcrace0001 is offline
What's HL7?
 
Join Date: Nov 2010
Posts: 1
jcrace0001 is on a distinguished road
Default Hl7 Interface Built between Clinitek Analyzer Lab Device and an EMR System


The code below worked for using a source transformer on a channel to write a file to HL7 in the format I needed for our EMR. I removed the DB server name and username and password. It works flawlessly.

var isError = false;
var errorString = "";

// This line is equivalent to the preceding Message Builder steps
msg['MSH']['MSH.4']['MSH.4.1'] = 'BS';
msg['MSH']['MSH.5']['MSH.5.1'] = 'PERFORMING-LAB-3';

// Extract NTE segment info order number, set OBR.2, spitting on :, getting second piece
// DValue:123
var orderNumber = new String(msg['NTE'][1]['NTE.3']['NTE.3.1'].toString().split(":")[1]);
if (orderNumber.length <= 0)
{
isError = true;
errorString = "Invalid order number (empty)";
}

if (!isError)
{
try
{
var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('com.sybase.jdbc3.jdbc.SybDriver','jdbc:sybase:Td s:**ip of server***:port number of db?ServiceName=ims','username','password');

var sql = "";
sql += "select patient_master.patient_no, patient_master.lastname, ";
sql += "patient_master.firstname from dba.lab_order_hdr, dba.patient_master where ";
sql += "lab_order_hdr.patient_id = patient_master.id "
sql += "and lab_order_hdr.tran_id = " + orderNumber;

var patientChart = "";
var lastName = "";
var firstName = "";

var result = dbConn.executeCachedQuery(sql);

if (result != undefined) {
if (result.next())
{
patientChart = new String(result.getString("patient_no"));
lastName = new String(result.getString("lastname"));
firstName = new String(result.getString("firstname"));
}


} else {
isError = true;
errorString = "Invalid result from query";
}
} catch(exp) {
isError = true;
errorString = exp;
}

try
{
dbConn.close();
} catch(exp) {
// Ignore any error when attempting to close db connection
}

}

if (isError)
{
Packages.org.mozilla.javascript.Context.throwAsScr iptRunTimeEx(new java.lang.Exception(errorString));
}

// Make static change to Patient Chart Number
msg['PID']['PID.2']['PID.2.1'] = patientChart;

// Update PID.3.1 with order number
msg['PID']['PID.3']['PID.3.1'] = orderNumber;

// Update OBR.2.1 with order number
msg['OBR'][0]['OBR.2']['OBR.2.1'] = orderNumber;

//Make static change to Patient Name
msg['PID']['PID.5']['PID.5.1'] = lastName;
msg['PID']['PID.5']['PID.5.2'] = firstName;

// Pad PID to have 17 subfields
msg['PID']['PID.17']['PID.17.1'] = '';

// Remove NTE segments
delete msg['NTE'];

// Fix OBR.4: test ID and description
msg['OBR'][0]['OBR.4']['OBR.4.1'] = '123';
msg['OBR'][0]['OBR.4']['OBR.4.2'] = 'Urinalysis, dip stick';

//Add Collection Date to OBR.07
var dateString = DateUtil.getCurrentDate("yyyyMMdd");
msg['OBR']['OBR.7'] = dateString;

//Add Collection Date to OBR.14
var dateString = DateUtil.getCurrentDate("yyyyMMdd");
msg['OBR']['OBR.14'] = dateString;

// Add the reference range to all OBX [0-11] 7.1 segments

msg['OBX'][0]['OBX.7']['OBX.7.1'] = 'Negative'
msg['OBX'][1]['OBX.7']['OBX.7.1'] = 'Negative'
msg['OBX'][2]['OBX.7']['OBX.7.1'] = 'Negative'
msg['OBX'][3]['OBX.7']['OBX.7.1'] = '1.001-1.035'
msg['OBX'][4]['OBX.7']['OBX.7.1'] = 'Negative'
msg['OBX'][5]['OBX.7']['OBX.7.1'] = '5-9'
msg['OBX'][6]['OBX.7']['OBX.7.1'] = 'Negative'
msg['OBX'][7]['OBX.7']['OBX.7.1'] = '<=1.0'
msg['OBX'][8]['OBX.7']['OBX.7.1'] = 'Negative'
msg['OBX'][9]['OBX.7']['OBX.7.1'] = 'Negative'
msg['OBX'][10]['OBX.7']['OBX.7.1'] = 'Yellow'
msg['OBX'][11]['OBX.7']['OBX.7.1'] = 'Clear'

// Fix missing OBX date/time. copy from OBX.19.1 to OBX.14.1
for (var i=0;i<msg..OBX.length();i++)
{
msg..OBX[i]['OBX.14']['OBX.14.1'] = msg..OBX[i]['OBX.19']['OBX.19.1'].toString();


}


var maxCount = msg.OBX.length();
if (maxCount > 11) maxCount = 11

for (var i=0;i<=maxCount;i++)
{
// Extract field, convert to string to support length property test
var testField = new String(msg..OBX[i]['OBX.8']['OBX.8.1'].toString());
if (i == 10)
{
var testYellow = new String(msg..OBX[i]['OBX.5']['OBX.5.1'].toString());
if (testYellow == 'Yellow')
{msg..OBX[i]['OBX.8']['OBX.8.1'] = 'N';
} else {msg..OBX[i]['OBX.8']['OBX.8.1'] = 'H'
}
} else if (i == 11)
{var testClear = new String(msg..OBX[i]['OBX.5']['OBX.5.1'].toString());
if (testClear == 'Clear')
{msg..OBX[i]['OBX.8']['OBX.8.1'] = 'N';
} else {msg..OBX[i]['OBX.8']['OBX.8.1'] = 'H'
}
} else {
if (testField.length > 0)
{
// If a value exists, must be A, change to H
msg..OBX[i]['OBX.8']['OBX.8.1'] = 'H';
} else {
// No value exists, change to N
msg..OBX[i]['OBX.8']['OBX.8.1'] = 'N';
}
}
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:14 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation