Skip to content

Commit

Permalink
Merge branch 'main' into feat/aihs-reduzidas
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfg authored May 23, 2024
2 parents 7a71c01 + 3f3bc94 commit c5f5531
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 74 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/elementary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Deploy Elementary Report
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
schedule:
- cron: 00 22 * * 1-5
workflow_dispatch:
Expand Down
115 changes: 53 additions & 62 deletions models/br_ms_cnes/br_ms_cnes__estabelecimento.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,51 +56,47 @@ 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,
replace(
safe_cast({{ clean_cols("COD_IR") }} as string), 'nan', null
) tipo_retencao_tributos_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,
safe_cast(vinc_sus as int64) indicador_vinculo_sus,
safe_cast(tpgestao as string) tipo_gestao,
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,
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,
safe_cast({{ clean_cols("ATIVIDAD") }} as string) tipo_atividade_ensino_pesquisa,
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,
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,
nullif(safe_cast(nat_jur as string), '') id_natureza_juridica,
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,
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,
safe_cast({{ clean_cols("TP_UNID") }} as string) tipo_unidade,
replace(safe_cast({{ clean_cols("TURNO_AT") }} as string), 'nan', null) tipo_turno,
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,
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,
Expand All @@ -118,28 +114,23 @@ select
safe_cast(
safe.parse_date('%Y%m%d', cast(dt_exped as string)) as date
) data_expedicao_alvara,
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,
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,
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,
Expand Down
14 changes: 10 additions & 4 deletions models/br_ms_cnes/br_ms_cnes__profissional.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ select
-- UFMUNRES que indica null
safe_cast(regexp_replace(ufmunres, '0{6}', '') as string) id_municipio_6_residencia,
safe_cast(nomeprof as string) nome,
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,
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,
-- 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}', null) as string) cartao_nacional_saude,
safe_cast(cns_prof as string) cartao_nacional_saude,
safe_cast(cbo as string) cbo_2002_original,
safe_cast(
case
Expand Down
12 changes: 6 additions & 6 deletions models/br_ms_sih/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5f5531

Please sign in to comment.