web stats
Removing HL7 segment via transformer - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2020, 06:34 AM
snijderkw snijderkw is offline
What's HL7?
 
Join Date: Feb 2020
Posts: 1
snijderkw is on a distinguished road
Default Removing HL7 segment via transformer

Im using Mirth Connect Server 3.4.2.8129.
I want to transform a HL7 message when a certain segment is in the message more than 1 time.

Case:
Sometimes our messages contains the IN1 segment more than one time.If that is the case I want to check if in that segment IN1.17 contains the word 'Zelf'. If so only that segment is needed. The other segments (IN1 and IN2) must be deleted. Does anyone know how to do such a thing?

Example message:
MSH
EVN
PID
ROL
PV1
PV2
IN1|1|1000^BVNOORD TESTVERZEKERING|1000^^^UZOVI^PAYORID|BVNOORD TESTVERZEKERING|^^xxxxx|||||||20170611|20200804||| TWEEENZEVENTIG^A.U.G.|Zelf||^^^^^NLD|||1|||||||||| |||1101||||||||||||BOTH
IN2|||||V
IN1|2|3311^ZILVEREN KRUIS ZORGVERZEKERINGEN NV|3311^^^UZOVI^PAYORID|GEN NV|POSTBUS 631&POSTBUS 631^^xxxxx^^8000AP||^^^^^^^^^^^(0900) 5665665|||||20181220|20200811|||TWEEENZEVENTIG^A.U .G.|xxxxx||^^^^^NLD|||2|||||||||||||1138|||||||||| ||BOTH
IN2|||||V
Reply With Quote
  #2  
Old 02-14-2020, 01:27 PM
jackwhaines jackwhaines is offline
 
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 255
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines
Default

Try this:

Code:
if (msg['IN1'].length() > 0 && msg['IN1'][0]['IN1.17']['IN1.17.1'].toString() == "Zelf")
	{
	for (var i = msg['IN1'].length(); i > 0; i--)
		{
		delete msg['IN1'][i];
		delete msg['IN2'][i];
		}
	}
__________________

-= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
-= jack.haines@HealthcareIntegrations.com
-= Mirth Connect (Advanced)-certified
-= Gold member of HL7.org
-= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines
Reply With Quote
  #3  
Old 02-14-2020, 06:01 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road
Default

Jack's solution works for your example, but makes the assumptions that 1) Zelf is always in the first IN1 segment, and 2) Every IN1 has a matching IN2.

This should be a little more robust.

Code:
var in1, nextSeg, i;
if (msh.IN1.length() > 0) {
    // find the IN1 containing Zelf
    for (i = 0; i < msg.IN1.length(); i++) {
        in1 = msg.IN1[i];
        if (in1['IN1.17']['IN1.17.1'].toString() == "Zelf") break;
    }
    if (i < msg.IN1.length()) {
        // we found one, and in1 is a reference to it
        // check if there is an IN2.
        // nextSeg will have a length of 0 if in1 is the last segment in the message
        nextSeg = msg.child(in1.childIndex() + 1);
        if (nextSeg.length() > 0 && nextSeg.localName() == 'IN2') {
            // replace all IN2 with this IN2 in the position of msg.IN2[0]
            msg.IN2 = nextSeg;
        }
        else {
            // delete all IN2 segments
            delete msg.IN2;
        }
        // replace all IN1 segments with this IN1 segment in the position of msg.IN1[0]
        msg.IN1 = in1;
    }
}
Reply With Quote
  #4  
Old 02-14-2020, 06:15 PM
jackwhaines jackwhaines is offline
 
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 255
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines
Default

agermano, agreed and agreed. More samples would yield a more robust codeset (or what you did, thanks.) =)
__________________

-= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
-= jack.haines@HealthcareIntegrations.com
-= Mirth Connect (Advanced)-certified
-= Gold member of HL7.org
-= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines
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 11:47 PM.


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