Global Clinic Docsv1.0
Back to app
Docs / Developer Documentation

3. API Documentation

The current implementation uses mock data read through lib/data.ts. This section defines the production-ready APIs required to support every business workflow. The machine-readable contract is docs/developer/api/openapi.yaml (OpenAPI 3.1); this page is the readable guide to it: conventions first, then each of the 17 resource groups.

3.1 Conventions

Base URL and versioning

https://api.globalclinic.app/v1

The version is in the path (/v1). Breaking changes increment the major version; additive changes do not. The front-end reads the base URL from NEXT_PUBLIC_API_BASE_URL and calls it from the lib/data.ts seam.

Authentication

All endpoints except the public catalogue and the auth endpoints require a bearer access token (OAuth 2.1 / OIDC, short-lived JWT) in the Authorization: Bearer <token> header. Staff roles additionally require that the token was issued through an MFA-completed session. See Security.

Authorization

Every request is authorised server-side by role plus tenant and case scope, deny by default. A patient token resolves to one patient and one case; a clinic token to one clinic; staff tokens to assigned cases. Requests outside scope return 403. The RBAC matrix defines who can call what.

Request and response format

JSON only (Content-Type: application/json). Field names are camelCase and conform to the types in lib/schema.ts. Timestamps are ISO-8601 UTC. Money is an integer minor unit plus an ISO-4217 currency (never a float).

Pagination

List endpoints use cursor pagination: ?limit= (default 25, max 100) and ?cursor=. Responses include data[] and a page object with nextCursor and hasMore.

Idempotency

All POST endpoints that create resources or move money accept an Idempotency-Key header. Re-sending the same key returns the original result, never a duplicate. This is mandatory for payments, refunds, document uploads and visa submission.

Errors

Errors use standard HTTP status codes and a consistent body:

{
  "error": {
    "code": "validation_error",
    "message": "Human-readable summary.",
    "details": [{ "field": "documentId", "issue": "must reference a verified document" }],
    "requestId": "req_01H..."
  }
}

Common codes: 400 validation_error, 401 unauthenticated, 403 forbidden, 404 not_found, 409 conflict (for example a state-machine violation such as submitting an incomplete visa), 422 unprocessable, 429 rate_limited, 5xx server_error. Every response carries a requestId for support and tracing.

Rate limiting

Limits are per token and per IP, returned in RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset headers; 429 includes Retry-After. Indicative tiers:

SurfaceLimit
Public catalogue (unauthenticated)60 requests / minute / IP
Authenticated reads600 requests / minute / token
Writes (general)120 requests / minute / token
Money and document writes30 requests / minute / token, idempotency required
Auth (login, OTP, reset)10 requests / minute / IP, with lockout and backoff

Webhooks

Outbound webhooks (to clinics, agents and internal consumers) are signed with an HMAC X-GC-Signature header and delivered at-least-once with retry and backoff. Inbound webhooks (from payment, visa and travel partners) are verified by signature and idempotency key. See Integrations.

3.2 Resource groups

The endpoint tables below summarise each group. Full request and response schemas, validation and error responses are in the OpenAPI file. Methods follow REST conventions; :id and :caseId are path parameters.

1. Authentication and authorization

MethodPathPurpose
POST/auth/registerCreate an account (patient or clinic)
POST/auth/verify-emailVerify an email with a code
POST/auth/loginExchange credentials (and MFA for staff) for tokens
POST/auth/token/refreshRefresh an access token
POST/auth/logoutRevoke the current session
POST/auth/password/forgotBegin password reset
POST/auth/password/resetComplete password reset with a token
POST/auth/mfa/enroll and /auth/mfa/verifyStaff MFA enrolment and step-up
GET/auth/meCurrent principal, roles and tenant scope

Validation: email format, password policy, rate-limited OTP, single-use reset tokens. Errors: 401 on bad credentials, 429 on too many attempts. The reference build models this with a client-side mock (lib/auth.tsx, two demo accounts).

2. Patient management

MethodPathPurpose
GET/patients/:idPatient profile (self or authorised staff)
PATCH/patients/:idUpdate profile fields
GET/patients/:id/casesCases for a patient
POST/casesOpen a case (from an accepted enquiry)
GET/cases/:caseIdFull case with stage, corridor, coordinator
GET/cases/:caseId/journeyThe 14-stage progress with owners and SLA state
GET/cases/:caseId/activityActivity feed

Authorization: a patient may read and update only their own record and case; staff are case-scoped. Validation: currentStage 0 to 13 and forward-only; attendant count at most two.

3. Clinic management

MethodPathPurpose
GET/clinics/:idPublic clinic profile
PATCH/clinics/:idUpdate profile (own clinic)
GET/clinics/:id/inquiriesInbound inquiries, filter by status
POST/clinics/:id/inquiries/:inquiryId/quoteSend an itemised quote
PATCH/clinics/:id/inquiries/:inquiryIdDecline or update an inquiry
GET/clinics/:id/casesActive cases by stage
GET/PUT/clinics/:id/pricingRead and update indicative procedure prices
GET/POST/PATCH/clinics/:id/teamManage surgeons and staff
POST/clinics/:id/onboardingSubmit onboarding for review

Authorization: clinic-tenant isolation. Visibility rule: a clinic is publicly listed only when status = verified.

4. Provider management

Provider management is the clinical and operational side of a clinic: accreditation, empanelment, and milestone confirmation that drives escrow.

MethodPathPurpose
GET/POST/providers/:id/accreditationsAccreditations held (JCI, NABH, ISO)
POST/providers/:id/empanelmentSubmit or update empanelment evidence
GET/providers/:id/cases/:caseIdShared case data the provider may see
POST/cases/:caseId/milestones/:milestoneId/confirmProvider confirms a milestone (for example admission, discharge)

Authorization: empanelment review is owned by the Medical Director; milestone confirmation is restricted to the treating provider for the case. Confirming a milestone emits an event that the Payments service consumes to release escrow.

5. Treatment catalogue

Public, cacheable catalogue powering discovery.

MethodPathPurpose
GET/catalogue/specialtiesSpecialties
GET/catalogue/proceduresProcedures with indicative and reference pricing and savings
GET/catalogue/procedures/:keyOne procedure with cost breakdown
GET/catalogue/clinicsMarketplace search and filter (specialty, country, price, rating)
GET/catalogue/clinics/:id/pricingA clinic's indicative procedure prices
GET/catalogue/pricing/:procedureKeyItemised cost breakdown and home-market savings
GET/catalogue/networkDestinations and considerations

No authentication; aggressively cached at the CDN. All prices are labelled indicative.

6. Medical records

The documents wallet and secure storage.

MethodPathPurpose
GET/cases/:caseId/documentsList documents with status
POST/cases/:caseId/documentsCreate an upload (returns a pre-signed URL)
PUT(storage pre-signed URL)Upload the file directly to object storage
POST/cases/:caseId/documents/:docId/finalizeFinalise after upload (triggers scan)
POST/cases/:caseId/documents/:docId/verifyReviewer marks verified
GET/cases/:caseId/documents/:docId/downloadTime-limited, audited download URL

Validation: type (Identity, Medical, Visa, Financial, Travel), size and MIME checks, virus scan before verified. Authorization: patient uploads; only an authorised reviewer verifies. Every read and write is audited. Verifying a document with a linked visa checklist item updates that item (the signature flow).

7. Consultations

The specialist opinion workflow.

MethodPathPurpose
POST/cases/:caseId/consultationsOpen a consultation, attach records
GET/cases/:caseId/consultations/:idConsultation status and opinion
POST/cases/:caseId/consultations/:id/opinionSpecialist records the written opinion
POST/cases/:caseId/consultations/:id/request-recordsRequest specific additional records
GET/cases/:caseId/care-planCare-plan phases derived from the opinion

Authorization: specialist and coordinator, case-scoped. The opinion is the specialist's, recorded by the platform; the API stores authorship.

8. Appointments

Scheduling for consultations, admission, procedure and follow-up tele-consults.

MethodPathPurpose
GET/cases/:caseId/appointmentsAll appointments for a case
POST/cases/:caseId/appointmentsSchedule (consult, admission, procedure, follow-up 7/30/90)
PATCH/cases/:caseId/appointments/:idReschedule or update
POST/cases/:caseId/appointments/:id/cancelCancel with reason

Validation: no-show and reschedule rules; follow-up appointments default to day 7, 30 and 90. Conflicts return 409.

9. Visa management

The flagship engine, driven by Country Packs.

MethodPathPurpose
GET/cases/:caseId/visaApplication: hero, checklist, timeline
GET/cases/:caseId/visa/checklistChecklist with derived completion
POST/cases/:caseId/visa/submitSubmit (only when complete)
POST/cases/:caseId/visa/invitation-letterGenerate the invitation letter
GET/corridors/:corridorId/country-packCorridor rules: documents, fees, processing, routing

Validation: submit is rejected with 409 unless every checklist item resolves to done. Required documents come from the corridor Country Pack. Idempotent submit.

10. Travel management

Flights and transfers, coordinator-confirmed.

MethodPathPurpose
GET/cases/:caseId/travelTrip plan, options and current selections
GET/cases/:caseId/travel/flightsFlight options for the corridor and dates
GET/cases/:caseId/travel/transfersGround-transfer options
POST/cases/:caseId/travel/selectionSubmit preferred flight, transfer and add-ons
POST/cases/:caseId/travel/confirmTravel Desk confirms (staff)

Authorization: patient selects; Travel Desk confirms. Prices are indicative; confirmation calls airline and transfer providers (see Integrations).

11. Hotel management

Accommodation, attendant-aware.

MethodPathPurpose
GET/cases/:caseId/travel/staysAccommodation options near the hospital
POST/cases/:caseId/travel/stays/selectionSelect a preferred stay
POST/cases/:caseId/travel/stays/confirmTravel Desk confirms the booking

Filtering: attendant bed, halal kitchen, distance to hospital. Confirmation integrates a hotel-booking provider.

12. Payments and refunds

Escrow, milestones, ledger and refunds.

MethodPathPurpose
GET/cases/:caseId/paymentsTotal, held, currency, milestones, ledger
POST/cases/:caseId/payments/escrow/fundFund the escrow deposit
GET/cases/:caseId/payments/milestonesMilestone schedule and status
POST/cases/:caseId/payments/milestones/:id/releaseRelease on a verified trigger (system or finance)
POST/cases/:caseId/payments/refundsRequest a refund
GET/cases/:caseId/payments/ledgerAppend-only ledger

Validation: idempotency required; a milestone releases only on a verified trigger; pre-arrival refunds are full, post-milestone per schedule; ledger entries are immutable. Multi-currency per corridor. Integrates the payment and escrow partner.

13. Notifications

MethodPathPurpose
GET/cases/:caseId/notificationsNotifications for a case
POST/cases/:caseId/notifications/:id/readMark read
PUT/users/:id/notification-preferencesChannel preferences (in-app, WhatsApp, email, SMS)

Notifications are emitted by domain events (milestone, visa, travel, message) and delivered omnichannel.

14. Reviews and ratings

MethodPathPurpose
GET/reviewsPublic reviews, filter by clinic or procedure
GET/clinics/:id/reviewsA clinic's verified reviews
POST/cases/:caseId/reviewsSubmit a review at close-out (verified, attributed)
GET/reputationPlatform reputation aggregate and distribution

Rule: a verified review must tie to a completed, attributed case; genuine negative verified reviews are not suppressed.

15. Messaging and communication

MethodPathPurpose
GET/cases/:caseId/threadsThreads with the care team
GET/threads/:id/messagesMessages in a thread (paged)
POST/threads/:id/messagesSend a message (with attachments)
POST/threads/:id/readMark a thread read

Production is real-time (WebSocket or server-sent events) with an audit trail and omnichannel delivery prioritising WhatsApp; interpreter and translation support is Planned.

16. Administration

MethodPathPurpose
GET/POST/PUT/admin/country-packsVersioned, feature-flagged corridor rules
POST/admin/country-packs/:id/publishPublish a Country Pack version
GET/POST/admin/clinics/empanelmentManage the hospital panel
GET/PUT/admin/feature-flagsPlatform feature flags
GET/POST/admin/users and /admin/rolesStaff users and role assignment

Authorization: administrator only; all actions audited. Country Packs are versioned with an effective date so corridor rules change without a code release.

17. Reporting and analytics

MethodPathPurpose
GET/reports/funnelLead-to-case funnel by corridor and channel
GET/reports/slaStage SLA performance and breaches
GET/reports/conversionConversion and time-to-first-response, time-to-quote
GET/reports/affiliatesReferral attribution and payouts
GET/reports/outcomesCase outcomes and review capture

Reads are served from the analytics warehouse, not the operational store. Authorization: admin, finance and medical-director roles, scoped to their remit.

3.3 Mapping the data seam to the API

Today lib/data.ts exposes typed getters backed by static JSON. In production each getter becomes a fetch to the matching endpoint, returning the same lib/schema.ts types. For example:

// today
export const documents = documentsJson as unknown as Document[];

// production
export async function getDocuments(caseId: string): Promise<Document[]> {
  const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/cases/${caseId}/documents`, {
    headers: { Authorization: `Bearer ${token}` },
  });
  if (!res.ok) throw await toApiError(res);
  return res.json();
}

Server Components await the getter; client providers (PortalProvider, ClinicProvider) are seeded from server responses instead of static imports. The types do not change, so no view component changes.