I would like to fashion an if-then statement that looks through the problem list (OBS: FORMPROBLEMS) and then do something. What I have so far is below, however it keeps resulting with "no". I suspect it is because I am using the wrong wildcard character?
{if OBSPREV('FORMPROBLEMS') = '* Conjunctivitis *' then 'yo' else 'no' endif}
the disease in question is in fact in the obs value. see: "FORMPROBLEMS: Urinary tract infection , Conjunctivitis , Hiv disease , debility , Vaccination , Well child exam"
Help would be appreciated.
There is no such thing as a wildcard character in MEL, I think you want this.
match(OBSPREV('FORMPROBLEMS'),'Conjunctivitis')>0
Match will return the position of the string match for the second argument in the first argument. If no match is found then zero is returned.
To add to the correct advice provided, some important notes about 'match'.
Match is a 'literal' and one 'use' function in that in order for it to make a match, the text must be exactly the same.
'Literal' aspect:
Match uses the ASCII code equivalent of characters so upper and lower case characters are not the same. Likewise, spaces, punctuation, and hidden characters can cause a match to fail.
In other words, 'Apple' is not the same as 'apple'.
You can compensate for case differences by invoking 'toupper' or 'tolower' commands as appropriate.
'Use' aspect:
Match returns a zero if no match is found, otherwise it returns the numerical index position of the start of the string within a string. It is important to note that as soon as a match is made, the function is exited, meaning if the string you are looking for exists in more than one location in the string, it will not 'see' anything beyond the first instance. This is of concern when you are looking for a specific phrase that may be contained inside of another phrase.
In other words, if you are looking to find the word 'if' in the string 'Specificity is required if it exists more than once.', you will need a method to ignore the 'if' in 'specificity', which is the first instance of 'if' in the string and would otherwise provide a false result.
This can be accomplished by using 'if ' instead of 'if'. By including the trailing space, we avoid the first instance of 'if' in specificity' and are able to find the 'if' we are looking for'.
Should you need to find more than one instance, consider breaking the string into an array and looping through it to match on each element. This approach actually works rather well.
When understood, match can be a powerful tool, certainly not wildcard strength, but it is as close as we can get in MEL.
I'm getting an error using this match function. maybe i'm not using it correctly?
{if match(OBSPREV('FORMPROBLEMS'),'Conjunctivitis')>0 then ‘yo’ else ‘no’ endif}
returns:
{if match(OBSPREV('FORMPROBLEMS'),'Conjunctivitis')>0 then ‘yo’ else ‘no’ endif <-UNKNOWN ERROR
The use of match looks okay, I would avoid backticks though, I usually use double quotes for all things MEL, single quotes should also work, but backticks can cause issues. Copying and pasting MEL can also cause issues depending on where you paste. Pasting in VFE is not problematic, pasting in handout templates or quicktext in Centricity can be. Try this
{if match(OBSPREV("FORMPROBLEMS"),"Conjunctivitis")>0 then "yo" else "no" endif}
fantastic! that worked. thank you for your help!