Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: basedosdados/queries-basedosdados
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c5f55318d7427fca30058570be40de661c83496a
Choose a base ref
..
head repository: basedosdados/queries-basedosdados
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 356095d17ca1783262b0e927ebbb4405bdcdd712
Choose a head ref
Showing with 76 additions and 81 deletions.
  1. +2 −0 .github/workflows/elementary.yaml
  2. +62 −53 models/br_ms_cnes/br_ms_cnes__estabelecimento.sql
  3. +4 −10 models/br_ms_cnes/br_ms_cnes__profissional.sql
  4. +8 −18 models/br_ms_sih/schema.yml
2 changes: 2 additions & 0 deletions .github/workflows/elementary.yaml
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ name: Deploy Elementary Report
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
schedule:
- cron: 00 22 * * 1-5
workflow_dispatch:
115 changes: 62 additions & 53 deletions models/br_ms_cnes/br_ms_cnes__estabelecimento.sql
Original file line number Diff line number Diff line change
@@ -56,47 +56,51 @@ select
-- fazer replace em valores de linha com 14 zeros para null. 14 zeros é o tamanho
-- de um cpf/cnpj nulo
safe_cast(regexp_replace(cnpj_man, '0{14}', '') as string) cnpj_mantenedora,
case
when safe_cast({{ clean_cols("COD_IR") }} as string) = 'nan'
then null
else safe_cast({{ clean_cols("COD_IR") }} as string)
end as tipo_retencao_tributos_mantenedora,
replace(
safe_cast({{ clean_cols("COD_IR") }} as string), 'nan', null
) tipo_retencao_tributos_mantenedora,
safe_cast(vinc_sus as int64) indicador_vinculo_sus,
safe_cast(tpgestao as string) tipo_gestao,
case
when safe_cast({{ clean_cols("ESFERA_A") }} as string) = 'nan'
then null
else safe_cast({{ clean_cols("ESFERA_A") }} as string)
end as tipo_esfera_administrativa,
case
when regexp_replace(safe_cast(retencao as string), '^0+', '') = ''
then '0'
when safe_cast(retencao as string) = 'nan'
then null
else regexp_replace(safe_cast(retencao as string), '^0+', '')
end as tipo_retencao_tributos,
replace(
safe_cast({{ clean_cols("ESFERA_A") }} as string), 'nan', null
) tipo_esfera_administrativa,
replace(
safe_cast(
case
when regexp_replace(safe_cast(retencao as string), '^0+', '') = ''
then '0'
else regexp_replace(safe_cast(retencao as string), '^0+', '')
end as string
),
'nan',
null
) as tipo_retencao_tributos,
safe_cast({{ clean_cols("ATIVIDAD") }} as string) tipo_atividade_ensino_pesquisa,
case
when regexp_replace(safe_cast(natureza as string), '^0+', '') = ''
then '0'
when safe_cast(natureza as string) = 'nan'
then null
else regexp_replace(safe_cast(natureza as string), '^0+', '')
end as tipo_natureza_administrativa,
replace(
safe_cast(
case
when regexp_replace(safe_cast(natureza as string), '^0+', '') = ''
then '0'
else regexp_replace(safe_cast(natureza as string), '^0+', '')
end as string
),
'nan',
null
) as tipo_natureza_administrativa,
nullif(safe_cast(nat_jur as string), '') id_natureza_juridica,
case
when regexp_replace(safe_cast(clientel as string), '^0+', '') = ''
then '0'
when safe_cast(clientel as string) = 'nan'
then null
else regexp_replace(safe_cast(clientel as string), '^0+', '')
end as tipo_fluxo_atendimento,
replace(
safe_cast(
case
when regexp_replace(safe_cast(clientel as string), '^0+', '') = ''
then '0'
else regexp_replace(safe_cast(clientel as string), '^0+', '')
end as string
),
'nan',
null
) as tipo_fluxo_atendimento,
safe_cast({{ clean_cols("TP_UNID") }} as string) tipo_unidade,
case
when safe_cast({{ clean_cols("TURNO_AT") }} as string) = 'nan'
then null
else safe_cast({{ clean_cols("TURNO_AT") }} as string)
end as tipo_turno,
replace(safe_cast({{ clean_cols("TURNO_AT") }} as string), 'nan', null) tipo_turno,
safe_cast({{ clean_cols("NIV_HIER") }} as string) tipo_nivel_hierarquia,
safe_cast({{ clean_cols("TP_PREST") }} as string) tipo_prestador,
safe_cast(co_banco as string) banco,
@@ -114,23 +118,28 @@ select
safe_cast(
safe.parse_date('%Y%m%d', cast(dt_exped as string)) as date
) data_expedicao_alvara,
case
when safe_cast({{ clean_cols("ORGEXPED") }} as string) = 'nan'
then null
else safe_cast({{ clean_cols("ORGEXPED") }} as string)
end as tipo_orgao_expedidor,
case
when safe_cast({{ clean_cols("AV_ACRED") }} as string) = 'nan'
then null
else safe_cast({{ clean_cols("AV_ACRED") }} as string)
end as tipo_avaliacao_acreditacao_hospitalar,
case
when regexp_replace(safe_cast(clasaval as string), '^0+', '') = ''
then '0'
when safe_cast(clasaval as string) = 'nan'
then null
else regexp_replace(safe_cast(clasaval as string), '^0+', '')
end as tipo_classificacao_acreditacao_hospitalar,
replace(
safe_cast({{ clean_cols("ORGEXPED") }} as string), 'nan', null
) tipo_orgao_expedidor,
replace(
safe_cast({{ clean_cols("AV_ACRED") }} as string), 'nan', null
) tipo_avaliacao_acreditacao_hospitalar,
replace(
safe_cast(
case
when regexp_replace(safe_cast(clasaval as string), '^0+', '') = ''
then '0'
else regexp_replace(safe_cast(clasaval as string), '^0+', '')
end as string
),
'nan',
null
) as tipo_classificacao_acreditacao_hospitalar,
safe_cast(substr(cast(dt_acred as string), 1, 4) as int64) as ano_acreditacao,
safe_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,
safe_cast(substr(cast(dt_pnass as string), 1, 4) as int64) as ano_avaliacao_pnass,
safe_cast(substr(cast(dt_pnass as string), 5, 2) as int64) as mes_avaliacao_pnass,
safe_cast(nivate_a as int64) indicador_atencao_ambulatorial,
14 changes: 4 additions & 10 deletions models/br_ms_cnes/br_ms_cnes__profissional.sql
Original file line number Diff line number Diff line change
@@ -43,18 +43,12 @@ select
-- UFMUNRES que indica null
safe_cast(regexp_replace(ufmunres, '0{6}', '') as string) id_municipio_6_residencia,
safe_cast(nomeprof as string) nome,
case
when vinculac = 'nan' then null else safe_cast(vinculac as string)
end as tipo_vinculo,
case
when registro = 'nan' then null else safe_cast(registro as string)
end as id_registro_conselho,
case
when conselho = 'nan' then null else safe_cast(conselho as string)
end as tipo_conselho,
safe_cast(replace(vinculac, 'nan', null) as string) tipo_vinculo,
safe_cast(replace(registro, 'nan', null) as string) id_registro_conselho,
safe_cast(replace(conselho, 'nan', null) as string) tipo_conselho,
-- replace de valores de linha com 15 zeros para null. 15 zeros é valor do campo
-- CNS_PROF que indica null
safe_cast(cns_prof as string) cartao_nacional_saude,
safe_cast(regexp_replace(cns_prof, '0{15}', null) as string) cartao_nacional_saude,
safe_cast(cbo as string) cbo_2002_original,
safe_cast(
case
26 changes: 8 additions & 18 deletions models/br_ms_sih/schema.yml
Original file line number Diff line number Diff line change
@@ -67,12 +67,12 @@ models:
- name: cbo_2002_profissional
description: Identificador de Ocupação Brasileira do Profissional que realizou
o ato ou “00000” caso não tenha sido
# tests:
# - relationships:
# to: ref('br_bd_diretorios_brasil__cbo_2002')
# field: cbo_2002.cbo_2002
# config:
# where: __most_recent_year_month__
tests:
- relationships:
to: ref('br_bd_diretorios_brasil__cbo_2002')
field: cbo_2002.cbo_2002
config:
where: __most_recent_year_month__
- name: quantidade_procedimentos
description: Quantidade de procedimentos realizados
- name: id_cid_principal
@@ -333,18 +333,13 @@ models:
- custom_relationships:
to: ref('br_bd_diretorios_brasil__cid_10')
field: subcategoria
ignore_values: ["0000"]
config:
where: __most_recent_year_month__
- name: cid_causa_categoria
description: Categoria do CID de causa.
- name: cid_causa_subcategoria
description: Subcategoria do CID de causa.
tests:
- custom_relationships:
to: ref('br_bd_diretorios_brasil__cid_10')
field: subcategoria
config:
where: __most_recent_year_month__
- name: cid_principal_categoria
description: Código da categoria do diagnóstico principal (CID10).
- name: cid_principal_subcategoria
@@ -353,6 +348,7 @@ models:
- custom_relationships:
to: ref('br_bd_diretorios_brasil__cid_10')
field: subcategoria
ignore_values: ["0000"]
config:
where: __most_recent_year_month__
- name: cid_secundario_categoria
@@ -419,12 +415,6 @@ models:
description: Categoria do CID da morte.
- name: cid_morte_subcategoria
description: Subcategoria do CID da morte.
tests:
- custom_relationships:
to: ref('br_bd_diretorios_brasil__cid_10')
field: subcategoria
config:
where: __most_recent_year_month__
- name: indicador_obito
description: Indica Óbito
- name: remessa