1111
1212## Description <a name =" description " ></a >
1313
14- This is an SDK for interacting with [ CMS Blue Button 2.0 API] ( https://bluebutton.cms.gov/developers/ ) ,
15- the API allows applications to obtain a beneficiary's (who has login account with medicare.gov) grant
16- to access his/her medicare claims data - through OAUTH2 [ (RFC 6749)] ( https://datatracker.ietf.org/doc/html/rfc6749 ) authorization flow.
14+ This is an SDK for interacting with the [ CMS Blue Button 2.0 API] ( https://bluebutton.cms.gov/developers/ ) .
15+ The API allows applications to obtain a beneficiary's (who has login account with medicare.gov) grant
16+ to access their medicare claims data - through the OAuth 2.0 [ (RFC 6749)] ( https://datatracker.ietf.org/doc/html/rfc6749 ) authorization flow.
1717
18- By using the SDK, the development of applications accessing Blue Button 2.0 API can be greatly simplified.
18+ By using the SDK, the development of applications accessing the Blue Button 2.0 API can be greatly simplified.
1919
20- Note, following the OAUTH2 best practices, OAUTH2 PKCE etension [ (RFC 7636)] ( https://datatracker.ietf.org/doc/html/rfc7636 ) is always enabled.
20+ Note: In following OAuth 2.0 best practices, the PKCE extension [ (RFC 7636)] ( https://datatracker.ietf.org/doc/html/rfc7636 ) is always enabled.
2121
2222## Installation <a name =" installation " ></a >
2323
@@ -27,61 +27,106 @@ $ pip install cms-bluebutton-sdk
2727
2828## Configuration <a name =" configuration " ></a >
2929
30- the SDK needs to be properly configured to work, the parameters are:
30+ The SDK needs to be properly configured to work.
3131
32- - the app's credentials - client id, client secret
33- - the app's callback url
34- - the version number of the API
35- - the app's environment (web location where the app is registered)
32+ The configuration parameters are:
3633
37- the configuration is in json format and stored in a local file, the default location
38- is current working directory with file name: .bluebutton-config.json
34+ - The app's credentials - client id, client secret
35+ - The app's callback url
36+ - The version number of the API
37+ - The app's environment (the BB2.0 web location where the app is registered)
3938
40- A sample configuration json:
41-
42- ```
43- {
44- "clientId": "foo",
45- "clientSecret": "bar",
46- "callbackUrl": "https://www.fake.com/",
47- }
48-
49- ```
50-
51- | parameter | value | Comments |
39+ | Parameter | Value | Comments |
5240| ------------ | ----------------------- | ------------------------------- |
53- | clientId | "foo" | oauth2 client id of the app |
54- | clientSecret | "bar" | oauth2 client secret of the app |
55- | callbackUrl | "https://www.fake.com/" | oauth2 callback url of the app |
41+ | environment | "SANDBOX" or "PRODUCTION" | BB2 API environment (default="SANDBOX")
42+ | version | 1 or 2 | BB2 API version (default=2) |
43+ | client_id | "foo" | oauth2 client id of the app |
44+ | client_secret | "bar" | oauth2 client secret of the app |
45+ | callback_url | "https://www.fake.com/callback" | oauth2 callback URL of the app |
5646
5747For application registration and client id and client secret, please refer to:
5848[ Blue Button 2.0 API Docs - Try the API] ( https://bluebutton.cms.gov/developers/#try-the-api )
5949
60- ## Sample Usages: Obtain Access Grant, Probe Scope, and Access Data <a name =" usages " ></a >
6150
62- Below are psuedo code snippets showing SDK used with python server and flask.
51+ There are three ways to configure the SDK when instantiating a ` BlueButton ` class instance:
52+
53+ * Python Dictionary:
54+ - A dictionary of configuration key: value pairs can be used.
55+ - Configuration values can be provided from your own application's configuration method.
56+ - Example code:
57+ ``` python
58+ bb = BlueButton({
59+ " environment" : " PRODUCTION" ,
60+ " client_id" : " foo" ,
61+ " client_secret" : " bar" ,
62+ " callback_url" : " https://www.fake.com/callback" ,
63+ " version" : 2 ,
64+ }
65+ ```
66+ * JSON config file :
67+ - This is using a configuration file that is in a JSON format .
68+ - This is stored in a local file .
69+ - The default location is in the current working directory with a file name: .bluebutton- config.json
70+ - Example code:
71+ ```python
72+ bb = BlueButton(" settings/my_bb2_sdk_conf.json" )
73+ ```
74+ - Example JSON in file :
75+ ```json
76+ {
77+ " environment" : " SANDBOX" ,
78+ " client_id" : " foo" ,
79+ " client_secret" : " bar" ,
80+ " callback_url" : " https://www.fake.com/callback" ,
81+ " version" : 2
82+ }
83+ ```
84+
85+ * YAML config file :
86+ - This is using a configuration file that is in a YAML format .
87+ - This is stored in a local file .
88+ - The default location is in the current working directory with a file name: .bluebutton- config.yaml
89+ - Example code:
90+ ```python
91+ bb = BlueButton(" settings/my_bb2_sdk_conf.yaml" )
92+ ```
93+ - Example YAML in file :
94+ ```yaml
95+ environment: " SANDBOX"
96+ client_id: " foo"
97+ client_secret: " bar"
98+ callback_url: " https://www.fake.com/callback"
99+ version: 2
100+ ```
101+
102+ # # Sample Usage: Obtain Access Grant, Probe Scope, and Access Data <a name="usages"></a>
63103
64- ```
104+ Below are psuedo code snippets showing SDK used with python server and flask.
65105
106+ ```python
66107from flask import Flask
67108from flask import redirect, request
68109from cms_bluebutton import BlueButton, AuthorizationToken
69110
70111# initialize the app
71112app = Flask(__name__ )
72113
114+ # Instantiate SDK class instance via conf in file
73115bb = BlueButton()
116+
74117# auth_data is saved for the current user
75118auth_data = bb.generate_auth_data()
76119
77- # AuthorizationToken holds access grant info:
78- # access token, expire in, expire at, token type, scope, refreh token, etc.
79- # it is associated with current logged in user in real app,
80- # check SDK python docs for more details.
120+ """
121+ AuthorizationToken holds access grant info:
122+ access token, expire in, expire at, token type, scope, refreh token, etc.
123+ It is associated with current logged in user in real app.
124+ Check SDK python docs for more details.
125+ """
81126
82127auth_token = None
83128
84- # start authorize flow: response with URL to redirect to Medicare.gov beneficiary login
129+ # Start authorize flow: Response with URL to redirect to Medicare.gov beneficiary login
85130@ app.route(" /" , methods = [" GET" ])
86131def get_auth_url():
87132 return bb.generate_authorize_url(auth_data)
@@ -95,33 +140,38 @@ def authorization_callback():
95140
96141 auth_token = bb.get_authorization_token(auth_data, code, state)
97142
98- # now access token obtained, note, during authorization, the beneficiary can grant
99- # access to his/her demographic data and claims data or only claims data, check the scope
100- # of the current access token as shown below:
143+ """
144+ Now access token obtained.
145+
146+ Note: During authorization, the beneficiary can grant
147+ access to their demographic data and claims data or only claims data.
101148
149+ Check the scope
150+ of the current access token as shown below:
151+ """
102152 scopes = auth_token.scope;
103153
104154 # iterate scope entries here or check if a permission is in the scope
105- if (scopes.index( "patient/Patient.read") > -1) {
106- // patient info access granted
107- }
108-
109- # 1. access token scope where demagraphic info included:
110- #
111- # scope: [
112- # "patient/Coverage.read",
113- # "patient/ExplanationOfBenefit.read",
114- # "patient/Patient.read",
115- # "profile",
116- # ]
117- #
118- # 2. access token scope where demagraphic info not included:
119- #
120- # scope: [
121- # "patient/Coverage.read",
122- # "patient/ExplanationOfBenefit.read",
123- # ]
124-
155+ if " patient/Patient.read" in scopes:
156+ # patient info access granted
157+
158+ """
159+ 1. access token scope where demagraphic info included:
160+
161+ scope: [
162+ "patient/Coverage.read",
163+ "patient/ExplanationOfBenefit.read",
164+ "patient/Patient.read",
165+ "profile",
166+ ]
167+
168+ 2. access token scope where demagraphic info not included:
169+
170+ scope: [
171+ "patient/Coverage.read",
172+ "patient/ExplanationOfBenefit.read",
173+ ]
174+ """
125175 config = {
126176 " auth_token" : auth_token,
127177 " params" : {},
@@ -134,10 +184,13 @@ def authorization_callback():
134184 try :
135185 eob_data = bb.get_explaination_of_benefit_data(config)
136186 result[' eob_data' ] = eob_data[' response' ].json()
187+
137188 pt_data = bb.get_patient_data(config)
138189 result[' patient_data' ] = pt_data[' response' ].json()
190+
139191 coverage_data = bb.get_coverage_data(config)
140192 result[' coverage_data' ] = coverage_data[' response' ].json()
193+
141194 profile_data = bb.get_profile_data(config)
142195 result[' profile_data' ] = profile_data[' response' ].json()
143196 except Exception as ex:
@@ -157,20 +210,25 @@ A Python React sample app can be found at:
157210
158211# # API Versions and Environments <a name="versions_and_environments"></a>
159212
160- From two environments: PRODUCTION and SANDBOX, Blue Button API is available in v1 and v2, data served from v1 is in FHIR STU2 format, and data from v2 is in FHIR R4 format, an application's target environment and API version can be set in the SDK configuration as shown by example below:
213+ Can be selected for environments: PRODUCTION and SANDBOX .
161214
162- ```
215+ The Blue Button API is available in versions v1 and v2.
216+
217+ The data served from v1 is in FHIR STU2 format , and data from v2 is in FHIR R4 format .
218+
219+ An application' s target environment and API version can be set in the SDK configuration as shown by the JSON example below:
220+
221+ ```json
163222{
164223 " clientId" : " foo" ,
165224 " clientSecret" : " bar" ,
166225 " callbackUrl" : " https://www.fake.com/" ,
167226 " version" : " 2" ,
168227 " environment" : " PRODUCTION"
169228}
170-
171229```
172230
173- The default API version is v2, and default environment is SANDBOX.
231+ If not included, the default API version is v2, and the default environment is SANDBOX .
174232
175233Web location of the environments:
176234
0 commit comments