This works in a form, so maybe it will help a random chugger, but otherwise it gives me strange errors in the history view.
The main problem is that its not liking the way I'm converting the dates to a string and then back to dates. But i need to do that to sort the array of dates, Maybe there's an easier way to sort it that I am unaware of,
What it does is,
1)Pulls in all rows for a certain vaccine
2)Only takes the datetime then converts it to a date
4) Makes sure the vaccine was actually given
3) Removes duplicates
4)Converts the date to a string
5) Sorts it (You cant sort unless its in a string)
6) Converts back to a date
7) Removes blanks from array
/**Converts the date to a string**/
{fn convertDateYear(d,f) {
local retStr = ""
local dateArray
cond
case d == "": /*Do Nothing*/
case match(d, 1, "/") <= 0: /*Do Nothing*/
else:
dateArray = getfield(d, "/", "")
if size(dateArray) == 3 then
cond
case f == "yyyymmdd": retStr = dateArray[3] + dateArray[1] + dateArray[2]
endcond
endif
endcond
return retStr
}}
/**Converts the string to a date**/
{fn convertStringToDate(d,f)
{
local retStr = ""
cond
case d == "": /*Do Nothing*/
case size(d) == 8:
cond
case f == "mm/dd/yyyy": retStr = sub(d, 5, 2) + "/" + sub(d, 7, 2) + "/" + sub(d, 1, 4)
endcond
endcond
return retStr
}}
/**Main code - gets row, takes only the date, removes duplicates, sorts and displays***************/
{fn fnImmunoHxTesting(Vaccine) {
//gets vaccine
local hold = getfield(IMMUN_GETLIST(Vaccine, "all"), "|", "")
local temp = ""
local rslt = ""
local tempGiven = ""
local aArray = array()
local ttemp = ""
local tRslt = ""
local tArray = array()
local temp2 = ""
local fRslt = ""
local finalArray = array()
local testingRslt = ""
for i =1, i <= size(hold), i = i + 1 do
temp = getfield(hold[i], "^", "")
tempGiven = temp[7]
if (tempGiven <> "Y") then ""
else
if (match(rslt,ADDDATES(temp[30],"0","0","0")) == 0) then
rslt = ADDDATES(temp[30],"0","0","0")
rslt = convertDateYear(rslt,"yyyymmdd")
insert(aArray,i,rslt)
endif
endif
endfor
sort(aArray,false)
for j =1, j <= size(aArray), j = j + 1 do
ttemp = get(aArray,j)
if (match(tRslt,ttemp) == 0) then
tRslt = ttemp
fRslt = convertStringToDate(tRslt,"mm/dd/yyyy")+ hret
insert(tArray,i,fRslt)
endif
endfor
for k =size(tArray), k >= 1, k = k - 1 do
finalArray = tArray
temp2 = get(tArray,k)
if (temp2 == "") then remove(finalArray,k)
else testingRslt = testingRslt + get(finalArray,k)
endif
endfor
return testingRslt
}}
Thanks for taking a look!
Posted : January 17, 2017 9:21 am