diff --git a/models/br_ms_cnes/estabelecimento.sql b/models/br_ms_cnes/estabelecimento.sql index d3e40847..f4fac636 100644 --- a/models/br_ms_cnes/estabelecimento.sql +++ b/models/br_ms_cnes/estabelecimento.sql @@ -245,3 +245,5 @@ cnes_add_muni AS ( 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 AS t + WHERE (DATE_DIFF(CURRENT_DATE(),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6 + OR DATE_DIFF(DATE(2023,5,1),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 0) diff --git a/models/br_ms_cnes/leito_atualizado.sql b/models/br_ms_cnes/leito_atualizado.sql index dd113af6..35cfa781 100644 --- a/models/br_ms_cnes/leito_atualizado.sql +++ b/models/br_ms_cnes/leito_atualizado.sql @@ -33,7 +33,7 @@ leito_x_estabelecimento as( SELECT * FROM cnes_leito_without_duplicates as lt LEFT JOIN (SELECT id_municipio, CAST(ano as STRING) ano1,CAST(mes as STRING) mes1, id_estabelecimento_cnes,id_municipio AS IDDD from `basedosdados-dev.br_ms_cnes.estabelecimento`) as st - ON lt.id_estabelecimento_cnes = st.IDDD AND lt.ano = st.ano1 AND lt.mes = st.mes1 + ON lt.CNES = st.IDDD AND lt.ano = st.ano1 AND lt.mes = st.mes1 ) SELECT diff --git a/models/br_ms_cnes/profissional.sql b/models/br_ms_cnes/profissional.sql index 296c1abc..ffc21ed9 100644 --- a/models/br_ms_cnes/profissional.sql +++ b/models/br_ms_cnes/profissional.sql @@ -43,7 +43,7 @@ SAFE_CAST(VINCULAC AS STRING) id_vinculo, SAFE_CAST(REGISTRO AS STRING) id_registro_conselho, SAFE_CAST(CONSELHO AS STRING) id_conselho, -- replace de valores de linha com 15 zeros para null. 15 zeros é valor do campo CNS_PROF que indica null -SAFE_CAST(regexp_replace(CNS_PROF,'0{15}', '') A\S STRING) cartao_nacional_saude, +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, diff --git a/models/br_ms_cnes/profissional_atualizado.sql b/models/br_ms_cnes/profissional_atualizado.sql index 6a8a9b68..ea7ed847 100644 --- a/models/br_ms_cnes/profissional_atualizado.sql +++ b/models/br_ms_cnes/profissional_atualizado.sql @@ -46,7 +46,7 @@ SAFE_CAST(VINCULAC AS STRING) id_vinculo, SAFE_CAST(REGISTRO AS STRING) id_registro_conselho, SAFE_CAST(CONSELHO AS STRING) id_conselho, -- replace de valores de linha com 15 zeros para null. 15 zeros é valor do campo CNS_PROF que indica null -SAFE_CAST(regexp_replace(CNS_PROF,'0{15}', '') A\S STRING) cartao_nacional_saude, +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,