OHDSI/ROhdsiWebApi

Error when exporting Json Expression from Atlas

Opened this issue · 1 comments

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.

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)