Skip to content
Snippets Groups Projects
Commit 8e966d00 authored by Edu Trevisan's avatar Edu Trevisan
Browse files

Add equipes de saude table resources

parent 04a2b3ae
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
# This file is part of SMPPIR-Tables.
# SMPPIR-Tables is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# SMPPIR-Tables is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with SMPPIR-Tables. If not, see <https://www.gnu.org/licenses/>.
import os
import csv
import sys
addr = "ftp://ftp.datasus.gov.br/cnes/"
fileName = "BASE_DE_DADOS_CNES_"
year = int(input("Ano:"))
month = int(input("Mes (utilizamos o mes 12 para os indicadores):"))
if month < 10:
date = str(year) + "0" + str(month)
else:
date = str(year) + str(month)
# Getting data from CNES
os.system('mkdir dados')
getAddr = addr + fileName + date + '.ZIP'
os.system('wget -nc ' + getAddr)
os.system('mv ' + fileName + date + '.ZIP dados/')
# Unpacking data
fileName = "dados/BASE_DE_DADOS_CNES_"
tableName = "tbEquipe"
# tableName = input('nome da tabela (tbEquipe ou tbTipoEquipe):')
zipFile = ''
os.system('mkdir csv' + zipFile)
zipFile = fileName + date + '.ZIP'
os.system('unzip ' + zipFile + ' ' + tableName + date + '.csv -d csv')
# Processar dados
csvName = "csv/" + tableName
os.system('mkdir dadosProcessados')
# Retorna string do mes na formatacao do nome dos arquivos
def treatMonth(month):
if int(month) < 10:
return '0' + str(month)
else:
return str(month)
# Tentar abrir arquivo
try:
ifile = open(csvName + str(year) + treatMonth(month) + '.csv', 'r')
except IOError:
print ('Arquivo nao encontrado: ' + csvName + str(year) + treatMonth(month) + '.csv')
exit()
# Se nao houve erro tratar csv
reader = csv.reader(ifile, delimiter=';')
ofile = open('dadosProcessados/' + tableName + str(year) + treatMonth(month) + '.csv', 'w')
writer = csv.writer(ofile, delimiter ='|')
# Escrever header no arquivo
headers = next(reader, None)
headers.append('MES_CENSO')
headers.append('ANO_CENSO')
writer.writerow(headers)
# Escrever linhas no arquivo com informacoes do ano e mes
for row in reader:
for i, string in enumerate(row):
row[i] = string.replace("\\", "/")
row.append(month)
row.append(year)
writer.writerow(row)
ifile.close()
ofile.close()
# limpar arquivos temporários
os.system('rm -rf dados/ csv/')
\ No newline at end of file
--
--Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
--Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
--
--This file is part of SMPPIR-Tables.
--
--SMPPIR-Tables is free software: you can redistribute it and/or modify
--it under the terms of the GNU General Public License as published by
--the Free Software Foundation, either version 3 of the License, or
--(at your option) any later version.
--
--SMPPIR-Tables is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU General Public License for more details.
--
--You should have received a copy of the GNU General Public License
--along with SMPPIR-Tables. If not, see <https://www.gnu.org/licenses/>.
--
CREATE TABLE Brasil AS
SELECT
regiao.id AS regiao_id,
regiao.nome AS nome_regiao,
estado.id AS estado_id,
estado.nome AS nome_estado,
estado.sigla AS sigla_estado,
municipio.id AS municipio_id,
municipio.nome AS nome_municipio
FROM
regiao,
estado,
municipio
WHERE
regiao.id = estado.regiao_id AND
estado.id = municipio.estado_id
;
\ No newline at end of file
--
--Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
--Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
--
--This file is part of SMPPIR-Tables.
--
--SMPPIR-Tables is free software: you can redistribute it and/or modify
--it under the terms of the GNU General Public License as published by
--the Free Software Foundation, either version 3 of the License, or
--(at your option) any later version.
--
--SMPPIR-Tables is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU General Public License for more details.
--
--You should have received a copy of the GNU General Public License
--along with SMPPIR-Tables. If not, see <https://www.gnu.org/licenses/>.
--
CREATE TABLE esf_quilombolas AS
SELECT
brasil.municipio_id AS municipio_id,
brasil.nome_municipio AS nome_municipio,
brasil.estado_id AS estado_id,
brasil.sigla_estado AS sigla_estado,
brasil.nome_estado AS nome_estado,
brasil.regiao_id AS regiao_id,
brasil.nome_regiao AS nome_regiao,
equipes_saude.cod_municipio AS id_municipio_equipes,
equipes_saude.no_referencia AS nome_equipe,
equipes_saude.ano_censo AS ano_censo
FROM
(SELECT municipio_id AS id, (municipio_id / 10) AS id_6 FROM brasil) AS novo_id,
equipes_saude,
brasil
WHERE
novo_id.id = brasil.municipio_id AND
equipes_saude.cod_municipio = novo_id.id_6 AND
equipes_saude.tp_pop_assist_quilomb = 1
ORDER BY
equipes_saude.ano_censo,
brasil.regiao_id,
brasil.estado_id
;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment