Does anybody understand how the Boolean Search works in the Cohort Builder?

Good day everyone,

I’ve been working on the Cohort Builder and I’m currently going through the Cohort Builder to check if everything is working as it should be. But, I really can’t tell if the “Boolean Search” on the Composition tab works as it is supposed to as I don’t know how it’s supposed to work. Can someone help with this? How does the “Boolean Search” work?

cc @ssmusoke

@joelakwes This is my favorite part of the Cohort builder - essentially where the magic happens :slight_smile: based on my understanding:

  1. The foundation of the cohort builder is cohort searches, but each search is only one aspect either a concept value, encounter, person attribute etc

  2. The composition tab allows a user to combine each of the individual cohort queries into more complex cohorts.

  3. The composition follows set theory AND (intersection) OR (union) with the nots etc. following precedence rules for Java (@darius please confirm)

  4. Parentheses are however used to enforce precedence and simplify usage for example

  • 1 AND 2 OR 3 is not very clear
  • 1 AND (2 OR 3) is much better for precedence

Hope this helps, feel free to ask more questions

I still do not understand? What does 1, 2 and 3 represent?

@joelakwes those are the cohort searches you are using in a composition - take a look at the screenshot below from the old cohort builder. I can create more complex cohorts below

  1. Female patients who have the specified encounter my composition would be 1 AND 3
  2. Male patients who have the encounter - 3 NOT 1
  3. Female adults who have the encounter - (1 AND 2) AND 3

Thanks for your response. I tried running this query on the old Cohort Builder but I get this error Error building composition filter. Do you have any idea why this is happening?

Do share a screenshot of what your selection looks like

Thanks for your help so far.

I guess that was happening because there was no saved cohort search. I tried again after doing some search and it works fine. I now understand how it works. On the New Cohort Builder, a description field was added so the user can add a descriptive name for the search.

Also, Any idea how the Search Saved Definitions and Search Saved Cohorts queries work on the Saved Tab in the new Cohort Builder? I noticed this tab isn’t on the Old Cohort Builder.

When you click the disk icon a window pops up allowing you to save a search which is then used in the Saved Tab.

Those are used as a the basis for Data Exports - to build a data export. The steps here may help even though they are not yet complete

You can also take a look at

I get it now. Thanks once again

1 Like

Good Day, Stephen

I want to get clarification on something. Let’s say I make a Search for “Female Patients” and that is 1, and I make another search for “Patients who have Weight(Kg) < 200” which is 2. In this case, which of the results below is a boolean search of 1 AND 2 supposed to return:

  • A combination of the results of search 1 and search 2

  • A new query result of all Female Patients whose weight is less than 200

@joelakwes You will get the only the patients who appear in both groups.

However if you use 1 OR 2 - you will bet the unique patients in both groups, no patient will appear twice.

Ok, so it just combines the patients from the result of both searches and not create a new query with the constraints from the searches.

Thanks, it’s clearer now

@joelakwes I am not sure of the backend implementation - of how the patient lists are merged would need to go deeper into the code to understand that. As an end user all I see is the output of the action

Can you help check it out?