ATLAS cohort explainer
OHDSI researchers
Supported ATLAS cohort JSON in. A plain-English explanation and the PostgreSQL query CuRE compiles from it out
Runs entirely in your browser. Nothing you type or paste is sent to us. It starts with a synthetic example, so you can see a result before using your own input
Paste a Circe cohort expression. This browser subset supports clinical-domain concept and absolute-date filters, observation requirements, nested inclusion groups, relative event windows and occurrence counts, event limits, date-offset endings and era collapse
Demographic filters, extensions, custom drug eras, censoring and other unsupported fields produce an error. This tool generates SQL; it does not query a database or estimate cohort size
Deterministic explanation
- Index events: condition occurrence using concept set 0
- Require at least 365 observed days before and 0 days after each index event; index selection: First
- After qualification select All events; after inclusion select All events per person
- Cohort ends 30 days from index start, clamped between index start and observation-period end
- Merge overlapping eras and eras separated by up to 0 days
- Concept set 0 (Synthetic example concept set): include concept 201826 (Type 2 diabetes mellitus; name supplied in JSON) plus valid descendants
Names are copied from your JSON and are not verified against a vocabulary. Descendant and mapped concept expansion happens when the SQL runs against your vocabulary tables
PostgreSQL membership query
CuRE compiler output for the omop schema. The first binding is a synthetic organization UUID; replace it with the authorized organization at execution. The query requires CuRE's org_id column on omop.person
WITH person_scope AS (
SELECT person_id, gender_concept_id, race_concept_id, ethnicity_concept_id, year_of_birth
FROM omop.person
WHERE org_id = $1::uuid
),
codeset_0 AS (
SELECT _inc.concept_id FROM (
SELECT unnest($2::int[]) AS concept_id
UNION
SELECT c.concept_id
FROM omop.concept_ancestor ca
JOIN omop.concept c ON c.concept_id = ca.descendant_concept_id
WHERE ca.ancestor_concept_id = ANY($3::int[])
AND c.invalid_reason IS NULL
) AS _inc
),
entry_events AS (
SELECT
e.person_id,
e.condition_start_date AS event_start_date,
COALESCE(e.condition_end_date, e.condition_start_date) AS event_end_date
FROM omop.condition_occurrence e
JOIN person_scope ps ON ps.person_id = e.person_id
WHERE TRUE
AND e.condition_concept_id IN (SELECT concept_id FROM codeset_0)
),
entry_in_observation AS (
SELECT DISTINCT
ee.person_id,
ee.event_start_date,
ee.event_end_date,
op.observation_period_start_date,
op.observation_period_end_date
FROM entry_events ee
JOIN omop.observation_period op
ON op.person_id = ee.person_id
AND ee.event_start_date >= op.observation_period_start_date
AND ee.event_start_date <= op.observation_period_end_date
WHERE (ee.event_start_date - op.observation_period_start_date) >= $4::int
AND (op.observation_period_end_date - ee.event_start_date) >= $5::int
),
index_events AS (
SELECT person_id, event_start_date, event_end_date, observation_period_start_date, observation_period_end_date FROM (
SELECT _s.*, ROW_NUMBER() OVER (
PARTITION BY _s.person_id ORDER BY _s.event_start_date ASC, _s.event_end_date ASC
) AS _rn
FROM entry_in_observation _s
) _ranked WHERE _ranked._rn = 1
),
universe AS (
SELECT
ie.person_id,
ie.event_start_date AS index_date,
ie.event_end_date AS index_end_date,
ie.observation_period_start_date,
ie.observation_period_end_date,
ps.gender_concept_id,
ps.race_concept_id,
ps.ethnicity_concept_id,
(EXTRACT(YEAR FROM ie.event_start_date)::int - ps.year_of_birth) AS age_at_index
FROM index_events ie
JOIN person_scope ps ON ps.person_id = ie.person_id
),
s0 AS (SELECT DISTINCT person_id FROM universe),
qualified_events AS (
SELECT person_id, index_date, index_end_date, observation_period_start_date, observation_period_end_date, gender_concept_id, race_concept_id, ethnicity_concept_id, age_at_index FROM universe _s
WHERE _s.person_id IN (SELECT person_id FROM s0)
),
included_events AS (
SELECT person_id, index_date, index_end_date, observation_period_start_date, observation_period_end_date, gender_concept_id, race_concept_id, ethnicity_concept_id, age_at_index FROM qualified_events _s
WHERE _s.person_id IN (SELECT person_id FROM s0)
),
cohort_rows AS (
SELECT
ie.person_id,
ie.index_date AS cohort_start_date,
GREATEST(LEAST(ie.index_date + $6::int, ie.observation_period_end_date), ie.index_date) AS cohort_end_date
FROM included_events ie
),
cohort_marked AS (
SELECT
person_id,
cohort_start_date,
cohort_end_date,
CASE
WHEN cohort_start_date <= (
MAX(cohort_end_date) OVER (
PARTITION BY person_id ORDER BY cohort_start_date, cohort_end_date
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
)
) + $7::int THEN 0
ELSE 1
END AS _era_start
FROM cohort_rows
),
cohort_grouped AS (
SELECT
person_id,
cohort_start_date,
cohort_end_date,
SUM(_era_start) OVER (
PARTITION BY person_id ORDER BY cohort_start_date, cohort_end_date
ROWS UNBOUNDED PRECEDING
) AS _era
FROM cohort_marked
),
cohort_eras AS (
SELECT person_id, MIN(cohort_start_date) AS cohort_start_date, MAX(cohort_end_date) AS cohort_end_date
FROM cohort_grouped
GROUP BY person_id, _era
)
SELECT person_id, cohort_start_date, cohort_end_date FROM cohort_eras ORDER BY person_id, cohort_start_datePositional parameter bindings
[
"00000000-0000-4000-8000-000000000001",
[
201826
],
[
201826
],
365,
0,
30,
0
]Attrition count query
WITH person_scope AS (
SELECT person_id, gender_concept_id, race_concept_id, ethnicity_concept_id, year_of_birth
FROM omop.person
WHERE org_id = $1::uuid
),
codeset_0 AS (
SELECT _inc.concept_id FROM (
SELECT unnest($2::int[]) AS concept_id
UNION
SELECT c.concept_id
FROM omop.concept_ancestor ca
JOIN omop.concept c ON c.concept_id = ca.descendant_concept_id
WHERE ca.ancestor_concept_id = ANY($3::int[])
AND c.invalid_reason IS NULL
) AS _inc
),
entry_events AS (
SELECT
e.person_id,
e.condition_start_date AS event_start_date,
COALESCE(e.condition_end_date, e.condition_start_date) AS event_end_date
FROM omop.condition_occurrence e
JOIN person_scope ps ON ps.person_id = e.person_id
WHERE TRUE
AND e.condition_concept_id IN (SELECT concept_id FROM codeset_0)
),
entry_in_observation AS (
SELECT DISTINCT
ee.person_id,
ee.event_start_date,
ee.event_end_date,
op.observation_period_start_date,
op.observation_period_end_date
FROM entry_events ee
JOIN omop.observation_period op
ON op.person_id = ee.person_id
AND ee.event_start_date >= op.observation_period_start_date
AND ee.event_start_date <= op.observation_period_end_date
WHERE (ee.event_start_date - op.observation_period_start_date) >= $4::int
AND (op.observation_period_end_date - ee.event_start_date) >= $5::int
),
index_events AS (
SELECT person_id, event_start_date, event_end_date, observation_period_start_date, observation_period_end_date FROM (
SELECT _s.*, ROW_NUMBER() OVER (
PARTITION BY _s.person_id ORDER BY _s.event_start_date ASC, _s.event_end_date ASC
) AS _rn
FROM entry_in_observation _s
) _ranked WHERE _ranked._rn = 1
),
universe AS (
SELECT
ie.person_id,
ie.event_start_date AS index_date,
ie.event_end_date AS index_end_date,
ie.observation_period_start_date,
ie.observation_period_end_date,
ps.gender_concept_id,
ps.race_concept_id,
ps.ethnicity_concept_id,
(EXTRACT(YEAR FROM ie.event_start_date)::int - ps.year_of_birth) AS age_at_index
FROM index_events ie
JOIN person_scope ps ON ps.person_id = ie.person_id
),
s0 AS (SELECT DISTINCT person_id FROM universe),
qualified_events AS (
SELECT person_id, index_date, index_end_date, observation_period_start_date, observation_period_end_date, gender_concept_id, race_concept_id, ethnicity_concept_id, age_at_index FROM universe _s
WHERE _s.person_id IN (SELECT person_id FROM s0)
),
included_events AS (
SELECT person_id, index_date, index_end_date, observation_period_start_date, observation_period_end_date, gender_concept_id, race_concept_id, ethnicity_concept_id, age_at_index FROM qualified_events _s
WHERE _s.person_id IN (SELECT person_id FROM s0)
),
cohort_rows AS (
SELECT
ie.person_id,
ie.index_date AS cohort_start_date,
GREATEST(LEAST(ie.index_date + $6::int, ie.observation_period_end_date), ie.index_date) AS cohort_end_date
FROM included_events ie
),
cohort_marked AS (
SELECT
person_id,
cohort_start_date,
cohort_end_date,
CASE
WHEN cohort_start_date <= (
MAX(cohort_end_date) OVER (
PARTITION BY person_id ORDER BY cohort_start_date, cohort_end_date
ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
)
) + $7::int THEN 0
ELSE 1
END AS _era_start
FROM cohort_rows
),
cohort_grouped AS (
SELECT
person_id,
cohort_start_date,
cohort_end_date,
SUM(_era_start) OVER (
PARTITION BY person_id ORDER BY cohort_start_date, cohort_end_date
ROWS UNBOUNDED PRECEDING
) AS _era
FROM cohort_marked
),
cohort_eras AS (
SELECT person_id, MIN(cohort_start_date) AS cohort_start_date, MAX(cohort_end_date) AS cohort_end_date
FROM cohort_grouped
GROUP BY person_id, _era
)
SELECT (SELECT count(*)::int FROM s0) AS c0, (SELECT COALESCE(array_agg(person_id ORDER BY person_id), ARRAY[]::int[]) FROM s0) AS survivorsCohort logic follows OHDSI Circe (Apache 2.0)
Uses the CuRE shared Circe compiler, following the OHDSI Circe cohort-expression structure (circe-be 1.13.0). SQL uses the CuRE PostgreSQL OMOP schema and positional bindings. The browser accepts an explicitly limited subset and rejects unsupported constructs
Carry this work into CuRE
This tool is part of CuRE Calculate. Request early access and we will set up your workspace on synthetic data