| Title: | Read Data from Relational Database Management Systems and Health Information Systems |
|---|---|
| Description: | Import Data from Relational Database Management Systems (RDBMS) and Health Information Systems ('HIS'). The current version of the package supports importing data from RDBMS including 'MS SQL', 'MySQL', 'PostGRESQL', and 'SQLite', as well as from two HIS platforms: 'DHIS2' and 'SORMAS'. |
| Authors: | Karim Mané [aut] (ORCID: <https://orcid.org/0000-0002-9892-2999>), Emmanuel Kabuga [aut] (ORCID: <https://orcid.org/0009-0006-2291-709X>), Bubacarr Bah [aut, cre] (ORCID: <https://orcid.org/0000-0003-3318-6668>), Bankolé Ahadzie [ctb], Nuredin Mohammed [ctb], Abdoelnaser Degoot [ctb], Hugo Gruson [rev] (ORCID: <https://orcid.org/0000-0002-4094-1476>), Pratik Gupte [rev] (ORCID: <https://orcid.org/0000-0001-5294-7819>), Andree Valle-Campos [rev] (ORCID: <https://orcid.org/0000-0002-7779-481X>), London School of Hygiene and Tropical Medicine, LSHTM [cph], data.org [fnd] |
| Maintainer: | Bubacarr Bah <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.6 |
| Built: | 2026-05-23 09:06:59 UTC |
| Source: | https://github.com/epiverse-trace/readepi |
Establish connection to a DHIS2 instance
dhis2_login(base_url, user_name, password)dhis2_login(base_url, user_name, password)
base_url |
A character with the base URL of the target DHIS2 instance |
user_name |
A character with the user name |
password |
A character with the user's password |
An httr2_response object if the connection was successfully
established
## Not run: dhis2_log <- dhis2_login( base_url = "https://play.im.dhis2.org/stable-2-42-1", user_name = "admin", password = "district" ) ## End(Not run)## Not run: dhis2_log <- dhis2_login( base_url = "https://play.im.dhis2.org/stable-2-42-1", user_name = "admin", password = "district" ) ## End(Not run)
Get DHIS2 API version
get_api_version(login)get_api_version(login)
login |
A httr2_response object returned by the |
A numeric with minor version of the API
## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # get the API version api_version <- get_api_version(login = dhis2_login) ## End(Not run)## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # get the API version api_version <- get_api_version(login = dhis2_login) ## End(Not run)
Get all data elements from a specific DHIS2 instance
get_data_elements(login)get_data_elements(login)
login |
A httr2_response object returned by the |
A data frame with the following two columns: the data elements IDs and their corresponding names.
## Not run: # establish the connection to the system dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # retrieve the data elements data_elements <- get_data_elements(login = dhis2_login) ## End(Not run)## Not run: # establish the connection to the system dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # retrieve the data elements data_elements <- get_data_elements(login = dhis2_login) ## End(Not run)
Retrieves all organisational reporting units and their levels, then builds a hierarchy for each unit by tracing its ancestries from the deepest level up to the root.
get_organisation_units(login)get_organisation_units(login)
login |
A httr2_response object returned by the |
Fetches all organisation units via the get_org_units() function,
Fetches all organisational unit levels via the get_org_unit_levels()
function,
Filters for organisational units at the deepest level,
Traces the parent hierarchy of each deepest unit up to the root,
Constructs a tabular structure where each row is a full lineage.
A data frame where each row represents a full hierarchy for the last-level unit by keeping the hierarchical organizational unit's name and ID at each level, using the official level names provided by the DHIS2 instance like "Country Name", "Country ID", etc.
## Not run: # establish the connection to the system dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # fetch the organisation units org_units <- get_organisation_units(login = dhis2_login) ## End(Not run)## Not run: # establish the connection to the system dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # fetch the organisation units org_units <- get_organisation_units(login = dhis2_login) ## End(Not run)
Get organisation units that are associated with a given program
get_program_org_units(login, program, org_units = NULL)get_program_org_units(login, program, org_units = NULL)
login |
A httr2_response object returned by the |
program |
A character with the program ID or name |
org_units |
A data frame with all organisation units from target DHIS2
instance. This is the output from the |
A data frame with the organisation units associated with the provided program
## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # fetch the organisation units org_units <- get_organisation_units(login = dhis2_login) # get the organisation units associated with the following program 'E5IUQuHg3Mg' target_org_units <- get_program_org_units( login = dhis2_login, program = "E5IUQuHg3Mg", org_units = org_units ) ## End(Not run)## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # fetch the organisation units org_units <- get_organisation_units(login = dhis2_login) # get the organisation units associated with the following program 'E5IUQuHg3Mg' target_org_units <- get_program_org_units( login = dhis2_login, program = "E5IUQuHg3Mg", org_units = org_units ) ## End(Not run)
Retrieves the stages associated with specified DHIS2 program IDs, or all programs if none are specified. If any of the supplied program names or IDs are not found, the function displays a message and proceeds with the valid ones.
get_program_stages(login, programs = NULL, program = NULL)get_program_stages(login, programs = NULL, program = NULL)
login |
A httr2_response object returned by the |
programs |
A data frame with the program IDs and names obtained from the
|
program |
A character with the program ID or name |
A data frame with the following columns:
program_id: the unique ID of the program
program_name: the displayed name of the program
program_stage_name: the name of each stage associate with the program
program_stage_id: the ID of each program stage
## Not run: # establish the connection to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # get the list of all program stages from the DHIS2 instance all_program_stages <- get_program_stages( login = dhis2_login, program = "E5IUQuHg3Mg", programs = NULL ) ## End(Not run)## Not run: # establish the connection to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # get the list of all program stages from the DHIS2 instance all_program_stages <- get_program_stages( login = dhis2_login, program = "E5IUQuHg3Mg", programs = NULL ) ## End(Not run)
The function first fetches all programs from the DHIS2 Aggregate system, then distinguishes the Tracker and Aggregate programs.
get_programs(login)get_programs(login)
login |
A httr2_response object returned by the |
A data frame with the following columns: the program ID, the program name, and the program type specifying whether the program is part of the Aggregate or Tracker system.
## Not run: # establish the connection to the system dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # fetch the programs programs <- get_programs(login = dhis2_login) ## End(Not run)## Not run: # establish the connection to the system dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # fetch the programs programs <- get_programs(login = dhis2_login) ## End(Not run)
Get tracked entity attributes, their corresponding IDs and event IDs
get_tracked_entities(login, api_version, org_unit, program, org_units)get_tracked_entities(login, api_version, org_unit, program, org_units)
login |
A httr2_response object returned by the |
api_version |
A numeric with the API version obtained from the
|
org_unit |
A character with the organisation unit ID or name |
program |
A character with the program ID or name |
org_units |
A data frame with all organisation units from target DHIS2
instance. This is the output from the |
A data frame with the tracked entity attributes alongside their events and tracked entity IDs
## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # set the program and org unit IDs program <- "E5IUQuHg3Mg" org_unit <- "GcLhRNAFppR" # get the api version api_version <- get_api_version(login = dhis2_login) # get all the organisation units from the DHIS2 instance org_units <- get_organisation_units(login = dhis2_login) # get the tracked entity attributes tracked_entity_attributes <- get_tracked_entities( login = dhis2_login, api_version = api_version, org_unit = org_unit, program = program, org_units = org_units ) ## End(Not run)## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) # set the program and org unit IDs program <- "E5IUQuHg3Mg" org_unit <- "GcLhRNAFppR" # get the api version api_version <- get_api_version(login = dhis2_login) # get all the organisation units from the DHIS2 instance org_units <- get_organisation_units(login = dhis2_login) # get the tracked entity attributes tracked_entity_attributes <- get_tracked_entities( login = dhis2_login, api_version = api_version, org_unit = org_unit, program = program, org_units = org_units ) ## End(Not run)
The current version of the package supports basic authentication (using the username and password) and personal authentication key (using API key and bearer token).
login( from, type, user_name = NULL, password = NULL, driver_name = NULL, db_name = NULL, port = NULL )login( from, type, user_name = NULL, password = NULL, driver_name = NULL, db_name = NULL, port = NULL )
from |
The URL to the HIS of interest. For APIs, this must be the base URL (required). |
type |
The source name (required). The current version of the package covers the following RDBMS and HIS types: "ms sql", "mysql", "postgresql", "sqlite", "dhis2", and "sormas". |
user_name |
The user name (optional). |
password |
The user's password (optional). When the password is not
provided (set to |
driver_name |
The driver name (optional). This is only needed for connecting to RDBMS only. |
db_name |
The database name (optional). This is only needed for connecting to RDBMS only. |
port |
The port ID (optional). This is only needed for connecting to RDBMS only. |
A connection object
# connect to the test MySQL server ## Not run: login <- login( from = "mysql-rfam-public.ebi.ac.uk", type = "mysql", user_name = "rfamro", password = "", driver_name = "", db_name = "Rfam", port = 4497 ) ## End(Not run) # connect to a DHIS2 instance ## Not run: dhi2s_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) ## End(Not run) # connect to SORMAS ## Not run: sormas_login <- login( type = "sormas", from = "https://demo.sormas.org/sormas-rest", user_name = "SurvSup", password = "Lk5R7JXeZSEc" ) ## End(Not run)# connect to the test MySQL server ## Not run: login <- login( from = "mysql-rfam-public.ebi.ac.uk", type = "mysql", user_name = "rfamro", password = "", driver_name = "", db_name = "Rfam", port = 4497 ) ## End(Not run) # connect to a DHIS2 instance ## Not run: dhi2s_login <- login( type = "dhis2", from = "https://smc.moh.gm/dhis", user_name = "test", password = "Gambia@123" ) ## End(Not run) # connect to SORMAS ## Not run: sormas_login <- login( type = "sormas", from = "https://demo.sormas.org/sormas-rest", user_name = "SurvSup", password = "Lk5R7JXeZSEc" ) ## End(Not run)
The lookup table is used to establish the correspondence between R operators, provided in an expression, and the DHIS2 or SQL operators.
lookup_tablelookup_table
A data frame of 11 rows and 3 columns
Import data from DHIS2
read_dhis2(login, org_unit, program)read_dhis2(login, org_unit, program)
login |
A httr2_response object returned by the |
org_unit |
A character with the organisation unit ID or name |
program |
A character with the program ID or name |
A data frame that contains both the tracked entity attributes and their event data.
## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://play.im.dhis2.org/stable-2-42-1", user_name = "admin", password = "district" ) org_unit <- "DiszpKrYNg8" program <- "IpHINAT79UW" # fetch the data from specific program an unit data <- read_dhis2( login = dhis2_login, org_unit = org_unit, program = program ) ## End(Not run)## Not run: # login to the DHIS2 instance dhis2_login <- login( type = "dhis2", from = "https://play.im.dhis2.org/stable-2-42-1", user_name = "admin", password = "district" ) org_unit <- "DiszpKrYNg8" program <- "IpHINAT79UW" # fetch the data from specific program an unit data <- read_dhis2( login = dhis2_login, org_unit = org_unit, program = program ) ## End(Not run)
The function assumes the user has read access to the database.
Importing data from RDBMS requires the installation of the appropriate
driver that is compatible with the server version hosting the database.
For more details, see the
Installing drivers on
how to install the driver.
read_rdbms(login, query)read_rdbms(login, query)
login |
The connection object obtained from the |
query |
An SQL query or a list with the following elements:
|
A data.frame with the requested data as specified in the query
argument.
## Not run: # establish the connection to the database rdbms_login <- login( from = "mysql-rfam-public.ebi.ac.uk", type = "mysql", user_name = "rfamro", password = "", driver_name = "", db_name = "Rfam", port = 4497 ) # import data where query parameters are specified as a list authors_list <- read_rdbms( login = rdbms_login, query = list(table = "author", fields = NULL, filter = NULL) ) # import data where query parameters is within an SQL query authors_list <- read_rdbms( login = rdbms_login, query = "select * from author" ) ## End(Not run)## Not run: # establish the connection to the database rdbms_login <- login( from = "mysql-rfam-public.ebi.ac.uk", type = "mysql", user_name = "rfamro", password = "", driver_name = "", db_name = "Rfam", port = 4497 ) # import data where query parameters are specified as a list authors_list <- read_rdbms( login = rdbms_login, query = list(table = "author", fields = NULL, filter = NULL) ) # import data where query parameters is within an SQL query authors_list <- read_rdbms( login = rdbms_login, query = "select * from author" ) ## End(Not run)
The function returns the following columns by default: case_id,
person_id, sex, date_of_birth, case_origin, country, city, latitude,
longitude, case_status, date_onset, date_admission, outcome, date_outcome,
contact_id, date_last_contact, date_first_contact, Ct_values.
read_sormas(login, disease, since = 0)read_sormas(login, disease, since = 0)
login |
A list with the user's authentication details |
disease |
A character with the target disease name |
since |
A Date value in ISO8601 format (YYYY-mm-dd). Default is |
Note that the some values in the date_of_birth column of the output object
might not have some missing elements such a missing year (NA-12-26), month
(2025-NA-01) or date (2025-12-NA), or a combination of two missing elements.
A data frame with the case data of the specified disease.
## Not run: # establish the connection to the SORMAS system sormas_login <- 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 <- read_sormas( login = sormas_login, disease = "coronavirus" ) ## End(Not run)## Not run: # establish the connection to the SORMAS system sormas_login <- 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 <- read_sormas( login = sormas_login, disease = "coronavirus" ) ## End(Not run)
The request_parameters data frame contains the information related to which request parameters should be used when fetching data from a specific version of DHIS2. It currently contains parameters for versions ranging from 2.22 to 2.42.
request_parametersrequest_parameters
A data frame of 3 rows and 12 columns
Display the list of tables in a database
show_tables(login)show_tables(login)
login |
The connection object obtained from the |
a character that contains the list of all tables found
in the specified database.
## Not run: # connect to the test MySQL server rdbms_login <- 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 available tables from this database tables <- show_tables(login = rdbms_login) ## End(Not run)## Not run: # connect to the test MySQL server rdbms_login <- 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 available tables from this database tables <- show_tables(login = rdbms_login) ## End(Not run)
Download the API specification file from SORMAS
sormas_get_api_specification(path = tempdir(), overwrite = TRUE)sormas_get_api_specification(path = tempdir(), overwrite = TRUE)
path |
A character with the path to the folder where the downloaded data
dictionary should be stored. Default is |
overwrite |
A logical used to specify whether to overwrite to overwrite
the existing data dictionary or not. Default is |
Invisibly returns the path to the folder where the file is stored.
When path = NULL, the file will be stored in the R temporary
folder as: api_specification.json
# save the SORMAS API specification into the temporary R folder path_api_specs <- sormas_get_api_specification()# save the SORMAS API specification into the temporary R folder path_api_specs <- sormas_get_api_specification()
Download SORMAS data dictionary
sormas_get_data_dictionary(path = tempdir(), overwrite = TRUE)sormas_get_data_dictionary(path = tempdir(), overwrite = TRUE)
path |
A character with the path to the folder where the downloaded data
dictionary should be stored. Default is |
overwrite |
A logical used to specify whether to overwrite to overwrite
the existing data dictionary or not. Default is |
A character with path to the folder where the data dictionary is
stored. When path = NULL, the file will be stored in the R
temporary folder as: dictionary.xlsx
# download and save the data dictionary in the default R temporary directory path_to_dictionary <- sormas_get_data_dictionary()# download and save the data dictionary in the default R temporary directory path_to_dictionary <- sormas_get_data_dictionary()
Get the list of disease names from a SORMAS instance
sormas_get_diseases(login)sormas_get_diseases(login)
login |
A list with the user's authentication details |
A vector of the list of disease names in a SORMAS instance
## Not run: # establish the connection to the SORMAS system sormas_login <- login( type = "sormas", from = "https://demo.sormas.org/sormas-rest", user_name = "SurvSup", password = "Lk5R7JXeZSEc" ) disease_names <- sormas_get_diseases( login = sormas_login ) ## End(Not run)## Not run: # establish the connection to the SORMAS system sormas_login <- login( type = "sormas", from = "https://demo.sormas.org/sormas-rest", user_name = "SurvSup", password = "Lk5R7JXeZSEc" ) disease_names <- sormas_get_diseases( login = sormas_login ) ## End(Not run)