Files
ISSSTELEON/Persistance/dbt/models/gold/cacu/cacu_sample_biopsies.sql
T
Roberto Treviño 2fe5301fd1
ci / python (push) Successful in 51m44s
ci / web (push) Successful in 16m59s
CaCu: procedures with their cytology and histology, seven measures, the cytology form's fields
2026-11-30 23:32:01 -06:00

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