Skip to content

Commit 74a780f

Browse files
committed
Allow mapper to autodetect death date therefore makrking it as true
1 parent f3f0c18 commit 74a780f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

app/airflow/dags/libs/queries.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424

2525

2626
find_existing_concepts_query = """
27+
-- This check marks the current table as a "death table" if the user specifically chose the "death_date" field for the date_event.
28+
-- We include this here to ensure that any downstream automapping logic that depends on knowing if a table is a "death table" (for example, only assigning death concepts to death tables) will behave correctly.
29+
-- The check is performed right before we pull existing concepts so the information is always up-to-date in automapping flows.
30+
UPDATE mapping_scanreporttable
31+
SET death_table = TRUE
32+
WHERE id = %(table_id)s
33+
AND date_event_id IS NOT NULL
34+
AND EXISTS (
35+
SELECT 1
36+
FROM mapping_scanreportfield f
37+
WHERE f.id = mapping_scanreporttable.date_event_id
38+
AND LOWER(TRIM(f.name)) = 'death_date'
39+
);
40+
2741
INSERT INTO temp_existing_concepts_%(table_id)s (
2842
object_id, sr_concept_id, source_concept_id, content_type_id
2943
)
@@ -139,7 +153,9 @@
139153
-- Because concepts may or may not have the standard_concept_id, in general. And we prefer to use the standard_concept_id, if it exists.
140154
WHERE target_concept.concept_id = COALESCE(temp_existing_concepts.standard_concept_id, temp_existing_concepts.source_concept_id);
141155
142-
-- When the scan report table is a death table, override dest_table_id to the death OMOP table so rules show destination table: death, field: cause_concept_id
156+
-- If the scan report table has the "death_table" flag set to TRUE, set the destination table to OMOP's "death" table.
157+
-- This ensures that mapping rules will use "death" as the destination table and, for example, will select "cause_concept_id" as the mapped field.
158+
-- Note: The "death_table" flag may have been set automatically if a date_event was mapped to the "death_date" field earlier in the workflow.
143159
UPDATE temp_existing_concepts_%(table_id)s temp_existing_concepts
144160
SET dest_table_id = (SELECT id FROM mapping_omoptable WHERE "table" = 'death' LIMIT 1)
145161
WHERE (SELECT death_table FROM mapping_scanreporttable WHERE id = %(table_id)s) = TRUE;

0 commit comments

Comments
 (0)