Implement Volunteer Exited State in Camp Status Schema
Issue Summary
Overview
Enhance the medical camp volunteer status API to support an "exited" state. This allows the system to identify volunteers who have finished their shift, enabling a more robust and responsive frontend workflow.
Problem Statement
-
Description: The existing
signup-statusendpoint only provides information on whether a volunteer is signed up or has checked in. It lacks visibility into whether the volunteer has completed their duties and logged out for the day. - Impact: Without this state, the frontend cannot automatically transition the volunteer to a "Thank You" screen upon successful exit attendance marking, leading to a stagnant user experience.
- Affected Systems: EHRS Backend API and Medical Camp Service logic.
Proposed Solution
-
Approach: Introduce a new boolean field
is_exitedin theVolunteerCampStatusschema. Populating this field by checking if the volunteer's current camp visit record contains a non-nulllogout_time. -
Modules to Change:
-
app/schemas/medical_camp.py: Update the response model. -
app/services/medical_camp_service.py: Implement the logic to detect logout status.
-
-
Dependencies: Relies on the existing
CampVisitdatabase table structure.
Test-Driven Development
Acceptance Criteria (Given-When-Then)
Scenario 1: Volunteer is active (Not Exited)
Given a volunteer has a checked-in `CampVisit` record
And the `logout_time` is null
When the status API is queried for this volunteer
Then the response should contain `is_exited: false`
Scenario 2: Volunteer has finished shift (Exited)
Given a volunteer has a `CampVisit` record
And the `logout_time` is populated with a timestamp
When the status API is queried for this volunteer
Then the response should contain `is_exited: true`
Test Cases
| Test ID | Test Description | Precondition | Test Steps | Expected Result | Priority |
|---|---|---|---|---|---|
| TC-001 | Response Schema Validation | N/A | Call status API |
is_exited exists in response |
High |
| TC-002 | Exited Status Logic | Logout time set | Get status via service |
is_exited is True |
High |
| TC-003 | Default Status Logic | No logout time | Get status via service |
is_exited is False |
Medium |
Unit Test Requirements
Components/Functions to Test:
| Module/Component | Function/Hook | Test Cases to Cover |
|---|---|---|
medical_camp_service.py |
get_volunteer_camp_status |
TC-002, TC-003 |
medical_camp.py |
VolunteerCampStatus |
TC-001 |
Test Assertions Required:
-
Schema validates correctly with initial state -
Correctly identifies presence of logout timestamp -
Returns falsy value when logout time is missing or null -
Updates status response mapping appropriately
Implementation Details
Files to Change
| File Path | Action | Purpose |
|---|---|---|
app/schemas/medical_camp.py |
Modify | Add is_exited boolean to the Pydantic model |
app/services/medical_camp_service.py |
Modify | Implement check for logout_time in status logic |
tests/schemas/test_medical_camp_schema.py |
Modify | Add schema validation unit tests |
tests/test_services/test_medical_camp_service.py |
Modify | Add unit tests for the service logic |
Technical Considerations
-
Database Performance: The check is performed on an existing query result for
CampVisit, so there is zero additional database overhead. -
Backward Compatibility: The field is added with a default value of
Falseto maintain compatibility with any older versions of the frontend.
Testing Strategy
Manual Testing
Test Environment:
- API Client: Postman / Swagger UI
- User Role: Volunteer (via token)
Manual Test Steps:
- Use an admin account to mark a volunteer as logged out.
- Query the volunteer status endpoint using the volunteer's token.
- Verify
is_exitedreturnstrue.
Automated Testing
Unit Tests:
-
Pydantic schema validation tests -
Service layer logic tests (Test-driven) -
Database record matching tests
Definition of Done
-
Acceptance criteria met (all Given-When-Then scenarios pass) -
All test cases executed and passing -
Unit tests written and passing -
Code reviewed and approved -
No linting errors (Ruff/Flake8) -
Pydantic models used effectively -
No console/debug statements left -
TypeScript types shared (via frontend sync) -
Documentation (Docstrings/OpenAPI) updated
Additional Context
Related Issues
- Blocks the frontend implementation of the Volunteer appreciation screen.
References
- EHRS Medical Camp API Specification
- Volunteer Management Workflow Overview