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

Package review, updates and addition of translation and cleaning functions #16

Merged
merged 203 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
20fc9b6
bumped RoxygenNote in DESCRIPTION
joshwlambert Jan 19, 2023
091f93f
removed tidyverse dependency from DESCRIPTION
joshwlambert Jan 19, 2023
b9313e0
added testing infrastructure and a test for get_cases to run locally …
joshwlambert Jan 19, 2023
a9a5949
added testthat to DESCRIPTION
joshwlambert Jan 19, 2023
f727169
linted style of get_cases
joshwlambert Jan 19, 2023
976d73f
changed file.type argument and variables to snake case
joshwlambert Jan 19, 2023
56417f4
updated get_cases documentation
joshwlambert Jan 19, 2023
70bf982
remove imports that are not used in get_cases
joshwlambert Jan 19, 2023
987cd45
changed get_cases output from data frame to tibble
joshwlambert Jan 20, 2023
f32c6a3
linted get_active_outbreak
joshwlambert Jan 20, 2023
fc26e4c
added tests for get_active_outbreak (skipped by default)
joshwlambert Jan 20, 2023
ceb3a7f
removed pipes from get_active_outbreak
joshwlambert Jan 20, 2023
6f30665
used explicit namespace instead of import in get_active_outbreak
joshwlambert Jan 20, 2023
5cf6e5d
added comments to get_active_outbreak
joshwlambert Jan 20, 2023
f0606a1
updated get_active_outbreak documentation
joshwlambert Jan 20, 2023
00cca1b
linted check_godata_version
joshwlambert Jan 20, 2023
8ad29dc
updated documentation for check_godata_version
joshwlambert Jan 20, 2023
b6dc35d
added test for check_godata_version (skipped by default)
joshwlambert Jan 20, 2023
2833b13
removed pipes from check_godata_version
joshwlambert Jan 20, 2023
d1833a5
used explicit namespace instead of import for check_godata_version
joshwlambert Jan 20, 2023
fb6581f
updated documentation for check_godata_version
joshwlambert Jan 20, 2023
f73a524
reduce cyclomatic complexity of check_godata_version
joshwlambert Jan 20, 2023
f6d894f
linted get_godata_version
joshwlambert Jan 20, 2023
e1f7972
added test for get_godata_version (skipped by default)
joshwlambert Jan 20, 2023
95511f1
updated documentation for get_godata_version
joshwlambert Jan 20, 2023
fefc74e
removed pipe from get_godata_version
joshwlambert Jan 20, 2023
6d5a167
used explicit namespace instead of import in get_godata_version
joshwlambert Jan 20, 2023
25edbda
linted batch_downloader
joshwlambert Jan 20, 2023
d75335f
added tests for batch_downloader
joshwlambert Jan 20, 2023
7749434
updated batch_downloader documentation
joshwlambert Jan 20, 2023
984d667
removed recursive argument defaults for batch_downloader
joshwlambert Jan 20, 2023
0d54ffb
removed pipes from batch_downloader and renamed some variables
joshwlambert Jan 20, 2023
8a9424f
used explicit namespace instead of import for batch_downloader
joshwlambert Jan 20, 2023
a974cfb
removed manual removing of variables in batch_downloader
joshwlambert Jan 20, 2023
f2165f8
set to NULL rather than rm variable in batch_downloader
joshwlambert Jan 20, 2023
a5ce035
updated documentation for batch_downloader
joshwlambert Jan 20, 2023
7e04fbc
fixed variable names in batch_downloader
joshwlambert Jan 20, 2023
2a0ab13
removed redundant assignment in batch_downloader
joshwlambert Jan 20, 2023
7ae103b
linted export_downloader
joshwlambert Jan 20, 2023
2fb3a39
added tests for export_downloader (skipped by default)
joshwlambert Jan 20, 2023
4751cc5
updated documentation for export_downloader
joshwlambert Jan 20, 2023
45455fb
changes file.type argument to file_type in export_downloader
joshwlambert Jan 20, 2023
4e5d1c6
removed recursive argument defaults from export_downloader
joshwlambert Feb 1, 2023
175ec5e
removed pipe from export_downloader
joshwlambert Feb 1, 2023
95349c5
change output type of export_downloader to tibble
joshwlambert Feb 1, 2023
957f189
used explicit namespace instead of import in export_downloader
joshwlambert Feb 1, 2023
ecfcab3
fixed variable name in export_downloader
joshwlambert Feb 1, 2023
6d0edf1
added expectation for tibble in export_downloader tests
joshwlambert Feb 1, 2023
ac3865e
removed recursive argument defaults for get_active_outbreak
joshwlambert Feb 1, 2023
4a5801a
removed recursive argument defaults for get_access_token
joshwlambert Feb 1, 2023
7a2b775
linted get_access_token
joshwlambert Feb 1, 2023
26e9a28
use explicit namespace instead of import for get_access_token
joshwlambert Feb 1, 2023
960cca8
added test for get_access_token (skipped by default)
joshwlambert Feb 1, 2023
a4d47a4
linted get_export_status
joshwlambert Feb 1, 2023
3c7ff14
removed recursive argument defaults for get_export_status
joshwlambert Feb 1, 2023
4cc6abf
removed pipe from get_export_status
joshwlambert Feb 1, 2023
7c6500d
used explicit namespace instead of import for get_export_status
joshwlambert Feb 1, 2023
dcae444
added test for get_export_status (skipped by default)
joshwlambert Feb 1, 2023
1b5ccc9
linted get_all_outbreaks
joshwlambert Feb 1, 2023
19fc4dd
removed pipe from get_all_outbreaks
joshwlambert Feb 1, 2023
2b95a8a
removed recursive argument defaults for get_all_outbreaks
joshwlambert Feb 1, 2023
64a7f12
used explicit namespace instead of import for get_all_outbreaks
joshwlambert Feb 1, 2023
552d11d
updated get_all_outbreaks documentation and made return type a tibble
joshwlambert Feb 1, 2023
475cd2f
added test for get_all_outbreaks (skipped by default)
joshwlambert Feb 1, 2023
bc0cc85
linted check_godata_url
joshwlambert Feb 2, 2023
ecb17e0
removed recursive argument default for check_godata_url
joshwlambert Feb 2, 2023
cf14b90
removed pipe from check_godata_url
joshwlambert Feb 2, 2023
99fdf29
used explicit namespace instead of import for check_godata_url
joshwlambert Feb 2, 2023
c6c3ced
added test for check_godata_url (skipped by default)
joshwlambert Feb 2, 2023
b5934e3
updated check_godata_url documentation
joshwlambert Feb 2, 2023
7cea7eb
removed recursive default arguments for get_cases
joshwlambert Feb 2, 2023
588ad2c
linted get_clusters
joshwlambert Feb 2, 2023
45a7bea
removed recursive argument defaults for get_clusters
joshwlambert Feb 2, 2023
9966338
removed pipe from get_clusters
joshwlambert Feb 2, 2023
0d4f3ca
used explicit namespace instead of import for get_clusters
joshwlambert Feb 2, 2023
0c9cb7b
added test for get_clusters
joshwlambert Feb 2, 2023
a8fe768
linted set_active_outbreak
joshwlambert Feb 2, 2023
270e430
removed recursive argument defaults from set_active_outbreak
joshwlambert Feb 2, 2023
a52f48f
removed pipe from set_active_outbreak
joshwlambert Feb 2, 2023
77d87db
used explicit namespace instead of import for set_active_outbreak
joshwlambert Feb 2, 2023
5f56dcf
set_active_outbreak now returns outbreak_id invisibly
joshwlambert Feb 2, 2023
2eaec65
added tests for set_active_outbreak
joshwlambert Feb 2, 2023
7abe81f
linted get_contacts
joshwlambert Feb 2, 2023
cf5c17b
removed recursive argument defaults for get_contacts
joshwlambert Feb 2, 2023
dadff76
removed imports from get_contacts
joshwlambert Feb 2, 2023
28e64bd
added test for get_contacts
joshwlambert Feb 2, 2023
58d4309
ensure contacts are returned as tibble in get_contacts
joshwlambert Feb 2, 2023
98796a1
linted get_contacts_of_contacts
joshwlambert Feb 2, 2023
e9fddf3
removed recursive default arguments from get_contacts_of_contacts
joshwlambert Feb 2, 2023
b298b01
removed imports from get_contacts_of_contacts
joshwlambert Feb 2, 2023
9f10f0c
ensure get_contact_of_contacts is returned as a tibble
joshwlambert Feb 2, 2023
d771daa
added test for get_contacts_of_contacts
joshwlambert Feb 2, 2023
e23a889
linted get_languages
joshwlambert Feb 3, 2023
4e44181
removed pipe from get_languages
joshwlambert Feb 3, 2023
2ec3a5f
removed recursive default arugments from get_languages
joshwlambert Feb 3, 2023
668c3a8
used explicit namespace instead of import for get_languages
joshwlambert Feb 3, 2023
31389c7
added test for get_languages
joshwlambert Feb 3, 2023
52e1d83
linted get_language_tokens
joshwlambert Feb 3, 2023
72b47a0
removed recursive argument defaults for get_language_tokens
joshwlambert Feb 3, 2023
339ef2d
removed pipe from get_language_tokens
joshwlambert Feb 3, 2023
79a1801
used explicit namespace instead of import for get_language_tokens
joshwlambert Feb 3, 2023
73cf559
added test for get_language_tokens
joshwlambert Feb 3, 2023
af77bd7
added translate_categories function and helper functions
joshwlambert Feb 5, 2023
998c2c7
linted get_labresults
joshwlambert Feb 14, 2023
69a0167
removed recursive arugment defaults for get_labresults
joshwlambert Feb 14, 2023
13a9f09
used explicit namespace instead of import in get_labresults
joshwlambert Feb 14, 2023
56ab9a6
added test for get_labresults
joshwlambert Feb 14, 2023
aac21b5
linted get_relationships
joshwlambert Feb 14, 2023
eab7490
removed recursive argument defaults from get_relationships
joshwlambert Feb 14, 2023
a31aa75
used explicit namespace instead of import in get_relationships
joshwlambert Feb 14, 2023
ab55e6a
added test for get_relationships
joshwlambert Feb 14, 2023
a0da8ea
linted get_followups
joshwlambert Feb 14, 2023
c78f04e
removed recursive argument defaults for get_followups
joshwlambert Feb 14, 2023
9fb1041
used explicit namespace instead of import for get_followups
joshwlambert Feb 14, 2023
da9ca87
added test for get_followups
joshwlambert Feb 14, 2023
8f67af0
linted get_events
joshwlambert Feb 14, 2023
25fcab9
removed recurive argument defaults from get_events
joshwlambert Feb 14, 2023
6736ff1
used explicit namespace instead of import for get_events
joshwlambert Feb 14, 2023
e54a4b3
added test for get_events
joshwlambert Feb 14, 2023
810789b
linted get_teams
joshwlambert Feb 14, 2023
7b83f36
removed recursive default arguments in get_teams
joshwlambert Feb 14, 2023
d5f51dd
removed pipe from get_teams
joshwlambert Feb 14, 2023
4c41361
used explicit namespace instead of import in get_teams
joshwlambert Feb 14, 2023
8addbeb
ensure get_teams returns a tibble
joshwlambert Feb 14, 2023
1b26a09
added test for get_teams
joshwlambert Feb 14, 2023
d6167e5
updated NAMESPACE
joshwlambert Feb 14, 2023
b6b4a79
linted get_locations
joshwlambert Feb 14, 2023
ee83866
removed recursive arugment defaults for get_locations
joshwlambert Feb 14, 2023
113a45f
removed pipe from get_locations
joshwlambert Feb 14, 2023
e26c7ec
used explicit namespace instead of import in get_locations
joshwlambert Feb 14, 2023
c0a6a8c
ensure get_locations returns a tibble
joshwlambert Feb 14, 2023
2dd80e3
added test for get_locations
joshwlambert Feb 14, 2023
b7f722d
linted get_reference_data
joshwlambert Feb 14, 2023
d203ca8
removed recursive default arguments in get_reference_data
joshwlambert Feb 14, 2023
54f00e5
removed pipe from get_reference_data
joshwlambert Feb 14, 2023
e4d0627
used explicit namespace instead of import for get_reference_data
joshwlambert Feb 14, 2023
cc3dbe6
ensure get_reference_data returns a tibble
joshwlambert Feb 14, 2023
175c6cb
added test for get_reference_data
joshwlambert Feb 14, 2023
36cb8df
linting tests
joshwlambert Feb 14, 2023
2014104
linted get_users
joshwlambert Feb 14, 2023
4d0a0d0
removed recursive argument defaults in get_users
joshwlambert Feb 14, 2023
2569d5b
removed pipe from get_users
joshwlambert Feb 14, 2023
3d04234
used explicit namespace instead of import for get_users
joshwlambert Feb 14, 2023
39ab66d
ensure get_users returns a tibble
joshwlambert Feb 14, 2023
f6ecc5e
added test for get_users
joshwlambert Feb 14, 2023
6c0cd73
linted mongify_date
joshwlambert Feb 14, 2023
483a81c
added tests for mongify_date and linted mongify_date
joshwlambert Feb 14, 2023
2fabad6
linted get_date_range
joshwlambert Feb 14, 2023
f07b89e
added tests for get_date_range
joshwlambert Feb 14, 2023
3b9277e
added clean_locations function, documentation and a test
joshwlambert Feb 16, 2023
0550177
added clean_case_address_history function, documentation and test
joshwlambert Feb 16, 2023
7e375e6
added clean_case_med_history function, documentation and test
joshwlambert Feb 16, 2023
ef57c7e
added clean_case_vax_history function, documentation and test
joshwlambert Feb 16, 2023
8589d3a
added clean_cases function, documentation and test
joshwlambert Mar 14, 2023
5bcb9db
added cases_from_contacts function, documentation and test
joshwlambert Mar 14, 2023
d1974e3
added clean_contact_address_history function, documentation and test
joshwlambert Mar 14, 2023
19ddad5
added clean_contact_vax_history function, documentation and test
joshwlambert Mar 14, 2023
aff3943
added clean_contacts_of_contacts_address_history function, documentat…
joshwlambert Mar 15, 2023
6f70b4d
added clean_contacts_of_contacts_vax_history function, documentation …
joshwlambert Mar 15, 2023
78d1f53
added clean_contacts_of_contacts function, documentation and test (WI…
joshwlambert Mar 15, 2023
442c3a4
added clean_followups function, documentation and test
joshwlambert Mar 15, 2023
688d28c
added clean_events function, documentation and test (WIP function cur…
joshwlambert Mar 15, 2023
05380ac
added clean_users function, documentation and test
joshwlambert Mar 16, 2023
0de513a
fixed bug in clean_users
joshwlambert Mar 16, 2023
fc1180d
added clean_teams function, documentation and test
joshwlambert Mar 16, 2023
035e710
added clean_relationships function, documentation and test
joshwlambert Mar 16, 2023
54ec892
added contacts_per_case function, documentation and test
joshwlambert Mar 16, 2023
e3ee640
added exposures_per_case function, documentation and test
joshwlambert Mar 16, 2023
bab80d6
added clean_contacts
joshwlambert Mar 31, 2023
6c9e113
added dplyr namespace to case_when in clean_cases
joshwlambert Mar 31, 2023
2696fd5
fixed clean_case_address_history by adding locations_clean argument t…
joshwlambert Mar 31, 2023
a002663
fixed clean_locations by fixing typo in return
joshwlambert Mar 31, 2023
c28d345
updated check_godata_url function, doc and test to use success_code a…
joshwlambert Mar 31, 2023
bb9c39d
updated check_godata_version to use strsplit, added version names and…
joshwlambert Mar 31, 2023
c57fbf9
updated batch_downloader test
joshwlambert Mar 31, 2023
6c9fe8c
fixed clean_cases test
joshwlambert Mar 31, 2023
5421094
updated clean_case_address_history
joshwlambert Mar 31, 2023
649f5fb
fixed cases_from_contacts test
joshwlambert Mar 31, 2023
fe8b34e
fixed export_downloader test
joshwlambert Mar 31, 2023
b8344d7
fixed get_all_outbreaks test
joshwlambert Mar 31, 2023
f05251f
added first draft of get_cases_questionnaire
joshwlambert Mar 31, 2023
fbaeeac
updated get_cases_questionnaire documentation
joshwlambert Mar 31, 2023
e6be607
updated documentation
joshwlambert Apr 6, 2023
7084b71
used translation function in clean_case_address_history
joshwlambert Apr 6, 2023
fe63123
used translation function in clean_case_med_history
joshwlambert Apr 6, 2023
7ed2c25
added translation function to clean_case_vax_history
joshwlambert Apr 6, 2023
4e27174
used translation function in clean_cases
joshwlambert Apr 6, 2023
5bdef54
used translation function in clean_contact_address_history
joshwlambert Apr 6, 2023
c9460d5
used translation function in clean_contact_vax_history
joshwlambert Apr 6, 2023
3316a80
used translation function in clean_contacts_of_contacts_address_history
joshwlambert Apr 6, 2023
fe7009d
used translation function in clean_contacts_of_contacts_vax_history
joshwlambert Apr 6, 2023
ae4a7e5
removing extra #' in clean_case_vax_history
joshwlambert Apr 6, 2023
77c0665
used translation function in clean_contacts_of_contacts (function fails)
joshwlambert Apr 6, 2023
3e4d502
added janitor as package dependency
joshwlambert Apr 14, 2023
dedc9df
used translation function in clean_contacts
joshwlambert Apr 14, 2023
dd93982
added test for clean_contacts
joshwlambert Apr 14, 2023
31734f8
updated clean_events function and test
joshwlambert Apr 14, 2023
0076247
used translation function for clean_followups and updated test
joshwlambert Apr 14, 2023
2569f9f
used translation function in clean_locations and updated test
joshwlambert Apr 14, 2023
ac142b3
used translation function in clean_relationships and updated test
joshwlambert Apr 14, 2023
fdcb33a
updated clean_teams test
joshwlambert Apr 14, 2023
5bb71f6
used translation function in clean_users and updated test
joshwlambert Apr 14, 2023
f6daa6f
updated examples in documentation
joshwlambert Apr 14, 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
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ Imports:
stringr,
tibble,
tidyr,
tidyverse,
urltools
urltools,
janitor
Suggests:
devtools,
testthat
devtools,
testthat (>= 3.0.0)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Depends:
R (>= 2.10)
Config/testthat/edition: 3
24 changes: 21 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
# Generated by roxygen2: do not edit by hand

export(cases_from_contacts)
export(check_godata_url)
export(clean_case_address_history)
export(clean_case_med_history)
export(clean_case_vax_history)
export(clean_cases)
export(clean_contact_address_history)
export(clean_contact_vax_history)
export(clean_contacts)
export(clean_contacts_of_contacts)
export(clean_contacts_of_contacts_address_history)
export(clean_contacts_of_contacts_vax_history)
export(clean_events)
export(clean_followups)
export(clean_locations)
export(clean_relationships)
export(clean_teams)
export(clean_users)
export(contacts_per_case)
export(expand_location_tree)
export(exposures_per_case)
export(get_access_token)
export(get_active_outbreak)
export(get_all_outbreaks)
export(get_cases)
export(get_cases_epiwindow)
export(get_cases_questionnaire)
export(get_clusters)
export(get_contacts)
export(get_contacts_epiwindow)
Expand All @@ -29,18 +49,16 @@ export(get_users)
export(mongify_date)
export(null2na)
export(set_active_outbreak)
export(translate_categories)
import(data.table)
import(dplyr)
import(httr)
import(jsonlite)
import(lubridate)
import(purrr)
import(stringr)
import(tibble)
import(tidyr)
import(urltools)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(purrr,pluck)
importFrom(stringr,str_split)
importFrom(utils,read.csv)
120 changes: 73 additions & 47 deletions R/batch_downloader.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
#'
#' A housekeeping function to do batch downloads.
#'
#' @param url Insert the base URL for your instance of Go.Data here. Don't forget the forward slash "/" at end!
#' @param url Insert the base URL for your instance of Go.Data here. Don't
#' forget the forward slash "/" at end!
#' @param username The email address for your Go.Data login.
#' @param password The password for your Go.Data login
#' @param api_call_n The API url to get the number of records.
#' @param api_call_get The API url to GET the records.
#' @param batch_size Specifies the number of records to retrieve in each iteration.
#' @param batch_size Specifies the number of records to retrieve in each
#' iteration.
#'
#' @return
#' Returns a data frame. Some fields, such as addresses, hospitalization history, and questionnaire fields may require further unnesting. See \code{\link[tidyr]{nest}} for assitance with unnesting.
#' Returns a data frame. Some fields, such as addresses, hospitalization
#' history, and questionnaire fields may require further unnesting. See
#' `\link[tidyr]{nest}` for assitance with unnesting.
#'
#' @examples
#' \dontrun{
Expand All @@ -19,66 +23,88 @@
#' password <- "mypassword"
#' outbreak_id <- "3b5554d7-2c19-41d0-b9af-475ad25a382b"
#'
#' cases <- get_cases(url=url,
#' username=username,
#' password=password,
#' outbreak_id=outbreak_id)
#' cases <- get_cases(
#' url = url,
#' username = username,
#' password = password,
#' outbreak_id = outbreak_id
#' )
#' }
#' @importFrom magrittr %>%
#' @import dplyr
#' @import tidyr
#' @import httr
#' @import tibble
#' @importFrom jsonlite fromJSON
#' @importFrom purrr pluck
#'
#'
batch_downloader <- function(url = url,
username = username,
password = password,
api_call_n = api_call_n,
api_call_get = api_call_get,
batch_size = batch_size) {
batch_downloader <- function(url,
username,
password,
api_call_n,
api_call_get,
batch_size) {

num_record_request <- httr::GET(
paste0(api_call_n),
httr::add_headers(
Authorization = paste("Bearer", get_access_token(
url = url,
username = username,
password = password
), sep = " ")))

#get total number of records
df_n <- GET(paste0(api_call_n),
add_headers(Authorization = paste("Bearer", get_access_token(url=url, username=username, password=password), sep = " "))) %>%
content(as="text") %>%
fromJSON(flatten=TRUE) %>%
unlist() %>%
unname()
num_record_content <- httr::content(num_record_request, as = "text")

num_records <- jsonlite::fromJSON(num_record_content, flatten = TRUE)
num_records <- num_records$count

#Import records in batches
df <- tibble()
batch_size <- batch_size # number of records to import per iteration
skip <-0
df <- tibble::tibble()
skip <- 0
message("****************************")

#Download records in batches, and then append them into a single dataset
while (skip < df_n) {
while (skip < num_records) {

#Progress message
if (df_n <= batch_size) message(paste0("...downloading records 1 to ",df_n))
if (df_n > batch_size) message(paste0("...downloading records ", as.character(skip+1, scientific = FALSE), " to ", format(skip+batch_size, scientific = FALSE)))
if (num_records <= batch_size) {
message(paste0("...downloading records 1 to ", num_records))
}
if (num_records > batch_size) {
message(
paste0(
"...downloading records ",
as.character(skip + 1, scientific = FALSE),
" to ",
format(skip + batch_size, scientific = FALSE)
)
)
}

#fetch the batch of records
df.i <- GET(paste0(api_call_get,
"?filter={%22limit%22:",format(batch_size, scientific = FALSE),",%22skip%22:",format(skip, scientific = FALSE),"}"),
add_headers(Authorization = paste("Bearer", get_access_token(url=url, username=username, password=password), sep = " "))) %>%
content(as='text') %>%
fromJSON( flatten=TRUE) %>%
as_tibble()
record_request <- httr::GET(
paste0(
api_call_get,
"?filter={%22limit%22:",
format(batch_size, scientific = FALSE),
",%22skip%22:",
format(skip, scientific = FALSE),
"}"
),
httr::add_headers(
Authorization = paste("Bearer", get_access_token(
url = url,
username = username,
password = password),
sep = " ")
)
)

record_content <- httr::content(record_request, as = "text")

records <- jsonlite::fromJSON(record_content, flatten = TRUE)

records <- tibble::as_tibble(records)

#append the new batch of records to the existing data frame
df <- df %>%
bind_rows(df.i)
df <- dplyr::bind_rows(df, records)

#update numbers for the next iteration
skip <- skip + batch_size
rm(df.i)
records <- NULL
}
rm(batch_size, skip, df_n)
return(df)
}


106 changes: 106 additions & 0 deletions R/cases_from_contacts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#' Pull out all cases that used to be contacts
#'
#' @param cases_clean The cleaned case data. Case data is returned by
#' [`get_cases()`] and cleaned by [`clean_cases()`].
#'
#' @return A tibble containing the cases that used to be contacts.
#' @export
#'
#' @examples
#' \dontrun{
#' url <- "https://MyGoDataServer.com/"
#' username <- "myemail@email.com"
#' password <- "mypassword"
#' outbreak_id <- "3b5554d7-2c19-41d0-b9af-475ad25a382b"
#'
#' cases <- get_cases(
#' url = url,
#' username = username,
#' password = password,
#' outbreak_id = outbreak_id
#' )
#'
#' # other cleaned data required for `clean_cases()`
#' cases_vacc_history_clean <- clean_case_vax_history(cases = cases)
#' cases_address_history_clean <- clean_case_address_history(cases = cases)
#' cases_dateranges_history_clean <- clean_case_med_history(cases = cases)
#'
#' cases_clean <- clean_cases(
#' cases = cases,
#' cases_address_history_clean = cases_address_history_clean,
#' cases_vacc_history_clean = cases_vacc_history_clean,
#' cases_dateranges_history_clean = cases_dateranges_history_clean
#' )
#'
#' cases_from_contacts <- cases_from_contacts(cases_clean = cases_clean)
#' }
cases_from_contacts <- function(cases_clean) {

contacts_becoming_cases <- dplyr::filter(
.data = cases_clean,
.data$was_contact == TRUE
)

# set this status to became case and no longer active
contacts_becoming_cases <- dplyr::mutate(
.data = contacts_becoming_cases,
follow_up_status = "BECAME_CASE",
was_case = NA,
date_of_last_contact = NA,
follow_up_team_id = NA,
relationship_exposure_type = NA,
relationship_context_of_transmission = NA,
relationship_exposure_duration = NA,
relationship_exposure_frequency = NA,
relationship_certainty_level = NA,
relationship_cluster_id = NA,
)

# organize order of vars, only bring in what we need, take away confusing vars
contacts_becoming_cases <- dplyr::select(
.data = contacts_becoming_cases,
"id", # identifier
"visual_id", # identifier
"classification", # identifier
"follow_up_status", # identifier
"first_name", # demographics
"middle_name", # demographics
"last_name", # demographics
"gender", # demographics
"age", # demographics
"age_class", # demographics
"occupation", # demographics
"pregnancy_status", # demographics
"date_of_reporting", # dates
"date_of_last_contact", # dates
"date_of_burial", # dates
"risk_level", # epi
"risk_reason", # epi
"responsible_user_id", # assigned contact tracer
"follow_up_team_id", # assigned contact tracer
dplyr::matches("^admin_.*name$"), # address
"lat", # address
"long", # address
"address", # address
"postal_code", # address
"city", # address
"telephone", # address
"email", # address
"vaccinated",
"outcome", # outcome
"date_of_outcome", # outcome
"relationship_exposure_type",
"relationship_context_of_transmission",
"relationship_exposure_duration",
"relationship_exposure_frequency",
"relationship_certainty_level",
"relationship_cluster_id",
"location_id", # uuid in case need later for joining of whatever sort
"created_by", # record modification
"datetime_created_at", # record modification
"updated_by", # record modification
"datetime_updated_at" # record modification
)

return(contacts_becoming_cases)
}
22 changes: 11 additions & 11 deletions R/check_godata_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
#' is valid. This is a housekeeping function
#' used in many of the other `godataR` functions.
#'
#' @param url Insert the base URL for your instance of Go.Data here. Don't forget the forward slash "/" at end!
#' @param url Insert the base URL for your instance of Go.Data here. Don't
#' forget the forward slash "/" at end!
#' @param success_code A numeric specifying which code is returned by the API
#' when successfully returning the status code. Default is 200.
#'
#' @return
#' Boolean, where `TRUE` indicates a valid URL.
#' @examples
#' \dontrun{
#' url <- "https://MyGoDataServer.com/"
#' check_godata_url(url=url)
#' check_godata_url(url = url)
#' }
#' @importFrom magrittr %>%
#' @import httr
#' @importFrom purrr pluck
#' @export
check_godata_url <- function(url=url) {
check_godata_url <- function(url,
success_code = 200) {

# Get status code for version check
status_code <- GET(paste0(url,"api/system-settings/version")) %>%
pluck("status_code")
status_code <- httr::GET(paste0(url, "api/system-settings/version"))

# create boolean based on status code being 200 (success)
check <- (status_code==200)
status_code <- purrr::pluck(status_code, "status_code")
joshwlambert marked this conversation as resolved.
Show resolved Hide resolved

return(check)
# return boolean based on status code being a success
return(isTRUE(status_code == success_code))

}
Loading