# P1-FE — prescription component v2 (frontend)

Read `_COMMON.md` first. FE repo only. Backend is DONE (commit e6e9d85b6) — read these to learn the exact contract: `Modules/Clinic/app/Support/PrescriptionRules.php` (validation), `Http/Resources/PrescriptionResource.php` + `PrescriptionItemResource.php` (response), `Http/Controllers/DrugSearchController.php` (search rows `{source, id, name, name_ar, form, dosage_form_id, product_id, alert_note, presets[{form, ready_sentence, is_default}]}`), `Http/Controllers/PrescriptionController.php` (update/pdf/stopItem), routes in `Modules/Clinic/routes/api.php` (grep `drugs/search`, `prescriptions/{prescription}`). Settings: `clinic.pharmacy_source` (products|standalone_formulary) and `clinic.rx.item_model` (sentence|structured|both).

Design target: the Rx card of the approved prototype `../visit-shell-prototype.html` (screenshot it headless — see S1 brief for the helper) and `../design-visit-shell.md` §2.6 «الروشتة = دواء + جملة افتراضية» + `../legacy-obgy-options-analysis.md` (drug + default sentence + Duplicate).

## Do — `src/app/features/clinic/encounter/prescription/**` + `src/app/features/clinic/services/clinic-prescription.service.ts` (+ i18n keys)
1. One compact row per drug: drug name · form · the ready sentence (pre-filled from the default preset, editable inline) · duration/times · «⧉ تكرار» (Duplicate: clone the row with the next preset sentence or blank) · ×. When `clinic.rx.item_model` = structured or both, an expander shows dose / frequency (MedicationFrequency select) / duration / route (MedicationRoute 13 values) / PRN; sentence-only rows are valid.
2. «＋ إضافة دواء»: ONE search box on `GET /clinic/drugs/search?q=` (debounced) → picker list with presets per drug and the alert_note badge; replace the current double search (products + formulary) — remove the duplicate code path in the service.
3. Subject: a toggle «المريض / الزوج / آخر» (+ name for other) — shown only when the department clinical type is gyn_ob OR a company setting allows it (for now: always available, collapsed under «مكتوبة لـ»).
4. Edit before print: an issued (not printed) prescription opens editable and saves with `PUT /clinic/prescriptions/{id}`; printed/cancelled ones are read-only with a clear chip; signed encounter → read-only.
5. Print: «طباعة PDF» calls `GET /clinic/prescriptions/{id}/pdf?lang=ar|en` as a blob (through the app's HTTP client so X-Authorization is sent) and opens it in a new tab. Keep the existing browser print path too (label it «طباعة سريعة») — the server PDF's Arabic shaping is still pending.
6. Inpatient kind (encounter kind inpatient/day_case): times column instead of duration + «إيقاف» per active line (`POST …/items/{i}/stop`).
7. Keep the component's public inputs/outputs unchanged (the visit shell S1 and nutrition/dental hosts embed it). Read who embeds `app-clinic-prescription` first.
8. i18n: ar/en via small targeted edits (other agents edit the same files) — do NOT bump I18N_VERSION.

Verify: `npx ng build --base-href /app/` green. Report the screens/states you built and anything you couldn't reproduce from the prototype. You may consult a Fable agent (model "fable") once if the compact row layout needs a decision the prototype doesn't settle.

Out of scope: BE, visit-shell folder (S1), other panels.
