-
Notifications
You must be signed in to change notification settings - Fork 8
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 #21 from TopologyHealth/better-auth-redirect
Better-auth-redirect
- Loading branch information
Showing
5 changed files
with
92 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,98 +22,6 @@ Using npm's git repo support: `npm install [email protected]:TopologyHealth/SMARTer | |
|
||
Support for the npm registry will be coming soon | ||
|
||
<!-- npm: --> | ||
<!-- | ||
```bash | ||
npm install smarter-fhir | ||
``` --> | ||
|
||
## Usage | ||
|
||
Here's a basic example demonstrating how to use the SMARTerFHIR library: | ||
|
||
### Web Launch (using EMR or Standalone Launch) | ||
|
||
The following is an example of a function to handle the SMART Launch. I.e., when the EMR launches the application, it must be directed to the page that runs the following. E.g., this could be https://www.yourwebsite.com/launch | ||
|
||
```typescript | ||
async function handleWebLaunch() { | ||
try { | ||
const emrClientID = YOUR_EMR_CLIENT_ID | ||
const emrClientSecret = EMR_CLIENT_SECRET //OPTIONAL -> Only Required if your EMR Authentication was registered with a Secret | ||
const smartLaunchHandler = new SmartLaunchHandler(emrClientID, emrClientSecret) //If no secret, use 'new SmartLaunchHandler(emrClientID)' | ||
await smartLaunchHandler.authorizeEMR(LAUNCH.EMR) //If Standalone, use 'await smartLaunchHandler.authorizeEMR(LAUNCH.STANDALONE)' | ||
} | ||
catch (e) { | ||
if (e instanceof Error) { | ||
throw e; | ||
} | ||
throw new Error(`Unknown Error: ${e}`) | ||
} | ||
} | ||
``` | ||
|
||
Here’s a breakdown of the above code snippet: | ||
|
||
* `emrClientID`: Pass in the Client ID of the EMR Client that you want to connect to | ||
* `emrClientSecret`: Pass in the Client Secret of the EMR Client that you want to connect to | ||
* `SmartLaunchHandler`: Our Handler Object. Used mainly with authorizeEMR() to authorize the app and redirect accordingly | ||
|
||
### Standalone Launch Details (Only for Standalone Launch. Skip if doing EMR Launch) | ||
Relevant if using Standalone Launch. | ||
|
||
When running `handleWebLaunch` for Standalone Launch, an `iss` query parameter must be passed to the webpage. | ||
|
||
To aid in simplicity, you can use this example button that navigates to the page that runs `handleWebLaunch` and passes in the appropriately required `iss`: | ||
```typescript | ||
<Button my="sm" onClick={startStandaloneLaunch}> | ||
{"Execute Standalone Launch"} | ||
</Button> | ||
|
||
const startStandaloneLaunch = () => | ||
{ | ||
const emrType = ((YOUR_REACT_APP_EMR_TYPE).toLowerCase() as EMR) //YOUR_REACT_APP_EMR_TYPE must be set to 'EPIC' or 'CERNER' (More EMRs to come!) | ||
const emrEndpoints = getEndpointsForEmr(emrType) | ||
const iss = emrEndpoints.r4.toString() | ||
navigate({ | ||
pathname: '/standalonelaunch', //This pathname should make a request to the page that runs 'handleWebLaunch' | ||
search: `?iss=${iss}`, | ||
}); | ||
} | ||
``` | ||
|
||
### SMART Client | ||
|
||
The following is an example of a function to instantiate the SMART Client after `SMART Launch` has completed. During SmartLaunch, the EMR will authenticate your application. Once completed, it will redirect to the assigned redirect url. The code below should be set to run upon successful authentication and redirect: | ||
|
||
```typescript | ||
async function mySmartClientInstantiator() { | ||
try { | ||
const clientFactory = new ClientFactory(); | ||
const client = await clientFactory.createEMRClient(LAUNCH.EMR) //If Standalone, use 'await clientFactory.createEMRClient(LAUNCH.STANDALONE)' | ||
if (!client) throw new Error('no client found') | ||
return client | ||
} catch (reason) { | ||
if (!(reason instanceof Error)) | ||
throw new Error(`Unknown Error: ${reason}`) | ||
if (reason.message.includes("No 'state' parameter found. Please (re)launch the app.") | ||
|| reason.message.includes("Could not find any JWT token") | ||
|| reason.message === NO_CODE) { | ||
return console.log('No EMR connection established.') | ||
} | ||
if (reason.message.includes("User is not available")) | ||
return console.log('Waiting for Web Launch...') | ||
console.error(reason.message) | ||
} | ||
} | ||
``` | ||
Code snippet breakdown: | ||
|
||
* `clientFactory`: Object for creating new EMRClients post-SMART authentication | ||
* `client`: Client object for performing operations against the EMR for writing/receiving data | ||
|
||
Make sure to import the necessary classes, interfaces, and types based on your requirements. | ||
|
||
## Documentation | ||
|
||
For detailed documentation on the SMARTerFHIR library, including classes, methods, and usage examples, please refer to the official documentation at [https://topology.health/docs](https://topology.health/docs). | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.