OHDSI / ROhdsiWebApi

An R package for interfacing with a WebAPI instance
https://ohdsi.github.io/ROhdsiWebApi
10 stars 17 forks source link

Error when exporting Json Expression from Atlas #255

Open eleroel opened 1 year ago

eleroel commented 1 year ago

In the ROhdsiWebApi documentation for getCohortDefinitionExpression, it says that this function has been deprecated. To obtain a definition expression, it is suggested to use the following: 1) cohortDefinition <- getCohortDefinition(baseUrl = baseUrl, cohortId = cohortId) 2) validJsonExpression <- RJSONIO::toJSON(cohortDefinition$expression) 3) save validJsonExpression object as .txt

However, when saving the cohortDefinition expression, concepts ids >10^8 are not saved properly, the number is rounded.

Here is an example:

library(here)
library(ROhdsiWebApi)
# atlas server
baseUrl <- "[https://atlas-demo.ohdsi.org/WebAPI"](https://atlas-demo.ohdsi.org/WebAPI%22)
# Atlas cohort Id
cohort_Id <- 1780634
# get the cohort definition
cohort  <- getCohortDefinition(baseUrl = baseUrl, cohortId = cohortId)
# get cohort name
name <- cohort$name
# get json expression
validJsonExpression <- RJSONIO::toJSON(cohort$expression)
# save in jsons files with the cohort name
fileConn<-file(paste0(name,".txt"))
writeLines(validJsonExpression, fileConn)
close(fileConn)

This cohort includes concepts Ids for measurements in LOINC vocabulary such as: • Detected, Concept ID: 45877985 • Positive, Concept ID: 45884084 • Present, Concept ID: 45879438 However in the json file generated using toJson, these concepts ids are: 45877990, 45884080, and 45879440, respectively.

gowthamrao commented 1 year ago

This cohort includes concepts Ids for measurements in LOINC vocabulary such as: • Detected, Concept ID: 45877985 • Positive, Concept ID: 45884084 • Present, Concept ID: 45879438 However in the json file generated using toJson, these concepts ids are: 45877990, 45884080, and 45879440, respectively

Looks like a numerical precision issue during transformation from list to json.

The issue is probably happening here

validJsonExpression <- RJSONIO::toJSON(cohort$expression)

try

validJsonExpression <- RJSONIO::toJSON(cohort$expression, digits = 23)

That should fix it

(i.e. its probably an issue of RJSONIO, not ROhdsiWEbApi)