-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1902c1
commit b4cead8
Showing
22 changed files
with
582 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
models/marts/core/dimensions/dim_estabelecimento_historico.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
alias="estabelecimento_historico", | ||
) | ||
}} | ||
|
||
|
||
with | ||
|
||
estabelecimento as ( | ||
select * | ||
from {{ ref("raw_cnes___estabelecimento") }}) | ||
|
||
estab_sms as ( | ||
select * | ||
from estabelecimento | ||
where | ||
cnpj_mantenedora = "29468055000102" -- SMS-RIO | ||
or id_cnes = "5456932" -- Fio Cruz | ||
or (id_municipio_gestor = "330455" and id_natureza_juridica = "2011") -- Rio de Janeiro & Empresa Publica (Rio Saúde) | ||
or (id_municipio_gestor = "330455" and id_natureza_juridica = "1031") -- Rio de Janeiro & Orgao Publico do Poder Executivo Municipal | ||
), | ||
|
||
estab_aux as (select * from {{ ref("raw_sheets__estabelecimento_auxiliar") }}), | ||
|
||
estab_final as ( | ||
select | ||
estab_sms.*, | ||
estab_aux.tipo_sms, | ||
estab_aux.tipo_sms_simplificado, | ||
estab_aux.nome_limpo, | ||
estab_aux.nome_sigla, | ||
estab_aux.prontuario_tem, | ||
estab_aux.prontuario_versao, | ||
estab_aux.responsavel_sms, | ||
estab_aux.administracao, | ||
estab_aux.prontuario_estoque_tem_dado, | ||
estab_aux.prontuario_estoque_motivo_sem_dado, | ||
coalesce( | ||
estab_aux.area_programatica, estab_sms.id_distrito_sanitario | ||
) as id_distrito_sanitario_corrigido, -- corrige registros que possuem algum erro no cadsus | ||
from estab_sms | ||
left join estab_aux using (id_cnes) | ||
) | ||
|
||
|
||
select | ||
-- Primary key | ||
est.id_unidade, | ||
|
||
-- Foreign keys | ||
est.id_cnes, | ||
est.id_tipo_unidade, | ||
est.id_distrito_sanitario_corrigido as area_programatica, | ||
|
||
-- Common fields | ||
IF (est.id_motivo_desativacao is null, "sim", "não") as ativa, | ||
unidade.descricao as tipo , # TODO: renomear para tipo_cnes | ||
est.tipo_sms, | ||
est.tipo_sms_simplificado, | ||
est.nome_limpo, | ||
est.nome_sigla, | ||
est.nome_fantasia, | ||
est.responsavel_sms, | ||
est.administracao, | ||
est.prontuario_tem, | ||
est.prontuario_versao, | ||
est.prontuario_estoque_tem_dado, | ||
est.prontuario_estoque_motivo_sem_dado, | ||
est.endereco_bairro, | ||
est.endereco_logradouro, | ||
est.endereco_numero, | ||
est.endereco_complemento, | ||
est.endereco_cep, | ||
est.endereco_latitude, | ||
est.endereco_longitude, | ||
est.telefone, | ||
est.fax, | ||
est.email, | ||
est.aberto_sempre, | ||
turno.descricao as turno_atendimento, | ||
est.diretor_clinico_cpf, | ||
est.diretor_clinico_conselho, | ||
|
||
-- Metadata | ||
data_atualizao_registro, | ||
usuario_atualizador_registro, | ||
est.mes_particao, | ||
est.data_carga, | ||
est.data_snapshot, | ||
|
||
from estab_final as est | ||
left join turno using (id_turno_atendimento) | ||
left join unidade using (id_tipo_unidade) | ||
|
||
order by ativa desc, est.id_tipo_unidade asc, area_programatica asc, est.endereco_bairro asc, est.nome_fantasia asc |
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
models/marts/treinamento/mart_treinamento__estoque_movimento.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ | ||
config( | ||
alias="estoque_movimento", | ||
schema="projeto_treinamento_escritorio", | ||
) | ||
}} | ||
|
||
|
||
with source as (select * from `rj-sms`.`projeto_estoque`.`estoque_movimento`) | ||
|
||
select * | ||
from source | ||
where | ||
estabelecimento_area_programatica = "31" | ||
and data_particao between "2023-12-03" and "2023-12-09" |
14 changes: 14 additions & 0 deletions
14
models/marts/treinamento/mart_treinamento__estoque_posicao.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{ | ||
config( | ||
alias="estoque_posicao_atual", | ||
schema="projeto_treinamento_escritorio", | ||
) | ||
}} | ||
|
||
|
||
with source as (select * from `rj-sms`.`projeto_estoque`.`estoque_posicao_atual`) | ||
|
||
select * from source | ||
where estabelecimento_area_programatica = "31" | ||
and lote_dias_para_vencer > -10 | ||
-- order by lote_dias_para_vencer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: brutos_cnes_staging | ||
database: rj-sms | ||
schema: brutos_cnes_staging | ||
- name: br_ms_cnes | ||
database: basedosdados | ||
schema: br_ms_cnes | ||
tables: | ||
- name: rlEstabProgFundo | ||
- name: tbEstabelecimento | ||
- name: tbTipoUnidade | ||
- name: tbTipoEstabelecimento | ||
- name: tbGestao | ||
- name: tbTurnoAtendimento | ||
- name: estabelecimento | ||
- name: equipamento | ||
- name: habilitacao | ||
- name: leito | ||
- name: profissional | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
with source as ( | ||
select * from {{ source('br_ms_cnes', 'equipamento') }} | ||
), | ||
renamed as ( | ||
select | ||
{{ adapter.quote("ano") }}, | ||
{{ adapter.quote("mes") }}, | ||
{{ adapter.quote("sigla_uf") }}, | ||
{{ adapter.quote("id_municipio") }}, | ||
{{ adapter.quote("id_estabelecimento_cnes") }}, | ||
{{ adapter.quote("id_equipamento") }}, | ||
{{ adapter.quote("tipo_equipamento") }}, | ||
{{ adapter.quote("quantidade_equipamentos") }}, | ||
{{ adapter.quote("quantidade_equipamentos_ativos") }}, | ||
{{ adapter.quote("indicador_equipamento_disponivel_sus") }}, | ||
{{ adapter.quote("indicador_equipamento_indisponivel_sus") }} | ||
|
||
from source | ||
) | ||
select * from renamed | ||
|
Oops, something went wrong.