OHDSI / Capr

Cohort definition Application Programming in R
https://ohdsi.github.io/Capr
Apache License 2.0
15 stars 11 forks source link

Feature Request: Convert Cohort Expression JSON from ATLAS to Capr Object for Programmatic Modifications #101

Open gowthamrao opened 1 month ago

gowthamrao commented 1 month ago

I have a use case where I need to programmatically modify a set of existing cohort definitions that are already defined in ATLAS (e.g., OHDSI Phenotype Library). Specifically, I would like to modify around 100+ cohort definitions by doing things like:

Capr seems like a fantastic tool for achieving this, but to proceed, I first need to convert an existing cohort expression from ATLAS into a Capr object. Currently, it appears there is no straightforward way to achieve this conversion.

Reproducible Code Example:

Here’s an example of what I’m trying to do. I want to convert the cohort definition to a Capr object, programmatically modify it, and post it back into Atlas:

Steps:

baseUrl <- "https://atlas-demo.ohdsi.org/WebAPI"

# Retrieve the cohort definition from ATLAS, which includes metadata like the cohort name
cohortDefinition <- ROhdsiWebApi::getCohortDefinition(cohortId = 1790465, baseUrl = baseUrl)

# Extract only the cohort expression component as a list from cohortDefinition
cohortExpressionList <- cohortDefinition$expression

# Convert the expression to JSON
cohortExpressionJson <- cohortExpressionList |> RJSONIO::toJSON(digits = 23)

# stuck - should cohortExpressionJson be converted to Capr object?

Feature Request: asCapr

Could a function be added to Capr that allows for the conversion of a cohort expression JSON (retrieved from ATLAS via WebAPI) into a Capr object, such as 'asCapr'? This would enable users to leverage Capr’s powerful programmatic interface to modify existing cohort definitions easily.

# This is the step where I would like to convert the JSON to a Capr object, but there is no function like 'asCapr'
cohortExpressionCapr <- Capr::asCapr(cohortExpressionJson)

Thank you for considering this feature request!

Gowtham

mdlavallee92 commented 1 week ago

Yes this feature needs to be added. It was in an older version of Capr. Will need some time to implement it