Chapter 1 · Sessions 1–2
What the old LIMS holds, and the tables that replace it
A laboratory information management system (LIMS) records every sample from collection to an approved result and a certificate of analysis. Session 1 finds out what yours holds and costs, from its own reports and bills. Session 2 adds the fourteen lims_ tables to your Foundation platform, with the two rules that keep results honest written into the database from the start: a result is never overwritten, and every sample is judged against the specification version pinned to it.
30 minAbout 7 hours hands-on across six sessionsSessions 1–2: 5 steps14 tables
By the end of this chapter you can
- Inventory the LIMS you pay for today from its own reports and bill, and run three baseline tests on it.
- Map the module onto your Foundation spine so it keeps no second item, lot or people list.
- Have Claude Code write the fourteen tables, the result and pin rules, the tests, a fixture of hand-worked values and a made-up seed, and try them on the development project yourself.
What a LIMS does
A laboratory tests samples and reports results that other people act on: release a lot, reject a delivery, change a process. A LIMS holds the whole path. A sample is registered and labelled, received, stored, assigned to an analyst and an instrument, tested, judged against a specification, reviewed, approved, and reported on a certificate of analysis (CoA). Every step names the person and the time [1][2]. ISO/IEC 17025:2017 sets the general requirements for a laboratory's competence, including how results are recorded and reported [3]. Tools in this class include LabWare, LabVantage, STARLIMS, Thermo Fisher SampleManager, LabLynx, QBench and Labguru.
| Standard | Used in this module for |
|---|---|
| ASTM E1578-18; LIMSpec | Laboratory informatics requirements |
| ISO/IEC 17025:2017 | Competence of testing and calibration laboratories |
| 21 CFR 211.160–211.194; 21 CFR Part 11; EU Annex 11 | Laboratory controls and records; electronic records and signatures |
| FDA guidance on investigating OOS results (rev. 2022) | Phase I laboratory and Phase II full-scale investigations |
| ICH Q1A(R2); ICH Q2(R2) | Stability testing; validation of analytical procedures |
| ISPE GAMP 5 (2nd ed.) | Risk-based computerised system validation |
Samples, statuses and custody
A sample has a type (raw, in_process, finished, stability, environmental, water, retain, complaint or investigation), a priority (routine, rush or stat), a number issued by the system, and links to the item, lot, sampling point and specification. The chain of custody is the unbroken record of who held it and where: each hand-over is a row with one of seven actions, added and never changed. A chain is complete when it begins with collected, includes received and stored, runs in time order, and each from-person equals the previous to-person.
Session 1: Inventory the LIMS you pay for, from its own reports and bill
35 minutesWhy
The module must replace something real, not a guess. A number you read from the tool's own report or invoice can be checked by anyone; a number from memory is the first thing finance or an auditor knocks down, and the saving in Session 6 rests on this bill. The inventory in the repository also gives Claude Code the facts it needs in Session 2 instead of inventing them.
Do this
Gather first: one finished sample's full record with its custody and results, one specification printout with its version, the tool's turnaround or backlog report if it has one, and its account or billing page. Ask the laboratory lead before you copy anything; leave customer names and sample descriptions out of what you save.
cd ~/code/acme-platform && git switch main && git pull && claudeOn a new branch lims/inventory, create docs/lims-inventory.md for Acme Bottling, site Cleveland (cle), as a form I will fill in from the old LIMS's own reports and invoices. Do not invent any number, name or price: where I have not given one, write "not known: ask <role>".
Sections:
1. Sample types, sampling points and how samples are labelled and numbered today.
2. Methods and specifications: counts, how versions are kept, how a change is approved, and whether old results stay tied to the version they were judged by.
3. Instruments, and how calibration status and analyst training are checked before a test (and by whom).
4. Users by role (requester, analyst, reviewer, approver, manager) and how they sign in and sign.
5. Paid tools: name, owner, named users, the amount and what it covers as printed on the invoice, renewal date, notice period, which exports it gives (methods, specifications, samples, results, audit trail) and how long history stays readable after cancelling.
6. Counts, each with its report: samples a month by type, tests a month, open samples, OOS results last year.
7. The four numbers as the tool reports them (turnaround, backlog, OOS rate, right-first-time) with each definition it uses.
8. Three tests (I will run them).
9. Workarounds, in the users' own words: trending in spreadsheets, paper custody forms, certificates typed by hand.
10. The first slice: one sample type, one item and its specification, one laboratory, and why.
Then ask me for each section in turn and write my answers in. Open a pull request titled "LIMS inventory" when I say it is complete.You will see recreated screen
- Nothing is invented: a gap you can see beats a figure nobody can trace.
- Each number with the definition the tool uses: Session 6 compares like with like.
Check it worked
docs/lims-inventory.md has every section filled from a report, an invoice or a named person, and each number says where it came from.
Fastest path
Fill sections 5 to 7 from the vendor's account page and the tool's standard reports in one sitting with the right login: they are where most "not known" answers come from.
If it goes wrong
Claude Code fills in a price or a sample count I never gave it
Say: Remove every number I did not give you and write "not known: ask <role>". Every number in this file must name its source.
The tool cannot export its audit trail
Write that down as a finding: Session 5 will keep the old tool's full export as the archive, and the people who decide (quality, IT) need to know before you cancel.
Session 1: Run three tests on today's system, and choose the first slice
25 minutesWhy
The module's definition of done is three tests: a corrected result can still be retrieved with its reason and signer, a result is judged against the specification version pinned at login, and the chain of custody is complete. Running the same three on today's system gives the baseline the new way must beat, and shows the laboratory what the change is for.
Do this
Correction test. Find one result that was corrected. Can the tool show the original value, who changed it, when and why? Time it.
Pin test. Find one sample tested under an older specification version. Does the tool still judge it against that version, or against today's?
Custody test. Pick three samples from last month. Is every hand-over recorded, in order, with no gap? Count the gaps.
Add the three test results I give you below to section 8 of docs/lims-inventory.md, as facts with their source, and the first slice to section 10. Then open the pull request "LIMS inventory", wait for the checks, and tell me the result in plain words.
Correction test: <paste>
Pin test: <paste>
Custody test: <paste>
First slice and why: <paste>Have the laboratory lead and the approver read the slice in the pull request; owner two approves and it merges.
You will see recreated screen
| Test | Today | Source |
|---|---|---|
| Original of a corrected assay | Not shown; value edited | Audit report empty |
| Old sample against its version | Re-judged against today's | Sample screen |
| Custody, 3 samples | 2 gaps (paper form missing) | Custody log |
- Each a fact with a source. These are the three things the module must fix.
- The slice names people who have read it.
Check it worked
docs/lims-inventory.md is merged with the three tests, a bill and renewal date for each paid tool, and the first slice read by the laboratory lead and the approver.
If it goes wrong
Claude Code says the checks passed but the pull request shows a red check
Say: The check is red. Run gh pr checks, read the failed log, fix it and wait for green before you report. We trust the check on GitHub, never the summary.
Fourteen tables on your spine
The module keeps no item list, lot list, people table or signature store of its own. It points at the spine tables the module library calls core_item, core_lot, core_person, core_equipment, core_storage_location, core_party, core_uom, core_attachment and core_e_signature; some already exist in your Foundation under another name (your parts and lots tables). Step 3 writes that map. Every table also has the standard columns id, site_id, created_at, created_by, updated_at, updated_by, row_version, archived_at and ext: the specification's tenant_id becomes site_id, so each table keeps the one simple access rule your Foundation already uses. Types: text, int, num (decimal, never a float, which would store 99.1 as an approximation), bool, date, ts, uuid, json; req means required; a list after a colon is the allowed values.
| Table | Holds | Columns |
|---|---|---|
| lims_test_method | A versioned analytical method | code text req; version text req; name text req; technique text; sop_doc_ref uuid (soft link to document control); analytes json req; calculations json; status text req: draft, active or retired |
| lims_specification | One version of a specification for an item, stage and customer | spec_no text req; version text req; item_id → core_item req; stage text req: raw, in_process, release, stability, customer or environmental; customer_party_id → core_party; status text req: draft, approved, effective or superseded; effective_at ts; approved_signature_id → core_e_signature |
| lims_spec_limit | The limit for one analyte of a specification | specification_id → lims_specification req; test_method_id → lims_test_method req; analyte text req; lsl num; usl num; target num; uom_id → core_uom; text_spec text; reportable bool req; oot_rule json |
| lims_sampling_point | Where samples are drawn | code text req, unique; name text req; equipment_id → core_equipment; storage_location_id → core_storage_location; point_type text req: process, raw_receipt, finished, environmental, utility_water, air or surface; schedule_rrule text; active bool req |
| lims_sample | A laboratory sample | sample_no text req, unique; sample_type text req: raw, in_process, finished, stability, environmental, water, retain, complaint or investigation; item_id → core_item; lot_id → core_lot; sampling_point_id → lims_sampling_point; specification_id → lims_specification; production_order_ref uuid (soft link to MES); parent_sample_id → lims_sample; collected_at ts; collected_by → core_person; received_at ts; received_by → core_person; status text req: planned, collected, received, in_testing, in_review, approved, rejected or disposed; priority text req: routine, rush or stat; storage_location_id → core_storage_location; disposition text: pending, pass, fail or conditional |
| lims_custody_event | One step in the chain of custody | sample_id → lims_sample req; action text req: collected, transferred, received, stored, retrieved, consumed or disposed; from_person_id → core_person; to_person_id → core_person; storage_location_id → core_storage_location; at ts req |
| lims_worklist | A batch of tests for one analyst and instrument run | worklist_no text req, unique; instrument_equipment_id → core_equipment; analyst_id → core_person; status text req: open, running, complete or cancelled; created_at_run ts |
| lims_test | One method applied to one sample | sample_id → lims_sample req; test_method_id → lims_test_method req; worklist_id → lims_worklist; analyst_id → core_person; instrument_equipment_id → core_equipment; status text req: pending, assigned, in_progress, complete, reviewed, approved, cancelled or retest; started_at ts; completed_at ts |
| lims_result | One analyte's result, its flags and its approvals | test_id → lims_test req; analyte text req; value_num num; value_text text; uom_id → core_uom; source text req: manual, instrument or calculated; raw_attachment_id → core_attachment; entered_by → core_person req; entered_at ts req; in_spec bool; oos bool; oot bool; reviewed_by → core_person; reviewed_at ts; approved_by → core_person; approved_at ts; review_signature_id → core_e_signature; approval_signature_id → core_e_signature; superseded_by_id → lims_result |
| lims_oos_investigation | A phased investigation of an OOS result | investigation_no text req, unique; result_id → lims_result req; phase text req: phase_1_lab or phase_2_full; hypothesis text; assignable_cause bool; conclusion text; retest_plan text; quality_event_ref uuid (soft link to quality); status text req: open, phase_1_closed, escalated or closed |
| lims_stability_study | A stability protocol being run | study_no text req, unique; item_id → core_item req; lot_id → core_lot; protocol_doc_ref uuid (soft link to document control); conditions json req; timepoints_months json req; start_at date req; status text req: planned, active, complete or cancelled |
| lims_stability_pull | A scheduled pull point that creates a sample | study_id → lims_stability_study req; condition text req; timepoint_months num req; scheduled_at date req; sample_id → lims_sample; status text req: scheduled, pulled, tested or missed |
| lims_reagent | A reagent, standard or prepared solution | name text req; grade text; lot_no text; supplier_party_id → core_party; received_at date; opened_at date; prepared_from json; expires_at date req; storage_location_id → core_storage_location; status text req: available, quarantine, expired or consumed |
| lims_coa | A certificate of analysis for a lot | coa_no text req, unique; lot_id → core_lot req; specification_id → lims_specification req; customer_party_id → core_party; generated_at ts req; attachment_id → core_attachment; signature_id → core_e_signature |
Versions, and the pin
A method or specification is never edited once in force: a change is a new version. A specification's status only moves forward: draft, approved (signed), effective (from its date), superseded. Pinning means a sample stores the id of the specification version in force when it was logged in, and that id never changes. Every flag is computed against that version, whatever is published later.
| Analyte | SPEC-P100 version 1 (from 1 Jan 2026) | Version 2 (from 1 Jul 2026) |
|---|---|---|
| Assay (ASSAY-01) | 98.0 to 102.0 % (method version 1) | 98.5 to 101.5 % (method version 2) |
| pH (PH-01) | 6.5 to 7.5 | 6.5 to 7.5 |
Session 2: Map the module onto your spine, before any table
15 minutesWhy
The module library names spine tables your Foundation may already hold under its own names, or may not have yet. Building them blind is how a plant ends up with two item lists and two lot tables that drift apart. A written map makes Claude Code extend what exists and create only what is missing, in a separate spine migration that merges first.
Do this
Read docs/SCHEMA-PLAN.md, docs/naming-standard.md, docs/matrix.json and every file in supabase/migrations. Do not write any SQL yet.
On a new branch lims/spine, add a section "## M10 Laboratory (LIMS)" to docs/spine-map.md, the one spine map every module shares (if it does not exist yet, create it with the heading "# Spine map" first; never a separate map file for this module). Put in the section, under "### Tables", exactly the text between the lines below. Then, under "### Map": for each spine table or function the module needs (core_item, core_lot, core_person, core_job_role, core_equipment, core_storage_location, core_party, core_uom, core_attachment with a sha256 checksum, core_e_signature with signer_id, meaning, record_type, record_id, record_hash, signed_at, auth_method, printed_name and comment, core_number_sequence, core_action_item, core_event_outbox, core_audit_log with core_audit_row(), core_block_mutation(), core_touch_row(), core_current_tenant()), say "we have it as <our table>, missing columns: ..." or "missing". Never plan a second table for something we already have (our parts table may be core_item, our lots table core_lot); add missing columns instead. Module tables carry site_id in place of the specification's tenant_id, so each keeps one simple access rule. End the section with "Questions for me". Open a pull request titled "LIMS spine map".
----- tables for docs/spine-map.md -----
# The module's fourteen tables (from module library M10)
Standard columns on every table: id, site_id (in place of tenant_id), created_at, created_by, updated_at, updated_by, row_version, archived_at, ext.
Types: text, int, num (numeric, never float), bool, date, ts (timestamptz), uuid, json (jsonb). "req" = not null. A list after a colon = the only allowed values. "→" = foreign key. Soft links are uuid with no foreign key.
## lims_test_method
A versioned analytical method.
- code text req
- version text req
- name text req
- technique text
- sop_doc_ref uuid (soft link to document control)
- analytes json req
- calculations json
- status text req: draft, active or retired
## lims_specification
One version of a specification for an item, stage and customer.
- spec_no text req
- version text req
- item_id → core_item req
- stage text req: raw, in_process, release, stability, customer or environmental
- customer_party_id → core_party
- status text req: draft, approved, effective or superseded
- effective_at ts
- approved_signature_id → core_e_signature
## lims_spec_limit
The limit for one analyte of a specification.
- specification_id → lims_specification req
- test_method_id → lims_test_method req
- analyte text req
- lsl num
- usl num
- target num
- uom_id → core_uom
- text_spec text
- reportable bool req
- oot_rule json
## lims_sampling_point
Where samples are drawn.
- code text req, unique
- name text req
- equipment_id → core_equipment
- storage_location_id → core_storage_location
- point_type text req: process, raw_receipt, finished, environmental, utility_water, air or surface
- schedule_rrule text
- active bool req
## lims_sample
A laboratory sample.
- sample_no text req, unique
- sample_type text req: raw, in_process, finished, stability, environmental, water, retain, complaint or investigation
- item_id → core_item
- lot_id → core_lot
- sampling_point_id → lims_sampling_point
- specification_id → lims_specification
- production_order_ref uuid (soft link to MES)
- parent_sample_id → lims_sample
- collected_at ts
- collected_by → core_person
- received_at ts
- received_by → core_person
- status text req: planned, collected, received, in_testing, in_review, approved, rejected or disposed
- priority text req: routine, rush or stat
- storage_location_id → core_storage_location
- disposition text: pending, pass, fail or conditional
## lims_custody_event
One step in the chain of custody.
- sample_id → lims_sample req
- action text req: collected, transferred, received, stored, retrieved, consumed or disposed
- from_person_id → core_person
- to_person_id → core_person
- storage_location_id → core_storage_location
- at ts req
## lims_worklist
A batch of tests for one analyst and instrument run.
- worklist_no text req, unique
- instrument_equipment_id → core_equipment
- analyst_id → core_person
- status text req: open, running, complete or cancelled
- created_at_run ts
## lims_test
One method applied to one sample.
- sample_id → lims_sample req
- test_method_id → lims_test_method req
- worklist_id → lims_worklist
- analyst_id → core_person
- instrument_equipment_id → core_equipment
- status text req: pending, assigned, in_progress, complete, reviewed, approved, cancelled or retest
- started_at ts
- completed_at ts
## lims_result
One analyte's result, its flags and its approvals.
- test_id → lims_test req
- analyte text req
- value_num num
- value_text text
- uom_id → core_uom
- source text req: manual, instrument or calculated
- raw_attachment_id → core_attachment
- entered_by → core_person req
- entered_at ts req
- in_spec bool
- oos bool
- oot bool
- reviewed_by → core_person
- reviewed_at ts
- approved_by → core_person
- approved_at ts
- review_signature_id → core_e_signature
- approval_signature_id → core_e_signature
- superseded_by_id → lims_result
## lims_oos_investigation
A phased investigation of an OOS result.
- investigation_no text req, unique
- result_id → lims_result req
- phase text req: phase_1_lab or phase_2_full
- hypothesis text
- assignable_cause bool
- conclusion text
- retest_plan text
- quality_event_ref uuid (soft link to quality)
- status text req: open, phase_1_closed, escalated or closed
## lims_stability_study
A stability protocol being run.
- study_no text req, unique
- item_id → core_item req
- lot_id → core_lot
- protocol_doc_ref uuid (soft link to document control)
- conditions json req
- timepoints_months json req
- start_at date req
- status text req: planned, active, complete or cancelled
## lims_stability_pull
A scheduled pull point that creates a sample.
- study_id → lims_stability_study req
- condition text req
- timepoint_months num req
- scheduled_at date req
- sample_id → lims_sample
- status text req: scheduled, pulled, tested or missed
## lims_reagent
A reagent, standard or prepared solution.
- name text req
- grade text
- lot_no text
- supplier_party_id → core_party
- received_at date
- opened_at date
- prepared_from json
- expires_at date req
- storage_location_id → core_storage_location
- status text req: available, quarantine, expired or consumed
## lims_coa
A certificate of analysis for a lot.
- coa_no text req, unique
- lot_id → core_lot req
- specification_id → lims_specification req
- customer_party_id → core_party
- generated_at ts req
- attachment_id → core_attachment
- signature_id → core_e_signature
----- end -----My answers to the questions in the M10 section of docs/spine-map.md: <paste>.
Now write ONE spine migration on this branch (npx supabase migration new lims_spine) that adds only what the map says is missing, with create table if not exists for missing core_ tables. Row-level security on for every new table, no policies (they come from docs/matrix.json in Session 3). pgTAP tests that each new table exists with RLS on. Push, wait for the schema check, and tell me the result in plain words.You will see recreated screen
- Extend, do not duplicate.
- Questions about meaning are yours to answer.
Check it worked
Pull request LIMS spine map is green, the M10 section of docs/spine-map.md has no open questions, and no new table duplicates one you had.
Fastest path
The table list goes into the shared spine map in the same prompt, so Claude Code reads the columns from a file instead of from memory.
If it goes wrong
The map plans core_item as a new table although we have parts
Say: Our parts table is core_item. Add the missing columns to parts instead.
CI fails with: column does not exist, on a fresh database
A column the code uses has no migration. Say: Rebuild from nothing using only supabase/migrations, run supabase db diff, and write any missing change as a new migration, never by editing an old one. We hit this: a merged change added ten columns with no migration.
Session 2: One prompt: the fourteen tables, the honest-result rules, the tests, the worked example and the seed
30 minutesWhy
The rules that keep results honest must be in the database before any screen exists, so no screen, import or agent can skip them: a result's value never changes, a sample's specification never changes, custody is never rewritten, and nobody types a flag. The worked example is small and fixed, kept as a test fixture so Session 4 can check every flag and count against numbers you worked out by hand; the seed gives the development project the same rows shifted onto today, so the screens show recent work.
Do this
After the spine pull request has merged:
Read the M10 section of docs/spine-map.md and docs/naming-standard.md. Use our table names from the map wherever the module library says core_...
On a new branch lims/tables:
1. npx supabase migration new lims_tables. Create the fourteen lims_ tables exactly as the M10 section of docs/spine-map.md lists them, with site_id in place of tenant_id: every column, type, required flag and allowed value (check constraints). Results and limits numeric, never float. Soft links plain uuid with a comment naming the table they will point to. Every table: an index on its scope column, row-level security on with no policies, the touch trigger and the audit trigger. Numbers (sample_no, worklist_no, investigation_no, study_no, coa_no) unique and issued from core_number_sequence. Unique (code, version) on methods and (spec_no, version) on specifications.
2. Checks: lsl <= usl; a limit has at least one of lsl, usl, text_spec; a result has value_num or value_text.
3. Triggers: (a) lims_result: delete refused; update may change only reviewed_by, reviewed_at, review_signature_id, approved_by, approved_at, approval_signature_id and superseded_by_id. (b) lims_sample: item_id never changes; specification_id never changes once set; a sample that is not planned needs a specification; the specification must be of the same item, not draft or approved, and effective no later than collected_at. (c) lims_specification: status only moves forward; approved or effective needs approved_signature_id; limits change only while draft. (d) lims_custody_event and lims_coa append-only with core_block_mutation(). (e) lims_evaluate(specification_id, test_method_id, analyte, value, before) returning in_spec, oos, oot, called by a before-insert trigger on lims_result that fills the flags from the sample's PINNED specification: in spec when at least lsl and at most usl, whichever are given, otherwise OOS; OOT only when in spec, the limit's oot_rule is {"rule":"run","points":3}, and this and the two latest earlier non-superseded results of the same item and analyte, by entered_at, all rise or all fall.
4. pgTAP tests in supabase/tests/lims_schema.test.sql that the database refuses: a sample with status shipped, lsl above usl, an update of a result's value, a delete of a result, a change of a sample's specification_id, a sample with no specification, an update of a custody event.
5. The worked example, exactly as I give it in the next message, in two places: tests/fixtures/lims-worked.json with its fixed dates, which the seed test loads into the test database and checks against the counts and flags; and supabase/seeds/lims.sql, listed under [db.seed] sql_paths in supabase/config.toml, holding the same rows shifted onto today (every date moved by the same whole number of days, so the latest approval falls yesterday), marked SYNTHETIC, and safe to run twice (fixed ids, on conflict do nothing). Never appended to supabase/seed.sql, never in a migration; the deploy workflow never seeds production.
Do not connect to or change any live project. Then wait for my next message.The worked example for the LIMS module. Fixed dates in UTC, as written here, go into tests/fixtures/lims-worked.json: Session 4 checks exact numbers against them. supabase/seeds/lims.sql holds the same rows shifted onto today. Every row is made up, marked SYNTHETIC and carries ext synthetic true. No real names, customers or readings. Insert each sample at collected and walk it forward with updates in the order a person would, and results in entered_at order, so the fixture and the seed pass every rule.
Spine: units kg, %, pH; item P-100 (finished_good, kg, lot-controlled); lots L-001 to L-005 released, L-006 to L-008 quarantine; customer "SYNTHETIC · Customer A"; storage LAB-FR-01 (lab); instruments TIT-01 (titrator) and PH-01 (pH meter) at site cle; four people: a requester, an analyst, a reviewer, an approver (display names start "SYNTHETIC · "). Sequences: lims_sample SMP-2026- next 7 (4 digits); lims_worklist WL-2026- next 3; lims_oos_investigation OOS-2026- next 1; lims_coa COA-2026- next 1.
Methods: ASSAY-01 v1 (retired), ASSAY-01 v2 (active), PH-01 v1 (active).
Specifications (insert draft, add limits, then move forward with the approver's signature): SPEC-P100 v1, stage release, effective 2026-01-01, superseded; v2, effective 2026-07-01, effective. Limits: v1 assay 98.0–102.0 % by ASSAY-01 v1, pH 6.5–7.5 by PH-01 v1; v2 assay 98.5–101.5 % by ASSAY-01 v2, pH 6.5–7.5 by PH-01 v1. All reportable; both assay limits carry the run-of-three oot_rule.
Sampling points SP-FIN-01 (finished) and SP-WAT-01 (utility_water). Reagents: titrant TIT-L1 available to 2028-12-31; pH 7 buffer BUF-L2 available to 2028-12-31; older buffer BUF-L1 expired 2026-06-30.
Six samples, finished, routine, P-100, SP-FIN-01 (number, lot, collected, received, version, final status): 0001 L-001 2026-06-10 07:30, 09:00, v1, approved; 0002 L-002 2026-07-08 07:30, 09:00, v2, approved; 0003 L-003 2026-07-15 08:30, 10:00, v2, approved; 0004 L-004 2026-07-22 07:30, 09:00, v2, approved; 0005 L-005 2026-07-29 07:30, 09:00, v2, approved; 0006 L-006 2026-07-30 07:30, 09:00, v2, in_testing. The first five disposition pass.
Custody, four per sample (24): collected (to requester), received (requester to analyst), stored (LAB-FR-01, +10 min), retrieved (+40 min).
Worklists WL-2026-0001 (TIT-01) and WL-2026-0002 (PH-01), open, holding sample 0006's tests. Twelve tests: one assay and one pH per sample; the first ten approved (0001's assay by ASSAY-01 v1, other assays v2), 0006's two assigned.
Ten results, entered 13:00 (assay) and 13:30 (pH) on the day of receipt: assay 98.2, 99.0, 98.8, 99.1, 99.5; pH 7.0, 7.1, 7.2, 7.0, 7.4. Each reviewed (two hours before approval) and approved, with a signature each (20, plus 2 on the specifications = 22). Approvals: 2026-06-11 15:00, 07-09 09:00, 07-16 16:00, 07-23 21:00, 07-31 09:00.
The seed test, on the fixture and again on the shifted seed run twice, must prove: 6 samples, 24 custody events, 12 tests, 10 results (10 in spec, 0 OOS, exactly 1 OOT: the assay of 0005), 22 signatures.
Now push, open a pull request titled "LIMS tables", wait for every check, and tell me the result in plain words. If a check fails, fix it and wait again before reporting.You will see recreated screen
- Dated migration: production gets it from the deploy pipeline on merge (Session 11), never by hand.
- The honest-result rule, in the table itself.
- The counts you will hand-check, proven in CI.
Check it worked
Pull request LIMS tables is green and its summary gives the seed counts: 6 samples, 24 custody events, 12 tests, 10 results with exactly one OOT, 22 signatures.
Fastest path
Two messages sent one after the other replace a dozen exchanges: the first sets every rule, the second gives the worked example and the counts the test must prove.
If it goes wrong
The seed fails on the pin trigger
The seed inserts a sample before its specification is effective, or with a version effective after collection. Say: Insert each specification as draft, add its limits, then move it forward with its signature, before the samples that pin it. Fix the seed, not the trigger.
A later step expects a count the seed does not give
Say: List every count any later step or test expects and show the seed line that creates each. Fix the seed, not the check. Reviews of five Academy modules found this fault.
Claude Code proposes to drop a rule to get green
Say: Never edit, skip or loosen a test or a rule to make something pass. Explain why you think it is wrong and stop.
Session 2: Try it on the development project yourself, then predict the flags
20 minutesWhy
CI proves the files build a database from nothing; the development project proves they apply on top of your real, already-migrated Foundation. You run it, in your own terminal, because changing a database is kept for a person; production then gets the same migrations from the deploy pipeline on merge. Predicting the flags by hand first makes the checks honest.
Do this
In a terminal, not inside Claude Code. The password is in the password manager under Supabase: acme-platform-dev database password:
cd ~/code/acme-platform && git fetch && git switch lims/tablesnpx supabase link --project-ref tsrqponmlkjihgfedcbacat supabase/.temp/project-refIt must print tsrqponmlkjihgfedcba. If it prints abcdefghijklmnopqrst, stop: that is production. Then push the migrations and load the new seed file the first time (after that, reload the made-up rows with npm run seed:dev):
npx supabase db push --include-seedhttps://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/sql/new
The development project's SQL editor. Paste the query below and press Run.
select count(*) filter (where in_spec) as in_spec, count(*) filter (where oos) as oos,
count(*) filter (where oot) as oot, count(*) as results
from lims_result;Before you look, write docs/lims-seed.md by hand: which of the ten results are in spec, OOS or OOT and why, and what 98.2 would be against version 2. Commit it; owner two approves and the pull request merges.
You will see recreated screen
- The development project. Check every time.
- Production gets these files from the deploy pipeline when the pull request merges.
You will see recreated screen
| in_spec | oos | oot | results |
|---|---|---|---|
| 10 | 0 | 1 | 10 |
- Your hand prediction should say the same: ten in spec, the fifth assay OOT.
Check it worked
The query shows 10 in spec, 0 OOS, 1 OOT of 10 results on acme-platform-dev; docs/lims-seed.md holds your predictions; the pull request is merged and the deploy pipeline run is green on the Actions tab.
If it goes wrong
db push says: Remote migration versions not found in local migrations directory
The development project has a migration your branch does not. Do not force anything. In Claude Code: List which versions differ and which branch each came from, without changing any project.
The migration changed in review after I pushed it to the development project
Never reset the database. Say: Write the change as a new migration, never by editing one already pushed. Push it to the development project yourself, then reload the made-up rows with npm run seed:dev; the seed is safe to run twice.
A page later fails on the live site with "column does not exist"
Production did not get the migration. Open the deploy run on GitHub's Actions tab. Our live database once fell nine migrations behind main; the Session 11 pipeline and its daily check exist so that never happens silently.
Knowledge check
Version 2 of a specification becomes effective on 1 July. A sample collected on 20 June is still being tested on 3 July. Which version judges it?
Knowledge check
Where are the module's migrations first applied, and by whom?
References
- LIMSwiki: LIMSpec primary laboratory workflow (mapped to ASTM E1578-18). https://limswiki.org/index.php/LII:LIMSpec/Primary_Laboratory_Workflow
- LIMSwiki: LIMSpec sample management. https://limswiki.org/index.php/Template:LIMSpec/Sample_management
- ISO/IEC 17025:2017 General requirements for the competence of testing and calibration laboratories. https://www.iso.org/standard/66912.html
- Supabase CLI reference: supabase db push. https://supabase.com/docs/reference/cli/supabase-db-push
Chapter 2 · Session 3
Who may do what, and the screens
A result is not final until a second and a third person have looked at it. Session 3 writes who may request, test, review and approve into docs/matrix.json, generates the access rules from it, and builds the laboratory's screens: the requester's form, the analyst's bench, the review and approval queues, investigations, methods and the manager's board.
20 minSession 3: 2 steps4 roles and a reader, 1 machine account7 screens
By the end of this chapter you can
- Add the module's roles, the importer account, tables, screens and routes to docs/matrix.json and regenerate the access rules.
- Walk Sessions 4 to 6 against the matrix so no later step is refused.
- Have Claude Code build the seven screens and test them signed out, per role and at phone width.
Three different people
Review and approval are separate steps by separate people. The reviewer checks the result against the raw data and the method; the approver, usually the laboratory lead, accepts it for release. Each signs, and the database refuses the shortcuts. An electronic signature records who signed, what it meant (authored, reviewed, approved, released or rejected), the record, a hash of its text, when and how they authenticated; Part 11 expects a signed record to show the printed name, date and time, and meaning [1].
| Role | Scope | May | May not |
|---|---|---|---|
| Requester | Own samples | Register a sample (collected) and its first custody event; see own samples and their approved results and certificates | Update a sample once registered; see others' samples |
| Analyst | Site | Receive, store, assign, test, enter results, open investigations, sign (authored) | Review or approve own results; change a value |
| Reviewer | Site | Review results (first level, signed); close investigations they did not open | Review a result they entered; approve |
| Approver | Site | Approve results and samples; own methods and specifications; release certificates | Approve a result they entered or reviewed |
| Manager | Site | Read the board: samples by status and age, the four numbers | Change anything |
| Importer (machine) | Site | Insert methods, specifications, open samples and history with ext imported_from, only through import-lims.yml (Sessions 5–6) | Update, delete, sign, review or approve; write the outbox; sign in after cut-over (set NOLOGIN) |
Two facts about row-level security shape the cells [2]: an update finds rows only through the role's read rule, so a role that updates must also read the row before and after the change; and an insert that returns its row needs read too, so routes make their own ids with crypto.randomUUID(). The flag trigger reads earlier results for the trend, so the analyst must read every result.
| Key or secret | What it unlocks | Where it lives | Who holds it | Never |
|---|---|---|---|---|
| lims_importer password | Lets .github/workflows/import-lims.yml sign in as lims_importer, which may only insert methods, specifications and samples with imported_from | GitHub Actions secret LIMS_IMPORTER_PASSWORD, typed by a person; password manager; named in docs/KEYS.md | pat@acme.com | In Vercel, the repository or a chat; the account is set NOLOGIN at cut-over |
Session 3: The roles and rights into the matrix
35 minutesWhy
Access decided once in the matrix and generated everywhere cannot drift: the database, the routes and the menus all say the same thing. Walking every later step against the matrix now is what stops Session 4 failing halfway through a review, or an approval that reports success and changes nothing because the role could not read the row.
Do this
Read docs/matrix.json, the M10 section of docs/spine-map.md, scripts/gen-policies.mjs and docs/access-review.md.
On a new branch lims/access, add to docs/matrix.json, starting every cell blank and adding only what the job needs: the roles requester (own samples), analyst, reviewer, approver and the existing manager (read the board only), and the machine account importer (lims_importer: its own sign-in with a password a person sets, insert-only, never the service key), with exactly the rights in element M10 chapter 2's table, which I paste below; the seven screens /lims/request, /lims/bench, /lims/review, /lims/approve, /lims/investigations, /lims/methods, /lims/board and the routes /api/lims/register, receive, test, result, investigation, review, approve, coa and spec, each with the roles that may use it (the import is a workflow, not a route). No delete for anyone. Every role that updates a table also reads it, before and after the change; the analyst reads every result (the trend needs it).
Then write docs/access-walk.md: one line per step of Sessions 4, 5 and 6 in element M10 (I paste the list below): role, table, action, the cell that allows it. Mark and add any missing cell.
Run scripts/gen-policies.mjs (Session 8) and scripts/gen-routes.mjs, which writes lib/access/routes.ts (Session 9). Add tests: a requester sees no other requester's samples and cannot update a sample; an analyst cannot review own result; a reviewer cannot approve; the manager can change nothing; the importer cannot sign; nobody can delete from any lims_ table; and for each role that updates a table, the row really changed afterwards. Also, in the LIMS seed file only (never a migration, never a page or switch in the app), add public.dev_act_as(email text, person_code text) that links that sign-in to the made-up person, refusing any person without ext synthetic true. Push, open "LIMS access", wait for every check, report.
<paste the role table and the step list>You will see recreated screen
- Each signer may set only the columns of their own level.
- The walk catches the refusal before the session that would hit it.
Check it worked
Pull request LIMS access is green; docs/access-walk.md has a cell for every line; the refused-role and really-changed tests are in supabase/tests/access.test.sql.
If it goes wrong
An approval reports success but the result is not approved
The approver can update rows it cannot read, so the update matched nothing. Say: Check the approver's read policy covers the row before and after approval, and add a test that approves and checks the row really changed. We met this in three modules.
Claude Code proposes the service_role key for the import route
Refuse: The importer is its own sign-in with only its matrix rights. Never service_role in a route. It skips every policy.
Claude Code put dev_act_as in a migration or added an "act as" switch
Say: Remove it. It lives only in the seed, which never runs in production. A demo switch once made every visitor an administrator in production.
Session 3: The screens, built and tried by the people who will use them
40 minutesWhy
Analysts judge the module by the bench screen, gloved, at a fume hood; requesters by how fast a sample is logged. Building the screens against the seed, then testing every one signed out, per role and at phone width, catches the wrong person recorded as the author or a page that answers without sign-in before anyone relies on it.
Do this
Read node_modules/next/dist/docs/ first: this version of Next.js differs from what you know, and request checks live in proxy.ts. Then read docs/matrix.json, lib/access/routes.ts and the screens from Foundation Sessions 12 to 15.
On a new branch lims/screens, build:
- /lims/request: register a sample at a sampling point; the route takes the number from the sequence and pins the latest specification version effective at the collection time for the stage that fits the point; print a label with the number as a barcode, item, lot, point and time. The version is shown beside the sample everywhere.
- /lims/bench: receive, store, retrieve; worklists; enter a result (value, unit, source, raw-data file stored with its sha256), with the limits shown and the flags as the database set them.
- /lims/review and /lims/approve: queues with the raw data beside each result; signing asks for the password again.
- /lims/investigations, /lims/methods (versions, never edits), /lims/board (samples by status and age, the four numbers, "No data" where there is none).
The server takes the person from the signed-in session, never from the page, and sets every time from its own clock. Tests: every screen and route signed out lands on sign-in; each role sees only its screens; a result entered by the analyst records the analyst whoever the page claims; the screen-size check at 360 and 390 px. Push, open "LIMS screens", wait for every check including the preview, and report with the preview link.https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/sql/new
Run select public.dev_act_as('pat@acme.com', '<person>'); in the development project's SQL editor to act as the requester, analyst, reviewer or approver.
Sit a requester at /lims/request and an analyst at /lims/bench. Do not explain. Write down every place each one stopped, and give the list to Claude Code.
You will see recreated screen
- Made-up data says so. If a preview shows real data, stop.
- The pinned version beside the sample, on every screen.
Check it worked
Pull request LIMS screens is green; on the preview each role sees only its screens; every screen passes at 360 and 390 px; you have notes from a requester and an analyst.
If it goes wrong
Every result says it was entered by the same person
The page sent a name and the server trusted it. Say: Take the person from the signed-in session on the server and ignore what the page sends; add a test with two users.
The board shows 0 hours turnaround for a type with no approved samples
Say: Show "No data" where there is none, never 0, and add a test per widget rendered empty. A chart once graded twelve hard-coded points "In control" on 87 screens.
A page answers without sign-in
Stop. Say: Call every /lims page and /api/lims route signed out and show me each status code. A prior build had 376 of 449 route handlers with no guard.
Knowledge check
An analyst enters a result. Who may review it?
Knowledge check
An approval reports success but the result is still unapproved. The likeliest cause?
References
- eCFR: 21 CFR Part 11, Electronic Records; Electronic Signatures. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
- Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
- PostgreSQL Documentation: Row Security Policies. https://www.postgresql.org/docs/current/ddl-rowsecurity.html
Chapter 3 · Session 4
The workflow: from sample to certificate
Two new samples go through the laboratory on the preview: one shows a typing error corrected by superseding, never overwriting; the other a genuine out-of-specification result that blocks approval until its investigation is closed in two phases. Then you prove the pin and hand-count the whole dataset.
30 minSession 4: 5 steps3 flags, 2 phases0 results overwritten
By the end of this chapter you can
- Have Claude Code write the remaining rules and their tests, each shown failing first.
- Run a correction and a genuine OOS end to end, with custody, two signatures and a certificate.
- Prove the pin and match a hand count of the dataset.
Flags, corrections and OOS
When a result is inserted, the trigger fills in_spec, oos and oot from the sample's pinned specification. Nobody types them.
A wrong result is never overwritten. Part 11 expects audit trails that do not obscure previously recorded information [1], and the FDA's data integrity guidance sets the same expectation for original data [2]. A correction is a new result on the same test and analyte with a signed, non-empty reason; the old one gets superseded_by_id and stays on file. An OOS result opens an investigation: Phase I looks for an assignable cause in the laboratory, shown from the raw data; if none, Phase II escalates to the quality module [3]. While any investigation on a sample is open, nothing on it can be approved, and the person who opened it may not close it.
Session 4: The rules page, then one prompt for the remaining rules and their tests
25 minutesWhy
A rule you can read on one page is one the laboratory lead can check before anything is built, and the same page tells Claude Code exactly what to enforce. Each rule as a database trigger with a test that tries to break it means the refusal holds for every screen and import, and a later change that quietly removes it turns CI red.
Do this
On a new branch lims/workflow, write docs/lims-rules.md, one page: the pin; the flags and the run-of-three rule; the rounding rule from our SOP (I paste it below); correction by superseding; the two investigation phases; who may review, approve and close; the custody completeness check; and the certificate rules. Stop and show me the page; the laboratory lead will read it.
Our rounding rule: <paste from your SOP>When the laboratory lead has signed it off:
docs/lims-rules.md is signed off. Now, as new migrations on lims/workflow, add triggers that:
(a) refuse superseded_by_id unless the old result is not yet approved, the new result has the same test and analyte, and a signature for the new result by the person who entered it has a non-empty comment (the reason);
(b) refuse a review by the person who entered the result, an approval by the person who reviewed or entered it, a review without review_signature_id, and an approval without approval_signature_id or without a review;
(c1) refuse approval of a result, and a sample status approved or rejected, while any investigation on that sample's results is not closed; and refuse closing an investigation by the person who opened it;
(c2) refuse a sample status approved or rejected while any non-superseded result is not approved;
(d) refuse a lims_coa unless the lot's sample is approved on the same specification. A certificate is built only from approved, non-superseded results.
The signature's record_hash is SHA-256 of the test id, analyte, value, unit and entered_at.
Also a custody-check query (a sample is complete when its events begin with collected, include received and stored, run in time order, and each from_person_id equals the previous to_person_id).
Tests in supabase/tests/lims_workflow.test.sql, each in a transaction it rolls back, for every rule, each shown failing with its rule removed and passing with it back. Push, open "LIMS workflow", wait for every check and report.You will see recreated screen
- The message names the rule in the laboratory's words.
- Red first: a test that cannot fail proves nothing.
Check it worked
docs/lims-rules.md is signed off by the laboratory lead; pull request LIMS workflow is green, with each test shown failing before it passed.
Fastest path
"Show it failing with the rule removed" in the prompt saves the day you find a test that was green all along because it could never fail.
If it goes wrong
A test checks that a word appears in a file, not that the database refuses
Say: For each test, tell me what behaviour it proves. Rewrite any that only looks for a name to perform the action and check the refusal.
Claude Code goes round in circles on the same failing test
After the second identical failure: Stop. Quote the error, what you tried, whether the cause is in our code or outside it, and what you need from me.
Session 4: Register two samples, receive them, and assign the tests
15 minutesWhy
Registration is where the pin is made and the number is issued, and custody starts at the first hand-over. Trying the expired buffer and a change of specification here shows the database refusing the two mistakes that would make every later result indefensible.
Do this
On the preview of LIMS workflow, acting in turn with dev_act_as:
- As the requester on /lims/request: SP-FIN-01, P-100, lot L-007, routine. It becomes SMP-2026-0007, pinned to SPEC-P100 version 2, with a custody event collected. Print the label. Register L-008 the same way (SMP-2026-0008).
- As the analyst on /lims/bench: receive both (received, from the requester), store in LAB-FR-01, retrieve.
- Assign: try buffer lot BUF-L1 (refused: expired), then BUF-L2. Check TIT-01 and PH-01 are in calibration and you are qualified (read from M05 and M07 where installed, otherwise a manual check recorded on the test). Create WL-2026-0003 (assay, TIT-01) and WL-2026-0004 (pH, PH-01).
Read-only, on the development project as the approver: try to change SMP-2026-0007's specification_id to version 1 inside a transaction you roll back, and show the refusal. Then show both new samples with their pinned version, custody events and tests, and run the custody check over all eight samples.You will see recreated screen
- From the sequence, never counted by a person.
- Pinned now, and never changed.
You will see recreated screen
- The pin holds against any writer, not only the screen.
Check it worked
SMP-2026-0007 and -0008 exist, pinned to version 2, each with four custody events; BUF-L1 was refused; 4 worklists and 16 tests exist; the custody check lists nothing.
If it goes wrong
The register route pinned version 1 to a July sample
It looked up the wrong version. Say: Pick, for the stage that fits the sampling point, the version with the latest effective_at not later than collected_at; add a test with a sample on each side of 1 July.
The preview shows real laboratory data
Stop. Previews must use the development project (Session 11). Ask Claude Code which project the Preview variables name (names only, not values) and fix it in Vercel yourself.
Session 4: A typing error: OOS, Phase I, supersede, two signatures, a certificate
20 minutesWhy
This is the module's first definition-of-done test: the wrong value stays on file with its reason and signer, and the certificate never shows it. It also shows the honest order of events: the flag opens an investigation, the cause is shown from the raw data, a new result supersedes the old, and only then do two other people sign.
Do this
- As the analyst: attach raw-0007-assay.txt (the line "assay 99.1 %"). Enter the assay as 91.9 (the digits swapped) and the pH as 7.3. The trigger flags the assay OOS and the route opens OOS-2026-0001.
- Phase I on /lims/investigations: hypothesis "transcription error"; compare with the raw data; assignable cause yes; conclusion; status phase_1_closed. Do not retest.
- Enter the assay as 99.1 and sign it with the reason "Digits transposed on entry; raw data shows 99.1; see OOS-2026-0001". Supersede the 91.9.
- As the reviewer: close OOS-2026-0001; review both current results. As the approver: approve them, approve the sample (pass), generate the certificate for L-007.
Read-only, on the development project: return the superseded result of SMP-2026-0007 with its value, the reason, the signer's printed name and the value that replaced it; then the lines of the certificate for lot L-007.You will see recreated screen
- Nobody typed the flag, and approval of this sample is now blocked.
You will see recreated screen
- The old value, the reason and the signer: one row.
- The certificate is built only from approved, current results.
Check it worked
The query returns 91.9 with its reason, signer and the 99.1 that replaced it; the certificate has two lines and no 91.9; a self-review, done as SQL in a rolled-back transaction, is refused.
If it goes wrong
Claude Code offers to "fix" the 91.9 by updating it
Refuse: A result is never updated. Enter a new one with a signed reason and supersede the old. The trigger refuses the update anyway; the offer means CLAUDE.md should say so.
The certificate shows three lines
It included the superseded result. Say: Build certificate lines only from approved results whose superseded_by_id is empty; add a test.
Session 4: A genuine OOS: Phase II, approval blocked, the lot rejected
15 minutesWhy
A real failure must stop the lot, and retesting must not make it disappear. Seeing approval refused while the investigation is open, and the certificate refused for the rejected lot, is the proof that the laboratory's decision reaches the plant only through the rules.
Do this
- As the analyst: attach raw-0008.txt ("assay 100.2 %; pH 8.1"); enter both. The pH is OOS: OOS-2026-0002 opens.
- Phase I: raw data agrees, instrument and buffer BUF-L2 in order: no assignable cause. Escalate: phase_2_full, status escalated, and an action item for the approver (or a quality event if M08 is installed).
- As the reviewer: review both results (allowed while open). As the approver: try to approve (refused); close in Phase II with a conclusion and retest plan "none"; approve; reject the sample (fail, signed); try a certificate for L-008 (refused).
Read-only, on the development project: show OOS-2026-0002's phase, status and conclusion, SMP-2026-0008's status and disposition, and the lims. events in core_event_outbox for SMP-2026-0007 and -0008.You will see recreated screen
- The database refuses it, whatever screen or import tries.
- A rejected lot gets no certificate. The quality module acts on lims.lot.disposition.
Check it worked
OOS-2026-0002 is closed in Phase II, SMP-2026-0008 is rejected with disposition fail, and the certificate for L-008 was refused.
If it goes wrong
Someone asks to retest until it passes
The original result and every retest stay on record, and what may be retested is set by the investigation plan and the FDA guidance, not by the hope of a pass.
Session 4: Prove the pin, and match a hand count of the whole dataset
15 minutesWhy
The second definition-of-done test is that a flag follows the pinned version, not today's. The hand count is the defence against a seed and a set of steps that disagree: if the queries and your paper count differ, one of them is wrong, and it is never the count you did by hand from the steps.
Do this
On paper first: samples 8 (5 approved, 1 in_testing, 1 disposed after the certificate, 1 rejected); results 15 (1 superseded, 2 OOS, 1 OOT, 13 in spec); investigations 2, closed; certificates 1 with 2 lines; worklists 4, tests 16.
Read-only, on the development project: run lims_evaluate for the assay of SMP-2026-0001 (98.2) against SPEC-P100 version 2 with the current time as before, and show the stored flags of that result. Then count, by query: samples by status, results (superseded, OOS, OOT, in spec), investigations by status, certificates and their lines, worklists, tests, custody events and signatures. Write both into docs/lims-rules.md on the branch, then wait for the checks and tell me when the pull request is ready for review.Owner two approves and the workflow pull request merges; the pipeline applies it to production.
You will see recreated screen
- One value, two verdicts: the stored one follows the pin.
- If any count differs, fix the query or the step, not your count.
Check it worked
docs/lims-rules.md holds both lines of the pin proof and the counts, matching your paper count; the workflow pull request is merged with every check green.
If it goes wrong
The counts are one sample short
The aliquot practice was not rolled back, or a step was skipped. Find which, and fix the step, not the count.
Knowledge check
An analyst typed 91.9; the raw data says 99.1. What is the right correction?
Knowledge check
A result is in spec but the third of three rising values under a run-of-three rule. Its flags?
References
- eCFR: 21 CFR Part 11, Electronic Records; Electronic Signatures. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
- FDA: Data Integrity and Compliance With Drug CGMP, Questions and Answers. https://www.fda.gov/regulatory-information/search-fda-guidance-documents/data-integrity-and-compliance-drug-cgmp-questions-and-answers
- FDA: Investigating Out-of-Specification (OOS) Test Results for Pharmaceutical Production. https://www.fda.gov/regulatory-information/search-fda-guidance-documents/investigating-out-specification-test-results-pharmaceutical-production
Chapter 4 · Sessions 5–6
Move the records, prove it, switch the old LIMS off
Methods, specifications and open samples come across; closed history stays in the old tool's export as the archive. You prove the specifications moved correctly by re-evaluating real historical results against them, rehearse on the development project with a copy IT approved, import into production through a workflow a person starts from main with an export owner two approved, run side by side for a week, cut over and cancel with the saving from invoices.
25 minSessions 5–6: 4 stepsRe-evaluate historyEnds with the module gate
By the end of this chapter you can
- Map an export, load every specification version with the approver's line-by-line check, and dry-run the import.
- Rehearse on the development project, re-evaluating history against the migrated specifications.
- Import into production through import-lims.yml with an approved export, compare the four numbers side by side, cut over and cancel.
| Number | Definition (write it before comparing) |
|---|---|
| Turnaround time | Median hours from received_at to approval, by sample type |
| Backlog | Samples received and not yet approved, by age |
| OOS rate | OOS results ÷ reportable results |
| Right-first-time | Results approved without retest or correction ÷ results entered (a superseded result and its correction both count as corrections) |
The module library's plan is: export methods, specifications and historical results; load them; and validate by re-evaluating a sample of history against the migrated specifications. Validation should be risk-based: ISPE GAMP 5 (second edition) is the guide the library names [1], and EU Annex 11 sets expectations for computerised systems in regulated settings [2].
Session 5: Read the export, map it, and dry-run the import
35 minutesWhy
A specification that moves with one limit wrong silently changes every verdict after cut-over. Mapping every value to an allowed one (never by guess), loading each version as draft and having the approver compare it line by line with the old printout before signing, and a dry run that writes nothing, catch that before any result depends on it.
Do this
Take the export yourself from the old tool's own export page; keep it in a private company folder, never in the repository. It may carry customer names and sample descriptions.
I will describe the old LIMS export's files and column headers below (no data). On a new branch lims/import:
1. Write docs/lims-migration-plan.md: counts per file (I will fill them in), what the export lacks (audit trail, signatures, custody), and the mapping of old sample types, statuses, stages and units to our allowed values, items to our items, lots to our lots (a missing lot is reported, never created), people and instruments to ours.
2. scripts/import-lims.mjs with --dry-run: reads the files from a path I give, applies the mapping, writes nothing, and reports per file rows read, rows it would import and every value it cannot match. Never maps by guess.
3. .github/workflows/import-lims.yml, run only by hand (workflow_dispatch) from main, refusing any other branch, with inputs target (dev or production) and dry_run (default true). It downloads the export from the private Storage bucket imports of the target project; refuses it unless every file's sha256 and expected counts are listed in docs/imports/lims-approved.md on main; signs in as lims_importer with the password in that target's Actions secret (never the service key); runs the same code as the script in one transaction; and fails, keeping nothing, on any count that differs from the approved file. Counts go to the job summary. No GitHub environment with required reviewers: the reviewed pull request that merges the approved file is the approval. A migration creates lims_importer as a database role with NOLOGIN, insert-only on the tables it loads (no update, no delete); a person turns its login on with a password they set. It loads: methods (each version a row: in use active, older retired); specifications loaded as draft with their limits, left for the approver to compare and sign; open samples with the old vial number, pinned to the version in force at their collected_at, with custody, tests and results so far (flags computed by the trigger). Every row has ext imported_from with the old tool's name and id and a batch id.
4. Three checks into docs/lims-migration-check.md, each must return no rows: an item and stage with samples but no effective specification, or two; a specification approved or effective without limits or signature; a limit of an approved or effective specification whose method is retired.
5. Tests on a made-up export (marked synthetic) with one bad row of each kind, and the count rule: read = imported + skipped, per file; a file whose sha256 is not in the approved file is refused; a count mismatch fails and keeps nothing; lims_importer cannot update or delete.
Push, open "LIMS import", wait for every check and report.
<paste the file names and column headers, no data>node scripts/import-lims.mjs --dry-run --from ~/private/lims-exportYou will see recreated screen
- Fix the mapping, never guess in the import.
- Every open sample has the version that was in force when it was collected.
Check it worked
The dry run maps every value or explains each skip; read = would-import + skipped per file; the three check queries are written; the pull request is green and merged.
If it goes wrong
Claude Code asks to read the export to check the format
Give it the column headers and made-up rows of the same shape, never the real file.
The old tool's stage names do not fit ours
Map each one deliberately in docs/lims-migration-plan.md and have the approver agree; never let the script guess.
Session 5: Rehearse on the development project and re-evaluate history
40 minutesWhy
Matching row counts proves nothing about limits. Re-evaluating real historical results with lims_evaluate against the migrated specifications, and comparing with the old tool's own verdicts, proves the specifications behave as the old ones did. Doing it first on the development project, with a copy IT approved in writing and removed the same day, rehearses the very workflow production will use, away from production.
Do this
Get IT's written approval to load a copy of the export into acme-platform-dev for one rehearsal, redacted where it holds personal data (people's names in sample descriptions, customer contacts). In the development project's SQL editor, turn on lims_importer's login with a password you make (alter role lims_importer login password '…'); keep it in the password manager, type it into the Actions secret LIMS_IMPORTER_PASSWORD_DEV and name it in docs/KEYS.md. Create a private Storage bucket imports in the development project and upload the redacted copy.
https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/storage/buckets
Development project Storage: a private bucket named imports; upload the redacted copy.
shasum -a 256 *.csvOn a new branch lims/import-approval, write docs/imports/lims-approved.md with a section "Rehearsal (development project only)": each file's name, sha256 and expected row count (I paste them below), the date the copy was taken, what was redacted, and IT's written approval (date and role). Open a pull request titled "LIMS: approve rehearsal export".
<paste the shasum lines and row counts>Owner two reviews and approves; merge. Run the workflow with target dev, dry run first, then for real. As the approver on the preview, compare each specification version in force with the old printout line by line, then sign it to approved and effective with its old date.
https://github.com/acme-ops/acme-platform/actions/workflows/import-lims.yml
Run workflow from main: target dev, dry_run true; read the counts; then dry_run false.
Read-only, on the development project: counts with ext imported_from per table beside docs/imports/lims-approved.md; the three checks in docs/lims-migration-check.md; then re-evaluate 50 historical results from the export (I give their values, analytes, items and collection dates below) with lims_evaluate against the specification version in force at each collection date, and compare with the old tool's verdict. List every difference with its likely cause. Results: <paste>Then remove the copy from the development project the same day (ask Claude Code for a statement that deletes only rows with ext imported_from, which you run yourself in the SQL editor), delete the file from the bucket, and write the date of removal in docs/imports/lims-approved.md.
You will see recreated screen
| File | Read | Imported | Skipped |
|---|---|---|---|
| methods.csv | 41 | 41 | 0 |
| specs.csv | 63 | 63 | 0 |
| samples.csv | 28 | 28 | 0 |
- Only an export owner two approved can be loaded, and only from main.
You will see recreated screen
- Every number traced to the approved file.
- Exactly what this step is for: a limit that moved wrongly, found before any result depends on it.
Check it worked
The rehearsal ran through import-lims.yml with the approved copy; every specification in force is signed after a line-by-line check; the three checks return nothing; the re-evaluated history agrees with the old tool or every difference is explained and fixed; the copy was removed from the development project the same day, with the date recorded.
If it goes wrong
The workflow refuses: sha256 not approved
The file changed since you recorded it (often opened and saved in a spreadsheet, which rewrites it). Upload the approved file again, or record the new fingerprint through a pull request owner two approves.
A re-evaluated result disagrees with the old tool
Do not change the result. Find the cause: a limit, a unit, a version date, a rounding rule. Fix the specification (a new draft if it was already signed) and re-evaluate.
An open sample has no specification in force at its collection date
Report it and decide with the approver; never pin a later version to make it fit.
Session 6: Import into production through the workflow, and prove the counts
25 minutesWhy
Production gets the records the way the rehearsal proved: a person starts import-lims.yml from main, it reads an export whose fingerprint and counts owner two approved in a reviewed pull request, and it signs in as an insert-only account. Nobody runs SQL against the live database, no upload page exists in the app, and a count that differs stops the import with nothing kept.
Do this
Take the final export yourself from the old tool. Upload it to a private Storage bucket imports in production. Turn on lims_importer's login in production with a new password you make, keep it in the password manager, type it into the Actions secret LIMS_IMPORTER_PASSWORD and name it in docs/KEYS.md.
https://supabase.com/dashboard/project/abcdefghijklmnopqrst/storage/buckets
Production Storage: a private bucket named imports; upload the final export.
On a new branch lims/import-production, add a section "Production" to docs/imports/lims-approved.md: each file's name, sha256 and expected counts (read, to import, skipped, from the dry run I paste below), and the date taken. Open a pull request titled "LIMS: approve production export".
<paste the shasum lines and the dry run's counts>Owner two reviews and approves; merge. Run the workflow from main with target production, dry run first, then for real. The approver signs each specification in force after the same line-by-line check.
https://github.com/acme-ops/acme-platform/actions/workflows/import-lims.yml
Run workflow from main: target production, dry_run true; check the counts equal the approved file; then dry_run false.
Read-only, through the app as the approver on production: counts per table against docs/imports/lims-approved.md and the three checks; write the results into docs/cutover.md on a new branch lims/cutover. Do not change any data.You will see recreated screen
| File | Read | Imported | Skipped |
|---|---|---|---|
| methods.csv | 41 | 41 | 0 |
| specs.csv | 63 | 63 | 0 |
| samples.csv | 31 | 31 | 0 |
- Same fingerprints and counts as the approved file, or the run stops.
- Read = imported + skipped, file by file.
Check it worked
The production run's summary matches docs/imports/lims-approved.md for every file; docs/cutover.md shows read = imported + skipped, the three checks returning nothing and every specification in force signed.
If it goes wrong
The run fails: counts differ from the approved file
Nothing was kept: the import runs in one transaction. Find why (a re-export, a filter in the old tool), and approve the right file through a new pull request. Never edit the counts to fit.
Someone suggests a GitHub environment with required reviewers
Not available on the Team plan for private repositories. The reviewed pull request that merges docs/imports/lims-approved.md is the approval.
Production reports a table or column missing
The pipeline did not apply a migration. Open the deploy run on GitHub's Actions tab; do not apply anything by hand.
Someone suggests running the import SQL straight against production
No. Records come only through import-lims.yml so every row has its imported_from mark, its audit entry and the importer's identity.
Session 6: A week side by side, then cut over and cancel with the saving from invoices
60 minutes, after a weekWhy
A week of the same samples through both systems, with the four numbers on the same definitions, is the evidence that the new way records what the old way did. Cancelling only after the cut-over works and the full export is stored, with the saving from real invoices, makes the figure one finance can sign.
Do this
For one week the same samples go through both systems; the old one stays the official record and the same people enter both. Then:
On branch lims/cutover, add to docs/cutover.md from numbers I give and read-only queries as the approver on production:
1. The four numbers for the week, old tool (with the report each came from) against platform, on the definitions in element M10 chapter 4; explain every difference.
2. Three samples of the week compared result by result: values, flags, specification version, reviewer and approver.
3. The three kept rules as queries with results: a superseded result is retrievable with reason and signer; for every result the stored flags equal lims_evaluate against the pinned version with its entered_at; custody complete for every sample of the week.
4. The cut-over date and rollback plan: who tells the laboratory and requesters, samples in flight on the day, when the old LIMS becomes read-only, where the export and its checksum are kept, the date after which a result entered only in the old tool is not accepted.
5. The saving: the old cost from the invoice I paste minus what the module costs on services we already pay for, arithmetic shown.
6. A migration that sets lims_importer NOLOGIN at cut-over; I will delete the LIMS_IMPORTER_PASSWORD secrets and note the date in docs/KEYS.md.
Mark each capability in docs/lims-inventory.md replaced, kept elsewhere or out of scope, with the date. Open "LIMS cut-over", wait for checks, report.
<paste the week's numbers and the invoice lines>On the cut-over date, make the old LIMS read-only and put the request and bench screens where people looked for the old ones. Cancel on the vendor's own account page within its notice period, after the full export and its checksum are stored in the company's storage.
You will see recreated screen
| Number | Old tool | Platform | Why different |
|---|---|---|---|
| Median turnaround | 26 h | 30 h | Old counts working hours |
| Backlog | 4 | 4 | |
| OOS rate | 1 of 52 | 1 of 52 | |
| Right-first-time | not reported | 50 of 52 | Old tool cannot tell |
- Every difference has a cause written beside it.
- From invoices, never estimates.
Check it worked
docs/cutover.md is merged with the four numbers explained, three samples compared, the three kept rules, the cut-over date and rollback plan, lims_importer set NOLOGIN, and the cancellation (or end date) with the saving from invoices.
If it goes wrong
A difference cannot be explained
You are not ready. Keep both running, find the cause (a definition, a start time, a sample entered in one system only) and run another week if needed.
Your laboratory is accredited to ISO/IEC 17025
Keep this document, the Session 5 re-evaluation and the tests as the evidence that the system was checked before use, and ask your quality manager what your accreditation body expects.
Knowledge check
How is the migration of specifications validated?
Knowledge check
Five approved samples took 30, 24, 30, 36 and 48 hours. The median turnaround?
References
- ISPE: GAMP 5 Guide, 2nd Edition. https://ispe.org/publications/guidance-documents/gamp-5-guide-2nd-edition
- European Commission: EudraLex Volume 4, EU GMP guidelines (includes Annex 11, computerised systems). https://health.ec.europa.eu/medicinal-products/eudralex/eudralex-volume-4_en
- GitHub Docs: Manually running a workflow. https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow
Chapter 5 · 12 questions · 80% passes
Final assessment
Twelve questions across the element. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.
15 min12 questions≈ 15 minutesRetake allowed
Your result
CivOps AI Academy
Laboratory (LIMS): Samples, Specifications, Results, OOS and Certificates of Analysis
Element M10 complete · Learner
Your LMS records this completion. For the CivOps Foundation certificate, finish the Foundation Course at https://civops.io/learn.