feat(secretary): implement scope separation for secretaries in clinics and personal practices
- Added `owner_type` and `clinic_id` fields to `DoctorSecretary` entity to distinguish between clinic and personal practice relationships. - Updated repository methods to be scope-aware, allowing for specific queries based on the context of the secretary's relationship (clinic or doctor). - Modified `SecretaryController` to handle secretary creation with appropriate scope based on the current user's role. - Enhanced `AuthController` to build contexts that reflect the scope of the secretary's access. - Updated `DashboardController` and `PatientController` to respect the new scope logic when retrieving data. - Created migration to update the database schema accordingly, dropping the old unique constraint and adding the new fields and constraints.
This commit is contained in:
+25
-3
@@ -2,6 +2,19 @@
|
||||
|
||||
> **Prefix:** `/api/v1/secretary`, `/api/v1/secretaries`
|
||||
|
||||
## مدل Scope
|
||||
|
||||
هر رابطه منشی-پزشک دارای یک **scope** است که از تداخل بین محیطهای مختلف جلوگیری میکند:
|
||||
|
||||
| Scope | `owner_type` | تعریفکننده | دسترسی |
|
||||
|-------|-------------|-------------|---------|
|
||||
| مطب شخصی | `doctor` | خود پزشک | فقط نوبتها و دادههای مطب شخصی |
|
||||
| کلینیک | `clinic` | مدیر کلینیک | فقط نوبتها و دادههای کلینیک |
|
||||
|
||||
- یک منشی میتواند هم در مطب شخصی یک دکتر و هم در کلینیک همان دکتر فعال باشد (دو ردیف مجزا)
|
||||
- منشی کلینیک میتواند به چند دکتر در همان کلینیک متصل باشد
|
||||
- scope فعال در runtime از جدول `user_active_context` (db_uuid) خوانده میشود
|
||||
|
||||
Secretaries are linked to a doctor and have granular permissions controlling what they can do on behalf of the doctor.
|
||||
|
||||
---
|
||||
@@ -10,7 +23,7 @@ Secretaries are linked to a doctor and have granular permissions controlling wha
|
||||
|
||||
Create a secretary for a doctor.
|
||||
|
||||
**Permission:** `ROLE_DOCTOR` (must own the doctor) | `ROLE_CLINIC` (must have the doctor in its clinic) | `ROLE_ADMIN`
|
||||
**Permission:** `ROLE_DOCTOR` (must own the doctor — creates `owner_type='doctor'`) | `ROLE_CLINIC` (must have the doctor in its clinic — creates `owner_type='clinic'`) | `ROLE_ADMIN`
|
||||
|
||||
### Request Body (`application/json`)
|
||||
```json
|
||||
@@ -78,6 +91,8 @@ Create a secretary for a doctor.
|
||||
"mobile_number": "09123456789",
|
||||
"doctor_name": "دکتر احمد رضایی",
|
||||
"doctor_uuid": "...",
|
||||
"owner_type": "doctor",
|
||||
"clinic_uuid": null,
|
||||
"is_active": true,
|
||||
"permissions": { ... },
|
||||
"created_at": 1717000000
|
||||
@@ -85,6 +100,12 @@ Create a secretary for a doctor.
|
||||
}
|
||||
```
|
||||
|
||||
**مقادیر `owner_type`:**
|
||||
| مقدار | معنی |
|
||||
|-------|------|
|
||||
| `doctor` | منشی توسط خود دکتر تعریف شده — فقط مطب شخصی |
|
||||
| `clinic` | منشی توسط مدیر کلینیک تعریف شده — فقط کلینیک |
|
||||
|
||||
### Errors
|
||||
| Code | HTTP | Description |
|
||||
|------|------|-------------|
|
||||
@@ -257,8 +278,9 @@ Get all secretaries across **all doctors** of a clinic.
|
||||
```
|
||||
|
||||
### Notes
|
||||
- یک منشی میتواند برای یک یا چند دکتر تعریف شود (جداگانه در جدول `doctor_secretaries`)
|
||||
- این endpoint همه منشیان همه دکترهای کلینیک را یکجا برمیگرداند با ستون `doctor_name` برای تشخیص
|
||||
- این endpoint فقط منشیانی را برمیگرداند که با `owner_type='clinic'` تعریف شدهاند
|
||||
- منشیانی که خود دکتر (با `owner_type='doctor'`) تعریف کرده از این لیست مخفی هستند
|
||||
- یک منشی میتواند به چند دکتر در همان کلینیک متصل باشد — در لیست چندبار ظاهر میشود (یک ردیف به ازای هر دکتر)
|
||||
|
||||
### Errors
|
||||
| Code | HTTP | Description |
|
||||
|
||||
Reference in New Issue
Block a user