In [1]:
import pandas as pd

AlertaDengue API

A API AlertaDengue foi desenhada para atender às Secretarias de Saúde que necessitam dos dados do sistema para a integração em suas próprias rotinas.

A API disponibiliza a seguinte funcionalidade:

  • consulta de dados de alertas para a cidade do Rio de Janeiro.

Consulta de dados de alertas para a cidade do Rio de Janeiro

Esssa funcionalidade está disponível por meio da URL:

https://info.dengue.mat.br/api/alertcity?<PARAMETROS_DA_CONSULTA>

Onde <PARAMETROS_DA_CONSULTA> deve conter os parâmetros:

  • geocode: código IBGE da cidade
  • disease: tipo de doença a ser consultado (str:dengue|chikungunya|zika)
  • format: formato de saída dos dados (str:json|csv)
  • ew_start: semana epidemiológica de início da consulta (int:1-53)
  • ew_end: semana epidemiológica de final da consulta (int:1-53)
  • e_year: ano de referência da consulta (int:0-9999)

Todos os parâmetros acima mencionados são obrigatórios para a consulta.

Abaixo, segue exemplo de requisição de registros de dengue entre a semana 1 e 50 do ano de 2017, em formato CSV:

https://info.dengue.mat.br/api/alertcity?geocode=3304557&disease=dengue&format=csv&ew_start=1&ew_end=50&e_year=2017

A continuação, seguem exemplos de uso da API referente a funcionalidade descrita.

Consulta em formato CSV


In [2]:
# 3304557 = Rio de Janeiro city geocode
url = 'http://localhost:8000/api/alertcity'
search_filter = (
    'geocode=3304557&disease=dengue&format=csv&' +
    'ew_start=1&ew_end=50&e_year=2017'
)
df = pd.read_csv('%s?%s' % (url, search_filter))
print(url)
df.head()


http://localhost:8000/api/alertcity
Out[2]:
id aps se data tweets casos casos_est casos_estmin casos_estmax tmin rt prt1 inc nivel
0 190034 2.1 201724 2017-06-11 12 1 1.0 1.0 1.0 18.8571 0.349526 0.137641 0.180933 1
1 213390 2.1 201733 2017-08-13 13 5 5.0 5.0 5.0 19.7143 1.777530 0.797493 0.904665 1
2 217372 2.1 201734 2017-08-20 15 2 2.0 2.0 2.0 18.2857 0.664763 0.311178 0.361866 1
3 225358 2.1 201737 2017-09-10 12 3 3.0 3.0 3.0 17.9714 1.266840 0.616171 0.542799 1
4 229380 2.1 201738 2017-09-17 22 4 4.0 4.0 4.0 18.3429 1.820440 0.783039 0.723732 1

In [3]:
# 4106902 = Curitiba city geocode
url = 'http://localhost:8000/api/alertcity'
search_filter = (
    'geocode=4106902&disease=dengue&format=csv&' +
    'ew_start=1&ew_end=50&e_year=2017'
)
df = pd.read_csv('%s?%s' % (url, search_filter))
print(url)
df.head()


http://localhost:8000/api/alertcity
Out[3]:
data_iniSE SE casos_est casos_est_min casos_est_max casos p_rt1 p_inc100k Localidade_id nivel id versao_modelo
0 2017-10-08 201741 22.0 22 22 22 0.477252 1.16156 0 1 4106902020174117533 2018-01-02
1 2017-11-26 201748 20.0 18 21 18 0.265967 1.05597 0 1 4106902020174817533 2018-01-02
2 2017-01-01 201701 130.0 130 130 130 0.999967 6.86379 0 1 4106902020170117533 2018-01-02
3 2017-01-08 201702 142.0 142 142 142 0.997440 7.49737 0 1 4106902020170217533 2018-01-02
4 2017-01-15 201703 143.0 143 143 143 0.913890 7.55017 0 1 4106902020170317533 2018-01-02

Consulta em formato JSON


In [4]:
# 4106902 = Curitiba city geocode
search_filter = (
    'geocode=4106902&disease=dengue&format=json&' +
    'ew_start=1&ew_end=50&e_year=2017'
)
search_url = '%s?%s' % (url, search_filter)

df = pd.read_json(search_url)

print(search_url)
df.head()


http://localhost:8000/api/alertcity?geocode=4106902&disease=dengue&format=json&ew_start=1&ew_end=50&e_year=2017
Out[4]:
Localidade_id SE casos casos_est casos_est_max casos_est_min data_iniSE id nivel p_inc100k p_rt1 versao_modelo
0 0 201741 22 22 22 22 1507420800000 4106902020174117533 1 1.16156 0.477252 2018-01-02
1 0 201748 18 20 21 18 1511654400000 4106902020174817533 1 1.05597 0.265967 2018-01-02
2 0 201701 130 130 130 130 1483228800000 4106902020170117533 1 6.86379 0.999967 2018-01-02
3 0 201702 142 142 142 142 1483833600000 4106902020170217533 1 7.49737 0.997440 2018-01-02
4 0 201703 143 143 143 143 1484438400000 4106902020170317533 1 7.55017 0.913890 2018-01-02

In [5]:
# 3304557 = Rio de Janeiro city geocode
search_filter = (
    'geocode=3304557&disease=dengue&format=json&' +
    'ew_start=1&ew_end=50&e_year=2017'
)
search_url = '%s?%s' % (url, search_filter)

df = pd.read_json(search_url)

print(search_url)
df.head()


http://localhost:8000/api/alertcity?geocode=3304557&disease=dengue&format=json&ew_start=1&ew_end=50&e_year=2017
Out[5]:
aps casos casos_est casos_estmax casos_estmin data id inc nivel prt1 rt se tmin tweets
0 2.1 1 1 1 1 1497139200000 190034 0.180933 1 0.137641 0.349526 201724 18.8571 12
1 2.1 5 5 5 5 1502582400000 213390 0.904665 1 0.797493 1.777530 201733 19.7143 13
2 2.1 2 2 2 2 1503187200000 217372 0.361866 1 0.311178 0.664763 201734 18.2857 15
3 2.1 3 3 3 3 1505001600000 225358 0.542799 1 0.616171 1.266840 201737 17.9714 12
4 2.1 4 4 4 4 1505606400000 229380 0.723732 1 0.783039 1.820440 201738 18.3429 22

Tratamento de Erros


In [6]:
params = [
    '',
    'disease=dengue',
    'geocode=3304557',
    'format=csv',
    'ew_start=1',
    'ew_end=50',
    'e_year=2017'
]

search_filter = ''
sep = ''
for param in params:
    print('-' * 80)
    
    search_filter += sep + param
    url_search = '%s?%s' % (url, search_filter)
    
    print(url_search)
    
    df = pd.read_csv(url_search)
    sep = '&'
    print(df.head())


--------------------------------------------------------------------------------
http://localhost:8000/api/alertcity?
Empty DataFrame
Columns: [[EE] error_message: Disease sent is empty.]
Index: []
--------------------------------------------------------------------------------
http://localhost:8000/api/alertcity?&disease=dengue
Empty DataFrame
Columns: [[EE] error_message: GEO-Code sent is empty.]
Index: []
--------------------------------------------------------------------------------
http://localhost:8000/api/alertcity?&disease=dengue&geocode=3304557
Empty DataFrame
Columns: [[EE] error_message: Format sent is empty.]
Index: []
--------------------------------------------------------------------------------
http://localhost:8000/api/alertcity?&disease=dengue&geocode=3304557&format=csv
Empty DataFrame
Columns: [[EE] error_message: Epidemic start week sent is empty.]
Index: []
--------------------------------------------------------------------------------
http://localhost:8000/api/alertcity?&disease=dengue&geocode=3304557&format=csv&ew_start=1
Empty DataFrame
Columns: [[EE] error_message: Epidemic end week sent is empty.]
Index: []
--------------------------------------------------------------------------------
http://localhost:8000/api/alertcity?&disease=dengue&geocode=3304557&format=csv&ew_start=1&ew_end=50
Empty DataFrame
Columns: [[EE] error_message: Epidemic year sent is empty.]
Index: []
--------------------------------------------------------------------------------
http://localhost:8000/api/alertcity?&disease=dengue&geocode=3304557&format=csv&ew_start=1&ew_end=50&e_year=2017
       id  aps      se        data  tweets  casos  casos_est  casos_estmin  \
0  190034  2.1  201724  2017-06-11      12      1        1.0           1.0   
1  213390  2.1  201733  2017-08-13      13      5        5.0           5.0   
2  217372  2.1  201734  2017-08-20      15      2        2.0           2.0   
3  225358  2.1  201737  2017-09-10      12      3        3.0           3.0   
4  229380  2.1  201738  2017-09-17      22      4        4.0           4.0   

   casos_estmax     tmin        rt      prt1       inc  nivel  
0           1.0  18.8571  0.349526  0.137641  0.180933      1  
1           5.0  19.7143  1.777530  0.797493  0.904665      1  
2           2.0  18.2857  0.664763  0.311178  0.361866      1  
3           3.0  17.9714  1.266840  0.616171  0.542799      1  
4           4.0  18.3429  1.820440  0.783039  0.723732      1