The Doctors API allows you to create, retrieve, update, and delete doctor profiles in the system. Each doctor has an associated user account for authentication.
Authentication
All endpoints require authentication with appropriate permissions:
VIEW_DOCTORS - View doctor profiles
MANAGE_DOCTORS - Create, update, and delete doctors
Endpoints
List Doctors
curl -X GET "https://your-domain.com/api/doctors" \
-H "Cookie: session=your-session-token"
Retrieve a list of all doctors in the system.
Indicates if the request was successful
Array of doctor objects Unique doctor profile identifier
Associated user account ID
Doctor’s initials (auto-generated from name)
Professional license number
Primary branch assignment
Name of the primary branch
Account status (active, inactive)
{
"success" : true ,
"doctors" : [
{
"doctor_id" : 1 ,
"user_id" : 5 ,
"name" : "Dr. Sarah Smith" ,
"username" : "drssmith" ,
"email" : "[email protected] " ,
"initials" : "DSS" ,
"specialty" : "Orthodontics" ,
"license_number" : "ODO-12345" ,
"branch_id" : 1 ,
"branch_name" : "Main Office" ,
"status" : "active" ,
"created_at" : "2024-01-10T08:00:00Z"
},
{
"doctor_id" : 2 ,
"user_id" : 6 ,
"name" : "Dr. Michael Johnson" ,
"username" : "drjohnson" ,
"email" : "[email protected] " ,
"initials" : "DMJ" ,
"specialty" : "Endodontics" ,
"license_number" : "END-67890" ,
"branch_id" : 2 ,
"branch_name" : "Downtown Branch" ,
"status" : "active" ,
"created_at" : "2024-01-15T10:30:00Z"
}
]
}
Create Doctor
curl -X POST "https://your-domain.com/api/doctors" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"name": "Dr. Sarah Smith",
"username": "drssmith",
"email": "[email protected] ",
"password": "SecurePass123!",
"specialty": "Orthodontics",
"license_number": "ODO-12345",
"branch_id": 1
}'
Create a new doctor profile with an associated user account.
Username for login (must be unique)
Password for the account (will be hashed)
Email address (must be unique if provided)
Medical specialty (e.g., “Orthodontics”, “Endodontics”, “Periodontics”)
Professional license number
Primary branch assignment
{
"success" : true ,
"message" : "Médico registrado correctamente" ,
"id" : 5
}
The system automatically generates initials from the doctor’s name. For example, “Dr. Sarah Smith” becomes “DSS”.
Update Doctor
curl -X PUT "https://your-domain.com/api/doctors" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"doctor_id": 1,
"user_id": 5,
"name": "Dr. Sarah Smith-Jones",
"username": "drssmith",
"email": "[email protected] ",
"specialty": "Orthodontics & Pediatric Dentistry",
"license_number": "ODO-12345",
"branch_id": 1,
"status": "active"
}'
Update an existing doctor’s profile.
Associated user account ID
Professional license number
Primary branch assignment
Account status: “active” or “inactive” (default: “active”)
{
"success" : true ,
"message" : "Médico actualizado correctamente"
}
Delete Doctor
curl -X DELETE "https://your-domain.com/api/doctors?userId=5" \
-H "Cookie: session=your-session-token"
Delete a doctor profile and associated user account.
User account ID to delete (this will also delete the associated doctor profile)
{
"success" : true ,
"message" : "Médico eliminado correctamente"
}
Deleting a doctor removes both the doctor profile and the associated user account. This action cannot be undone.
Doctor Initials
The system automatically calculates doctor initials from their name:
Takes the first letter of each word in the name
Converts to uppercase
Limits to 3 characters maximum
Examples:
“Sarah Smith” → “SS”
“Dr. Sarah Smith” → “DSS”
“John Michael Anderson” → “JMA”
Initials are recalculated automatically when the doctor’s name is updated.
Common Use Cases
List All Active Doctors
curl -X GET "https://your-domain.com/api/doctors" \
-H "Cookie: session=your-session-token"
Filter active doctors client-side by checking status === "active".
Create Doctor with Full Profile
curl -X POST "https://your-domain.com/api/doctors" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"name": "Dr. Emily Rodriguez",
"username": "dremily",
"email": "[email protected] ",
"password": "SecurePassword123!",
"specialty": "Periodontics",
"license_number": "PER-54321",
"branch_id": 1
}'
Update Doctor Specialty
curl -X PUT "https://your-domain.com/api/doctors" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"doctor_id": 1,
"user_id": 5,
"name": "Dr. Sarah Smith",
"username": "drssmith",
"email": "[email protected] ",
"specialty": "Orthodontics & Cosmetic Dentistry",
"license_number": "ODO-12345",
"branch_id": 1
}'
Deactivate Doctor
curl -X PUT "https://your-domain.com/api/doctors" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"doctor_id": 1,
"user_id": 5,
"name": "Dr. Sarah Smith",
"username": "drssmith",
"email": "[email protected] ",
"specialty": "Orthodontics",
"license_number": "ODO-12345",
"branch_id": 1,
"status": "inactive"
}'
Error Responses
401 Unauthorized
403 Forbidden
400 Bad Request
409 Conflict
500 Internal Server Error
{
"message" : "No autorizado"
}
Source Reference
API implementation can be found in:
src/routes/api/doctors/+server.js - All doctor management endpoints