Skip to content

Media — events ​

Per-module slice of docs/events-catalog.md (auto-generated). Update both files when adding or removing events.

Published ​

EventWhenPayloadSubscribers
document.uploadedDocumentService.create_document — every upload, photos and X-rays included; transactional (db=db).document_id, clinic_id, patient_id, title, document_type, media_kind, media_category, media_subtypepatient_timeline (drops media_kind photo/xray, which get their own card from media.photo_uploaded)
media.photo_uploadedSame call, additionally, when media_kind is an image kind; transactional.document_id, clinic_id, patient_id, title, media_kind, media_category, media_subtype, captured_at (nullable)imaging_viewer, patient_timeline
document.deletedDocumentService.delete_document.document_id, clinic_id, patient_id—
media.pair_createdpair — before/after pairing set on two documents of the same patient.clinic_id, patient_id, document_a_id, document_b_idpatient_timeline
media.pair_removedunpair.clinic_id, patient_id, document_id, former_partner_id—
media.attachment_linkedAttachmentService.link — a document attached to an owner through the registry.attachment_id, clinic_id, document_id, owner_type, owner_id, patient_id—
media.attachment_unlinkedAttachmentService.unlink (the document stays).attachment_id, clinic_id, document_id, owner_type, owner_id—

Subscribed ​

EventHandlerModeEffect
patient.archived__init__.py::MediaModule._on_patient_archivedtransactional (ADR 0019)Soft-archive the patient's documents, atomically with the archive itself.

Adding a new event ​

  1. Add the constant to backend/app/core/events/types.py (EventType).
  2. Publish from a service method after flush() — the bus runs handlers inline, before the request commits. Pass db=db so transactional subscribers can join the transaction (ADR 0019, issue #183).
  3. Add the row to the table(s) above.
  4. Run python backend/scripts/generate_catalogs.py to refresh the global catalog.