Below is some code I created to find active meds and I populate a field that is in a non visible region with yes or no. I then make the original field visible base on the answer comparing to the field in the unseen region. Basically I search for the med class names. This should point you in the right direction. I use this for exactly what your inquiring about.
/*finds ACE/ARB, Antithrombotic and Beta Blocker Medications*/
{!fn fnGetMeds() {
local medvalue = "None"
local med1value = "None"
local medACEvalue = "None"
local medARBvalue = "None"
local medACEdate
local ACERefdate
local medARBdate
local ARBRefdate
local medlist
local medary
local medmax
local medcount
local medrow
medlist = MEDS_AFTER("delimited")
medary = getfield(medlist,"|","")
medmax = size(medary)
for medcount=1, medcount 0 or match(medrow[2],1,"CLOPIDOGREL") > 0 or match(medrow[2],1,"DABIGATRAN") > 0 or match(medrow[2],1,"DIPYRIDAMOLE") > 0 or match(medrow[2],1,"ENOXAPARIN") > 0 or match(medrow[2],1,"RIVAROXABAN") > 0 or match(medrow[2],1,"WARFARIN") > 0 then medvalue = "True"
else
endif
/*Beta Blocker med search */
If match(medrow[2],1,"ACEBUTOLOL") > 0 or match(medrow[2],1,"ATENOLOL") > 0 or match(medrow[2],1,"LEVOBUNOLOL") > 0 or match(medrow[2],1,"SOTALOL") > 0 or match(medrow[2],1,"BETAXOLOL") > 0 or match(medrow[2],1,"BISOPROLOL") > 0 or match(medrow[2],1,"TIMOLOL") > 0 or match(medrow[2],1,"NEBIVOLOL") > 0 or match(medrow[2],1,"CARVEDILOL") > 0 or match(medrow[2],1,"NADOLOL") > 0 or match(medrow[2],1,"PROPRANOLOL") > 0 or match(medrow[2],1,"LABETALOL") > 0 or match(medrow[2],1,"METOPROLOL") > 0 or match(medrow[2],1,"PINDOLOL") > 0 then med1value = "True"
else
endif
/*ACE Med Search */
If match(medrow[2],1,"QUINAPRIL") > 0 or match(medrow[2],1,"PERINDOPRIL") > 0 or match(medrow[2],1,"RAMIPRIL") > 0 or match(medrow[2],1,"BENAZEPRIL") > 0 or match(medrow[2],1,"CAPTOPRIL") > 0 or match(medrow[2],1,"ENALAPRIL") > 0 or match(medrow[2],1,"FOSINOPRIL") > 0 or match(medrow[2],1,"LISINOPRIL") > 0 or match(medrow[2],1,"TRANDOLAPRIL") > 0 or match(medrow[2],1,"MOEXIPRIL") > 0 then medACEvalue = "True"
else
endif
If match(medrow[2],1,"QUINAPRIL") > 0 or match(medrow[2],1,"PERINDOPRIL") > 0 or match(medrow[2],1,"RAMIPRIL") > 0 or match(medrow[2],1,"BENAZEPRIL") > 0 or match(medrow[2],1,"CAPTOPRIL") > 0 or match(medrow[2],1,"ENALAPRIL") > 0 or match(medrow[2],1,"FOSINOPRIL") > 0 or match(medrow[2],1,"LISINOPRIL") > 0 or match(medrow[2],1,"TRANDOLAPRIL") > 0 or match(medrow[2],1,"MOEXIPRIL") > 0 then medACEdate = val(medrow[9])
else
endif
/* Check for Refill Date*/
If match(medrow[2],1,"QUINAPRIL") > 0 or match(medrow[2],1,"PERINDOPRIL") > 0 or match(medrow[2],1,"RAMIPRIL") > 0 or match(medrow[2],1,"BENAZEPRIL") > 0 or match(medrow[2],1,"CAPTOPRIL") > 0 or match(medrow[2],1,"ENALAPRIL") > 0 or match(medrow[2],1,"FOSINOPRIL") > 0 or match(medrow[2],1,"LISINOPRIL") > 0 or match(medrow[2],1,"TRANDOLAPRIL") > 0 or match(medrow[2],1,"MOEXIPRIL") > 0 then ACERefdate = val(medrow[16])
else
endif
/*ARB med search */
If match(medrow[2],1,"CANDESARTAN") > 0 or match(medrow[2],1,"IRBESARTAN") > 0 or match(medrow[2],1,"OLMESARTAN") > 0 or match(medrow[2],1,"VALSARTAN") > 0 or match(medrow[2],1,"LOSARTAN") > 0 or match(medrow[2],1,"TELMISARTAN") > 0 then medARBvalue = "True"
else
endif
If match(medrow[2],1,"CANDESARTAN") > 0 or match(medrow[2],1,"IRBESARTAN") > 0 or match(medrow[2],1,"OLMESARTAN") > 0 or match(medrow[2],1,"VALSARTAN") > 0 or match(medrow[2],1,"LOSARTAN") > 0 or match(medrow[2],1,"TELMISARTAN") > 0 then medARBdate = val(medrow[9])
else
endif
If match(medrow[2],1,"CANDESARTAN") > 0 or match(medrow[2],1,"IRBESARTAN") > 0 or match(medrow[2],1,"OLMESARTAN") > 0 or match(medrow[2],1,"VALSARTAN") > 0 or match(medrow[2],1,"LOSARTAN") > 0 or match(medrow[2],1,"TELMISARTAN") > 0 then ARBRefdate = val(medrow[16])
else
endif
endfor
if (medvalue = "True") then DOCUMENT.MEDS_PRESENT = "Yes"
else DOCUMENT.MEDS_PRESENT = "No"
endif
if (med1value = "True") then DOCUMENT.MEDS1_PRESENT = "Yes"
else DOCUMENT.MEDS1_PRESENT = "No"
endif
if (medACEvalue = "True") then DOCUMENT.ACE_PRESENT = "Yes"
else DOCUMENT.ACE_PRESENT = "No"
endif
if (medARBvalue = "True") then DOCUMENT.ARB_PRESENT = "Yes"
else DOCUMENT.ARB_PRESENT = "No"
endif
/* Select ACE date as prescribed date unless refill was given */
If (ACERefdate "") then DOCUMENT.ACE_REFIL_DA = str(ACERefdate)
else DOCUMENT.ACE_REFIL_DA = str(medACEdate)
endif
/* Select ARB date as prescribed date unless refill was given */
If (ARBRefdate "") then DOCUMENT.ARB_REFIL_DA = str(ARBRefdate)
else DOCUMENT.ARB_REFIL_DA = str(medARBdate)
endif
return medvalue
}
}