Skip to content

feat: bookings.update, bill at booking, Booking.invoices (1.10.0) - #17

Merged
BackStacked merged 1 commit into
mainfrom
claude/project-thread-w4wng5
Nov 11, 2026
Merged

BackStacked merged 1 commit into
mainfrom
claude/project-thread-w4wng5

Conversation

@BackStacked

Copy link
Copy Markdown
Contributor

Requested by Himanshu · project thread

This is the client side of api's booking edits and billing at booking (mgpl-diagnostics/api, branch claude/project-thread-w4wng5).

  • bookings.update(id, input) calls updateBooking. The input covers the doctor, collection type, time and address, notes, addTests and removeTestCodes. It returns:
    • the booking and its samples;
    • the invoices issued and cancelled;
    • any credit notes;
    • refundablePaise.
  • bookings.create accepts bill: { payments, billDiscountPaise, applyTaxRules }, and the result carries the invoice.
  • Booking now selects sampleCollection.address and invoices (every invoice of the booking).

Release

After merge, tag v1.10.0. api's kits.json already points at it, and the api's lockfile needs refreshing once the package is published.

Checks

  • npm run typecheck, npm run build and npm run llms pass.
  • The api's test suite ran against this client, packed as a tarball: 260 passed, 0 failed on PostgreSQL. This includes the check that every query and mutation has a client operation.

Generated by Claude Code

…ces (1.10.0)

- bookings.update(id, input): doctor, collection details, notes, add or
  remove tests; returns the booking, samples, issued and cancelled
  invoices, credit notes and the refundable amount.
- createBooking input.bill issues the invoice in the same request; the
  result carries it.
- Booking selects sampleCollection.address and invoices (every invoice of
  the booking).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018jBohjC7uBfVPopxyZBtS1
@BackStacked BackStacked self-assigned this Nov 11, 2026
@BackStacked
BackStacked merged commit aa81288 into main Nov 11, 2026
1 check passed
@BackStacked
BackStacked deleted the claude/project-thread-w4wng5 branch November 11, 2026 14:44
BackStacked added a commit to mgpl-diagnostics/api that referenced this pull request Nov 11, 2026
<!-- claude-projects-attribution: {"github_login":"BackStacked"} -->
_Requested by **Himanshu** · [project
thread](https://claude.ai/code/project/chan_016JXeBZ2UxSi4N5VU2C26fQ?thread=cmsg_016JXeBZ2UxSi4N5VU2C26fQAJpeqaqNzFLLBxQs5TiAW8)_

This covers C1 and C2 from the handoff: a booking can be changed after
it is made, and it can be billed in the same request that creates it.

## updateBooking (`booking:update`)

A booking can be edited while it is booked, sample collected or in
process.

- **Doctor, collection type, time, address and notes.** Fields left out
stay as they are. `null` clears the doctor, the time or the address.
- **Add tests.** A new sample type gets a new pending tube.
- **Remove tests.** Only while the test has no results; its empty report
is dropped.
- A tube that hasn't been collected yet is dropped when no remaining
test needs it.
  - The last test can't be removed. Cancel the booking instead.
- **Billing follows, in the same transaction.**

| The invoice is | What happens | Extra permission |
|---|---|---|
| Unpaid | Cancelled and issued again with the booking's tests. Line
discounts and the bill discount (capped) are kept. | `invoice:create`,
plus `invoice:cancel` when tests are removed |
| Paid or credited | A credit note for each removed test's line.
`refundablePaise` says what can be refunded. | `accounts:post` |
| Paid, and tests are added | A new invoice for the added tests |
`invoice:create` |

- `Booking.invoice` stays on the first live invoice. The new
`Booking.invoices` lists every invoice of the booking, and
`cancelBooking` now checks all of them.
- Every edit is audited as `booking.update` with what changed.

Front desk can add tests, but can't remove a billed test, because that
needs `invoice:cancel` or `accounts:post`.

## createBooking `bill` (C2)

`bill: { payments, billDiscountPaise, applyTaxRules }` issues the
invoice for the booked tests inside the booking's transaction. A bad
discount or payment leaves no booking behind. It needs `invoice:create`,
plus `invoice:discount` for a discount and `payment:create` for
payments, the same as `issueInvoice`.

## Releases needed first

1. **client 1.10.0** (mgpl-diagnostics/client#17). `kits.json` already
points at it.
2. Then refresh the lockfile with `npm install
@mgpl-diagnostics/client@1.10.0`. Until then, CI's check that every
operation exists in the client fails on `updateBooking`.

No other kit changes: it uses db-kit 2.1.1 and finance-kit 1.0.1 as they
are. Version 0.1.4. Tag `v0.1.4` after merge; that release also carries
#33.

## Checks

- **PostgreSQL:** `TEST_BACKENDS=pg npm test`, with client 1.10.0
installed from its packed tarball, gives **260 passed, 0 failed**. That
includes 22 new end-to-end checks:
- billing at booking, including rollback on a bad payment and the
discount permission;
  - an unpaid invoice replaced;
  - a paid invoice credited, with a separate invoice for the added test;
  - the permission checks for front desk;
  - results locking a test in;
  - tenant isolation and the audit entries;
  - the trial balance still balancing.
- **MongoDB:** not run here, because this container can't download
MongoDB. CI runs it.
- Typecheck passes. The schema, API reference and llms files are
regenerated. `docs/07-domain-flows.md` and
`docs/examples/lab-day.graphql` are updated.

---
_Generated by [Claude
Code](https://claude.ai/code/session_018jBohjC7uBfVPopxyZBtS1)_

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants