Skip to main content

Medication Service — Service Overview

Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · 03 platform-services · 02 DDD · FHIR-first

1. Purpose

The medication-service is the platform's canonical owner of medication knowledge, longitudinal medication lists, prescribing workflows, pharmacy fulfillment, dispensing, inventory, and medication administration (MAR). It provides the clinical meaning for every medication-related FHIR resource except the national interop copies of MedicationRequest / MedicationDispense that are mediated by the ghasi-eprescribing-gateway-service.

The service spans two historically separate modules:

Source moduleContribution
medication-managementLongitudinal med list, prescribe-time safety checks (drug-drug, drug-allergy, drug-condition, duplicate therapy), reconciliation, MAR, signing, dose calculation.
pharmacyFulfillment plane: dispensing queues, verification, inventory (lot/expiry/recall), pharmacy portal, external adapter hooks (NCPDP SCRIPT optional), controlled-substance dispense counter-sign.

2. Bounded Context

Medication Domain — classified as Core. Pharmaceutical safety is a differentiating clinical capability; medication-related data is the largest source of preventable adverse events in hospital care.

3. Responsibilities

AreaWhat medication-service Owns
Medication listLongitudinal list per patient: active / on-hold / discontinued / completed / proposed; sources: prescribed, patient-reported, history, facility-administered.
PrescribingDrafting, dose/sig/route/frequency structuring, formulary lookup, signing, renewal, refill, substitution (DAW), discontinue, hold/resume.
Safety checksAllergy checks (vs allergies in patient-chart-service), drug-drug interactions, drug-condition, duplicate therapy, dose range validation. Uses configurable knowledge-base adapter.
ReconciliationAdmission, transfer, discharge, outpatient reconciliation sessions with side-by-side diff + actions.
Administration (MAR)MedicationAdministration events: given / held / refused / not-available; timing, route actual, administered-by.
Fulfillment queueProjection of gateway MedicationRequest into pharmacy work items; verification; print labels; PDF prescription output.
DispensingMedicationDispense writes, atomic inventory decrement, partial dispense, returns, emergency override with reason.
InventoryStock items per facility node: NDC/local code, lot, expiry, supplier, quantity-on-hand, reorder points, recalls, valuation.
Pharmacy portalStandalone offline-first portal for pharmacists and technicians; separate from clinical shell.
Controlled substancesCounter-sign at dispense, enhanced audit, disclosure accounting. Prescribe-time CS rules delegated to Access-Policy / tenant-service.
Alerts & overridesBlocking + non-blocking alerts; override record with reason (≥10 chars), drug-KB snapshot version, actor.

4. Non-Responsibilities

AreaOwnerWhy not medication-service
National interop MedicationRequest / MedicationDispense SoTghasi-eprescribing-gateway-serviceCross-tenant / cross-org routing and validation is a gateway-level concern; this service authors the clinical intent, gateway persists the interop copy.
CPOE order lifecycle for medicationorders-serviceOrders-service owns the general CPOE ServiceRequest / order lifecycle; it produces MedicationRequest on activation and delegates safety checks here.
Allergies storagepatient-chart-servicemedication-service reads AllergyIntolerance via FHIR; it does not own the allergy record.
Conditions / problem listpatient-chart-serviceDrug-condition checks read Condition; they are not written here.
Terminology (RxNorm, ATC, NDC)terminology-servicemedication-service references codes; terminology-service owns valuesets and expansion.
Billing charge generationbilling-servicemedication-service emits a dispense event; billing-service turns it into ChargeItem.
Notifications (SMS/email on ready-for-pickup)communication-servicemedication-service emits events; communication-service delivers.

5. Dependencies

5.1 Upstream

DependencyPatternPurpose
orders-serviceEvent consumer + FHIR readConsumes orders.medication_request.activated.v1 to create medication-list entries and fulfillment rows.
patient-chart-serviceFHIR readAllergy, problem-list, vitals for safety checks.
terminology-serviceRESTCode lookup, valueset expansion for sig/route/frequency.
ghasi-eprescribing-gateway-serviceEvent consumer + FHIR readIngests eprescribing.medication_request.created.v1 for cross-tenant Rx arriving from external prescribers.
identity-serviceJWTAuthN; prescriber / pharmacist roles via tenant-service role claims.
tenant-serviceRESTAccess-Policy for controlled substances, formulary configuration per tenant.

5.2 Downstream

ConsumerPatternPurpose
ghasi-eprescribing-gateway-serviceHTTP POSTPosts MedicationDispense to gateway for national interop; posts MedicationRequest when prescribing for external pharmacies.
billing-serviceEvent consumerCharges on medication.dispensing.completed.v1.
communication-serviceEvent consumerReady-for-pickup, refill reminder notifications.
patient-chart-serviceEvent consumerMedication-list projection for chart summary.
audit-serviceEvent consumerImmutable audit of every prescribe/sign/dispense/override.
population-health-serviceEvent consumerMedication adherence metrics, controlled-substance surveillance.

6. Slice Involvement

SliceScopeMilestone
S1 — Core ClinicalMed list, prescribe + sign, allergy + interaction checks, MAR basicM1
S2 — FulfillmentPharmacy queue ingestion, dispensing, inventory lot/expiry, reconciliation sessionsM2
S3 — AdvancedControlled substances counter-sign, offline pharmacy portal, recalls, NCPDP optional adapterM3
S4 — EnterpriseFull IG profile validation, analyzer-grade KB, dose-calc for pediatrics/renal, MoPH controlled-substance reportingM4

7. Architectural Decisions

  1. Single service merges prescribe + fulfill to keep the longitudinal medication graph intact (prescriber intent, dispense events, administrations) and to preserve referential integrity at the DB layer. Both sub-domains share a common Medication reference table.
  2. Gateway is authoritative for interop copies. Local prescriptions is a fulfillment projection keyed by gateway_medication_request_fhir_id. Clinical chart writes happen locally; interop writes post to the gateway.
  3. Pharmacy portal is a separate Next.js surface under the same service, not a separate service. Rationale: shared domain model + RLS + same deployment cadence; different shell app only.
  4. Drug knowledge base behind a port. DrugKnowledgeBase port has adapters for: local formulary + terminology-service, external licensed DB (e.g. First Databank), WHO EML baseline. Alerts include KB-snapshot-version in the override record.
  5. Inventory decrement is transactional with dispense. Single SQL transaction updates dispensing_events, decrements stock_items.quantity_on_hand, writes outbox entry. No saga; rollback on any failure.
  6. Controlled-substance dispense requires counter-sign — a different actor than the dispenser. Schedule II always; Schedule III–V by tenant policy.

8. Architecture Diagram

9. Source Reconciliation

medication-management and pharmacy source modules merged using these decisions:

QuestionDecision
Single or split aggregate for prescription vs dispense?Single domain, two aggregates (Prescription, DispensingEvent) with shared Medication VO.
Where does MedicationAdministration live?Here (MAR), consumed by patient-chart-service for chart display.
Prescribe-time alert overridesRecorded here with KB snapshot; delegated to medication-management aggregate.
Dispense-time controlsOwn aggregate DispensingEvent with inventory transaction + counter-sign invariant.
FR-ID prefix harmonizationBoth FR-MEDS-* and FR-PHARM-* legacy refs preserved with new prefix FR-MED-*.
EventsUnified under medication.* subject; legacy MEDICATION.* and PHARMACY.* documented as deprecated with dual-publish in M2.

10. Readiness Levels

LevelDescriptionTarget
L2Med list, prescribe, sign, alerts, MAR; basic dispensing queueM1
L3Inventory, reconciliation, recalls, controlled-substance dispenseM2
L4Offline pharmacy portal, NCPDP/HL7 adapters, full IG validation, chaos-testedM3+