Clinic Permissions API Integration Guide
This document provides a comprehensive guide for frontend developers to integrate the Clinic Permissions APIs into the Kulcare application.
Table of Contents
- Overview
- Database Schema
- System Architecture
- API Endpoints
- Permission Management Flow
- Permission Search via Elasticsearch
- Response Formats
- Error Handling
Overview
The Clinic Permissions system allows clinic owners and administrators to manage role-based permissions for their clinic staff. This granular permission system ensures that staff members only have access to features they need for their specific roles.
Key Features:
- Role-based permissions: Assign permissions to specific roles (Owner, Doctor, Receptionist, Admin)
- Granular control: Control access to individual features across all modules
- Default permissions: Each role comes with predefined default permissions
- Elasticsearch integration: Fast permission search and filtering capabilities
Permission Categories:
- Appointments
- Patients
- Billing
- Settings
- Communications
- Packages
- Account
Database Schema
The RBAC system is built on three core tables that work together to provide flexible, clinic-specific permission management:
System Architecture
The following diagram shows how the RBAC system components interact:
Required Permissions for API Endpoints
Each API endpoint in the Kulcare system requires specific permissions. Below are the key permission requirements:
✅ APIs Updated with RBAC in This PR
The following endpoints have been updated to use the new RBAC permission system:
Appointments Module
- GET /clinics/:clinic_id/appointments (
index): Requiresappointments.viewpermission - GET /clinics/:clinic_id/appointments/list (
list): Requiresappointments.viewpermission - POST /clinics/:clinic_id/appointments (
create): Requiresappointments.createpermission - PUT /clinics/:clinic_id/appointments/:id (
update): Requiresappointments.edit/appointments.reschedulepermission - DELETE /clinics/:clinic_id/appointments/:id (
destroy): Requiresappointments.deletepermission
Patients Module
- GET /clinics/:clinic_id/patients (
index): Requirespatients.view_listpermission - GET /clinics/:clinic_id/patients/list (
list): Requirespatients.view_listORbilling.reportspermission - GET /clinics/:clinic_id/patients/:id (
show): Requirespatients.view_detailspermission - POST /clinics/:clinic_id/patients (
create): Requirespatients.createORpatients.editpermission - GET /clinics/:clinic_id/patients/generate_report (
generate_report): Requirespatients.view_listORbilling.reportspermission
Billing Module
- GET /clinics/:clinic_id/bills/today (
todays_bills): Requiresbilling.viewpermission - POST /clinics/:clinic_id/bills (
create): Requiresbilling.createpermission - PUT /clinics/:clinic_id/bills/:id (
update): Requiresbilling.editpermission - DELETE /clinics/:clinic_id/bills/:id (
destroy): Requiresbilling.editpermission - GET /clinics/:clinic_id/clinic_bills (
index): Requiresbilling.reportspermission - GET /clinics/:clinic_id/clinic_bills/summary (
summary): Requiresbilling.reportspermission - GET /clinics/:clinic_id/billing_logs (
billing_logs): Requiresbilling.reportspermission
Care Packages Module
- GET /clinics/:clinic_id/packages (
index): Requirespackages.viewpermission - GET /clinics/:clinic_id/packages/:id (
show): Requirespackages.viewpermission - POST /clinics/:clinic_id/packages (
create): Requirespackages.createpermission - DELETE /clinics/:clinic_id/packages/:id (
destroy): Requirespackages.deletepermission - POST /clinics/:clinic_id/packages/:id/associate (
associate): Requirespackages.viewpermission - POST /clinics/:clinic_id/packages/:id/share (
share): Requirespackages.sharepermission
Settings Module
- GET /clinics/:clinic_id/settings (
show): Requiressettings.clinicpermission - GET /clinics/:clinic_id/services (
index): Requiressettings.clinicpermission - POST /clinics/:clinic_id/services (
create): Requiressettings.clinicpermission - GET /clinics/:clinic_id/staff (
index): Requiressettings.userspermission - POST /clinics/:clinic_id/staff (
create): Requiressettings.userspermission - DELETE /clinics/:clinic_id/staff/:id (
destroy): Requiressettings.userspermission - POST /clinics/:clinic_id/staff/:id/reinvite (
reinvite): Requiressettings.userspermission - GET /clinics/:clinic_id/permissions (
index): Requiressettings.permissions.viewpermission - POST /clinics/:clinic_id/permissions (
create): Requiressettings.permissions.editpermission - POST /clinics/:clinic_id/permissions/remove (
remove): Requiressettings.permissions.editpermission
Communications Module
- POST /clinics/:clinic_id/communications/sms (
sms): Requirescommunicationspermission - POST /clinics/:clinic_id/communications/whatsapp (
whatsapp): Requirescommunicationspermission - POST /clinics/:clinic_id/communications/email (
email): Requirescommunicationspermission
Account Module
- GET /billing_payments (
index): Requiresaccount.transactionspermission - GET /telemedicine_payments (
index): Requiresaccount.transactionspermission - GET /clinics/:clinic_id/bank_details (
index): Requiresaccount.bank_detailspermission - POST /clinics/:clinic_id/bank_details (
create): Requiresaccount.bank_detailspermission
API Endpoints
Base URL: {{url}}/clinics/:clinic_id/permissions
| Method | Endpoint | Purpose | Authorization Required |
|---|---|---|---|
| GET | / | List all permissions for a clinic | Yes (Owner only) |
| POST | / | Create/update permissions for a role | Yes (Owner only) |
| POST | /remove | Remove specific permissions from a role | Yes (Owner only) |
Permission Search API (Elasticsearch)
Base URL: {{elasticsearch_url}}/permissions_{{env}}/_search
This endpoint provides fast search capabilities across all available permissions with filtering options.
Permission Management Flow
1. List Current Clinic Permissions
Retrieve all permissions configured for the clinic, grouped by role.
GET {{url}}/clinics/:clinic_id/permissions
Authorization: Bearer {{auth_token}}Parameters:
clinic_id(path): The ID of the clinic
Response example:
{
"success": true,
"message": "Permissions fetched successfully",
"data": [
{
"role_id": 1,
"role_name": "Owner",
"permissions": [
{
"id": 123,
"permission_id": 1,
"permission_name": "appointments.view",
"permission_category": "appointments",
"enabled": true,
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T10:30:00.000Z"
},
{
"id": 124,
"permission_id": 2,
"permission_name": "appointments.create",
"permission_category": "appointments",
"enabled": true,
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T10:30:00.000Z"
}
]
},
{
"role_id": 2,
"role_name": "Doctor",
"permissions": [
{
"id": 125,
"permission_id": 1,
"permission_name": "appointments.view",
"permission_category": "appointments",
"enabled": true,
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T10:30:00.000Z"
}
]
}
]
}UI Implementation:
- Display permissions grouped by role in a tabbed or accordion interface
- Show permission categories with expandable sections
- Use toggle switches for enable/disable functionality
- Highlight permissions that differ from defaults
2. Create/Update Permissions
Assign permissions to a specific role within the clinic. This endpoint can be used to:
- Grant new permissions to a role
- Update existing permission settings
- Bulk update multiple permissions at once
POST {{url}}/clinics/:clinic_id/permissions
Authorization: Bearer {{auth_token}}
Content-Type: application/json
{
"role_id": 2,
"permission_ids": [1, 2, 3, 5, 8]
}Parameters:
clinic_id(path): The ID of the clinicrole_id(body): The role to assign permissions topermission_ids(body): Array of permission IDs to enable for this role
Response example:
{
"success": true,
"message": "Permissions updated successfully",
"data": [
{
"role_id": 2,
"role_name": "Doctor",
"permissions": [
{
"id": 125,
"permission_id": 1,
"permission_name": "appointments.view",
"permission_category": "appointments",
"enabled": true,
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T12:00:00.000Z"
},
{
"id": 126,
"permission_id": 2,
"permission_name": "appointments.create",
"permission_category": "appointments",
"enabled": true,
"created_at": "2025-01-15T12:00:00.000Z",
"updated_at": "2025-01-15T12:00:00.000Z"
}
]
}
]
}UI Implementation:
- Show loading state during update
- Display success notification
- Update UI immediately to reflect changes
- Consider implementing optimistic updates
3. Remove Permissions
Remove specific permissions from a role. This is useful when you need to revoke access to certain features.
POST {{url}}/clinics/:clinic_id/permissions/remove
Authorization: Bearer {{auth_token}}
Content-Type: application/json
{
"role_id": 2,
"permission_ids": [3, 5]
}Parameters:
clinic_id(path): The ID of the clinicrole_id(body): The role to remove permissions frompermission_ids(body): Array of permission IDs to remove
Response example:
{
"success": true,
"message": "Permissions removed successfully"
}UI Implementation:
- Confirm before removing permissions
- Show warning if removing critical permissions
- Update UI to reflect removed permissions
- Consider batch operations for efficiency
Permission Search via Elasticsearch
The permissions are indexed in Elasticsearch for fast searching and filtering. This is particularly useful for:
- Building permission selection interfaces
- Searching permissions by name or category
- Filtering available permissions
Search All Permissions
POST {{elasticsearch_url}}/permissions_{{env}}/_search
Content-Type: application/json
{
"query": {
"match_all": {}
},
"size": 100
}UI Implementation:
- Use Elasticsearch for autocomplete in permission search
- Implement category filters
- Cache search results for performance
- Show permission descriptions in search results
Response Formats
Success Response Structure
All successful API calls follow this format:
{
"success": true,
"message": "Operation completed successfully",
"data": { ... }
}Error Response Structure
{
"success": false,
"error": "Error message",
"error_code": "ERROR_CODE",
"details": { ... }
}