Skip to content

Draft: feat(patients): Auto-generate unique sequential book number

Kushal Lagichetty requested to merge feat/patients-auto-generate-book-no into develop

Close #49 (closed)

MR: Auto-generate Unique Sequential Book Number

Summary

This MR adds a backend endpoint to generate the smallest available book_no automatically, ensuring uniqueness and gap-filling without relying on manual assignment.


Changes

  • Added GET /api/v1/patients/book_no/generate endpoint
  • Implemented efficient gap-detection logic using ordered/index-friendly queries
  • Ensured generated book_no never collides with existing records
  • Added proper error handling for database failures
  • Preserved existing patient creation APIs

Data Integrity

  • book_no uniqueness enforced at DB level
  • Endpoint generates a candidate number only
  • Patient creation handles rare race-condition retries safely

Testing

  • Verified behavior with:
    • Empty table
    • Contiguous sequences
    • Gapped sequences
    • Large ranges (thousands of records)

Notes

  • Backend-only change
  • Scalable and production-safe implementation
Edited by Kushal Lagichetty

Merge request reports

Loading