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
- Start a query. Click New Query in the upper right of the Query Builder.
- 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.
- 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.
- 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.
- 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.
- Count patients. Click the rounded arrows to count how many patients in your network fit the criteria.
- Name the query (click the pencil) so you can find it again.
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
- 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.
- 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.
Next steps
Once your query defines a cohort, learn how to explore and analyze that cohort.