How do I send data to the platfrom

645 views
Skip to first unread message

Paul Marriott

unread,
Mar 4, 2015, 9:27:19 PM3/4/15
to smart-...@googlegroups.com
looking at the docs they all show how to get data and launch apps but nothing about sending data. Is the import also fhir or do I have to hack the database instead?

Cheers

Paul

Josh Mandel

unread,
Mar 4, 2015, 10:34:32 PM3/4/15
to Paul Marriott, smart-...@googlegroups.com
Hi Paul,

Great question! The answer boils down to "yes we support writes, but..." :-)

So here's the deal: SMART on FHIR uses the FHIR REST API to allow apps to communicate with an EHR system. As such, the API itself provides support for reading as well as writing data. So you'll see, for example, in our permission model that an app can ask for read-only permissions like "patient/Observation.read" (which allows an app to read all observations about the patient-in-context), or an app can ask for write permissions like "patient/Observation.write" (or "patient/Observation.*", which is read + write together).

Now in the real world, and especially early on in the adoption curve, we expect that most EHRs will have much better support for read access. So if you're looking at building an application that runs in as many places as possible, it's definitely best to think about limiting your access to read-only. (We expect that EHRs will begin to support writes very cautiously, perhaps into some kind of scratchpad area that requires end-user curation before being fully incorporated into a patient's record. This is an area we're excited to explore with willing vendors.)

That said, SMART's reference server supports writing data to the system. Indeed, that's how we bootstrap our own server: by POSTing patient records to server using a FHIR "transaction" interaction. So if you're interested in running your own copy of our reference stack, for development/debugging purposes, you can install a copy of our server locally and just POST to it to store your own data. 

(As it turns out, our public sandbox also supports write access -- but we don't make any guarantees that we'll keep your data around for very long. We reset the state or our public sandbox periodically to maintain a working environment. If you're interested in contributing permanent sample data to our default pool, so that is persists across resets, we're happy to accept contributions via https://github.com/smart-on-fhir/sample-patients .)

Hope that helps,

  Josh


Paul

--
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.

Bao Pham

unread,
Jul 14, 2015, 1:06:00 AM7/14/15
to smart-...@googlegroups.com, paulma...@gmail.com
Hi Josh,

When will this be implemented?

Josh Mandel

unread,
Jul 14, 2015, 7:35:47 AM7/14/15
to Bao Pham, smart-...@googlegroups.com, Paul Marriott

Hi Bob,

We haven't gotten around to adding write functionality in our client library for a couple of reasons:

1. We have been cautious to add features that we don't think will be widely supported on the EHR server side.

2. We have been considering whether to swap out our client library for fhir.js around the DSTU2 time frame.

That said, hearing from the user community is the most important way that we make informed decisions! And of course we are always happy to accept code contributions :-)

Josh

Bao Pham

unread,
Jul 14, 2015, 1:39:22 PM7/14/15
to smart-...@googlegroups.com, b...@appnovation.com, paulma...@gmail.com
Thank you for the response. As for #2, do you recommend that we use fhir.js (https://github.com/FHIR/fhir.js) now? A quick look at the JS, it looks like it supports POST and PUT. Is there anything we should be aware of in terms the difference between this JS client and the smart-on-fhir JS client?

Josh Mandel

unread,
Jul 14, 2015, 3:22:47 PM7/14/15
to Bao Pham, smart-...@googlegroups.com, paulma...@gmail.com

The fhir.js client doesn't currently handle the details of obtaining authorization from a SMART server. SMART's client has this built in. Ideally We'd extract two components, one for doing the authorization and one for making API calls. Then fhir.js could be used as an option for the latter.

-Josh

Lars Kristian Roland

unread,
Aug 19, 2015, 4:45:23 AM8/19/15
to SMART on FHIR, b...@appnovation.com, paulma...@gmail.com
In case posting to SMART on FHIR is still of interest, here's some code I hacked together to get it to work. Using fhir.js was a bit complicated for me because of the lack of examples, though probably if I took to the time to understand it, it'd be great. 

Here's from my code (You can see the whole file here https://bitbucket.org/snippets/larsie/89XAE/angular-controller-using-smart-on-fhir

The code may have some issues, but it was for a quick demo. 
...

FHIR.oauth2.ready(function (smart) {
            $scope.token = smart.server.auth.token; // This is Angular-code. If pure Javascript, you could use a normal var instead of $scope
...
further down.
...
$scope.saveData = function (pId, weight) {
            $scope.message = 'Saving data';

            console.log("inside getObservations:"+$scope.smart);

            var json = {
                "resourceType": "Observation",
                "text": {
                    "status": "generated",
                    "div": '<div xmlns=\"http://www.w3.org/1999/xhtml\">' + weight + ' kg</div>'
                },
                "code": {
                    "coding": [
                        {
                            "system": "http://loinc.org",
                            "code": "3141-9",
                            "display": "weight"
                        }
                    ]
                },
                "appliesDateTime":new Date(),
                "valueQuantity": {
                    "value": weight,
                    "units": "kg",
                    "system": "http://unitsofmeasure.org/",
                    "code": "kg"
                },
                "reliability": "ok",
                "subject": {"reference": "Patient/" + pId}
            };

            $.ajax({
                type: "POST",
                url: FHIR_URL + '/Observation',
                headers: {
                    "Authorization":"Bearer "+$scope.token
                },
                data: JSON.stringify(json),
                success: function (data) {
                    $scope.$apply(function () {
                        $scope.message = 'Data sent';
                        //$scope.search();
                        $scope.getObservations();
                    });
                },
                datatype: 'json',
                contentType: 'application/json+fhir;charset=utf-8'
            });


        };


Message has been deleted
Message has been deleted

aly.mohamm...@gmail.com

unread,
Dec 9, 2015, 9:59:10 PM12/9/15
to SMART on FHIR, b...@appnovation.com, paulma...@gmail.com
Thanks a lot Lars for the very informative post.
Me too was trying to use the
patient.api.update()

but did not succeed. so I though of using the raw ajax to do this within a javascript/jquery code. kindly find below the code, it is supposed to be generic enough to accept various resource types, as it parse the resource it self for the "type" attribute and then adding to the "resource.subject.reference" to add the patient ID. Also it get the url from the "smart" object rather than hard coding it within the function, so it can be used within different scripts with less modifications. Then some parsing for the response XML for the newly allocated "resource.id" and meta information. Then it suppose to return the updated resource with this information.
note: I was getting error when tried to embed the fhir server url, but when I get it from the smart object it was working fine.

The key question: is this the optimal method to "update" a fhir resource using SMART on FHIR? If not, so where we can find the optimal way?

Thanks again Lars and thanks for the whole SMART on FHIR team, actually SMART on FHIR makes it easier to develop apps and to foster systems interoperability.

//getting the FHIR server url
var url = smart.server.serviceUrl;
//getting the token
var token = smart.server.auth.token;
//function to be called as postToFHIR(paitentID, jsonFhirResource)
var postToFHIR = function (patientID, resJson) {
   
    resJson
.subject = {
       
"reference": "Patient/" + patientID
   
},
    $
.ajax({
        type
: "POST",
        url
: url + '/' + resJson.resourceType,
        headers
: {
           
"Authorization": "Bearer " + token
       
},
        data
: JSON.stringify(resJson),
        success
: function (data) {
           
Console.log('the Resource was POSTed Successfully');
           
var xmlString = (new XMLSerializer()).serializeToString(data);
           
//Parsing the response XML for the newly assigned resource.id, meta.versionid and meta.lastUpdated
           
var xmlDoc = $.parseXML(xmlString),
            $xml
= $(xmlDoc),
            $idValue
= $xml.find("id").attr('value'),
            $versionIdValue
= $xml.find("versionId").attr('value'),
            $lastUpdatedValue
= $xml.find("lastUpdated ").attr('value');
           
//the following can be used to log to the console some of the retrieved response data
           
//console.log($idValue);
           
//console.log($versionIdValue);
           
//console.log($lastUpdatedValue);
           
//adding the new information to the input resource and returning it
            resJson
.id = $idValue;
            resJson
.meta = {
                versionId
: $versionIdValue,
                lastUpdated
: $lastUpdatedValue
           
};
           
return resJson;

       
},
        datatype
: 'json',
        contentType
: 'application/json+fhir;charset=utf-8'
   
});
};

Nikolai Schwertner

unread,
Dec 9, 2015, 10:02:34 PM12/9/15
to smart-...@googlegroups.com
See https://github.com/smart-on-fhir/sample-apps/tree/master/write for an example that uses the JS client

aly.mohamm...@gmail.com

unread,
Dec 10, 2015, 12:46:22 AM12/10/15
to SMART on FHIR
thanks a lot, that was so fast. I'll check it !

aly.mohamm...@gmail.com

unread,
Dec 10, 2015, 1:38:30 AM12/10/15
to SMART on FHIR
Thanks a lot, I adapted it for my use case and it worked great.
Appreciating so much your effort and time.



On Wednesday, December 9, 2015 at 8:02:34 PM UTC-7, Nikolai Schwertner wrote:
...

Phil Oxenberg

unread,
Jan 26, 2016, 11:22:42 AM1/26/16
to SMART on FHIR
Thank you very much.  Would you mind posting your launch.html file?
Thanks.


On Wednesday, August 19, 2015 at 2:45:23 AM UTC-6, Lars Kristian Roland wrote:

Nikolai Schwertner

unread,
Jan 26, 2016, 8:01:06 PM1/26/16
to smart-...@googlegroups.com
Here is a complete example of creating and updating a resource using the fhir.js methods:
https://github.com/smart-on-fhir/sample-apps/tree/master/write

Adrian Gropper

unread,
Jan 26, 2016, 9:39:23 PM1/26/16
to Nikolai Schwertner, SMART on FHIR
I'm not yet involved in SMART on FHIR development but hope to be in the coming months. FHIR is, I assume, a symmetrical protocol. For every FHIR data server there's a FHIR data client and, as far as FHIR is concerned, both the server and the destination might be EHRs. How does SMART on FHIR differ from just FHIR, particularly in the context of a single patient transaction?

Adrian
--

Adrian Gropper MD

PROTECT YOUR FUTURE - RESTORE Health Privacy!
HELP us fight for the right to control personal health data.

DONATE: http://patientprivacyrights.org/donate-2/

Josh Mandel

unread,
Jan 26, 2016, 10:07:39 PM1/26/16
to Adrian Gropper, SMART on FHIR, Nikolai Schwertner

Hi Adrian,

To briefly answer your question: SMART on FHIR gives app developers they tools they need to build health apps that integrate with EHR data. This includes an authorization process, single sign-on, data profiles that lock down vocabularies, and (optionally) some UX integration glue including context sharing so apps can be embedded within an EHR.

Please check out our developer docs as described in this thread for detail about how to read and write days in our sandbox environment, which illustrates use of the API.

Best,

Josh

Vijay Kannan

unread,
Jan 27, 2016, 10:04:20 AM1/27/16
to SMART on FHIR, agro...@healthurl.com, nikolai.s...@gmail.com
Hello All,

Hope every one doing great.

I am trying to setup my own sandbox and trying play with adding sample apps. I was trying to add records to it based on given below link but I am getting invalid scope error after the app launch. [http://52.74.23.247:8001/?error=invalid_scope&error_description=Invalid+scope&state=708018ea-6562-2a6b-7e41-38dd6688bab6&scope=user%2F*.* ]


I have checked this group already[ as per this thread Mr.Josh pointed out] about does that client JS has writeTo function but it was not there as well !!! please some one can help me what I am missing here?

Vijay Kannan

unread,
Jan 30, 2016, 6:56:17 AM1/30/16
to SMART on FHIR, agro...@healthurl.com, nikolai.s...@gmail.com
Hello All,

I was able to finally add data on behalf of patient :-) .Thanks everyone.

still facing issue on creating patient though. here with I have attached index and launch html. Please someone help me out to work this use case will be really great.

Regards,
Vijay
index.html
launch.html

Nikolai Schwertner

unread,
Jan 30, 2016, 10:17:33 AM1/30/16
to Vijay Kannan, SMART on FHIR, agro...@healthurl.com
What issue are you facing crating a patient? The example that you are quoting illustrates precisely how to create a patient using smart.api.create (i.e. fhir.js's create method). I thought that it worked on your end?!
Reply all
Reply to author
Forward
0 new messages