Files
ISSSTELEON/Persistance/dbt/models/gold/cama/cama_biopsies.sql
T
Roberto Treviño b9ed108855 ISSSTELEON 8a7974a
2026-11-29 18:09:05 -06:00

19 lines
779 B
SQL

{% set p = var('cama') %}
select
b.person_id,
{{ dbt.concat(['b.person_id', "'|'", 'cast(b.request_date as ' ~ dbt.type_string() ~ ')',
"'|'", "coalesce(cast(b.mammogram_exam_date as " ~ dbt.type_string() ~ "), '')"]) }} as biopsy_id,
b.request_date, b.report_date, b.histology,
case
when b.histology is null then -1
{%- for code in p.biopsy_severity %}
when b.histology = '{{ code }}' then {{ loop.index }}
{%- endfor %}
else 0
end as histology_rank,
b.order_known_at as known_at, b.report_known_at,
m.mammogram_id, m.birads, m.birth_date
from {{ ref('breast_biopsy') }} as b
left join {{ ref('cama_mammograms') }} as m
on m.person_id = b.person_id and m.exam_date = b.mammogram_exam_date