Skip to content

Commit

Permalink
Merge branch 'main' into br_inep_censo_escolar__escola
Browse files Browse the repository at this point in the history
  • Loading branch information
vilelaluiza authored Feb 28, 2024
2 parents 3796a1d + 7d591fe commit 6ffc5f1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
28 changes: 17 additions & 11 deletions models/br_ms_cnes/br_ms_cnes__estabelecimento.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ select
safe_cast(ano as int64) as ano,
safe_cast(mes as int64) as mes,
safe_cast(sigla_uf as string) sigla_uf,
cast(substr(dt_atual, 1, 4) as int64) as ano_atualizacao,
cast(substr(dt_atual, 5, 2) as int64) as mes_atualizacao,
cast(substr(cast(dt_atual as string), 1, 4) as int64) as ano_atualizacao,
cast(substr(cast(dt_atual as string), 5, 2) as int64) as mes_atualizacao,
safe_cast(id_municipio as string) id_municipio,
safe_cast(codufmun as string) id_municipio_6,
safe_cast({{ clean_cols("REGSAUDE") }} as string) id_regiao_saude,
Expand Down Expand Up @@ -79,22 +79,28 @@ select
safe_cast(c_corren as string) conta_corrente,
safe_cast(contratm as string) id_contrato_municipio_sus,
safe_cast(
parse_date('%Y%m%d', dt_publm) as date
parse_date('%Y%m%d', cast(dt_publm as string)) as date
) data_publicacao_contrato_municipal,
safe_cast(parse_date('%Y%m%d', dt_puble) as date) data_publicacao_contrato_estadual,
safe_cast(
parse_date('%Y%m%d', cast(dt_puble as string)) as date
) data_publicacao_contrato_estadual,
safe_cast(contrate as string) id_contrato_estado_sus,
safe_cast(alvara as string) numero_alvara,
safe_cast(parse_date('%Y%m%d', dt_exped) as date) data_expedicao_alvara,
safe_cast(
parse_date('%Y%m%d', cast(dt_exped as string)) as date
) data_expedicao_alvara,
safe_cast({{ clean_cols("ORGEXPED") }} as string) tipo_orgao_expedidor,
safe_cast(
{{ clean_cols("AV_ACRED") }} as string
) tipo_avaliacao_acreditacao_hospitalar,
safe_cast(clasaval as string) tipo_classificacao_acreditacao_hospitalar,
cast(substr(dt_acred, 1, 4) as int64) as ano_acreditacao,
cast(substr(dt_acred, 5, 2) as int64) as mes_acreditacao,
safe_cast({{ clean_cols("AV_PNASS") }} as int64) tipo_avaliacao_pnass,
cast(substr(dt_pnass, 1, 4) as int64) as ano_avaliacao_pnass,
cast(substr(dt_pnass, 5, 2) as int64) as mes_avaliacao_pnass,
cast(substr(cast(dt_acred as string), 1, 4) as int64) as ano_acreditacao,
cast(substr(cast(dt_acred as string), 5, 2) as int64) as mes_acreditacao,
safe_cast(
cast({{ clean_cols("AV_PNASS") }} as string) as int64
) tipo_avaliacao_pnass,
cast(substr(cast(dt_pnass as string), 1, 4) as int64) as ano_avaliacao_pnass,
cast(substr(cast(dt_pnass as string), 5, 2) as int64) as mes_avaliacao_pnass,
safe_cast(nivate_a as int64) indicador_atencao_ambulatorial,
safe_cast(gesprg1e as int64) indicador_gestao_basica_ambulatorial_estadual,
safe_cast(gesprg1m as int64) indicador_gestao_basica_ambulatorial_municipal,
Expand Down Expand Up @@ -263,9 +269,9 @@ select
safe_cast(ap07cv04 as int64) indicador_atendimento_regulacao_plano_seguro_terceiro,
safe_cast(ap07cv05 as int64) indicador_atendimento_regulacao_plano_saude_publico,
safe_cast(ap07cv06 as int64) indicador_atendimento_regulacao_plano_saude_privado
from cnes_add_muni
{% if is_incremental() %}
where

date(cast(ano as int64), cast(mes as int64), 1)
> (select max(date(cast(ano as int64), cast(mes as int64), 1)) from {{ this }})
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ select
) data_portaria,
cast(substr(maportar, 1, 4) as int64) as ano_portaria,
cast(substr(maportar, 5, 2) as int64) as mes_portaria,
from cnes_add_muni
{% if is_incremental() %}
where

Expand Down
2 changes: 1 addition & 1 deletion models/br_ms_cnes/br_ms_cnes__habilitacao.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_habilitacaol as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.habilitacao`
from `basedosdados-staging.br_ms_cnes_staging.habilitacao`
where cnes is not null
),
raw_cnes_habilitacao_without_duplicates as (
Expand Down
5 changes: 0 additions & 5 deletions models/br_ms_cnes/br_ms_cnes__leito.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
"data_type": "int64",
"range": {"start": 2007, "end": 2024, "interval": 1},
},
pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}",
post_hook=[
'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)',
'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:[email protected]", "group:[email protected]") FILTER USING (True)',
],
)
}}

Expand Down
2 changes: 1 addition & 1 deletion models/br_ms_cnes/br_ms_cnes__profissional.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ with
cast(ano as string) as ano1,
cast(mes as string) as mes1,
id_estabelecimento_cnes as iddd
from `basedosdados-staging.br_ms_cnes.estabelecimento`
from `basedosdados.br_ms_cnes.estabelecimento`
) as st
on pf.cnes = st.iddd
and pf.ano = st.ano1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
},
cluster_by=["ano", "mes"],
),
)
}}
with
ons as (
Expand Down

0 comments on commit 6ffc5f1

Please sign in to comment.