### Example: process_sinan_leishmaniose_tegumentar on sample data Source: https://rfsaldanha.github.io/microdatasus/reference/process_sinan_leishmaniose_tegumentar.html Example call using the sample dataset sinan_leishmaniose_tegumentar_sample. The output shows a tibble with 100 rows and 79 columns, where supported codes are replaced with descriptive values. ```R process_sinan_leishmaniose_tegumentar(sinan_leishmaniose_tegumentar_sample) #> # A tibble: 100 × 79 #> TP_NOT ID_AGRAVO DT_NOTIFIC SEM_NOT NU_ANO SG_UF_NOT ID_MUNICIP ID_REGIONA #> #> 1 Individu… B551 2023-09-21 202338 2023 Espírito… 320265 NA #> 2 Individu… B551 2023-07-19 202329 2023 Espírito… 320115 NA #> 3 Individu… B551 2023-03-17 202311 2023 Espírito… 320450 NA #> 4 Individu… B551 2023-02-17 202307 2023 Espírito… 320370 NA #> 5 Individu… B551 2023-12-26 202352 2023 Espírito… 320450 NA #> 6 Individu… B551 2023-10-11 202341 2023 Espírito… 320450 NA #> 7 Individu… B551 2023-09-25 202339 2023 Espírito… 320313 NA #> 8 Individu… B551 2023-07-25 202330 2023 Espírito… 320360 NA #> 9 Individu… B551 2023-02-02 202305 2023 Espírito… 320450 NA #> 10 Individu… B551 2023-05-11 202319 2023 Espírito… 320450 NA #> # ℹ 90 more rows #> # ℹ 71 more variables: ID_UNIDADE , DT_DIAG , SEM_DIAG , #> # ANO_NASC , NU_IDADE_N , CS_SEXO , CS_GESTANT , #> # CS_RACA , CS_ESCOL_N , SG_UF , ID_MN_RESI , #> # ID_RG_RESI , ID_PAIS , NDUPLIC_N , DT_DIGITA , #> # DT_TRANSUS , DT_TRANSDM , DT_TRANSSM , DT_TRANSRM , #> # DT_TRANSRS , DT_TRANSSE , NU_LOTE_V , NU_LOTE_H , … ``` -------------------------------- ### fetch_datasus() examples for SIM-DO and SIH-RD Source: https://rfsaldanha.github.io/microdatasus/reference/fetch_datasus.html Example usage of fetch_datasus() for SIM-DO and SIH-RD systems. The first call downloads SIM-DO data for Acre in 2014 with selected columns; the second downloads SIH-RD data for Acre and Roraima from January to February 2014. The example is wrapped in if (FALSE) to avoid execution during package checks. ```r if (FALSE) { # interactive() && curl::has_internet() sim <- fetch_datasus( year_start = 2014, year_end = 2014, uf = "AC", information_system = "SIM-DO", vars = c("CODMUNRES", "DTOBITO", "CAUSABAS") ) sih <- fetch_datasus( year_start = 2014, month_start = 1, year_end = 2014, month_end = 2, uf = c("AC", "RR"), information_system = "SIH-RD" ) } ``` -------------------------------- ### Install microdatasus from GitHub Source: https://rfsaldanha.github.io/microdatasus/index.html Install the development version of the microdatasus package using the remotes package. ```R install.packages("remotes") remotes::install_github("rfsaldanha/microdatasus", ref = "dev") ``` -------------------------------- ### Example of process_sinasc with sample data Source: https://rfsaldanha.github.io/microdatasus/reference/process_sinasc.html Demonstrates the output of processing a SINASC sample dataset. ```R process_sinasc(sinasc_sample) #> # A tibble: 100 × 69 #> contador ORIGEM CODESTAB CODMUNNASC LOCNASC IDADEMAE ESTCIVMAE ESCMAE #> #> 1 1 1 5618347 110020 Hospital 29 União consensual 4 a 7… #> 2 2 1 5618347 110020 Hospital 14 União consensual 4 a 7… #> 3 3 1 4001303 110020 Hospital 30 Casada 4 a 7… #> 4 4 1 5618347 110020 Hospital 23 Solteira 8 a 1… #> 5 5 1 5618347 110020 Hospital 30 Casada 8 a 1… #> 6 6 1 3970442 110020 Hospital 25 União consensual 8 a 1… #> 7 7 1 5701929 120001 Hospital 21 União consensual 1 a 3… #> 8 8 1 5701929 120001 Hospital 16 União consensual 8 a 1… #> 9 9 1 5701929 120001 Hospital 25 NA 8 a 1… #> 10 10 1 5701929 120001 Hospital 25 Solteira 4 a 7… #> # ℹ 90 more rows #> # ℹ 61 more variables: QTDFILVIVO , QTDFILMORT , CODMUNRES , #> # GESTACAO , GRAVIDEZ , PARTO , CONSULTAS , DTNASC , #> # HORANASC , SEXO , APGAR1 , APGAR5 , RACACOR , #> # PESO , IDANOMAL , DTCADASTRO , CODANOMAL , #> # NUMEROLOTE , VERSAOSIST , DTRECEBIM , DIFDATA , #> # DTRECORIGA , NATURALMAE , CODMUNNATU , CODUFNATU , … ``` -------------------------------- ### process_sim example: recode sim_do_sample Source: https://rfsaldanha.github.io/microdatasus/reference/process_sim.html Example call to process_sim() on the sim_do_sample dataset. The output is a tibble with 100 rows and 101 columns, showing recoded values such as 'Não Fetal' for TIPOBITO and 'Masc…'/'Femi…' for SEXO. The displayed output is truncated with 90 more rows and 92 more variables. ```r process_sim(sim_do_sample) #> # A tibble: 100 × 101 #> CONTADOR ORIGEM TIPOBITO DTOBITO HORAOBITO CODMUNNATU DTNASC IDADE SEXO #> #> 1 1 1 Não Fetal 2016-01-01 NA 120033 1988-1… 427 Masc… #> 2 2 1 Não Fetal 2016-01-01 NA 120030 2002-1… 413 Femi… #> 3 3 1 Não Fetal 2016-01-01 NA 120030 1985-1… 430 Masc… #> 4 4 1 Não Fetal 2016-01-01 2100 NA 1959-1… 456 Masc… #> 5 5 1 Não Fetal 2016-01-01 2050 120040 2014-1… 401 Femi… #> 6 6 1 Não Fetal 2016-01-01 2040 120050 1974-0… 441 Masc… #> 7 7 1 Não Fetal 2016-01-01 0530 120040 1970-0… 445 Masc… #> 8 8 1 Não Fetal 2016-01-01 0230 130350 1978-0… 437 Masc… #> 9 9 1 Não Fetal 2016-01-01 0600 120040 1989-0… 426 Masc… #> 10 10 1 Não Fetal 2016-01-01 0450 120060 1958-0… 457 Femi… #> # ℹ 90 more rows #> # ℹ 92 more variables: RACACOR , ESTCIV , ESC , ESC2010 , #> # SERIESCFAL , CODMUNRES , LOCOCOR , CODESTAB , #> # ESTABDESCR , CODMUNOCOR , IDADEMAE , ESCMAE , #> # ESCMAE2010 , SERIESCMAE , QTDFILVIVO , QTDFILMORT , #> # GRAVIDEZ , SEMAGESTAC , GESTACAO , PARTO , #> # OBITOPARTO , PESO , TPMORTEOCO , OBITOGRAV , … ``` -------------------------------- ### process_sih() example with output Source: https://rfsaldanha.github.io/microdatasus/reference/process_sih.html Example call processing the sample data frame sih_rd_sample, followed by the resulting tibble output. The output shows the first 10 rows and 121 columns, with character columns and municipality data added. ```r process_sih(sih_rd_sample) ``` ```r #> # A tibble: 100 × 121 #> UF_ZI ANO_CMPT MES_CMPT ESPEC CGC_HOSP N_AIH IDENT CEP MUNIC_RES NASC #> #> 1 120000 2016 6 03 04034526001… 1216… Prin… 6994… 120050 1934… #> 2 120000 2016 6 03 04034526001… 1216… Prin… 6994… 120050 1982… #> 3 120000 2016 6 03 04034526001… 1216… Prin… 6994… 120050 1973… #> 4 120000 2016 6 03 04034526001… 1216… Prin… 6994… 120050 1938… #> 5 120000 2016 6 03 04034526001… 1216… Prin… 6994… 120050 1943… #> 6 120000 2016 6 03 04034526001… 1216… Prin… 6994… 120050 1947… #> 7 120000 2016 6 01 04034526002… 1216… Prin… 6998… 120020 2006… #> 8 120000 2016 6 01 04034526002… 1216… Prin… 6998… 120020 1978… #> 9 120000 2016 6 02 04034526001… 1216… Prin… 6994… 120050 1993… #> 10 120000 2016 6 02 04034526001… 1216… Prin… 6994… 120050 1992… #> # ℹ 90 more rows #> # ℹ 111 more variables: SEXO , UTI_MES_IN , UTI_MES_AN , #> # UTI_MES_AL , UTI_MES_TO , MARCA_UTI , UTI_INT_IN , #> # UTI_INT_AN , UTI_INT_AL , UTI_INT_TO , DIAR_ACOM , #> # QT_DIARIAS , PROC_SOLIC , PROC_REA , VAL_SH , #> # VAL_SP , VAL_SADT , VAL_RN , VAL_ACOMP , #> # VAL_ORTP , VAL_SANGUE , VAL_SADTSR , VAL_TRANSP , … ``` -------------------------------- ### Process CNES-ST establishment sample Source: https://rfsaldanha.github.io/microdatasus/reference/process_cnes.html Example call using the cnes_st_sample dataset with information_system = "CNES-ST". The output is a tibble with 100 rows and 209 columns, showing recoded values and added municipality data. ```r process_cnes(cnes_st_sample, information_system = "CNES-ST") #> # A tibble: 100 × 209 #> CNES CODUFMUN COD_CEP CPF_CNPJ PF_PJ NIV_DEP CNPJ_MAN COD_IR REGSAUDE #> #> 1 2002043 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 2 2002159 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 3 3006166 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 4 3382745 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 5 3393984 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 6 3638685 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 7 5403669 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 8 5701929 120001 69945000 00000000000… Pess… Mantida 4034526… NA NA #> 9 6514669 120001 69945000 00000000000… Pess… Mantida 8430673… NA NA #> 10 7026641 120001 69945000 00000000000… Pess… Mantida 4034526… NA NA #> # ℹ 90 more rows #> # ℹ 200 more variables: MICR_REG , DISTRSAN , DISTRADM , #> # VINC_SUS , TPGESTAO , ESFERA_A , RETENCAO , #> # ATIVIDAD , NATUREZA , CLIENTEL , TP_UNID , #> # TURNO_AT , NIV_HIER , TP_PREST , CO_BANCO , #> # CO_AGENC , C_CORREN , CONTRATM , DT_PUBLM , #> # CONTRATE , DT_PUBLE , ALVARA , DT_EXPED , … ``` -------------------------------- ### Process CNES-PF professional sample Source: https://rfsaldanha.github.io/microdatasus/reference/process_cnes.html Example call using the cnes_pf_sample dataset with information_system = "CNES-PF". The output is a tibble with 100 rows and 48 columns, showing the different layout for professional records. ```r process_cnes(cnes_pf_sample, information_system = "CNES-PF") #> # A tibble: 100 × 48 #> CNES CODUFMUN REGSAUDE MICR_REG DISTRSAN DISTRADM TPGESTAO PF_PJ CPF_CNPJ #> #> 1 2002043 120001 NA NA NA NA Municipal Pess… 0 #> 2 2002159 120001 NA NA NA NA Municipal Pess… 0 #> 3 3006166 120001 NA NA NA NA Municipal Pess… 0 #> 4 3006166 120001 NA NA NA NA Municipal Pess… 0 #> 5 3006166 120001 NA NA NA NA Municipal Pess… 0 #> 6 3006166 120001 NA NA NA NA Municipal Pess… 0 #> 7 3006166 120001 NA NA NA NA Municipal Pess… 0 #> 8 3006166 120001 NA NA NA NA Municipal Pess… 0 #> 9 3006166 120001 NA NA NA NA Municipal Pess… 0 #> 10 3006166 120001 NA NA NA NA Municipal Pess… 0 #> # ℹ 90 more rows #> # ℹ 39 more variables: NIV_DEP , CNPJ_MAN , ESFERA_A , #> # ATIVIDAD , RETENCAO , NATUREZA , CLIENTEL , #> # TP_UNID , TURNO_AT , NIV_HIER , TERCEIRO , #> # CPFUNICO , CBO , CBOUNICO , NOMEPROF , CNS_PROF , #> # CONSELHO , REGISTRO , VINCULAC , VINCUL_C , #> # VINCUL_A , VINCUL_N , PROF_SUS , PROFNSUS , … ``` -------------------------------- ### process_sinan_malaria() example with sample data Source: https://rfsaldanha.github.io/microdatasus/reference/process_sinan_malaria.html Example call to `process_sinan_malaria()` on the sample dataset `sinan_malaria_sample`. The output is a tibble with 100 rows and 55 columns, all character type, with recoded descriptive values for supported fields. ```r process_sinan_malaria(sinan_malaria_sample) #> # A tibble: 100 × 55 #> TP_NOT ID_AGRAVO DT_NOTIFIC SEM_NOT NU_ANO SG_UF_NOT ID_MUNICIP ID_REGIONA #> #> 1 Individu… B54 2016-01-01 201552 2016 São Paulo 355030 1331 #> 2 Individu… B54 2016-01-02 201552 2016 Bahia 292740 1380 #> 3 Individu… B54 2016-01-02 201552 2016 Bahia 291072 1388 #> 4 Individu… B54 2016-01-02 201552 2016 Espírito… 320130 1510 #> 5 Individu… B54 2016-01-02 201552 2016 Bahia 292860 1380 #> 6 Individu… B54 2016-01-03 201601 2016 Paraíba 250750 1377 #> 7 Individu… B54 2016-01-04 201601 2016 Paraná 410830 1363 #> 8 Individu… B54 2016-01-04 201601 2016 Goiás 520870 1779 #> 9 Individu… B54 2016-01-04 201601 2016 Rio Gran… 430510 1608 #> 10 Individu… B54 2016-01-04 201601 2016 São Paulo 350950 1342 #> # ℹ 90 more rows #> # ℹ 47 more variables: ID_UNIDADE , DT_SIN_PRI , SEM_PRI , #> # ANO_NASC , NU_IDADE_N , CS_SEXO , CS_GESTANT , #> # CS_RACA , CS_ESCOL_N , SG_UF , ID_MN_RESI , #> # ID_RG_RESI , ID_PAIS , DT_INVEST , ID_OCUPA_N , #> # CLASSI_FIN , AT_ATIVIDA , AT_LAMINA , AT_SINTOMA , #> # TPAUTOCTO , COUFINF , COPAISINF , COMUNINF , … ``` -------------------------------- ### Example: process_sinan_dengue(sinan_dengue_sample) with output Source: https://rfsaldanha.github.io/microdatasus/reference/process_sinan_dengue.html Example call to `process_sinan_dengue()` on the sample dataset `sinan_dengue_sample`. The output is a tibble with 100 rows and 79 columns, showing recoded values such as "Individu…" for TP_NOT and "Pernambu…" for SG_UF_NOT. The remaining columns are character vectors, as indicated by the `` type annotations. ```r process_sinan_dengue(sinan_dengue_sample) #> # A tibble: 100 × 79 #> TP_NOT ID_AGRAVO DT_NOTIFIC SEM_NOT NU_ANO SG_UF_NOT ID_MUNICIP ID_REGIONA #> #> 1 Individu… A90 2010-01-26 201004 2010 Pernambu… 260190 1499 #> 2 Individu… A90 2010-01-26 201004 2010 Rio de J… 330455 NA #> 3 Individu… A90 2010-01-11 201002 2010 Tocantins 170950 NA #> 4 Individu… A90 2010-01-22 201003 2010 Tocantins 170950 NA #> 5 Individu… A90 2010-01-25 201004 2010 Minas Ge… 314330 1473 #> 6 Individu… A90 2010-01-25 201004 2010 Minas Ge… 314330 1473 #> 7 Individu… A90 2010-01-29 201004 2010 Minas Ge… 314330 1473 #> 8 Individu… A90 2010-01-21 201003 2010 Minas Ge… 314330 1473 #> 9 Individu… A90 2010-01-25 201004 2010 Minas Ge… 314330 1473 #> 10 Individu… A90 2010-01-25 201004 2010 Minas Ge… 314330 1473 #> # ℹ 90 more rows #> # ℹ 71 more variables: ID_UNIDADE , DT_SIN_PRI , SEM_PRI , #> # NU_IDADE_N , CS_SEXO , CS_GESTANT , CS_RACA , #> # CS_ESCOL_N , SG_UF , ID_MN_RESI , ID_RG_RESI , #> # ID_PAIS , NDUPLIC_N , DT_DIGITA , CS_FLXRET , #> # FLXRECEBI , MIGRADO_W , DT_INVEST , ID_OCUPA_N , #> # DT_SORO , RESUL_SORO , DT_NS1 , RESUL_NS1 , … ``` -------------------------------- ### Install stable version from CRAN Source: https://rfsaldanha.github.io/microdatasus/index.html Use this command to install the stable release of the microdatasus package from the CRAN repository. ```R install.packages("microdatasus") ``` -------------------------------- ### process_sinan_chagas() example with output Source: https://rfsaldanha.github.io/microdatasus/reference/process_sinan_chagas.html Example usage of process_sinan_chagas() on the sample dataset sinan_chagas_sample. The output is a tibble with 100 rows and 113 columns, showing recoded values such as 'Individu…' for TP_NOT and 'B571' for ID_AGRAVO, with many columns truncated in the display. ```r process_sinan_chagas(sinan_chagas_sample) #> # A tibble: 100 × 113 #> TP_NOT ID_AGRAVO DT_NOTIFIC SEM_NOT NU_ANO SG_UF_NOT ID_MUNICIP ID_REGIONA #> #> 1 Individu… B571 2023-05-05 202318 2023 Bahia 292740 1380 #> 2 Individu… B571 2023-11-30 202348 2023 Pará 150210 1496 #> 3 Individu… B571 2023-03-07 202310 2023 Pará 150150 1484 #> 4 Individu… B571 2023-02-28 202309 2023 Pará 150140 1484 #> 5 Individu… B571 2023-06-12 202324 2023 Pará 150140 1484 #> 6 Individu… B571 2023-03-28 202313 2023 Pará 150210 1496 #> 7 Individu… B571 2023-07-03 202327 2023 Pará 150442 1484 #> 8 Individu… B571 2023-10-03 202340 2023 Rio de J… 330455 NA #> 9 Individu… B571 2023-01-31 202305 2023 Pará 150210 1496 #> 10 Individu… B571 2023-07-02 202327 2023 Ceará 231290 1521 #> # ℹ 90 more rows #> # ℹ 105 more variables: ID_UNIDADE , DT_SIN_PRI , SEM_PRI , #> # ANO_NASC , NU_IDADE_N , CS_SEXO , CS_GESTANT , #> # CS_RACA , CS_ESCOL_N , SG_UF , ID_MN_RESI , #> # ID_RG_RESI , ID_PAIS , NDUPLIC_N , DT_INVEST , #> # ID_OCUPA_N , ANT_UF_1 , MUN_1 , ANT_UF_2 , MUN_2 , #> # ANT_UF_3 , MUN_3 , PRESENCA , PARASITO , … ``` -------------------------------- ### fetch_datasus annual query for SIM-DO Source: https://rfsaldanha.github.io/microdatasus/articles/download-e-rastreabilidade.html Use for annual systems (SIM, SINASC, SINAN) where only years are required. The example fetches SIM-DO data for Acre from 2020 to 2022. Note that SIM-DO and SINASC files are organized by UF; special SIM subsets and SINAN diseases are national and ignore the uf argument with a warning. ```r sim_raw <- fetch_datasus( year_start = 2020, year_end = 2022, uf = "AC", information_system = "SIM-DO" ) ``` -------------------------------- ### Example: process_sinan_leishmaniose_visceral on sample data Source: https://rfsaldanha.github.io/microdatasus/reference/process_sinan_leishmaniose_visceral.html Example usage of `process_sinan_leishmaniose_visceral()` on the sample dataset `sinan_leishmaniose_visceral_sample`. The output is a tibble with 100 rows and 81 columns, showing recoded values such as 'Individu…' for TP_NOT and state names like 'Rondônia' and 'Maranhão'. The tibble contains character columns, and the output is truncated with 90 more rows and 73 more variables. ```r process_sinan_leishmaniose_visceral(sinan_leishmaniose_visceral_sample) #> # A tibble: 100 × 81 #> TP_NOT ID_AGRAVO DT_NOTIFIC SEM_NOT NU_ANO SG_UF_NOT ID_MUNICIP ID_REGIONA #> #> 1 Individu… B550 2023-09-06 202336 2023 Rondônia 110028 1482 #> 2 Individu… B550 2023-01-06 202301 2023 Maranhão 210530 1440 #> 3 Individu… B550 2023-05-08 202319 2023 Maranhão 210530 1440 #> 4 Individu… B550 2023-06-09 202323 2023 Maranhão 210530 1440 #> 5 Individu… B550 2023-07-04 202327 2023 Maranhão 210530 1440 #> 6 Individu… B550 2023-04-12 202315 2023 Roraima 140010 NA #> 7 Individu… B550 2023-04-05 202314 2023 Roraima 140010 NA #> 8 Individu… B550 2023-07-24 202330 2023 Minas Ge… 316860 1465 #> 9 Individu… B550 2023-01-29 202305 2023 Roraima 140010 NA #> 10 Individu… B550 2023-02-12 202307 2023 Roraima 140040 NA #> # ℹ 90 more rows #> # ℹ 73 more variables: ID_UNIDADE , DT_SIN_PRI , SEM_PRI , #> # ANO_NASC , NU_IDADE_N , CS_SEXO , CS_GESTANT , #> # CS_RACA , CS_ESCOL_N , SG_UF , ID_MN_RESI , #> # ID_RG_RESI , ID_PAIS , NDUPLIC_N , DT_DIGITA , #> # CS_FLXRET , FLXRECEBI , MIGRADO_W , DT_INVEST , #> # ID_OCUPA_N , FEBRE , FRAQUEZA , EDEMA , EMAGRA , … ``` -------------------------------- ### process_sinan_zika() example with sinan_zika_sample Source: https://rfsaldanha.github.io/microdatasus/reference/process_sinan_zika.html Example call to `process_sinan_zika()` using the built-in `sinan_zika_sample` dataset. The output is a tibble with 100 rows and 43 columns, showing recoded values such as 'Individu…' for `TP_NOT` and 'Tocantins' for `SG_UF_NOT`. The tibble includes many additional character columns (e.g., `ID_REGIONA`, `DT_SIN_PRI`, `SEM_PRI`) that are not shown in the preview. ```r process_sinan_zika(sinan_zika_sample) #> # A tibble: 100 × 43 #> TP_NOT ID_AGRAVO CS_SUSPEIT DT_NOTIFIC SEM_NOT NU_ANO SG_UF_NOT ID_MUNICIP #> #> 1 Individu… A928 NA 2016-01-01 201552 2016 Tocantins 170230 #> 2 Individu… A928 NA 2016-01-01 201552 2016 Bahia 292040 #> 3 Individu… A928 NA 2016-01-01 201552 2016 Bahia 292040 #> 4 Individu… A928 NA 2016-01-01 201552 2016 Bahia 293240 #> 5 Individu… A928 NA 2016-01-01 201552 2016 Espírito… 320530 #> 6 Individu… A928 NA 2016-01-01 201552 2016 Espírito… 320530 #> 7 Individu… A928 NA 2016-01-01 201552 2016 Espírito… 320530 #> 8 Individu… A928 NA 2016-01-01 201552 2016 Espírito… 320530 #> 9 Individu… A928 NA 2016-01-01 201552 2016 Pará 150613 #> 10 Individu… A928 NA 2016-01-01 201552 2016 Pará 150613 #> # ℹ 90 more rows #> # ℹ 35 more variables: ID_REGIONA , DT_SIN_PRI , SEM_PRI , #> # NU_IDADE_N , CS_SEXO , CS_GESTANT , CS_RACA , #> # CS_ESCOL_N , SG_UF , ID_MN_RESI , ID_RG_RESI , #> # ID_PAIS , NDUPLIC_N , IN_VINCULA , DT_INVEST , #> # ID_OCUPA_N , CLASSI_FIN , CRITERIO , TPAUTOCTO , #> # COUFINF , COPAISINF , COMUNINF , DOENCA_TRA , … ``` -------------------------------- ### Handle partial success with stop_on_error = FALSE Source: https://rfsaldanha.github.io/microdatasus/articles/download-e-rastreabilidade.html With `stop_on_error = FALSE`, valid files are used and failures are collected into a single diagnostic. The return is `NULL` when no file can be obtained, so always check before processing or persisting; the example shows the required `if (!is.null(dados))` guard before calling `process_sih()`. ```R dados <- fetch_datasus( year_start = 2023, month_start = 1, year_end = 2023, month_end = 12, uf = c("AC", "RO"), information_system = "SIH-RD", stop_on_error = FALSE ) ``` ```R if (!is.null(dados)) { dados <- process_sih(dados) } ``` -------------------------------- ### Baixar múltiplas UFs com fetch_datasus Source: https://rfsaldanha.github.io/microdatasus/articles/FAQ.html Baixa dados de múltiplas UFs em uma única chamada. Use `uf = "all"` para todas as UFs, mas não combine com códigos individuais. Em sistemas nacionais como SINAN, `uf` é ignorado com alerta; filtre a variável territorial depois do download. ```r dados <- fetch_datasus( year_start = 2023, month_start = 1, year_end = 2023, month_end = 1, uf = c("AC", "RO", "AM"), information_system = "CNES-ST" ) ``` -------------------------------- ### fetch_datasus com track_source = TRUE Source: https://rfsaldanha.github.io/microdatasus/articles/FAQ.html Usa track_source = TRUE para adicionar a coluna source indicando o arquivo de origem de cada linha. A coluna é preservada quando vars é usado e não sobrescreve uma coluna source já existente no DBC. ```R dados <- fetch_datasus( year_start = 2023, month_start = 1, year_end = 2023, month_end = 2, uf = c("AC", "RO"), information_system = "SIH-RD", track_source = TRUE ) unique(dados$source) ``` -------------------------------- ### Converter colunas após process_sim() Source: https://rfsaldanha.github.io/microdatasus/articles/FAQ.html Converte colunas processadas para os tipos necessários após process_sim(). As funções process_*() retornam um tibble de colunas character; converta somente o que a análise exige, depois de inspecionar códigos especiais, ausências e mudanças de layout. ```R sim <- process_sim(sim_raw) sim$DTOBITO <- as.Date(sim$DTOBITO) sim$IDADEanos <- as.integer(sim$IDADEanos) ``` -------------------------------- ### Ler DBC com tipos inferidos (as_character = FALSE) Source: https://rfsaldanha.github.io/microdatasus/articles/FAQ.html Lê um arquivo DBC mantendo os tipos inferidos do DBF. Use `as_character = FALSE` para preservar os tipos originais. ```r dados <- read_dbc("arquivo.dbc", as_character = FALSE) ``` -------------------------------- ### Fluxo básico: baixar e processar SIM-DO com conversão de data Source: https://rfsaldanha.github.io/microdatasus/articles/exemplos.html Exemplo do fluxo básico: baixa dados de mortalidade (SIM-DO) do Acre em 2022, processa com process_sim() e converte a coluna DTOBITO para Date. Inclui o argumento track_source = TRUE. ```R sim_raw <- fetch_datasus( year_start = 2022, year_end = 2022, uf = "AC", information_system = "SIM-DO", vars = c("CODMUNRES", "DTOBITO", "CAUSABAS"), track_source = TRUE ) sim <- process_sim(sim_raw) sim$DTOBITO <- as.Date(sim$DTOBITO) ``` -------------------------------- ### Download and process CNES professionals (CNES-PF) Source: https://rfsaldanha.github.io/microdatasus/articles/exemplos.html Downloads CNES-PF data for Pará (PA) in October 2021 and processes it with the default nomes parameter. This example is for professionals data. ```R cnes_pf_raw <- fetch_datasus( year_start = 2021, month_start = 10, year_end = 2021, month_end = 10, uf = "PA", information_system = "CNES-PF" ) cnes_pf <- process_cnes( cnes_pf_raw, information_system = "CNES-PF" ) ``` -------------------------------- ### fetch_datasus com stop_on_error = FALSE Source: https://rfsaldanha.github.io/microdatasus/articles/FAQ.html Chama fetch_datasus com stop_on_error = FALSE (padrão) para retornar arquivos válidos e resumir falhas ao final. Se nenhum arquivo for lido, o retorno é NULL, e o exemplo verifica isso com is.null(). ```R dados <- fetch_datasus( year_start = 2023, month_start = 1, year_end = 2023, month_end = 12, uf = c("AC", "RO"), information_system = "SIH-RD", stop_on_error = FALSE ) if (is.null(dados)) { message("Nenhum arquivo foi obtido.") } ``` -------------------------------- ### fetch_datasus monthly query for SIH-RD Source: https://rfsaldanha.github.io/microdatasus/articles/download-e-rastreabilidade.html Use for monthly systems (SIH, SIA, CNES) where both month_start and month_end are required, even for a single month. The example fetches SIH-RD data for Minas Gerais from December 2023 to February 2024. The interval can cross years. ```r sih_raw <- fetch_datasus( year_start = 2023, month_start = 12, year_end = 2024, month_end = 2, uf = "MG", information_system = "SIH-RD" ) ``` -------------------------------- ### All UFs selection in fetch_datasus Source: https://rfsaldanha.github.io/microdatasus/articles/download-e-rastreabilidade.html Selects all UFs. Cannot be combined with individual UFs. Broad requests may consume significant network, memory, and time; prefer batching for large volumes. ```r uf = "all" ``` -------------------------------- ### Fetch and process SIM data Source: https://rfsaldanha.github.io/microdatasus/index.html Download SIM-DO data for a specific year and state, then process it. ```R library(microdatasus) sim_raw <- fetch_datasus( year_start = 2022, year_end = 2022, uf = "AC", information_system = "SIM-DO", vars = c("CODMUNRES", "DTOBITO", "CAUSABAS"), track_source = TRUE ) sim <- process_sim(sim_raw) ```