Files
zyt/artifacts/patient-render-image-fix/image-fix-report.md
T
2026-09-09 12:18:17 +08:00

41 lines
3.4 KiB
Markdown

# Doctor-notes image preview fix
## Confirmed cause
The actual editable and readonly diagnosis note thumbnail click chain was:
`NotesTimeline._RemoteImageButton.clicked``open_attachment_requested(url)``DiagnosisDialog._open_safe_resource(url)``QDesktopServices.openUrl(url)`.
The existing `ImagePreviewDialog` was not connected to this path. A regression using `QTest.mouseClick` on the real eight-image doctor-notes timeline failed before the implementation change because the system opener received `https://media.example.invalid/tongue-0.jpg`. This confirms an external-open bug. This reproduction did not establish an application crash or drawer reparenting bug.
## Changes
- Notes thumbnails now emit a dedicated image-group signal containing the note's image URLs and clicked index. Report-file attachment routing and deletion remain on their existing signals.
- Both editable and readonly diagnosis note timelines connect that signal to a retained, diagnosis-owned `ImagePreviewDialog`. It opens inside the application and supports previous/next image, fit/original-size zoom, and close. Only its explicit `安全外部打开` button launches the system opener.
- Closing the diagnosis closes its image preview. Closing the preview clears the retained reference without rejecting or reparenting the diagnosis.
- The preview now cancels outstanding image requests in `done()` as well as `closeEvent()`, covering Escape/reject, which bypasses Qt's close event. Late responses cannot update the closed preview.
Changed application files:
- `app/src/doctor_workstation/ui/diagnosis_drawer.py`
- `app/src/doctor_workstation/ui/dialogs/diagnosis.py`
- `app/src/doctor_workstation/ui/diagnosis_media.py`
## Validation
All tests used synthetic local image bytes and fake HTTP transport; no patient-image requests were made.
- `.venv/Scripts/python.exe -m pytest tests/test_diagnosis_notes_image_preview.py -x -p no:cacheprovider`**4 passed**, latest run 1.73 seconds. Actual clicks on first, eighth, and later thumbnails in both editable/readonly modes; selected image and eight-image group; decoded full-size preview; zoom; previous/next and wrap; close/reopen; Escape; diagnosis visibility/parent/generation retention; explicit external-open action; parent cleanup; pending-response cancellation with close button and Escape.
- `.venv/Scripts/python.exe -m pytest tests/test_diagnosis_media_thumbnail_visual.py -p no:cacheprovider`**9 passed**, 0.36 seconds. Existing thumbnail decode, stale-generation, URL/redirect/oversize safety, preview paging/cache, failures, deletion, chat and daily-toolbar checks. The tongue-click assertion now verifies the image-group signal rather than the external-attachment signal.
- Ruff checks on all five edited Python files — **passed**.
New regression: `app/tests/test_diagnosis_notes_image_preview.py`.
Updated regression: `app/tests/test_diagnosis_media_thumbnail_visual.py`.
## Reviewed screenshots
- `notes-eight-thumbnails.png`: editable doctor-notes tab with eight synthetic thumbnails and individual delete controls.
- `notes-image-preview.png`: image 8/8 displayed in the application's preview, with navigation, original-size zoom, reload, explicit external action, and close controls.
Screenshots were visually inspected after registering the bundled CJK font and settling the Qt layout. Images are clearly labelled synthetic test imagery. No build or installation was performed by this worker; packaging belongs to the parent task.