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

オープン 初心者向け
#2,590 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@DG47 がすでに取り組んでいます。

2026年11月10日 から。

  • #2591 @DG47 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, postgresql
領域
backend, databases

調査の方向性

CohortSamplingService.sampleElements と generateSample.sql を読みます。issue では notBetween フィルターと、生成される WHERE 句が示されています。コホートサンプリングの既存テストを確認し、コホートへの所属と、年齢モードが "not between" の場合の性別フィルターをカバーするテストを追加します。サンプルに選択したコホートの対象だけが含まれ、選択した性別が反映されれば完了です。issue ではテストファイルは指定されていません。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
153
フォーク
186
平均マージ
2日 19時間
マージ済み PR(30日)
19

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OHDSI/WebAPI のほかの issue

OHDSI/WebAPI の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。