Skip to content

Commit 9cc6e00

Browse files
committed
Added initial version of drug utilization in children study code.
1 parent e878e2b commit 9cc6e00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1390
-0
lines changed

DrugsInPeds/.Rbuildignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
^\.travis\.yml$
2+
^.*\.Rproj$
3+
^\.Rproj\.user$
4+
documents

DrugsInPeds/.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# History files
2+
.Rhistory
3+
4+
# Example code in package build process
5+
*-Ex.R
6+
7+
# R data files from past sessions
8+
.Rdata
9+
.Rproj.user
10+
11+
R/TC
12+
statement_*.sql
13+
errorReport.txt
14+
15+
#C++ objects
16+
src/*.o
17+
src/*.so
18+
src/*.dll
19+
/Debug
20+
standalone/build/*

DrugsInPeds/DESCRIPTION

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Package: DrugsInPeds
2+
Title: Exploration of drug utilization in children
3+
Version: 0.1
4+
Author: Martijn J. Schuemie [aut, cre]
5+
Maintainer: Martijn J. Schuemie <[email protected]>
6+
Description: What the study does (paragraph)
7+
Depends:
8+
R (>= 3.1),
9+
DatabaseConnector (>= 1.2.1)
10+
Imports:
11+
SqlRender,
12+
DBI,
13+
mailR,
14+
OhdsiSharing
15+
Suggests:
16+
testthat
17+
License: Apache License 2.0
18+
LazyData: true

DrugsInPeds/DrugsInPeds.Rproj

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: No
4+
SaveWorkspace: No
5+
AlwaysSaveHistory: No
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 4
10+
Encoding: UTF-8
11+
12+
RnwWeave: knitr
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
18+
BuildType: Package
19+
PackageInstallArgs: --no-multiarch --with-keep.source
20+
PackageRoxygenize: rd,namespace

DrugsInPeds/NAMESPACE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Generated by roxygen2 (4.1.1): do not edit by hand
2+
3+
export(email)
4+
export(execute)
5+
export(getDefaultStudyEmailSubject)
6+
export(getDefaultStudyFileName)
7+
export(getDefaultStudyFolder)
8+
export(getDestinationAddress)

DrugsInPeds/R/FigureMockups.R

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2015 Observational Health Data Sciences and Informatics
2+
#
3+
# This file is part of DrugsInPeds
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
createMockupsForProtocol <- function(){
18+
library(ggplot2)
19+
20+
#data <- expand.grid(c("CDARS","JMDC","NHIRD", "AUSOM","CCAE"), c("<2","2-11","12-18"), c("A","B","C","D","G","H","J","L","M","N","P"))
21+
data <- expand.grid(c("CDARS","JMDC","NHIRD", "AUSOM","CCAE"), c("<2","2-11","12-18"), c("Alimentary","Blood","Cardiovascular","Dermatological","Genitourinary","Hormonal","Anti-infectives","Antineoplastic","Muscoskeletal","Nervous system","Antiparasitic drugs"))
22+
colnames(data) <- c("Database","Age","Class")
23+
data$Prevalence <- runif(nrow(data),0,100)
24+
25+
ggplot(data, aes(x = Age, y = Prevalence, group = Database, fill = Database)) +
26+
geom_bar(stat = "identity") +
27+
facet_grid(.~ Class) +
28+
theme(axis.text.x = element_text(angle=-90),
29+
strip.text.x = element_text(angle=-90))
30+
31+
ggsave("documents/mockup1.png", width = 9, height = 5, dpi= 200)
32+
33+
data <- expand.grid(c("CDARS","JMDC","NHIRD", "AUSOM","CCAE"), c("Male","Female"), c("Alimentary","Blood","Cardiovascular","Dermatological","Genitourinary","Hormonal","Anti-infectives","Antineoplastic","Muscoskeletal","Nervous system","Antiparasitic drugs"))
34+
colnames(data) <- c("Database","Gender","Class")
35+
data$Prevalence <- runif(nrow(data),0,100)
36+
37+
ggplot(data, aes(x = Gender, y = Prevalence, group = Database, fill = Database)) +
38+
geom_bar(stat = "identity") +
39+
facet_grid(.~ Class) +
40+
theme(axis.text.x = element_text(angle=-90),
41+
strip.text.x = element_text(angle=-90))
42+
43+
ggsave("documents/mockup2.png", width = 9, height = 5, dpi= 200)
44+
45+
46+
data <- expand.grid(c("CDARS","JMDC","NHIRD", "AUSOM","CCAE"), c("<2","2-11","12-18"), c("Alimentary","Blood","Cardiovascular","Dermatological","Genitourinary","Hormonal","Anti-infectives","Antineoplastic","Muscoskeletal","Nervous system","Antiparasitic drugs"), 2008:2014)
47+
colnames(data) <- c("Database","Age","Class", "Year")
48+
data$Prevalence <- runif(nrow(data),0,100)
49+
50+
ggplot(data, aes(x = Year, y = Prevalence, group = Database, color = Database)) +
51+
geom_line() +
52+
facet_grid(Class ~ Age) +
53+
theme(axis.text.x = element_text(angle=-90),
54+
strip.text.y = element_text(angle=0))
55+
56+
ggsave("documents/mockup3.png", width = 7, height = 8, dpi= 200)
57+
}

DrugsInPeds/R/StudyInvariant.R

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2015 Observational Health Data Sciences and Informatics
2+
#
3+
# This file is part of DrugsInPeds
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
#' @title Email results
18+
#'
19+
#' @details
20+
#' This function emails the result CSV files to the study coordinator.
21+
#'
22+
#' @return
23+
#' A list of files that were emailed.
24+
#'
25+
#' @param from Return email address
26+
#' @param to (Optional) Delivery email address (must be a gmail.com acccount)
27+
#' @param subject (Optional) Subject line of email
28+
#' @param dataDescription A short description of the database
29+
#' @param file (Optional) Name of local file with results; makee sure to use forward slashes (/)
30+
#'
31+
#' @export
32+
email <- function(from,
33+
to,
34+
subject,
35+
dataDescription,
36+
file) {
37+
38+
if (missing(from)) stop("Must provide return address")
39+
if (missing(dataDescription)) stop("Must provide a data description")
40+
41+
if (missing(to)) to <- getDestinationAddress()
42+
if (missing(subject)) subject <- getDefaultStudyEmailSubject()
43+
if (missing(file)) file <- getDefaultStudyFileName()
44+
45+
if(!file.exists(file)) stop(paste(c("No results file named '",file,"' exists"),sep = ""))
46+
47+
tryCatch({
48+
result <- mailR::send.mail(from = from,
49+
to = to,
50+
subject = subject,
51+
body = paste("\n", dataDescription, "\n",
52+
sep = ""),
53+
smtp = list(host.name = "aspmx.l.google.com",
54+
port = 25),
55+
attach.files = file,
56+
authenticate = FALSE,
57+
send = TRUE)
58+
if (result$isSendPartial()) {
59+
stop("Unknown error in sending email")
60+
} else {
61+
writeLines(c(
62+
"Sucessfully emailed the following file:",
63+
paste("\t", file, sep = ""),
64+
paste("to:", to)
65+
))
66+
}
67+
}, error = function(e) {
68+
writeLines(c(
69+
"Error in automatically emailing results, most likely due to security settings.",
70+
"Please manually email the following file:",
71+
paste("\t", file, sep = ""),
72+
paste("to:", to)
73+
))
74+
})
75+
}

0 commit comments

Comments
 (0)