I am trying to learn Capr package and have it help with phenotype February.
My goal is to create R code that creates the cohort that is exactly the same as cohort defined via GUI in Atlas.
So at the end, I will compare the json to be identical (or equivalent).
cohort_by_coding
“equals” cohort_by_gui
(either on SQL level or JSON level or any other means)
I want to recreate drug based cohorts in one gideline study (led by Kevin) (but it would apply in general to any study)
infliximab https://atlas-demo.ohdsi.org/#/cohortdefinition/1792089
adalimumab https://atlas-demo.ohdsi.org/#/cohortdefinition/1792086
golimumab https://atlas-demo.ohdsi.org/#/cohortdefinition/1792085
vedolizumab https://atlas-demo.ohdsi.org/#/cohortdefinition/1792094
tofacitinib https://atlas-demo.ohdsi.org/#/cohortdefinition/1792088
ustekinumab https://atlas-demo.ohdsi.org/#/cohortdefinition/1792087
methotrexate https://atlas-demo.ohdsi.org/#/cohortdefinition/1792092
natalizumab https://atlas-demo.ohdsi.org/#/cohortdefinition/1792098
certolizumab pegol https://atlas-demo.ohdsi.org/#/cohortdefinition/1792090
My first victim is the first cohort on the list.
https://atlas-demo.ohdsi.org/#/cohortdefinition/1792089/conceptsets
937368 infliximab
I am running into error in R. Any help is appreciated.
Capr::as.jason seem to be the key problem. I have not looked at the R code of that problem method and opted for community help.
library(Capr)
ch <- cohort(
entry = entry(
drugExposure(cs(descendants(937368),name='infliximab'))
),
exit = exit(endStrategy = observationExit())
)
#gives error
cohort_by_coding <- Capr::as.json(ch)
#Error: unable to find an inherited method for function ‘as.json’ for signature ‘x = "Cohort"’
#also give same error
#other later code (planned)
assertCohortCompiles(ch)
library(CirceR)
sessioninfo::package_info()
#cohort_by_gui = Fetch via API, for now, manually
sql_by_coding <- CirceR::buildCohortQuery(
expression = CirceR::cohortExpressionFromJson(ch),
options = CirceR::createGenerateOptions(generateStats = FALSE)
)
connectionDetails <- Eunomia::getEunomiaConnectionDetails()
cohortsToCreate <- tibble::tibble(cohortId = 1,cohortName = "one",sql = sql)
cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = "my_cohort_table")
CohortGenerator::createCohortTables(
connectionDetails = connectionDetails,
cohortDatabaseSchema = "main",
cohortTableNames = cohortTableNames
)
# Generate the cohorts
cohortsGenerated <- CohortGenerator::generateCohortSet(
connectionDetails = connectionDetails,
cdmDatabaseSchema = "main",
cohortDatabaseSchema = "main",
cohortTableNames = cohortTableNames,
cohortDefinitionSet = cohortsToCreate
)
@mdlavallee92 @Adam_Black
I need to read more the documentation to also replicate other parts of the cohort (e.g., cohort exist as end of continuous drug exposure)
I also anticipate the equivalence evaluation will not be easy (perhaps do it on R list level (and not as JSON).
The SQL generated is quite long and comparison will be tedious.