Skip to content

fix: mark cohort_definition_id as primary key in v5.3 and v5.4 (Fixes #787, #772)#788

Open
rtmalikian wants to merge 1 commit into
OHDSI:mainfrom
rtmalikian:fix/issue-787-cohort-definition-pk
Open

fix: mark cohort_definition_id as primary key in v5.3 and v5.4 (Fixes #787, #772)#788
rtmalikian wants to merge 1 commit into
OHDSI:mainfrom
rtmalikian:fix/issue-787-cohort-definition-pk

Conversation

@rtmalikian

Copy link
Copy Markdown

Fixes #787
Fixes #772

Problem

The cohort_definition_id field in the cohort_definition table is the natural primary key (each cohort definition has a unique ID), but it was not marked as isPrimaryKey=Yes in the CSV spec files for v5.3 and v5.4. The v6.0 CSV handles this differently (as a FK to the cohort table).

This means the generated DDL files for all database dialects (PostgreSQL, Oracle, SQL Server, BigQuery, etc.) are also missing the primary key constraint for the cohort_definition table in v5.3 and v5.4.

Solution

Changed isPrimaryKey from No to Yes for cohort_definition_id in the cohort_definition table in:

  • inst/csv/OMOP_CDMv5.3_Field_Level.csv
  • inst/csv/OMOP_CDMv5.4_Field_Level.csv

Updated all generated DDL primary key files (15 dialects × 2 versions = 30 files) to include the cohort_definition primary key constraint.

Updated the generated HTML documentation:

  • docs/cdm53.html — Primary Key column now shows "Yes"
  • docs/cdm54.html — Primary Key column now shows "Yes", and the cohort table's FK reference is correctly shown

Verification

# Verify CSV changes
grep "cohort_definition,cohort_definition_id" inst/csv/OMOP_CDMv5.3_Field_Level.csv
# Expected: ...Yes,integer,...,Yes,No,...
grep "cohort_definition,cohort_definition_id" inst/csv/OMOP_CDMv5.4_Field_Level.csv
# Expected: ...Yes,integer,...,Yes,No,...

# Verify DDL includes PK
grep "cohort_definition" inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_primary_keys.sql
# Expected: ALTER TABLE ... ADD CONSTRAINT xpk_cohort_definition PRIMARY KEY (cohort_definition_id);

Changelog

Date Change Author
2026-06-19 Mark cohort_definition_id as PK in v5.3/v5.4 CSVs, DDL, and HTML docs rtmalikian

Files Changed

  • inst/csv/OMOP_CDMv5.3_Field_Level.csv — isPrimaryKey No → Yes
  • inst/csv/OMOP_CDMv5.4_Field_Level.csv — isPrimaryKey No → Yes
  • inst/ddl/5.3/*/OMOPCDM_*_primary_keys.sql (15 files) — Added cohort_definition PK
  • inst/ddl/5.4/*/OMOPCDM_*_primary_keys.sql (15 files) — Added cohort_definition PK
  • docs/cdm53.html — Updated Primary Key column
  • docs/cdm54.html — Updated Primary Key column + fixed cohort table FK display

Verification

  • CSV grep confirms isPrimaryKey=Yes for cohort_definition_id
  • DDL grep confirms PK constraint present in all dialects
  • HTML docs show Primary Key=Yes in cohort_definition table

About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.

📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a


Disclosure: This code was developed with assistance from MiMo-v2.5-pro (Xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.

Fixes OHDSI#787
Fixes OHDSI#772

The cohort_definition_id field in the cohort_definition table is the
natural primary key (each cohort definition has a unique ID), but it
was not marked as isPrimaryKey=Yes in the CSV spec files for v5.3 and
v5.4. The v6.0 CSV correctly handles this table differently.

Changes:
- inst/csv/OMOP_CDMv5.3_Field_Level.csv: isPrimaryKey No → Yes
- inst/csv/OMOP_CDMv5.4_Field_Level.csv: isPrimaryKey No → Yes
- All v5.3 and v5.4 DDL primary key files: added cohort_definition PK
- docs/cdm53.html: updated Primary Key column
- docs/cdm54.html: updated Primary Key column and fixed cohort table FK

Signed-off-by: Raphael Malikian <rtmalikian@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant