Skip to content

Commit

Permalink
feat: improve index informations
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Jan 10, 2025
1 parent bb4c113 commit 4698d79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,11 @@ models:
- name: mart_historico_clinico_app__indice
description: >
Tabela utilizada para busca por CNS e Nome no histórico clínico.
columns:
- name: cns_particao
description: Coluna de particionamento de CNS.
data_tests:
- not_null:
name: mart_historico_clinico_app__indice__cns_particao__not_null
- unique:
name: mart_historico_clinico_app__indice__cns_particao__unique
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,41 @@
}}

with
source_mart as (
source_paciente_mart as (
select
*
from {{ ref('mart_historico_clinico__paciente') }}
),
source_app as (
source_paciente_app as (
select
*
from {{ ref('mart_historico_clinico_app__paciente') }}
),
source_episodio_app as (
select
*
from {{ ref('mart_historico_clinico_app__episodio') }}
),

-- -----------------------------------------
-- Enriquecimento
-- -----------------------------------------
cns_mapeamento as (
select
valor_cns, cpf
from source_mart, unnest(cns) as valor_cns
from source_paciente_mart, unnest(cns) as valor_cns
),
nome_mae_mapeamento as (
select
dados.mae_nome, cpf
from source_mart
from source_paciente_mart
),
episodios_por_pessoas as (
select
source_episodio_app.cpf,
count(*) as quantidade_episodios
from source_episodio_app
group by 1
),

-- -----------------------------------------
Expand All @@ -44,17 +56,18 @@ with
dados as (
select
cast(cns_mapeamento.valor_cns as int64) as cns_particao,
source_app.cpf,
source_paciente_app.cpf,
registration_name as nome,
birth_date as data_nascimento,
{{ calculate_age('cast(birth_date as date)') }} AS idade,
gender as genero,
nome_mae_mapeamento.mae_nome as nome_mae,
coalesce(quantidade_episodios, 0) as quantidade_episodios
exibicao,

from source_app
inner join cns_mapeamento on cns_mapeamento.cpf = source_app.cpf
inner join nome_mae_mapeamento on nome_mae_mapeamento.cpf = source_app.cpf
from source_paciente_app
inner join cns_mapeamento on cns_mapeamento.cpf = source_paciente_app.cpf
inner join nome_mae_mapeamento on nome_mae_mapeamento.cpf = source_paciente_app.cpf
left join episodios_por_pessoas on episodios_por_pessoas.cpf = source_paciente_app.cpf
)
-- -=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--
-- FINAL
Expand Down

0 comments on commit 4698d79

Please sign in to comment.