In Transform Order AIS by AIS 3.1 value
I have a SIU message that has multiple AIS segments in an RGS group. I need to reorder the AIS segments based on the AIS 3.1 value.
What is the most efficient way to do this in a transform?
Comments
Are the values in AIS:3.1 sequential integers ranging from 1 to the number of AIS segments? If yes, it's very easy.
If not ... just a little harder. You'd populate a subscripted variable using the values in AIS:3.1 as the index and the segment repetition number as the array element value. Then $ORDER() through it get the source segment repetition number and assign that segment to the target in AIS:3.1 order. For example:
.png)
The variable tAISArr will be subscripted by the values in AIS:3.1. So now we just $ORDER() through tAISArr in a code action:
set tIdx = 1
set tKey = $ORDER(tAISArr(""))
while (tKey '= "")
{
// Grab the segment identified by the value of the array subscript
set AISSeg = source.GetValueAt("RGSgrp(1).AISgrp("_tAISArr(tKey)_").AIS")
// stuff it into the target segment at the current position of the value of the loop counter tIdx
do target.SetValueAt(AISSeg,"RGSgrp(1).AISgrp("_tIdx_").AIS")
// Don't forget to renumber the Set ID
do target.SetValueAt(tIdx,"RGSgrp(1).AISgrp("_tIdx_").AIS:1")
set tIdx = tIdx + 1
set tKey = $ORDER(tAISArr(tKey))
}Sample Input:
.png)
Sample Output:
.png)