Learn R Programming

readepi: Read data from health information systems

readepi is an R package for reading data from several health information systems (HIS) and relational database management systems (RDBMS).

readepi currently supports reading data from the followings:

  • RDBMS (Relational Database Management Systems) including MS SQL, MySQL, PostgreSQL, and SQLite 
  • DHIS2: an open source and web-based platform for managing health information
  • SORMAS: an eHealth system for monitoring the spread of infectious diseases and responding to outbreak situations

readepi returns a data frame with the data from the specified system.

readepi is developed by Epiverse-TRACE team at the Medical Research Center, The Gambia unit at London School of Hygiene and Tropical Medicine.

Installation

readepi can be installed from CRAN using

install.packages("readepi")

The latest development version of readepi from GitHub with:

if (!require("pak")) install.packages("pak")
pak::pak("epiverse-trace/readepi")
library(readepi)

Quick start

readepi currently has three main functions that read data from a specified source. While the arguments to these functions are generally similar, some are specific to their data source (see the vignette for more details). The examples below show how to use the package functionalities to import data from a variety of sources.

Reading data from RDBMS

The read_rdbms() function is used to import data from a variety of RDBMS, including MS SQL, MySQL, PostgreSQL, and SQLite. Reading data from a RDBMS requires:

  • A MS SQL driver that is compatible with the version of DBMS of interest. The install drivers vignette vignette describes how to install the appropriate driver for each database management system.

Users can read data from a RDBMS by providing a list with the query parameters of interest or an SQL query (for more information, see the vignette).

# CONNECT TO THE TEST MYSQL SERVER
rdbms_login <- readepi::login(
  from = "mysql-rfam-public.ebi.ac.uk",
  type = "mysql",
  user_name = "rfamro",
  password = "",
  driver_name = "",
  db_name = "Rfam",
  port = 4497
)

# DISPLAY THE LIST OF TABLES FROM A DATABASE OF INTEREST
tables <- readepi::show_tables(login = rdbms_login)

# READING ALL FIELDS AND ALL RECORDS FROM ONE TABLE (`author`) USING AN SQL QUERY
dat <- readepi::read_rdbms(
  login = rdbms_login,
  query = "select * from author"
)

# SELECT FEW COLUMNS FROM ONE TABLE AND LEFT JOIN WITH ANOTHER TABLE
dat <- readepi::read_rdbms(
    login = rdbms_login,
    query = "select author.author_id, author.name,
  family_author.author_id from author left join family_author on
  author.author_id = family_author.author_id"
)

# READING ALL FIELDS AND ALL RECORDS FROM ONE TABLE (`author`) WHERE QUERY PARAMETERS ARE SPECIFIED AS A LIST
dat <- readepi::read_rdbms(
  login = rdbms_login,
  query = list(table = "author", fields = NULL, filter = NULL)
)

Reading data from DHIS2

# CONNECT TO A DHIS2 INSTANCE
dhis2_login <- readepi::login(
  type = "dhis2",
  from = "https://smc.moh.gm/dhis",
  user_name = "test",
  password = "Gambia@123"
)

# IMPORT DATA FROM DHIS2 FOR THE SPECIFIED ORGANISATION UNIT AND PROGRAM IDs
data <- readepi::read_dhis2(
  login = dhis2_login,
  org_unit = "GcLhRNAFppR",
  program = "E5IUQuHg3Mg"
)

Reading data from SORMAS

# 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 (coronavirus) CASES FROM THE TEST SORMAS INSTANCE
covid_cases <- readepi::read_sormas(
  login = sormas_login,
  disease = "coronavirus",
)

Package Vignettes

The vignette of the readepi package contains detailed illustrations about the use of each function and the description of every argument. This can be accessed by typing the command below:

# OPEN THE VIGNETTE WITHIN RSTUDIO
vignette("readepi")

# OPEN THE VIGNETTE IN YOUR WEB BROWSER.
browseVignettes("readepi")

Development

Lifecycle

This package is currently maturing, as defined by the RECON software lifecycle. This means that it can be used in production with the understanding that the interface may still undergo minor changes.

Contributions

Contributions are welcome via pull requests.

Code of Conduct

Please note that the readepi project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Citing this package

citation("readepi")
#> To cite readepi in publications use:
#> 
#>   Karim Mané, Emmanuel Kabuga, Bankolé Ahadzie, Abdoelnaser
#>   Degoot, Nuredin Mohammed, Bubacarr Bah (2025). readepi: Read
#>   Data From Relational Database Management Systems and Health
#>   Information Systems website:
#>   https://epiverse-trace.github.io/readepi/
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Manual{,
#>     title = {Read Data From Health Information Systems},
#>     author = {Karim Mané and Emmanuel Kabuga and Nuredin Mohammed and Bubacarr Bah and Bankolé Ahadzie and Abdoelnaser Degoot},
#>     year = {2025},
#>     url = {https://github.com/epiverse-trace/readepi},
#>   }

Copy Link

Version

Install

install.packages('readepi')

Monthly Downloads

11,946

Version

1.0.4

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Bubacarr Bah

Last Published

January 29th, 2026

Functions in readepi (1.0.4)

login

Establish a connection to the HIS of interest.
read_rdbms

Import data from relational database management systems (RDBMS).
url_check

Check if the value for the base_url argument has a correct structure
sormas_get_api_specification

Download the API specification file from SORMAS
get_org_units

Retrieve DHIS2 organization units, along with their IDs, names, parent IDs, and levels.
sormas_get_cases_data

Get case data from a SORMAS instance
server_make_query

Make an SQL query from a list of query parameters
server_make_sql_expression

Convert R expression into SQL expression
sormas_get_persons_data

Get personal data of cases from a SORMAS instance
lookup_table

Lookup table
sormas_get_diseases

Get the list of disease names from a SORMAS instance
sormas_get_pathogen_data

Get pathogen tests data from SORMAS
get_programs

get all programs from a given specific DHIS2 instance
request_parameters

Request parameters
server_fetch_data

Fetch all or specific rows and columns from a table
show_tables

Display the list of tables in a database
server_make_subsetting_query

Create a subsetting query
read_sormas

Import data from SORMAS
sormas_get_data_dictionary

Download SORMAS data dictionary
read_dhis2

Import data from DHIS2
sormas_get_contact_data

Get contact data from SORMAS
get_entity_attributes

Get the attribute names and ids of the tracked entities
get_api_version

Get DHIS2 API version
get_data_elements

Get all data elements from a specific DHIS2 instance
dhis2_login

Establish connection to a DHIS2 instance
get_program_stages

Get program stages for one or more DHSI2 programs
get_tracked_entities

Get tracked entity attributes, their corresponding IDs and event IDs
get_organisation_units

Get the organization units from a specific DHIS2 instance
get_program_org_units

Get organisation units that are associated with a given program
query_check

Check whether the user-provided query is valid
check_program

Validate and retrieve program IDs
fields_check

Check whether the user-specified fields are valid
get_org_unit_levels

Extract the DHSI2 organization unit's hierarchical levels.
get_event_ids

Get event IDs for specific tracked entity
convert_to_date

Convert numeric values into POSIXct,then into Date
check_org_unit

Validate user-specified organisation unit ID or name.
get_entity_data

Get tracked entity attributes
get_event_data

Get event data from the newer DHIS2 versions (version >= 2.41)
get_request_params

Get the request query parameters for a specific API version
get_org_unit_as_long

Transform the organisation units data frame from large to long format