Cohort sample with age "not between" includes people from other cohorts and ignores the gender filter

Aperta Adatta ai principianti
#2,590 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@DG47 ci sta già lavorando.

Dal 10/11/2026.

  • #2591 di @DG47 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, postgresql
Ambito
backend, databases

Direzione di ricerca

Leggi CohortSamplingService.sampleElements e generateSample.sql, dove l’issue identifica il filtro notBetween e la relativa clausola WHERE generata. Controlla i test esistenti per il campionamento delle coorti e aggiungi copertura per l’appartenenza alla coorte e il filtro del genere con la modalità di età "not between". Il lavoro è completato quando i campioni includono solo la coorte selezionata e rispettano il genere selezionato; l’issue non indica un file di test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Expected behavior

Creating a cohort sample (POST /cohortsample/{cohortDefinitionId}/{sourceKey}, the "Samples" tab of a cohort definition in ATLAS) with the age mode "not between" and a minimum and maximum age should only draw people from that cohort whose age at cohort start is below the minimum or above the maximum, and should still apply the selected gender filter.

Actual behavior

CohortSamplingService.sampleElements builds the filter for notBetween as

expressionBuilder.append(" AND age > @age_max OR age < @age_min");

and appends it after WHERE cohort_definition_id = @cohort_definition_id in generateSample.sql. Because AND binds tighter than OR, the condition becomes

WHERE (cohort_definition_id = @cohort_definition_id AND age > @age_max)
   OR (age < @age_min AND gender_concept_id IN (...))

so the sample:

  • draws people younger than the minimum age from every cohort in the results schema's cohort table, not only the selected cohort, and
  • draws people older than the maximum age regardless of the gender filter.

The other age modes (lessThan, between, ...) are not affected.

Steps to reproduce behavior

With a results schema cohort table and a CDM person table on PostgreSQL (all cohort entries start on 2020-06-01, so age = 2020 - year_of_birth):

person_id gender_concept_id year_of_birth age cohort_definition_id
1 8507 2010 10 1
2 8532 1970 50 1
3 8532 1940 80 1
4 8507 1935 85 1
5 8532 2015 5 2
6 8532 1930 90 2
  1. Create a sample of cohort 1 with age "not between" 20 and 60 and no gender filter. Expected people 1, 3, 4; actual 1, 3, 4, 5 (person 5 is only in cohort 2).
  2. Create a sample of cohort 1 with age "not between" 20 and 60 and gender female. Expected person 3; actual 3, 4 (male), 5 (cohort 2).

The WHERE clause of generateSample.sql for step 2, before translation:

WHERE cohort_definition_id = @cohort_definition_id
      AND age > @age_max OR age < @age_min AND gender_concept_id IN (8532)
Environment

WebAPI master (3.0.1-SNAPSHOT, 89de588d); the same code is in v2.15.1. ATLAS offers "not between" in the sample age options (cohort-definition-manager.js). Reproduced on PostgreSQL; the precedence is the same on every supported dialect.

Lingua principale
Java
Stelle
153
Fork
186
Merge medio
2g 19h
PR unite (30g)
19

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OHDSI/WebAPI

Tutte le issue di OHDSI/WebAPI

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.