mirror of
https://github.com/AmanTahiliani/FHIR-Sandbox.git
synced 2026-08-07 19:56:17 -04:00
chore: remove DB and binary from repo, add .gitignore to exclude artifacts
This commit is contained in:
141
README.md
141
README.md
@@ -1,86 +1,83 @@
|
||||
# FHIR-Sandbox: SMART on FHIR Integration Application
|
||||
# FHIR-Sandbox: SMART on FHIR Healthcare Platform
|
||||
|
||||
A Go-based application that demonstrates integration with Electronic Health Record (EHR) systems using the SMART on FHIR protocol.
|
||||
A production-quality Go-based platform for integrating with Electronic Health Record (EHR) systems using the SMART on FHIR protocol. This sandbox demonstrates authentication, persistence, and dashboarding for patient and practitioner data.
|
||||
|
||||
## Overview
|
||||
## Features
|
||||
|
||||
This application implements a SMART on FHIR client that can:
|
||||
- Launch from an EHR context
|
||||
- Authenticate using OAuth 2.0
|
||||
- Retrieve patient information from FHIR servers
|
||||
- Display patient details in a structured format
|
||||
- **SMART on FHIR Launch:** Supports the full SMART App Launch flow (EHR launch and standalone).
|
||||
- **Identity Resolution:** Correctly handles practitioner identification from both `practitioner` and `user` (Practitioner/ID) fields in OAuth2 token responses.
|
||||
- **SQLite Persistence:** Persists patient and practitioner data upon successful launch using a pure-Go SQLite driver (no CGO required).
|
||||
- **Session Management:** Server-side sessions stored in SQLite with secure, HttpOnly cookies.
|
||||
- **Responsive Dashboard:** A modern UI built with Go `html/template` that displays patient demographics and practitioner details.
|
||||
- **Extensible Architecture:** Clean package separation (`handlers`, `db`, `fhir`, `models`, `middleware`, `config`) designed for growth.
|
||||
|
||||
## Architecture
|
||||
|
||||
The project is structured into modular packages under `/app`:
|
||||
- `/db`: Database schema, migrations, and CRUD operations using `modernc.org/sqlite`.
|
||||
- `/fhir`: FHIR R4 resource definitions and SMART discovery/client logic.
|
||||
- `/handlers`: HTTP request handlers and template rendering.
|
||||
- `/middleware`: Session loading and authentication guards.
|
||||
- `/models`: Shared data structures.
|
||||
- `/templates`: HTML templates with layout inheritance.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Go 1.16 or higher
|
||||
- Access to a SMART on FHIR-compatible EHR system
|
||||
- Client credentials (client ID and secret) from your EHR system
|
||||
- **Go 1.24+**
|
||||
- **No external database required** (uses embedded SQLite)
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. **Clone the repository:**
|
||||
```bash
|
||||
git clone https://github.com/AmanTahiliani/FHIR-Sandbox.git
|
||||
cd FHIR-Sandbox
|
||||
```
|
||||
|
||||
2. **Run the application:**
|
||||
```bash
|
||||
go run app/main.go
|
||||
```
|
||||
The server starts on `http://localhost:8080`.
|
||||
|
||||
3. **Test with a Sandbox:**
|
||||
Use the [SMART Health IT Sandbox](https://launch.smarthealthit.org/):
|
||||
- **App Launch URL:** `http://localhost:8080/launch`
|
||||
- **Redirect URL:** `http://localhost:8080/auth-redirect`
|
||||
- The default configuration in `main.go` is pre-set to work with the SmartHealthIT sandbox.
|
||||
|
||||
## Configuration
|
||||
|
||||
The application uses a configuration structure defined in `main.go`. You'll need to configure:
|
||||
Configuration is currently managed in `app/main.go` via `config.AppConfig`. You can define multiple EHRs, set your redirect URI, and required scopes.
|
||||
|
||||
1. SMART App settings:
|
||||
```go
|
||||
SMARTAppConfig {
|
||||
redirectPath: "http://localhost:8080/auth-redirect",
|
||||
clientID: "your-client-id",
|
||||
clientSecret: "your-client-secret",
|
||||
scopes: []string{"launch", "patient/*.read"},
|
||||
}
|
||||
2. EHR Client settings:
|
||||
```go
|
||||
EHRClientsConfig {
|
||||
name: "EHR_NAME",
|
||||
url: "https://your-ehr-fhir-endpoint.com",
|
||||
authType: "auth-2",
|
||||
clientID: "your-ehr-client-id",
|
||||
clientSecret: "your-ehr-client-secret",
|
||||
patientAPI: true,
|
||||
}
|
||||
```
|
||||
## Installation
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone github.com/AmanTahiliani/fhir-sandbox.git
|
||||
cd fhir-sandbox
|
||||
```go
|
||||
cfg := &config.AppConfig{
|
||||
DBPath: "fhir_sandbox.db",
|
||||
SMART: config.SMARTConfig{
|
||||
RedirectURL: "http://localhost:8080/auth-redirect",
|
||||
Scopes: []string{"openid", "profile", "launch", "patient/*.read", "user/*.read"},
|
||||
},
|
||||
EHRs: []config.EHRConfig{
|
||||
{
|
||||
Name: "SmartHealthIT Sandbox (R4)",
|
||||
FHIRURL: "https://launch.smarthealthit.org/v/r4/fhir",
|
||||
ClientID: "your-client-id",
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
go mod tidy
|
||||
```
|
||||
|
||||
## Running the Application
|
||||
|
||||
1. Start the application:
|
||||
```bash
|
||||
go run main.go
|
||||
```
|
||||
2. The application will start and listen on `http://localhost:8080`.
|
||||
|
||||
## Endpoints
|
||||
- `/` - Root endpoint, displays welcome message
|
||||
- `/launch` - SMART launch endpoint
|
||||
- `/auth-redirect` - OAuth2 redirect endpoint
|
||||
|
||||
## SMART on FHIR Launch Flow
|
||||
|
||||
- EHR system initiates launch with parameters:
|
||||
- `launch` - Launch ID
|
||||
- `iss` - FHIR server URL
|
||||
- Application authenticates with the EHR:
|
||||
- Retrieves SMART configuration
|
||||
- Initiates OAuth2 flow
|
||||
- Exchanges code for access token
|
||||
- Application retrieves and displays patient information
|
||||
|
||||
## Testing
|
||||
|
||||
You can test the application using a FHIR server that supports SMART on FHIR. Ensure you have the necessary credentials and configuration.
|
||||
A good EHR Launcher to test with is: o test with is: [SMART Health IT Sandbox](https://launch.smarthealthit.org/). Some of the steps you would need to take are:
|
||||
- Create a new EHR client in the sandbox
|
||||
- Add the redirect URL
|
||||
- Add the client ID and secret
|
||||
- Add the scopes
|
||||
- Set the same client ID and secret in the application
|
||||
The project includes unit tests for database logic and FHIR parsing.
|
||||
|
||||
```bash
|
||||
go test ./...
|
||||
```
|
||||
|
||||
## Future Improvements
|
||||
|
||||
- [ ] Support for Observations, Conditions, and Encounters.
|
||||
- [ ] Move configuration to a YAML/TOML file.
|
||||
- [ ] Add structured logging (slog).
|
||||
- [ ] Implement Refresh Token handling.
|
||||
|
||||
Reference in New Issue
Block a user