Last active
April 24, 2019 20:53
-
-
Save sschottler/75c57295436d69fbe3028e94bcaf5ade to your computer and use it in GitHub Desktop.
End to End Visit SDK calls to launch visit
This file contains hidden or 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
// before running this: | |
// 1) make sure you are logged in as a provider on another laptop | |
// instructions for how to do that: | |
// https://wiki.audaxhealth.com/pages/viewpage.action?spaceKey=ENG&title=Setting+up+an+Amwell+provider+for+a+visit | |
// 2) You should have the telehealth video player installed. The code below won't do that for you | |
// you can get the url to install it in sdk.visitService.telehealthVideoInstallUrl after initializing the sdk | |
// 3) Have your .env.development.local credentials setup (see readme in Telemedicine-UI) | |
// 4) put the thunk action creator below in awsdkActions.ts and call it on app componentDidMount | |
// I will be grouping these into separate actions that make sense and | |
// dispatching data to redux store (mainly visit object) | |
export const endToEndVisit = (): ThunkResult => async (dispatch, getState, { sdk, getDevelopmentCredentials }) => { | |
const initialized = await sdk.initialize(SDK_CONFIG); | |
const credentials = getDevelopmentCredentials(); | |
const authenticationResponse = await sdk.authenticationService.authenticateConsumerWithUsername( | |
credentials!.username, | |
credentials!.password | |
); | |
const consumer = authenticationResponse.consumer; | |
// most calls aren't on typescript interface yet: | |
const sdkAny = sdk as any; | |
const practiceList = await sdkAny.practiceService.getPractices(consumer); | |
// need to filter here, for now just grab first | |
// const practiceID = 'AmwellPractice01'; | |
const firstPractice = practiceList.practices[0]; | |
const onDemandSpecialties = await sdkAny.practiceService.getOnDemandSpecialties(consumer, firstPractice); | |
const firstOnDemandSpecialty = onDemandSpecialties[0]; | |
const visitContext = await sdkAny.visitService.getVisitContext(consumer, firstOnDemandSpecialty); | |
// amwell mutates visit object passed and also returns a visit | |
const visit = await sdkAny.visitService.createOrUpdateVisit(visitContext); | |
const visitWithCost = await sdkAny.visitService.waitForVisitCostCalculationToFinish(visit); | |
const visitWithProvider = await sdkAny.visitService.findFirstAvailable(visitWithCost); | |
const startedVisit = await sdkAny.visitService.startVisit(visitWithProvider); | |
const telehealthVideoLaunched = await sdkAny.visitService.launchTelehealthVideo(startedVisit); | |
if (!telehealthVideoLaunched) { | |
const installUrl = sdkAny.visitService.telehealthVideoInstallUrl; | |
// we'd show something like this if launch fails: | |
// <a href={installUrl} download> | |
} | |
const visitWithVideoStarted = await sdkAny.visitService.waitForTelehealthVideoToStart(startedVisit); | |
const visitWithProviderJoined = await sdkAny.visitService.waitForProviderToJoinVisit( | |
visitWithVideoStarted, | |
updatedVisit => { | |
console.log('visit polling update:', updatedVisit); | |
} | |
); | |
const connectedVisit = await sdkAny.visitService.updateConnectionStatus(visitWithProviderJoined); | |
const finishedVisit = await sdkAny.visitService.waitForVisitToFinish(connectedVisit); | |
const visitSummary = await sdkAny.visitService.getVisitSummary(finishedVisit); | |
console.log('done'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment