Skip to content

feat(cardiology): reset the rhythm classification and captions from the patient page - #110

Merged
homarone00 merged 1 commit into
AImageLab-zip:mainfrom
theElandor:remove_annotation
Oct 12, 2026
Merged

homarone00 merged 1 commit into
AImageLab-zip:mainfrom
theElandor:remove_annotation

Conversation

@theElandor

Copy link
Copy Markdown
Contributor

Why

In production we need a quick way to remove annotations that are wrong, or that were made only for demo purposes. Today the cardiology rhythm call can be changed but never withdrawn, and captions can only be deleted one at a time. This PR adds a Reset action for both on the cardiology patient page, so a patient can be put back to "unannotated" in one step.

What changes

  • Reset classification (red button, Classification tab): withdraws the AF/NSR/Other/NI call. The patient then shows as unclassified on the patient page, in the "has classification" list filter and in exports. The button is disabled while there is no call.
  • Reset captions (red button, Captions tab): an annotator deletes all the captions they wrote on the patient; a project admin deletes every caption on it. These are the same owner/admin rules as the existing per-caption delete.
  • Both buttons open a confirmation dialog first (Cancel / red Reset). Users without write access see neither button.

How it fits the existing rules

  • Clearing the call goes through a new service, annotations.services.ecg_rhythm.clear_ecg_rhythm, which records a new empty revision rather than deleting rows:
    • The withdrawn call and its author stay on the audit trail.
    • The raw-ECG lock stays on: ever_annotated is monotonic.
    • A reset sent with an out-of-date revision is refused with 409, like a stale save.
    • The existing "latest revision" queries already read an empty latest revision as "no call", so the list filters and the export needed no change.
  • The caption reset is a shared view, reset_voice_captions, in common/domain_views/voice_captions.py next to the other caption views, but only cardiology routes it for now. Extending reset to the other domains needs decisions we haven't made yet: maxillo's occlusion is legacy-only storage and interacts with the raw-data lock, and laparoscopy has no captions panel. That is left for a follow-up.
  • No models change, so no migrations (makemigrations --check: no changes).

Tests

6 new tests in cardiology/tests.py (ResetTests):

  • Clearing records a revision and hides the call from the list filters and the export.
  • A stale clear gets 409, and clearing a patient with no call is a no-op.
  • Viewers can't clear the call or reset captions.
  • An annotator resets only their own captions; an admin resets everyone's.

The new URLs are covered automatically by common.tests_cross_project_matrix. cardiology, annotations, common.tests_cross_project_matrix and common.tests_domain_registry pass against MySQL (527 tests). ruff and lint-imports were not run locally; CI runs them.

Manual test

  1. Open a cardiology patient as an annotator.
  2. Set a rhythm, then click Reset classification and confirm: the selection clears.
  3. Add a couple of captions, then click Reset captions and confirm: your captions are gone.
  4. Repeat as an admin: captions by other users are removed too.

🤖 Generated with Claude Code

…he patient page

A red Reset button in the Classification tab withdraws the rhythm call; one
in the Captions tab deletes the user's own captions (every caption for a
project admin). Both ask for confirmation in a modal first.

Clearing the call records an empty revision rather than deleting rows, so the
audit trail survives, the raw-ECG lock stays on, and a stale reset is refused
with 409 like a stale save. The caption reset is a shared view in
common/domain_views/voice_captions.py, routed only by cardiology for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@homarone00 homarone00 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@homarone00
homarone00 merged commit c31eefb into AImageLab-zip:main Oct 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants