diff --git a/DESCRIPTION b/DESCRIPTION
index acc9830b..82de55b9 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -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 = "sjackson@baosystems.com",
diff --git a/NEWS.md b/NEWS.md
index 6a64a849..daf36bd4 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,8 @@
+# datimutils 0.5.3
+
+## Bug fixes
+* Fixes error conditions in getDataValueSets.
+
# datimutils 0.5.2
## Bug fixes
diff --git a/R/getDataValueSets.R b/R/getDataValueSets.R
index 854add86..90ed96f7 100644
--- a/R/getDataValueSets.R
+++ b/R/getDataValueSets.R
@@ -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.
@@ -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
diff --git a/man/d2Session.Rd b/man/d2Session.Rd
index d40a8167..347e91a3 100644
--- a/man/d2Session.Rd
+++ b/man/d2Session.Rd
@@ -32,13 +32,13 @@ with the DHIS2 instance.}
\section{Methods}{
\subsection{Public methods}{
\itemize{
-\item \href{#method-new}{\code{d2Session$new()}}
-\item \href{#method-clone}{\code{d2Session$clone()}}
+\item \href{#method-d2Session-new}{\code{d2Session$new()}}
+\item \href{#method-d2Session-clone}{\code{d2Session$clone()}}
}
}
\if{html}{\out{
}}
-\if{html}{\out{}}
-\if{latex}{\out{\hypertarget{method-new}{}}}
+\if{html}{\out{}}
+\if{latex}{\out{\hypertarget{method-d2Session-new}{}}}
\subsection{Method \code{new()}}{
Create a new DHISLogin object
\subsection{Usage}{
@@ -56,16 +56,13 @@ Create a new DHISLogin object
connections}
\item{\code{me}}{DHIS2 me response object}
-
-\item{\code{max_cache_age}}{cache expiry currently used
-by datim validation}
}
\if{html}{\out{}}
}
}
\if{html}{\out{
}}
-\if{html}{\out{}}
-\if{latex}{\out{\hypertarget{method-clone}{}}}
+\if{html}{\out{}}
+\if{latex}{\out{\hypertarget{method-d2Session-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
diff --git a/tests/testthat/test-getDataValueSets.R b/tests/testthat/test-getDataValueSets.R
index 366e1fbe..b60379ab 100644
--- a/tests/testthat/test-getDataValueSets.R
+++ b/tests/testthat/test-getDataValueSets.R
@@ -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",
@@ -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")
@@ -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)
+
+
})
})