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

# 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"]])


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

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.

KNIME and R — installation across operating systems — some remarks
https://medium.com/p/6494a2a498cc

KNIME and Python — Setting up and managing Conda environments
https://medium.com/p/2ac217792539


# 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)


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")

locate and create /data/ folder with absolute paths
Collect Local Metadata
../dbc_compressed/*.dbc
List Files/Folders
URL to File Path
Path to URI
Table Row to Variable
v_table_file
Java Snippet (simple)
v_table_file
Table Writer
v_parquet_file
Java Snippet (simple)
../data/PARS2112.parquet=> check if Parquet file Export has worked
Parquet Reader
start loop
Table Row to Variable Loop Start
path
String to Path (Variable)
v_dbf_file
Java Snippet (simple)
library(foreign) knime.out <- read.dbf(knime.flow.in[["v_dbf_file"]])
R Source (Table)
end loop
Variable Loop End
v_dbc_file
Java Snippet (simple)
library("read.dbc")
R Source (Table)

Nodes

Extensions

Links