PDA

View Full Version : Replacing a character in multiple OBX lines


wit-man
05-24-2012, 12:07 PM
First, forgive me if I use the wrong terminology or process as this is my first attempt at modifying a transformer.

I am trying to use javascript to remove a carat character in the OBX|5 field. So, for example, I want to change the following lines:

OBX|1|ST|BT^BLOOD TYPE^B^BLD TYPE^B||^OP|
OBX|2|ST|ABSGEL^ANTIBODY SCREEN GEL^B^ABS GEL^ABS||^NEGATIVE|

In this, I want to replace "^OP" with "OP" in the first line and I want to replace "^NEGATIVE" with "NEGATIVE" in the second line. Can someone assist.

I haven't tried it yet but can someone tell me if this looks correct:

-----------------------------------------

var str

for(var i=0;i<msg['OBX'].length();)
{
str = msg['OBX'][i]['OBX.5'].toString()
msg['OBX'][i]['OBX.5'].toString() = str.replace("^", "");
i++;
}

-----------------------------------------

Thanks.

wit-man
05-24-2012, 12:22 PM
Sorry, I think this should be:

var str

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

str = msg['OBX'][i]['OBX.5']
msg['OBX'][i]['OBX.5'] = str.replace("^","");

i++;
}


Emoticons are replacing some of the text.

wit-man
05-24-2012, 12:23 PM
OK, where do I disable the emoticons???

narupley
05-24-2012, 12:26 PM
If that's a sample message from your client, then they're sending you messages with the observation value in OBX.5.2 rather than OBX.5.1.

If that caret is meant to be literal, then the client is sending you technically invalid HL7 (they should be sending the caret as \S\ instead). In this case the best course of action (though not always feasible) is to go back to the client and get them to send you proper HL7.

Otherwise, it sounds like you just want the observation value to come in OBX.5.1 right? If so, do this:

for each (obx in msg.OBX)
for each (obx5 in obx['OBX.5'])
if (!obx5['OBX.5.1'].toString() && obx5['OBX.5.2'].toString()) {
obx5['OBX.5.1'] = obx5['OBX.5.2'].toString();
delete obx5['OBX.5.2'];
}

Note: If you want the above code to work for messages that have repeating OBX.5 fields, remember to check Parse Field Repetitions in the protocol settings.

narupley
05-24-2012, 12:27 PM
OK, where do I disable the emoticons???

Just use CODE tags.

wit-man
05-24-2012, 12:34 PM
Thanks for the reply. Where are the code tags?

This was the response from the vendor:

"Yes. The standard functionality of this interface feed is to always send a caret within OBX|5. Would you like to submit a custom request to have the caret removed? Are you running this feed through an interface engine? If so, can the engine reformat this field to be a single component?"

They have said that this is standard and not including it would not be normal.

Can you explain your script? Sorry, I come from a vbscript background, not javascript so I get some of it but not all. Still new to HL7 but yes, you are probably correct about it going in 5.1. Thanks again.

wit-man
05-24-2012, 01:25 PM
OK, let me take a stab at your script.

The ^ symbol is a separator(is that right?) so basically what you are doing is setting 5.1 equal to 5.2, then deleting 5.2? So something like this (using the example above):

Original:
^OP
5.1 = nothing
5.2 = OP

Now:
5.1 = OP
5.2 is deleted

Is that correct? I still don't know what some of the syntax equals but this looks like what you are doing.

narupley
05-24-2012, 01:35 PM
Thanks for the reply. Where are the code tags?

When you submit a reply on this forum, press the # button in the editing panel.

This was the response from the vendor:

"Yes. The standard functionality of this interface feed is to always send a caret within OBX|5. Would you like to submit a custom request to have the caret removed? Are you running this feed through an interface engine? If so, can the engine reformat this field to be a single component?"

They have said that this is standard and not including it would not be normal.

The representative you talked to may have a somewhat na´ve understanding of HL7 v2.x. Carets (or whatever gets placed in the first character position of MSH.2) represent field component separators. Saying "We always send a caret in OBX.5" doesn't clarify anything, because the exact position of component separators can change the entire meaning of a field. I think what the vendor representative meant to say is "We always send the observation value in OBX.5.2 rather than OBX.5.1." If that's the case, then the code example I shared should remedy the issue for you.

If, however, the vendor meant to say "We always include a literal caret at the beginning of the observation value in OBX.5.1", then the appropriate response would be "In that case, you should be escaping that literal caret, otherwise it's ambiguous and improper HL7, but we can fix it for you anyway." Here's an example of how you would fix that literal caret problem:

for each (obx in msg.OBX)
for each (obx5 in obx['OBX.5']) {
obx5['OBX.5.1'] = obx5['OBX.5.1'].toString() + (obx5['OBX.5.2'].toString()?'\\S\\'+obx5['OBX.5.2'].toString():'');
delete obx5['OBX.5.2'];
}

Or, if you're worried about other literal carets besides the first one, you could do this:

for each (obx in msg.OBX)
for each (obx5 in obx['OBX.5']) {
var newNode = <OBX.5/>;
newNode['OBX.5.1'] = XMLtoHL7(obx5).replace('^','\\S\\');
obx.children()[obx5.childIndex()] = newNode;
}

Look here for more info: http://www.mirthcorp.com/community/forums/showpost.php?p=24558&postcount=6

narupley
05-24-2012, 01:36 PM
OK, let me take a stab at your script.

The ^ symbol is a separator(is that right?) so basically what you are doing is setting 5.1 equal to 5.2, then deleting 5.2? So something like this (using the example above):

Original:
^OP
5.1 = nothing
5.2 = OP

Now:
5.1 = OP
5.2 is deleted

Is that correct? I still don't know what some of the syntax equals but this looks like what you are doing.

Yep, that's exactly right.

wit-man
05-24-2012, 01:48 PM
This still doesn't seem to be working. Here is my raw and encoded message:

Raw:
OBX|1|NM|K^POTASSIUM^L^POTASSIUM^T^100.0450^Potass ium Level^CHEM^CHEMISTRY^CHEM^C|1.1|^2.8|

Encoded:
OBX|1|NM|K^POTASSIUM^L^POTASSIUM^T^100.0450|1.1||

It looks like it is removing it completely. I tried:

for each (obx in msg.OBX)
for each (obx5 in obx['OBX.5']) {
obx5['OBX.5.1'] = obx5['OBX.5.1'].toString() + (obx5['OBX.5.2'].toString()?'\\S\\'+obx5['OBX.5.2'].toString():'');
delete obx5['OBX.5.2'];
}

narupley
05-24-2012, 01:50 PM
That should work, unless you have other code in the transformer, or an outbound template, etc. Can you post your channel here?

wit-man
05-24-2012, 02:01 PM
Here it is.

narupley
05-24-2012, 02:10 PM
Here it is.

You're using the strict parser; turn that off and it should work just fine. If you want to use the strict parser (HAPI) for other things, I'd suggest doing a bit of research (http://hl7api.sourceforge.net/) to figure out exactly what XML structure the message gets parsed into, and what requirements there are for each field.

wit-man
05-24-2012, 02:43 PM
I turned the strict parser off but will have to wait till tomorrow to test. I'll let you know. Thanks.

wit-man
05-25-2012, 08:58 AM
Hmm, still didn't seem to work. I turned off the strict parsing by doing this (and you can tell me if this is wrong or not):


Go into the channel
Click "Set Data Types"
Click "Properties" for my Outbound Destination Connector
Uncheck "Use Strict Parser"
Close the two open dialog boxes
Save the changes
Redeploy the channel


------------------------------------------------

However, I completely took out this new step with the javascript you sent and redeployed the channel. It is still stripping out that field. Something in Mirth is stripping the field out. I don't see anything in that channel that would be doing it. I see a reference in the Demographics writer destination for OBX5 but that is a different destination. That wouldn't affect my other destination, would it?

Any idea on where I would look to find out what might be doing this? Thanks.

narupley
05-25-2012, 09:25 AM
You'll need to uncheck that on the Source Connector Outbound properties, not the destination. IIRC, it was already unchecked on the destination anyway...

narupley
05-25-2012, 09:28 AM
However, I completely took out this new step with the javascript you sent and redeployed the channel. It is still stripping out that field. Something in Mirth is stripping the field out. I don't see anything in that channel that would be doing it. I see a reference in the Demographics writer destination for OBX5 but that is a different destination. That wouldn't affect my other destination, would it?

Any idea on where I would look to find out what might be doing this? Thanks.

Can you post your updated channel?

wit-man
05-25-2012, 10:42 AM
OK, after unchecking it in the Source Connector Outbound, it kind of worked. Except the "^" was replaced with "\S\", so instead of "^15", I had "\S\15".

wit-man
05-25-2012, 11:06 AM
When I took out \\S\\ from the script you sent, the value was there. What you put in looks like regular expressions but i am not too familiar with those. Can you tell me what this line does, specifically the part within the parentheses:

obx5['OBX.5.1'] = obx5['OBX.5.1'].toString() + (obx5['OBX.5.2'].toString()?'\\S\\'+obx5['OBX.5.2'].toString():'');

It looks like this part "obx5['OBX.5.1'].toString()" is setting it to OBX5.1, which should be nothing + the rest of the line in parentheses but i don't know what the rest means, specifically the "?" and ":" and what follows those. Thanks again. I feel I am close.

narupley
05-25-2012, 11:38 AM
OK, after unchecking it in the Source Connector Outbound, it kind of worked. Except the "^" was replaced with "\S\", so instead of "^15", I had "\S\15".

I did this because that's proper HL7. If you really want you can simply choose to propagate the same error that your vendor did, in which case you can just leave the message alone, and the encoded data will come out the same as the raw data, at least for OBX.5.

When I took out \\S\\ from the script you sent, the value was there. What you put in looks like regular expressions but i am not too familiar with those. Can you tell me what this line does, specifically the part within the parentheses:

obx5['OBX.5.1'] = obx5['OBX.5.1'].toString() + (obx5['OBX.5.2'].toString()?'\\S\\'+obx5['OBX.5.2'].toString():'');

It looks like this part "obx5['OBX.5.1'].toString()" is setting it to OBX5.1, which should be nothing + the rest of the line in parentheses but i don't know what the rest means, specifically the "?" and ":" and what follows those. Thanks again. I feel I am close.

It's a ternary conditional operation; basically, that line is setting OBX.5.1 to itself, plus (if OBX.5.2 isn't blank or non-existent) \S\ plus OBX.5.2.

wit-man
05-25-2012, 12:34 PM
If I have looked this up correctly, the "\S\" sequence concatenates the two values? So is the vendor not parsing this value correctly? When it comes across into the EMR from mirth, it shows up as "^value", e.g., "^10". See the attached image.

We are concerned that that physicians might confuse this with a ">" or "<" sign.

See the other attachment for how it shows up in mirth.

narupley
05-25-2012, 03:52 PM
As stated before, if the vendor is passing you an OBX.5 of "^value" and the caret is supposed to be literal rather than a component separator, then it should be escaped properly, also as explained before.

When you pass an HL7 message with \S\ in it to an EMR, it should convert that to a caret when displaying it in a flowsheet or whatever. Now if you want to get rid of that caret altogether, follow my initial suggestion in this thread. However, if it's meant to be a literal caret, then it's almost always not a good idea to modify that. It really depends on what legal agreements you have with your vendor and with who you're going to be sending the messages to, but generally speaking you never want to alter clinically significant data. The main exception is converting discrete documents to non-discrete (e.g. ORUs to MDMs), but in that case you would likely already have a validation process in place with the contributor source to ensure that no clinically significant data is altered.

wit-man
05-25-2012, 04:28 PM
First, let me say again, thanks for your help and to once again apologize for any redundant information you had to give. I am still new to HL7 and mirth and trying to understand the whole process.

That being said, I think I misunderstood your previous post that contained the two sample code segments. As far as I know, the caret is not supposed to be there but I will need to confirm with the sending vendor. Each of the OBX.5 segments passed through should only have one value for the test performed, although there could be multiple OBX lines.

This brings me to my next (and hopefully final) question. In your first post, you state:

"Note: If you want the above code to work for messages that have repeating OBX.5 fields, remember to check Parse Field Repetitions in the protocol settings. "

I am not sure I understand what you mean by this. Do you mean multiple OBX lines or something else? Is this the setting under "Set Data Type -> Set Outbound Connector -> Parse Field Repetitions" or is it a different location?

I ask because we sent through some tests with multiple OBX lines and it looks like all of the values in OBX.5 came through the engine correctly for each of the lines but that box is not checked as far as I can see. Thanks again.

narupley
05-25-2012, 04:45 PM
First, let me say again, thanks for your help and to once again apologize for any redundant information you had to give. I am still new to HL7 and mirth and trying to understand the whole process.

That being said, I think I misunderstood your previous post that contained the two sample code segments. As far as I know, the caret is not supposed to be there but I will need to confirm with the sending vendor. Each of the OBX.5 segments passed through should only have one value for the test performed, although there could be multiple OBX lines.

This brings me to my next (and hopefully final) question. In your first post, you state:

"Note: If you want the above code to work for messages that have repeating OBX.5 fields, remember to check Parse Field Repetitions in the protocol settings. "

I am not sure I understand what you mean by this. Do you mean multiple OBX lines or something else? Is this the setting under "Set Data Type -> Set Outbound Connector -> Parse Field Repetitions" or is it a different location?

I ask because we sent through some tests with multiple OBX lines and it looks like all of the values in OBX.5 came through the engine correctly for each of the lines but that box is not checked as far as I can see. Thanks again.

Hey no problem! Yep, that's the right place to check Parse Field Repetitions. Even if you don't check it, the encoded data will still contain repetitions due to how Mirth serializes the XML back into HL7. However, code that iterates through repetitions (like the sample I gave) will only work if you check that setting. If it's not checked, then multiple OBXs are parsed into E4X as one long OBX.

wit-man
05-25-2012, 05:35 PM
But, the thing is, your code worked and I don't have that checked. See the attached screenshot. These are the results after having been run through the loop from your code and they are correct in the receiving EMR.

Is this not the way it should work? If I understand what you are saying on how it should work with my current settings, those two values should be concatenated into one value, not split into the two separate lines like they are?

I double checked to make sure this was not checked in that location and it isn't.

narupley
05-25-2012, 05:41 PM
But, the thing is, your code worked and I don't have that checked. See the attached screenshot. These are the results after having been run through the loop from your code and they are correct in the receiving EMR.

Is this not the way it should work? If I understand what you are saying on how it should work with my current settings, those two values should be concatenated into one value, not split into the two separate lines like they are?

I double checked to make sure this was not checked in that location and it isn't.

That's because you don't have any repetitions in the example you showed. Try it with a repeating OBX.5 and you'll see what I mean.

wit-man
05-25-2012, 05:59 PM
OK, maybe I have the terminology mixed up. When you say repetitions in the OBX.5 field, do you mean more than one value in the OBX.5 field for each line?

narupley
05-25-2012, 07:13 PM
OK, maybe I have the terminology mixed up. When you say repetitions in the OBX.5 field, do you mean more than one value in the OBX.5 field for each line?

Well not more than one "value in the field", it's more than one field, delimited by the character in the second position of MSH.2 (usually a tilde). This (https://www.google.com/search?q=hl7+tutorial) might help...

So if you have "OBX|1||||a~b", then there are two repetitions for OBX.5, each repetition having the first component populated.

wit-man
05-25-2012, 10:55 PM
Yes, that does clear it up. Thanks for all your help!