19 lines
779 B
SQL
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
|