web stats
Building OBX field + adding to string - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2020, 10:32 AM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default Building OBX field + adding to string

I'm not sure how to even start explaining this one. This code & setup existed before I was around, and I'm trying to make sense of it. If anyone can look at this and needs more info, I'll get whatever you need! Thank you


The channel is attached (in question is destination transformer #3).


This 1st part of the code is to create the OBX-5 field data. This works fine:

Code:
for (var i = 0; i < msg['OBX'].length(); i++)

{

var obx3dot1 = msg['OBX'][i]['OBX.3']['OBX.3.1'].toString();

//var contrast = obx3dot1.startsWith('RADLLR', 0 );

var obx3 = msg['OBX'][i]['OBX.3']['OBX.3.2'].toString();

var obx5 = msg['OBX'][i]['OBX.5']['OBX.5.1'].toString();

var obx6 = msg['OBX'][i]['OBX.6']['OBX.6.1'].toString();


var obr4_1 = msg['OBR']['OBR.4']['OBR.4.1'].toString(); 
var obr4_2 = msg['OBR']['OBR.4']['OBR.4.2'].toString(); 

 

var obx5dot2 = obx3.concat('Given:',obx5, obx6);

 
if (obx3dot1.substring(0,6)  ==  'RADLLR')



{
                                msg['OBX'][i]['OBX.2']['OBX.2.1'] = 'CE';

                                msg['OBX'][i]['OBX.3']['OBX.3.1'] = obr4_1 ; //msg['OBR'][i]['OBR.4']['OBR.4.1'].toString();

                                msg['OBX'][i]['OBX.3']['OBX.3.2'] = obr4_2 ; //msg['OBR'][i]['OBR.4']['OBR.4.2'].toString();

                                msg['OBX'][i]['OBX.5']['OBX.5.1'] = 'Contrast';

                                msg['OBX'][i]['OBX.5']['OBX.5.2'] = obx3.concat(' ','Given:',obx5,' ', obx6);

}

The above takes a source message like this:

OBR|1|308550745^EPC|TF6661159|CT1059^CT CHEST W CONTRAST^CT1059^^CT CHEST W C|STAT|202002201100|||||Norm|||||12222681^LAINE^JO NATHAN^E^^^^^SOMSER^^^^SOMSER|(530)582-3208|12222681|TFH CT ROOM|||20200220110200||CT|EXAM ENDED||^^^20200220112257^20200220112046^STAT||||^A bd trauma, blunt, stable;Right anterior inferior rib tenderness with splinting on that side|||ASHLEY||20200220110500||||||||CT1059^CT CHEST W CONTRAST^RADEAP^^CT CHEST W C|
OBX|1|ST|86437^SODIUM CHLORIDE 0.9 % (FLUSH) INJECTION SYRINGE||50|mL|
OBX|2|ST|86437^SODIUM CHLORIDE 0.9 % (FLUSH) INJECTION SYRINGE||10|mL|
OBX|3|ST|RADLLR88470^IOVERSOL 300 MG IODINE/ML INTRAVENOUS SOLUTION||100|mL|


And produces an outbound OBX that we want:

OBX|3|CE|CT1059^CT CHEST W CONTRAST||Contrast^IOVERSOL 300 MG IODINE/ML INTRAVENOUS SOLUTION Given:100 mL|mL|


Problems arise when we have TWO "RADLLR" values in different OBX segments, as the destination system can't receive repeated values like this:

OBX|3|CE|CT1059^CT CHEST W CONTRAST||Contrast^IOPAMIDOL 61 % INTRAVENOUS SOLUTION Given:50 mL|mL|
OBX|4|CE|CT1059^CT CHEST W CONTRAST||Contrast^IOVERSOL 300 MG IODINE/ML INTRAVENOUS SOLUTION Given:100 mL|mL|


We need to the output to "Contrast" and "Contrast1". How can that be done?
Reply With Quote
  #2  
Old 02-26-2020, 10:39 AM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default

Here is one method we tried so far, which works in a sense but does so incorrectly. I can't identify what it's stumbling on.


Code:
for each (obx in msg['OBX']) {

//look for setID greater than 1, indicating possible multiple RADLLR values

    if ( obx['OBX.1']['OBX.1.1'] > "1" ) {

//add a 1 to the "Contrast" string in OBX.5.1
        obx['OBX.5']['OBX.5.1'] = obx['OBX.5']['OBX.5.1'].toString() + "1";
Sometimes this works, sometimes it doesn't. When it doesn't, it adds "1" repeatedly AND at the other subcomponents of OBX.5. Example:

OBX|1|ST|86437^SODIUM CHLORIDE 0.9 % (FLUSH) INJECTION SYRINGE||50|mL|
OBX|2|ST|86437^SODIUM CHLORIDE 0.9 % (FLUSH) INJECTION SYRINGE||101111|mL|
OBX|3|CE|CT1059^CT CHEST W CONTRAST||Contrast11^IOPAMIDOL 61 % INTRAVENOUS SOLUTION Given:5011 mL|mL|
OBX|4|CE|CT1059^CT CHEST W CONTRAST||Contrast1^IOVERSOL 300 MG IODINE/ML INTRAVENOUS SOLUTION Given:100111 mL|mL|


Clearly something is wrong with the code, but what? Why is this wrong, what is it doing instead of our intention?
Reply With Quote
  #3  
Old 02-26-2020, 02:12 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road
Default

Add this before you begin the loop in the first line code in your first post.
Code:
var contrastCount = -1;
And then when you are setting obx.5.1
Code:
msg['OBX'][i]['OBX.5']['OBX.5.1'] = 'Contrast' + ((++contrastCount > 0) ? contrastCount : '');
I'm not sure what's going on with your second post without seeing all of the code, but my guess is that loop is inside of another loop.
Reply With Quote
  #4  
Old 02-26-2020, 05:46 PM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default

Quote:
Originally Posted by agermano View Post
Add this before you begin the loop in the first line code in your first post.
Code:
var contrastCount = -1;
And then when you are setting obx.5.1
Code:
msg['OBX'][i]['OBX.5']['OBX.5.1'] = 'Contrast' + ((++contrastCount > 0) ? contrastCount : '');
I'm not sure what's going on with your second post without seeing all of the code, but my guess is that loop is inside of another loop.
Thanks for the response! I put that in but the "Contrast" value in OBX.5.1 is being left alone in the end. Both segments end up w/"Contrast" still. I'm currently messing with it to see if I got it wrong, but I did what you suggested. The new var is the very 1st line of code, and then I replaced the OBX.5.1 designation w/the statement you wrote.
Reply With Quote
  #5  
Old 02-26-2020, 06:10 PM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default

Here's the whole code. I removed the 2nd part that wasn't working correctly anyway.

Now I'm again getting "Contrast" in OBX.5.1 for both segments that match the criteria. Does this have to do w/recalling the raw OBX.5.1 value and then re-assigning the output OBX.5.1 in the same transformer?


Code:
var contrastCount = -1;

for (var i = 0; i < msg['OBX'].length(); i++)

{

var obx3dot1 = msg['OBX'][i]['OBX.3']['OBX.3.1'].toString();

var obx3 = msg['OBX'][i]['OBX.3']['OBX.3.2'].toString();

var obx5 = msg['OBX'][i]['OBX.5']['OBX.5.1'].toString();
//recalling the med measurement in source OBX.5.1

var obx6 = msg['OBX'][i]['OBX.6']['OBX.6.1'].toString();

var obr4_1 = msg['OBR']['OBR.4']['OBR.4.1'].toString();

var obr4_2 = msg['OBR']['OBR.4']['OBR.4.2'].toString();

var obx5dot2 = obx3.concat('Given:',obx5, obx6);

 

 

if (obx3dot1.substring(0,6)  ==  'RADLLR')

{

                                msg['OBX'][i]['OBX.2']['OBX.2.1'] = 'CE';

                                msg['OBX'][i]['OBX.3']['OBX.3.1'] = obr4_1 ;// msg['OBR'][i]['OBR.4']['OBR.4.1'].toString();

                                msg['OBX'][i]['OBX.3']['OBX.3.2'] = obr4_2 ;


msg['OBX'][i]['OBX.5']['OBX.5.1'] = 'Contrast' + ((++contrastCount > 0) ? contrastCount : '');
// assigning "Contrast" for output OBX.5.1


                                msg['OBX'][i]['OBX.5']['OBX.5.2'] = obx3.concat(' ','Given:',obx5,' ', obx6);
Reply With Quote
  #6  
Old 02-26-2020, 06:24 PM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default

Aha! I overlooked a couple typos in the other field assignments. Once I caught & corrected those, the rest worked out.

Problem solved ... until they come up with something else

Thanks again for the tip on automatic counting; I knew I had to do that, I just couldn't figure out the syntax & statement to make it happen.
Reply With Quote
  #7  
Old 02-26-2020, 07:19 PM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 173
stormcel is on a distinguished road
Smile

Quote:
var conCount = 0;
var chkStr = "Contrast";

for each (obx in msg['OBX']) {

var seg = obx['OBX.5']['OBX.5.1'].toString()
//check if it starts with Contrast
if(seg.lastIndexOf(chkStr , 0) === 0) {
conCount++
//add an incremented number to the "Contrast" string in OBX.5.1
obx['OBX.5']['OBX.5.1'] = seg.replace('Contrast','Contrast' + conCount);
}
}
this is untested.... is this right agermano?

Last edited by stormcel; 02-26-2020 at 07:21 PM.
Reply With Quote
  #8  
Old 02-27-2020, 06:57 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road
Default

Quote:
Originally Posted by stormcel View Post
this is untested.... is this right agermano?
That would need to be run after they had already been changed to Contrast, while my solution numbers them in the same loop while it is changing the value to Contrast. I'm only pointing this out as a difference and not saying your way is wrong.

However, your solution will use the values [Contrast1, Contrast2, Contrast3, ...] rather than [Contrast, Contrast1, Contrast2, ...].
Reply With Quote
  #9  
Old 02-27-2020, 07:00 AM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default

Quote:
Originally Posted by agermano View Post
That would need to be run after they had already been changed to Contrast, while my solution numbers them in the same loop while it is changing the value to Contrast. I'm only pointing this out as a difference and not saying your way is wrong.

However, your solution will use the values [Contrast1, Contrast2, Contrast3, ...] rather than [Contrast, Contrast1, Contrast2, ...].

That's good to make note of! In this case, the receiving system matches these values into tables which are named "Contrast" and "Contrast1". Why, I have no idea, but that's how it was set. Of course, that could be changed but being in the middle it's up to me to match what each side is working with if possible. I can absolutely see a time when we have to send unique, but not table-matching, values, and the 2nd idea above would be perfectly fine.

Sometimes the slightest difference makes ideas more useful or better suited for situations, so thanks for posting that up @stormcel.
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 06:19 AM.


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