diff --git a/README.md b/README.md index 2ab5df7e..109c618f 100644 --- a/README.md +++ b/README.md @@ -176,9 +176,13 @@ print(patient.name[0].given) Take a look at [flask_app.py](https://github.com/smart-on-fhir/client-py/blob/main/demos/flask/flask_app.py) to see how you can use the client in a simple (Flask) app. -This app starts a web server, -listening on [_localhost:8000_](http://localhost:8000), -and prompts you to log in to our sandbox server and select a patient. + +This demo requires a server that is capable of SMART OAuth logins for patients, +so make sure you have such a server ready first. + +This app will start a web server, +listen on [_localhost:8000_](http://localhost:8000), +and prompt you to log in to our sandbox server and select a patient. It then retrieves the selected patient's demographics and med prescriptions and lists them on a simple HTML page. @@ -192,6 +196,7 @@ and install the needed packages as shown: python3 -m venv env . env/bin/activate pip install -r requirements.txt + # Edit flask_app.py and put your own server's URL as api_base. ./flask_app.py diff --git a/demos/flask/flask_app.py b/demos/flask/flask_app.py index 4b36a030..fbde5ee8 100755 --- a/demos/flask/flask_app.py +++ b/demos/flask/flask_app.py @@ -10,13 +10,7 @@ # app setup smart_defaults = { 'app_id': 'my_web_app', - # The CapabilityStatement being returned from the new test server, - # r4.smarthealthit.org, is currently missing a required field in the - # description of one of the search params. So you may see a - # 'Non-optional property "type"' error message when running this with - # the default config. We'll remove this message once that has been - # fixed and tested. - 'api_base': 'https://r4.smarthealthit.org/', + 'api_base': None, 'redirect_uri': 'http://localhost:8000/fhir-app/', } @@ -29,8 +23,10 @@ def _get_smart(): state = session.get('state') if state: return client.FHIRClient(state=state, save_func=_save_state) - else: + elif smart_defaults['api_base']: return client.FHIRClient(settings=smart_defaults, save_func=_save_state) + else: + return None def _logout(): if 'state' in session: @@ -80,8 +76,13 @@ def index(): """ smart = _get_smart() body = "
Please edit flask_app.py and set a value for 'api_base', """ + body += """pointing at your own OAuth-capable server.
""" + + # "ready" may be true but the access token may have expired, making smart.patient = None + elif smart.ready and smart.patient is not None: name = smart.human_name(smart.patient.name[0] if smart.patient.name and len(smart.patient.name) > 0 else 'Unknown') # generate simple body text @@ -92,6 +93,7 @@ def index(): else: body += "(There are no prescriptions for {0})
".format("him" if 'male' == smart.patient.gender else "her") body += """""" + else: auth_url = smart.authorize_url if auth_url is not None: