PatoLab includes a fully collaborative, multi-section report editor designed specifically for pathology workflows. Multiple pathologists can simultaneously edit different sections of the same report in real time, with each user’s cursor position, edits, and formatting changes instantly visible to collaborators. The editor is built on TipTap as the rich-text foundation, Yjs as the conflict-free replicated data type (CRDT) engine, and Hocuspocus as the WebSocket collaboration server that brokers document state between connected clients and persists it back to Laravel.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/lerichardv/patolab-platform/llms.txt
Use this file to discover all available pages before exploring further.
Architecture Overview
Browser connects
The React editor opens a WebSocket connection to the Hocuspocus server using a room name formatted as
report-{id}-{field} (e.g. report-42-macroscopy). The server fires an onConnect webhook to Laravel, which returns the saved Yjs binary state for that field so the editor is pre-populated.User types
As a pathologist types, TipTap generates Yjs update operations. Hocuspocus broadcasts these deltas to all other connected clients in the same room in real time.
Auto-save
When a typing pause threshold is reached, Hocuspocus fires an
onChange webhook to Laravel containing the updated binary Yjs state (document) and the rendered HTML (html). Laravel saves both: the binary state to the yjs_*_state column for future reconnections, and the HTML to the *_html column for PDF generation.The collaboration server must be running and reachable at the URL defined in the
VITE_COLLABORATION_SERVER_URL environment variable. The React frontend uses this variable to establish WebSocket connections. If the server is unreachable, the editor will still function in single-user offline mode, but real-time collaboration and auto-save will not work.Room Naming Convention
Each editable section of a report gets its own isolated collaboration room. Room names follow the pattern:| Room suffix | HTML column | Yjs state column |
|---|---|---|
macroscopy | macroscopy_html | yjs_macroscopy_state |
microscopy | microscopy_html | yjs_microscopy_state |
diagnosis | diagnosis_html | yjs_diagnosis_state |
clinical_details | clinical_details_html | yjs_clinical_details_state |
comments_notes | comments_notes_html | yjs_comments_notes_state |
protocols | protocols_html | yjs_protocols_state |
legend | legend_html | yjs_legend_state |
report_date | report_date | yjs_report_date_state |
sections_order | sections_order | (JSON, not binary) |
sections_order configuration.
Report State Machine
ASpecimenReport is created when a pathologist first opens a specimen’s report editor. At that point, the specimen status advances to macroscopic_review. From there, report workflow transitions are driven through:
| Target status | Timestamp set | Notes |
|---|---|---|
macroscopic_review | — | Initial state, set on report creation |
processing | macroscopy_finalization_datetime | Locks macroscopy phase |
microscopic_review | microscopy_finalization_datetime | Locks microscopy phase |
finalized | report_finalization_datetime | Generates PDF, calculates commissions, sends WhatsApp to patient |
Transitioning to
finalized requires all assigned pathologists to have a saved signature on their user profile. If any assigned pathologist is missing a signature, the transition is blocked and an error listing the missing names is returned.Report Editor Endpoints
Open the editor
Open the editor
SpecimenReport, assigned pathologists, and available supply products (insumos) for the current user.Create the initial report record
Create the initial report record
SpecimenReport row for the specimen and advances the specimen status to macroscopic_review. If the pathologist has a saved specimen type template matching the specimen’s type and examination, the template’s HTML content is pre-populated into all editor sections.Returns an error if a report already exists for this specimen.Manual save
Manual save
macroscopy_access can write macroscopy_html, and only those with microscopy_access can write microscopy_html. The diagnosis, clinical_details, comments_notes, protocols, and legend sections are writable by anyone with either access flag.Update report date
Update report date
report_date field on the linked SpecimenReport. Requires the calling user to have at least one access flag (macroscopy or microscopy) on this specimen.Preview PDF
Preview PDF
storage/public/temp_reports/{sequence_code}/. Returns a public URL and the total page count so the editor can display a preview.Upload an image
Upload an image
storage/public/report-images/{sequence_code}/ and the public URL is returned.Link billed products (insumos)
Link billed products (insumos)
insumos) charged to this specimen. The controller intelligently reconciles stock: quantities that are reduced restore stock back to inventory, and quantities that are increased deduct from inventory with full movement logging.Download final PDF
Download final PDF
report_file on the SpecimenReport, it is served directly. Otherwise, the PDF is generated on the fly from the current report HTML.Finalize and regenerate PDF
Finalize and regenerate PDF
Webhook Endpoint
The Hocuspocus server communicates with Laravel through a single webhook route:onConnect (initialization), create (room setup), and onChange (background save).
