Skip to content

Commit

Permalink
Merge pull request #174 from OHDSI/mah_mockPhenotypeR
Browse files Browse the repository at this point in the history
Create mockPhenotypeR() and use it in function examples
  • Loading branch information
edward-burn authored Dec 14, 2024
2 parents 56e29f8 + b71b91b commit f030438
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 248 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Suggests:
shinyWidgets,
plotly,
tidyr,
ggpol,
scales
Config/testthat/edition: 3
RoxygenNote: 7.3.2
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(databaseDiagnostics)
export(exportSummarisedResult)
export(importSummarisedResult)
export(matchedDiagnostics)
export(mockPhenotypeR)
export(phenotypeDiagnostics)
export(populationDiagnostics)
export(settings)
Expand Down
16 changes: 2 additions & 14 deletions R/addCodelistAttribute.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,11 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(PhenotypeR)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 100) |>
#' mockObservationPeriod() |>
#' mockCohort()
#' cdm <- mockPhenotypeR()
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#'
#' cohort <- addCodelistAttribute(cohort = cdm$cohort, codelist = list("cohort_1" = 1L))
#' cohort <- addCodelistAttribute(cohort = cdm$my_cohort, codelist = list("cohort_1" = 1L))
#' attr(cohort, "cohort_codelist")
#'
#' CDMConnector::cdm_disconnect(cdm)
Expand Down
17 changes: 2 additions & 15 deletions R/codelistDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,16 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(CohortConstructor)
#' library(PhenotypeR)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 100) |>
#' mockObservationPeriod() |>
#' mockConditionOccurrence()
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#' cdm <- mockPhenotypeR()
#'
#' cdm$arthropathies <- conceptCohort(cdm,
#' conceptSet = list("arthropathies" = c(40475132)),
#' name = "arthropathies")
#'
#' result <- cdm$arthropathies |>
#' codelistDiagnostics()
#' result <- codelistDiagnostics(cdm$arthropathies)
#'
#' CDMConnector::cdmDisconnect(cdm = cdm)
#' }
Expand Down
18 changes: 2 additions & 16 deletions R/cohortDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,11 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(PhenotypeR)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 100) |>
#' mockObservationPeriod() |>
#' mockConditionOccurrence() |>
#' mockVisitOccurrence() |>
#' mockCohort(name = "my_cohort")
#' cdm <- mockPhenotypeR()
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#'
#' cdm$my_cohort |> cohortDiagnostics()
#' result <- cohortDiagnostics(cdm$my_cohort)
#'
#' CDMConnector::cdmDisconnect(cdm = cdm)
#' }
Expand Down
23 changes: 4 additions & 19 deletions R/databaseDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,12 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(PhenotypeR)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 100) |>
#' mockObservationPeriod() |>
#' mockConditionOccurrence() |>
#' mockDrugExposure() |>
#' mockObservation() |>
#' mockMeasurement() |>
#' mockCohort(name = "my_cohort", numberCohorts = 2)
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#'
#' db_diag <- databaseDiagnostics(cdm)
#' cdm <- mockPhenotypeR()
#'
#' result <- databaseDiagnostics(cdm)
#'
#' CDMConnector::cdmDisconnect(cdm = cdm)
#' }
databaseDiagnostics <- function(cdm){
Expand Down
21 changes: 2 additions & 19 deletions R/matchedDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,12 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(PhenotypeR)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 100) |>
#' mockObservationPeriod() |>
#' mockConditionOccurrence() |>
#' mockDrugExposure() |>
#' mockObservation() |>
#' mockMeasurement() |>
#' mockVisitOccurrence() |>
#' mockProcedureOccurrence() |>
#' mockCohort(name = "my_cohort")
#' cdm <- mockPhenotypeR()
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#' result <- matchedDiagnostics(cdm$my_cohort)
#'
#' result <- cdm$my_cohort |> matchedDiagnostics()
#' CDMConnector::cdmDisconnect(cdm = cdm)
#' }
matchedDiagnostics <- function(cohort,
Expand Down
55 changes: 55 additions & 0 deletions R/mockPhenotypeR.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' Function to create a mock cdm reference for mockPhenotypeR
#'
#' @description
#' `mockPhenotypeR()` creates an example dataset that can be used to show how
#' the package works
#'
#' @param nPerson number of people in the cdm.
#' @param con A DBI connection to create the cdm mock object.
#' @param writeSchema Name of an schema on the same connection with writing
#' permissions.
#' @param seed seed to use when creating the mock data.
#'
#' @return cdm object
#' @export
#'
#' @examples
#' \donttest{
#' library(PhenotypeR)
#'
#' cdm <- mockPhenotypeR()
#'
#' cdm
#' }
mockPhenotypeR <- function(nPerson = 100,
con = DBI::dbConnect(duckdb::duckdb()),
writeSchema = "main",
seed = 111){

omopgenerics::assertNumeric(nPerson, length = 1, na = FALSE, null = FALSE)
omopgenerics::assertNumeric(seed, length = 1, na = FALSE, null = FALSE)
omopgenerics::assertCharacter(writeSchema, length = 1, na = FALSE, null = FALSE)

cdm_local <- omock::mockCdmReference() |>
omock::mockPerson(nPerson = 100, seed = seed) |>
omock::mockObservationPeriod(seed = seed) |>
omock::mockConditionOccurrence(seed = seed) |>
omock::mockVisitOccurrence(seed = seed) |>
omock::mockDrugExposure(seed = seed) |>
omock::mockObservation(seed = seed) |>
omock::mockMeasurement(seed = seed) |>
omock::mockProcedureOccurrence(seed = seed) |>
omock::mockCohort(name = "my_cohort", numberCohorts = 2)

cdm <- CDMConnector::copy_cdm_to(con = con,
cdm = cdm_local,
schema = writeSchema,
overwrite = TRUE)
attr(cdm, "write_schema") <- writeSchema

return(cdm)
}




21 changes: 2 additions & 19 deletions R/phenotypeDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,12 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(PhenotypeR)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 100) |>
#' mockObservationPeriod() |>
#' mockConditionOccurrence() |>
#' mockDrugExposure() |>
#' mockObservation() |>
#' mockMeasurement() |>
#' mockVisitOccurrence() |>
#' mockProcedureOccurrence() |>
#' mockCohort(name = "my_cohort")
#' cdm <- mockPhenotypeR()
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#' result <- phenotypeDiagnostics(cdm$my_cohort)
#'
#' result <- cdm$my_cohort |> phenotypeDiagnostics()
#' CDMConnector::cdmDisconnect(cdm = cdm)
#' }
phenotypeDiagnostics <- function(cohort,
Expand Down
20 changes: 2 additions & 18 deletions R/populationDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,10 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(PhenotypeR)
#' library(dplyr)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 1000) |>
#' mockObservationPeriod() |>
#' mockConditionOccurrence() |>
#' mockDrugExposure() |>
#' mockObservation() |>
#' mockMeasurement() |>
#' mockVisitOccurrence() |>
#' mockCohort(name = "my_cohort")
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#' cdm <- mockPhenotypeR()
#'
#' dateStart <- cdm$my_cohort |>
#' summarise(start = min(cohort_start_date, na.rm = TRUE)) |>
Expand All @@ -46,6 +29,7 @@
#'
#' result <- cdm$my_cohort |>
#' populationDiagnostics(populationDateRange = c(dateStart, dateEnd))
#'
#' CDMConnector::cdmDisconnect(cdm = cdm)
#' }
populationDiagnostics <- function(cohort,
Expand Down
23 changes: 2 additions & 21 deletions R/shinyDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,11 @@
#'
#' @examples
#' \donttest{
#' library(omock)
#' library(CDMConnector)
#' library(DBI)
#' library(PhenotypeR)
#'
#' cdm_local <- mockCdmReference() |>
#' mockPerson(nPerson = 1000) |>
#' mockObservationPeriod() |>
#' mockConditionOccurrence() |>
#' mockDrugExposure() |>
#' mockObservation() |>
#' mockMeasurement() |>
#' mockVisitOccurrence() |>
#' mockProcedureOccurrence() |>
#' mockCohort(name = "my_cohort")
#' cdm <- mockPhenotypeR()
#'
#' con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
#' cdm <- CDMConnector::copy_cdm_to(con = con,
#' cdm = cdm_local,
#' schema = "main")
#' attr(cdm, "write_schema") <- "main"
#'
#' result <- cdm$my_cohort |>
#' phenotypeDiagnostics()
#' result <- phenotypeDiagnostics(cdm$my_cohort)
#'
#' shinyDiagnostics(result, tempdir())
#'
Expand Down
3 changes: 3 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ reference:
- subtitle: Codelist diagnostics helper
- contents:
- matches("addCodelistAttribute")
- subtitle: Mock data
- contents:
- matches("mockPhenotypeR")
2 changes: 1 addition & 1 deletion man/PhenotypeR-package.Rd

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

10 changes: 7 additions & 3 deletions man/addCodelistAttribute.Rd

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

22 changes: 8 additions & 14 deletions man/codelistDiagnostics.Rd

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

Loading

0 comments on commit f030438

Please sign in to comment.