Please Help with my logic

The goal of the hidden value for each rapid test type is to report on tests
that were performed and came back negative without placing additional
burden on the user to indicate those.

The current collection of test questions displays only if the user
indicates that rapid testing is needed during this visit. The questions are:

  1. positive_test_list: Select all rapid tests which had POSITIVE results
    (check box)
    1. hiv
    2. syphilis
    3. gonorrhea
    4. chlamydia
    5. malaria
    6. none_of_above
  2. tests_not_performed: Were any rapid tests NOT performed? (check box)
    1. hiv_not_performed
    2. syphilis_not_performed
    3. gonorrhea_not_performed
    4. chlamydia_not_performed
    5. malaria_not_performed
    6. all_tests_performed

Essentially, we want to have one hidden value per test type which indicates
deliberately whether or not that test was performed AND negative. To that
end, I attempted hidden values called “[testname]_done_negative” but when I
go to test, the fields all read “no” even though I selected none_of_above
and all_tests_performed (scenario 4). See below example of the calculation
logic in chlamydia_done_negative field:

If(not(selected(#form/positive_test_list, ‘chlamydia’) and
not(selected(#form/tests_not_performed, ‘chlamydia_not_performed’)) or
not(selected(#form/positive_test_list, ‘chlamydia’) and
selected(#form/tests_not_performed, ‘all_tests_performed’)) or
selected(#form/positive_test_list, ‘none_of_above’) and
not(selected(#form/tests_not_performed, ‘chlamydia_not_performed’)) or
selected(#form/positive_test_list, ‘none_of_above’) and
selected(#form/tests_not_performed, ‘all_tests_performed’)), ‘yes’, ‘no’)

This is intended to capture a test as negative if:

  1. the test was not marked positive and was not marked not-performed OR

  2. the test was not marked positive and the all_tests_performed check box
    was marked OR

  3. none_of_above was selected from positive_test_list and test was not
    marked not-performed OR

  4. none_of_above was selected from positive_test_list and all_tests_performed
    was selected from tests_not_performed

Hi Jessica,

Since you’re combining *and *and or in your logic, you may need brackets
to differentiate when two things should be and-ed vs. or-ed together.
Based on your description, I’ve added some brackets I think are missing to
your logic. See below (added brackets are bolded):

if(
(not(selected(#form/positive_test_list, ‘chlamydia’) and
not(selected(#form/tests_not_performed, ‘chlamydia_not_performed’))
)

or
(not(selected(#form/positive_test_list, ‘chlamydia’) and
selected(#form/tests_not_performed, ‘all_tests_performed’))
)

or
(selected(#form/positive_test_list, ‘none_of_above’) and
not(selected(#form/tests_not_performed, ‘chlamydia_not_performed’))
)

or
(selected(#form/positive_test_list, ‘none_of_above’) and
selected(#form/tests_not_performed, ‘all_tests_performed’))
)
,
‘yes’, ‘no’)

Thanks,
Sheel

··· On Thu, Oct 20, 2016 at 12:07 PM, Jessica Clatterbuck wrote:

The goal of the hidden value for each rapid test type is to report on
tests that were performed and came back negative without placing additional
burden on the user to indicate those.

The current collection of test questions displays only if the user
indicates that rapid testing is needed during this visit. The questions are:

  1. positive_test_list: Select all rapid tests which had POSITIVE
    results (check box)
    1. hiv
    2. syphilis
    3. gonorrhea
    4. chlamydia
    5. malaria
    6. none_of_above
  2. tests_not_performed: Were any rapid tests NOT performed? (check box)
    1. hiv_not_performed
    2. syphilis_not_performed
    3. gonorrhea_not_performed
    4. chlamydia_not_performed
    5. malaria_not_performed
    6. all_tests_performed

Essentially, we want to have one hidden value per test type which
indicates deliberately whether or not that test was performed AND negative.
To that end, I attempted hidden values called "[testname]_done_negative"
but when I go to test, the fields all read “no” even though I selected
none_of_above and all_tests_performed (scenario 4). See below example of
the calculation logic in chlamydia_done_negative field:

If(not(selected(#form/positive_test_list, ‘chlamydia’) and
not(selected(#form/tests_not_performed, ‘chlamydia_not_performed’)) or
not(selected(#form/positive_test_list, ‘chlamydia’) and
selected(#form/tests_not_performed, ‘all_tests_performed’)) or
selected(#form/positive_test_list, ‘none_of_above’) and
not(selected(#form/tests_not_performed, ‘chlamydia_not_performed’)) or
selected(#form/positive_test_list, ‘none_of_above’) and
selected(#form/tests_not_performed, ‘all_tests_performed’)), ‘yes’, ‘no’)

This is intended to capture a test as negative if:

  1. the test was not marked positive and was not marked not-performed OR

  2. the test was not marked positive and the all_tests_performed check box
    was marked OR

  3. none_of_above was selected from positive_test_list and test was not
    marked not-performed OR

  4. none_of_above was selected from positive_test_list and all_tests_performed
    was selected from tests_not_performed


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Sheel Shah
Project Manager | Dimagi
m: +1.781.428.5419 | skype: sheel_shah

Thank you SO much Sheel! This was quite over my head and I was getting very
frustrated. Your fix seems to hold up in testing. I really appreciate it.

··· On Friday, October 21, 2016 at 2:48:49 PM UTC-4, Sheel Shah wrote: > > Hi Jessica, > > Since you're combining *and *and *or* in your logic, you may need > brackets to differentiate when two things should be and-ed vs. or-ed > together. Based on your description, I've added some brackets I think are > missing to your logic. See below (added brackets are bolded): > > if( > *(*not(selected(#form/positive_test_list, 'chlamydia') and > not(selected(#form/tests_not_performed, 'chlamydia_not_performed'))*)* > or > *(*not(selected(#form/positive_test_list, 'chlamydia') and > selected(#form/tests_not_performed, 'all_tests_performed'))*)* > or > *(*selected(#form/positive_test_list, 'none_of_above') and > not(selected(#form/tests_not_performed, 'chlamydia_not_performed'))*)* > or > *(*selected(#form/positive_test_list, 'none_of_above') and > selected(#form/tests_not_performed, 'all_tests_performed'))*)*, > 'yes', 'no') > > Thanks, > Sheel > > > On Thu, Oct 20, 2016 at 12:07 PM, Jessica Clatterbuck <imc...@gmail.com > wrote: > >> The goal of the hidden value for each rapid test type is to report on >> tests that were performed and came back negative without placing additional >> burden on the user to indicate those. >> >> >> >> The current collection of test questions displays only if the user >> indicates that rapid testing is needed during this visit. The questions are: >> >> >> >> 1. positive_test_list: Select all rapid tests which had POSITIVE >> results (check box) >> 1. hiv >> 2. syphilis >> 3. gonorrhea >> 4. chlamydia >> 5. malaria >> 6. none_of_above >> 2. tests_not_performed: Were any rapid tests NOT performed? (check >> box) >> 1. hiv_not_performed >> 2. syphilis_not_performed >> 3. gonorrhea_not_performed >> 4. chlamydia_not_performed >> 5. malaria_not_performed >> 6. all_tests_performed >> >> >> >> Essentially, we want to have one hidden value per test type which >> indicates deliberately whether or not that test was performed AND negative. >> To that end, I attempted hidden values called "[testname]_done_negative" >> but when I go to test, the fields all read "no" even though I selected >> none_of_above and all_tests_performed (scenario 4). See below example of >> the calculation logic in chlamydia_done_negative field: >> >> >> If(not(selected(#form/positive_test_list, 'chlamydia') and >> not(selected(#form/tests_not_performed, 'chlamydia_not_performed')) or >> not(selected(#form/positive_test_list, 'chlamydia') and >> selected(#form/tests_not_performed, 'all_tests_performed')) or >> selected(#form/positive_test_list, 'none_of_above') and >> not(selected(#form/tests_not_performed, 'chlamydia_not_performed')) or >> selected(#form/positive_test_list, 'none_of_above') and >> selected(#form/tests_not_performed, 'all_tests_performed')), 'yes', 'no') >> >> >> This is intended to capture a test as negative if: >> >> 1. the test was not marked positive and was not marked not-performed OR >> >> 2. the test was not marked positive and the all_tests_performed check box >> was marked OR >> >> 3. none_of_above was selected from positive_test_list and test was not >> marked not-performed OR >> >> 4. none_of_above was selected from positive_test_list and all_tests_performed >> was selected from tests_not_performed >> >> -- >> You received this message because you are subscribed to the Google Groups >> "commcare-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to commcare-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Sheel Shah > Project Manager | Dimagi > m: +1.781.428.5419 | skype: sheel_shah > > >