Skip to content

Commit

Permalink
fix: set models to basedosdados-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
folhesgabriel committed Feb 26, 2024
1 parent b947433 commit d8256d4
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__dados_complementares.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_dados_complementares as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.dados_complementares`
from `basedosdados-staging.br_ms_cnes_staging.dados_complementares`
where cnes is not null
),
raw_cnes_dados_complementares_without_duplicates as (
Expand All @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_dados_complementares_without_duplicates.codufmun
= mun.id_municipio_6
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__equipamento.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with
raw_cnes_equipamento as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.equipamento`
from `basedosdados-staging.br_ms_cnes_staging.equipamento`
where cnes is not null
),
unique_raw_cnes_equipamento as (
Expand All @@ -35,7 +35,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on unique_raw_cnes_equipamento.codufmun = mun.id_municipio_6
)
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__equipe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ with
raw_cnes_equipe as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.equipe`
from `basedosdados-staging.br_ms_cnes_staging.equipe`
where cnes is not null
),
cnes_add_muni as (
Expand All @@ -30,7 +30,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_equipe.codufmun = mun.id_municipio_6
)
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__estabelecimento.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_estabelecimento_without_duplicates.codufmun = mun.id_municipio_6
)
Expand Down Expand Up @@ -239,7 +239,7 @@ select
safe_cast(ap03cv04 as int64) indicador_atendimento_sadt_plano_seguro_terceiro,
safe_cast(ap03cv05 as int64) indicador_atendimento_sadt_plano_saude_publico,
safe_cast(ap03cv06 as int64) indicador_atendimento_sadt_plano_saude_privado,
safe_cast(ap04cv01 as string) indicador_atendimento_urgencia_sus,
safe_cast(ap04cv01 as int64) indicador_atendimento_urgencia_sus,
safe_cast(ap04cv02 as int64) indicador_atendimento_urgencia_privado,
safe_cast(ap04cv03 as int64) indicador_atendimento_urgencia_plano_seguro_proprio,
safe_cast(ap04cv04 as int64) indicador_atendimento_urgencia_plano_seguro_terceiro,
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__estabelecimento_ensino.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_estabelecimento_ensino as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.estabelecimento_ensino`
from `basedosdados-staging.br_ms_cnes_staging.estabelecimento_ensino`
where cnes is not null
),
raw_cnes_estabelecimento_ensino_without_duplicates as (
Expand All @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_estabelecimento_ensino_without_duplicates.codufmun
= mun.id_municipio_6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_estabelecimento_filantropico as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.estabelecimento_filantropico`
from `basedosdados-staging.br_ms_cnes_staging.estabelecimento_filantropico`
where cnes is not null
),
raw_cnes_estabelecimento_filantropico_without_duplicates as (
Expand All @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_estabelecimento_filantropico_without_duplicates.codufmun
= mun.id_municipio_6
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__gestao_metas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_gestao_metas as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.gestao_metas`
from `basedosdados-staging.br_ms_cnes_staging.gestao_metas`
where cnes is not null
),
raw_cnes_gestao_metas_without_duplicates as (
Expand All @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_gestao_metas_without_duplicates.codufmun = mun.id_municipio_6
)
Expand Down
5 changes: 5 additions & 0 deletions models/br_ms_cnes/br_ms_cnes__habilitacao.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"data_type": "int64",
"range": {"start": 2005, "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 (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)',
],
)
}}
with
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__incentivos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_incentivos as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.incentivos`
from `basedosdados-staging.br_ms_cnes_staging.incentivos`
where cnes is not null
),
raw_cnes_incentivos_without_duplicates as (
Expand All @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_incentivos_without_duplicates.codufmun = mun.id_municipio_6
)
Expand Down
10 changes: 6 additions & 4 deletions models/br_ms_cnes/br_ms_cnes__leito.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
with
raw_cnes_leito as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select * from `basedosdados-dev.br_ms_cnes_staging.leito` where cnes is not null
select *
from `basedosdados-staging.br_ms_cnes_staging.leito`
where cnes is not null
),
cnes_leito_without_duplicates as (select distinct * from raw_cnes_leito),
leito_x_estabelecimento as (
Expand Down Expand Up @@ -52,9 +54,9 @@ select
safe_cast(cnes as string) as id_estabelecimento_cnes,
safe_cast(codleito as string) as tipo_especialidade_leito,
safe_cast(tp_leito as string) as tipo_leito,
safe_cast(qt_exist as string) as quantidade_total,
safe_cast(qt_contr as string) as quantidade_contratado,
safe_cast(qt_sus as string) as quantidade_sus
safe_cast(qt_exist as int64) as quantidade_total,
safe_cast(qt_contr as int64) as quantidade_contratado,
safe_cast(qt_sus as int64) as quantidade_sus
from leito_x_estabelecimento
{% if is_incremental() %}
where
Expand Down
16 changes: 8 additions & 8 deletions models/br_ms_cnes/br_ms_cnes__profissional.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_profissional as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.profissional`
from `basedosdados-staging.br_ms_cnes_staging.profissional`
where cnes is not null
),
profissional_x_estabelecimento as (
Expand All @@ -32,7 +32,7 @@ with
cast(ano as string) as ano1,
cast(mes as string) as mes1,
id_estabelecimento_cnes as iddd
from `basedosdados-dev.br_ms_cnes.estabelecimento`
from `basedosdados-staging.br_ms_cnes.estabelecimento`
) as st
on pf.cnes = st.iddd
and pf.ano = st.ano1
Expand All @@ -55,12 +55,12 @@ select
-- CNS_PROF que indica null
safe_cast(regexp_replace(cns_prof, '0{15}', '') as string) cartao_nacional_saude,
safe_cast(cbo as string) cbo_2002,
safe_cast(terceiro as string) indicador_estabelecimento_terceiro,
safe_cast(vincul_c as string) indicador_vinculo_contratado_sus,
safe_cast(vincul_a as string) indicador_vinculo_autonomo_sus,
safe_cast(vincul_n as string) indicador_vinculo_outros,
safe_cast(prof_sus as string) indicador_atende_sus,
safe_cast(profnsus as string) indicador_atende_nao_sus,
safe_cast(terceiro as int64) indicador_estabelecimento_terceiro,
safe_cast(vincul_c as int64) indicador_vinculo_contratado_sus,
safe_cast(vincul_a as int64) indicador_vinculo_autonomo_sus,
safe_cast(vincul_n as int64) indicador_vinculo_outros,
safe_cast(prof_sus as int64) indicador_atende_sus,
safe_cast(profnsus as int64) indicador_atende_nao_sus,
safe_cast(horaoutr as int64) carga_horaria_outros,
safe_cast(horahosp as int64) carga_horaria_hospitalar,
safe_cast(hora_amb as int64) carga_horaria_ambulatorial
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__regra_contratual.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_regra_contratual as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.regra_contratual`
from `basedosdados-staging.br_ms_cnes_staging.regra_contratual`
where cnes is not null
),
raw_cnes_regra_contratual_without_duplicates as (
Expand All @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_regra_contratual_without_duplicates.codufmun
= mun.id_municipio_6
Expand Down
4 changes: 2 additions & 2 deletions models/br_ms_cnes/br_ms_cnes__servico_especializado.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
raw_cnes_servico_especializado as (
-- 1. Retirar linhas com id_estabelecimento_cnes nulo
select *
from `basedosdados-dev.br_ms_cnes_staging.servico_especializado`
from `basedosdados-staging.br_ms_cnes_staging.servico_especializado`
where cnes is not null
),
raw_cnes_servico_especializado_without_duplicates as (
Expand All @@ -33,7 +33,7 @@ with
left join
(
select id_municipio, id_municipio_6,
from `basedosdados-dev.br_bd_diretorios_brasil.municipio`
from `basedosdados-staging.br_bd_diretorios_brasil.municipio`
) as mun
on raw_cnes_servico_especializado_without_duplicates.codufmun
= mun.id_municipio_6
Expand Down

0 comments on commit d8256d4

Please sign in to comment.