Skip to content

Commit

Permalink
Refactor patient identification columns in mart_historico_clinico__al…
Browse files Browse the repository at this point in the history
…ergia.sql and _mart_historico_clinico_schema.yml
  • Loading branch information
ThiagoTrabach committed Aug 27, 2024
1 parent 8d00922 commit 0b9efb5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
12 changes: 0 additions & 12 deletions models/marts/historico_clinico/_mart_historico_clinico_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,12 @@ models:
garante que os identificadores dos pacientes sejam consistentes e
precisos.
columns:
- name: paciente_cns
description: |
Número do Sistema Único de Saúde do paciente.
tests:
- unique:
name: mart_historico_clinico__alergia__paciente_cns__unique
config:
where: "paciente_cns is not null"
policy_tags:
- '{{ var ("TAG_CNS") }}'
- name: paciente_cpf
description: |
Cadastro de Pessoas Físicas do paciente.
tests:
- unique:
name: mart_historico_clinico__alergia__paciente_cpf__unique
config:
where: "paciente_cpf is not null"
policy_tags:
- '{{ var ("TAG_CPF") }}'
- name: alergias
Expand Down
24 changes: 15 additions & 9 deletions models/marts/historico_clinico/mart_historico_clinico__alergia.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ with
select *
from vitai
union all
select * from vitacare
select *
from vitacare
),

final as (
select
cpf as paciente_cpf,
array_agg(distinct alergia) as alergias,
-- array_agg(distinct cns ignore nulls) as cns,
struct(current_timestamp() as created_at) as metadados
from total
where cpf is not null
group by cpf
)
select
cpf as paciente_cpf,
array_agg(distinct alergia) as alergias,
array_agg(distinct cns ignore nulls) as cns,
safe_cast(current_datetime() as datetime) as processed_at
from total
where cpf is not null
group by cpf

select *
from final

0 comments on commit 0b9efb5

Please sign in to comment.