Icon

DATASUS - Import DBC Files - Convert into DBF and Parquet

<p>Use KNIME, R (read.dbc) to import DBC (compressed DBF) from DATASUS (Department of Informatics of Brazilian Health System)</p><p><br>https://forum.knime.com/t/automated-download-of-a-series-of-files-from-the-same-server/88326/8?u=mlauber71</p><p><br>----<br>KNIME and R — installation across operating systems — some remarks<br>https://medium.com/p/6494a2a498cc<br><br>KNIME and Python — Setting up and managing Conda environments<br>https://medium.com/p/2ac217792539</p>

URL: read.dbc - An R package for reading data in the DBC (compressed DBF) format used by DATASUS https://github.com/danicat/read.dbc
URL: HUB: Import DBF (dBase) file with the help of R's foreign library or Python packages https://hub.knime.com/-/spaces/-/latest/~SDBFAcbXIzJLn9XA/
URL: Medium: KNIME and R — installation across operating systems — some remarks https://medium.com/p/6494a2a498cc
URL: Medium: KNIME and Python — Setting up and managing Conda environments https://medium.com/p/2ac217792539
URL: HUB: Use KNIME, R (read.dbc) and Python (dbfread) to import DBC (compressed DBF) from DATASUS (Department of Informatics of Brazilian Health System) https://hub.knime.com/-/spaces/-/latest/~VkImhhmw7SwUKo5b/
URL: forum entry https://forum.knime.com/t/widget-to-upload-multiple-files/69854/6?u=mlauber71
URL: KNIME Forum (88326) - DATASUS Download solution by hmfa https://forum.knime.com/t/automated-download-of-a-series-of-files-from-the-same-server/88326/5?u=mlauber71
URL: r_test / packages / r-read.dbc https://anaconda.org/r_test/r-read.dbc

Annotations and comments
  • install.packages("devtools") install.packages("roxygen2") devtools::check() install.packages("read.dbc") # if this does not work you can install from the GitHub page directly # https://github.com/danicat/read.dbc devtools::install_github("danicat/read.dbc")
  • Use KNIME, R (read.dbc) and Python (dbfread) to import DBC (compressed DBF) from DATASUS (Department of Informatics of Brazilian Health System) https://forum.knime.com/t/automated-download-of-a-series-of-files-from-the-same-server/88326/8?u=mlauber71
  • # read.dbc - An R package for reading data in the DBC (compressed DBF) format used by DATASUS # https://github.com/danicat/read.dbc # install.packages("read.dbc") library("read.dbc") v_dbc_file_path <- knime.flow.in[["v_dbc_file"]] v_dbf_file_path <- knime.flow.in[["v_dbf_file"]] # The call return logi = TRUE on success if( dbc2dbf(input.file = v_dbc_file_path , output.file = v_dbf_file_path) ) { print("File decompressed!") } knime.out <- data.frame("v_dbc_file_path" = v_dbc_file_path, "v_dbf_file_path" = v_dbf_file_path)
  • # Load the 'foreign' package to read legacy DBF (dBase/FoxPro) files library(foreign) # Load the 'arrow' package to write data in Parquet format library(arrow) # Read the DBF file from the path provided by the KNIME flow variable 'v_dbf_file' # The result is a data.frame stored in 'knime.out', which is the expected output object for KNIME R Script nodes knime.out <- read.dbf(knime.flow.in[["v_dbf_file"]]) # Write the data.frame to a Parquet file at the path provided by the KNIME flow variable 'v_parquet_file' # This does not affect the KNIME output directly; it's just writing a file to disk write_parquet(knime.out, knime.flow.in[["v_parquet_file"]])
  • DATASUS (https://datasus.saude.gov.br/) is the name of the Department of Informatics of Brazilian Health System. It is the agency resposible for publishing Brazilian public healthcare data. Besides DATASUS, the Brazilian National Agency for Supplementary Health (ANS) also uses this file format for its public data.
  • context.workflow.parent-path
  • path.separator.system length_parent_path= length(column("context.workflow.parent-path")) substr(column("context.workflow.parent-path"), length_parent_path-1, 1)
  • => paths
  • create /data/ folder if it does not exist
  • context.workflow.absolute-path context.workflow.path context.workflow.name
  • context.workflow.data-path
  • data-path
  • path variables
  • py3_knime
  • v_dbf_file
  • v_parquet_file
  • v_table_file
  • v_dbc_file
  • ../dbc_compressed/ *.dbc
  • ../data/PARS2112.parquet => check if Parquet file Export has worked
  • library(foreign) knime.out <- read.dbf(knime.flow.in[["v_dbf_file"]])
  • library("read.dbc")
  • path
  • start loop
  • end loop

Nodes

Extensions

Links