library(ROhdsiWebApi)

This Vignettes describes how ROhdsiWebApi maybe used to work with cohorts in a WebApi. Please review ‘The Book of OHDSI’ chapter on Cohorts.

we define a cohort as a set of persons who satisfy one or more inclusion criteria for a duration of time. The term cohort is often interchanged with the term phenotype. Cohorts are used throughout OHDSI analytical tools and network studies as the primary building blocks for executing a research question.

A cohort is defined as the set of persons satisfying one or more inclusion criteria for a duration of time. One person may qualify for one cohort multiple times during non-overlapping time intervals. Cohorts are constructed in ATLAS by specifying cohort entry criteria and cohort exit criteria. Cohort entry criteria involve selecting one or more initial events, which determine the start date for cohort entry, and optionally specifying additional inclusion criteria which filter to the qualifying events. Cohort exit criteria are applied to each cohort entry record to determine the end date when the person’s episode no longer qualifies for the cohort.

In many cases, we would like to get a list of definitions that are published in WebApi. e.g. what are the list of cohort definitions in Atlas? - To get this metadata into R as a dataframe, we can use the function getMetadataForAllSpecifications(baseUrl) %>% dplyr::filter('cohortDefinitions') . We can then use dplyr functions to filter to the cohorts that we are interested in. WebApi uniquely identifies every cohort definition by an integer id - called cohort id. Cohort Names are also unique within WebApi.

Once we know the cohort id’s we are interested in, we can extract the expression of the cohort specification. WebApi stores specifications as JSON objects. We can use getCohortDefinition(baseUrl = baseUrl, cohortId = 3424). Note this will be R-objects (not JSON). We follow a generic design pattern where all objects either returned or used by the package are standard R-objects like list, data frame, vector etc. If you want to see the JSON expression we can You will have to convert it into JSON as in this getCohortDefinition(baseUrl = baseUrl, cohortId = 3424)$expression %>% RJSONIO::toJSON(pretty = TRUE).

We may want to know if a certain cohort specification has been generated by checking cohort generation status getCohortGenerationStatuses(baseUrl, definitionIds= c(4234, 43242)). If a cohort is not previously generated, it may be generated using invokeCohortSetGeneration(baseUrl, definitionId = c(4234)) . If it is already generated, we can extract its output of cohort generation using getCohortGenerationOutput(baseUrl, cohortId = 4234).

Many times we may want to move a cohort definition from one instance to another. To add an existing cohort specification expression in R into another WebApi instance we can postSpecification(baseUrl = newBaseUrl, name = 'This is new name', type = 'cohort', object = expression . To delete a cohort definition deleteCohortDefinition(cohortId = 4234, baseUrl = baseUrl).