Does anyone have a function already built they could share that looks at a list of obs and returns the most recent with value and date? The list of obs needs to be variable. I want to use the function multiple times in a handout.
For example, I need to look for the most recent LDL, be it from the obs "LDL" or "LDL (CALCUL)".
Any help would be appreciated - thanks much...
We use this functionality in many of our forms:
{!
global gblObsNamesImmRevPeds = array("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", "KINRIX", "PENT#1", "PERTUSSISVAX", "HIB #1", "TD Booster", "Boostrixdose", "DTAPbsttrade", "TETANUS IMMU", "TDAP", "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", "KINRIX", "PENT#1", "IPV reason", "Pedia reason", "HIBHEPB#1", "HIB1HEPB2", "DTaP/HIB#1", "DTP/HIB #1", "HemInfB#1", "HIBHEPB#2", "HIB2HEPB3", "DTaP/HIB#2", "DTP/HIB #2", "HemInfB#2", "HIBHEPB#3", "DTaP/HIB#3", "DTP/HIB #3", "HemInfB#3", "HIB3HEPB4", "DTaP/HIB#4", "DTP/HIB #4", "HemInfB#4", "DTaP/HIB#5", "DTP/HIB #5", "HemInfB#5", "PENT#1", "HIB reason", "PPD RESULT","TB-PPD INTRP","BCG VAX HX", "SYNAGIS", "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", "ROTAVIR#1", "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", "H1N1#1 VAC", "H1N1RSNNTGVN", "FLU VAX", "rsn no fluvx", "MENINGOC VAX", "Mening reasn", "PNEUMOVAX", "PNEUMO2TRNM", "RsnPneuNtGn", "HPV #1 DRUG", "HPVDECLINE")
global gblObsListChangesImmRevPeds
global gblCalcForTransImmRevPeds = ""
}
{
global CombinedDTPs = ""
global CombinedBoosters = ""
global CombinedDTPImmunContras = ""
global CombinedPolios = ""
global CombinedPolioImmunContras = ""
global CombinedHIBs = ""
global CombinedHIBImmunContras = ""
global CombinedPPDs = ""
global CombinedHepAs = ""
global CombinedHepAImmunContras = ""
global CombinedMMRs = ""
global CombinedMMRImmunContras = ""
global CombinedPCVs = ""
global CombinedPCVImmunContras = ""
global CombinedVaricellas = ""
global CombinedVarImmunContras = ""
global CombinedRotas = ""
global CombinedPalivs = ""
global CombinedHepBs = ""
global CombinedHepBImmunContras = ""
global CombinedH1N1s = ""
global CombinedH1N1ImmunContras = ""
global CombinedFlus = ""
global CombinedFluImmunContras = ""
global CombinedMens = ""
global CombinedMenImmunContras = ""
global CombinedPneumos = ""
global CombinedPneumoImmunContras = ""
global CombinedHPVs = ""
global CombinedHPVImmunContras = ""
}
{if obs_list_changes()<>gblObsListChangesImmRevPeds then
gblObsListChangesImmRevPeds = obs_list_changes()
if gblObsListChangesImmRevPeds=="" then
SetGlobalsImmRevPeds()
else
CheckForObsImmRevPeds()
endif
else
""
endif}
{fn CheckForObsImmRevPeds()
{
local obslistchangesarray
local obs
local sizearray
local sizearray2
local index
local index2
local pos
obslistchangesarray = GETFIELD(gblObsListChangesImmRevPeds, hret, "")
sizearray2 = SIZE(gblObsNamesImmRevPeds)
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(gblObsNamesImmRevPeds[index2]) then
SetGlobalsImmRevPeds()
index2 = sizearray2
index = sizearray
endif
index2 = index2 + 1
endwhile
endif
index = index + 1
endwhile
}
}
{fn SetGlobalsImmRevPeds()
{
gblCalcForTransImmRevPeds = "done"
CombinedBoosters = CombineBoostersPeds()
CombinedDTPs = CombineDTPs()
CombinedDTPImmunContras = CombineDTPImmunContras()
CombinedPolios = CombinePolios()
CombinedPolioImmunContras = CombinePolioImmunContras()
CombinedHIBs = CombineHIBs()
CombinedHIBImmunContras = CombineHIBImmunContras()
CombinedPPDs = CombinePPDs2()
CombinedHepAs = CombineHepAs()
CombinedHepAImmunContras = CombineHepAImmunContras()
CombinedMMRs = CombineMMRs()
CombinedMMRImmunContras = CombineMMRImmunContras()
CombinedPCVs = CombinePCVs()
CombinedPCVImmunContras = CombinePCVImmunContras()
CombinedVaricellas = CombineVaricellas()
CombinedVarImmunContras = CombineVarImmunContras()
CombinedRotas = CombineRotas()
CombinedPalivs = CombinePalivs()
CombinedHepBs = CombineHepBs()
CombinedHepBImmunContras = CombineHepBImmunContras()
CombinedH1N1s = CombineH1N1s()
CombinedH1N1ImmunContras = CombineH1N1ImmunContras()
CombinedFlus = CombineFlus()
CombinedFluImmunContras = CombineFluImmunContras()
CombinedMens = CombineMens()
CombinedMenImmunContras = CombineMenImmunContras()
CombinedPneumos = CombinePneumos()
CombinedPneumoImmunContras = CombinePneumoImmunContras()
CombinedHPVs = CombineHPVs()
CombinedHPVImmunContras = CombineHPVImmunContras()
return ""
}
}
{fn CombineDTPs()
{
local Types = array("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", "KINRIX", "PENT#1", "PERTUSSISVAX")
return CombineImmunizations(Types, 0)
}
}
{fn CombineBoostersPeds()
{
local Types = array("TD Booster", "Boostrixdose", "DTAPbsttrade", "TETANUS IMMU", "TDAP")
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", "KINRIX", "PENT#1")
return CombineImmunizations(Types, 0)
}
}
{fn CombinePolioImmunContras()
{
local Types = array("IPV reason", "Pedia reason")
return CheckImmunContra(Types, 1)
}
}
{fn CombineHIBs()
{
local Types = array("HIBHEPB#1", "HIB1HEPB2", "DTaP/HIB#1", "DTP/HIB #1", "HemInfB#1", "HIBHEPB#2", "HIB2HEPB3", "DTaP/HIB#2", "DTP/HIB #2", "HemInfB#2", "HIBHEPB#3", "DTaP/HIB#3", "DTP/HIB #3", "HemInfB#3", "HIB3HEPB4", "DTaP/HIB#4", "DTP/HIB #4", "HemInfB#4", "DTaP/HIB#5", "DTP/HIB #5", "HemInfB#5", "PENT#1", "HIB #1")
return CombineImmunizations(Types, 0)
}
}
{fn CombineHIBImmunContras()
{
local Types = array("HIB reason")
return CheckImmunContra(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 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 CombineRotas()
{
local Types = array("ROTAVIR#1")
return CombineImmunizations(Types, 0)
}
}
{fn CombinePalivs()
{
local Types = array("SYNAGIS")
return CombineImmunizations(Types, 1)
}
}
{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 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, 3)
}
}
{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 CombineHPVs()
{
local Types = array("HPV #1 DRUG")
return CombineImmunizations(Types, 0)
}
}
{fn CombineHPVImmunContras()
{
local Types = array("HPVDECLINE")
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
}
}
Thank you!!