vignettes/checks/isForeignKey.Rmd
isForeignKey.Rmd
Level: Field check
Context: Verification
Category: Conformance
Subcategory: Relational
Severity: Fatal 💀
The number and percent of records that have a value in the cdmFieldName field in the cdmTableName table that does not exist in the fkTableName table.
This check will make sure that all foreign keys as specified in the CDM version have a value in the related primary key field. While this issue should generally be prevented by foreign key database constraints, some database management systems such as Redshift do not enforce such constraints.
This check failure must be resolved. Failures in various fields could impact analysis in many different ways, for example:
Many CDM columns are foreign keys to the concept_id
column in the CONCEPT
table. See below for suggested
investigation steps for concept ID-related foreign key check
failures:
_concept_id
missing from the CONCEPT table might be
the result of an error in SOURCE_TO_CONCEPT_MAP
; you may
check it this way:SELECT *
FROM @vocabSchema.source_to_concept_map
LEFT JOIN @vocabSchema.concept ON concept.concept_id = source_to_concept_map.target_concept_id
WHERE concept.concept_id IS NULL;
-- @cdmTableName.@cdmFieldName is the _concept_id or _source_concept_id field in a CDM table
-- Inspect the contents of the _source_value field to investigate the source of the error
SELECT
'@cdmTableName.@cdmFieldName' AS violating_field,
cdmTable.*,
COUNT(*) OVER(PARTITION BY '@cdmTableName.@cdmFieldName') AS num_violations_per_concept
FROM @cdmSchema.@cdmTableName
LEFT JOIN @vocabSchema.concept on @cdmTableName.@cdmFieldName = concept.concept_id
WHERE concept.concept_id IS NULL
ORDER BY num_violations_per_concept DESC;
When an entry is missing from one of the other CDM tables (LOCATION, PERSON, PROVIDER, VISIT_DETAIL, VISIT_OCCURRENCE, PAYER_PLAN_PERIOD, NOTE, CARE_SITE, EPISODE), this likely originates from binding / key generation errors in the ETL.
As above, mapping or binding logic needs to be amended in your ETL in order to resolve this error.
Few options are available to correct this error without amending the ETL code that populated your OMOP CDM. If a limited proportion of rows are impacted, you could consider dropping them from your database; however, do so at your own risk and only if you are confident that doing so will not have a significant impact on the downstream use cases of your CDM. A less aggressive approach could be to retain the affected rows and document the scope of their impact (in order to resolve the check failure, nullable values can be set to NULL and non-nullable concept ID values to 0). However, it is strongly recommended to pursue resolution further upstream in the ETL.