web stats
Copying between IN1/IN2 segments in a repeating set. - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2012, 01:05 PM
tlpcsey tlpcsey is offline
What's HL7?
 
Join Date: Apr 2012
Posts: 3
tlpcsey is on a distinguished road
Default Copying between IN1/IN2 segments in a repeating set.

Hi,

I'm trying to copy data between the IN2 and IN1 segment when there are repeating IN1 and IN2's.

Sample HL7 Message segment framework..

MSH
EVN
PID
IN1
IN2
IN1
IN2

Basically my logic is, if IN1-17 for that iteration of the segment is =! to 'SELF', then copy the value from IN2-64 in that set to IN1-49

I've been using a for each statement for the IN1, but i'm not sure how to integrate the IN2 into the mix, since i have to loop through both segments and keep the iterations linked together between the 2 for continuity.

Thanks for any thoughts on the frame work of the loops!
Reply With Quote
  #2  
Old 04-12-2012, 02:42 PM
tlpcsey tlpcsey is offline
What's HL7?
 
Join Date: Apr 2012
Posts: 3
tlpcsey is on a distinguished road
Default My Code

///////////// Copy business phones to GT1-2 and IN1-49 WHERE RELATIONSHIP IS NOT SELF.

for each (seg in msg.children())
{
if (seg.name().toString() == "IN1")
{
var IN117 = seg['IN1.17']['IN1.17.1'].toString();
var IN117result = "UNDEFINED";
if ((IN117 == "") || (IN117 == "SELF") || (IN117 == "Self"))
{
seg['IN1.49']['IN1.49.1'] = "";
IN117result = "SELF";
seg['IN1.48']['IN1.48.1'] = IN117result;
}
}
if ((seg.name().toString() == "IN2") && (IN117result == "UNDEFINED"))
{
var IN264 = seg['IN2.64']['IN2.64.1'].toString();
seg['IN1.49']['IN1.49.1'] = IN264;
seg['IN2.63']['IN2.63.1'] = IN264;
}
}
Reply With Quote
  #3  
Old 04-13-2012, 05:34 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,498
narupley is on a distinguished road
Default

Here's an example:

Code:
for each (in1 in msg.IN1)
	if (in1['IN1.17']['IN1.17.1'].toString() != 'SELF') {
		var in2 = getSegmentsAfter(msg,in1,'IN2',false);	
		if (in2.length > 0)
			in1['IN1.49']['IN1.49.1'] = in2[0]['IN2.64']['IN2.64.1'].toString();
	}
And the code for getSegmentsAfter:

Code:
/*
	Author: Nick Rupley
	Michiana Health Information Network
	Date Modified: 1/6/2012
*/

function getSegmentsAfter(root, startSeg, segName, consecutiveInd, stopSegNames) {
	var index = startSeg.childIndex()+1;
	var out = [];
	var done = false;
	var stopNames = {};
	var stopNamesInd = false;
	if (stopSegNames !== undefined && stopSegNames !== null) {
		stopNamesInd = true;
		for each (name in stopSegNames)
			stopNames[name] = 1;
	}

	while (index < root.children().length() && !done) {
		if (stopNamesInd && root.children()[index].name().toString() in stopNames)
			done = true;
		else if (root.children()[index].name().toString() == startSeg.name().toString() && !consecutiveInd)
			done = true;
		else if (root.children()[index].name().toString() != segName && consecutiveInd)
			done = true;
		else if (root.children()[index].name().toString() == segName)
			out.push(root.children()[index]);
		index++;
	}

	return out;
}
Reply With Quote
  #4  
Old 04-13-2012, 01:25 PM
tlpcsey tlpcsey is offline
What's HL7?
 
Join Date: Apr 2012
Posts: 3
tlpcsey is on a distinguished road
Default

I was able to get some assistance.
Here is an easy way to do it.

for each (seg in msg.children())
{
if (seg.name().toString() == "IN1")
{
var IN117 = seg['IN1.17']['IN1.17.1'].toString();
var IN117result = "UNDEFINED";
if ((IN117 == "") || (IN117 == "SELF") || (IN117 == "Self"))
{
seg['IN1.49']['IN1.49.1'] = "";
IN117result = "SELF";
}
}
if ((seg.name().toString() == "IN2") && (IN117result == "UNDEFINED") && (lastSeg.name().toString() == "IN1"))
{
var IN264 = seg['IN2.64']['IN2.64.1'].toString();
lastSeg['IN1.49']['IN1.49.1'] = IN264;
}
lastSeg = seg;
}
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 -7. The time now is 03:51 PM.


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