# API documentation

Authenticated API routes are defined in `routes/api.php`. `GET /api/me` returns the signed-in user's basic identity. `GET /api/patients/search?q=...` performs a facility-scoped patient lookup. These routes use Laravel Sanctum (`laravel/sanctum`); configure an approved token issuance/client onboarding mechanism before exposing API access. Token issuance and API client onboarding are not included in the current UI.


## Interoperability additions

FHIR-like R4 endpoints (authenticated with Sanctum): `GET /api/fhir/R4/metadata`, `GET /api/fhir/R4/Patient`, `GET /api/fhir/R4/Patient/{id}`, `GET /api/fhir/R4/Encounter`, `GET /api/fhir/R4/Encounter/{id}`. Supported search parameters are limited to `_id`, `identifier`, `name`, `patient`, and `_count` as applicable. This is a narrow read-only adapter, not a complete FHIR implementation. `GET /api/terminology/search?system=ICD-10&category=diagnosis&q=...` searches mappings loaded by an authorised administrator. Do not load proprietary terminology content without the appropriate licence.

Inventory stocktake sync uses authenticated web session and CSRF: `POST /sync/inventory-stocktake`. It requires `client_operation_id`, `batch_id`, expected quantity and timestamp, counted quantity and reason. It detects stale server snapshots and returns HTTP 409 without overwriting changed stock. Conflict records can be reviewed at `/sync/conflicts` (JSON) and via the conflict review screen. DHIS2 preview: `GET /integrations/dhis2/preview?from=YYYY-MM-DD&to=YYYY-MM-DD`; outbound submission requires server-side DHIS2 credentials and approved mapping configuration.
