MediLabel v19 - AUTO-DETECT EDITION
====================================

THREE UPGRADES IN THIS VERSION
------------------------------

1. PRINTER AUTO-DETECTION (new)
   Settings -> Printer COM port now defaults to "Auto".
   - MediLabel scans every serial port and ranks them by how likely
     they are to be the NIIMBOT B1 (recognises the CH340/FTDI/CP210x
     USB chips NIIMBOT uses, and any port that names itself NIIMBOT).
   - When you print, it tries the best candidates in order until one
     succeeds, then REMEMBERS the winning port - so from the second
     print onward "Auto" is instant.
   - Plug the printer into a different USB socket and it just works.
   - You can still pick a fixed COM port manually; that is obeyed
     exactly as before. Settings shows "<- likely NIIMBOT" next to
     the best guess.

2. LONG NAMES NO LONGER CUT OFF (carried in from the v18 fix)
   e.g. "VAHID RAFIEI KARKAVANDI" used to print as "VAHID RAFIEI KA".
   The font now auto-shrinks until the name fits; if it would become
   too small to read, the name wraps onto two lines instead.
   Verified by automated test with 5 long names incl. hyphenated ones.

3. BP REGISTRY PATIENT CAPTURE (new - the big one)
   Best Practice writes the currently open patient's name to a local
   registry value the instant a record is opened, and CLEARS it when
   the record is closed. MediLabel now reads this at hotkey time:
   - More reliable than window-title parsing (works on every BP
     screen, not just ones that show the patient in the title).
   - SAFER: if you close the patient record and press the hotkey,
     the popup opens BLANK instead of showing the last patient -
     the registry's cleared value tells us no patient is open.
   - Name comes from the registry; DOB is still read from the screen
     as before (registry has no DOB). Confirmation popup unchanged -
     you always see and approve what prints.
   - On PCs where BP doesn't expose this value, MediLabel silently
     falls back to title parsing (exactly v18 behaviour).
   - The capability strip at the bottom of the main window now shows
     "BPreg [OK]" when the mechanism is present on that PC.

NOT TESTED ON REAL HARDWARE YET - see OFFICE_TEST_CHECKLIST.txt
for tomorrow's test plan.

v19.1 HOTFIXES (14 Aug 2026 - after first office test)
------------------------------------------------------
1. LONG NAMES REALLY FIXED THIS TIME.
   Root cause found: the NIIMBOT B1 print head is only 48 mm (384
   dots) wide, but we were rendering a full 50 mm image - the last
   ~2 mm of every label was physically unprintable, so the printer
   itself cut the text ("VAHID RAFIEI KARKV..."). The label is now
   rendered no wider than the print head, with a wider safety margin,
   and long names wrap to two lines. Verified with real-font
   rendering tests + visual proof.
2. BOTTOM MENU ALWAYS VISIBLE.
   The Test Print / Settings / Audit Log / License / Help bar
   disappeared at smaller window sizes (Tkinter clips last-packed
   widgets first). The bar is now packed before the form, and the
   window has a sensible minimum size - the menu stays visible at
   any window size.

v19.2 (15 Aug 2026)
-------------------
1. NAME + SURNAME ON TWO LINES BY DEFAULT.
   Long names now split naturally - given name(s) on line 1, SURNAME
   on line 2 ("VAHID RAFIEI" / "KARKAVANDI") - both lines stay BIG.
   One line is only used when it fits at 32pt or larger.
2. VERSION PRINTED ON EVERY LABEL + IN THE TITLE BAR.
   Labels now end with "Printed: <date>  v19.2" and the window title
   says "MediLabel v19.2". If a label has no version marker, it came
   from an OLD copy of the app still on the PC - close/remove it.
3. last_label.png - the app saves an exact image of every label it
   sends to the printer (kit folder). If paper ever differs from
   this file, the problem is hardware/driver, not the app.

v19.3 (15 Aug 2026 - after second office test)
----------------------------------------------
1. DATE STAMP CAN NEVER DISAPPEAR AGAIN.
   Adding a clinic name used to push the printed date off the label
   (it was drawn LAST, at the bottom). Photo forensics of the office
   test labels showed the B1 only reliably prints the TOP HALF of
   the label when its gap calibration drifts (the red-light state).
   The date/time/version stamp is now anchored TOP-RIGHT on the very
   first row - nothing can ever push it off. Clinic name sits
   top-left, and time was added per RCPA labelling guidance (date
   AND time on specimen labels).
2. WHOLE LABEL PACKS INTO THE TOP (SAFE) HALF.
   Clinic, name (up to 2 big lines), DOB and up to 2 lines of notes
   are all laid out compactly in the top ~15 mm. Notes shrink to one
   line with "..." if space runs out - the important fields never do.
   Verified by an automated safety check across 5 worst-case labels.
3. BLANK FIRST PRINT OF THE DAY - WAKE-UP FIX.
   The printer sometimes ate the first label after sitting idle
   (waking + re-calibrating on it). The app now sends a wake-up
   query to the printer before the first print of a session, and
   again whenever more than 30 minutes have passed since the last
   print, then pauses briefly so the printer is ready before the
   label data arrives.
   ALSO RECOMMENDED (hardware side): when the light goes red, run
   the B1's label calibration - hold the print button (or use the
   NIIMBOT phone app: Settings > Label Calibration) so it re-learns
   the label gaps. That is what the red light is asking for.
