Hi jjordet,
I altered the function as below, but the data display is empty. Do you see anything I botched or missed from your directions? I'm calling it with {fn CombineImmuns()}.
{fn CombineImmuns()
{
local Types = array("HepBvax#1", "HepBvax#2", "HepBvax#3", "HepBvax#4", "HepBvax#5", "HepBvax#6", "rotavir#1", "rotavir#2", "rotavir#3", "DPT #1", "DPT #2", "DPT #3", "DPT #4", "DPT #5", "Td booster", "HemInfB#1", "HemInfB#2", "HemInfB#3", "HemInfB#4", "pneuped#1", "pneuped#2", "pneuped#3", "pneuped#4", "pneumovax", "IPV #1", "IPV #2", "IPV #3", "IPV #4", "IPV #5", "MMR #1", "MMR #2", "MMR #3", "Varicella#1", "Varicella#2", "Varicella#3", "HepAvax #1", "HepAvax #2", "HepAvax #3", "HepAvax #4", "HepAvax #5", "HPV VAX #1", "HPV #2", "HPV #3", "Meningoc vax", "BUN", "ZOSTAVAX", "Flu vax", "TB-PPD", "Rabies vax", "Rab vax#2", "Rab vax#3", "Rab vax#4", "BUN", "Typhoid vax", "Yellow f vac", "Jap Encep", "JapEnce#2", "JapEnce#3")
return CombineImmunizations(Types, 1)
}
}
{fn CombineImmunizations(Types, Last)
{
local aTypes = array("")
local aVals = array("")
local aDates = array("")
local aDatesConverted = array("")
local arraysize = size(Types)
local result
local index
local index2
local temp
local count
for index = 1, index <= arraysize, index = index + 1 do
FillArraysWithObs(Types[index], aTypes, aVals, aDates, aDatesConverted)
endfor
arraysize = size(aTypes) - 1
for index = 1, index < arraysize, index = index + 1 do
for index2 = 1, index2 <= arraysize - index, index2 = index2 + 1 do
if aDatesConverted[index2]>aDatesConverted[index2 + 1] then
temp = aTypes[index2]
aTypes[index2] = aTypes[index2 + 1]
aTypes[index2 + 1] = temp
temp = str(aVals[index2])
aVals[index2] = aVals[index2 + 1]
aVals[index2 + 1] = temp
temp = str(aDates[index2])
aDates[index2] = aDates[index2 + 1]
aDates[index2 + 1] = temp
temp = str(aDatesConverted[index2])
aDatesConverted[index2] = aDatesConverted[index2 + 1]
aDatesConverted[index2 + 1] = temp
endif
endfor
endfor
result = ""
count = 0
for index = 1, index <= arraysize, index = index + 1 do
if (Last == 0)
or (index > (arraysize - Last)) then
count = count + 1
if result<>"" then
result = result + hret
endif
result = result + count + " " + aDates[index] + " " + aVals[index]
endif
endfor
return result
}
}
{fn FillArraysWithObs(ObsTerm, aTypes, aVals, aDates, aDatesConverted)
{
local count
local length
if LIST_OBS(ObsTerm,'Update','list','valuedate')<>"" then
local obs_array1 = getfield(LIST_OBS(ObsTerm,'Update','list','valuedate'), hret, "")
length = size(obs_array1)
for count = 1, count <= length, count = count + 1 do
if size(obs_array1[count])>0
and match(obs_array1[count], 1, "(")>0 then
local obs_array2 = getfield(obs_array1[count], "(", "")
if size(obs_array2)>2 then
obs_array2[1] = obs_array2[1] + "(" + obs_array2[2]
obs_array2[2] = obs_array2[3]
endif
insert(aTypes, 1, ObsTerm)
insert(aVals, 1, trim(obs_array2[1]))
insert(aDates, 1, sub(obs_array2[2], 1, 10))
insert(aDatesConverted, 1, ConvertDate(obs_array2[2]))
endif
endfor
endif
}
}
{fn Trim(string)
{
local result = string
local dowhile = true
local sizeresult
while dowhile do
if size(result)==0 then
dowhile = false
else
if result[1]<>" " then
dowhile = false
else
result = remove(result, 1, 1)
endif
endif
endwhile
dowhile = true
sizeresult = size(result)
while dowhile do
if sizeresult==0 then
dowhile = false
else
if result[sizeresult]<>" " then
dowhile = false
else
result = remove(result, sizeresult, 1)
sizeresult = size(result)
endif
endif
endwhile
return result
}
}
{fn ConvertDate(date)
{
local newdate
newdate = sub(date, 7, 4)
newdate = newdate + "" + sub(date, 1, 2)
newdate = newdate + "" + sub(date, 4, 2)
return newdate
}
}