← Back to Pull requests

EMS Management: supply inventory foundation (E1) #97

Open
unknown opened this pull request with 471 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 19, 2026 22:38 UTC
Author

What

The first slice (E1) of EMS Management: a new EMS Supply Inventory page under a new EMS sidebar group, with its module, permissions, rules, server logic and tests.

  • Catalog: items with category, unit, cost, barcode, vendor, and whether a lot number or expiration date is required.

  • Locations: station → storage area → cabinet → shelf → bin, plus vehicles (can link to a Fleet vehicle). Nesting loops are refused, and a location still holding stock can't be turned off.

  • Par levels per item per location, which drive the low-stock and out-of-stock flags.

  • Stock movements: receive, use (with incident number), transfer/restock, remove expired, remove damaged, waste, return to vendor.

  • - Lots are picked first-expiring-first (FEFO) by default, or first-in-first-out (FIFO) as a department setting.
    - Expired stock is never used, and stock never goes below zero.
  • Physical counts: every difference needs a reason. Someone other than the counter has to approve.

  • Reversals of a posted transaction, by an approver. Each transaction can be reversed once.

  • History, the ledger of stock movements, and an Audit tab.
  • How

  • Browsers only read. All writes go through 11 emsInventory* callables in functions/lib/emsInventory/. In firestore.rules every new collection has allow write: if false.

  • Each movement is one Firestore transaction covering the ledger record, the affected balances and the audit event.

  • The client sends a request id per action. The ledger doc id T-{requestId} is created with create(), so a retry or double tap returns the first result instead of moving stock twice.

  • There is a new module key, emsManagement, plus six permissions:

  • - viewEmsInventory
    - useEmsSupplies
    - manageEmsInventory
    - approveEmsInventoryAdjustments
    - manageEmsSettings
    - viewEmsAudit

    Built-in role defaults are set in defaultRoles.js and the server JSON, which the existing tests keep in sync. The permission table is in docs/ems/IMPLEMENTATION_REPORT.md.

  • Two new indexes on emsInventoryTransactions support the History filters.

  • docs/ems/REPOSITORY_DISCOVERY.md covers:

  • - how the full EMS spec maps onto this codebase
    - the E1–E9 slice plan
    - security findings in existing code, not changed here: auditLogs is writable by members, and the storage read rule is broad.

    Testing

  • New tests:

  • - 18 unit tests on the stock rules.
    - 18 function tests against the emulator, including:
    - retry and double-submit deduct only once
    - two people taking the last unit (one wins, nothing goes negative)
    - permissions per role, and other departments refused
    - counts and reversals
    - 5 rules tests.
  • Full suite: lint, build, unit 793/793, rules 173/173, functions 221/221. The last two fixes were CSS only and weren't covered by a test rerun, but lint and build passed after them.

  • In the browser on the offline demo: created items and locations, received two lots, and recorded a use that drew from the first-expiring lot as expected. Checked the desktop and phone layouts. Transfers, counts and the Firefighter role view were covered by tests, not clicked through.
  • For reviewers

  • Known limits are listed in the report:

  • - Crews can record use at any location, not only their assigned unit.
    - No reservations, and one item per transaction.
    - No expiration alerts or notifications yet.
    - "Today" for expiration is the UTC date.
  • Deploying: functions, rules and indexes, then hosting. Let the two indexes finish building before using the History filters.

  • Plans that list modules need emsManagement added in the Creator Console. Nothing existing changes behaviour.
  • 🤖 Generated with Claude Code

    Diff: 471 lines (+353 / -118) across 5 files Reviewer: chatgpt-codex-connector[bot] Review duration: 3m
    All Vouch review confidence checks passed
    Residual risk 0.37 = Change Risk (0.46) × (1 − Review Confidence (0.20)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 471 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 26% · Reviewer familiarity: 35%
    19%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.368
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #97"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 19.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.7% (MEDIUM) · Higher = larger blast radius
    45.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 19.6% · Lower = rushed or shallow review
    19.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 36.7% · Moderate risk
    36.7%