Chicago / lead-safe-api-docs

http://dev.cityofchicago.org/docs/lead-safe/
1 stars 1 forks source link

Response JSON includes extra quotes #45

Closed tomschenkjr closed 6 years ago

tomschenkjr commented 6 years ago

@AOCjcarr mentioned he is seeing the following:

In the result segment, there is an extra set of quotes around the remaining elements that is causing the entire result section to be seen as a string. The validate result should be:


{
"items": [
{
"result": {
"risk_score_notes": "1. Please follow protocol for lead safety.",
"errors": [
    ],
    "network_id": "AllianceChicago",
    "timestamp": "2018-05-08 15:19:05",
    "clinic_id": "NN",
    "patient_id": "240049",
    "risk_score": "0.182835714286",
    "version": "1.0.0-rc.3",
    "location_id": "NNHS"
  }
}

] }



@geneorama - can you replicate this?
geneorama commented 6 years ago

@tomschenkjr I think you missed the quotes that @AOCjcarr was talking about?

When I run the Curl command directly I get (for example) {"items":[{"result":"{\"risk_score_notes\": \"1. Please follow protocol for lead safety.\", \"errors\": [], \"network_id\": \"Alliance Health\", \"timestamp\": \"2018-05-10 14:47:56\", \"clinic_id\": \"EF\", \"patient_id\": \"6425\", \"risk_score\": \"0.190358333333\", \"version\": \"1.0.0-rc.3\", \"location_id\": \"examp_loc\"}"}]}

I think the problem is the quotes that start after "result" in between the colon and the curly brace

{"items":[{"result":"{\"risk_score...
                    ^

and ends at the second to last curly brace:

": \"examp_loc\"}"}]}
                 ^

It seems to start early in our process. The result string is stored as a JSON string in the tbl_lead_out (sorry for the jargon everyone), and the quotes and internally escaped quotes are necessary to pass the string between python and the database. (I think this issue is strongly related to #44)

geneorama commented 6 years ago

The problem is that we need to put the result into a table of separate fields, not as a single precomposed JSON string.

So if you have the table, the JSON is returned properly. Within Sun's code, the statement is more like "select * where id=", rather than "select result where id=".

Here is an example of a good result with dummy data: image

And here is the underlying table: image

This is actually a pretty big change (although maybe not very complicated), which will help with logging and other down the road steps.

@tomschenkjr what do you think about implementing this? Maybe we can talk offline later?

geneorama commented 6 years ago

Great news, Sun seems to have a working solution in dev, which we can probably get into production tomorrow.

The return for the new version looks like this:

{"risk_score_notes": "1. Please follow protocol for lead safety.", "errors": [], "network_id": "Alliance Health", "timestamp": "2018-05-21 21:16:39", "clinic_id": "EF", "patient_id": "6425", "risk_score": "0.190358333333", "version": "1.0.0-rc.3", "location_id": "examp_loc"}

So, the JSON is no longer enclosed in "items" and "result". Looking at the documentation, I think this is actually what we specified in the first place. @AOCjcarr do you think this will work for you or are you expecting the top level wrapper fields? (not sure what to call them)

Note, this new version will be release candidate 4 (v1.0.0-rc.4)

geneorama commented 6 years ago

Jeremy has replied to say that the issue is resolved through the changes Sun made.