Skip to content

Reagent lots record their opening, in-use period, storage and certificate files - #93

Merged
gabalint merged 3 commits into
developfrom
feat/reagent-in-use
Dec 2, 2026
Merged

gabalint merged 3 commits into
developfrom
feat/reagent-in-use

Conversation

@gabalint

@gabalint gabalint commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

First increment of the roadmap area Reagent and standard lots in use (requirement OQ-011): opening and in-use periods.

  • A reagent or reference standard lot names its supplier from the supplier register. Every new lot states its storage condition. Where the laboratory sets one, a lot has an in-use period after opening.
  • Record opening (analyst, quality) records the day a lot was opened, once. The lot's last day of use is a database-generated column: the earlier of the expiry date and the opening day + period − 1.
    • A lot with an in-use period is refused at every entry point until its opening is recorded. This covers result and batch QC entry, imports, readings, plates, resource use and preparing a solution.
    • An opening dated in the future, before receipt, or after the lot's first use or preparation is refused.
  • Record used up (analyst, reviewer, quality) is for a released lot only. It needs a reason and is irreversible. The lot takes no further use and nothing is prepared from it; it can still be rejected.
  • Attach certificate (analyst, quality) keeps the supplier's certificate as a file, unchanged with its SHA-256 checksum:
    • at most 10 per lot, with the same size limit and storage ceiling as other uploaded files;
    • append-only by trigger;
    • each file advances the lot's revision, so a release signed over fewer files is stale;
    • the download re-verifies the checksum.
  • One status per lot: awaiting release, released (expiring soon), expired, used up or rejected. Expired follows from the last day of use.
    • The Reagents list column becomes Last day of use (grid version 2) and gains the filter Used up.
    • The overview counts, reminders, bench labels ("Opening not recorded") and the method register follow the last day of use and leave out used-up lots.
  • Independent release: whoever recorded the lot, recorded its opening or attached one of its certificate files does not release it, whatever roles they hold.
  • Prepared solutions have no supplier and no in-use period. They cannot be dated before their source lot was received or opened, and cannot outlive its last day of use.

Product choices (no source read sets an in-use period, a used-up status or these refusals) are recorded in docs/product.md and in the regulatory matrix note of 2026-12-01.

Migration and upgrade

  • One migration, laboratory.0008_reagent_in_use. In a single transaction it:
    • adds the columns, the generated column last_use_on, check constraints and ReagentCertificate;
    • replaces the lot guard of 0002, so the opening and the used-up record are written once, every change advances the revision, and the generated column is never compared;
    • makes certificate files append-only.
  • storage_condition has a database default, so the previous release can still insert lots while the deployment migrates. This was checked with an insert using the old column list.
  • The upgrade note is in docs/operations.md.
  • Rehearsed on a local copy: forward, back (the old guard accepts a lot update again), then forward.

Documentation

  • Page docs: three new (open, used up, certificate) and nine updated.
  • docs/product.md (status tables and a new paragraph), architecture, operations, regulations note, README.
  • Roadmap: the first increment is moved into the card's "Already built"; the tooltip and the introduction are updated.
  • Changelog entry, and traceability for OQ-011.

Verification

  • ruff check, ruff format --check, Django check, makemigrations --check --dry-run (PostgreSQL), collectstatic, changelog --check.
  • New tests:
    • laboratory/tests/test_reagent_in_use.py (19): arithmetic and boundaries, eligibility, role and stale refusals, audit, used up, status/filter agreement, reminders, bench, certificate files, database guards, release independence, preparation dates, used up racing a use;
    • laboratory/tests/test_reagent_in_use_views.py (8);
    • e2e/test_reagent_in_use_journey.py.
  • Full PostgreSQL suite and the affected browser journeys: results in the comment below.
  • An independent review found 1 High, 2 Medium and 4 Low issues, all fixed in the second commit: release independence; the migration window and reversal; preparation dates; the lineage check at a past time; the history query; test gaps.

🤖 Generated with Claude Code

Gabriel Balint and others added 3 commits December 1, 2026 22:11
…torage and certificate files

A reagent or reference standard lot names its supplier from the register and
every new lot states its storage condition. Where an in-use period is set the
lot is used only once its opening is recorded; its last day of use (a stored
generated column) is the earlier of the expiry date and the period's last day.
A released lot can be recorded used up, irreversibly. Certificate files are
kept unchanged with their checksum. Lists, reminders, the overview, the bench
and the method register follow the last day of use.

Migrations laboratory 0008 (columns, constraints, ReagentCertificate) and 0009
(guard trigger replaced: opening and used-up written once, revision advances;
certificate files append-only).

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

- The person who recorded a lot's opening or attached one of its certificate
  files does not release it, whatever roles they hold.
- The guard replacement moves into 0008, in the transaction that adds the
  generated column, so no moment or reversal leaves the 0002 guard comparing
  it; storage_condition has a database default so the previous release can
  still insert lots while a deployment migrates (operations upgrade note).
- A solution is not dated before its source lot was received or opened; the
  lineage check at a past time uses the source's opening as of that day.
- Laboratory history names accounts (one query per page).
- Tests: release independence, preparation dates, opening after a
  preparation, used up racing a use, download integrity failure, history.

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

gabalint commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Local verification on 9cae60c (the changelog commit ccb4ea4 changes only changelog.d/ and CHANGELOG.md):

  • Static: ruff check, ruff format --check, Django check, makemigrations --check --dry-run (PostgreSQL), collectstatic, changelog --check: all pass.
  • Full PostgreSQL suite (pytest -n auto): 3733 passed, 3 skipped, 1 failed. The failure, stability/tests/test_testing.py::test_two_analysts_assigning_one_pull_at_once_create_each_test_once, happened while the browser journeys ran on the same machine. The test gives a second thread 0.5 s to reach its lock. It passed 3 of 3 alone, and this change does not touch stability.
  • Browser journeys: test_reagent_in_use_journey, test_calculation_bench_journey, test_method_resources_journey, test_planning_journey, test_plate_count_journey and test_pagedocs: 6 passed.
  • Migration rehearsed on a local copy: forward, then back to 0007 (the 0002 guard accepts a lot update again), then forward. An insert with the previous release's column list succeeds after the migration.
  • Deployment smoke script rehearsed locally, 7/7. It covers a lot recorded with supplier, storage and in-use period, a certificate attached and downloaded unchanged, a signed release, the opening and last day of use, recording used up, and the page help.

@gabalint
gabalint merged commit d59ff84 into develop Dec 2, 2026
5 checks passed
@gabalint
gabalint deleted the feat/reagent-in-use branch December 2, 2026 03:58
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.

1 participant