Skip to content

Commit

Permalink
Merge pull request #222 from prefeitura-rio/hci/drop-duplicates-vitacare
Browse files Browse the repository at this point in the history
[HCI] Aplica regras de descarte Vitacare
  • Loading branch information
TanookiVerde authored Feb 21, 2025
2 parents 262be10 + e0dba26 commit 772d8fa
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,22 @@ with
select *, 'historico' as origem
from {{ ref("base_prontuario_vitacare__atendimento_historico") }}
),
atendimentos_teste_duplicados as (
select id_hci, count(*) as qtd
from atendimentos
where cnes_unidade in ('6922031', '9391983', '7856954', '7414226')
and datahora_inicio > '2024-11-06'
group by 1
),
atendimentos_sem_teste_duplicados as (
select *
from atendimentos
where id_hci not in (select id_hci from atendimentos_teste_duplicados)
),

atendimentos_deduplicados as (
select *
from atendimentos
from atendimentos_sem_teste_duplicados
qualify row_number() over (partition by id_prontuario_global order by updated_at desc) = 1
),

Expand Down

0 comments on commit 772d8fa

Please sign in to comment.