-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
360 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#' get_hipaa_disclosure_log_from_ehr_fhir_logs | ||
#' @description | ||
#' Read a data needed for a HIPAA disclosure log from a REDCap database | ||
#' given a DBI connection object to the REDCap database and some optional | ||
#' parameters to narrow the returned result. | ||
#' | ||
#' @param conn a DBI connection object to the REDCap database | ||
#' @param ehr_id the REDCap EHR_ID for the EHR of interest (optional) | ||
#' @param start_date The first date from which we should return results (optional) | ||
#' | ||
#' @return A dataframe suitable for generating a HIPAA disclosure log | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' library(tidyverse) | ||
#' library(lubridate) | ||
#' library(REDCapR) | ||
#' library(dotenv) | ||
#' library(redcapcustodian) | ||
#' library(DBI) | ||
#' library(RMariaDB) | ||
#' | ||
#' init_etl("export_fhir_traffic_log") | ||
#' conn <- connect_to_redcap_db() | ||
#' | ||
#' get_hipaa_disclosure_log_from_ehr_fhir_logs(conn) | ||
#' } | ||
get_hipaa_disclosure_log_from_ehr_fhir_logs <- function( | ||
conn, | ||
ehr_id = NA_real_, | ||
start_date = as.Date(NA)) { | ||
# make DBI objects for joins | ||
user_information <- dplyr::tbl(conn, "redcap_user_information") |> | ||
dplyr::select( | ||
"ui_id", | ||
"username" | ||
) | ||
|
||
projects <- dplyr::tbl(conn, "redcap_projects") |> | ||
dplyr::select( | ||
"project_id", | ||
"app_title", | ||
"project_pi_firstname", | ||
"project_pi_mi", | ||
"project_pi_lastname", | ||
"project_pi_email", | ||
"project_pi_alias", | ||
"project_irb_number" | ||
) | ||
|
||
disclosures <- dplyr::tbl(conn, "redcap_ehr_fhir_logs") |> | ||
dplyr::filter(.data$resource_type == "Patient" & .data$mrn != "") |> | ||
dplyr::left_join(user_information, by = c("user_id" = "ui_id")) |> | ||
dplyr::left_join(projects, by = c("project_id")) |> | ||
dplyr::collect() |> | ||
dplyr::mutate(disclosure_date = lubridate::floor_date(.data$created_at, unit = "day")) |> | ||
dplyr::select(-c("id", "created_at")) |> | ||
dplyr::distinct() |> | ||
dplyr::arrange(.data$disclosure_date) |> | ||
dplyr::rename(redcap_project_name = "app_title") |> | ||
dplyr::select( | ||
"disclosure_date", | ||
"fhir_id", | ||
"mrn", | ||
"project_irb_number", | ||
"project_pi_firstname", | ||
"project_pi_mi", | ||
"project_pi_lastname", | ||
"project_pi_email", | ||
"redcap_project_name", | ||
"username", | ||
dplyr::everything() | ||
) | ||
|
||
return(disclosures) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.23.0 | ||
1.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
library(redcapcustodian) | ||
library(dotenv) | ||
library(callr) | ||
library(argparse) | ||
|
||
set_script_run_time() | ||
|
||
parser <- ArgumentParser() | ||
parser$add_argument("script_name", help="Script to be run") | ||
parser$add_argument("optional_args", nargs='*', help="Zero or more optional arguments of any type") | ||
|
||
if (!interactive()) { | ||
args <- parser$parse_args() | ||
} else { | ||
args <- parser$parse_args( | ||
c( | ||
"study_template/etl/test_failure_alert.R", | ||
"test", | ||
"another test" | ||
) | ||
) | ||
} | ||
|
||
script_name <- args$script_name | ||
optional_args <- args$optional_args | ||
|
||
if(!fs::file_exists(script_name)) { | ||
stop(sprintf("Specified file, %s, does not exist", script_name)) | ||
} | ||
|
||
tryCatch({ | ||
if (length(optional_args) == 0) { | ||
rscript(script = script_name, stderr = "log.txt") | ||
} else { | ||
rscript(script = script_name, cmdargs = optional_args, stderr = "log.txt") | ||
} | ||
}, error = function(e) { | ||
email_body <- "See the attached log for error details." | ||
script_path <- paste(basename(getwd()), script_name, sep = "/") | ||
email_subject <- paste0("Failed | ", script_path, " | ", format(get_script_run_time(), "%Y-%m-%d")) | ||
file_name = "log.txt" | ||
|
||
send_email(email_body = email_body, email_subject = email_subject, file_name = file_name) | ||
}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
print("Hello, example host!") | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
# Test that the command line args are read | ||
print(paste0("This is a ", args[1])) | ||
print(paste0("This is ", args[2])) | ||
|
||
# This will fail as test.csv does not exist. | ||
read.csv("test.csv") | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Test email alert on script failure | ||
0 0 1 * * root /usr/bin/docker run --rm --env-file /rcc/study_template/.env rcc.site Rscript etl/run_etl.R etl/test_failure_alert.R test "another test" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
library(redcapcustodian) | ||
library(dotenv) | ||
library(callr) | ||
library(argparse) | ||
|
||
set_script_run_time() | ||
|
||
parser <- ArgumentParser() | ||
parser$add_argument("script_name", help="Script to be run") | ||
parser$add_argument("optional_args", nargs='*', help="Zero or more optional arguments of any type") | ||
|
||
if (!interactive()) { | ||
args <- parser$parse_args() | ||
} else { | ||
args <- parser$parse_args( | ||
c( | ||
"study_template/etl/test_failure_alert.R", | ||
"test", | ||
"another test" | ||
) | ||
) | ||
} | ||
|
||
script_name <- args$script_name | ||
optional_args <- args$optional_args | ||
|
||
if(!fs::file_exists(script_name)) { | ||
stop(sprintf("Specified file, %s, does not exist", script_name)) | ||
} | ||
|
||
tryCatch({ | ||
if (length(optional_args) == 0) { | ||
rscript(script = script_name, stderr = "log.txt") | ||
} else { | ||
rscript(script = script_name, cmdargs = optional_args, stderr = "log.txt") | ||
} | ||
}, error = function(e) { | ||
email_body <- "See the attached log for error details." | ||
script_path <- paste(basename(getwd()), script_name, sep = "/") | ||
email_subject <- paste0("Failed | ", script_path, " | ", format(get_script_run_time(), "%Y-%m-%d")) | ||
file_name = "log.txt" | ||
|
||
send_email(email_body = email_body, email_subject = email_subject, file_name = file_name) | ||
}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
print("Hello, example host!") | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
# Test that the command line args are read | ||
print(paste0("This is a ", args[1])) | ||
print(paste0("This is ", args[2])) | ||
|
||
# This will fail as test.csv does not exist. | ||
read.csv("test.csv") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.