Skip to main content

API Reference

All endpoints require a valid RS256 Bearer token from the Auth Server.

Base URL: http://localhost:8083

Referral CRUD

Create referral (draft)

POST /api/referrals
Role: CLINICIAN or ADMIN

Creates a referral in DRAFT status. No consent check at this stage.

FieldRequiredDescription
patientIdFHIR Patient reference
requesterIdFHIR Practitioner reference of referring clinician
receivingFacilityClientIdSMART client_id of receiving facility
performerIdFHIR Organization reference
referralCodeSNOMED CT code
priorityROUTINE (default), URGENT, ASAP, STAT
reasonCodesICD-10 or SNOMED CT list (max 20)
clinicalNoteFree text (max 2048 characters)
sharedResourceTypesFHIR resource types to share via consent gate (max 20)
supportingInfoFHIR references to attached documents (max 20)
occurrenceDateIntended appointment/procedure date

Response: 201 Created


Get referral

GET /api/referrals/{id}
Role: CLINICIAN, ADMIN, or PATIENT

Returns 404 if not found.


My referrals (requester view)

GET /api/referrals/my-referrals?page=0&size=20
Role: CLINICIAN or ADMIN

Returns referrals created by the authenticated clinician (identified by JWT subject), newest first. Paginated.


Patient's referrals

GET /api/referrals/patient/{patientId}
Role: CLINICIAN or ADMIN, or the patient themselves

Receiving facility inbox

GET /api/referrals/inbox?performerId=Organization/royal-london-cardiology
Role: CLINICIAN or ADMIN

Returns all active referrals where performer_id matches. Ordered by priority (STAT first) then created_at ascending.


Workflow actions

Send referral

POST /api/referrals/{id}/send
Role: CLINICIAN or ADMIN

Runs the consent gate. Transitions DRAFT → ACTIVE if all consent checks pass.

Success: 200 — updated referral with status: ACTIVE

Consent gate failure: 422

{
"code": "CONSENT_GATE_FAILED",
"message": "Cannot send referral — patient has not consented to share Condition with ..."
}

Invalid state: 422

{
"code": "INVALID_TRANSITION",
"message": "Cannot send referral in status ACTIVE — must be DRAFT"
}

Update task status

PATCH /api/referrals/{id}/tasks/{taskId}
Role: CLINICIAN or ADMIN

Used by the receiving facility to progress the workflow.

{
"status": "ACCEPTED",
"note": "Appointment booked for 15 July at 14:00",
"rejectionReason": null
}

Valid transitions:

  • REQUESTEDRECEIVED, CANCELLED
  • RECEIVEDACCEPTED, REJECTED, CANCELLED
  • ACCEPTEDINPROGRESS, CANCELLED
  • INPROGRESSCOMPLETED, ONHOLD, FAILED
  • ONHOLDINPROGRESS, CANCELLED

Invalid transitions return 422 with INVALID_TRANSITION.


Revoke referral

POST /api/referrals/{id}/revoke?reason=...
Role: CLINICIAN or ADMIN

Cancels all open tasks. The referral and task records are preserved.


Hold referral

POST /api/referrals/{id}/hold?reason=...
Role: CLINICIAN or ADMIN

Only valid when status = ACTIVE.


Resume referral

POST /api/referrals/{id}/resume
Role: CLINICIAN or ADMIN

Only valid when status = ONHOLD.


Tasks

Get tasks for referral

GET /api/referrals/{id}/tasks
Role: CLINICIAN or ADMIN

Returns all tasks for the referral, oldest first.


Admin

Stats

GET /api/referrals/stats
Role: ADMIN
{
"draft": 12,
"active": 234,
"completed": 1820,
"revoked": 43
}

Error responses

All errors return RFC 7807 ProblemDetail or the referral module's own error record:

{ "code": "CONSENT_GATE_FAILED", "message": "..." }
{ "code": "INVALID_TRANSITION", "message": "..." }
HTTP StatusWhen
201Referral created
200Action succeeded
400Validation failure (missing required field, invalid value)
401Missing or invalid Bearer token
403Insufficient role
404Referral or task not found
422Consent gate failed or invalid state transition
500Unexpected server error (details in server log only)

Next: Configuration →