Cohort category is defined as text, or as number ?
Try putting a commit records/requests after line 7. Temporarily, ofc, and see if it goes into the IF.
Also begin the script by setting 2 vars,
Set Variable($Cohort; Patient InformationMaster::Cohort Category")
Set Variable($TRS; Patient InformationMaster::Test Retest Subset)
and use these in the IFs
Cohort Category is a text field.
also, something like
set field [xxx; value1]
set field [xxx; value 2]
set field [xxx; choose (test; value 2; value 1) ]
You have the following possible conditions...
CATEGORY RETEST FLAG DATE COHORT 1 YES PLUS 30 COHORT 1 NO PLUS 93 COHORT 2 YES PLUS 30 COHORT 2 NO PLUS 93 COHORT 3 YES PLUS 30 COHORT 3 NO PLUS 30 COHORT 4 YES PLUS 30 COHORT 4 NO PLUS 365
Is this what you want?
What happens if CATEGORY is not COHORT 1,2,3 or 4? or the RETEST FLAG is not = "Yes" or not = "No"?
If it works as you expect in all possible conditions then any refactoring may be premature optimization.
As you work on this problem, and I can't really help without having the actual code, it is a good idea NOT to embed numbers (so-called "magic numbers") directly into code/scripts. Consider having a table with constants or date offsets defined. Or, create a variable like "TODAY_PLUS_30_DAYS" based on a data field or calculation alone.
Including numbers like this makes code understanding more difficult and if a number should change, maintenance a probable nightmare.
Just an idea (see "Code Complete 2", MS Press).
The commit didn’t help.
Yes that is what I want. The users set the cohort from a drop-down list which they cannot change, the same for testretest. Both are defined as text. So, I can’t figure out why the tests are failing. I just wanted to be sure that my nesting was written correctly.
Also, does anyone know why I can’t reply in the FM forum? Nothing happens when I click on Reply. I can only reply via email.
the only reason that the script would proceed as you specify (lines 9 >15>21) is if the data in Cohort Category field in the current record at the time of execution is not equal to the text you specify in the If() arguments.
"Test"="test" = true
"Test"="TEST" = true
"test "="test" not true
Next time you run it through the debugger use the data viewer to test the comparison operation...
Category field = "Cohort 1" and see what the result is while it is executing. Any extra spaces or non printable characters in the data in the field OR in the "Text string" argument will cause the test to return false.
Basically lines 8 - 21 it could be rewritten as
Set Field(target date; BaselineDate + 30)
Set Field(target date; BaselineDate + choose( Div(getasNumber(cohort);3); 93;365)
Thanks everyone, I found the problem. The Cohort Category value stored in the record was actually “Cohort 1 “. There was a trailing space for that entry in the value list.
Glad you found it. sounds like my suggestion lead to a solution.
Yes, yours and Siplus. Thank you, everyone.
Beware this hidden characters!