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

Update of epidict package to include an EWAR/EBS template #22

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
be7e08e
Added EWAR as an option to the list of datasets
pbkeating Feb 24, 2022
a65c182
Added EWAR kobo forms to the survey dict excel file
pbkeating Feb 24, 2022
296e442
Added EWAR as an option to the get_dictionary() function
pbkeating Feb 24, 2022
7ca6047
Removed spaces and notes from EWAR tab
pbkeating Feb 24, 2022
994eb22
Updated variable names to make all unique e.g. comments becames comme…
pbkeating Feb 24, 2022
795a826
Made each variable name of event_id unique
pbkeating Feb 24, 2022
daffd3a
Added ewar as an option and to error messages
pbkeating Feb 24, 2022
e65746c
Tidied up documentation part of the script to include EWAR
pbkeating Feb 24, 2022
f626dc8
Add a short section on EWAR dictionary to organise the appearance of …
pbkeating Feb 24, 2022
8c390f7
fixed the variable name to make it reflect the ewar dataset
pbkeating Feb 24, 2022
b9df540
Created a signal ID and copied it to the assessment and response sign…
pbkeating Feb 24, 2022
07ebd36
Commented out code causing error
pbkeating Feb 24, 2022
3cacd63
Columns take NA when signal is not verified
pbkeating Feb 24, 2022
40b2912
Switched the order of making NA to see if helps
pbkeating Feb 24, 2022
faf8a47
Added initials variable
pbkeating Feb 24, 2022
86d5e97
fixed typo in acf vs act
pbkeating Feb 24, 2022
1a82f76
Added code to ensure alert status reflects the outcome of the risk ch…
pbkeating Feb 25, 2022
63a531f
Minor clarification on wording in comments
pbkeating Mar 1, 2022
2c76287
Add extra questions to the risk assessment forms
pbkeating Jul 28, 2022
c29f2d8
Added EWAR in list of relevant templates that can be used with the ms…
pbkeating Feb 20, 2023
192792c
Add EWAR among list of included dictionaries
pbkeating Feb 20, 2023
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
118 changes: 117 additions & 1 deletion R/gen_msf_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @param dictionary Specify which dictionary you would like to use.
#' Currently supports "Cholera", "Measles", "Meningitis", "AJS",
#' "Mortality", "Nutrition", "Vaccination_long" and "Vaccination_short"
#' "Mortality", "Nutrition", "Vaccination_long", "Vaccination_short" and "EWAR"
#'
#' @param varnames Specify name of column that contains variable names. Currently
#' default set to "data_element_shortname". If `dictionary` is a survey,
Expand Down Expand Up @@ -857,6 +857,122 @@ gen_msf_data <- function(dictionary, dat_dict, is_survey, varnames = "data_eleme

}

if (dictionary == "EWAR") {

# set date of event starting to the earliest date from those given
dis_output$date_event_start <- with(
dis_output,
pmin(
date_event_start,
date_signal,
date_triage,
date_verification,
date_assessment,
date_response_started,
date_response_ended,
na.rm = TRUE
)
)

# date signal
dis_output <- enforce_timing(dis_output,
first = "date_signal",
second = "date_triage",
5:30
)

## date triage
dis_output <- enforce_timing(dis_output,
first = "date_triage",
second = "date_verification",
5:30,
inclusive = TRUE
)

# died verification
dis_output <- enforce_timing(dis_output,
first = "date_verification",
second = "date_assessment",
5:30
)

## date assessment
dis_output <- enforce_timing(dis_output,
first = "date_assessment",
second = "date_response_started",
5:30,
inclusive = TRUE
)

## date response started
dis_output <- enforce_timing(dis_output,
first = "date_response_started",
second = "date_response_ended",
5:30,
inclusive = TRUE
)

## create an initials variable of 3 random letters
dis_output$initials <- stringi::stri_rand_strings(nrow(dis_output), 2,
pattern = "[a-z]")


## create a signal id
dis_output$event_id_sig <- paste0(dis_output$initials, "_",
dis_output$location_signal, "_",
dis_output$signal_type, "_",
dis_output$date_signal)


## Copy this signal id to assessment and response event id variables
dis_output$event_id_assess <- dis_output$event_id_sig

dis_output$event_id_res <- dis_output$event_id_sig


## Add a random number for total people affected
dis_output$total_affected <- sample(1:10, nrow(dis_output), replace = TRUE)


## Add one person less for under 5 affected
dis_output$under5_affected <- dis_output$total_affected - 1


## Add a random number for total people identified by active case finding
dis_output$acf_total <- sample(2:15, nrow(dis_output), replace = TRUE)

## Add one person less for total under 5 identified by active case finding
dis_output$acf_under5 <- dis_output$acf_total - 1


## Ensure that alert_status takes a value of 1 where risk characterisation
## is y (yes)
dis_output$alert_status[dis_output$risk_characterisation == "y"] <- 1


## Ensure that alert_status takes a value of 0 where risk characterisation
## is n (n) or u (unsure)
dis_output$alert_status[dis_output$risk_characterisation == "n" |
dis_output$risk_characterisation == "u"] <- 0

## Convert all columns NA when no intervention required
dis_output[dis_output$alert_status == 0, 42:49] <- NA

## Convert all values in columns to NA when a signal is not verified
dis_output[dis_output$event_status == 0, 22:49] <- NA

## Convert all values in columns to NA when a signal doesn't require
## verification
dis_output[dis_output$need_verif == 0, 18:49] <- NA


## Convert dates of start and end of response to NA if no response carried out
## or if unsure if a response was carried out
dis_output[dis_output$response_undertaken %in% c("n", "u"),
c("date_response_started","date_response_ended")] <- NA

}


# return dataset as a tibble
dplyr::as_tibble(dis_output)
Expand Down
4 changes: 2 additions & 2 deletions R/msf_dict.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#'
#' @param disease Specify which disease you would like to use.
#' - `msf_dict()` supports "AJS", "Cholera", "Measles", "Meningitis"
#' - `msf_dict_survey()` supports "Mortality", "Nutrition", "Vaccination_long"
#' and "Vaccination_short" (only used in surveys if `template = TRUE`)
#' - `msf_dict_survey()` supports "Mortality", "Nutrition", "Vaccination_long",
#' "Vaccination_short" (only used in surveys if `template = TRUE`) and "EWAR"
#'
#' @param name the name of the dictionary stored in the package.
#' - `msf_dict_survey()` supports Kobo dictionaries not stored within this package,
Expand Down
11 changes: 6 additions & 5 deletions R/msf_dict_rename_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @export
#' @param disease Specify which disease you would like to use.
#' Currently supports "Cholera", "Measles", "Meningitis", "AJS",
#' "Mortality", "Nutrition", "Vaccination_short" and "Vaccination_long".
#' "Mortality", "Nutrition", "Vaccination_short", "Vaccination_long" and "EWAR".
#'
#' @param name The name of the dictionary stored in the package. The default
#' will use dictionaries from the package. However you can also use
Expand All @@ -15,7 +15,7 @@
#' @param varnames The name of column that contains variable names. The
#' default set to "data_element_shortname".
#' If `dictionary` is a survey ("Mortality", "Nutrition", "Vaccination_short"
#' or "Vaccination_long") `varnames` needs to be "name"`. Otherwise if using
#' "Vaccination_long" or "EWAR") `varnames` needs to be "name"`. Otherwise if using
#' your own dictionary then specify.
#'
#' @param varnames_type The name of column that contains the variable type.
Expand Down Expand Up @@ -60,10 +60,11 @@ msf_dict_rename_helper <- function(disease,
if (
!tolower(disease) %in% c("cholera", "measles", "meningitis", "ajs",
"mortality", "nutrition", "vaccination_short",
"vaccination_long") &
"vaccination_long", "ewar") &
template) {
stop("disease must be one of `cholera`, `measles`, `meningitis`, `ajs`,
`mortality`, `nutrition`, `vaccination_short`, `vaccination_long`.
`mortality`, `nutrition`, `vaccination_short`, `vaccination_long`,
`ewar`.
If using your own dictionary please set template to `FALSE`",
call. = FALSE)
}
Expand All @@ -85,7 +86,7 @@ msf_dict_rename_helper <- function(disease,

# get msf disease specific survey data dictionary
if (disease == "mortality" | disease == "nutrition" |
disease == "vaccination_short" | disease == "vaccination_long") {
disease == "vaccination_short" | disease == "vaccination_long" | disease == "ewar") {

dat_dict <- msf_dict_survey(disease, compact = TRUE)

Expand Down
4 changes: 2 additions & 2 deletions R/msf_dict_survey.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ msf_dict_survey <- function(disease, name = "MSF-survey-dict.xlsx",
disease <- get_dictionary(disease, org = "MSF")$survey

if (length(disease) == 0) {
stop("disease must be one of 'Mortality', 'Nutrition', 'Vaccination_long', 'Vaccination_short'", call. = FALSE)
stop("disease must be one of 'Mortality', 'Nutrition', 'Vaccination_long', 'Vaccination_short', 'EWAR'", call. = FALSE)
}
# get excel file path (need to specify the file name)
path <- system.file("extdata", name, package = "epidict")
Expand Down Expand Up @@ -86,7 +86,7 @@ msf_dict_survey <- function(disease, name = "MSF-survey-dict.xlsx",

outtie <- if (tibble) tibble::as_tibble(outtie) else outtie

# Return second option: a list with data dictionary and value options seperate
# Return second option: a list with data dictionary and value options separate
} else {
if (tibble) {
dat_dict <- tibble::as_tibble(dat_dict)
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ get_dictionary <- function(dictionary, org = "MSF") {

# define which ones are outbreaks and which ones are survey datasets
if (toupper(org) == "MSF") {
SURVEYS <- c("Mortality", "Nutrition", "Vaccination_long", "Vaccination_short")
SURVEYS <- c("Mortality", "Nutrition", "Vaccination_long", "Vaccination_short", "EWAR")
OUTBREAKS <- c("Cholera", "Measles", "Meningitis", "AJS")
# NOTE: For future collaborators, if you have other dictionaries you wish to
# add to this project, then you should place the names of your valid
Expand Down
Binary file modified inst/extdata/MSF-survey-dict.xlsx
Binary file not shown.