# Report 1 — prescriptions & medication (Explore agent, 2026-10-21)
BE = /home/moonui3/moon-erp-be/Modules, FE = /home/moonui3/public_html/moon-erp/src/app

3 separate implementations: Clinic Rx (Nutrition + Dental reuse it), Hospital MAR, WebStore uploaded Rx. Core drug catalog underneath Clinic. No Rx in NPHIES/LIS/POS/Sales/Inventory/Dental BE.

## 1. Clinic prescription
- prescriptions: company/branch, prescription_number, encounter_id NOT NULL, patient_id, doctor_id, issued_at, status (issued), notes, softDeletes (Clinic migration 2026_06_22_180001; 2026_10_12_180000 adds cancel_reason/by/at).
- prescription_items: drug_id NOT NULL → products.id, dose/frequency/duration string(100) required, route (MedicationRoute enum 10 values), instructions. NO form column (…180002).
- Models Clinic/app/Models/Prescription.php (patient = LabPatient, doctor = LabDoctor :86-95), PrescriptionItem.php; BaseModel (Auditable, TenantAware).
- Attached to Clinic Encounter only. NO subject/husband column. Spouse only as profile questions ClinicProfilePacks.php:80-82.
- Drug source: requires company products row (IssuePrescription.php:51-55, StorePrescriptionRequest.php:33-36). Second catalog clinic_drugs (category, active_ingredient, drug_name, form, use_note, product_id; 2026_07_28_100000/110000). ResolveDrugProduct.php:46-70 firstOrCreates Core product (is_drug=true, track_inventory=false). FE searches catalog then core/products?is_drug=1 (clinic-prescription.service.ts:201-228). Setting clinic.pharmacy_source (products|standalone_formulary) NOT read anywhere.
- Speed: clinic_drug_presets (product/drug_name, form, ready_sentence, is_default; DrugPresetController); clinic_favorites polymorphic per user type drug; most-used top 15 per doctor (DrugPresetController.php:232); repeat-last (:187); clinic_drug_alerts one note per product (2026_10_09_110000). Preset apply writes "—" into dose/frequency/duration, form into dose, sentence into instructions (prescription.component.ts:87,595-597); print blanks "—" (clinic-prescription.service.ts:295-305) → structured fields hold the sentence model in disguise.
- Lifecycle issued→printed→cancelled; dispensed reserved/unreachable. GET /print returns JSON, sets printed, 422 if cancelled (PrescriptionController.php:75-114); FE builds HTML; no BE PDF. Cancel: prescriber or owner/clinic.settings.manage, blocked if dispensed (:127-171). BE does NOT check encounter lock/sign on store (FE [locked] only). No update endpoint. PrescriptionIssued no listeners. No dispensing/inventory/POS/billing link.
- Routes api.clinic.*: encounters.prescriptions.index/store, prescriptions.print/cancel (:510-514); drug-presets.index/store/most-used, prescriptions.repeat-last (:524-527); drugs.* + drugs.resolve-product (:224-232); drug-alerts (:236-237); favorites (:470-472).
- FE: features/clinic/encounter/prescription/prescription.component.ts (1027 lines), hosted in consultation.html:278 (general), :440 (dental_consult), nutrition-consult-board.html:650 (dialog), clinic-patient-visits-page.html:308. Admin clinic/medications/clinic-medications.component.ts. Readers: visit summary print, VisitHistoryService.php:50, PatientReadService.php:189 (current meds), AppointmentReadiness.php:118.
- Permissions clinic.prescriptions.view/create/print (ClinicPermissionDependencies.php:85-86); catalog clinic.service.view/manage.

## 2. Nutrition — reuse. PatientMedicationsService.php:36-70 reads Clinic Prescription (last 10) + ClinicDrugAlert. DispensedItemsService shows sales/POS lines + inventory issues for linked partner (display only). No supplement entity.
## 3. Dental — no Rx tables; reuses Clinic component in dental_consult. on_medication history question only.
## 4. Hospital MAR — parallel. hospital_med_orders: admission_id, drug FREE STRING, dose, route (own list NursingService::ROUTES :30 ≠ Clinic enum), frequency code (FREQ od/bid/…/prn/stat → times :24), times json, prn, starts/ends, status active/stopped, product_id, warehouse_id, unit_price, charge_per_dose, ordered_by. hospital_med_admins: slot, given/held/refused, service_order_line_id. Given dose charged to folio; stock via ConsumptionService::issue nested inside charge condition (NursingService.php:129-135); FE nursing panel sends no product/warehouse → never issues stock. No link to Clinic Rx. Discharge = free text discharge_instructions; no discharge meds. Routes api.hospital.nursing.orders.store/stop/administer. Surgery items kind medication (billing only); packages medication_limit.
## 5. WebStore — store_prescriptions: customer, image, note, review status pending/approved/rejected; no items, no link to orders/Clinic.
## 6. Core catalog — products.is_drug; product_drug_details (dosage_form_id, strength, is_prescription, is_controlled, atc_code); active_ingredients; dosage_forms; product_active_ingredient. Clinic Rx never uses dosage_form_id. POS settings pharmacy.dispensing_enabled/allow_partial_dispense/prescription_validity_days/require_prescription_rx = "feature still to be built" (only a test reads them).
## 7. KB decisions — gyna-reference.md:57-79 8-point Rx contract (pick don't type; drug→form→ready sentence cascade with is_default; auto-add next row; autosave, print only action; per-doctor favorites/most-used; repeat-last; inline add missing drug; clinic print format + per-doctor signature; husband subject toggle on same order :114). clinic-principles.md:29-35,62: two models (a) linked to purchases/inventory with dispensing separate in Sales, (b) standalone drug DB; dispensing never in doctor's screen. his.md:87,137. clinic-execution-phases.md:96,114 (م7 fast Rx, م8 print settings).

Gaps: two disconnected medication models (vocab differs); three drug lists, form free text, dosage_forms unused; sentence stored as "—"; no subject; no BE lock enforcement/no edit; pharmacy_source + POS dispensing inert, dispensed unreachable; MAR stock issue gated on charge, UI sends no product/warehouse; no BE PDF, no discharge Rx, WebStore Rx image-only.
