Skip to main content

API Routes

The ChartChat server is an Express application. All routes are registered in packages/server/src/app.ts.


Route Groups​

PrefixRouter filePurpose
/healthcheckhealthcheck.tsLiveness probe — returns 200 OK
/openapi.jsonopenapi.tsOpenAPI spec
/.well-known/wellknown/OIDC discovery, JWKS
/auth/auth/routes.tsAuthentication (login, register, MFA, external)
/oauth2/oauth/routes.tsOAuth2 token endpoints
/fhir/R4/fhir/routes.tsFHIR R4 resource CRUD and operations
/fhir/R4/Binaryfhir/binary.tsBinary file upload/download
/fhir/ehr-import/ehr-import/routes.tsEHR OAuth connect, callback, disconnect, sync
/fhir/ (custom)fhir/customRoutes.tsChartChat-specific FHIR extensions
/fhir/ (export)fhir/exportPatient.tsPatient data export
/fhir/ (import)fhir/importPatient.tsPatient data import
/smart/smart/routes/launch.tsSMART on FHIR launch
/smart/patient-summarysmart/routes/patient-summary.tsAI patient summary
/admin/admin/routes.tsAdmin API (users, bots, secrets, etc.)
/api/admin/queuesworkers/bullboard.tsBullMQ queue dashboard
/api/audit/audit/audit-routes.tsAudit log query
/support/v1/support/routes.tsSupport ticket system
/email/v1/email/routes.tsEmail sending
/dicom/PS3/dicom/routes.tsDICOM image handling
/scim/v2/scim/routes.tsSCIM user provisioning
/keyvalue/v1/keyvalue/routes.tsKey-value store
/storage/storage/routes.tsBinary storage
/webhook/webhook/routes.tsWebhook receivers
/fhircast/STU2/fhircast/routes.tsFHIRcast STU2
/fhircast/STU3/fhircast/routes.tsFHIRcast STU3
/mcp/mcp/routes.tsModel Context Protocol (if enabled)

All Endpoints​

Complete flat reference of every endpoint exposed by the ChartChat server.

System​

MethodPathAuthDescription
GET/healthcheckNoneLiveness probe — returns 200 OK
GET/openapi.jsonNoneOpenAPI spec

Auth & MFA​

MethodPathAuthDescription
POST/auth/loginNoneEmail + password login
POST/auth/registerNoneNew user registration
POST/auth/mfa/statusBearerReturns MFA enrollment state and QR code URI if not enrolled
POST/auth/mfa/enrollBearerConfirms TOTP enrollment with a 6-digit code
POST/auth/mfa/verifyNoneVerifies TOTP during login flow
POST/auth/mfa/disableBearerDisables MFA after verifying current TOTP code

OAuth2​

MethodPathAuthDescription
POST/oauth2/tokenNoneIssues access / refresh tokens
POST/oauth2/revokeNoneRevokes a refresh token
GET/.well-known/openid-configurationNoneOIDC discovery document
GET/.well-known/jwks.jsonNoneJSON Web Key Set for token verification

EHR Import​

MethodPathAuthDescription
POST/fhir/ehr-import/startPatientBegins EHR OAuth for a built-in provider — returns authorizeUrl
POST/fhir/ehr-import/hospital-startPatientBegins EHR OAuth for a HospitalIntegration using dynamic SMART discovery
GET/fhir/ehr-import/callbackNoneOAuth callback — exchanges code, creates/updates PatientEHRConnection, triggers sync
GET/fhir/ehr-import/smart-discoveryNoneProbes a FHIR base URL for its SMART .well-known/smart-configuration
POST/fhir/ehr-import/disconnect/:connectionIdPatientRevokes an EHR connection and clears its Redis token cache

EHR Sync​

MethodPathAuthDescription
POST/fhir/referesh/all-ehrsPatientQueues a background sync of all active EHR connections for the patient
POST/fhir/referesh/single/:connectionIdPatientQueues a background sync for one specific EHR connection
GET/fhir/referesh/statusPatientReturns current sync state (idle / syncing) and last result

SMART on FHIR (Provider Launch / SSO)​

MethodPathAuthDescription
GET/smart/launchNoneEntry point for EHR-initiated SMART launch — validates iss + launch params and redirects to EHR auth
GET/smart/callbackNoneOAuth callback for SMART launch — exchanges code and creates session
GET/smart/medplum/loginNoneInitiates Medplum SSO login flow
GET/smart/medplum/callbackNoneHandles Medplum SSO OAuth callback
POST/smart/medplum/resumeNoneResumes Medplum login after MFA challenge
GET/smart/sync/patientBearerManually triggers a patient data sync (admin/provider use)
POST/smart/patient-summaryBearerGenerates an AI-powered patient summary

Document Proxy​

MethodPathAuthDescription
GET/fhir/binary-proxy/:binaryIdPatientStreams a FHIR Binary file from S3 — enforces access policy server-side
GET/fhir/url-proxyPatientProxies a pre-signed storage URL — prevents exposing S3 URLs to the browser

FHIR R4​

MethodPathAuthDescription
*/fhir/R4/*BearerStandard FHIR R4 CRUD and search for all resource types
*/fhir/R4/BinaryBearerBinary file upload and download
GET/fhir/get-access-policyBearerReturns the access policy ID assigned to the authenticated user's project membership
GET/fhir/hospitals/searchPatientSearches Organization + Endpoint resources by name, state, city, or postal code
POST/fhir/epic/exchange-tokenNoneExchanges an Epic authorization code for tokens server-side
DELETE/fhir/deletePatient/:idAdminDeletes a patient and all associated FHIR resources
POST/fhir/import/bulk-patientAdminBulk-imports patient data from NDJSON export URLs

Audit​

MethodPathAuthDescription
GET/api/audit/logsAdminQueries AuditEvent resources with filters

Support Tickets​

MethodPathAuthDescription
POST/support/v1/create-ticketPatientCreates a support ticket and sends a confirmation email
PATCH/support/v1/admin/tickets/:idAdminUpdates ticket status, priority, or internal notes
POST/support/v1/admin/tickets/:id/replyAdminSends a reply to the patient and creates an in-app notification

Admin​

MethodPathAuthDescription
*/admin/*AdminAdmin API — user management, bots, secrets, project config
GET/api/admin/queuesAdminBullMQ queue dashboard (Bull Board UI)

EHR Import Routes​

These are ChartChat's custom routes for EHR OAuth and sync. All under /fhir/ehr-import/.

MethodRouteAuthDescription
POST/fhir/ehr-import/startPatient tokenBegins EHR OAuth — returns authorizeUrl for a built-in EHR provider (epic, healow, meditech)
POST/fhir/ehr-import/hospital-startPatient tokenBegins EHR OAuth for a HospitalIntegration — discovers SMART endpoints dynamically
GET/fhir/ehr-import/callbackNone (browser redirect)OAuth callback — exchanges code for token, creates/updates PatientEHRConnection, triggers background sync
POST/fhir/ehr-import/disconnect/:connectionIdPatient tokenSets connection status: revoked and clears Redis token cache

Audit Routes​

MethodRouteAuthDescription
GET/api/audit/logsAdmin tokenQuery audit events with filters

Support Routes​

MethodRouteAuthDescription
POST/support/v1/create-ticketPatient tokenCreate a support ticket (rate limited 10/15 min)
PATCH/support/v1/admin/tickets/:idAdmin tokenUpdate ticket status, priority, or internal notes
POST/support/v1/admin/tickets/:id/replyAdmin tokenSend a reply to the patient and email notification

See Custom API Routes for full request/response documentation.


Middleware Stack​

Every request passes through this middleware chain (in order):

  1. standardHeaders — Sets security headers: Cache-Control, Strict-Transport-Security, Content-Security-Policy, Permissions-Policy, Referrer-Policy, X-Content-Type-Options, X-Frame-Options, X-XSS-Protection
  2. CORS — Configured in cors.ts — restricts origins to allowed domains
  3. CSRF protection — csrf.ts — validates CSRF token on non-GET requests
  4. Compression — gzip response compression
  5. Request context — attachRequestContext — sets up per-request logging and user context
  6. Request logging — requestLogMiddleware — writes every request to the RequestLog DB table
  7. Rate limiting — rateLimitHandler — per-IP limits (stricter on auth endpoints)
  8. Body parsers — URL-encoded, JSON (up to maxJsonSize), HL7 v2 text

Error Handling​

Unhandled errors are caught by the global errorHandler middleware at the end of the chain:

Error typeResponse
FHIR OperationOutcomeReturned as-is with appropriate HTTP status
entity.parse.failed400 Bad Request — invalid JSON/body
entity.too.large400 Bad Request — payload over size limit
UnsupportedMediaTypeError415 Unsupported Media Type
Other500 Internal Server Error