How kirangoyal20/ehr-dashboard works
EHR Patient Dashboard is a Next.js application for synchronizing patients, conditions, and medication requests from HAPI, Oracle Health, and Epic, normalizing them into PostgreSQL, and presenting a unified patient view. The main workflow runs from dashboard/API requests through vendor-specific synchronization, FHIR mapping, and idempotent persistence, then reads persisted records through patient APIs for display. Epic adds a SMART OAuth/PKCE authorization flow. Source excerpts show the sync and database calls; README statements support the dashboard capabilities and broader product flow where route internals were not excerpted.
Main entry points: patients.ts Patient queries and upserts · PatientDashboard.tsx Patient dashboard · hapi/sync.ts HAPI synchronization · oracle/sync.ts Oracle synchronization
Components 27
Dashboard and API
- Patient dashboard
src/components/PatientDashboard.tsx - Patient detail page
src/app/patients/[id]/page.tsx - Patient APIs
src/app/api/patients/route.ts - Patient detail API
src/app/api/patients/[id]/route.ts - HAPI sync route
src/app/api/sync/hapi/route.ts - Oracle sync route
src/app/api/sync/oracle/route.ts - Epic login route
src/app/api/auth/epic/login/route.ts - Epic callback route
src/app/api/auth/epic/callback/route.ts
EHR integrations
- HAPI synchronization
src/lib/ehr/hapi/sync.ts - HAPI FHIR client
src/lib/ehr/hapi/client.ts - HAPI resource mapping
src/lib/ehr/hapi - Oracle synchronization
src/lib/ehr/oracle/sync.ts - Oracle FHIR client
src/lib/ehr/oracle/client.ts - Oracle resource mapping
src/lib/ehr/oracle - Epic synchronization
src/lib/ehr/epic/sync.ts - Epic FHIR and OAuth client
src/lib/ehr/epic/client.ts
Persistence
- Patient queries and upserts
src/lib/db/patients.ts - Condition upserts
src/lib/db/conditions.ts - Medication upserts
src/lib/db/medications.ts - PostgreSQL
src/lib/db/migrations/001_initial.sql
Shared models
- Normalized EHR models
src/lib/ehr/models.ts - Patient view types
src/types/patient.ts
Other components
- Dashboard user
- HAPI FHIR service
- Oracle FHIR service
- Epic FHIR service
- Epic authorization service
Connections 41
- Dashboard user → Patient dashboard: views
README.md - Patient dashboard → Patient APIs: loads patients
README.md - Patient dashboard → HAPI sync route: requests sync
README.md - Patient dashboard → Oracle sync route: requests sync
README.md - Patient dashboard → Epic login route: starts connection
README.md - Patient detail page → Patient detail API: loads details
- Patient APIs → Patient queries and upserts: queries
src/app/api/patients/route.ts - Patient detail API → Patient queries and upserts: queries
src/app/api/patients/[id]/route.ts - HAPI sync route → HAPI synchronization: dispatches
src/app/api/sync/hapi/route.ts - Oracle sync route → Oracle synchronization: dispatches
src/app/api/sync/oracle/route.ts - Epic login route → Epic FHIR and OAuth client: creates authorization
src/app/api/auth/epic/login/route.ts - Epic authorization service → Epic callback route: returns code
README.md - Epic callback route → Epic FHIR and OAuth client: exchanges code
src/app/api/auth/epic/callback/route.ts - Epic callback route → Epic synchronization: starts sync
src/app/api/auth/epic/callback/route.ts - HAPI synchronization → HAPI FHIR client: fetches resources
src/lib/ehr/hapi/sync.ts - HAPI synchronization → HAPI resource mapping: maps resources
src/lib/ehr/hapi/sync.ts - HAPI synchronization → Patient queries and upserts: upserts patients
src/lib/ehr/hapi/sync.ts - HAPI synchronization → Condition upserts: upserts conditions
src/lib/ehr/hapi/sync.ts - HAPI synchronization → Medication upserts: upserts medications
src/lib/ehr/hapi/sync.ts - Oracle synchronization → Oracle FHIR client: fetches resources
src/lib/ehr/oracle/sync.ts - Oracle synchronization → Oracle resource mapping: maps resources
src/lib/ehr/oracle/sync.ts - Oracle synchronization → Patient queries and upserts: upserts patients
src/lib/ehr/oracle/sync.ts - Oracle synchronization → Condition upserts: upserts conditions
src/lib/ehr/oracle/sync.ts - Oracle synchronization → Medication upserts: upserts medications
src/lib/ehr/oracle/sync.ts - Epic synchronization → Epic FHIR and OAuth client: fetches resources
src/lib/ehr/epic/sync.ts - Epic synchronization → HAPI resource mapping: reuses FHIR mapping
src/lib/ehr/epic/sync.ts - Epic synchronization → Patient queries and upserts: upserts patients
src/lib/ehr/epic/sync.ts - Epic synchronization → Condition upserts: upserts conditions
src/lib/ehr/epic/sync.ts - Epic synchronization → Medication upserts: upserts medications
src/lib/ehr/epic/sync.ts - HAPI FHIR client → HAPI FHIR service: requests FHIR
README.md - Oracle FHIR client → Oracle FHIR service: requests FHIR
README.md - Epic FHIR and OAuth client → Epic FHIR service: requests FHIR
README.md - Epic FHIR and OAuth client → Epic authorization service: exchanges token
src/lib/ehr/epic/client.ts - Patient queries and upserts → PostgreSQL: reads and writes
- Condition upserts → PostgreSQL: upserts
- Medication upserts → PostgreSQL: upserts
- Patient dashboard → Patient view types: uses response types
src/components/PatientDashboard.tsx - Patient detail page → Patient view types: uses response types
src/app/patients/[id]/page.tsx - Patient queries and upserts → Normalized EHR models: accepts normalized records
src/lib/db/patients.ts - Condition upserts → Normalized EHR models: accepts normalized records
src/lib/db/conditions.ts - Medication upserts → Normalized EHR models: accepts normalized records
src/lib/db/medications.ts