Skip to content

Commit

Permalink
Merge pull request #41 from NorwegianVeterinaryInstitute/dev
Browse files Browse the repository at this point in the history
NVIdb v0.11.1
  • Loading branch information
PetterHopp authored Feb 5, 2024
2 parents 5be4e9d + 0835838 commit b8714c0
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 80 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: NVIdb
Title: Tools to facilitate the use of NVI's databases
Version: 0.11.0
Date: 2024-01-24
Version: 0.11.1
Date: 2024-02-05
Authors@R:
c(person(given = "Petter",
family = "Hopp",
Expand Down
15 changes: 14 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
NVIdb 0.11.1 - (2024-02-05)
----------------------------------------

New features:

- set_disease_parameters now accepts the arguments purpose, FUN and select_statement.


Bug fixes:

- set_disease_parameters now accepts metodekode with 2 digits.


NVIdb 0.11.0 - (2024-01-24)
----------------------------------------

New features:

- Created `retrieve_PJS_data` to retrieve and standardisation of PJSdata.
- Created `retrieve_PJS_data` to retrieve and standardise PJSdata.

- Created `transform_code_values` to easy transform few code combinations into other values.

Expand Down
50 changes: 33 additions & 17 deletions R/build_query_one_disease.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
#' @title Builds query for selecting data for one disease from PJS
#' @description Builds the query for selecting all data for one infection/disease within one year from PJS. The input is the analytter
#' for the infectious agent and/or disease, the hensikter and metoder specific for the infection and/or disease. The the query is
#' written in T-SQL as used by MS-SQL.
#' @description Builds the query for selecting all data for one
#' infection/disease within one year from PJS. The input is the
#' analytter for the infectious agent and/or disease, the
#' hensikter and metoder specific for the infection and/or
#' disease. The the query is written in T-SQL as used by MS-SQL.
#'
#' @details The function builds the SQL syntax to select all PJS-journals concerning one infection and/o disease from PJS. This is based
#' on selecting all journals with the disease and/or infectious agent analytt in resultat, konklusjon or sakskonklusjon. By this, all
#' journals were the examination have been performed and a result has been entered should be selected.
#' @details The function builds the SQL syntax to select all PJS-journals
#' concerning one infection and/o disease from PJS. This is based
#' on selecting all journals with the disease and/or infectious
#' agent analytt in resultat, konklusjon or sakskonklusjon. By this,
#' all journals were the examination have been performed and a
#' result has been entered should be selected.
#'
#' One or more specific hensikter may be input to the selection statement. With specific hensikt is meant a hensikt that will imply
#' that the sample will be examined for the infectious agent or disease. Thereby, the selection will include samples that haven't
#' been set up for examination yet, samples that were unfit for examination and samples for which wrong conclusions have been entered.
#' One or more specific hensikter may be input to the selection
#' statement. With specific hensikt is meant a hensikt that will
#' imply that the sample will be examined for the infectious agent
#' or disease. Thereby, the selection will include samples that
#' haven't been set up for examination yet, samples that were
#' unfit for examination and samples for which wrong conclusions
#' have been entered.
#'
#' One or more specific metoder may be input to the selection statement. With specific metode is meant a metode that implies an
#' examination that will give one of the input analytter as a result. Thereby, the query will include samples that have been set up
#' for examination, but haven't been examined yet, samples that were unfit for examination and samples for which wrong results have
#' been entered.
#' One or more specific metoder may be input to the selection
#' statement. With specific metode is meant a metode that implies
#' an examination that will give one of the input analytter as a
#' result. Thereby, the query will include samples that have been
#' set up for examination, but haven't been examined yet, samples
#' that were unfit for examination and samples for which wrong
#' results have been entered.
#'
#' To select both the disease analytt and the infectious agent analytt ensures that all journals that have been examined with a result
#' is included in the output. The inclusion of specific hensikter and metoder, if exists, ensures that all journals received with the
#' purpose of examining for the infectious agent and/or disease will be included even if the examination has not been performed. This
#' is important for a full control of all relevant data for an infectious agent and/or disease.
#' To select both the disease analytt and the infectious agent
#' analytt ensures that all journals that have been examined with
#' a result is included in the output. The inclusion of specific
#' hensikter and metoder, if exists, ensures that all journals
#' received with the purpose of examining for the infectious agent
#' and/or disease will be included even if the examination has
#' not been performed. This is important for a full control of
#' all relevant data for an infectious agent and/or disease.
#'
#' @template build_query_year
#' @param analytt [\code{character}]\cr
Expand Down
44 changes: 37 additions & 7 deletions R/set_disease_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#' a relevant "utbrudds_ID" and/or specific "metoder." These can be used to select
#' saker in PJS and/or to structure and simplify the output from PJS.
#'
#' The purpose is a short description of purpose of the selection described by the
#' selection parameters for example "ok_svin_virus" that describes the selection
#' parameters for the OK programme for virus in swine. The purpose is also used as
#' part of the file name for selection_parameters, i.e. "purpose_selection_parameters"
#' and in the annual tables for ok_programmer: Kontrolltabeller for yyyy.
#'
#' One or more specific "hensiktkoder" may be input to the selection statement.
#' With specific "hensiktkode" is meant a "hensiktkode" that will imply that the sample
#' will be examined for specific infectious agent(s) or disease. One or more
Expand Down Expand Up @@ -39,9 +45,11 @@
#' warning is issued and the input is transferred to \code{include_missing_art} and
#' \code{selection_parameters}, respectively.
#'
#' @param purpose [\code{character}]\cr
#' A short description of the purpose of the selection, see details. Defaults to NULL.
#' @param hensikt2select [\code{character}]\cr
#' Specific "hensiktkoder" for the "analytt" in question. If sub-codes should
#' be included, end the code with \%.Defaults to \code{NULL}.
#' be included, end the code with \%. Defaults to \code{NULL}.
#' @param hensikt2delete [\code{character}]\cr
#' "hensiktkoder" for which saker should be excluded.
#' If sub-codes should be included, end the code with \%. Defaults to \code{NULL}.
Expand All @@ -66,6 +74,14 @@
#' Either the path and file name for an R script that can be sourced and that
#' sets the selection parameters or a named list with the selection parameters
#' (i.e. equal to the output of this function). Defaults to \code{NULL}.
#' @param FUN [\code{function}]\cr
#' Function to build the selection statement, see
#' \ifelse{html}{\code{\link{retrieve_PJSdata}}}{\code{retrieve_PJSdata}}).
#' Defaults to \code{NULL}.
#' @param select_statement [\code{character(1)}]\cr
#' A written select statement, see
#' \ifelse{html}{\code{\link{retrieve_PJSdata}}}{\code{retrieve_PJSdata}}).
#' Defaults to \code{NULL}.
#' @param \dots Other arguments to be passed to `set_disease_parameters`.
#'
#' @return A named list with selection parameters that can be used to generate
Expand All @@ -80,23 +96,28 @@
#' hensikt2select = c("0100108018", "0100109003", "0100111003", "0800109"),
#' metode2select = c("070070", "070231", "010057", "060265")
#' )
set_disease_parameters <- function(hensikt2select = NULL,
set_disease_parameters <- function(purpose = NULL,
hensikt2select = NULL,
hensikt2delete = NULL,
utbrudd2select = NULL,
metode2select = NULL,
analytt2select = NULL,
analytt2delete = NULL,
art2select = NULL,
include_missing_art = NULL,
FUN = NULL,
select_statement = NULL,
selection_parameters = NULL,
...) {

# SET SELECTION PARAMETERS ----
# Vector with possible selection parameter names
# missing_art is deprecated
var2select_template <- c("hensikt2select", "hensikt2delete", "utbrudd2select",
var2select_template <- c("purpose",
"hensikt2select", "hensikt2delete", "utbrudd2select",
"metode2select", "analytt2select", "analytt2delete", "art2select",
"include_missing_art", "missing_art")
"include_missing_art", "missing_art",
"FUN", "select_statement")

# PREPARE ARGUMENTS BEFORE CHECKING ----
if ("file" %in% ...names() & is.null(selection_parameters)) {
Expand Down Expand Up @@ -165,11 +186,12 @@ set_disease_parameters <- function(hensikt2select = NULL,
# checks <- checkmate::makeAssertCollection()

# Perform checks
checkmate::assert_string(purpose, null.ok = TRUE, add = checks)
NVIcheckmate::assert_non_null(list(analytt2select, hensikt2select, utbrudd2select, unlist(selection_parameters)), add = checks)
checkmate::assert_character(hensikt2select, min.chars = 2, max.chars = 15, any.missing = FALSE, null.ok = TRUE, add = checks)
checkmate::assert_character(hensikt2delete, min.chars = 2, max.chars = 15, any.missing = FALSE, null.ok = TRUE, add = checks)
checkmate::assert_character(utbrudd2select, max.chars = 5, any.missing = FALSE, null.ok = TRUE, add = checks)
checkmate::assert_character(metode2select, n.chars = 6, any.missing = FALSE, null.ok = TRUE, add = checks)
checkmate::assert_character(metode2select, min.chars = 2, max.chars = 6, any.missing = FALSE, null.ok = TRUE, add = checks)
checkmate::assert_character(analytt2select, min.chars = 2, max.chars = 20, any.missing = FALSE, null.ok = TRUE, add = checks)
checkmate::assert_character(analytt2delete, min.chars = 2, max.chars = 20, any.missing = FALSE, null.ok = TRUE, add = checks)
checkmate::assert_character(art2select, min.chars = 2, max.chars = 20, all.missing = FALSE, null.ok = TRUE, add = checks)
Expand All @@ -178,17 +200,25 @@ set_disease_parameters <- function(hensikt2select = NULL,
choices = c("never", "always", "for_selected_hensikt"),
add = checks)
# }
checkmate::assert_function(FUN, null.ok = TRUE, add = checks)
checkmate::assert(checkmate::check_list(x = select_statement, null.ok = TRUE),
checkmate::check_string(x = select_statement),
combine = "or",
add = checks)

# Report check-results
checkmate::reportAssertions(checks)

# CREATE LIST WITH PARAMETER VALUES ----
return(list("hensikt2select" = hensikt2select,
return(list("purpose" = purpose,
"hensikt2select" = hensikt2select,
"hensikt2delete" = hensikt2delete,
"utbrudd2select" = utbrudd2select,
"metode2select" = metode2select,
"analytt2select" = analytt2select,
"analytt2delete" = analytt2delete,
"art2select" = art2select,
"include_missing_art" = include_missing_art))
"include_missing_art" = include_missing_art,
"FUN" = FUN,
"select_statement" = select_statement))
}
50 changes: 33 additions & 17 deletions man/build_query_one_disease.Rd

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

24 changes: 23 additions & 1 deletion man/set_disease_parameters.Rd

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

Loading

0 comments on commit b8714c0

Please sign in to comment.