Skip to content

Flag six v5.3 fields as foreign keys so their constraints are generated - #825

Open
chenyangsu wants to merge 2 commits into
OHDSI:mainfrom
chenyangsu:fix/v5.3-missing-foreign-keys
Open

chenyangsu wants to merge 2 commits into
OHDSI:mainfrom
chenyangsu:fix/v5.3-missing-foreign-keys

Conversation

@chenyangsu

@chenyangsu chenyangsu commented Nov 20, 2026 •

Copy link
Copy Markdown

In inst/csv/OMOP_CDMv5.3_Field_Level.csv, these six rows have isForeignKey = No, so createForeignKeys() skips them and the shipped v5.3 constraints scripts have no constraint for them:

Field References
procedure_occurrence.provider_id PROVIDER.PROVIDER_ID
procedure_occurrence.visit_occurrence_id VISIT_OCCURRENCE.VISIT_OCCURRENCE_ID
procedure_occurrence.visit_detail_id VISIT_DETAIL.VISIT_DETAIL_ID
procedure_occurrence.procedure_source_concept_id CONCEPT.CONCEPT_ID
condition_era.person_id PERSON.PERSON_ID
note_nlp.note_id NOTE.NOTE_ID

The first five name an FK target already; the same fields are foreign keys in the other v5.3 event tables (condition_occurrence, drug_exposure, drug_era, dose_era) and in v5.4 and v5.5. These are the only v5.3 rows that have an FK target but isForeignKey = No, apart from drug_exposure.days_supply, whose misalignment #820 fixes.

note_nlp.note_id (added in a second commit) had no target in the CSV, but the v5.3.1 release DDL declared it (fpk_note_nlp_note), #539 added it to v5.4, and DataQualityDashboard's v5.3 checks already treat it as a foreign key to NOTE.

Change

  • Set isForeignKey to Yes on the six rows (plus NOTE/NOTE_ID as the target for note_nlp.note_id).
  • Regenerated inst/ddl/5.3/*/OMOPCDM_*_5.3_constraints.sql with buildRelease() (SqlRender 1.19.7). Rebuilding from the unchanged CSV first reproduced the committed constraints files byte for byte, so the diff in each of the 16 files is only the six new ALTER TABLE lines.
  • Updated the Foreign Key column on the v5.3 spec page (docs/cdm53.html, docs/search.json). I kept only the content changes from the render because my local Quarto is 1.10.20, not 1.10.18.

Check
I ran the v5.3 PostgreSQL ddl, primary keys and constraints scripts in PGlite. All statements succeed, and the foreign-key count goes from 157 to 163. An orphan note_nlp.note_id is now rejected by fpk_note_nlp_note_id.

If v5.3 spec fixes should go to a particular release branch, I can retarget.

In OMOP_CDMv5.3_Field_Level.csv these rows named a target table and field
but had isForeignKey = No, so createForeignKeys() skipped them:

- procedure_occurrence.provider_id -> PROVIDER.PROVIDER_ID
- procedure_occurrence.visit_occurrence_id -> VISIT_OCCURRENCE.VISIT_OCCURRENCE_ID
- procedure_occurrence.visit_detail_id -> VISIT_DETAIL.VISIT_DETAIL_ID
- procedure_occurrence.procedure_source_concept_id -> CONCEPT.CONCEPT_ID
- condition_era.person_id -> PERSON.PERSON_ID

The same fields are foreign keys in the other v5.3 event tables
(condition_occurrence, drug_exposure, drug_era, dose_era) and in v5.4 and v5.5.

Regenerated the v5.3 constraints scripts for all dialects with buildRelease()
(SqlRender 1.19.7); the only change in each is the five new ALTER TABLE lines.
Updated the Foreign Key column on the v5.3 specification page to match.
The v5.3.1 release DDL declared fpk_note_nlp_note on this field, and v5.4
gained it in OHDSI#539, but the v5.3 Field_Level.csv still had isForeignKey = No
with no fkTableName, so createForeignKeys() skipped it.

Regenerated the v5.3 constraints scripts for all dialects; the only change in
each is one new ALTER TABLE line. Updated the v5.3 specification page to match.
@chenyangsu chenyangsu changed the title Flag five v5.3 fields as foreign keys so their constraints are generated Flag six v5.3 fields as foreign keys so their constraints are generated Nov 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant