Read case data

Last updated on 2026-10-27 | Edit this page

Overview

Questions

  • Where do you usually store outbreak data?
  • What data formats do you commonly use for analysis?
  • Can you import data directly from servers and health information systems?

Objectives

  • Identify common sources of outbreak data.
  • Import outbreak data from multiple formats into R environment.
  • Access and retrieve data from remote servers and health information systems using APIs.
Prerequisite

Prerequisites

This episode requires you to be familiar with Data science: Basic tasks with R.

Introduction


The first step in outbreak analysis is importing your dataset into the R environment. Data can come from local sources, like files on your computer, or external sources, like databases and health information systems (HIS).

Outbreak data takes many forms. It may be sorted as a flat file in various formats, housed in relational database management systems (RDBMS), or managed through specialized HIS like SORMAS and DHIS2. These HISs offer application programming interfaces (APIs) that allow authorized users to modify and retrieve data entries efficiently, making them particularly valuable for large-scale institutional health data collection and storage.

This episode demonstrates how to read case data from each of these sources. Let’s begin by loading the packages we’ll need. We will use rio to read data stored in files and readepi to access data from RDBMS and HIS. We will also load here to locate file paths within your project directory, and tidyverse, which includes magrittr (providing the pipe operator %>%) and dplyr (for data manipulation). The pipe operator allows us to chain functions together seamlessly.

R

# Load packages
library(tidyverse) # for {dplyr} functions and the pipe %>%
library(rio) # for importing data from files
library(here) # for easy file referencing
library(readepi) # for importing data directly from RDBMS or HIS
library(dbplyr) # for a database backend for {dplyr}
Checklist

The double-colon (::) operator

The double-colon :: in R lets you call a specific function from a package without loading the entire package. For example, dplyr::filter(data, condition) uses the filter() function from the dplyr package, without requiring library(dplyr).

This notation serves two purposes: it makes code more readable by explicitly showing which package each function comes from, and it prevents namespace conflicts that occur when multiple packages contain functions with the same name.

Prerequisite

Setup a project and folder

Reading from files


Several packages are available for importing outbreak data stored in individual files into R. These include {rio}, {readr} from the tidyverse, {io}, {ImportExport}, and {data.table}. Together, these packages offer methods to read single or multiple files in a wide range of formats.

The below example shows how to import a csv file into R environment using the rio package. We use the here package to tell R to look for the file in the data/ folder of your project, and dplyr::as_tibble() to convert into a tidier format for subsequent analysis in R.

R

# read data
# e.g., if the path to our file is "data/raw-data/ebola_cases_2.csv" then:
ebola_confirmed <- rio::import(
  here::here("data", "raw-data", "ebola_cases_2.csv")
) %>%
  dplyr::as_tibble() # for a simple data frame output

# preview data
ebola_confirmed

OUTPUT

# A tibble: 120 × 4
    year month   day confirm
   <int> <int> <int>   <int>
 1  2014     5    18       1
 2  2014     5    20       2
 3  2014     5    21       4
 4  2014     5    22       6
 5  2014     5    23       1
 6  2014     5    24       2
 7  2014     5    26      10
 8  2014     5    27       8
 9  2014     5    28       2
10  2014     5    29      12
# ℹ 110 more rows

You can use the same approach to import other file formats such as tsv, xlsx, and more.

Checklist

Why should we use the {here} package?

The here package is designed to simplify file referencing in R projects by providing a reliable way to construct file paths relative to the project root. The main reason to use is for cross-environment compatibility.

It works across different operating systems (Windows, Mac, Linux) without needing to adjust file paths.

  • On Windows, paths are written using backslashes ( \ ) as the separator between folder names: "data\raw-data\file.csv" .
  • On Unix based operating systems such as macOS or Linux the forward slash ( / ) is used as the path separator: "data/raw-data/file.csv".

The here package reinforces the reproducibility of your work across multiple operating systems. If you are interested in reproducibility, we invite you to read this tutorial to increase the openess, sustainability, and reproducibility of your epidemic analysis with R

Challenge

Reading compressed data

Can you read data from a compressed file in R?

Download this zip file containing Marburg outbreak data and then import it to your R environment.

You can check the full list of supported file formats in the rio package on the package website. To see the list of supported formats in rio, run:

R

rio::install_formats()

R

rio::import(here::here("data", "Marburg.zip"))

Reading from databases


The readepi library contains functions that allow you to import data directly from RDBMS. The readepi::read_rdbms() function supports importing data from servers such as Microsoft SQL, MySQL, PostgreSQL, and SQLite. It build on the {DBI} package, which provides a general interface for interacting RDBMS.

Discussion

Advantages of reading data directly from a database?

Importing data directly from a database optimizes the memory usage in the R session. By processing the database with “queries” (e.g., SELECT, FILTER, GROUP BY) before extraction, you reduce the memory load in our RStudio session. In contrast, loading an entire dataset into R for manipulation can consume more RAM than your local machine can handle, potentially causing RStudio to slow down or freeze.

RDBMS also enable multiple users to access, store, and analyze parts of the dataset simultaneously without transferring individual files. This eliminates the version control problems that arise when multiple file copies circulate among users.

1. Connect with a database

You can use the readepi::login() function to establish a connection to the database, as shown below:

R

# establish the connection to a test MySQL database
rdbms_login <- readepi::login(
  from = "genome-mysql.soe.ucsc.edu",
  type = "MySQL",
  user_name = "genome",
  password = "",
  driver_name = "",
  db_name = "hgFixed",
  port = 3306
)

OUTPUT

✔ Logged in successfully!

R

rdbms_login

OUTPUT

<Pool> of MySQLConnection objects
  Objects checked out: 0
  Available in pool: 1
  Max size: Inf
  Valid: TRUE

The function parameters are:

  • from: The database server address (genome-mysql.soe.ucsc.edu)
  • type: The type of database system (“MySQL”)
  • user_name: The username for authentication (“genome”)
  • password: The password (empty string “” indicates no password required for this public test database)
  • driver_name: The database driver (empty string uses the default driver)
  • db_name: The specific database to connect to (“hgFixed”)
  • port: The port number for the connection (3306)

The function returns a connection object stored in variable rdbms_login, which can then be used to query and retrieve data from the database.

Callout

Note: This example uses a public test database from the University of California, Santa Cruz (UCSC) Genome Browser project, which is why no password is required. It uses the standard MySQL port (3306), so it is less likely to be blocked than test servers on non-standard ports, but access could still be limited by strict organizational network restrictions.

2. Access the list of tables from the database

The readepi::show_tables() function retrieves the full list of table names from a database:

R

# get the table names
tables <- readepi::show_tables(login = rdbms_login)

tables[1:5]

OUTPUT

[1] "affy10KDetails"  "affy120KDetails" "affyExps"        "affyGenoDetails"
[5] "arbFlyLifeAll"  

In a relational database, you typically have multiple tables. Each table represents a specific entity (e.g., patients, care units, treatments). Tables are linked through common identifiers called primary keys or foreign keys.

3. Read data from a table in a database

You can read the data from the author table using dplyr::tbl(). This table lists authors of GenBank sequence submissions, with each name stored as "LastName,F.I.".

R

# import data from the 'author' table using an SQL query
dat <- rdbms_login %>%
  dplyr::tbl(from = "author") %>%
  dplyr::filter(stringr::str_sub(string = name, start = 1, end = 1) == "A") %>%
  dplyr::slice_sample(n = 20) %>% 
  dplyr::arrange(desc(id))

dat

OUTPUT

# A query:    ?? x 3
# Database:   mysql 5.5.5-10.11.8-MariaDB [@genome-mysql.soe.ucsc.edu:/hgFixed]
# Ordered by: desc(id)
       id name                                                               crc
    <int> <chr>                                                            <dbl>
 1 336399 Ali H, AbdelMageed M, Olsson L, Israelsson A, Lindmark G, Hamm… 8.68e8
 2 330710 Alakoski T, Ulvila J, Yrjola R, Vainio L, Magga J, Szabo Z, Li… 2.47e8
 3 328385 Ajogbasile,F.V., Oguzie,J.U., Oluniyi,P.E., Eromon,P.E., Uwani… 2.39e9
 4 309405 Abeln M, Borst KM, Cajic S, Thiesler H, Kats E, Albers I, Kuhn… 9.99e8
 5 282733 Atef ME and Anand-Srivastava MB.                                2.98e9
 6 281458 Archambaud C, Nahori MA, Soubigou G, Becavin C, Laval L, Lecha… 1.32e9
 7 279821 Adler E, Hoon MA, Mueller KL, Chandrashekar J, Ryba NJ and Zuk… 6.00e8
 8 270046 Aizenberg-Gershtein,Y., Laviad,S., Samuni-Blank,M. and Halpern… 2.39e9
 9 216764 Abe,S., Miyamoto,K. and Sasaki,E.                               2.75e9
10 216220 Ahsan,M.N., Aoki,H. and Watabe,S.                               3.82e9
11 192242 Arauz,D., De Urriola,L., Jones,J., Castillo,M., Martinez,A., M… 2.75e9
12 142821 Andersson,U., Antonicka,H., Houstek,J. and Cannon,B.            1.67e9
13 133296 Anderson,R.A. and Sando,G.N.                                    2.40e9
14 114792 Aarts,W.M., Willemze,R., Bende,R.J., Meijer,C.J., Pals,S.T. an… 1.63e9
15  99026 Aza-Gonzalez,C., Herrera-Isidron,L., Nunes-Palenius,H.G., Mart… 3.25e9
16  64950 Asada,A., Kusakawa,T., Orii,H., Watanabe,K. and Tsubaki,M.      2.40e9
17  61824 Akerblom,I.E.                                                   1.68e9
18  46733 Ahmed,A., Arshad,M., Malik,A., Parveen,S. and Alsenaidy,A.M.    2.50e9
19  25785 Adam,M.A.M., Phillips,M.S., Jones,J.T. and Blok,V.C.            3.82e9
20  23395 Arca,B., Lombardo,F., Lanfrancotti,A., Spanos,L., Veneri,M., L… 2.39e9

When you apply dplyr verbs to this database table, they are automatically translated into SQL queries:

R

# Show the SQL queries translated
dat %>%
  dplyr::show_query()

OUTPUT

<SQL>
SELECT `id`, `name`, `crc`
FROM (
  SELECT
    *,
    CASE
WHEN (NOT(((RAND()) IS NULL))) THEN ROW_NUMBER() OVER (PARTITION BY (CASE WHEN (((RAND()) IS NULL)) THEN 1 ELSE 0 END) ORDER BY RAND())
END AS `col01`
  FROM `author`
  WHERE (SUBSTR(`name`, 1, 1) = 'A')
) AS `q01`
WHERE (`col01` <= 20)
ORDER BY `id` DESC

Alternatively, you can use the readepi::read_rdbms() function to import data from a database table. It accepts either an SQL query or a list of query parameters.

4. Extract data from the database

Use dplyr::collect() to force computation of a database query and extract the output to your local computer.

R

# Pull all data down to a local tibble
dat %>%
  dplyr::collect()

OUTPUT

# A tibble: 20 × 3
       id name                                                               crc
    <int> <chr>                                                            <dbl>
 1 359121 Amirfallah A, Arason A, Einarsson H, Gudmundsdottir ET, Freyst… 1.37e9
 2 357812 ANDERSON,D.G., WESSELHOEFT,R.A. and KOWALSKI,P.S.               2.78e9
 3 348634 Alleboina S, Ayalew D, Peravali R, Chen L, Wong T and Dokun AO. 1.14e9
 4 336506 Antunes LCM, Cartell A, de Farias CB, Bakos RM, Roesler R and … 1.24e9
 5 335333 Alici,E.                                                        1.65e6
 6 274535 Ashida H, Hong Y, Murakami Y, Shishioh N, Sugimoto N, Kim YU, … 3.95e9
 7 245111 Aquea,F. and Arce-Johnson,P.                                    1.49e9
 8 229181 Adams,M.E., Minamide,L.S., Duester,G. and Bamburg,J.R.          3.91e9
 9 218329 Asch,W.S., Leake,D., Canger,A.K., Passini,M.A., Argenton,F. an… 3.98e9
10 213167 Amarilla,A.A., de Almeida,F.T., Jorge,D.M., Alfonso,H.L., de C… 9.80e8
11 165415 Abe,K.                                                          9.96e4
12 148173 Abarca-Heidemann,K.                                             2.07e9
13 114715 Adams,J.C. and Zhang,L.                                         2.83e9
14  76824 Alonso,J.M., Chamarro,J. and Granell,A.                         2.39e9
15  75226 Aalen,R.B., Opsahl-Ferstad,H.G., Linnestad,C. and Olsen,O.A.    2.40e9
16  72078 Ashrafi,M., Azimi Moqadam,M.R., Moradi,P., Shekari,F. and Mohs… 4.24e8
17  63896 Adams,J.M., Cory,S. and Spahr,P.F.                              2.40e9
18  55727 Appella,D.H., Micklitsch,C., Yemane,B. and Zhao,C.              1.18e9
19  42590 Ager,E.I., Cowing,J., Rodger,J. and Hunt,D.M.                   1.67e9
20  38510 Ambagala,A.P., Feng,Z., Barletta,R.G. and Srikumaran,S.         3.09e9

Ideally, after specifying a set of queries, we can reduce the size of the input dataset to use in the environment of our R session.

Challenge

Run SQL queries in R using {dbplyr}

Create one table containing:

  • the column name from table author,
  • the column acc from table gbCdnaInfo, and
  • using the author’s id as primary key or common identifier.

Following these steps:

  • Use dplyr verbs to select column and join tables,
  • Print the relational database SQL queries, and
  • Pull out data to your local session.

Join columns from two different tables:

  • From the table author, select id and name, keeping only a handful of rows (e.g. authors whose surname starts with "A") — gbCdnaInfo covers every GenBank submission ever made, so narrowing author down first keeps the join fast.
  • From the table gbCdnaInfo, select author (the foreign key to author$id) and acc.
  • Join to the table author the table gbCdnaInfo using dplyr::left_join(), matching author$id to gbCdnaInfo$author — note the join columns have different names, so you’ll need by = c("id" = "author") rather than relying on a shared column name.
  • Print the SQL query using dplyr::show_query()
  • collect the joined output using dplyr::collect()

R

# SELECT FEW COLUMNS FROM ONE TABLE AND LEFT JOIN WITH ANOTHER TABLE
author <- rdbms_login %>%
  dplyr::tbl(from = "author") %>%
  dplyr::filter(stringr::str_sub(string = name, start = 1, end = 1) == "A") %>%
  dplyr::slice_sample(n = 5) %>%
  dplyr::select(id, name)

gb_cdna_info <- rdbms_login %>%
  dplyr::tbl(from = "gbCdnaInfo") %>%
  dplyr::select(author, acc)

dplyr::left_join(
  x = author,
  y = gb_cdna_info,
  by = c("id" = "author"),
  keep = TRUE
) %>%
  dplyr::show_query()

OUTPUT

<SQL>
SELECT `LHS`.*, `author`, `acc`
FROM (
  SELECT `id`, `name`
  FROM (
    SELECT
      *,
      CASE
WHEN (NOT(((RAND()) IS NULL))) THEN ROW_NUMBER() OVER (PARTITION BY (CASE WHEN (((RAND()) IS NULL)) THEN 1 ELSE 0 END) ORDER BY RAND())
END AS `col01`
    FROM `author`
    WHERE (SUBSTR(`name`, 1, 1) = 'A')
  ) AS `q01`
  WHERE (`col01` <= 5)
) AS `LHS`
LEFT JOIN `gbCdnaInfo`
  ON (`LHS`.`id` = `gbCdnaInfo`.`author`)

R

dplyr::left_join(
  x = author,
  y = gb_cdna_info,
  by = c("id" = "author"),
  keep = TRUE
) %>%
  dplyr::collect()

OUTPUT

# A tibble: 146 × 4
       id name                                                      author acc
    <int> <chr>                                                      <dbl> <chr>
 1 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 2 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 3 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 4 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 5 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 6 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 7 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 8 210433 Arankalle,V.A., Shrivastava,S., Cherian,S., Gunjikar,R.S… 210433 EF02…
 9  41988 Aschenbach,J.R., Steglich,K., Honscha,K.U. and Gabel,G.    41988 FJ20…
10  41988 Aschenbach,J.R., Steglich,K., Honscha,K.U. and Gabel,G.    41988 FJ20…
# ℹ 136 more rows

You can also review the dbplyr R package. But for a step-by-step tutorial about SQL, we recommend you this tutorial about data management with SQL for Ecologist.

We can close the connection to the database with:

R

pool::poolClose(rdbms_login)

You can confirm the connection closed running the created objects in console:

R

rdbms_login

OUTPUT

<Pool> of MySQLConnection objects
  Objects checked out: 0
  Available in pool: 0
  Max size: Inf
  Valid: FALSE

R

dat

ERROR

Error in `poolCheckout()` at pool/R/pool-methods.R:136:3:
! The pool has been closed.

Reading from HIS APIs


Health data is increasingly stored in specialized HIS such as Fingertips, GoData, REDCap, DHIS2, SORMAS, etc. The current version of the readepi library allows importing data from DHIS2 and SORMAS. The subsections below demonstrate how to import data from these two systems.

Importing data from DHIS2

DHIS2 (District Health Information System 2) is an open-source software that has revolutionized global health information management. The readepi::read_dhis2() function imports data from the DHIS2 Tracker system via its API.

To successfully import data from DHIS2, you need to:

  1. Connect to the system using the readepi::login() function
  2. Provide the name or ID of the target program and organization unit

You can retrieve the IDs and names of available programs and organization units using the get_programs() and get_organisation_units() functions, respectively.

R

# establish the connection to the system
dhis2_login <- readepi::login(
  type = "dhis2",
  from = "https://play.im.dhis2.org/stable-2-42-6",
  user_name = "admin",
  password = "district"
)

ERROR

Error in `httr2::req_perform()` at readepi/R/read_dhis2-helpers.R:57:3:
! HTTP 404 Not Found.

R

dhis2_login

OUTPUT

function(base_url,
                        user_name,
                        password) {
  target_url <- file.path(base_url, "api", "me")
  resp <- httr2::request(target_url) |>
    httr2::req_auth_basic(user_name, password) |>
    httr2::req_perform()
  cli::cli_alert_success("Logged in successfully!")
  return(invisible(resp))
}
<bytecode: 0x55876b61c830>
<environment: namespace:readepi>

If the step above fails, check for others available in the list of DHIS2 Demo Instances, all accessible with username "admin" and password "district". Just replace stable-2-42-6 in the URL string. The only conditions is that it must be of version equal or lower than 2.42.

Caution

Avoid publishing your USER NAME and PASSWORD. You could use rstudioapi:

R

dhis2_login <- readepi::login(
  type = "dhis2",
  from = "https://play.im.dhis2.org/stable-2-42-6",
  user_name = rstudioapi::askForPassword("Database username"),
  password = rstudioapi::askForPassword("Database password")
)

Your can read further from this blogpost on How to Avoid Publishing Credentials in Your Code

R

# get the names and IDs of the programs
programs <- readepi::get_programs(login = dhis2_login)

ERROR

Error in `login[["url"]]`:
! object of type 'closure' is not subsettable

R

# print tables
tibble::as_tibble(programs)

ERROR

Error:
! object 'programs' not found

R

# get the names and IDs of the organisation units
org_units <- readepi::get_organisation_units(login = dhis2_login)

ERROR

Error in `login[["url"]]`:
! object of type 'closure' is not subsettable

R

# print tables
tibble::as_tibble(org_units)

ERROR

Error:
! object 'org_units' not found

After retrieving organization units and program names from the DHIS2 database, we can import data using either names or coded IDs, as demonstrated in the code chunks below:

R

# import data from DHIS2 using names
data_name <- readepi::read_dhis2(
  login = dhis2_login,
  org_unit = "Bucksal Clinic",
  program = "Child Programme"
)

ERROR

Error in `readepi::read_dhis2()`:
! Assertion on 'login' failed: Must inherit from class 'httr2_response', but has class 'function'.

R

tibble::as_tibble(data_name)

ERROR

Error:
! object 'data_name' not found

R

# import data from DHIS2 using IDs
data_id <- readepi::read_dhis2(
  login = dhis2_login,
  org_unit = "vRC0stJ5y9Q",
  program = "IpHINAT79UW"
)

ERROR

Error in `readepi::read_dhis2()`:
! Assertion on 'login' failed: Must inherit from class 'httr2_response', but has class 'function'.

R

identical(data_id, data_name)

ERROR

Error:
! object 'data_id' not found

Note that not all organization units are registered for a specific program. To find which organization units are running a particular program, use the get_program_org_units() function as shown below:

R

# get the list of organisation units that run the program "IpHINAT79UW"
target_org_units <- readepi::get_program_org_units(
  login = dhis2_login,
  program = "IpHINAT79UW",
  org_units = org_units
)

ERROR

Error in `login[["url"]]`:
! object of type 'closure' is not subsettable

R

tibble::as_tibble(target_org_units)

ERROR

Error:
! object 'target_org_units' not found
Challenge

Reading from a DHIS2 sever

Test readepi by accessing to a DHIS2 server with your credentials.

Do the following:

  • Log into a different server,
  • List all available programs and organization units,
  • Read data from one of these programs,
  • Optional: Reproduce one descriptive figure.

Try using rstudioapi::askForPassword() for user_name and password.

If you get errors, please fill an issue in the readepi GitHub repository.

Importing data from SORMAS

The SORMAS (Surveillance Outbreak Response Management and Analysis System) is an open-source e-health system that optimizes infectious disease surveillance and outbreak response processes. The readepi::read_sormas() function allows you to import data from SORMAS via its API.

In the current version of the readepi package, the read_sormas() function returns data for the following columns: case_id, person_id, sex, date_of_birth, case_origin, country, city, lat, long, case_status, date_onset, date_admission, date_last_contact, date_first_contact, outcome, date_outcome, and Ct_values.

The code chunk below demonstrates how to import data from a demo SORMAS system:

R

# CONNECT TO THE SORMAS SYSTEM
sormas_login <- readepi::login(
  type = "sormas",
  from = "https://demo.sormas.org/sormas-rest",
  user_name = "SurvSup",
  password = "Lk5R7JXeZSEc"
)

# FETCH ALL COVID (Corona virus) CASES FROM THE TEST SORMAS INSTANCE
covid_cases <- readepi::read_sormas(
  login = sormas_login,
  disease = "coronavirus",
)
tibble::as_tibble(covid_cases)

OUTPUT

# A tibble: 3 × 15
  case_id             person_id date_onset case_origin case_status outcome sex
  <chr>               <chr>     <date>     <chr>       <chr>       <chr>   <chr>
1 TYG7I3-2GONYO-JDJP… QJXOUU-6… NA         IN_COUNTRY  SUSPECT     NO_OUT… <NA>
2 ULMPMT-PBQOQ2-ETGY… WVP6NB-J… 2026-05-31 IN_COUNTRY  NOT_CLASSI… NO_OUT… <NA>
3 W3RLN3-LNPNMV-ETUQ… R6HELZ-O… NA         IN_COUNTRY  NOT_CLASSI… NO_OUT… <NA>
# ℹ 8 more variables: date_of_birth <chr>, country <chr>, city <chr>,
#   latitude <chr>, longitude <chr>, contact_id <chr>,
#   date_last_contact <date>, Ct_values <chr>

A key parameter is the disease name. To ensure correct syntax, you can retrieve the list of available disease names using the sormas_get_diseases() function.

R

# get the list of all disease names
disease_names <- readepi::sormas_get_diseases(
  login = sormas_login
)

tibble::as_tibble(disease_names)

OUTPUT

# A tibble: 69 × 2
   disease            active
   <chr>              <chr>
 1 AFP                TRUE
 2 CHOLERA            TRUE
 3 CONGENITAL_RUBELLA TRUE
 4 DENGUE             TRUE
 5 EVD                TRUE
 6 GUINEA_WORM        TRUE
 7 LASSA              TRUE
 8 MONKEYPOX          TRUE
 9 NEW_INFLUENZA      TRUE
10 PLAGUE             TRUE
# ℹ 59 more rows
Challenge

Reading from Demo SORMAS sever

Log into this server, list all available diseases, and import cases related to the monkeypox (mpox) disease.

R

# establish the connection to the system
sormas_demo <- readepi::login(
  type = "sormas",
  from = "https://demo.sormas.org/sormas-rest",
  user_name = "SurvSup",
  password = "Lk5R7JXeZSEc"
)

# List the names of all disease
demo_diseases <- readepi::sormas_get_diseases(login = sormas_demo)
tibble::as_tibble(demo_diseases)

OUTPUT

# A tibble: 69 × 2
   disease            active
   <chr>              <chr>
 1 AFP                TRUE
 2 CHOLERA            TRUE
 3 CONGENITAL_RUBELLA TRUE
 4 DENGUE             TRUE
 5 EVD                TRUE
 6 GUINEA_WORM        TRUE
 7 LASSA              TRUE
 8 MONKEYPOX          TRUE
 9 NEW_INFLUENZA      TRUE
10 PLAGUE             TRUE
# ℹ 59 more rows

R

# get the list of all disease names
mpox_cases <- readepi::read_sormas(
  login = sormas_demo,
  disease = "monkeypox",
)

WARNING

Warning in as.POSIXct(as.numeric(x), origin = "1970-01-01"): NAs introduced by
coercion

R

tibble::as_tibble(mpox_cases)

OUTPUT

# A tibble: 1 × 15
  case_id             person_id date_onset case_origin case_status outcome sex
  <chr>               <chr>     <date>     <chr>       <chr>       <chr>   <chr>
1 TU75PT-MMBE3I-OEJN… XQFYXH-R… NA         IN_COUNTRY  NOT_CLASSI… NO_OUT… <NA>
# ℹ 8 more variables: date_of_birth <chr>, country <chr>, city <chr>,
#   latitude <chr>, longitude <chr>, contact_id <chr>,
#   date_last_contact <date>, Ct_values <chr>
Key Points
  • Use rio, io, readr or {ImportExport} to read data from individual files.
  • Use readepi to read data from RDBMS and HIS.
  • The {rio} package supports a wide range of file formats including CSV, TSV, XLSX, and compressed files.
  • Use readepi::login() to establish connections to RDBMS, DHIS2, or SORMAS systems.
  • The readepi package currently supports importing data from DHIS2 and SORMAS health information systems.