Can not run python example

870 views
Skip to first unread message

WU CHEN SU

unread,
Jun 2, 2017, 8:58:37 AM6/2/17
to SMART on FHIR
Hello,

Does any one know why I can not run blow codes?

from fhirclient import client

settings = {

    'app_id': 'my_web_app',

    'api_base': 'https://fhir-open-api-dstu2.smarthealthit.org'

}

smart = client.FHIRClient(settings=settings)


import fhirclient.models.patient as p

patient = p.Patient.read('hca-pat-1', smart.server)

patient.birthDate.isostring

# '1963-06-12'

smart.human_name(patient.name[0])

# 'Christy Ebert


Server problems? Or?


Thx! 

Sanders

Dennis Steed

unread,
Jun 4, 2017, 8:56:34 PM6/4/17
to SMART on FHIR
First problem is the api_base is out of date.


The sandbox’s open DSTU2 FHIR server is accessible directly at https://sb-fhir-dstu2.smarthealthit.org/api/smartdstu2/open and the secure endpoint for launching a standalone app that’s been registered is at https://sb-fhir-dstu2.smarthealthit.org/api/smartdstu2/data. Note that the data in the online sandbox is reset on a nightly basis.

You should be using       'api_base': 'https://sb-fhir-dstu2.smarthealthit.org/api/smartdstu2/open'

Second problem is that hca-pat-1 is not on this server.  An id that is on the server is hca-pat-64 .

Finally, you must be sure to use the proper version of fhirclient.  To get the version of fhirclient that works as above you must use   pip install fhirclient==1.0.6





Working code in python 2.7 for version 1.0.6 of fhirclient is:

from fhirclient import client

settings = {
    'app_id': 'my_web_app',
}

smart = client.FHIRClient(settings=settings)

import fhirclient.models.patient as p

patient = p.Patient.read('hca-pat-64', smart.server)

print patient.birthDate.isostring

print smart.human_name(patient.name[0])


Output is:
1990-06-29
Joseph Chen

Sharud Agarwal

unread,
Jun 7, 2017, 2:45:08 AM6/7/17
to SMART on FHIR
Even this revised code does not work for me, either with fhir client 3.0.0 and stu3 api_base or fhir client 1.0.6 with dstu2 api_base and python 2.7.10.

from fhirclient import client
settings = {
    'app_id': 'my_web_app',

Pascal Pfiffner

unread,
Jun 7, 2017, 11:18:42 PM6/7/17
to SMART on FHIR
Please see the README here: https://github.com/smart-on-fhir/client-py#read-data-from-server

You need to open authorize_url in a browser, then intercept the redirect-url. See the sample flask app included in the repo.

Krishna Dubba

unread,
Jul 25, 2017, 12:54:31 PM7/25/17
to SMART on FHIR
Hi,
I am still confused with the python example on github. Whatever I try to do, I get  FHIRUnauthorizedException: <Response [401]>. I am using "https://sb-fhir-stu3.smarthealthit.org/api/smartdstu3/open".

Isn't that open where I can access some data without login?

Or is there a way I can provide login information to the client.FHIRClient?


from fhirclient import client
settings = {
     'app_id': 'my_web_app',

     }
smart = client.FHIRClient(settings=settings)
import fhirclient.models.patient as p

patient = p.Patient.read('hca-pat-64', smart.server)

=============

Traceback (most recent call last):
  File "/tmp/test.py", line 9, in <module>

    patient = p.Patient.read('hca-pat-64', smart.server)
  File "/home/dubba/anaconda3/envs/onto/lib/python3.5/site-packages/fhirclient/models/fhirabstractresource.py", line 83, in read
    instance = cls.read_from(path, server)
  File "/home/dubba/anaconda3/envs/onto/lib/python3.5/site-packages/fhirclient/models/fhirabstractresource.py", line 102, in read_from
    ret = server.request_json(path)
  File "/home/dubba/anaconda3/envs/onto/lib/python3.5/site-packages/fhirclient/server.py", line 161, in request_json
    res = self._get(path, headers, nosign)
  File "/home/dubba/anaconda3/envs/onto/lib/python3.5/site-packages/fhirclient/server.py", line 189, in _get
    self.raise_for_status(res)
  File "/home/dubba/anaconda3/envs/onto/lib/python3.5/site-packages/fhirclient/server.py", line 282, in raise_for_status
    raise FHIRUnauthorizedException(response)
server.FHIRUnauthorizedException: <Response [401]>


I didn't understand what the authorize_url is. When I do this, I again get the same error above i.e. server.FHIRUnauthorizedException: <Response [401]>

print (smart.authorize_url)

Can someone point me to working example with the latest version in github?

Thanks,
Krishna

Travis Cummings

unread,
Jul 25, 2017, 1:50:44 PM7/25/17
to Krishna Dubba, SMART on FHIR

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

Krishna Dubba

unread,
Jul 26, 2017, 6:29:01 AM7/26/17
to SMART on FHIR, krishn...@gmail.com
Thanks Travis, that works :-)

Sander Su

unread,
May 2, 2019, 2:50:57 PM5/2/19
to SMART on FHIR
Hi,

https://sb-fhir-stu3.smarthealthit.org/smartstu3/data


is not working. Does anyone know other sites?

Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to smart-...@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages