feat(backend): enforce patient & doctor phone validation and mandatory patient fields
🚀 Feature Request
Is your feature request related to a problem? Please describe.
Currently, phone number validation for Patient and Doctor entities is primarily handled on the frontend. This allows invalid or inconsistent data (such as incorrect length, non-Indian numbers, or missing mandatory fields) to be persisted if API endpoints are called directly or frontend validation is bypassed. Additionally, patient age and gender are not strictly enforced during create or update operations.
Describe the solution you'd like
Enhance backend schemas/serializers to enforce the following validations:
-
Phone Number (Patient & Doctor)
- Must be exactly 10 digits
- Numeric only
- Must start with 6, 7, 8, or 9
- Country codes (e.g., +91) must be rejected
- Validation should apply to both create and update operations
-
Mandatory Patient Fields
-
patient_agemust be required -
patient_sexmust be required - Requests missing these fields should fail validation for both create and update
-
All invalid requests should return clear and descriptive validation errors.
Describe alternatives you've considered
- Relying only on frontend validation was considered but rejected, as backend must act as the source of truth.
- Database-level constraints alone were considered but would provide less user-friendly error handling compared to schema-level validation.
Additional context
This backend enhancement complements the existing frontend issue that implements real-time validation and duplicate phone number detection during patient registration. Backend validation ensures data integrity regardless of the client consuming the API.