Excellent ideas and thank you for paying it forward by posting your final solution. That is what these forums are all about - pooling resources and sharing ideas!
A note on the final solution and a few updates for future reference and other users:
First, the selected answer I checked isn't technically the answer, but the post with the actual answer doesn't have a checkmark and I want to point other users in the right direction. That whole thread answered this question!
Second, I continued chipping away at it this morning and was able to add nested for loops that pulled out values from both the diagnoses and ICD10 codes, then put them together. I want to log three of my major steps in the process, so I will use three replies to this post to keep it organized. If this is not an acceptable use of this board, please let me know and I will remove them and will refrain from doing this in the future.
SIMPLE SOLUTION
This solution adds an if statement that finds "~" and replaces them with HRET. This puts the diagnoses in a vertical list, with the ICD10 codes below in another vertical list. I wanted to make this work first, so in case I couldn't do the more complex solution, I at least had this to submit. It may still be helpful to someone in the future.
{
!fn getOrderPieces() {
local tests = getfield(ORDERS_NEW("delimited",""),"|","")
local temp
local testrslt = ""
local refrslt = ""
local endrslt = ""
local dx = ""
local allDx = ""
local i = 1
for i = 1, i 0 then
allDx = replacestr(dx, "~", HRET)
userok(allDx)
testrslt = allDx
else
""
endif
endfor
if testrslt "" then
testrslt = testrslt
else
testrslt = "No tests or referrals ordered in this update."
endif
}
}
COMPLEX SOLUTION 1.1
This solution actually pulled out two formatted lists, one of diagnoses and one of ICD10 codes. The end result was identical to my SIMPLE SOLUTION, but the process was much more difficult, yet taught me a lot about for loops.
The biggest takeaway from this experience was that talking out the logic helps a lot! I struggled trying to match my second loop to my first one, but the second one kept returning each individual letter as a single element in the array. I was testing this with a userok and was amused watching the dx being spelled out letter by letter.
I soon realized that I had to use getfield OUTSIDE the for loop, so the array could be built and THEN broken apart by the for loop. Once that happened, everything else fell into place.
local tests = getfield(ORDERS_NEW("delimited",""),"|","")
local temp
local testrslt = ""
local refrslt = ""
local endrslt = ""
local dx = ""
local allDx = ""
local splitDx = ""
local totalDx = ""
local finalDx = ""
local ICD10 = ""
local allICD10 = ""
local splitICD10 = ""
local totalICD10 = ""
local finalICD10 = ""
local i = 1
for i = 1, i <= size(tests), i = i + 1 do
temp = getfield(tests[i], "^","")
dx = temp[6]
ICD10 = temp[7]
userok(dx + " dx")
allDx = getfield(dx, "~", "")
userok(allDx + " allDx")
for i = 1, i <= size(allDx), i = i + 1 do
splitDx = allDx[i]
userok(splitDx + " splitDx")
totalDx = totalDx + splitDx + HRET
userok(totalDx + " totalDx")
endfor
allICD10 = getfield(ICD10, "~", "")
for i = 1, i <= size(allICD10), i = i + 1 do
splitICD10 = allICD10[i]
userok(splitICD10 + " splitICD10")
totalICD10 = totalICD10 + splitICD10 + HRET
endfor
testrslt = totalDx + totalICD10
endfor
if testrslt "" then
testrslt = testrslt
else
testrslt = "No tests or referrals ordered in this update."
endif
}
}
FINAL SOLUTION
After making the last block of code work, my thought was to take those two final array variables, break them apart, and then put those pieces together to put each ICD10 code after their matching diagnosis. While thinking about that, however, I realized that in order to break these variables into arrays, I'd have to add a delimiting mark so the getfield() function knew where to make the split. It had to be something unique, something like a... "~"...
So I started over and tried something that I didn't think was going to work. Inside my outer loop (the first loop that broke up the orders), I made variable arrays out of the diagnoses (temp[6]) and the ICD10 codes (temp[7]). I put those arrays into two variables, allDx and allICD10. Then I started a loop that ran through every element in allDx. I figured that, since allDx and allICD10 were the same size, I could use allDx's for loop to count us through allICD10's for loop and it worked.
I then added an if statement that filtered for orders with multiple diagnoses by looking for "~" and I rebuilt the other text and data that was needed. I also added a count variable that increases on every round of the outer loop. This adds a number to the beginning of each listed order.
If anyone has any questions about this, ever, please feel free to ask. I'm happy to explain further.
{
!fn getOrderPieces() {
local tests = getfield(ORDERS_NEW("delimited",""),"|","")
local count = 0
local temp = ""
local testrslt = ""
local refrslt = ""
local endrslt = ""
local dx = ""
local allDx = ""
local splitDx = ""
local totalDx = ""
local finalDx = ""
local ICD10 = ""
local allICD10 = ""
local splitICD10 = ""
local totalICD10 = ""
local finalICD10 = ""
local i = 1
for i = 1, i 0 then
allDx = getfield(dx, "~", "")
allICD10 = getfield(ICD10, "~", "")
for i = 1, i <= size(allDx), i = i + 1 do
for i = 1, i <= size(allICD10), i = i + 1 do
totalICD10 = totalICD10 + allDx[i] + " (" + allICD10[i] + ")" + HRET
endfor
endfor
testrslt = testrslt + "Order " + count + HRET +
"Order Description: " + HRET + temp[1] + ", " + temp[3] + " on " + temp[4] + HRET + HRET +
"Diagnoses: " + HRET + totalICD10 + HRET +
"Auth Provider: " + HRET + temp[21] + HRET + HRET + HRET
else
testrslt = testrslt + "Order " + count + HRET +
"Order Description: " + HRET + temp[1] + ", " + temp[3] + " on " + temp[4] + HRET + HRET +
"Diagnosis: " + HRET + temp[6] + " (" + temp[7] + ")" + HRET + HRET +
"Auth Provider: " + HRET + temp[21] + HRET + HRET + HRET
endif
endfor
if testrslt "" then
testrslt = testrslt
else
testrslt = "No tests or referrals ordered in this update."
endif
}
}
So, as it turns out, my final function up there only posts one order with one diagnosis and one order with multiple diagnoses. That's it. There's something in my nested for loops/if statement that breaks out of the larger outer loop. If I run only the outer loop, back where I started, then it'll display as many orders as I want it to.
Sticking some useroks in there reveals that it's allDx and totalICD10 are always reaching back to the first entered order, so I think that's the issue. I'll post an update when I figure out what the problem is...