fix:update the registered patients count in the camp analytics page
Overview
This MR fixes an issue in the Camp Analytics page where registered patient data was not displayed correctly. The API was returning an empty patient list despite existing registrations, leading to incorrect analytics.
What does this MR do and why?
The issue was caused by improper mocking of chained database queries in the test setup, which resulted in empty responses from the get_patients_by_camp_endpoint.
This MR corrects the query execution order and ensures proper chaining, allowing accurate retrieval of registered patient data for analytics.
Changes Made
- Fixed query mocking order in test cases
- Updated chaining of
.options(),.join(),.filter(),.all() - Modified test cases for both success and empty scenarios
- Ensured correct patient data retrieval in API
- Verified frontend analytics display
Technical Details
-
Root Cause: Incorrect ordering of
db.query.side_effectin tests, breaking query chain simulation - Fix: Aligned mock execution with actual query flow and ensured all chained methods return expected results
- Impact: API now correctly returns patients with 'entry' status
Type of Change
-
🐛 Bug fix (non-breaking change that fixes an issue) -
✨ New feature -
💥 Breaking change -
📝 Documentation update -
♻ ️ Refactor -
⚡ Performance improvement -
🧪 Test update -
🔧 Configuration change -
🚨 Security fix -
🗑 ️ Deprecation
Related Issues / References
- Fixes incorrect patient count in camp analytics dashboard
Screenshots or Screen Recordings
- API now returns correct patient list
- Analytics dashboard shows accurate registered patient count
How to Validate Locally
- Open Camp Analytics page
- Select a medical camp
- Verify registered patient count
- Confirm patient list is displayed correctly
Testing Done
-
Unit tests updated -
API endpoint tests passing
Test Cases Covered:
| Scenario | Expected Result | Status |
|---|---|---|
| Patients exist | Correct patient list returned | |
| No patients | Empty list returned |
Test Commands Run:
pytest
pytest tests/test_api_v1/test_patient_routes.py -v
pytest --cov=app
Code Quality Checklist
Code Standards
-
Code follows conventions -
No unused code -
No duplication -
Proper type hints
Python & FastAPI Best Practices
-
Proper query handling -
Optimized SQLAlchemy usage -
Error handling implemented
API Design
-
RESTful standards followed -
Proper response structure
Documentation
-
README updated -
API docs updated
Known Limitations / Technical Debt
- None identified
Additional Notes
This fix ensures accurate tracking of registered patients, improving analytics reliability for camp coordinators and administrators.
MR Acceptance Checklist
Quality & Correctness
-
Fix works as expected -
No regressions introduced
Maintainability
-
Code is clean and testable -
Follows project standards
Acceptance Review
-
Reviewed by product owner
Edited by Ahlad Pataparla

