web stats
Replace OBR/Orders request UID - OBR4.1 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-15-2012, 02:55 PM
ramblix ramblix is offline
What's HL7?
 
Join Date: Sep 2010
Posts: 5
ramblix is on a distinguished road
Red face Replace OBR/Orders request UID - OBR4.1

First of all I am a newbie. Need to figure out a way to create a transform or mapping that will look in OBR4.1 and change it from our code(s) to the receiving code(s). Now some files will have multiple OBR lines and it needs to look at all of them.

For example:
OBR|1|177464-45||CPT-85025^CBC with Differential|||20120131||1||N|||||1922000942|||||| |||||^^^^^R
ORC|NW|177464-46|||||||20120131|||1922000942
OBR|1|177464-46||CPT-81000^Urinalysis|||20120131||1||N|||||1922000942|| |||||||||^^^^^R

The CPT-85025 needs to be replaced with "CBCN" and the CPT-81000 to "UA".

I was able to change it if there is only one OBR by using this:
if (msg['OBR']['OBR.4']['OBR.4.1'] == "CPT-85025")
{ msg['OBR']['OBR.4']['OBR.4.1'] = 'CBCN' };

Now I don't know if that is the right route.

Can anyone help? We will have about 30 different codes that need to be replaced.

Thanks,

Shareef Huddle
Reply With Quote
  #2  
Old 05-15-2012, 09:00 PM
glenn71 glenn71 is offline
OBX.3 Kenobi
 
Join Date: Nov 2010
Location: Sydney Australia
Posts: 129
glenn71 is on a distinguished road
Default

here is an example which I think is easy to manage / maintain.

Code:
// create a function that can be used to translate codes.
// the function caters for a default value if no match is found
// 'defValue'
function getMap (mapName, mapValue, defValue) {

	var mapResult = mapName.get(mapValue);
	if (mapResult != null) {
		return mapResult;
	} else {
		return defValue;
	}
}

// create translation maps
// below examples translate gender & next of kin types
// so a gender of 'M' returns '1'
var pid_genderMap = new Packages.java.util.HashMap ();
pid_genderMap.put ('M', '1');
pid_genderMap.put ('F', '2');
pid_genderMap.put ('""', '""');

var nk1_relationshipMap = new Packages.java.util.HashMap ();
nk1_relationshipMap.put ('Brother', 'SIB');
nk1_relationshipMap.put ('Companion', 'OTH');
nk1_relationshipMap.put ('Nil Contact', 'OTH');
nk1_relationshipMap.put ('Other', 'OTH');
nk1_relationshipMap.put ('Daughter', 'CHD');
nk1_relationshipMap.put ('Son', 'CHD');
nk1_relationshipMap.put ('Friend', 'FND');
nk1_relationshipMap.put ('Guardian', 'LGR');
nk1_relationshipMap.put ('Husband', 'SPO');
nk1_relationshipMap.put ('Wife', 'SPO');
nk1_relationshipMap.put ('Relative', 'EXF');
nk1_relationshipMap.put ('Sister', 'EXF');
nk1_relationshipMap.put ('Parent', 'PAR');
nk1_relationshipMap.put ('Partner', 'DOM');
nk1_relationshipMap.put ('""', '""');

// now process the msg
msg['PID']['PID.8']['PID.8.1'] = getMap(pid_genderMap, msg['PID']['PID.8']['PID.8.1'].toString(), '');

for each (nk1 in msg.NK1)
{
	nk1['NK1.3']['NK1.3.1'] =  
			getMap(nk1_relationshipMap, nk1['NK1.3']['NK1.3.1'].toString(), '');
	
}
Reply With Quote
  #3  
Old 05-15-2012, 09:05 PM
glenn71 glenn71 is offline
OBX.3 Kenobi
 
Join Date: Nov 2010
Location: Sydney Australia
Posts: 129
glenn71 is on a distinguished road
Default

Another thing to add to the above example. This is a form of 'hard coding'.. ideally this translation should be held in a application / database so someone other than me can maintain the code translations. Ideally I would read in the translation codes from a database (but not for every message otherwise performance might take a hit).

This is what I am working on as stage 2 of the solution.
Reply With Quote
  #4  
Old 05-16-2012, 04:13 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

Here's another (just as valid as glenn71's method) way to do it:

Code:
var codeMap = {
	'CPT-85025': 'CBCN',
	'CPT-81000': 'UA'
	// Add others as necessary
};

for each (obr in msg.OBR)
	obr['OBR.4']['OBR.4.1'] = codeMap[obr['OBR.4']['OBR.4.1'].toString()] || 'Unknown';
As glenn71 suggested, if you're going to be using this translation (or others like it) in other channels, it would certainly make it much easier for you by placing the values in a database and reading from it. Here's an example of how I'd do it:

Deploy Script
Code:
importPackage(java.sql);
new com.mysql.jdbc.Driver();
var dbConn = DriverManager.getConnection('jdbc:mysql://localhost:3306/test','user','pass');
$gc('codeMap',{});
var rs = dbConn.prepareStatement('select code, alias from code_map').executeQuery();
while (rs.next())
	$gc('codeMap')[rs.getString(1)+''] = rs.getString(2)+'';
dbConn.close();
return;
Transformer
Code:
for each (obr in msg.OBR)
	obr['OBR.4']['OBR.4.1'] = $gc('codeMap')[obr['OBR.4']['OBR.4.1'].toString()] || 'Unknown';
Doing the database work in the deploy script rather than the transformer will reduce your overhead significantly, especially if you're connecting to a remote database. Of course, when you make changes in the database you'll have to re-deploy the channel in order for those changes to be reflected, but I actually think that's a better/safer way to do things anyway.

Last edited by narupley; 05-16-2012 at 04:28 AM.
Reply With Quote
  #5  
Old 05-16-2012, 05:56 AM
Tracie Tracie is offline
Mirth Newb
 
Join Date: Feb 2012
Posts: 15
Tracie is on a distinguished road
Default

Just wanted to say a Huge Thank you for this code...I was having this exact issue today and this has solved it perfectly for me!

once again - this forum has been a life saver!

Take care
Tracie
Reply With Quote
  #6  
Old 05-16-2012, 08:57 AM
ramblix ramblix is offline
What's HL7?
 
Join Date: Sep 2010
Posts: 5
ramblix is on a distinguished road
Smile Thank You!

Exactly what I needed. Thank you all!
Reply With Quote
  #7  
Old 05-16-2012, 06:36 PM
glenn71 glenn71 is offline
OBX.3 Kenobi
 
Join Date: Nov 2010
Location: Sydney Australia
Posts: 129
glenn71 is on a distinguished road
Default

Fantastic narupley... I am going to steal your deploy script :-).
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 10:18 AM.


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