AI Review Flow¶
End-to-end view of how a case flows from client submission through AI inference to a projected diagnosis.
Note on the admin dashboard: the "AI inferences" card and "AI diagnosis breakdown" donut on the admin dashboard are sourced from
clinical-api.DermReview(the direct-call audit table that records each request/response against DERM), not from theDiagnosisprojection described in step 5 below. DermReview is populated even by product integrations that go straight from clinical-api → DERM without engaging the orchestrator-mediated flow on this page, so it's the more reliable signal for "have we ever asked DERM about this case." Failure metrics on the dashboard partitionDermReview.status='failed'(non-2xx / pre-flight) from 2xx responses whoseresult_json.analysisResultis notPROCESSING_ANSWER_TYPE_SUCCESSFUL_PROCESSING.
Steps¶
-
Case submission — A client posts
POST /v1/clinical-api/caseswith case metadata and image references.clinical-apipersists theCaserow and associatedImagerows (patient PHI fields encrypted at rest with the patient's DEK), and returns 201. -
Workflow instantiation —
clinical-apiemitscase.createdto the Redis Stream.orchestratorconsumes the event, looks up the activeWorkflowDefinitionfor the organisation and product, snapshots it into a newWorkflowInstance, and schedules a workflow deadline via BullMQ. -
Consent check (if configured) — If the definition includes a
gate_on_consentstep, orchestrator dispatchesconsent.check.requested. Theconsentservice evaluates the patient'sConsentRecordand emitsconsent.check.completedwith agrantedboolean. Orchestrator advances (on_pass) or halts (on_fail). -
AI dispatch — Orchestrator dispatches
ai_review.requested. The payload includes presigned image URLs fromclinical-api.ai-reviewcreates anAiReviewrow, enqueues a BullMQ job, and sends the images to DERM AI. It persists the raw response inAiReviewResultand per-lesion detail inAiReviewLesion. -
Diagnosis projection —
ai-reviewemitsai_review.completed.clinical-apiconsumes this event and projects the AI diagnoses into itsDiagnosistable (source field:ai). These become the system-of-record diagnoses for the case unless overridden by a human review. -
Workflow completion — Orchestrator also consumes
ai_review.completed, evaluates the next-step expression, and (if no further steps are configured) dispatches the terminalemit_finalstep, which causes orchestrator to emitcase.workflow.completedtoclinical-api.
Code paths¶
- Case creation:
services/clinical-api/src/cases/cases.controller.ts/cases.service.ts case.createdemission:services/clinical-api/src/cases/cases.service.ts- Orchestrator
case.createdconsumer:services/orchestrator/src/consumers/case-created.consumer.ts - Orchestrator completion consumer:
services/orchestrator/src/consumers/completion-events.consumer.ts - Orchestrator dispatcher:
services/orchestrator/src/dispatcher/dispatcher.service.ts - AI review inbound consumer:
services/ai-review/src/events/ai-review-requested.consumer.ts - AI review event publisher:
services/ai-review/src/reviews/review.events.ts - Diagnosis projection (clinical-api):
services/clinical-api/src/ai-review/ai-review-consumer.service.ts
Related diagrams¶
The Mermaid sequence source is at docs/diagrams/ai-review-sequence.mmd.