|
24 | 24 |
|
25 | 25 |
|
26 | 26 | 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 | +
|
27 | 41 | INSERT INTO temp_existing_concepts_%(table_id)s ( |
28 | 42 | object_id, sr_concept_id, source_concept_id, content_type_id |
29 | 43 | ) |
|
139 | 153 | -- 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. |
140 | 154 | WHERE target_concept.concept_id = COALESCE(temp_existing_concepts.standard_concept_id, temp_existing_concepts.source_concept_id); |
141 | 155 |
|
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. |
143 | 159 | UPDATE temp_existing_concepts_%(table_id)s temp_existing_concepts |
144 | 160 | SET dest_table_id = (SELECT id FROM mapping_omoptable WHERE "table" = 'death' LIMIT 1) |
145 | 161 | WHERE (SELECT death_table FROM mapping_scanreporttable WHERE id = %(table_id)s) = TRUE; |
|
0 commit comments