17 lines
766 B
SQL
17 lines
766 B
SQL
{# The biopsies each cytology sample led to, with the grade's severity (core.cacu
|
|
BIOPSY_SEVERITY, from 1; -1 a report without a grade, 0 a grade outside it). #}
|
|
{% set p = var('cacu') %}
|
|
select
|
|
{{ dbt.concat(['b.person_id', "'|'", 'cast(b.sample_date as ' ~ dbt.type_string() ~ ')']) }} as sample_id,
|
|
{{ dbt.concat(['b.person_id', "'|'", 'cast(b.date as ' ~ dbt.type_string() ~ ')']) }} as biopsy_id,
|
|
b.report_date, b.histology, b.known_at,
|
|
case
|
|
when b.histology is null then -1
|
|
{%- for grade in p.biopsy_severity %}
|
|
when b.histology = '{{ grade }}' then {{ loop.index }}
|
|
{%- endfor %}
|
|
else 0
|
|
end as severity
|
|
from {{ ref('cacu_procedures') }} as b
|
|
where b.type = 'biopsy' and b.sample_date is not null
|