This is what I use for our immunization review form. You won't need all of it. But if you look at the function CombineBoostersAdult(), it returns the last 3 values for the listed obs terms.
{!
global gblObsNamesImmRevAdult = array("TD Booster", "Boostrixdose", "DTAPbsttrade", "TETANUS IMMU", "TDAP", "PEDIARIX1", "PEDIARX1HEP2", "DTAP/HIB#1", "DTP/HIB #1", "DTAP #1", "DPT #1", "TD #1", "PEDIARIX2", "PEDIARX2HEP3", "DTAP/HIB#2", "DTP/HIB #2", "DTAP #2", "DPT #2", "TD #2", "PEDIARIX3", "PEDIARX3HEP4", "DTAP/HIB#3", "DTP/HIB #3", "DTAP #3", "DPT #3", "TD #3", "DTAP/HIB#4", "DTP/HIB #4", "DTAP #4", "DPT #4", "TD #4", "DTAP/HIB#5", "DTP/HIB #5", "DTAP #5", "DPT #5", "TD #5", "PENT#1", "KINRIX", "PERTUSSISVAX", "DTAP reason", "Pedia reason", "DT reason", "Td reason", "tdapreason", "Pediarix1", "Pediarx1hep2", "IPV #1", "OPV #1", "Pediarix2", "Pediarx2hep3", "IPV #2", "OPV #2", "Pediarix3", "Pediarx3hep4", "IPV #3", "OPV #3", "IPV #4", "OPV #4", "IPV #5", "OPV #5", "PENT#1", "KINRIX", "IPV reason", "Pedia reason", "Jap Encep", "Rabies Vax", "TYPHOID VAX", "TYPHOID ORAL", "HepAvax #1", "HepAvax #2", "HEPA BOOSTER", "TWINRIX1GIVN", "HEPA reason", "MMR #1", "MMR #2", "PROQUAD", "MEASLEMUMP", "MEASLESVAX", "MUMPSVAX", "RUBELLAVAX", "RsnMMRntGn", "PNEUPED#1", "PNEUPED#2", "PNEUPED#3", "PNEUPED#4", "PCV reason", "Varicella#1", "Varicella#2", "PROQUAD", "ZOSTAVAX", "Vari reason", "ZOSTAVAXRNG", "Yellow f vac", "PPD RESULT","TB-PPD INTRP","BCG VAX HX", "HIBHEPB#1", "HepBvax#1", "Pediarix1", "Pediarx1hep2", "Pediarix2", "HIBHEPB#2", "HIB1HEPB2", "HepBvax#2", "Pediarix3", "Pediarx2hep3", "HIBHEPB#3", "HIB2HEPB3", "HepBvax#3", "Pediarx3hep4", "HIB3HEPB4", "HepBvax#4", "HEPB Booster", "TWINRIX1GIVN", "HEPB reason", "Pedia reason", "HPV #1 DRUG", "HPVDECLINE", "H1N1#1 VAC", "H1N1RSNNTGVN", "FLU VAX", "rsn no fluvx", "MENINGOC VAX", "Mening reasn", "PNEUMOVAX", "PNEUMO2TRNM", "RsnPneuNtGn")
global gblObsListChangesImmRevAdult
global gblCalcForTransImmRevAdult = ""
}
{
global CombinedBoosters = ""
global CombinedDTPImmunContras = ""
global CombinedPolios = ""
global CombinedPolioImmunContras = ""
global CombinedJapEs = ""
global CombinedRabies = ""
global CombinedTyphoids = ""
global CombinedHepAs = ""
global CombinedHepAImmunContras = ""
global CombinedMMRs = ""
global CombinedMMRImmunContras = ""
global CombinedPCVs = ""
global CombinedPCVImmunContras = ""
global CombinedVaricellas = ""
global CombinedVarImmunContras = ""
global CombinedYellows = ""
global CombinedPPDs = ""
global CombinedHepBs = ""
global CombinedHepBImmunContras = ""
global CombinedHPVs = ""
global CombinedHPVImmunContras = ""
global CombinedH1N1s = ""
global CombinedH1N1ImmunContras = ""
global CombinedFlus = ""
global CombinedFluImmunContras = ""
global CombinedMens = ""
global CombinedMenImmunContras = ""
global CombinedPneumos = ""
global CombinedPneumoImmunContras = ""
}
{if obs_list_changes()<>gblObsListChangesImmRevAdult then
gblObsListChangesImmRevAdult = obs_list_changes()
if gblObsListChangesImmRevAdult=="" then
SetGlobalsImmRevAdult()
else
CheckForObsImmRevAdult()
endif
else
""
endif}
{fn CheckForObsImmRevAdult()
{
local obslistchangesarray
local obs
local sizearray
local sizearray2
local index
local index2
local pos
obslistchangesarray = getfield(gblObsListChangesImmRevAdult, hret, "")
sizearray2 = size(gblObsNamesImmRevAdult)
sizearray = size(obslistchangesarray)
index = 1
while index <= sizearray do
pos = match(obslistchangesarray[index], 26, ":")
if pos > 26 then
obs = sub(obslistchangesarray[index], 26, pos - 26)
index2 = 1
while index2 <= sizearray2 do
if TOUPPER(obs) == TOUPPER(gblObsNamesImmRevAdult[index2]) then
SetGlobalsImmRevAdult()
index2 = sizearray2
index = sizearray
endif
index2 = index2 + 1
endwhile
endif
index = index + 1
endwhile
}
}
{fn SetGlobalsImmRevAdult()
{
gblCalcForTransImmRevAdult = "done"
CombinedBoosters = CombineBoostersAdult()
CombinedDTPImmunContras = CombineDTPImmunContras()
CombinedPolios = CombinePolios()
CombinedPolioImmunContras = CombinePolioImmunContras()
CombinedJapEs = CombineJapEs()
CombinedRabies = CombineRabies()
CombinedTyphoids = CombineTyphoids()
CombinedHepAs = CombineHepAs()
CombinedHepAImmunContras = CombineHepAImmunContras()
CombinedMMRs = CombineMMRs()
CombinedMMRImmunContras = CombineMMRImmunContras()
CombinedPCVs = CombinePCVs()
CombinedPCVImmunContras = CombinePCVImmunContras()
CombinedVaricellas = CombineVaricellas()
CombinedVarImmunContras = CombineVarImmunContras()
CombinedYellows = CombineYellows()
CombinedPPDs = CombinePPDs2()
CombinedHepBs = CombineHepBs()
CombinedHepBImmunContras = CombineHepBImmunContras()
CombinedHPVs = CombineHPVs()
CombinedHPVImmunContras = CombineHPVImmunContras()
CombinedH1N1s = CombineH1N1s()
CombinedH1N1ImmunContras = CombineH1N1ImmunContras()
CombinedFlus = CombineFlus()
CombinedFluImmunContras = CombineFluImmunContras()
CombinedMens = CombineMens()
CombinedMenImmunContras = CombineMenImmunContras()
CombinedPneumos = CombinePneumos()
CombinedPneumoImmunContras = CombinePneumoImmunContras()
return ""
}
}
{fn CombineBoostersAdult()
{
local Types = array("TD Booster", "Boostrixdose", "DTAPbsttrade", "TETANUS IMMU", "TDAP", "PEDIARIX1", "PEDIARX1HEP2", "DTAP/HIB#1", "DTP/HIB #1", "DTAP #1", "DPT #1", "TD #1", "PEDIARIX2", "PEDIARX2HEP3", "DTAP/HIB#2", "DTP/HIB #2", "DTAP #2", "DPT #2", "TD #2", "PEDIARIX3", "PEDIARX3HEP4", "DTAP/HIB#3", "DTP/HIB #3", "DTAP #3", "DPT #3", "TD #3", "DTAP/HIB#4", "DTP/HIB #4", "DTAP #4", "DPT #4", "TD #4", "DTAP/HIB#5", "DTP/HIB #5", "DTAP #5", "DPT #5", "TD #5", "PENT#1", "KINRIX", "PERTUSSISVAX")
return CombineImmunizations(Types, 3)
}
}
{fn CombineDTPImmunContras()
{
local Types = array("DTAP reason", "Pedia reason", "DT reason", "Td reason", "tdapreason")
return CheckImmunContra(Types, 1)
}
}
{fn CombinePolios()
{
local Types = array("Pediarix1", "Pediarx1hep2", "IPV #1", "OPV #1", "Pediarix2", "Pediarx2hep3", "IPV #2", "OPV #2", "Pediarix3", "Pediarx3hep4", "IPV #3", "OPV #3", "IPV #4", "OPV #4", "IPV #5", "OPV #5", "PENT#1", "KINRIX")
return CombineImmunizations(Types, 0)
}
}
{fn CombinePolioImmunContras()
{
local Types = array("IPV reason", "Pedia reason")
return CheckImmunContra(Types, 1)
}
}
{fn CombineJapEs()
{
local Types = array("Jap Encep")
return CombineImmunizations(Types, 0)
}
}
{fn CombineRabies()
{
local Types = array("Rabies Vax")
return CombineImmunizations(Types, 0)
}
}
{fn CombineTyphoids()
{
local Types = array("TYPHOID VAX", "TYPHOID ORAL")
return CombineImmunizations(Types, 0)
}
}
{fn CombineHepAs()
{
local Types = array("HepAvax #1", "HepAvax #2", "HEPA BOOSTER", "TWINRIX1GIVN")
return CombineImmunizations(Types, 0)
}
}
{fn CombineHepAImmunContras()
{
local Types = array("HEPA reason")
return CheckImmunContra(Types, 1)
}
}
{fn CombineMMRs()
{
local Types = array("MMR #1", "MMR #2", "PROQUAD", "MEASLEMUMP", "MEASLESVAX", "MUMPSVAX", "RUBELLAVAX")
return CombineImmunizations(Types, 0)
}
}
{fn CombineMMRImmunContras()
{
local Types = array("RsnMMRntGn")
return CheckImmunContra(Types, 1)
}
}
{fn CombinePCVs()
{
local Types = array("PNEUPED#1", "PNEUPED#2", "PNEUPED#3", "PNEUPED#4")
return CombineImmunizations(Types, 0)
}
}
{fn CombinePCVImmunContras()
{
local Types = array("PCV reason")
return CheckImmunContra(Types, 1)
}
}
{fn CombineVaricellas()
{
local Types = array("Varicella#1", "Varicella#2", "PROQUAD", "ZOSTAVAX")
return CombineImmunizations(Types, 0)
}
}
{fn CombineVarImmunContras()
{
local Types = array("Vari reason", "ZOSTAVAXRNG")
return CheckImmunContra(Types, 1)
}
}
{fn CombineYellows()
{
local Types = array("Yellow f vac")
return CombineImmunizations(Types, 1)
}
}
{fn CombinePPDs()
{
local Types = array("PPD RESULT")
local result = CombineImmunizations(Types, 2)
local results = array()
if result<>"" then
results = GETFIELD(result, hret, "")
if SIZE(results)>2 then
return CFMT(SUB(results[1], 16), "", "", "", " mm " + SUB(results[1], 4, 10)) + CFMT(SUB(results[3], 16), "", hret, "", " mm " + SUB(results[3], 4, 10))
else
return CFMT(SUB(results[1], 16), "", "", "", " mm " + SUB(results[1], 4, 10))
endif
else
return ""
endif
}
}
{fn CombinePPDs2()
{
local results
local count = 0
if OBSANY("PPD RESULT")<>""
and OBSANY("TB-PPD INTRP")<>"" then
if DURATIONDAYS(LASTOBSDATE("PPD RESULT"), LASTOBSDATE("TB-PPD INTRP"))>0 then
count = count + 1
results = count + " " + CFMT(LASTOBSVALUE("TB-PPD INTRP"), "", "", "", " " + LASTOBSDATE("TB-PPD INTRP"))
else
if DURATIONDAYS(LASTOBSDATE("PPD RESULT"), LASTOBSDATE("TB-PPD INTRP"))<0 then
count = count + 1
results = count + " "
+ if LASTOBSVALUE("PPD RESULT")<>"done" then
CFMT(LASTOBSVALUE("PPD RESULT"), "", "", "", " mm " + LASTOBSDATE("PPD RESULT"))
else
CFMT(LASTOBSVALUE("PPD RESULT"), "", "", "", " " + LASTOBSDATE("PPD RESULT"))
endif
else
count = count + 1
results = count + " " + CFMT(LASTOBSVALUE("TB-PPD INTRP"), "", "", "", " " + LASTOBSDATE("TB-PPD INTRP"))
endif
endif
else
if OBSANY("PPD RESULT")<>"" then
count = count + 1
results = count + " "
+ if LASTOBSVALUE("PPD RESULT")<>"done" then
CFMT(LASTOBSVALUE("PPD RESULT"), "", "", "", " mm " + LASTOBSDATE("PPD RESULT"))
else
CFMT(LASTOBSVALUE("PPD RESULT"), "", "", "", " " + LASTOBSDATE("PPD RESULT"))
endif
else
if OBSANY("TB-PPD INTRP")<>"" then
count = count + 1
results = count + " " + CFMT(LASTOBSVALUE("TB-PPD INTRP"), "", "", "", " " + LASTOBSDATE("TB-PPD INTRP"))
else
results = ""
endif
endif
endif
if OBSANY("BCG VAX HX")<>"" then
count = count + 1
results = results + hret + count + " " + CFMT(LASTOBSVALUE("BCG VAX HX"), "", "BCG ", "", " " + LASTOBSDATE("BCG VAX HX"))
endif
return results
}
}
{fn CombineHepBs()
{
local Types = array("HIBHEPB#1", "HepBvax#1", "Pediarix1", "Pediarx1hep2", "Pediarix2", "HIBHEPB#2", "HIB1HEPB2", "HepBvax#2", "Pediarix3", "Pediarx2hep3", "HIBHEPB#3", "HIB2HEPB3", "HepBvax#3", "Pediarx3hep4", "HIB3HEPB4", "HepBvax#4", "HEPB Booster", "TWINRIX1GIVN")
return CombineImmunizations(Types, 0)
}
}
{fn CombineHepBImmunContras()
{
local Types = array("HEPB reason", "Pedia reason")
return CheckImmunContra(Types, 1)
}
}
{fn CombineHPVs()
{
local Types = array("HPV #1 DRUG")
return CombineImmunizations(Types, 0)
}
}
{fn CombineHPVImmunContras()
{
local Types = array("HPVDECLINE")
return CheckImmunContra(Types, 1)
}
}
{fn CombineH1N1s()
{
local Types = array("H1N1#1 VAC")
return CombineImmunizations(Types, 3)
}
}
{fn CombineH1N1ImmunContras()
{
local Types = array("H1N1RSNNTGVN")
return CheckImmunContra(Types, 1)
}
}
{fn CombineFlus()
{
local Types = array("FLU VAX")
return CombineImmunizations(Types, 2)
}
}
{fn CombineFluImmunContras()
{
local Types = array("rsn no fluvx")
return CheckImmunContra(Types, 1)
}
}
{fn CombineMens()
{
local Types = array("MENINGOC VAX")
return CombineImmunizations(Types, 0)
}
}
{fn CombineMenImmunContras()
{
local Types = array("Mening reasn")
return CheckImmunContra(Types, 1)
}
}
{fn CombinePneumos()
{
local Types = array("PNEUMOVAX", "PNEUMO2TRNM")
return CombineImmunizations(Types, 2)
}
}
{fn CombinePneumoImmunContras()
{
local Types = array("RsnPneuNtGn")
return CheckImmunContra(Types, 1)
}
}
{fn CheckImmunContra(Types, Last)
{
local result
result = CombineImmunizations(Types, Last)
if MATCH(TOLOWER(result), 1, "immune")<>0 then
return result
else
if MATCH(TOLOWER(result), 1, "contraindicated")<>0 then
return result
else
return ""
endif
endif
}
}
{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
if toupper(aTypes[index])=="TYPHOID ORAL" then
result = result + count + " " + aDates[index] + " " + "oral typhoid Rx given"
else
if tolower(aVals[index])=="done" or tolower(aVals[index])=="x" then
result = result + count + " " + aDates[index] + " " + aTypes[index]
else
result = result + count + " " + aDates[index] + " " + aVals[index]
endif
endif
endif
endfor
return result
}
}
{fn FillArraysWithObs(ObsTerm, aTypes, aVals, aDates, aDatesConverted)
{
local count
local length
if LIST_OBS(ObsTerm,'Pencil','list','valuedate')<>"" then
local obs_array1 = getfield(LIST_OBS(ObsTerm,'Pencil','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
}
}