Glenn,
I’m sure there may be a simpler way to do this, but here is what I did.
1. Initialize a counter variable:
COPY =0 -> @ctr
2. Iterate through your OBR’s. The only entry I have for the OBR is a MATH entry to increment the counter.
MATH: ADD =1 @ctr -> @ctr
3. After the iterate, add a MATH:SUB to subtract one from the final count in your counter variable. This could have also been done without the MATH entries by taking the final OBR-2 field and reading it into a counter but not all systems may send that field:
MATH: SUB @ctr =1 -> @ctr
4. Copy the @ctr variable into a % variable that isn’t going to be used:
COPY @ctr -> $%l1
5. Iterate again through your ORC/OBR pairs. Set the iterate up as below. The basis will depend on how your variant is set up.
ITERATE ENGINE=group Basis= 1(0).1 Variable= %g1
6. Move your ORC/OBR fields as needed.
7. Inside the ORC/OBR iterate, set up a nested iterate. The settings should b:
ITERATE ENGINE=group Basis= 1(0).1(%l1).1 Variable= %g2
8. Move your OBX segments in this manner:
1(0).1(%l1).1(%g2).OBX.000571 -> 1(0).1(%g1).1(%g2).OBX.00571
I got this to work in my tester (5.2). Let me know if you can get it to work for you. I’m also here in Houston at Memorial Hermann. Look me up if you want me to email you the code.
Thanks…
Thomas G Rioux
thomas.rioux@memorialhermann.org