I've done this dozens of times in different forms but can't seem to get it to work properly in my new form. With my previous ones, I was only looking at the field to have ANY value so it was always >"" This one needs to trigger on less than 3, but if the boxes are empty it's still displaying Allergy tests negative. This is how it is currently:
{IF OBSNOW("ALLERGY1") <"3" or
OBSNOW("ALLERGY2") <"3" or
OBSNOW("ALLERGY3") <"3" then FMT("Allergy tests negative. ","B,") else "" endif}
I tried flipping it around:
{IF OBSNOW("ALLERGY1") ="" or
OBSNOW("ALLERGY2") ="" or
OBSNOW("ALLERGY3") ="" then "" else FMT("Allergy tests negative. ","B,") endif}
But that didn't help. Thoughts?
Thanks in advance!
Not sure how you are storing data into your obs terms, but I suspect this may be a data type issue. If you are capturing numeric values into the OBS terms, you might try:
{IF val(OBSNOW(“ALLERGY1″)) < 3 OR
val(OBSNOW(“ALLERGY2″)) < 3 OR
val(OBSNOW(“ALLERGY3″)) < 3 then FMT(“Allergy tests negative. “,”B,”) else “” endif}
That will ensure you are comparing a numeric value to a numeric value as opposed to the possibility of comparing a string to a numeric value. I haven't tried this, but I'm assuming that an empty value will be zero when converted to a value.
You could also do this, but you will double the number of comparisons:
{IF val(OBSNOW(“ALLERGY1″)) < 3 OR
OBSNOW("ALLERGY1") == "" OR
val(OBSNOW(“ALLERGY2″)) < 3 OR
OBSNOW("ALLERGY2") == "" OR
val(OBSNOW(“ALLERGY3″)) < 3 OR
OBSNOW("ALLERGY3") == ""
then FMT(“Allergy tests negative. “,”B,”) else “” endif}
Thanks for the advice, I'm going to try val and see how it goes. Using ="" in addition to <"3" won't work because a blank entry means it wasn't tested to, so could not be negative. It shouldn't be this difficult lol
Chris,
if that's the case then it appears you will need to test for three possible conditions which will require nested if statements. In other words, it appears you want to be able to base your text translation on the following conditions:
When obs term is < 3: allergy is negative
When obs term is >= 3: allergy is positive
When obs term is blank or contains invalid value: allergy not tested
My recommendation would be to write a function and then pass the appropriate obs term to the function which would then return the text translation value that should appear in the note. Happy to assist you if you need additional guidance, just email me.
The function code is below...
You would call the function for each obs term as follows (example):
allergyTxtTrans("ALLERGY1")
fn allergyTxtTrans(obs)
{
local strTextTrans = ""
if (val(OBSNOW(obs)) < 3) then
strTextTrans = "Allergy negative"
else if (val(OBSNOW(obs)) >= 3) then
strTextTrans = "Allergy positive"
else
strTextTrans = "Allergy not tested"
endif
endif
return strTextTrans
}
No, I'm only looking for 1 condition, that it's less than 3. I already have another section made that checks for greater than 3 and is working properly, it's just this pesky negative.
All I'm wanting to do is if any of the obsterms have a value of less than 3 (drop down options are actually -, 1, and 2) then display that text, and if nothing is filled out, then nothing displays. The fact that it immediately displays upon opening a note makes me think that an empty box is considered less than 3...
So how would I do
OBSNOW("ALLERGY1") >"0" and OBSNOW("ALLERGY1") "0" and OBSNOW("ALLERGY2") <"3"
?
Have you tried this?
if ((val(OBSNOW(obs)) < 3) AND (OBSNOW(obs) <> UNDEFINED)) then strTextTrans = "Allergy negative" else strTextTrans = "not recorded" endif
I'm sure I could fix it if you just sent the .DLG file.
Greg
Greg,
I'm just breaking it down into a small chunk to trial it out, I'm actually evaluating 84 obsterms. If any of those 84 is less than 3 and greater than 0 then my heading displays. I have a second evaluation for each individual term that, based on their value, will go under a different heading. So while your code would likely work, it's only evaluating 1 instance and needs to be scaled...perhaps it's just not doable.
Here's an example of the working code for positives to give you an idea of what I'm doing:
{IF OBSNOW("Allergy 1")>"3" or
OBSNOW("Allergy 2")>"3" or
OBSNOW("Allergy 3")>"3" or
OBSNOW("Allergy 4")>"3" or
OBSNOW("Allergy 5")>"3" then FMT("
Percutaneous tests positive to: ","B,") else "" endif}
{IF OBSNOW("Allergy 1")>"3" then "Allergy 1, " else "" endif}
{IF OBSNOW("Allergy 2")>"3" then "Allergy 2, " else "" endif}
{IF OBSNOW("Allergy 3")>"3" then "Allergy 3, " else "" endif}
{IF OBSNOW("Allergy 4")>"3" then "Allergy 4, " else "" endif}
{IF OBSNOW("Allergy 5")>"3" then "Allergy 5, " else "" endif}
Which all said and done would look like:
Percutaneous tests positive to:Allergy 1, Allergy 2, etc.
Chris,
sorry for the delayed response. Apparently my CHUG notifications were going to my junk folder. I understand what you are trying to do now. My initial thought is to define an array of all 84 obs terms first and then pass each array value. This method will be more efficient and easier to maintain should you need to add or remove obsterms from the list of allergy terms you are checking. You will just have to test it with all 84 terms to see how quickly it will run, but you can start by adding just 10 terms to the array, and then continue to build this list as you go. You will find this approach a whole lot easier to maintain and troubleshoot because you won't have to replicate an "if then endif" statement for every single obsterm. Keep in mind you are storing the name of the OBS term in the array and not the value itself. The function evalTerm() is what is actually pulling the value of the OBS term and checking it against a threshold to see whether or not to add it to the positive or negative list. To handle the heading text (e.g. Percutaneous tests positive to:) for each section, I would create two document variables (e.g. POSALLERGY and NEGALLERGY and hide them on your form using a visibility group) to store the results of the positive and negative values; and then set the pretext value of each document variable with the appropriate text and formatting you need. You will need a button or a watcher expression to call the function below to initiate the text translation function (i.e. evalTerm()). The code below assumes the same allergy obs terms are used for your positive and negative lists; if not, you can just create separate functions for each test. Hope that makes sense.
//Define your list of allergy OBS terms
global allergyTerms = array("ALLERGY1","ALLERGY2,"ALLERGY3",.....,"ALLERGY84")
//function to generate list of positive and negative tests
{fn evalTerm()
{
local numTerms = size(allergyTerms)
local i
for i=1, i <= numTerms, i=i+1
do
//positive allergy string construction
if (val(OBSNOW(allergyTerms[i])) > 3) then
if (DOCUMENT.POSALLERGY <> "") then
DOCUMENT.POSALLERGY = DOCUMENT.POSALLERGY + ', ' + allergyTerms[i]
else
DOCUMENT.POSALLERGY = allergyTerms[i]
endif
else
endif
//negative allergy string construction
if ((val(OBSNOW(allergyTerms[i])) < 3) AND (OBSNOW(allergyTerms[i]) <> UNDEFINED)) then
if (DOCUMENT.NEGALLERGY <> "") then
DOCUMENT.NEGALLERGY = DOCUMENT.NEGLLERGY + ', ' + allergyTerms[i]
else
DOCUMENT.NEGALLERGY = allergyTerms[i]
endif
else
endif
endfor
}
}
I suspect that your original code would work with:
{IF (OBSNOW(“ALLERGY1″) <”3″ AND OBSNOW(“ALLERGY1″) ”″) or
(OBSNOW(“ALLERGY2″) <”3″ AND OBSNOW(“ALLERGY2″) ”″) or
(OBSNOW(“ALLERGY3″) <”3″ AND OBSNOW(“ALLERGY1″) ”″) then FMT(“Allergy tests negative. “,”B,”) else “” endif}
Alternatively you could create a function to perform the testing:
!fn fnAllergyTestCheckNegative(strValue)
{
return strValue "" AND strValue < 3
}
with the expression:
{IF fnAllergyTestCheckNegative(OBSNOW(“ALLERGY1″))) or
fnAllergyTestCheckNegative(OBSNOW(“ALLERGY2″)) or
fnAllergyTestCheckNegative(OBSNOW(“ALLERGY3″)) then FMT(“Allergy tests negative. “,”B,”) else “” endif}
The array idea is interesting, but it might be tricky to create a watcher to update it automatically. You would either need to include your entire list of observation terms (which might defeat the point of using the array) or you might be able to try using OBS_LIST_CHANGES(). That would likely cause the function to evaluate when any other observation is updated.
Alternatively you could try to set evaluation to be triggered with a button (in which case the user would need to press it) or with a page close handler (which may still have some issues in CPS depending on your version).