Client versioning is not identical to FHIR versioning. The
master branch is usually on the latest version of the client as shown below, possibly on bugfix releases thereof. The
develop branch should be on recent freezes, and the
feature/latest-ci branch is periodically updated to the latest FHIR continuous integration builds.
|**x.x**||(STU-3 Ballot, Jan 2017)|
|**x.x**||(STU-3 Ballot, Sep 2016)|
|**0.5**||(DSTU 2 Ballot, May 2015)|
pip install fhirclient
Technical documentation is available at docs.smarthealthit.org/client-py/.
To connect to a SMART on FHIR server (or any open FHIR server), you can use the
FHIRClient class. It will initialize and handle a
FHIRServer instance, your actual handle to the FHIR server you'd like to access.
To read a given patient from an open FHIR server, you can use:
If this is a protected server, you will first have to send your user to the authorize endpoint to log in. Just call
smart.authorize_url to obtain the correct URL. You can use
smart.prepare(), which will return
False if the server is protected and you need to authorize. The
smart.ready property has the same purpose, it will however not retrieve the server's CapabilityStatement resource and hence is only useful as a quick check whether the server instance is ready.
```python smart = client.FHIRClient(settings=settings) smart.ready
Trueafter fetching CapabilityStatement
smart.authorize_url # is
You can also search for resources matching a particular set of criteria:
The client contains data model classes, built using fhir-parser, that handle (de)serialization and allow to work with FHIR data in a Pythonic way. Starting with version 1.0.5, data model validity are enforced to a certain degree.
name = hn.HumanName() name.given = ['Peter'] name.family = ['Parker'] patient.name = [name] patient.as_json()
name.given = 'Peter' patient.as_json()
# Expecting property "given" on <class 'fhirclient.models.humanname.HumanName'> to be list, but is <class 'str'>
Take a look at
flask_app.py to see how you can use the client in a simple (Flask) app. This app starts a webserver, listening on localhost:8000, and prompts you to login to our sandbox server and select a patient. It then goes on to retrieve the selected patient's demographics and med prescriptions and lists them in a simple HTML page.
The Flask demo app has separate requirements. Clone the client-py repository, then best create a virtual environment and install the needed packages like so:
git clone https://github.com/smart-on-fhir/client-py.git cd client-py virtualenv -p python3 env . env/bin/activate pip install -r requirements_flask_app.txt python flask_app.py
pip install -r requirements.txt python setup.py sdist python setup.py bdist_wheel
bumpversion patch bumpversion minor bumpversion major
Running Doxygen will put the generated documentation into
docs, the HTML files into
docs/html. Those files make up the content of the
gh-pages branch. I usually perform a second checkout of the gh-pages branch and copy the html files over, with:
doxygen rsync -a docs/html/ ../client-py-web/
Using setuptools (Note: Alternatively, you can use twine https://pypi.python.org/pypi/twine/):
copy server.smarthealthit.org:/home/fhir/.pypirc to ~/.pypirc
python setup.py sdist python setup.py bdist_wheel
python setup.py sdist upload -r pypi python setup.py bdist_wheel upload -r pypi