The Patients API allows you to create, retrieve, update, and delete patient records in the OdontologyApp system.
Authentication
All endpoints require authentication. Users must have appropriate permissions:
VIEW_PATIENTS - View patient records
CREATE_PATIENTS - Create new patients
EDIT_PATIENTS - Update patient information
DELETE_PATIENTS - Delete patient records
Base Endpoints
List Patients
curl -X GET "https://your-domain.com/api/patients?query=john" \
-H "Cookie: session=your-session-token"
Retrieve a list of all patients with optional search filtering.
Search query to filter patients by name, cedula, or other fields
Indicates if the request was successful
Array of patient objects
Unique patient identifier
Patient’s identification number
Date of birth (YYYY-MM-DD)
Gender (male, female, otro)
Patient status (active, inactive)
{
"success": true,
"patients": [
{
"id": 1,
"medrecno": "P-2024-0001",
"first_name": "John",
"last_name": "Doe",
"cedula": "12345678",
"birth_date": "1990-05-15",
"phone": "+1234567890",
"email": "[email protected]",
"sex": "male",
"blood_group": "O+",
"allergies": "Penicillin",
"branch_id": 1,
"status": "active"
}
]
}
Create Patient
curl -X POST "https://your-domain.com/api/patients" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"first_name": "John",
"last_name": "Doe",
"cedula": "12345678",
"birth_date": "1990-05-15",
"phone": "+1234567890",
"email": "[email protected]",
"sex": "male",
"blood_group": "O+",
"allergies": "Penicillin",
"branch_id": 1
}'
Create a new patient record.
Patient’s identification number (must be unique)
Date of birth in YYYY-MM-DD format
Email address (must be unique)
Gender: “male”, “female”, or “otro” (default: “otro”)
Blood type (e.g., “O+”, “A-”)
ID of the branch to associate with this patient
{
"success": true,
"id": 42,
"medrecno": "P-2024-0042"
}
Get Patient Details
curl -X GET "https://your-domain.com/api/patients/1" \
-H "Cookie: session=your-session-token"
Retrieve detailed information about a specific patient.
{
"success": true,
"patient": {
"id": 1,
"medrecno": "P-2024-0001",
"first_name": "John",
"last_name": "Doe",
"cedula": "12345678",
"birth_date": "1990-05-15",
"phone": "+1234567890",
"email": "[email protected]",
"sex": "male",
"blood_group": "O+",
"allergies": "Penicillin",
"branch_id": 1,
"status": "active",
"created_at": "2024-01-15T10:30:00Z"
}
}
Update Patient
curl -X PUT "https://your-domain.com/api/patients/1" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"first_name": "John",
"last_name": "Smith",
"cedula": "12345678",
"phone": "+1234567899",
"status": "active"
}'
Update an existing patient’s information.
Patient’s identification number
Patient status (default: “active”)
{
"success": true,
"message": "Paciente actualizado correctamente"
}
Delete Patient
curl -X DELETE "https://your-domain.com/api/patients?id=1" \
-H "Cookie: session=your-session-token"
Delete a patient record from the system.
ID of the patient to delete
{
"success": true,
"message": "Paciente eliminado"
}
Patient Sub-Resources
Get Patient Appointments
curl -X GET "https://your-domain.com/api/patients/1/appointments" \
-H "Cookie: session=your-session-token"
Retrieve all appointments for a specific patient.
Permission Required: VIEW_APPOINTMENTS
{
"success": true,
"appointments": [
{
"id": 10,
"patient_id": 1,
"doctor_id": 2,
"branch_id": 1,
"appointment_date": "2024-03-20",
"appointment_time": "10:00:00",
"duration_minutes": 30,
"status": "scheduled",
"notes": "Regular checkup"
}
]
}
Create Patient Appointment
curl -X POST "https://your-domain.com/api/patients/1/appointments" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"doctor_id": 2,
"branch_id": 1,
"appointment_date": "2024-03-20",
"appointment_time": "10:00",
"duration_minutes": 30,
"notes": "Regular checkup"
}'
Permission Required: CREATE_APPOINTMENTS
Date in YYYY-MM-DD format
Duration in minutes (default: 30)
Get Patient Odontogram
curl -X GET "https://your-domain.com/api/patients/1/odontogram" \
-H "Cookie: session=your-session-token"
Retrieve the dental chart (odontogram) for a patient.
Permission Required: VIEW_ODONTOGRAM
{
"success": true,
"tooth_states": {
"11": "healthy",
"12": "cavity",
"21": "filled",
"22": "healthy"
}
}
Update Tooth State
curl -X POST "https://your-domain.com/api/patients/1/odontogram" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"tooth_number": "12",
"state": "cavity",
"notes": "Small cavity detected"
}'
Permission Required: EDIT_ODONTOGRAM
Tooth number (FDI notation)
State of the tooth (healthy, cavity, filled, missing, etc.)
Additional notes about the tooth
Get Medical Records
curl -X GET "https://your-domain.com/api/patients/1/records" \
-H "Cookie: session=your-session-token"
Retrieve all medical records for a patient.
Permission Required: VIEW_MEDICAL_RECORDS
{
"success": true,
"records": [
{
"id": 5,
"patient_id": 1,
"doctor_id": 2,
"motif": "Tooth pain",
"diagnosis": "Cavity in molar",
"treatment": "Filling applied",
"future_plan": "Follow-up in 6 months",
"next_visit": "2024-09-15",
"observations": "Patient responded well to treatment",
"created_at": "2024-03-15T14:30:00Z"
}
]
}
Create Medical Record
curl -X POST "https://your-domain.com/api/patients/1/records" \
-H "Content-Type: application/json" \
-H "Cookie: session=your-session-token" \
-d '{
"motif": "Tooth pain",
"diagnosis": "Cavity in molar",
"treatment": "Filling applied",
"future_plan": "Follow-up in 6 months",
"next_visit": "2024-09-15",
"observations": "Patient responded well"
}'
Permission Required: CREATE_MEDICAL_RECORDS
Next scheduled visit date (YYYY-MM-DD)
{
"success": true,
"message": "Historia clínica añadida correctamente",
"record_id": 5
}
Error Responses
{
"message": "No autorizado"
}
Source Reference
API implementation can be found in:
src/routes/api/patients/+server.js - Main patient endpoints
src/routes/api/patients/[id]/+server.js - Individual patient operations
src/routes/api/patients/[id]/appointments/+server.js - Patient appointments
src/routes/api/patients/[id]/odontogram/+server.js - Dental chart management
src/routes/api/patients/[id]/records/+server.js - Medical records