feat(patient): add blood_group field support in backend

Merge Request

Overview

This MR introduces support for storing and retrieving the blood_group field in the patient module. This enhancement ensures that blood group information captured during patient registration is persisted in the database and returned via API responses, enabling frontend display in the patient profile.


What does this MR do and why?

Previously, the system did not store patient blood group information, even though the frontend allowed selection. This caused inconsistency where blood group appeared as null in API responses and patient profiles.

This MR resolves the issue by:

  • Adding a new blood_group field in the database
  • Updating backend models and schemas
  • Ensuring the value is saved and returned correctly

This change is required to maintain data consistency and improve patient record completeness.


Changes Made

  • Added blood_group column to patients table

  • Updated SQLAlchemy Patient model

  • Updated Pydantic schemas:

    • PatientBase
    • PatientCreate
    • PatientUpdate
    • PatientResponse
  • Updated service layer to store blood_group

  • Ensured API responses include blood_group


Technical Details

  • Root cause: blood_group was not present in DB schema and not handled in service layer

  • Fix:

    • Added DB column (VARCHAR)
    • Updated schema validation
    • Passed field through service layer into DB
  • Data flow: UI → API → Schema → Service → DB → Response


Type of Change

  • 🐛 Bug fix
  • New feature
  • 💥 Breaking change
  • 📝 Documentation update
  • ️ Refactor
  • Performance improvement
  • 🧪 Test update
  • 🔧 Configuration change
  • 🚨 Security fix
  • 🗑️ Deprecation

Related Issues / References

Closes #


Screenshots or Screen Recordings

  • Verified via curl:
curl -X POST /api/v1/patients/ ...

Response:

"blood_group": "B+"

How to Validate Locally

  1. Start backend:
docker compose up -d
  1. Add column (if not migrated):
docker exec -it ehrs-postgres psql -U postgres -d medical_camp -c "ALTER TABLE patients ADD COLUMN blood_group VARCHAR;"
  1. Login:
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"book_no":"1","password":"admin123"}'
  1. Create patient:
curl -X POST http://localhost:8000/api/v1/patients/ \
-H "Authorization: Bearer <token>" \
-d '{"patient_name":"Test","patient_book_no":"99","patient_age":25,"patient_sex":"male","blood_group":"B+"}'
  1. Verify:
curl http://localhost:8000/api/v1/patients/<book_no>

Expected:

"blood_group": "B+"

Testing Done

  • Unit tests added/updated
  • API endpoint tests passing

Test Cases Covered:

Scenario Expected Result Status
Create patient with blood_group Stored correctly
Fetch patient Returns blood_group
Missing blood_group Returns null

Code Quality Checklist

  • Code follows project conventions
  • No unused code
  • Type hints added
  • Proper schema validation used

Documentation

  • README updated
  • CHANGELOG.md to be updated

Known Limitations / Technical Debt

  • No validation for allowed blood group values (can be added later as enum)

Additional Notes

  • This change is backward compatible
  • Existing patients will have blood_group = null

MR Acceptance Checklist

  • Code works as intended
  • No existing functionality broken
  • Edge cases handled

Closes #99 (closed)

Merge request reports

Loading