writing to SMART on FHIR and unable to search for new entry

193 views
Skip to first unread message

Lyn Franklin

unread,
Nov 28, 2016, 10:30:53 PM11/28/16
to SMART on FHIR
I am working on adding an observation to our own SMART on FHIR sandbox.  It appears that it is being added to the server.  I receive a message that it is successful, and I can use a get with the observation id to retrieve the entry.  However, if I search on the patient id or the loinc code, the entry is not retrieved.  I have tried to play around with the json to see if maybe I am missing a required field, but I'm now out of ideas.  This is the json data that I am currently writing:

            var ob_data = {
                "resourceType": "Observation",
                "meta": {
                  "versionId": "1",
                  "lastUpdated": new Date(),
                  "security": [
                    {
                      "system": "http://smarthealthit.org/security/users",
                      "code": "Patient/" + patientId
                    },
                    {
                      "system": "http://smarthealthit.org/security/categories",
                      "code": "vital-signs"
                    }
                  ]
                },
                "text": {
                    "status": "generated",
                    "div": '<div xmlns=\"http://www.w3.org/1999/xhtml\">2016-11-28: weight = 65 kg</div>'
                },
                "status": "final",
                "category": {
                  "coding": [
                    {
                      "system": "http://hl7.org/fhir/observation-category",
                      "code": "vital-signs",
                      "display": "Vital Signs"
                    }
                  ],
                  "text": "Vital Signs"
                },
                "code": {
                    "coding": [
                        {
                            "system": "http://loinc.org",
                            "code": "3141-9",
                            "display": "weight"
                        }
                    ],
                    "text": "weight"
                },
                "effectiveDateTime":new Date(),
                "valueQuantity": {
                    "value": 65,
                    "units": "kg",
                    "system": "http://unitsofmeasure.org/",
                    "code": "kg"
                },
                "reliability": "ok",
                "subject": {"reference": "Patient/" + patientId},
                "search" : {
                   "mode" : "match"
                }
            };

Here is my post command:
            var ob_url = serviceUri + "/Observation";
            $.ajax({
                type: "POST",
                url: ob_url,
                headers: {
                    "Accept": "application/json",
                    "Authorization":"Bearer "+ accessToken
                },
                data: JSON.stringify(ob_data),
                contentType: 'application/json+fhir;charset=utf-8'
            }).done(function(data) {
                document.body.innerHTML += "<h4>Observation Added</h4>";
                document.body.innerHTML += "<h4>" + JSON.stringify(data) + "</h4>";
            }).error(function(request, status, error) {
                alert(request.responseText);
            });

And here is my search to retrieve it (And I also look at the FHIR demo app):
            //var r_url = serviceUri + "/Observation?subject%3APatient=" + patientId;
            //var r_url = serviceUri + "/Observation?code=3141-9";
            var r_url = serviceUri + "/Observation/254845";
            $.ajax({
                url: r_url,
                type: "GET",
                dataType: "json",
                headers: {
                    "Accept": "application/json",
                    "Authorization": "Bearer " + accessToken
                },
            }).done(function(data){
                document.body.innerHTML += "<h4>Observation Retrieve</h4>";
                document.body.innerHTML += "<h4>" + JSON.stringify(data) + "</h4>";
            });


Does anyone have an idea on what I have incorrect?

Nikolai Schwertner

unread,
Nov 28, 2016, 11:10:41 PM11/28/16
to smart-...@googlegroups.com
Is your SMART on FHIR sandbox based on the SMART on FHIR reference implementation or another implementation? Have you tried adding your observation to the public unprotected FHIR server at https://fhir-open-api-dstu2.smarthealthit.org for comparison?

I tried your object template against the unprotected FHIR server like this:

curl 'https://fhir-open-api-dstu2.smarthealthit.org/Observation?' -H 'Content-Type: application/json+fhir' -X POST --data-binary @test.json

and it worked out for me. I was able to retrieve the object back using these requests:

http://fhir-open-api-dstu2.smarthealthit.org/Observation/583cfd740cf2f33f50c5d086
http://fhir-open-api-dstu2.smarthealthit.org/Observation?code=http%3A%2F%2Floinc.org%7C3141-9&patient=1288992
--
You received this message because you are subscribed to the Google Groups "SMART on FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smart-on-fhi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Lyn Franklin

unread,
Nov 29, 2016, 5:50:21 AM11/29/16
to SMART on FHIR

Nikolai,

Yes my SMART on FHIR sandbox is based on the SMART on FHIR reference implementation.

I have not tried adding it to the unprotected FHIR server.  I just clicked your links but I don't see the objects.  Does the open server delete newly added objects quickly? I'll have to try adding it there tonight.

Josh Mandel

unread,
Nov 29, 2016, 8:02:47 AM11/29/16
to Lyn Franklin, SMART on FHIR

Also a quick note that the "meta" values you're populating should be left out of your post (our server should ignore most of these and populate them itself), and the "search" property is invalid in this context (perhaps you've copied it from a Bundle.entry? But it doesn't belong on an Observation).


--
You received this message because you are subscribed to the Google Groups "SMART on FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smart-on-fhir+unsubscribe@googlegroups.com.

Nikolai Schwertner

unread,
Nov 29, 2016, 8:03:26 AM11/29/16
to smart-...@googlegroups.com
Yes, the open server resets at least once every 24 hours.
--
You received this message because you are subscribed to the Google Groups "SMART on FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smart-on-fhi...@googlegroups.com.

Lyn Franklin

unread,
Nov 29, 2016, 2:25:37 PM11/29/16
to SMART on FHIR
I saw Nikolai used both the code and patient in the search so I tried that, and the SMART on FHIR server that I'm using returned all the entries that I had added.  If I just search on patient, I don't see them, but there are a lot of other observations that are returned.  So I'm guessing that somewhere there is a limit on the response size.  Is there a limit within SMART on FHIR? The FHIR demo app is returning the same limited amount of data so I don't think it's my GET command.  But maybe there's a server configuration that affects it. 

Josh Mandel

unread,
Nov 29, 2016, 2:39:50 PM11/29/16
to Lyn Franklin, SMART on FHIR
You're probably getting paginated results. Our server will return up to 50 results per page, by default. But a client can keep asking for the "next page" until all results are retrieved. See http://hl7.org/fhir/http.html#paging for details!

On Tue, Nov 29, 2016 at 2:25 PM, Lyn Franklin <l_m_k...@hotmail.com> wrote:
I saw Nikolai used both the code and patient in the search so I tried that, and the SMART on FHIR server that I'm using returned all the entries that I had added.  If I just search on patient, I don't see them, but there are a lot of other observations that are returned.  So I'm guessing that somewhere there is a limit on the response size.  Is there a limit within SMART on FHIR? The FHIR demo app is returning the same limited amount of data so I don't think it's my GET command.  But maybe there's a server configuration that affects it. 

--
You received this message because you are subscribed to the Google Groups "SMART on FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smart-on-fhir+unsubscribe@googlegroups.com.

Nikolai Schwertner

unread,
Nov 29, 2016, 2:47:21 PM11/29/16
to smart-...@googlegroups.com
Exactly right. FHIR servers are allowed to return a subset of the results even if you don't specify any limits for efficiency reasons. If the response is a subset, it will contain a link to the next "chunk" of data that you can follow. Some client libraries, such as the SMART JS client, implement "fetchAll" accessory methods which recurse through the chunks and assemble the results in a single object for your convenience at the risk of meltdown in the event the results set is extraordinarily large and there are no decent protection mechanisms implemented at the server and/or client level.

-Nikolai


On 11/29/16 14:25, Lyn Franklin wrote:
I saw Nikolai used both the code and patient in the search so I tried that, and the SMART on FHIR server that I'm using returned all the entries that I had added.  If I just search on patient, I don't see them, but there are a lot of other observations that are returned.  So I'm guessing that somewhere there is a limit on the response size.  Is there a limit within SMART on FHIR? The FHIR demo app is returning the same limited amount of data so I don't think it's my GET command.  But maybe there's a server configuration that affects it. 
--
You received this message because you are subscribed to the Google Groups "SMART on FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smart-on-fhi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages