diff --git a/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql b/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql index 8bdd4a67..46df46c2 100644 --- a/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql +++ b/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql @@ -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, @@ -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, @@ -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 %} diff --git a/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql b/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql index 3d7145d2..6755b719 100644 --- a/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql +++ b/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql @@ -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 diff --git a/models/br_ms_cnes/br_ms_cnes__habilitacao.sql b/models/br_ms_cnes/br_ms_cnes__habilitacao.sql index 36ef2eae..dbada63f 100644 --- a/models/br_ms_cnes/br_ms_cnes__habilitacao.sql +++ b/models/br_ms_cnes/br_ms_cnes__habilitacao.sql @@ -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 ( diff --git a/models/br_ms_cnes/br_ms_cnes__leito.sql b/models/br_ms_cnes/br_ms_cnes__leito.sql index 2d86ab0c..06f7dcc2 100644 --- a/models/br_ms_cnes/br_ms_cnes__leito.sql +++ b/models/br_ms_cnes/br_ms_cnes__leito.sql @@ -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:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (True)', - ], ) }} diff --git a/models/br_ms_cnes/br_ms_cnes__profissional.sql b/models/br_ms_cnes/br_ms_cnes__profissional.sql index 93b1d402..88ca48e1 100644 --- a/models/br_ms_cnes/br_ms_cnes__profissional.sql +++ b/models/br_ms_cnes/br_ms_cnes__profissional.sql @@ -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 diff --git a/models/br_ons_estimativa_custos/br_ons_estimativa_custos__custo_variavel_unitario_usinas_termicas.sql b/models/br_ons_estimativa_custos/br_ons_estimativa_custos__custo_variavel_unitario_usinas_termicas.sql index f8dacb89..cbea9cef 100644 --- a/models/br_ons_estimativa_custos/br_ons_estimativa_custos__custo_variavel_unitario_usinas_termicas.sql +++ b/models/br_ons_estimativa_custos/br_ons_estimativa_custos__custo_variavel_unitario_usinas_termicas.sql @@ -13,7 +13,7 @@ }, }, cluster_by=["ano", "mes"], - ), + ) }} with ons as (