Skip to content

Commit e03a4c9

Browse files
author
JAMES FUQIAN
committed
code cleanup, use SDK.
1 parent 2a6960d commit e03a4c9

9 files changed

Lines changed: 190 additions & 253 deletions

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ Running the Back-end & Front-end
2525

2626
Once Docker and Python are Installed then do the following:
2727

28-
copy server/src/configs/sample_config.py -> server/src/configs/config.py
28+
cp server/sample-bluebutton-config.py server/.bluebutton-config.py
2929

30-
Make sure to replace the clientId and clientSecret variables within the config file with
31-
the ones you were provided, for your application, when you created your Blue Button Sandbox account.
32-
33-
copy server/src/prestart/env/sandbox.sample.env -> server/src/prestart/env/development.env
30+
Make sure to replace the client_id and client_secret variables within the config file with
31+
the ones you were provided, for your application, when you created your Blue Button Sandbox account,
32+
the supported environments are SANDBOX or PRODUCTION.
3433

3534
docker-compose up -d
3635

@@ -51,9 +50,9 @@ data would be: BBUser29999 (PWD: PW29999!) or BBUser29998 (PWD: PW29998!)
5150

5251
Development
5352
-----------
54-
Read the DEVELOPER NOTES found in the code to understand the application
55-
and where you will need to make adjustments/changes as well as some
56-
suggestions for best practices.
53+
Read the comments in the code to understand the application and where
54+
you will need to make adjustments/changes as well as some suggestions
55+
for best practices.
5756

5857
Debugging server component
5958
--------------------------

server/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ LABEL description="Demo of a Medicare claims data sample app"
55

66
WORKDIR /server
77

8-
COPY ["./src/configs/sample_config.py", "./src/configs/config.py"]
9-
COPY ["./src/prestart/env/sandbox.sample.env","./src/prestart/env/development.env"]
8+
# COPY ["./src/configs/sample_config.py", "./src/configs/config.py"]
9+
# COPY ["./src/prestart/env/sandbox.sample.env","./src/prestart/env/development.env"]
1010

1111
COPY . .
1212

13-
RUN pip install pipenv
14-
RUN pip install debugpy
13+
RUN pip install pipenv debugpy ./cms_bluebutton_sdk-1.0.0-py3-none-any.whl
1514
RUN pipenv install --system --deploy --ignore-pipfile
1615

17-
ENV ENV "development"
16+
# ENV ENV "development"
1817

1918
EXPOSE 3001
2019

21-
CMD ["sh", "-c", "python -m debugpy --listen 0.0.0.0:5678 run.py --ENV ${ENV}"]
20+
CMD ["sh", "-c", "python -m debugpy --listen 0.0.0.0:5678 app.py"]

server/Pipfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ name = "pypi"
55

66
[packages]
77
flask = "*"
8-
requests = "*"
9-
argparse = "*"
10-
requests-toolbelt = "*"
11-
python-dotenv = "*"
128

139
[dev-packages]
1410

server/Pipfile.lock

Lines changed: 67 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/app.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import os
2+
3+
from flask import redirect, request, Flask
4+
from cms_bluebutton.cms_bluebutton import BlueButton
5+
6+
7+
app = Flask(__name__)
8+
bb = BlueButton()
9+
10+
# This is where medicare.gov beneficiary associated
11+
# with the current logged in app user,
12+
# in real app, this could be the app specific
13+
# accoount management system
14+
loggedInUser = {
15+
'authToken': None,
16+
'eobData': None
17+
}
18+
19+
auth_data = bb.generate_auth_data()
20+
21+
# AuthorizationToken holds access grant info:
22+
# access token, expire in, expire at, token type, scope, refreh token, etc.
23+
# it is associated with current logged in user in real app,
24+
# check SDK python docs for more details.
25+
26+
auth_token = None
27+
28+
29+
@app.route('/api/authorize/authurl', methods=['GET'])
30+
def get_auth_url():
31+
redirect_url = bb.generate_authorize_url(auth_data)
32+
return redirect_url
33+
34+
35+
@app.route('/api/bluebutton/callback/', methods=['GET'])
36+
def authorization_callback():
37+
request_query = request.args
38+
code = request_query.get('code')
39+
state = request_query.get('state')
40+
41+
auth_token = bb.get_authorization_token(auth_data, code, state)
42+
43+
# correlate app user with medicare bene
44+
loggedInUser['authToken'] = auth_token
45+
46+
config = {
47+
"auth_token": auth_token,
48+
"params": {},
49+
"url": "to be overriden"
50+
}
51+
52+
# result = {}
53+
54+
try:
55+
# search eob
56+
57+
eob_data = bb.get_explaination_of_benefit_data(config)
58+
59+
# fhir search response could contain large number of resources,
60+
# by default they are chunked into pages of 10 resources each,
61+
# the response above might be the 1st page of EOBs, it is in
62+
# the format of a FHIR bundle resource with a link section where
63+
# page navigation urls such as 'first', 'last', 'self', 'next',
64+
# 'previous' might present depending on the current page.
65+
# Use bb.get_pages(data, config) to get all the pages
66+
67+
auth_token = eob_data['auth_token']
68+
loggedInUser['authToken'] = auth_token
69+
loggedInUser['eobData'] = eob_data['response'].json()
70+
except Exception as ex:
71+
print(ex)
72+
73+
return redirect(get_fe_redirect_url())
74+
75+
76+
@app.route('/api/data/benefit', methods=['GET'])
77+
def get_patient_eob():
78+
"""
79+
* this function is used directly by the front-end to
80+
* retrieve eob data from the logged in user from within the mocked DB
81+
* This would be replaced by a persistence service layer for whatever
82+
* DB you would choose to use
83+
"""
84+
if loggedInUser and loggedInUser.get('eobData'):
85+
return loggedInUser.get('eobData')
86+
else:
87+
return {}
88+
89+
90+
def get_fe_redirect_url():
91+
'''
92+
helper to figure out the correct front end redirect url per context
93+
'''
94+
is_selenium = os.getenv('SELENIUM_TESTS', 'False').lower() in ('true')
95+
return 'http://client:3000' if is_selenium else 'http://localhost:3000'
96+
97+
98+
if __name__ == '__main__':
99+
app.run(debug=True, host='0.0.0.0', port=3001)
16.9 KB
Binary file not shown.

server/run.py

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"environment": "SANDBOX",
3+
"client_id": "<client_id>",
4+
"client_secret": "<client_secret>",
5+
"callback_url": "http://localhost:3001/api/bluebutton/callback/",
6+
"version": 2,
7+
"retry_settings": {
8+
"total": 3,
9+
"backoff_factor": 5,
10+
"status_forcelist": [500, 502, 503, 504]
11+
}
12+
}

tslint.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)