Clinical and operational boundary
AMCDR stores the patient’s clinical medication record: requests, dispense and administration events, allergies, adverse reactions, and observations, linked to EHRs, encounters, compositions, audit, and provenance.
MediServe / Medication Tracker is the medication product, formulary, stock, batch, expiry, facility inventory, and dispensing-operation authority. AMCDR must not maintain a second medication product master in standard deployments.
In the AMCDR platform shell, MediServe appears under Applications -> MediServe. That workspace opens the external MediServe surfaces while keeping the AMCDR clinical medication workspace, clinical safety checks, and audit trail separate and governed by roles.
What AMCDR stores
| Data | AMCDR role | Notes |
|---|---|---|
| MedicationRequest / prescription | Authoritative clinical order | References the external product code selected from MediServe. |
| MedicationDispense | Clinical dispense event and traceability link | Tracker decrements stock and returns ledger metadata. |
| MedicationAdministration | Clinical administration event | Tracker decrements ward/procedure stock when configured. |
| AllergyIntolerance / adverse reaction | Authoritative patient clinical safety record | Captured from templates/forms or FHIR ingest. |
| Clinical safety decision | Audit/provenance copy on the action | Decision payload is stored with lifecycle events for traceability. |
| Product identifier copied on an order | Reference only | This is not a product master record. |
Medication lifecycle model
AMCDR presents medication work as one clinical lifecycle, but each stage remains a separate versioned record or event. The shared medication_workflow_id links the order, pharmacy verification/dispense, administration, safety decisions, cancellation events, and audit timeline.
| Stage | Owner | Record pattern | Typical state |
|---|---|---|---|
| Order | AMCDR | openEHR-backed clinical order with order status history | ORDERED, ACTIVE, ON_HOLD, CANCELLED |
| Verification and dispense | MediServe with AMCDR clinical event link | Operational dispense event linked to AMCDR order and stock ledger response | PENDING_VERIFICATION, VERIFIED, PARTIALLY_DISPENSED, DISPENSED |
| Administration | AMCDR | openEHR composition or administration event linked to order and dispense context | SCHEDULED, ADMINISTERED, OMITTED, REFUSED |
| Safety and audit | AMCDR and Clinical Safety Sidecar | Decision, override, lifecycle event, provenance, and audit records | ALLOW, WARN, REQUIRE_OVERRIDE, BLOCK |
Cancellation never deletes prior clinical or pharmacy history. It creates a MedicationCancelled lifecycle event with reason, actor, role, timestamp, previous status, and reconciliation metadata. If stock has already been reserved or dispensed, MediServe must reconcile stock through its own pharmacy rules while AMCDR keeps the clinical cancellation visible in the medication timeline.
GET /medications/orders/{order_id}/lifecycle
GET /medications/lifecycles/{medication_workflow_id}
POST /medications/orders/{order_id}/cancel
POST /medications/mediserve/launch-token
Access, Swagger, and Postman
AMCDR is the parent session authority. Users open MediServe from the AMCDR Applications workspace; AMCDR validates the current session and role, then issues a short-lived MediServe launch token. The user does not need a separate MediServe login for standard platform use.
| Access path | How it works |
|---|---|
| Frontend | Open Applications > MediServe. AMCDR launches MediServe with a session token derived from the current AMCDR user. |
| Swagger | Open /api-docs/swagger?area=clinical-workflows after signing in. Try-it-out requests use the current AMCDR bearer session automatically. |
| OpenAPI JSON | Open /api-docs/openapi.json after signing in, or call /openapi.json with Authorization: Bearer or X-API-Key. |
| Postman | Import postman/AMCDR_Medication_Lifecycle.postman_collection.json and postman/AMCDR_Sandbox.postman_environment.json, then set access_token or run local password login. |
The launch token endpoint requires a pharmacist, medication operator, MediServe operator, MediServe admin, or platform administrator role. The token is short-lived and is only for MediServe UI/API access; it does not replace AMCDR audit, RBAC, or medication lifecycle records.
What MediServe owns
| Data | Source of truth | AMCDR use |
|---|---|---|
| Medication product list | MediServe / Medication Tracker | AMCDR searches on demand with GET /fhir/Medication?q=.... |
| Formulary status and restrictions | MediServe / Medication Tracker | Clinical safety service reads restriction hooks. |
| Batch, lot, expiry, stock quantity | MediServe / Medication Tracker | Dispense/admin events update tracker ledger. |
| Facility stock locations | MediServe / Medication Tracker | AMCDR sends location ids when known. |
Role and action model
| Role | Typical action | Audit relevance |
|---|---|---|
| Clinician | Prescribe, acknowledge warnings, record administrations. | Links user, patient, encounter, medication request, safety decision, and composition. |
| Pharmacist | Review safety decisions, dispense, reconcile product selections. | Links dispense event to stock ledger response and AMCDR audit. |
| MediServe operator | Maintain product, stock, batch, expiry, formulary, and dispensing ledger. | Audited in MediServe and referenced from AMCDR when clinical events use those products. |
| Clinical safety reviewer | Review overrides, blocked orders, allergies, and interaction decisions. | Audits clinical safety decision id, override id, reason code, and reviewer. |
| Platform admin | Configure MediServe endpoint, module state, role access, and audit policy. | Audits module changes and integration configuration changes. |
Clinical Safety Sidecar
The Clinical Safety Sidecar is a separate FastAPI service that evaluates medication safety before prescribing, dispensing, administering, renewing, stopping, cancelling, or substituting medication. Keeping it separate lets medication rules, override workflows, CDS Hooks, and CQL support evolve alongside the clinical repository.
POST /safety/check
POST /safety/override
GET /safety/decision/{decision_id}
GET /safety/patient/{patient_id}/alerts
GET /safety/rules
POST /safety/rules
POST /safety/rules/{rule_id}/deactivate
GET /safety/audit
GET /cds-services
POST /cds-services/order-sign
POST /cds-services/medication-prescribe
POST /cds-services/medication-dispense
AMCDR CDS proxy:
GET /cds/safety/status
GET /cds/safety/rules
POST /cds/safety/check
The service has a persistent decision, override, rule, and audit store. It seeds default guardrails and loads environment-specific rules from a JSON file at startup. Production clinical content must be governed nationally or locally: each rule requires a clinical owner, version, publication status, review date, and test cases before it is enabled in a live environment.
| Safety area | How it is evaluated |
|---|---|
| Allergy and adverse reaction | Matches requested medication codes, ingredients, classes, RxNorm, ATC, SNOMED CT, and local codes against current effective AMCDR AllergyIntolerance/reaction records. Refuted, inactive, resolved, or entered-in-error allergy history is sent as context, not as a blocking fact. |
| Drug-drug interaction | Compares requested medication tokens with current effective MedicationRequest, MedicationStatement, and MedicationAdministration context. |
| Drug-condition and renal rules | Uses current effective Condition records and lab Observation values such as eGFR. Historical conditions remain available for audit and explanation. |
| Pregnancy and age restrictions | Uses the current pregnancy episode state, explicit pregnancy status, active pregnancy conditions, and age derived from demographics where available. Completed pregnancy episodes remain historical context. |
| Dose range | Uses daily dose fields or dose multiplied by frequency per day. |
| Formulary hooks | Uses MediServe / Medication Tracker formulary and interaction metadata when supplied with the selected product. |
The sidecar returns one of these decisions:
The AMCDR-facing contract includes decision, severity, reasons, matched_rules, recommended_action, override_requirements, audit_payload, and the checkpoint that was evaluated.
| Decision | Meaning | AMCDR behavior |
|---|---|---|
ALLOW | No configured issue detected. | Proceed. |
INFO | Informational result only. | Proceed and audit. |
WARN | Clinically relevant warning. | Show warning and audit. |
REQUIRE_OVERRIDE | Higher-risk issue requiring structured justification. | Reject until override acknowledgement/id is supplied. |
BLOCK | Action is not allowed by current policy. | Reject with MEDICATION_SAFETY_BLOCK. |
How AMCDR uses the sidecar
- Enable the sidecar in deployment configuration and start the
clinical-safety-sidecarservice with AMCDR. - Set
AMCDR_CLINICAL_SAFETY_ENABLED=trueand pointAMCDR_CLINICAL_SAFETY_BASE_URLto the sidecar, normallyhttp://clinical-safety-sidecar:8085inside Docker Compose. - Keep
AMCDR_MEDICATION_TRACKER_PRODUCT_CATALOG_MODE=externalso AMCDR searches MediServe / Medication Tracker for products instead of storing a second product master. - When a user creates or progresses a medication action, AMCDR builds a safety payload with patient, encounter, product, current allergy, active medication, active condition, observation, age, and effective pregnancy context.
- AMCDR calls
POST /safety/checkbefore saving the medication action. - If the sidecar returns
ALLOW,INFO, orWARN, AMCDR stores the medication action and attaches the safety decision to lifecycle audit. - If it returns
REQUIRE_OVERRIDE, AMCDR requires structured risk acknowledgement and submitsPOST /safety/overrideso the override is persisted and auditable in the sidecar. - If it returns
BLOCK, AMCDR stops the action and does not create the medication order, dispense, or administration event.
docker compose up -d clinical-safety-sidecar backend frontend
curl http://127.0.0.1:18085/health
curl -X POST http://127.0.0.1:18085/safety/check \
-H "Content-Type: application/json" \
-H "X-API-Key: ${CLINICAL_SAFETY_API_KEY}" \
-d '{"patient_id":"patient-1","action":"prescribe","requested_medication":{"display":"Warfarin"},"requesting_user":{"user_id":"clinician"},"context":{"active_medications":[{"medicationCodeableConcept":{"text":"Ibuprofen"}}]}}'
Safety check request
{
"patient_id": "patient-uuid",
"encounter_id": "encounter-uuid",
"action": "prescribe",
"requested_medication": {
"product_code": "GTIN-PARA-500",
"display": "Paracetamol 500 mg tablet",
"rxnorm_code": "198440",
"atc_code": "N02BE01",
"active_ingredients": ["paracetamol"]
},
"requesting_user": {
"user_id": "clinician"
},
"context": {
"current_allergies": [],
"allergy_history": [],
"active_medications": [],
"condition_history": [],
"pregnancy_status": "not_pregnant",
"pregnancy_episode_active": false
}
}
AMCDR builds this payload from the selected tracker product, the medication order, patient context, current AllergyIntolerance records, active medication history, active conditions, and effective pregnancy state. For dispense or administration, AMCDR resolves the original order so the same product context is checked even if the dispense form only contains quantity and batch details.
Rule administration
Medication safety rules are versioned JSON definitions. The sidecar ships with example guardrails for high-risk interaction, pregnancy, age, renal, and dose scenarios. Add or replace rules through POST /safety/rules, list current rules through GET /safety/rules, and retire a rule through POST /safety/rules/{rule_id}/deactivate. Deactivation is used instead of deletion so historical safety decisions remain explainable.
{
"rule_id": "interaction.warfarin.nsaid",
"rule_type": "interaction",
"version": "1.0.0",
"status": "active",
"severity": "major",
"decision": "REQUIRE_OVERRIDE",
"source_tokens": ["warfarin"],
"target_tokens": ["ibuprofen", "naproxen", "diclofenac", "nsaid"],
"explanation": "Warfarin with NSAIDs can increase bleeding risk.",
"recommended_action": "Use an alternative analgesic or document a structured override."
}
Supported rule families are interaction, contraindication, pregnancy, age, dose_range, renal, lab, and formulary.
Allergies and reactions
Known allergies and adverse reactions belong to the AMCDR clinical record. They must be captured through openEHR templates/forms or FHIR AllergyIntolerance ingest. The sidecar reads those records and compares them with the requested medication product, active ingredients, ingredient class, RxNorm, ATC, SNOMED CT, and local mappings.
Allergy history must not be deleted. If an allergy is refuted or no longer clinically active, mark it with the correct clinical and verification status. AMCDR sends active allergies as current_allergies and sends inactive, resolved, refuted, or entered-in-error records as allergy_history. The sidecar may return an informational issue for historical context, but it must not block solely on a refuted or inactive record.
When a reaction occurs after administration, document the reaction as an openEHR composition and, when clinically appropriate, create or update an AllergyIntolerance record with the correct verification status. The reaction must link to the MedicationAdministration, MedicationRequest, encounter, patient, composition, audit event, and provenance.
Pregnancy and changing clinical state
Pregnancy is evaluated as an effective state over time. Delivery, miscarriage, termination, or clinical review must close the active pregnancy episode instead of deleting the old record. AMCDR sends pregnancy_status, pregnancy_episode_active, and pregnancy_history so current pregnancy rules do not fire because of a completed historical episode.
Prescribing flow
- Clinician selects a patient and searches MediServe / Medication Tracker for the medication product.
- AMCDR keeps only the product reference fields needed for the clinical order and audit trail: product code, display, terminology codes, unit, source, and patient/order context.
- AMCDR does not store the full MediServe product master row. Current product, formulary, batch, expiry, and stock details are pulled from MediServe on demand.
- Before order creation, AMCDR calls
POST /safety/checkwith actionprescribe. - If allowed, AMCDR stores the MedicationRequest/order and lifecycle audit event.
- If configured, AMCDR mirrors the prescription to Medication Tracker as
MedicationRequest.
Dispensing and administration flow
- Pharmacy or ward user selects an existing AMCDR medication order.
- AMCDR resolves the selected order and sends medication context to the safety sidecar.
- For a completed dispense, AMCDR posts
MedicationDispenseto the tracker so stock decreases. - For bedside or ward administration, AMCDR posts
MedicationAdministrationwhendecrement_on_administrationis enabled. - AMCDR records the tracker response and audit/provenance metadata on the clinical event.
Configuration
| Setting | Purpose |
|---|---|
AMCDR_MEDICATION_TRACKER_ENABLED | Enables AMCDR calls to MediServe / Medication Tracker. |
AMCDR_MEDICATION_TRACKER_BASE_URL_CONTAINER | Container-facing base URL. In the integrated compose stack this is http://mediserve-nginx. |
AMCDR_MEDICATION_TRACKER_PUBLIC_URL | Browser-facing URL for opening MediServe from AMCDR, for example http://localhost:8088 locally. |
AMCDR_MEDICATION_TRACKER_PRODUCT_CATALOG_MODE=external | Prevents AMCDR from listing or writing local medication product master records. |
AMCDR_MEDICATION_TRACKER_ALLOW_LOCAL_PRODUCT_CATALOG_WRITES=false | Rejects local product-source/formulary writes. |
AMCDR_MEDICATION_TRACKER_SEND_PRESCRIPTIONS | Mirrors AMCDR medication orders to the tracker. |
AMCDR_MEDICATION_TRACKER_DECREMENT_ON_DISPENSE | Posts dispense events to tracker stock ledger. |
AMCDR_MEDICATION_TRACKER_DECREMENT_ON_ADMINISTRATION | Posts administration events to tracker stock ledger. |
AMCDR_CLINICAL_SAFETY_ENABLED | Enables AMCDR medication safety calls. |
AMCDR_CLINICAL_SAFETY_BASE_URL | Sidecar URL, for example http://clinical-safety-sidecar:8085. |
AMCDR_CLINICAL_SAFETY_FAIL_MODE | warn continues if the sidecar is unavailable; error fails closed. |
CLINICAL_SAFETY_API_KEY | Enforces API-key protection on sidecar safety and CDS endpoints. |
CLINICAL_SAFETY_DATABASE_URL | PostgreSQL URL for persisted decisions, overrides, rules, and sidecar audit rows in namespaced clinical_safety_* tables. |
CLINICAL_SAFETY_RULES_PATH | Optional JSON file containing production rule definitions to load at startup. |
CLINICAL_SAFETY_SEED_DEFAULT_RULES | Controls whether built-in starter guardrails are seeded when the rule table is empty. |
Audit expectations
Each medication order, dispense, administration, safety decision, safety override, rule change, and tracker synchronization must create traceable audit metadata. For production, keep AMCDR audit retention, sidecar audit retention, and tracker ledger retention aligned so each stock movement remains traceable to the patient context, order, performer, facility/location, safety rule version, and clinical decision that caused it.
Implementation checklist
- Enable Medication Tracker integration and verify
/medications/tracker/products/search. - Set medication product source mode to
external. - Enable Clinical Safety Sidecar in environments where medication ordering is used.
- Configure allergy/adverse reaction templates and FHIR ingest mappings.
- Load governed medication safety rules and confirm rule versions in
GET /safety/rules. - Confirm tracker stock decreases on dispense and/or administration according to policy.
- Test an allergy match, a warning, an override-required scenario, and a blocked scenario.