feat(api): add endpoint to unregister doctor from camp

Unregister Doctor Endpoint & Registration Bug Fix

Summary

Added a new DELETE endpoint to unregister doctors from the latest medical camp, and fixed a bug where registering a doctor via admin would fail with "already registered" even though the doctor wasn't shown as registered in the UI.


Changes Made

1. New Endpoint: Unregister Doctor from Camp

Endpoint: DELETE /api/v1/doctors/{doctor_id}/register
Location: doctor_routes.py

The unregister_doctor_endpoint performs the following:

  • Validates the doctor ID is a valid UUID format
  • Queries and verifies the doctor exists in the database
  • Finds the latest medical camp (ordered by camp_date descending)
  • Locates the doctor's camp registration record (CampVisit with camp_role='doctor')
  • Deletes the registration and commits the transaction

API Specification

  • Method: DELETE
  • Path: /api/v1/doctors/{doctor_id}/register
  • Authentication: Requires admin privileges (require_admin())
  • Response: HTTP 204 No Content on success

Error Handling

Status Code Condition
400 Invalid doctor ID format (not a valid UUID)
404 Doctor not found
404 Doctor is not registered for any camp

2. Bug Fix: "Doctor already registered" False Positive

Location: doctor_service.py → register_doctor_for_camp()

Problem

When a doctor self-signs up for a camp (via the camp signup flow), a CampVisit record is created with attendance=False.

The listing endpoint:

GET /registered

filters by:

attendance=True

So the doctor does not appear as registered in the UI.

However, the registration endpoint:

POST /{doctor_id}/register

only checked for the existence of a CampVisit record, regardless of attendance status.
This caused it to reject the registration with:

"Doctor already registered for this camp"

Fix

When an existing CampVisit record is found with:

attendance=False

the registration now updates the existing record instead of throwing an error:

  • signup=True
  • attendance=True

The "already registered" error is now raised only when the existing record already has attendance=True.

Edited by Mukthanand Reddy M

Merge request reports

Loading