Skip to content

Commit 91ecacb

Browse files
authored
Fix validating R concepts query (#1162)
1 parent d800133 commit 91ecacb

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

app/airflow/dags/libs/auto_mapping/find_R_concepts_to_reuse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def find_matching_value(**kwargs):
9999
scan_report_table=table_id,
100100
stage=JobStageType.REUSE_CONCEPTS,
101101
status=StageStatusType.IN_PROGRESS,
102-
details=f"Finding eligible concepts for reuse at the value level",
102+
details="Finding eligible concepts for reuse at the value level",
103103
)
104104

105105
# Create temp table for reuse concepts
@@ -133,7 +133,7 @@ def find_matching_value(**kwargs):
133133
},
134134
)
135135
logging.info(
136-
f"Successfully found M-type concepts for reuse at the value level"
136+
"Successfully found M-type concepts for reuse at the value level"
137137
)
138138
except Exception as e:
139139
logging.error(
@@ -181,7 +181,7 @@ def find_matching_field(**kwargs):
181181
scan_report_table=table_id,
182182
stage=JobStageType.REUSE_CONCEPTS,
183183
status=StageStatusType.IN_PROGRESS,
184-
details=f"Finding eligible concepts for reuse at the field level",
184+
details="Finding eligible concepts for reuse at the field level",
185185
)
186186

187187
try:
@@ -203,7 +203,7 @@ def find_matching_field(**kwargs):
203203
},
204204
)
205205
logging.info(
206-
f"Successfully found M-type concepts for reuse at the field level"
206+
"Successfully found M-type concepts for reuse at the field level"
207207
)
208208
except Exception as e:
209209
logging.error(
@@ -241,7 +241,7 @@ def create_reusing_concepts(**kwargs):
241241
find_object_id_query,
242242
parameters={"table_id": table_id},
243243
)
244-
logging.info(f"Successfully found object ids for reusing concepts")
244+
logging.info("Successfully found object ids for reusing concepts")
245245
except Exception as e:
246246
logging.error(f"Failed to find object ids for reusing concepts: {str(e)}")
247247
update_job_status(
@@ -258,7 +258,7 @@ def create_reusing_concepts(**kwargs):
258258
validate_reused_concepts_query,
259259
parameters={"table_id": table_id},
260260
)
261-
logging.info(f"Successfully validated reused concepts")
261+
logging.info("Successfully validated reused concepts")
262262
except Exception as e:
263263
logging.error(f"Failed to validate reused concepts: {str(e)}")
264264
update_job_status(

app/airflow/dags/libs/queries.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,9 @@
409409

410410

411411
validate_reused_concepts_query = """
412+
-- Remove duplicates first (without joining omop.concept)
412413
DELETE FROM temp_reuse_concepts_%(table_id)s AS temp_table
413-
USING temp_reuse_concepts_%(table_id)s AS temp_table_duplicate, omop.concept AS omop_concept
414+
USING temp_reuse_concepts_%(table_id)s AS temp_table_duplicate
414415
WHERE (
415416
-- Remove duplicates at the value level, keeping the one with the lowest source_scanreport_id
416417
(
@@ -432,15 +433,15 @@
432433
)
433434
AND temp_table.source_scanreport_id > temp_table_duplicate.source_scanreport_id
434435
)
435-
OR
436-
-- Remove concepts whose domain is not in the allowed domains
437-
(
438-
temp_table.concept_id = omop_concept.concept_id
439-
AND omop_concept.domain_id NOT IN (
440-
'Condition', 'Drug', 'Procedure', 'Specimen', 'Device',
441-
'Measurement', 'Observation', 'Gender', 'Race', 'Ethnicity', 'Spec Anatomic Site'
442-
)
443-
)
436+
);
437+
438+
-- Remove concepts whose domain is not in the allowed domains
439+
DELETE FROM temp_reuse_concepts_%(table_id)s AS temp_table
440+
USING omop.concept AS omop_concept
441+
WHERE temp_table.concept_id = omop_concept.concept_id
442+
AND omop_concept.domain_id NOT IN (
443+
'Condition', 'Drug', 'Procedure', 'Specimen', 'Device',
444+
'Measurement', 'Observation', 'Gender', 'Race', 'Ethnicity', 'Spec Anatomic Site'
444445
);
445446
446447
-- Delete concepts that have no object_id

0 commit comments

Comments
 (0)