Clinical Use

Medication Products and Clinical Safety

How AMCDR works with MediServe / Medication Tracker, allergies, interactions, stock movement, audit, and safety decisions.

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.

Medication responsibility boundary
AMCDRClinical record, allergy, orders, audit
->
Clinical Safety SidecarAllergy and interaction decision
->
MediServe / TrackerProducts, formulary, stock, batch
->
AMy-TermRxNorm, ATC, SNOMED CT, local maps

What AMCDR stores

DataAMCDR roleNotes
MedicationRequest / prescriptionAuthoritative clinical orderReferences the external product code selected from MediServe.
MedicationDispenseClinical dispense event and traceability linkTracker decrements stock and returns ledger metadata.
MedicationAdministrationClinical administration eventTracker decrements ward/procedure stock when configured.
AllergyIntolerance / adverse reactionAuthoritative patient clinical safety recordCaptured from templates/forms or FHIR ingest.
Clinical safety decisionAudit/provenance copy on the actionDecision payload is stored with lifecycle events for traceability.
Product identifier copied on an orderReference onlyThis 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.

StageOwnerRecord patternTypical state
OrderAMCDRopenEHR-backed clinical order with order status historyORDERED, ACTIVE, ON_HOLD, CANCELLED
Verification and dispenseMediServe with AMCDR clinical event linkOperational dispense event linked to AMCDR order and stock ledger responsePENDING_VERIFICATION, VERIFIED, PARTIALLY_DISPENSED, DISPENSED
AdministrationAMCDRopenEHR composition or administration event linked to order and dispense contextSCHEDULED, ADMINISTERED, OMITTED, REFUSED
Safety and auditAMCDR and Clinical Safety SidecarDecision, override, lifecycle event, provenance, and audit recordsALLOW, 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 pathHow it works
FrontendOpen Applications > MediServe. AMCDR launches MediServe with a session token derived from the current AMCDR user.
SwaggerOpen /api-docs/swagger?area=clinical-workflows after signing in. Try-it-out requests use the current AMCDR bearer session automatically.
OpenAPI JSONOpen /api-docs/openapi.json after signing in, or call /openapi.json with Authorization: Bearer or X-API-Key.
PostmanImport 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

DataSource of truthAMCDR use
Medication product listMediServe / Medication TrackerAMCDR searches on demand with GET /fhir/Medication?q=....
Formulary status and restrictionsMediServe / Medication TrackerClinical safety service reads restriction hooks.
Batch, lot, expiry, stock quantityMediServe / Medication TrackerDispense/admin events update tracker ledger.
Facility stock locationsMediServe / Medication TrackerAMCDR sends location ids when known.

Role and action model

RoleTypical actionAudit relevance
ClinicianPrescribe, acknowledge warnings, record administrations.Links user, patient, encounter, medication request, safety decision, and composition.
PharmacistReview safety decisions, dispense, reconcile product selections.Links dispense event to stock ledger response and AMCDR audit.
MediServe operatorMaintain product, stock, batch, expiry, formulary, and dispensing ledger.Audited in MediServe and referenced from AMCDR when clinical events use those products.
Clinical safety reviewerReview overrides, blocked orders, allergies, and interaction decisions.Audits clinical safety decision id, override id, reason code, and reviewer.
Platform adminConfigure 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 areaHow it is evaluated
Allergy and adverse reactionMatches 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 interactionCompares requested medication tokens with current effective MedicationRequest, MedicationStatement, and MedicationAdministration context.
Drug-condition and renal rulesUses current effective Condition records and lab Observation values such as eGFR. Historical conditions remain available for audit and explanation.
Pregnancy and age restrictionsUses 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 rangeUses daily dose fields or dose multiplied by frequency per day.
Formulary hooksUses 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.

DecisionMeaningAMCDR behavior
ALLOWNo configured issue detected.Proceed.
INFOInformational result only.Proceed and audit.
WARNClinically relevant warning.Show warning and audit.
REQUIRE_OVERRIDEHigher-risk issue requiring structured justification.Reject until override acknowledgement/id is supplied.
BLOCKAction is not allowed by current policy.Reject with MEDICATION_SAFETY_BLOCK.

How AMCDR uses the sidecar

  1. Enable the sidecar in deployment configuration and start the clinical-safety-sidecar service with AMCDR.
  2. Set AMCDR_CLINICAL_SAFETY_ENABLED=true and point AMCDR_CLINICAL_SAFETY_BASE_URL to the sidecar, normally http://clinical-safety-sidecar:8085 inside Docker Compose.
  3. Keep AMCDR_MEDICATION_TRACKER_PRODUCT_CATALOG_MODE=external so AMCDR searches MediServe / Medication Tracker for products instead of storing a second product master.
  4. 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.
  5. AMCDR calls POST /safety/check before saving the medication action.
  6. If the sidecar returns ALLOW, INFO, or WARN, AMCDR stores the medication action and attaches the safety decision to lifecycle audit.
  7. If it returns REQUIRE_OVERRIDE, AMCDR requires structured risk acknowledgement and submits POST /safety/override so the override is persisted and auditable in the sidecar.
  8. 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

  1. Clinician selects a patient and searches MediServe / Medication Tracker for the medication product.
  2. 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.
  3. AMCDR does not store the full MediServe product master row. Current product, formulary, batch, expiry, and stock details are pulled from MediServe on demand.
  4. Before order creation, AMCDR calls POST /safety/check with action prescribe.
  5. If allowed, AMCDR stores the MedicationRequest/order and lifecycle audit event.
  6. If configured, AMCDR mirrors the prescription to Medication Tracker as MedicationRequest.

Dispensing and administration flow

  1. Pharmacy or ward user selects an existing AMCDR medication order.
  2. AMCDR resolves the selected order and sends medication context to the safety sidecar.
  3. For a completed dispense, AMCDR posts MedicationDispense to the tracker so stock decreases.
  4. For bedside or ward administration, AMCDR posts MedicationAdministration when decrement_on_administration is enabled.
  5. AMCDR records the tracker response and audit/provenance metadata on the clinical event.

Configuration

SettingPurpose
AMCDR_MEDICATION_TRACKER_ENABLEDEnables AMCDR calls to MediServe / Medication Tracker.
AMCDR_MEDICATION_TRACKER_BASE_URL_CONTAINERContainer-facing base URL. In the integrated compose stack this is http://mediserve-nginx.
AMCDR_MEDICATION_TRACKER_PUBLIC_URLBrowser-facing URL for opening MediServe from AMCDR, for example http://localhost:8088 locally.
AMCDR_MEDICATION_TRACKER_PRODUCT_CATALOG_MODE=externalPrevents AMCDR from listing or writing local medication product master records.
AMCDR_MEDICATION_TRACKER_ALLOW_LOCAL_PRODUCT_CATALOG_WRITES=falseRejects local product-source/formulary writes.
AMCDR_MEDICATION_TRACKER_SEND_PRESCRIPTIONSMirrors AMCDR medication orders to the tracker.
AMCDR_MEDICATION_TRACKER_DECREMENT_ON_DISPENSEPosts dispense events to tracker stock ledger.
AMCDR_MEDICATION_TRACKER_DECREMENT_ON_ADMINISTRATIONPosts administration events to tracker stock ledger.
AMCDR_CLINICAL_SAFETY_ENABLEDEnables AMCDR medication safety calls.
AMCDR_CLINICAL_SAFETY_BASE_URLSidecar URL, for example http://clinical-safety-sidecar:8085.
AMCDR_CLINICAL_SAFETY_FAIL_MODEwarn continues if the sidecar is unavailable; error fails closed.
CLINICAL_SAFETY_API_KEYEnforces API-key protection on sidecar safety and CDS endpoints.
CLINICAL_SAFETY_DATABASE_URLPostgreSQL URL for persisted decisions, overrides, rules, and sidecar audit rows in namespaced clinical_safety_* tables.
CLINICAL_SAFETY_RULES_PATHOptional JSON file containing production rule definitions to load at startup.
CLINICAL_SAFETY_SEED_DEFAULT_RULESControls 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