Skip to content

Commit bf00c94

Browse files
committed
Fetch SINAN-Malaria data
1 parent 81b3e33 commit bf00c94

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

R/fetch_datasus.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#'
77
#' A specific UF or a vector of UFs can be informed using the following abbreviations: "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO".
88
#'
9-
#' The following systems are implemented: "SIH-RD", "SIH-RJ", "SIH-SP", "SIH-ER", "SIM-DO", "SIM-DOFET", "SIM-DOEXT", "SIM-DOINF", "SIM-DOMAT", "SINASC", "CNES-LT", "CNES-ST", "CNES-DC", "CNES-EQ", "CNES-SR", "CNES-HB", "CNES-PF", "CNES-EP", "CNES-RC", "CNES-IN", "CNES-EE", "CNES-EF", "CNES-GM", "SIA-AB", "SIA-ABO", "SIA-ACF", "SIA-AD", "SIA-AN", "SIA-AM", "SIA-AQ", "SIA-AR", "SIA-ATD", "SIA-PA", "SIA-PS", "SIA-SAD", "SINAN-DENGUE-FINAL", "SINAN-DENGUE-PRELIMINAR", "SINAN-CHIKUNGUNYA-FINAL", "SINAN-CHIKUNGUNYA-PRELIMINAR", "SINAN-ZIKA-FINAL", "SINAN-ZIKA-PRELIMINAR".
9+
#' The following systems are implemented: "SIH-RD", "SIH-RJ", "SIH-SP", "SIH-ER", "SIM-DO", "SIM-DOFET", "SIM-DOEXT", "SIM-DOINF", "SIM-DOMAT", "SINASC", "CNES-LT", "CNES-ST", "CNES-DC", "CNES-EQ", "CNES-SR", "CNES-HB", "CNES-PF", "CNES-EP", "CNES-RC", "CNES-IN", "CNES-EE", "CNES-EF", "CNES-GM", "SIA-AB", "SIA-ABO", "SIA-ACF", "SIA-AD", "SIA-AN", "SIA-AM", "SIA-AQ", "SIA-AR", "SIA-ATD", "SIA-PA", "SIA-PS", "SIA-SAD", "SINAN-DENGUE-FINAL", "SINAN-DENGUE-PRELIMINAR", "SINAN-CHIKUNGUNYA-FINAL", "SINAN-CHIKUNGUNYA-PRELIMINAR", "SINAN-ZIKA-FINAL", "SINAN-ZIKA-PRELIMINAR", "SINAN-MALARIA-FINAL", "SINAN-MALARIA-PRELIMINAR".
1010
#'
1111
#' @param year_start,year_end numeric. Start and end year of files in the format yyyy.
1212
#' @param month_start,month_end Numeric. Start and end month in the format mm. Those parameters are only used with the healh information systems SIH, CNES and SIA. There parameter are ignored if the information health system is SIM or SINASC.
@@ -45,15 +45,15 @@ fetch_datasus <- function(year_start, month_start, year_end, month_end, uf="all"
4545
sisSINASC <- c("SINASC")
4646
sisCNES <- c("CNES-LT", "CNES-ST", "CNES-DC", "CNES-EQ", "CNES-SR", "CNES-HB","CNES-PF","CNES-EP","CNES-RC","CNES-IN","CNES-EE","CNES-EF","CNES-GM")
4747
sisSIA <- c("SIA-AB", "SIA-ABO", "SIA-ACF", "SIA-AD", "SIA-AN", "SIA-AM", "SIA-AQ", "SIA-AR", "SIA-ATD", "SIA-PA", "SIA-PS", "SIA-SAD")
48-
sisSINAN <- c("SINAN-DENGUE-FINAL", "SINAN-DENGUE-PRELIMINAR", "SINAN-CHIKUNGUNYA-FINAL", "SINAN-CHIKUNGUNYA-PRELIMINAR", "SINAN-ZIKA-FINAL", "SINAN-ZIKA-PRELIMINAR")
48+
sisSINAN <- c("SINAN-DENGUE-FINAL", "SINAN-DENGUE-PRELIMINAR", "SINAN-CHIKUNGUNYA-FINAL", "SINAN-CHIKUNGUNYA-PRELIMINAR", "SINAN-ZIKA-FINAL", "SINAN-ZIKA-PRELIMINAR", "SINAN-MALARIA-FINAL", "SINAN-MALARIA-PRELIMINAR")
4949
available_information_system <- c(sisSIH, sisSIM, sisSINASC, sisCNES, sisSIA, sisSINAN)
5050
if(!(information_system %in% available_information_system)) stop("Health informaton system unknown.")
5151

5252
# Create dates for verification
5353
if(substr(information_system,1,3) == "SIH" | substr(information_system,1,4) == "CNES" | substr(information_system,1,3) == "SIA"){
5454
date_start <- as.Date(paste0(year_start,"-",formatC(month_start, width = 2, format = "d", flag = "0"),"-","01"))
5555
date_end <- as.Date(paste0(year_end,"-",formatC(month_end, width = 2, format = "d", flag = "0"),"-","01"))
56-
} else if(substr(information_system,1,3) == "SIM" | information_system == "SINASC" | information_system == "SINAN-DENGUE-FINAL" | information_system == "SINAN-DENGUE-PRELIMINAR" | information_system == "SINAN-CHIKUNGUNYA-FINAL" | information_system == "SINAN-CHIKUNGUNYA-PRELIMINAR" | information_system == "SINAN-ZIKA-FINAL" | information_system == "SINAN-ZIKA-PRELIMINAR"){
56+
} else if(substr(information_system,1,3) == "SIM" | information_system == "SINASC" | information_system == "SINAN-DENGUE-FINAL" | information_system == "SINAN-DENGUE-PRELIMINAR" | information_system == "SINAN-CHIKUNGUNYA-FINAL" | information_system == "SINAN-CHIKUNGUNYA-PRELIMINAR" | information_system == "SINAN-ZIKA-FINAL" | information_system == "SINAN-ZIKA-PRELIMINAR" | information_system == "SINAN-MALARIA-FINAL" | information_system == "SINAN-MALARIA-PRELIMINAR"){
5757
date_start <- as.Date(paste0(year_start,"-01-01"))
5858
date_end <- as.Date(paste0(year_end,"-01-01"))
5959
}
@@ -68,7 +68,7 @@ fetch_datasus <- function(year_start, month_start, year_end, month_end, uf="all"
6868
} else if(substr(information_system,1,3) == "SIM" | information_system == "SINASC"){
6969
dates <- seq(date_start, date_end, by = "year")
7070
dates <- lubridate::year(dates)
71-
} else if(information_system == "SINAN-DENGUE-FINAL" | information_system == "SINAN-DENGUE-PRELIMINAR" | information_system == "SINAN-CHIKUNGUNYA-FINAL" | information_system == "SINAN-CHIKUNGUNYA-PRELIMINAR" | information_system == "SINAN-ZIKA-FINAL" | information_system == "SINAN-ZIKA-PRELIMINAR"){
71+
} else if(information_system == "SINAN-DENGUE-FINAL" | information_system == "SINAN-DENGUE-PRELIMINAR" | information_system == "SINAN-CHIKUNGUNYA-FINAL" | information_system == "SINAN-CHIKUNGUNYA-PRELIMINAR" | information_system == "SINAN-ZIKA-FINAL" | information_system == "SINAN-ZIKA-PRELIMINAR" | information_system == "SINAN-MALARIA-FINAL" | information_system == "SINAN-MALARIA-PRELIMINAR"){
7272
dates <- seq(date_start, date_end, by = "year")
7373
dates <- lubridate::year(dates)
7474
dates <- substr(dates, 3, 4)
@@ -223,6 +223,12 @@ fetch_datasus <- function(year_start, month_start, year_end, month_end, uf="all"
223223
} else if(information_system == "SINAN-ZIKA-PRELIMINAR"){
224224
url <- "ftp://ftp.datasus.gov.br/dissemin/publicos/SINAN/DADOS/PRELIM/"
225225
files_list <- paste0(url,"ZIKA", file_extension)
226+
} else if(information_system == "SINAN-MALARIA-FINAL"){
227+
url <- "ftp://ftp.datasus.gov.br/dissemin/publicos/SINAN/DADOS/FINAIS/"
228+
files_list <- paste0(url,"MALA", file_extension)
229+
} else if(information_system == "SINAN-MALARIA-PRELIMINAR"){
230+
url <- "ftp://ftp.datasus.gov.br/dissemin/publicos/SINAN/DADOS/PRELIM/"
231+
files_list <- paste0(url,"MALA", file_extension)
226232
}
227233

228234
# Dowload files
@@ -244,7 +250,7 @@ fetch_datasus <- function(year_start, month_start, year_end, month_end, uf="all"
244250

245251
# Merge files
246252
if(nrow(partial) > 0){
247-
if(!all(vars %in% names(partial))) stop("One or more variables names are unknow. Typo?")
253+
if(!all(vars %in% names(partial))) stop("One or more variables names are unknown. Typo?")
248254
if(is.null(vars)){
249255
data <- dplyr::bind_rows(data, partial)
250256
} else {

man/fetch_datasus.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)