SpringLife Care API Documentation
The SpringLife Care API provides a comprehensive set of endpoints for managing patient information in the SpringLife Care healthcare system. This RESTful API enables integration with various platforms and applications, allowing for seamless patient data management.
Getting Started
Base URL
https://api.springlife-care.com/v1
Prerequisites
- PHP 7.4 or higher
- MySQL 5.7 or higher
- PDO PHP Extension
- JSON PHP Extension
Installation
- Clone the repository:
git clone https://github.com/your-organization/springlife-care-api.git
- Configure your database connection in
config/database.php
- Import the database schema:
mysql -u username -p springlife_care < schema.sql
Authentication
The SpringLife Care API uses token-based authentication. To authenticate your requests, include your API key in the request header:
Authorization: Bearer YOUR_API_KEY
For development purposes, you can use the test API key: test_key_123456
API Endpoints
The API is organized around resources. Each resource has its own set of endpoints for performing operations.
Patient Management
Creates a new patient record in the system.
Authentication
Required
Required Fields
Field | Type | Description | Constraints |
---|---|---|---|
full_name | string | Patient's full name | Max 100 characters |
string | Patient's email address | Valid email format, unique | |
password_hash | string | Hashed password | Min 8 characters |
gender | enum | Patient's gender | 'Male', 'Female', 'Other' |
date_of_birth | date | Patient's date of birth | Valid date format (YYYY-MM-DD) |
phone_number | string | Patient's phone number | Max 20 characters |
Optional Fields
Field | Type | Description | Default |
---|---|---|---|
emergency_contact_name | string | Name of emergency contact | null |
emergency_contact_phone | string | Phone number of emergency contact | null |
city | string | Patient's city of residence | null |
region | string | Patient's region/state | null |
country | string | Patient's country of residence | null |
relation_to_client | string | Relationship to the client | null |
is_account_created_for_relation | boolean | Whether account is created for a relation | false |
selected_service | string | Selected healthcare service | null |
service_duration | enum | Duration of service | 'Monthly' |
shift | string | Preferred service shift | null |
current_conditions | text | Current medical conditions | null |
total_cost | decimal | Total cost of service | 0.00 |
Example Request
{
"full_name": "John Doe",
"email": "john@example.com",
"password_hash": "hashedpassword",
"gender": "Male",
"date_of_birth": "1990-01-01",
"phone_number": "+1234567890",
"city": "New York",
"country": "USA"
}
Example Response
{
"status": "success",
"message": "Patient was created successfully.",
"data": {
"patient_id": 1,
"created_at": "2023-06-15T14:30:00Z"
}
}
Retrieves a list of all patients in the system.
Authentication
Required
Query Parameters
Parameter | Type | Description | Default |
---|---|---|---|
page | integer | Page number for pagination | 1 |
limit | integer | Number of records per page | 20 |
sort | string | Field to sort by | created_at |
order | string | Sort order (asc/desc) | desc |
Example Request
GET /patients/read.php?page=1&limit=10&sort=full_name&order=asc
Example Response
{
"status": "success",
"data": {
"records": [
{
"patient_id": 1,
"full_name": "John Doe",
"email": "john@example.com",
"gender": "Male",
"date_of_birth": "1990-01-01",
"phone_number": "+1234567890",
"emergency_contact_name": "Jane Doe",
"emergency_contact_phone": "+1987654321",
"city": "New York",
"region": "NY",
"country": "USA",
"relation_to_client": null,
"is_account_created_for_relation": false,
"selected_service": "Home Care",
"service_duration": "Monthly",
"shift": "Morning",
"current_conditions": "Hypertension",
"total_cost": 1500.00,
"created_at": "2023-06-15T14:30:00Z",
"updated_at": "2023-06-15T14:30:00Z"
}
],
"pagination": {
"total_records": 45,
"total_pages": 5,
"current_page": 1,
"records_per_page": 10
}
}
}
Retrieves detailed information about a specific patient.
Authentication
Required
Query Parameters
Parameter | Type | Description | Required |
---|---|---|---|
id | integer | Patient ID | Yes |
Example Request
GET /patients/read_one.php?id=1
Example Response
{
"status": "success",
"data": {
"patient_id": 1,
"full_name": "John Doe",
"email": "john@example.com",
"gender": "Male",
"date_of_birth": "1990-01-01",
"phone_number": "+1234567890",
"emergency_contact_name": "Jane Doe",
"emergency_contact_phone": "+1987654321",
"city": "New York",
"region": "NY",
"country": "USA",
"relation_to_client": null,
"is_account_created_for_relation": false,
"selected_service": "Home Care",
"service_duration": "Monthly",
"shift": "Morning",
"current_conditions": "Hypertension",
"total_cost": 1500.00,
"created_at": "2023-06-15T14:30:00Z",
"updated_at": "2023-06-15T14:30:00Z"
}
}
Updates an existing patient record.
Authentication
Required
Required Fields
Field | Type | Description |
---|---|---|
patient_id | integer | ID of the patient to update |
Optional Fields
Same as the optional fields for Create Patient.
Example Request
{
"patient_id": 1,
"full_name": "John Doe Updated",
"email": "john.updated@example.com",
"phone_number": "+1987654321"
}
Example Response
{
"status": "success",
"message": "Patient was updated successfully.",
"data": {
"patient_id": 1,
"updated_at": "2023-06-16T09:45:00Z"
}
}
Deletes a patient record from the system.
Authentication
Required
Required Fields
Field | Type | Description |
---|---|---|
patient_id | integer | ID of the patient to delete |
Example Request
{
"patient_id": 1
}
Example Response
{
"status": "success",
"message": "Patient was deleted successfully."
}
Request & Response Formats
Request Format
All requests should be made using JSON format with the appropriate Content-Type header:
Content-Type: application/json
Response Format
All responses follow a standard JSON format:
{
"status": "success|error",
"message": "Human-readable message",
"data": {
// Response data (if applicable)
}
}
Error Handling
The API uses standard HTTP status codes to indicate the success or failure of a request:
Status Code | Description |
---|---|
200 OK | Request succeeded |
201 Created | Resource created successfully |
400 Bad Request | Invalid parameters |
401 Unauthorized | Authentication required |
403 Forbidden | Insufficient permissions |
404 Not Found | Resource not found |
422 Unprocessable Entity | Validation error |
429 Too Many Requests | Rate limit exceeded |
500 Internal Server Error | Server error |
503 Service Unavailable | Service temporarily unavailable |
Error Response Format
{
"status": "error",
"message": "Detailed error message",
"errors": [
{
"field": "field_name",
"message": "Field-specific error message"
}
]
}
Rate Limiting
The API implements rate limiting to ensure fair usage:
- 100 requests per minute for standard API keys
- 1000 requests per minute for premium API keys
Rate limit information is included in the response headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1623758400
Security Considerations
Data Protection
- All data is transmitted over HTTPS
- Passwords are hashed using bcrypt with a cost factor of 12
- Sensitive data is encrypted at rest
Input Validation
- All input is sanitized to prevent SQL injection
- Input validation is performed on all fields
- Prepared statements are used for all database queries
CORS
Cross-Origin Resource Sharing (CORS) is enabled for the following origins:
- https://springlife-care.com
- https://admin.springlife-care.com
- https://app.springlife-care.com
Database Schema
The API uses the following database schema:
CREATE TABLE patients (
patient_id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
gender ENUM('Male', 'Female', 'Other') NOT NULL,
date_of_birth DATE NOT NULL,
phone_number VARCHAR(20) NOT NULL,
emergency_contact_name VARCHAR(100),
emergency_contact_phone VARCHAR(20),
city VARCHAR(100),
region VARCHAR(100),
country VARCHAR(100),
relation_to_client VARCHAR(100),
is_account_created_for_relation BOOLEAN DEFAULT FALSE,
selected_service VARCHAR(100),
service_duration ENUM('Weekly', 'Monthly', 'Yearly') DEFAULT 'Monthly',
shift VARCHAR(100),
current_conditions TEXT,
total_cost DECIMAL(10,2) DEFAULT 0.00,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Integration Examples
'John Doe',
'email' => 'john@example.com',
'password_hash' => password_hash('password123', PASSWORD_DEFAULT),
'gender' => 'Male',
'date_of_birth' => '1990-01-01',
'phone_number' => '+1234567890'
];
$options = [
'http' => [
'header' => "Content-type: application/json\r\nAuthorization: Bearer YOUR_API_KEY\r\n",
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);
print_r($response);
?>
// Create a new patient
async function createPatient() {
const url = 'https://api.springlife-care.com/v1/patients/create.php';
const data = {
full_name: 'John Doe',
email: 'john@example.com',
password_hash: 'hashedpassword', // In production, hash on server-side
gender: 'Male',
date_of_birth: '1990-01-01',
phone_number: '+1234567890'
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify(data)
});
const result = await response.json();
console.log(result);
} catch (error) {
console.error('Error:', error);
}
}
import requests
import json
# Create a new patient
url = 'https://api.springlife-care.com/v1/patients/create.php'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
}
data = {
'full_name': 'John Doe',
'email': 'john@example.com',
'password_hash': 'hashedpassword', # In production, hash on server-side
'gender': 'Male',
'date_of_birth': '1990-01-01',
'phone_number': '+1234567890'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)
Support
For technical support or questions about the API, please contact:
- Email: api-support@springlife-care.com
- Phone: +1 (555) 123-4567
- Documentation: https://docs.springlife-care.com/api