knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(PatientGenerator) library(shiny) library(testthat)
The PatientGenerator package provides an interactive Shiny application, patientDesigner(), to visually construct and edit synthetic patient datasets for the OMOP Common Data Model (CDM). This vignette demonstrates how to utilize the application to generate test data and integrate these datasets into a testthat suite.
To launch the interactive designer, execute the following command in the R console:
patientDesigner()
The application features:
Observation Period, Condition Occurrence, Drug Exposure, Measurement, and Procedure Occurrence.testthat IntegrationBy default, patientDesigner() searches for a tests/testthat/testCases directory within the current project. Clicking "Save Test Set" in the sidebar saves the JSON file directly to this location.
This facilitates a seamless development workflow:
1. Launch the application from the package root.
2. Visually design the test case.
3. Save the file (e.g., my_test_case.json).
4. The dataset is immediately available for unit testing.
testthatSaved test sets can be integrated into unit tests by loading them using the CDM constructor.
test_that("Custom test case behavior is correct", { # Locate the test case file relative to the tests/testthat directory test_file <- testthat::test_path("testCases", "my_test_case.json") # Instantiate the CDM constructor and load the JSON test set # Note: cdmConstructor is internal to PatientGenerator cdm <- PatientGenerator:::cdmConstructor$new() cdm$loadJsonTestSet(test_file) # Execute package logic using the synthetic data person_data <- cdm$person$data() expect_gt(nrow(person_data), 0) expect_equal(person_data$gender_concept_id[1], 8532) # Female })
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.