Skip to content

Commit

Permalink
Merge pull request #213 from basedosdados/staging/br_ms_cnes
Browse files Browse the repository at this point in the history
br_ms_cnes
  • Loading branch information
folhesgabriel authored Aug 3, 2023
2 parents 85e959e + c3f6689 commit 6b9a7cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
8 changes: 4 additions & 4 deletions models/br_ms_cnes/equipamento.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ cnes_add_muni AS (
ON raw_cnes_equipamento.CODUFMUN = mun.id_municipio_6
)
SELECT
SAFE_CAST(ano AS INT64),
SAFE_CAST(mes AS INT64),
SAFE_CAST(sigla_uf AS STRING),
SAFE_CAST(id_municipio AS STRING),
SAFE_CAST(ano AS INT64) AS ano,
SAFE_CAST(mes AS INT64) AS mes,
SAFE_CAST(sigla_uf AS STRING) AS sigla_uf,
SAFE_CAST(id_municipio AS STRING) AS id_municipio,
SAFE_CAST(CNES AS STRING) AS id_estabelecimento_cnes,
SAFE_CAST(CODEQUIP AS STRING) AS id_equipamento,
SAFE_CAST(TIPEQUIP AS STRING) AS tipo_equipamento,
Expand Down
9 changes: 4 additions & 5 deletions models/br_ms_cnes/equipe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ cnes_add_muni AS (
)

SELECT
SAFE_CAST(ano AS INT64),
SAFE_CAST(mes AS INT64),
SAFE_CAST(id_municipio AS STRING),
SAFE_CAST(sigla_uf AS STRING),
SAFE_CAST(ano AS INT64) AS ano,
SAFE_CAST(mes AS INT64) AS mes,
SAFE_CAST(sigla_uf AS STRING) AS sigla_uf,
SAFE_CAST(id_municipio AS STRING) AS id_municipio,
SAFE_CAST(CNES AS STRING) AS id_estabelecimento_cnes,
SAFE_CAST(ID_EQUIPE AS STRING) AS id_equipe,
SAFE_CAST(TIPO_EQP AS STRING) AS tipo_equipe,
SAFE_CAST(NOME_EQP AS STRING) AS equipe,
SAFE_CAST(AREA_EQP AS STRING) AS tipo_area_equipe,
SAFE_CAST(NOMEAREA AS STRING) AS area,
SAFE_CAST(ID_SEGM AS STRING) AS id_segmento,
SAFE_CAST(TIPOSEGM AS STRING) AS tipo_segmento,
Expand Down
19 changes: 5 additions & 14 deletions models/br_ms_cnes/leito.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,19 @@ WITH raw_cnes_leito AS (
SELECT *
FROM `basedosdados-dev.br_ms_cnes_staging.leito`
WHERE CNES IS NOT NULL),
cnes_leito_duplicates AS (
cnes_leito_without_duplicates AS (
SELECT DISTINCT *
FROM raw_cnes_leito
),
cnes_add_muni AS (
-- 3. Adicionar id_municipio
SELECT *
FROM cnes_leito_duplicates
LEFT JOIN (SELECT id_municipio, id_municipio_6,
FROM `basedosdados-dev.br_bd_diretorios_brasil.municipio`) as mun
ON cnes_leito_duplicates.CODUFMUN = mun.id_municipio_6
)

SELECT
SAFE_CAST(ano AS INT64),
SAFE_CAST(mes AS INT64),
SAFE_CAST(sigla_uf AS STRING),
SAFE_CAST(id_municipio AS STRING),
SAFE_CAST(ano AS INT64) AS ano,
SAFE_CAST(mes AS INT64) AS mes,
SAFE_CAST(sigla_uf AS STRING) AS sigla_uf,
SAFE_CAST(CNES AS STRING) AS id_estabelecimento_cnes,
SAFE_CAST(CODLEITO AS STRING) AS id_especialidade,
SAFE_CAST(TP_LEITO AS STRING) AS tipo_leito,
SAFE_CAST(QT_EXIST AS STRING) AS quantidade,
SAFE_CAST(QT_CONTR AS STRING) AS quantidade_contratado,
SAFE_CAST(QT_SUS AS STRING) AS quantidade_sus
FROM cnes_add_muni
FROM cnes_leito_without_duplicates

0 comments on commit 6b9a7cf

Please sign in to comment.