Skip to main content
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.
success
boolean
Indicates if the request was successful
doctors
array
Array of doctor objects
{
  "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.
name
string
required
Doctor’s full name
username
string
required
Username for login (must be unique)
password
string
required
Password for the account (will be hashed)
email
string
Email address (must be unique if provided)
specialty
string
Medical specialty (e.g., “Orthodontics”, “Endodontics”, “Periodontics”)
license_number
string
Professional license number
branch_id
integer
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.
doctor_id
integer
required
Doctor profile ID
user_id
integer
required
Associated user account ID
name
string
required
Doctor’s full name
username
string
required
Username for login
email
string
Email address
specialty
string
Medical specialty
license_number
string
Professional license number
branch_id
integer
Primary branch assignment
status
string
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.
userId
integer
required
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

{
  "message": "No autorizado"
}

Source Reference

API implementation can be found in:
  • src/routes/api/doctors/+server.js - All doctor management endpoints

Build docs developers (and LLMs) love