Queries are the heart of a TriNetX study. A query defines a patient population with Must Have and Cannot Have criteria, like the inclusion and exclusion criteria of a written protocol. The patients who fit are your cohort. A study can have one query or many, run on different networks, age groups, or time periods.

Build a basic query

  1. Start a query. Click New Query in the upper right of the Query Builder.
  2. Choose a network. Click the network name at the top of the query to see your options. All networks allow analyses on your cohort, but not all allow dataset downloads. Each query can use a different network, and you can change it later.
  3. Choose filters. Filter by Medical Center Type (Academic, Non-Academic, Unknown), Data Types (Demographics, Diagnoses, Genomics, Labs, Meds, Procedures), and Age & Sex. Age reflects the patient's current age on the day you count patients.
  4. Find and add terms. Use the search boxes to enter known codes or plain text (for example, β€œLiver”). Results span Diagnoses, Labs, Procedures, Medications, and Genomics; click a category button to filter. Hover a term and click the blue tree to drill into a more specific diagnosis, and click blue sideways arrows to expand subcodes.
  5. Add to the query. Click Add to Query. Terms land on the Must Have or Cannot Have side you searched from. Lab terms let you enter values and choose most-recent vs any historical result. Drag terms between sides as needed.
  6. Count patients. Click the rounded arrows to count how many patients in your network fit the criteria.
  7. Name the query (click the pencil) so you can find it again.
Mind the ANDs and ORs. Inclusions default to AND between list terms; exclusions default to OR. Click the word to toggle.
Timesaver: import a query. In a new blank query, click Import Query, pick a study (yours, one shared with you, or a template), and choose the query to reuse and edit, with no rebuilding.
Keep it tidy. Every time you edit and re-count, TriNetX generates a new unnamed query and adds it to the list on the right. Delete throwaway queries as you work, name the ones you want to keep, and star favorites.

Build a complex query

Real research questions are rarely simple. A few ways to fine-tune:

Filter a single term

The funnel on a term adds filtering to just that term, for example Age at Event, or details for cancer, meds, or labs. Use it to require that patients were a certain age when something occurred in their history.

Use groups

  1. Click New Group at the bottom of the Query Builder. Search and add terms to the main query first, then use Add Terms to pull ungrouped terms into the group from a checklist.
  2. Click Group Rules to set the group's parameters.

Add a time constraint

In a group, click Time Constraint and set a Relative Time (for example, within the last 3 months) or Specific Dates (for example, 01Mar2020 to 01Mar2021). The constraint applies to every term in that group; terms left out of the group are unaffected. Groups can each have different constraints.

Create a related group

To find patients whose terms occurred in a time relationship, create a group for the first terms, then click Add Related Group in Rules to create Groups A and B. Put the related terms in Group B and set the relationship: Group A stays fixed while Group B moves ahead of or behind it by the time period you define. You can also set each group's instance type, such as Most Recent or First Instance.

Hot tip. Add the same term more than once to capture all its relationships, for example relating Cellulitis both to a history of diabetes and to an inpatient admission.

Next steps

Once your query defines a cohort, learn how to explore and analyze that cohort.