Getting started with Flask using client-py.

Open In Colab

Getting started

You can run this notebook

  • in colab or
    • Feel free to ignore the "Start the app", "Convert this notebook" and "Run the app locally" sections
  • on your own machine
    • Please see index.ipynb and set things up to run on your own machine.

See also: https://github.com/smart-on-fhir/client-py

Code and test a simple flask app

App setup

True

Helper functions

smart = client.FHIRClient(settings=smart_defaults)
for p in _get_patients(smart): assert p.id is not None # TODO: write a better test

Views

index[source]

index()

The app's main page.

callback[source]

callback()

OAuth2 callback interception.

logout[source]

logout()

reset[source]

reset()

Start the app

Convert this notebook to a python module

After making changes to this notebook, we need to get nbdev to re-create the flask_client_py_readme.py file.

We can do this in code ↓ or from the command line with nbdev_build_lib

if not IN_COLAB:
    from nbdev.export import notebook2script
    notebook2script('51_flask_client_py_readme.ipynb')
Converted 51_flask_client_py_readme.ipynb.

Run the app locally

Now we can run python smart_on_fhir_client_py_demo/flask_client_py_readme.py from the command line and hit

Run the app in colab

The following cell will only run if you're in colab, where you'll see output like

 * Serving Flask app "__main__" (lazy loading)
 ...
INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): bin.equinox.io:443
...
DEBUG:urllib3.connectionpool:http://localhost:4040 "GET /api/tunnels HTTP/1.1" 200 779
 * Running on http://35c09c8e5eb5.ngrok.io
 * Traffic stats available on http://127.0.0.1:4040

Hit the ngrok.io link to see the app - none of the localhost or 127.0.0.1 links will work

if IN_COLAB:
    logging.basicConfig(level=logging.DEBUG)
    from flask_ngrok import run_with_ngrok
    run_with_ngrok(app)
    app.run()