Part 4: Exclusion Terms and Parentheses

Purpose

This is the fourth article in a series about how to write ESSENCE free-text queries. Free-text coding in ESSENCE, which is accessible to all users, follows distinct patterns. Learning to read these patterns allows users to take queries from many places and repurpose them to suit their unique needs. Syndromic surveillance depends heavily on sharing methods, and practitioners must understand the language.

Free Text Coding blue fractal with white text

Introduction

Please see Part 1: Wildcards for background information about the search criteria for ESSENCE free-text queries, which are built around Boolean logical operators and regular expressions.

So far in this series, we have covered basic query notation, use of carets, underscores, and brackets, and "OR" and "AND" statements. The final two parts of a query's structure can involve "ANDNOT" statements and parentheses. We have demonstrated the power of inclusion terms, and the "ANDNOT" statement is the next step to leveraging the system's query resources. We will also show how to add parentheses to specify how these "OR", "AND", and "ANDNOT" statements are applied and interact with each other.

"ANDNOT" statements

"ANDNOT" statements, also referred to as negations, exclusions, or exclusionary statements, are a common way to specify what you do not want your query to return. These statements are often leveraged in a syndrome definition to exclude common false positives. An "ANDNOT" statement without parentheses connects the word before it and the word after and will remove any returns where both criteria are met. To demonstrate this, we can work through the following simple query.

  • THIS,OR,THAT,ANDNOT,THERE

In this query, ESSENCE will return fields containing the term "THIS" or the term "THAT" and then look through the "THAT" returns for the presence of the term "THERE" and remove these records where both criteria are met. "ANDNOT" statements do not specify the order in which the terms appear. Also note that the example's "THERE" exclusion is only applied to "THAT" and does not apply to "THIS". "THIS" is unaffected by the exclusion statement. Similar to "AND" and "OR" statements, ESSENCE queries are not case sensitive, neither are the operators, and all operators should be surrounded by commas.

Let's assume the following Chief Complaints (used in Parts 1–3) and a desire to create a query for fall-related injuries.

  1. Fall
  2. Fell getting out of car
  3. Left arm injury; Fall
  4. Falling out with friends; Suicidal
  5. Feels crestfallen
  6. Patient brought in after falling on face
  7. Fall; Left wrist injury
  8. Feels congested; Allergies

You may reasonably assume the boldfaced CCs 1, 2, 3, 6, and 7 are the intended cases and 4, 5, and 8 are false positives.

“ANDNOT” Query Examples

Code Description

^Fall^

This is a simple query of a term surrounded by carets taken from Part 1. It returns CCs 1, 3, 4, 5, 6, and 7.
^Fall^,ANDNOT,^Crestfallen^ This query negates the false positive in CC 5. Returns CCs 1, 3, 4, 6, and 7.
^Fall^,OR,^Fell^,ANDNOT,^Crestfallen^ This covers both forms of “Fall” in our CCs, but the negation of “Crestfallen” follows the term ^Fell^. Since “Fell” and “Crestfallen” don’t appear in the same CC, no CCs are negated. Returns CCs 1, 2, 3, 4, 5, 6, and 7.
^Fall^,ANDNOT,^Falling out^,ANDNOT,^Crestfallen^ “ANDNOT” statements can be written in series. Multiple exclusionary statements in a row apply to the inclusionary term they immediately follow. Both negation terms apply to the ^Fall^ term. Returns CCs 1, 2, 3, 6, and 7.

Parentheses

Complex syndrome definitions often use parentheses to group terms and apply statements in different ways. "ANDNOT" statements are frequently used alongside parenthetical groupings. Regarding notation in ESSENCE, all parentheses should be surrounded by commas, except when the parenthesis starts or ends the statement. To demonstrate this notation and how parentheses can redistribute statements, we can work through the following simple query.

  • (,THIS,OR,THAT,),ANDNOT,(,THERE,OR,THEN,)

In this query, since both sections are surrounded in parentheses, ESSENCE will apply both the "ANDNOT" negations "THERE" and "THEN" to both the initial inclusion terms "THIS" and "THAT". An ESSENCE query will return fields containing either term "THIS" or the term "THAT" so long as there is not also the presence of either term "THERE" or "THEN". Notice the second "(" is surrounded by commas whereas the first one isn't because it is the first character in the query. Likewise, notice the first ")" is surrounded by commas whereas the last one isn't because it's the last character in the query. Misplaced commas are one of the most frequent reasons a query doesn't work as intended.

Let's assume the following Chief Complaints (used in Parts 1–3) and a desire to create a query for fall-related injuries.

  1. Fall
  2. Fell getting out of car
  3. Left arm injury; Fall
  4. Falling out with friends; Suicidal
  5. Feels crestfallen
  6. Patient brought in after falling on face
  7. Fall; Left wrist injury
  8. Feels congested; Allergies

You may reasonably assume the boldfaced CCs 1, 2, 3, 6, and 7 are the intended cases and 4, 5, and 8 are false positives.

Query Examples with Parentheses

Code Description

^Fall^

This is a simple query of a term surrounded by carets taken from Part 1. It returns CCs 1, 3, 4, 5, 6, and 7.
(,^Fall^,) Sometimes parentheses won’t change anything. This query functions exactly the same as the query above it. Returns CCs 1, 3, 4, 5, 6, and 7.
(,^Fall^,OR,^Fell^,),ANDNOT,^Crestfallen^ This covers both forms of “Fall” in our CCs, and the parentheses ensure the negation applies across both initial terms. Returns CCs 1, 2, 3, 4, 6, and 7.
^Fall^,ANDNOT,^Falling out^,ANDNOT,^Crestfallen^ “ANDNOT” statements can be written in series. Multiple exclusionary statements in a row apply to the inclusionary term they immediately follow. Both negation terms apply to the ^Fall^ term. Returns CCs 1, 2, 3, 6, and 7.
(,^Fall^,OR,^Fell^,),ANDNOT,(,^Crestfallen^,or,^Falling Out^,ANDNOT,(,^Out a window^,),) Syndromes can get complicated with multiple-nested parentheses. Notice this query attempts to negate the “Falling out with friends” CC while also trying to include visits related to “Falling out a window.” In this instance, the “ANDNOT” term is double negated by a second “ANDNOT” term. Returns CCs 1, 2, 3, 6, and 7.

Putting two sets of parentheses with different criteria linked by an "AND" statement means at least one item from each set of criteria must be met. In the example below, both coded statements will return the same visits, but the second statement is far more concise and easier to read:

  • ^Fall^,AND,^Injur^,OR,^Fall^,AND,^Face^,OR,^Fell^,AND,^Injur^,OR,^Fell^,AND,^Face^
  • (,^Fall^,or,^Fell^,),AND,(,^Injur^,or,^Face^,)

Putting it in practice

Here are a couple examples to show how "ANDNOT" and parentheses can be used in practice:

Example 1

  • (,^measl^,or,^meez^,or,^mesles^,or,^rubeo^,or, ^Measel^,or,^Measul^,or,^[;/ ]b05^,),andnot,(,^titer^,or,^measles mumps rubella^,or,^mmr^,or,^vacc^,or,^shot^,or,^immun^,or,^rubel^,or,^proph^,or,^room b05^,or,^german^,or,^homesless^,or,^rule out measles^,)

This example is an excerpt from the CDC Measles v1 CCDD Category. Notice how all inclusionary terms are grouped in a parenthetical statement, all negation terms are grouped into another, and then both statements are linked with an "ANDNOT" statement. This makes the query concise and easy to read. Without these parentheses to group the two sets, the first two inclusion terms alone would be:

  • ^measl^,ANDNOT,^titer^,ANDNOT,^measles mumps rubella^,ANDNOT,^mmr^,ANDNOT,^vacc^,ANDNOT,^shot^,ANDNOT,^immun^,ANDNOT,^rubel^,ANDNOT,^proph^,ANDNOT,^room b05^,ANDNOT,^german^,ANDNOT,^homesless^,ANDNOT,^rule out measles^,OR,^meez^,ANDNOT,^titer^,ANDNOT,^measles mumps rubella^,ANDNOT,^mmr^,ANDNOT,^vacc^,ANDNOT,^shot^,ANDNOT,^immun^,ANDNOT,^rubel^,ANDNOT,^proph^,ANDNOT,^room b05^,ANDNOT,^german^,ANDNOT,^homesless^,ANDNOT,^rule out measles^,

Example 2

  • (,^[;/ ]T40.1X1A^,OR,^[;/ ]T401X1A^,OR,^[;/ ]T40.1X4A^,OR,^[;/ ]T401X4A^,OR,^[;/ ]965.01[;/]^,OR,^[;/ ]96501[;/]^,OR,^[;/ ]E850.0^,OR,^[;/ ]E8500^,or,^295174006^,or,^295175007^,or,^295176008^,),or,(,(,(,^narcan^,or,^naloxo^,or,^poison^,or,^verdo[se][se]^,or,^over dose^,or,^overose^,or,^nodding^,or,^ nod ^,or,^snort^,or,^in[gj]est^,or,^intoxic^,or,^unresponsiv^,or,^loss of consciousness^,or,^syncop^,or,^shortness of breath^,or,^short of breath^,or,^altered mental status^,),and,(,^her[io][oi]n^,or,^ hod ^,or,^speedball^,or,^speed ball^,or,^dope^,),),andnot,(,^no loss of consciousness^,or,^denie[sd] loss of consciousness^,or,^negative loss of consciousness^,or,^denies any loss of consciousness^,or,^denies her[io][oi]n^,or,^deny her[io][oi]n^,or,^denied her[io][oi]n^,or,^denying her[io][oi]n^,or,^denies drug^,or,^deny drug^,or,^denied drug^,or,^denying drug^,or,^denies any drug^,or,^with dra^,or,^withdra^,or,^detoxification^,or,^detos^,or,^detoz^,or,^dtox^,),)

This example is the entire CDC Heroin Overdose v4 CCDD Category. Notice how the first statement is linked to the second one by an "AND" statement. Then, both statements are contained within parentheses and negated by the statement with an "ANDNOT" operator.

Try it out!

Compare the results of the following queries in the CCDD field of ESSENCE (results should be exactly the same):

  • ^Fall^,AND,^W19.XXXA^,OR,^Fall^,AND,^W19XXXA^
  • ^Fall^,AND,(,^W19.XXXA^,OR,^W19XXXA^,)

Try writing a set of negation terms (expected false positives) for the following query. Check your answer with the CDC Pertussis v1 CCDD Category in NSSP ESSENCE.

  • (,Whooping^,OR,^Pertuss^,),ANDNOT,(_______________)

We thank Senior Data Analyst Zachary Stein for volunteering to write a series of articles about free-text coding. Stein does epidemiological work to support NSSP efforts and is an active participant in our NSSP Community of Practice (CoP). He initially wrote about free-text coding as an entry on the NSSP-CoP Syndrome Definition Committee forum. The forum generated considerable interest, inspiring this series. Stein acknowledges input provided by others who contributed to the forum post.