|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
///////////// 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; } } |
|
#3
|
|||
|
|||
|
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();
}
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;
}
|
|
#4
|
|||
|
|||
|
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; } |
![]() |
| Thread Tools | |
| Display Modes | |
|
|