# الملف الطبي للمريض والمرفقات

كل المسارات هنا محمية (`Authorization: Bearer {token}`). Controllers:
`App\Http\Controllers\Api\V1\Clinic\{PatientProfileController,MedicalHistoryOptionController,PatientAttachmentController}`.

## GET v1/medical-history-options?type=condition|medication

قائمة الخيارات النشطة (الأمراض المزمنة/الأدوية) اللي بتتعرض كـ checkboxes في شاشة الملف
الطبي. `type` مطلوب و لازم يكون `condition` أو `medication` وإلا `422`.

```json
{
  "success": true, "code": "OK", "message": "تمت العملية بنجاح",
  "data": [
    { "id": 1, "type": "condition", "code": "hypertension", "name": "ضغط الدم" },
    { "id": 2, "type": "condition", "code": "diabetes", "name": "السكري" }
  ],
  "meta": {}, "errors": null
}
```

## GET v1/patient-profile/medical

الملف الطبي الحالي للمريض المسجّل دخوله. لو لسه مقدّمش الملف الطبي، `data` بترجع `{}`
(نفس اصطلاح "مفيش بيانات" الموحّد في [`00-api-response-format.md`](00-api-response-format.md)).

```json
{
  "success": true, "code": "OK", "message": "تمت العملية بنجاح",
  "data": {
    "date_of_birth": "1990-05-14", "gender": "female", "occupation": "Teacher",
    "medical_history": { "other": null, "hypertension": true, "diabetes": false },
    "surgical_history": { "had_surgery": false, "type": null, "date": null, "hospital": null, "notes": null },
    "medication_history": { "other": null, "notes": null },
    "allergy_type": null, "allergy_substance": null, "allergy_severity": null, "allergy_notes": null
  },
  "meta": {}, "errors": null
}
```

## PUT v1/patient-profile/medical

| الحقل | القواعد |
|---|---|
| `date_of_birth` | اختياري، تاريخ، قبل اليوم |
| `gender` | اختياري، `male` أو `female` |
| `occupation` | اختياري، نص، أقصى 150 حرف |
| `medical_history.other` | اختياري، نص، أقصى 500 حرف |
| `medical_history.{code}` | بوليان لكل خيار راجع من `medical-history-options?type=condition` |
| `surgical_history.had_surgery` | بوليان |
| `surgical_history.type/date/hospital/notes` | اختياري |
| `medication_history.other/notes` | اختياري |
| `medication_history.{code}` | بوليان لكل خيار راجع من `medical-history-options?type=medication` |
| `allergy_type` | اختياري، `drug`\|`food`\|`other` |
| `allergy_substance` | اختياري، نص، أقصى 255 حرف |
| `allergy_severity` | اختياري، `mild`\|`moderate`\|`severe` |
| `allergy_notes` | اختياري، نص، أقصى 1000 حرف |

بترجع نفس شكل `GET` أعلاه بعد التحديث (`200 OK`).

## GET v1/patient-attachments?category_id=&page=

مرفقات المريض (تحاليل/تقارير قديمة) — 15/صفحة، مفلترة حسب `category_id` لو اتبعت.

```json
{
  "success": true, "code": "OK", "message": "تمت العملية بنجاح",
  "data": [
    {
      "id": 4, "category": null, "label": "Old lab result",
      "file_url": "http://erp.local/uploads/clinic/patient-attachments/....pdf",
      "file_type": "file", "created_at": "2026-09-11T00:49:46+03:00"
    }
  ],
  "meta": { "pagination": { "current_page": 1, "per_page": 15, "total": 1, "last_page": 1 } },
  "errors": null
}
```

## POST v1/patient-attachments (multipart/form-data)

| الحقل | القواعد |
|---|---|
| `category_id` | اختياري، موجود في `clinic_medical_history_options` |
| `label` | اختياري، نص، أقصى 255 حرف |
| `file` | مطلوب، ملف، أقصى 10MB، الأنواع: `jpg,jpeg,png,webp,pdf,doc,docx` |

الرفع دائمًا ذاتي (المريض بيرفع لنفسه)، فمفيش `uploaded_by_admin_id`. بترجع العنصر
الجديد بنفس شكل عنصر القائمة أعلاه، بكود `201 CREATED`.
