Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dp 781 #110

Merged
merged 7 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)


})
})