|
| 1 | +# Example: SMART App Launch using Smartbox and Keycloak |
| 2 | + |
| 3 | +This example showcases the Smart App EHR and Patient [launch flows](https://hl7.org/fhir/smart-app-launch/app-launch.html). |
| 4 | + |
| 5 | +## Components |
| 6 | + |
| 7 | +1. Smartbox FHIR server with SMART-on-FHIR support. |
| 8 | +2. [Keycloak](https://www.keycloak.org/)\ |
| 9 | + Identity and Access Management solution that integrates with Aidbox through the [IdentityProvider](https://docs.aidbox.app/modules/security-and-access-control/set-up-external-identity-provider) resource. |
| 10 | +3. [Growth Chart Smart App](https://github.com/smart-on-fhir/growth-chart-app)\ |
| 11 | + A SMART pediatric web application that displays patient growth charts based on their observations. |
| 12 | +4. **Demo Launcher Page**\ |
| 13 | + A web page that emulates EHR patient context selection. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +* [Docker](https://www.docker.com/) |
| 18 | +* Cloned repository: [Github: Aidbox/examples](https://github.com/Aidbox/examples/tree/main) |
| 19 | +* Working directory: `smart-app-launch-smartbox` |
| 20 | + |
| 21 | +To clone the repository and navigate to the `smart-app-launch-smartbox` directory, run: |
| 22 | + |
| 23 | +```sh |
| 24 | +git clone [email protected]:Aidbox/examples.git && cd examples/smart-app-launch-smartbox |
| 25 | +``` |
| 26 | + |
| 27 | +Edit a `docker-compose.yaml` file and paste there your license keys. |
| 28 | + |
| 29 | +```yaml |
| 30 | +# docker-compose.yaml |
| 31 | +... |
| 32 | +services: |
| 33 | + portal: |
| 34 | + environment: |
| 35 | + AIDBOX_LICENSE: <YOUR_PORTAL_LICENSE> |
| 36 | +... |
| 37 | + sandbox: |
| 38 | + environment: |
| 39 | + AIDBOX_LICENSE: <YOUR_SANDBOX_LICENSE> |
| 40 | +``` |
| 41 | +
|
| 42 | +## Step 1: Run Demo Components |
| 43 | +
|
| 44 | +Start all the demo components by running: |
| 45 | +
|
| 46 | +```sh |
| 47 | +docker compose up |
| 48 | +``` |
| 49 | + |
| 50 | +Wait until all components are pulled and started. The components are accessible at: |
| 51 | + |
| 52 | +* Aidbox - [http://localhost:8888](http://localhost:8888) |
| 53 | +* Keycloak - [http://localhost:7777](http://localhost:7777) |
| 54 | +* Growth Chart - [http://localhost:9000](http://localhost:9000) |
| 55 | +* Demo Launcher Page - [http://localhost:7070/launcher.html](http://localhost:7070/launcher.html) |
| 56 | + |
| 57 | +## Step 2: Open launcher Page |
| 58 | + |
| 59 | +Open the [Demo Launcher Page](http://localhost:7070/launcher.html). |
| 60 | + |
| 61 | +* **Left Side:** A list of patients retrieved from Aidbox, simulating EHR patient context selection. |
| 62 | +* **Right Side:** A Patient Standalone Launch with a pre-selected patient context, simulating a launch directly from the SMART App. |
| 63 | + |
| 64 | +## Step 3: Perform EHR Launch |
| 65 | + |
| 66 | +**3.1** Select a patient from the list on the left side and click the `Launch Growth Chart App` button to start the launch process.\ |
| 67 | +**3.2** On the Aidbox login screen, click the `Sign in with Keycloak` button.\ |
| 68 | +**3.3** Log in to Keycloak with username `patient` and password `password`\ |
| 69 | +**3.4** On the consent screen, allow all requested scopes.\ |
| 70 | +**3.5** View the patient's data in the Growth Chart app. |
| 71 | + |
| 72 | +## Step 4: Perform Patient Standalone Launch |
| 73 | + |
| 74 | +**4.1** Go back to the [Demo Launcher](http://localhost:7070/launcher.html)\ |
| 75 | +**4.2** On the right side of the screen, click the **Launch Growth Chart App** button under Patient Standalone Launch.\ |
| 76 | +**4.2** On the consent screen, allow all requested scopes.\ |
| 77 | +**4.3** View the patient's data in the Growth Chart app. |
| 78 | + |
| 79 | +## EHR Launch Interaction Diagram |
| 80 | + |
| 81 | +```mermaid |
| 82 | +sequenceDiagram |
| 83 | + actor Customer as User |
| 84 | + participant EHR as EHR <br> (Demo Launcher) |
| 85 | + participant Aidbox as Aidbox |
| 86 | + participant Keycloak as Keycloak |
| 87 | + participant Smart App as Growth Chart <br> (SMART App) |
| 88 | + Note right of EHR: Communicates with Aidbox <br> using HTTP basic auth |
| 89 | + Customer ->> EHR: Launch Smart App |
| 90 | + activate EHR |
| 91 | + EHR ->> Smart App: Launch context |
| 92 | + deactivate EHR |
| 93 | + activate Smart App |
| 94 | + Smart App ->> Aidbox: Redirect to /auth/login?response_type=code&client_id.... |
| 95 | + deactivate Smart App |
| 96 | + activate Aidbox |
| 97 | + Aidbox ->> Keycloak: Redirect to Keycloak Login page |
| 98 | + deactivate Aidbox |
| 99 | + activate Keycloak |
| 100 | + Note right of Keycloak: Login with Keycloak credentials |
| 101 | + Keycloak ->> Aidbox: Response with code |
| 102 | + deactivate Keycloak |
| 103 | + activate Aidbox |
| 104 | + Aidbox ->> Keycloak: Request to exchange code to token |
| 105 | + deactivate Aidbox |
| 106 | + activate Keycloak |
| 107 | + Keycloak ->> Aidbox: Return token |
| 108 | + deactivate Keycloak |
| 109 | + activate Aidbox |
| 110 | + Aidbox ->> Keycloak: Request user info |
| 111 | + deactivate Aidbox |
| 112 | + activate Keycloak |
| 113 | + Keycloak ->> Aidbox: Return user info |
| 114 | + deactivate Keycloak |
| 115 | + activate Aidbox |
| 116 | + Aidbox ->> Aidbox: Create User resource in Aidbox |
| 117 | + Aidbox ->> Customer: Show the Grant screen |
| 118 | + deactivate Aidbox |
| 119 | + activate Customer |
| 120 | + Customer ->> Aidbox: Allow requested scopes |
| 121 | + deactivate Customer |
| 122 | + activate Aidbox |
| 123 | + Aidbox ->> Aidbox: Check granted permissions |
| 124 | + Aidbox ->> Smart App: Redirect with code |
| 125 | + deactivate Aidbox |
| 126 | + activate Smart App |
| 127 | + Smart App ->> Aidbox: Request /auth/token <br> to exchange code to token |
| 128 | + deactivate Smart App |
| 129 | + activate Aidbox |
| 130 | + Aidbox ->> Smart App: Return token |
| 131 | + deactivate Aidbox |
| 132 | + activate Smart App |
| 133 | + Smart App ->> Aidbox: Request /Observation and /Patient/<pt-id> with token |
| 134 | + deactivate Smart App |
| 135 | + activate Aidbox |
| 136 | + Aidbox ->> Aidbox: Validate scopes from token |
| 137 | + Aidbox ->> Smart App: Return Observations and Patient |
| 138 | + deactivate Aidbox |
| 139 | + activate Smart App |
| 140 | + Smart App ->> Customer: Show patient's data |
| 141 | + deactivate Smart App |
| 142 | +``` |
0 commit comments