growthcharts/jamesclient

Conversion to JSON string does not work for format 2.0

Closed this issue · 2 comments

There is a problem with the v2.0 format that prevents uploading a nicely formatted JSON string.

library(jamesclient)

fn1 <- system.file("extdata", "bds_v1.0", "smocc", "Laura_S.json", package = "jamesdemodata")
fn2 <- system.file("extdata", "bds_v2.0", "smocc", "Laura_S.json", package = "jamesdemodata")

js1a <- readLines(fn1)
js1b <- jsonlite::toJSON(jsonlite::fromJSON(fn1), auto_unbox = TRUE)
identical(js1a, js1b[1])
#> [1] TRUE

# works
resp1a <- request_chart(js1a)
resp1b <- request_chart(js1b)

js2a <- readLines(fn2)
js2b <- jsonlite::toJSON(jsonlite::fromJSON(fn2), auto_unbox = TRUE)
identical(js2a, js2b[1])
#> [1] FALSE

# works
resp2a <- request_chart(js2a)
# fails
resp2b <- request_chart(js2b)
#> Bad Request (HTTP 400).No encoding supplied: defaulting to UTF-8.

Created on 2021-11-24 by the reprex package (v2.0.1)

Might be related to https://stackoverflow.com/questions/58951351/how-to-remove-or-prevent-escape-slashes-from-json-file-data-in-azure-logic-app-w.

Direct call of james::draw_chart() yields the following:

library(james)
#> Loading required package: svglite

fn1 <- system.file("extdata", "bds_v1.0", "smocc", "Laura_S.json", package = "jamesdemodata")
fn2 <- system.file("extdata", "bds_v2.0", "smocc", "Laura_S.json", package = "jamesdemodata")

js1a <- readLines(fn1)
js1b <- jsonlite::toJSON(jsonlite::fromJSON(fn1), auto_unbox = TRUE)
identical(js1a, js1b[1])
#> [1] TRUE

resp1a <- draw_chart(js1a)
#> chartcode:  NMBH
resp1b <- draw_chart(js1b)
#> chartcode:  NMBH

js2a <- readLines(fn2)
js2b <- jsonlite::toJSON(jsonlite::fromJSON(fn2), auto_unbox = TRUE)
identical(js2a, js2b[1])
#> [1] FALSE

resp2a <- draw_chart(js2a)

#> chartcode:  NMBH
resp2b <- draw_chart(js2b)
#> Warning in `[<-.data.frame`(`*tmp*`, i, "bdsnummer", value = list(ElementNummer
#> = 82L, : provided 3 variables to replace 1 variables
#> BDS  82 (Zwangerschapsduur): Supplied: 110, Supplied type: list
#> BDS  63 (Geboortedatum ouder/verzorger) Onjuist format
#> Error in pp[pp$ElementNummer == 62L, "Waarde"]: incorrect number of dimensions

Created on 2021-11-25 by the reprex package (v2.0.1)

This is a problem in bdsreader::read_bds()so closing here.