Files
clinicpro/docs/phase2_taskes/task-12-secretary-completion/task.md
T
hamed df7a784701 feat: implement realistic data seeding for doctors, clinics, and secretaries
- Added seed_realistic_data.php to clean existing data and populate the database with realistic entries for doctors, clinics, and secretaries.
- Created a structured approach to generate 100 doctors per city with diverse specialties and services.
- Implemented database cleanup routines to ensure a fresh start for data seeding.
- Enhanced the DoctorSecretaryRepository with improved comments for clarity.
2026-06-15 14:18:25 +03:30

158 lines
6.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# تسک ۱۲: تکمیل منشی — محدودیت پنل + UI Permissions
## توضیح
Entity `DoctorSecretary` و API کامل موجود است (`src/Secretary/`). این تسک فقط دو چیز اضافه می‌کند:
1. Backend: بررسی سقف تعداد منشی بر اساس پنل اشتراکی
2. Frontend: Modal با checkbox matrix برای ویرایش permissions
**هیچ endpoint جدیدی ایجاد نمی‌شود.**
## فایل‌های موجود که تغییر می‌کنند
| فایل | تغییر |
| -------------------------------------------------- | ------------------------------------------------------------------ |
| `src/Secretary/Controller/SecretaryController.php` | inject `SubscriptionService`، اضافه کردن limit check در `create()` |
| `assets/admin/pages/SecretariesPage.tsx` | Modal ویرایش با checkbox matrix برای permissions |
## API موجود (بدون تغییر)
| متد | مسیر | توضیح |
| ------ | ---------------------------------- | ----------------------------------------------- |
| GET | `/api/v1/secretaries/{doctorUuid}` | لیست منشی ها |
| POST | `/api/v1/secretary` | ایجاد منشی ← **اینجا limit check اضافه می‌شود** |
| PATCH | `/api/v1/secretary/{uuid}` | ویرایش ← **permissions هم قابل ویرایش می‌شود** |
| DELETE | `/api/v1/secretary/{uuid}` | غیرفعال‌سازی (soft delete) |
## پیش‌نیازها
- تسک ۱۴ (Secretary — موجود در کد)
- **تسک ۱۱** (Subscription — `SubscriptionService` باید موجود باشد)
## زمان تخمینی
۴ تا ۵ ساعت
## تغییر Backend — SecretaryController::create()
### وضعیت فعلی (قبل):
```php
public function create(Request $request): JsonResponse
{
// validate fields
// create DoctorSecretary
// persist
return $this->success($secretary->toArray());
}
```
### وضعیت جدید (بعد):
```php
public function create(Request $request): JsonResponse
{
// 1. پیدا کردن دکتر از doctorUuid در body
$doctor = $this->doctorRepo->findByUuid($request->get('doctor_uuid'));
// 2. بررسی سقف پنل
$entityType = 'doctor';
$entityId = $doctor->getId();
$limit = $this->subscriptionService->getSecretaryLimit($entityType, $entityId);
$current = $this->secretaryRepo->countActive($doctor->getId());
if ($current >= $limit) {
return $this->error(
ErrorCodes::ERR_SECRETARY_LIMIT_REACHED,
'سقف تعداد منشی پنل اشتراکی شما رسیده است',
Response::HTTP_FORBIDDEN
);
}
// 3. ادامه ایجاد منشی ...
}
```
### خطای جدید که باید در ErrorCodes.php اضافه شود:
```php
// src/Shared/Constant/ErrorCodes.php
const ERR_SECRETARY_LIMIT_REACHED = 'ERR_SECRETARY_LIMIT_REACHED';
// messages: 'سقف تعداد منشی پنل اشتراکی شما رسیده است'
```
## تغییر Frontend — SecretariesPage.tsx
### ساختار DEFAULT_PERMISSIONS (از DoctorSecretary::DEFAULT_PERMISSIONS):
```php
[
'version' => 1,
'resources' => [
'appointments' => ['view' => true, 'create' => true, 'cancel' => false, 'update_status' => true],
'addresses' => ['view' => true, 'create' => false, 'update' => false, 'delete' => false],
'clinic_info' => ['view' => true, 'update' => false],
'insurances' => ['view' => true, 'create' => false, 'update' => false, 'delete' => false],
],
]
```
### نمونه UI Permissions checkbox matrix در Modal:
```
┌─────────────────────────────────────────────────────┐
│ دسترسی‌های منشی │
├──────────────┬───────┬────────┬────────┬────────────┤
│ بخش │ مشاهده│ ایجاد │ ویرایش │ حذف/لغو │
├──────────────┼───────┼────────┼────────┼────────────┤
│ نوبت‌ها │ ☑ │ ☑ │ ☑ │ ☐ │
│ آدرس‌ها │ ☑ │ ☐ │ ☐ │ ☐ │
│ اطلاعات کلینیک│ ☑ │ - │ ☐ │ - │
│ بیمه‌ها │ ☑ │ ☐ │ ☐ │ ☐ │
└──────────────┴───────┴────────┴────────┴────────────┘
```
### PATCH /api/v1/secretary/{uuid} با permissions:
```json
{
"permissions": {
"version": 1,
"resources": {
"appointments": {
"view": true,
"create": true,
"cancel": true,
"update_status": true
},
"addresses": {
"view": true,
"create": false,
"update": false,
"delete": false
}
}
}
}
```
## کدهای خطای جدید
| کد | پیام فارسی |
| ----------------------------- | ---------------------------------------- |
| `ERR_SECRETARY_LIMIT_REACHED` | سقف تعداد منشی پنل اشتراکی شما رسیده است |
## Response خطا (403)
```json
{
"success": false,
"errors": [
{
"code": "ERR_SECRETARY_LIMIT_REACHED",
"message": "سقف تعداد منشی پنل اشتراکی شما رسیده است. برای افزودن منشی بیشتر پنل را ارتقاء دهید."
}
]
}
```