Medical Records Web SDK - Implementation
This guide provides everything you need to integrate the Medical Records Web SDK into your application.
Overview
The Medical Records Web SDK (@eka-care/medical-records-ts-sdk) is a TypeScript SDK for the Eka Care Medical Records API. It is offline-first and works in both browser and Electron renderer environments. It provides:
- Records Management: Upload, list, group, download, edit and delete medical documents.
- Smart Reports: Fetch AI-extracted structured data from lab reports.
- Cases: Organise records into cases (folders) — a record can belong to multiple cases.
- Offline Support: All data is cached in IndexedDB; writes done offline are auto-synced on reconnect.
- Reactive UI Updates: Subscribe to DB change events so your UI auto-updates on any write.
- Electron Support: Route API calls through an IPC bridge with a single config switch.
Installation
Prerequisites
- A modern web browser (or Electron renderer) with IndexedDB support.
- A valid auth token generated via the Connect Login API.
Setup
Quick Start
Configuration
Parameters:
These headers are merged into every HTTP request automatically.
Full config example
Authentication
The token is sent as Authorization: Bearer <token> on every request.
On a 401 response, onUnauthorized is called — return a fresh token to auto-retry once.
Error Handling
editDocument, deleteDocument, createCase, updateCase, deleteCase
never throw on network failure — local state is always updated and server
sync retries automatically.
Document Types
The document type is supplied by your UI — the SDK just stores the code (passed as documentType on upload/edit). The type codes come from the hub API.
Common codes for reference:
Troubleshooting
Common Issues
1. APIs Not Being Called
Problem: API requests are not triggered or return errors.
Solution:
- Ensure the auth token is set via
sdk.setAuthToken() and has not expired.
- Verify
bid and patientId are passed on every call.
2. 401 Loops
Problem: Requests keep failing with 401.
Solution:
- Implement
onUnauthorized and return a fresh token — the SDK auto-retries once.
- If the refresh itself fails, redirect the user to login.
3. Stale Data in UI
Problem: The UI shows old records after an upload, edit or delete.
Solution:
- Subscribe to
documents:changed / cases:changed events and re-query the local DB. See Offline & Sync.