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
Open
fix: mark cohort_definition_id as primary key in v5.3 and v5.4 (Fixes #787, #772)#788rtmalikian wants to merge 1 commit into
rtmalikian wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #787
Fixes #772
Problem
The
cohort_definition_idfield in thecohort_definitiontable is the natural primary key (each cohort definition has a unique ID), but it was not marked asisPrimaryKey=Yesin 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_definitiontable in v5.3 and v5.4.Solution
Changed
isPrimaryKeyfromNotoYesforcohort_definition_idin thecohort_definitiontable in:inst/csv/OMOP_CDMv5.3_Field_Level.csvinst/csv/OMOP_CDMv5.4_Field_Level.csvUpdated all generated DDL primary key files (15 dialects × 2 versions = 30 files) to include the
cohort_definitionprimary 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 thecohorttable's FK reference is correctly shownVerification
Changelog
Files Changed
inst/csv/OMOP_CDMv5.3_Field_Level.csv— isPrimaryKey No → Yesinst/csv/OMOP_CDMv5.4_Field_Level.csv— isPrimaryKey No → Yesinst/ddl/5.3/*/OMOPCDM_*_primary_keys.sql(15 files) — Added cohort_definition PKinst/ddl/5.4/*/OMOPCDM_*_primary_keys.sql(15 files) — Added cohort_definition PKdocs/cdm53.html— Updated Primary Key columndocs/cdm54.html— Updated Primary Key column + fixed cohort table FK displayVerification
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.