d2Parser: General purpose parsing function for different formats of...

View source: R/d2Parser.R

d2ParserR Documentation

General purpose parsing function for different formats of DHIS2 data

Description

d2Parser will parse a compliant DHIS2 XML, JSON, or CSV file and transform it into a standard data frame which can be used in subsequent DATIM validation routines.

Usage

d2Parser(
  filename,
  type = "csv",
  datastream = "RESULTS",
  datasets = NA,
  organisationUnit = NA,
  dataElementIdScheme = "id",
  orgUnitIdScheme = "id",
  idScheme = "id",
  invalidData = FALSE,
  hasHeader = TRUE,
  isoPeriod = NA,
  d2session = dynGet("d2_default_session", inherits = TRUE)
)

Arguments

filename

Location of the payload to be imported. Should be a valid import file.

type

Type of the file. Should be one of xml, json or csv.

datastream

One of RESULTS, TARGETS, NARRATIVES or SIMS.

datasets

Should be a character vector of data set UIDs. Alternatively, if left missing, user will be promted to choose from a list.

organisationUnit

Organisation unit ancestor.

dataElementIdScheme

Should be one of either code, name, shortName, or id. If this paramater is "id", then the Data elements are assumed to be already specififed as UIDs.

orgUnitIdScheme

Should be one of either code, name, shortName or id. If this paramater is "id", then the organisation units are assumed to be already specififed as UIDs

idScheme

Remapping scheme for category option combos.

invalidData

Exclude any (NA or missing) data from the parsed file?

hasHeader

TRUE by default. Should be set to FALSE if the file does not contain header information.

isoPeriod

period to be used for date shift boundaries. If not provided, no boundaries are set.

d2session

DHIS2 Session id

Value

A list object consisting of "info", "data" and "tests".

Note

function(filename = "/home/me/foo.xml", type = "xml", dataElementIdScheme = "code", orgUnitIdScheme = "code", idScheme = "id") Note that all values will be returned as characters.

Examples

## Not run: 
    #Be sure to login to DATIM first
    datimutils::loginToDATIM(config_path = "/home/me/datim-test.json")
    #Load a CSV file
    d <- d2Parser("myfile.csv",type="csv",header=TRUE)
    #Load a JSON file
    d <- d2Parser("myfile.json",type="json",dataElementIdScheme="code")
    #Load an XML file
    d <- d2Parser("myfile.xml",type="xml",dataElementIdScheme="name")

## End(Not run)


jason-p-pickering/datim-validation documentation built on April 20, 2023, 5:32 a.m.