Skip to content

Commit

Permalink
Dp 781 (#110)
Browse files Browse the repository at this point in the history
* Update getDataValueSets.R

- added exceptions for dataSet requirement to allow for dataElementGroup
- added exceptions for orgUnit requirement to allow for orgUnitGroup

* Update getDataValueSets.R

-changed values to scalar operators

* errors and testing

- updated error message
- updated test coverage to cover both error changes

* Update test-getDataValueSets.R

- linting

* Update d2Session.Rd

* Update DESCRIPTION

* Update NEWS.md

Co-authored-by: sam-bao <[email protected]>
  • Loading branch information
flopez-bao and sam-bao authored Sep 8, 2022
1 parent 1f81eb3 commit 988a385
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: datimutils
Type: Package
Title: Utilities for interacting with the DATIM api from R
Version: 0.5.2
Date: 2022-08-18
Version: 0.5.3
Date: 2022-09-08
Authors@R:
c(
person("Scott", "Jackson", email = "[email protected]",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# datimutils 0.5.3

## Bug fixes
* Fixes error conditions in getDataValueSets.

# datimutils 0.5.2

## Bug fixes
Expand Down
12 changes: 7 additions & 5 deletions R/getDataValueSets.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ getDataValueSets <- function(variable_keys = NULL, #keys,
#Requirements
# The following constraints apply to the data value sets resource:

#1 At least one data set must be specified.
if (!(is.element("dataSet", variable_keys))) {
stop("At least one data set must be specified.")
#1 At least one data set must be specified OR a dataElementGroup.
if (!(is.element("dataSet", variable_keys)) == TRUE &&
!(is.element("dataElementGroup", variable_keys)) == TRUE) {
stop("At least one data set or data element group must be specified.")
}

#2 Either at least one period or a start date and end date must be specified.
Expand All @@ -54,8 +55,9 @@ getDataValueSets <- function(variable_keys = NULL, #keys,
}

#3 At least one organisation unit must be specified.
if (!(is.element("orgUnit", variable_keys))) {
stop("At least one organisation unit must be specified.")
if (!(is.element("orgUnit", variable_keys)) == TRUE &&
!(is.element("orgUnitGroup", variable_keys)) == TRUE) {
stop("At least one organisation unit or organisation unit group must be specified.")
}

#4 Organisation units must be within the hierarchy of the organisation units
Expand Down
15 changes: 6 additions & 9 deletions man/d2Session.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 18 additions & 8 deletions tests/testthat/test-getDataValueSets.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ test_that("GetDataValueSets", {
#correct file

with_mock_api({
data <- getDataValueSets(c("dataSet", "period", "orgUnit"),
c("pBOMPrpg1QX", "202201", "DiszpKrYNg8"),
data <- getDataValueSets(variable_keys = c("dataSet", "period", "orgUnit"),
variable_values = c("pBOMPrpg1QX", "202201", "DiszpKrYNg8"),
d2_session = play2372)

testthat::expect_named(data, c("dataElement",
Expand All @@ -28,8 +28,8 @@ test_that("GetDataValueSets", {
"followup"))
testthat::expect_equal(NROW(data), 3)

data2 <- getDataValueSets(c("dataSet", "period", "orgUnit"),
c("pBOMPrpg1QX", "202201", "DiszpKrYNg8"),
data2 <- getDataValueSets(variable_keys = c("dataSet", "period", "orgUnit"),
variable_values = c("pBOMPrpg1QX", "202201", "DiszpKrYNg8"),
d2_session = play2372,
verbose = TRUE)
testthat::expect_type(data2, "list")
Expand All @@ -46,10 +46,20 @@ test_that("GetDataValueSets", {
"followup"))
testthat::expect_equal(NROW(data2$data), 3)

testthat::expect_error(getDataValueSets(c("limit"),
c("3"),
play2372),
"At least one data set must be specified.",
# test missing data set or data element group
testthat::expect_error(getDataValueSets(variable_keys = c("limit"),
variable_values = c("3"),
d2_session = play2372),
"At least one data set or data element group must be specified.",
fixed = TRUE)

# test missing orgunit or orgunit group
testthat::expect_error(getDataValueSets(variable_keys = c("dataSet", "period"),
variable_values = c("pBOMPrpg1QX", "202201"),
d2_session = play2372),
"At least one organisation unit or organisation unit group must be specified.",
fixed = TRUE)


})
})

0 comments on commit 988a385

Please sign in to comment.