-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from CMSgov/jfuqian/BB2-1701-Node-Sample-App-c…
…ode-cleanup [BB2-1701] Node Sample App code cleanup and re-factor to use SDK
- Loading branch information
Showing
35 changed files
with
232 additions
and
1,074 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Blue Button 2.0 Sample Application Development Documentation | ||
|
||
## Introduction | ||
|
||
This README contains information related to developing the SDK. | ||
|
||
It is intended for BB2 team members or others performing sample application development work. | ||
|
||
## Run selenium tests in docker | ||
|
||
Configure the remote target BB2 instance where the tested app is registered (as described above "Running the Back-end & Front-end") | ||
|
||
Change your `callbackUrl` configuration to use `server` instead of `localhost`. For example: | ||
```JSON | ||
"callback_url": "http://server:3001/api/bluebutton/callback/" | ||
``` | ||
|
||
You can also start your configuration by the following the sample config template for selenium tests: | ||
|
||
cp server/sample-bluebutton-selenium-config.json server/.bluebutton-config.json | ||
|
||
You will also need to add this URL to your `redirect_uris` list in your application's configuration on the BB2 Sandbox UI. | ||
|
||
Go to local repository base directory and run docker compose as below: | ||
|
||
docker-compose -f docker-compose.selenium.yml up --abort-on-container-exit | ||
|
||
Note: --abort-on-container-exit will abort client and server containers when selenium tests ends | ||
|
||
Note: You may need to clean up already existing Docker containers, if you are having issues or have changed your configuration file. | ||
|
||
## Visual trouble shoot | ||
|
||
Install VNC viewer and point browser to http://localhost:5900 to monitor web UI interactions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import express, { Request, Response } from "express"; | ||
import { AuthorizationToken, BlueButton } from "cms-bluebutton-sdk"; | ||
|
||
interface User { | ||
authToken?: AuthorizationToken, | ||
eobData?: any, | ||
errors?: string[] | ||
} | ||
|
||
const BENE_DENIED_ACCESS = "access_denied" | ||
const FE_MSG_ACCESS_DENIED = "Beneficiary denied app access to their data" | ||
const ERR_QUERY_EOB = "Error when querying the patient's EOB!" | ||
const ERR_MISSING_AUTH_CODE = "Response was missing access code!" | ||
const ERR_MISSING_STATE = "State is required when using PKCE" | ||
|
||
const app = express(); | ||
|
||
const bb = new BlueButton(); | ||
const authData = bb.generateAuthData(); | ||
|
||
// This is where medicare.gov beneficiary associated | ||
// with the current logged in app user, | ||
// in real app, this could be the app specific | ||
// account management system | ||
|
||
const loggedInUser: User = { | ||
}; | ||
|
||
// helper to clean up cached eob data | ||
function clearBB2Data() { | ||
loggedInUser.authToken = undefined; | ||
loggedInUser.eobData = {}; | ||
} | ||
|
||
// AuthorizationToken holds access grant info: | ||
// access token, expire in, expire at, token type, scope, refreh token, etc. | ||
// it is associated with current logged in user in real app, | ||
// check SDK js docs for more details. | ||
|
||
let authToken: AuthorizationToken; | ||
|
||
// auth flow: response with URL to redirect to Medicare.gov beneficiary login | ||
app.get("/api/authorize/authurl", (req: Request, res: Response) => { | ||
res.send(bb.generateAuthorizeUrl(authData)); | ||
}); | ||
|
||
// auth flow: oauth2 call back | ||
app.get("/api/bluebutton/callback", (req: Request, res: Response) => { | ||
(async (req: Request, res: Response) => { | ||
if (typeof req.query.error === "string") { | ||
// clear all cached claims eob data since the bene has denied access | ||
// for the application | ||
clearBB2Data(); | ||
let errMsg = req.query.error; | ||
if (req.query.error === BENE_DENIED_ACCESS) { | ||
errMsg = FE_MSG_ACCESS_DENIED; | ||
} | ||
loggedInUser.eobData = {"message": errMsg}; | ||
process.stdout.write(errMsg + '\n'); | ||
} else { | ||
if ( | ||
typeof req.query.code === "string" && | ||
typeof req.query.state === "string" | ||
) { | ||
try { | ||
authToken = await bb.getAuthorizationToken( | ||
authData, | ||
req.query.code, | ||
req.query.state | ||
); | ||
// data flow: after access granted | ||
// the app logic can fetch the beneficiary's data in app specific ways: | ||
// e.g. download EOB periodically etc. | ||
// access token can expire, SDK automatically refresh access token when that happens. | ||
const eobResults = await bb.getExplanationOfBenefitData(authToken); | ||
authToken = eobResults.token; // in case authToken got refreshed during fhir call | ||
|
||
loggedInUser.authToken = authToken; | ||
|
||
loggedInUser.eobData = eobResults.response?.data; | ||
} catch (e) { | ||
loggedInUser.eobData = {}; | ||
process.stdout.write(ERR_QUERY_EOB + '\n'); | ||
process.stdout.write("Exception: " + e + '\n'); | ||
} | ||
} else { | ||
clearBB2Data(); | ||
process.stdout.write(ERR_MISSING_AUTH_CODE + '\n'); | ||
process.stdout.write("OR" + '\n'); | ||
process.stdout.write(ERR_MISSING_STATE + '\n'); | ||
process.stdout.write("AUTH CODE: " + req.query.code + '\n'); | ||
process.stdout.write("STATE: " + req.query.state + '\n'); | ||
} | ||
} | ||
const fe_redirect_url = | ||
process.env.SELENIUM_TESTS ? 'http://client:3000' : 'http://localhost:3000'; | ||
res.redirect(fe_redirect_url); | ||
} | ||
)(req, res); | ||
}); | ||
|
||
// data flow: front end fetch eob | ||
app.get("/api/data/benefit", (req: Request, res: Response) => { | ||
if (loggedInUser.eobData) { | ||
res.json(loggedInUser.eobData); | ||
} | ||
}); | ||
|
||
const port = 3001; | ||
app.listen(port, () => { | ||
process.stdout.write(`[server]: Server is running at https://localhost:${port}`); | ||
process.stdout.write("\n"); | ||
}); |
Oops, something went wrong.