# P1-BE2 — formulary support in the remaining drug readers/writers

Read `_COMMON.md` first. No migration. P1-BE (commit e6e9d85b6) made prescription items carry EITHER `drug_id` (Core product) OR `clinic_drug_id` (clinic formulary) per `Modules\Clinic\Support\PharmacySource`, and `ClinicDrugAlert::notesFor($companyId, $ids, $key = 'drug_id'|'clinic_drug_id')`. Three places still assume products only:

1. `Modules/Clinic/app/Http/Controllers/DrugAlertController.php` `update` (and its request): accept a formulary drug — body or route identifies `clinic_drug_id` (validate it belongs to the company) vs `drug_id` (product); upsert on the right key with `updateOrCreate` (the DB unique can't block NULL duplicates on MySQL — app-level uniqueness). Keep the product path unchanged.
2. `Modules/Clinic/app/Http/Controllers/DrugPresetController.php` `mostUsed` / `repeatLast`: group by `COALESCE(drug_id, clinic_drug_id)` with a `source` discriminator (products|formulary) so formulary items count; responses carry `source` + the right id + `drug_name` snapshot.
3. `Modules/Nutrition/app/Services/Visit/PatientMedicationsService.php` (~line 45): pass both id sets to `notesFor` so formulary alerts show.

Tests: `Modules/Clinic/tests/Feature/P1Be2FormularyTest.php` — formulary alert write+read via the API; mostUsed counts formulary items; repeatLast returns a formulary item with source; nutrition medications show a formulary alert. Run also `ClinicDrugAlertTest.php`, `DrugPresetTest.php`, `P1PrescriptionV2Test.php`, `NutritionMedicationsCancelledRxTest.php`, `NutritionVisitRecordTest.php` — keep green.

Out of scope: routes (none needed — if one is, report it), prescriptions/IssuePrescription, FE.
