Files
ISSSTELEON/Transformation/models/tea/gold/eventos/tea_alteraciones.sql
T

20 lines
1.0 KiB
SQL

-- One row per child of the cohort with a good EEG and knowledge version (`conocida_en`): the first good EEG known
-- by then (the study's) and, from its
-- metrics, whether it has any alteration and which. Later EEGs, good or bad, don't change them; each alteration
-- counts once per child and a child can have several. What M30 counts, by the period of that EEG.
select
h.pac_id,
h.grupo_edad,
h.eeg_estudio_id as procedimiento_id,
h.fecha_eeg_estudio as fecha_eeg,
h.conocida_en,
max(case when m.estado in ('aumentado', 'disminuido') then 1 else 0 end) as con_alteracion
{%- for metrica in tea_metricas() %},
max(case when m.metrica = '{{ metrica }}' and m.estado in ('aumentado', 'disminuido') then 1 else 0 end) as alt_{{ metrica }}
{%- endfor %}
from {{ ref('tea_hitos') }} h
left join {{ ref('tea_eeg_metricas') }} m on m.procedimiento_id = h.eeg_estudio_id
where h.eeg_estudio_id is not null
group by h.pac_id, h.grupo_edad, h.eeg_estudio_id, h.fecha_eeg_estudio, h.conocida_en