Medication Service — Event Schemas
Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · Naming · 04 Event-driven
1. Envelope
All events use the platform EventEnvelope (CloudEvents v1.0). Subject pattern: medication.{aggregate}.{event}.v{N}.
2. Events Produced
| Subject | v | Retention | Aggregate | Trigger |
|---|---|---|---|---|
medication.prescription.drafted.v1 | 1 | 30d | Prescription | Draft created |
medication.prescription.signed.v1 | 1 | 2y | Prescription | Sign success |
medication.prescription.discontinued.v1 | 1 | 2y | Prescription | Discontinue |
medication.prescription.held.v1 | 1 | 90d | Prescription | Hold |
medication.prescription.resumed.v1 | 1 | 90d | Prescription | Resume |
medication.alert.overridden.v1 | 1 | 7y | AlertOverride | Override recorded |
medication.dispensing.completed.v1 | 1 | 7y | DispensingEvent | Dispense success |
medication.dispensing.partial.v1 | 1 | 7y | DispensingEvent | Partial dispense |
medication.dispensing.returned.v1 | 1 | 7y | DispensingEvent | Return |
medication.controlled_substance.dispensed.v1 | 1 | 10y | DispensingEvent | Schedule II–V dispense |
medication.administration.recorded.v1 | 1 | 2y | MAR | Admin event |
medication.reconciliation.completed.v1 | 1 | 2y | ReconciliationSession | Session complete |
medication.inventory.stock_received.v1 | 1 | 2y | StockItem | GRN |
medication.inventory.reorder_alert.v1 | 1 | 90d | StockItem | Below reorder point |
medication.inventory.expiry_alert.v1 | 1 | 90d | StockItem | Expiry horizon |
medication.inventory.recall_triggered.v1 | 1 | 7y | StockItem | Lot recalled |
medication.fulfillment.queued.v1 | 1 | 30d | Prescription | MR ingested from gateway |
Example — medication.prescription.signed.v1
{
"specversion": "1.0",
"type": "medication.prescription.signed.v1",
"source": "ghasi/medication-service",
"id": "evt_01HX...",
"time": "2026-04-17T09:12:31Z",
"tenantid": "ten_...",
"actorid": "usr_...",
"correlationid": "corr_...",
"data": {
"prescriptionId": "rx_01HX...",
"patientId": "pat_...",
"medicationCode": "RxNorm|197361",
"medicationDisplay": "Amoxicillin 500 MG Oral Capsule",
"dose": { "amount": 500, "unit": "mg" },
"route": "oral",
"frequency": "TID",
"durationDays": 7,
"quantity": 21,
"quantityUnit": "capsule",
"refillsAuthorized": 0,
"isControlled": false,
"signedAt": "2026-04-17T09:12:30Z",
"prescriberId": "usr_...",
"overrides": []
}
}
Example — medication.dispensing.completed.v1
{
"type": "medication.dispensing.completed.v1",
"data": {
"dispenseId": "dsp_...",
"prescriptionId": "rx_...",
"patientId": "pat_...",
"dispensedQuantity": 30,
"quantityUnit": "tablet",
"stockItemId": "stk_...",
"lotNumber": "LOT-2026-04",
"expiryDate": "2027-12-31",
"pharmacistId": "usr_...",
"counterSignId": null,
"isPartial": false,
"gatewayMedicationDispenseFhirId": "MedicationDispense/..."
}
}
3. Events Consumed
| Subject | Producer | Purpose |
|---|---|---|
orders.medication_request.activated.v1 | orders-service | Seed medication list on CPOE activation |
eprescribing.medication_request.created.v1 | ghasi-eprescribing-gateway-service | Inbound Rx from external prescriber |
eprescribing.medication_request.updated.v1 | ghasi-eprescribing-gateway-service | Updates to ingested Rx |
patient-chart.allergy.updated.v1 | patient-chart-service | Invalidate cached allergy checks |
tenant.formulary.updated.v1 | tenant-service | Reload formulary cache |
4. Legacy Event Mapping
| Legacy shorthand | Legacy subject | New subject |
|---|---|---|
med.order.created | MEDICATION.medication.prescribed | medication.prescription.drafted.v1 |
med.order.signed | MEDICATION.medication.signed | medication.prescription.signed.v1 |
med.order.discontinued | MEDICATION.medication.discontinued | medication.prescription.discontinued.v1 |
med.alert.overridden | MEDICATION.alert.overridden | medication.alert.overridden.v1 |
PHARMACY.dispensing.completed | same | medication.dispensing.completed.v1 |
PHARMACY.inventory.* | same | medication.inventory.*.v1 |
PHARMACY.controlled-substance.dispensed | same | medication.controlled_substance.dispensed.v1 |
Dual-publish window: M2 — both subjects emitted; consumers migrate. Legacy subjects retired in M3.
5. Dead-Letter Handling
- Failed consumer deliveries (inbound gateway events) → DLQ
medication.ingestion.dlqwith 5-retry policy (exponential backoff, max 2h). - Failed outbound publishes → outbox stays, OutboxRelay retries; oldest-event alert at 10min.