Skip to content

Drug Safety

Drug Safety

DELPHOS performs drug-safety analysis at two distinct points in the prescription lifecycle:

  1. Streaming pipeline (pre-persistence, advisory). While the doctor dictates or types, the streaming endpoint runs a 6-gate pipeline in real time. Results stream alongside each extracted medication item. See Streaming Prescription Extraction for the SSE contract and gate-by-gate detail.
  2. Post-persistence safety check (blocking for critical interactions). Once a prescription is saved as a draft, the POST /v1/prescriptions/{id}/safety-check endpoint runs the three-tier cascading interaction lookup and stores results on the prescription record. Critical and contraindicated interactions must be acknowledged before the prescription can advance to signed.

This article covers the post-persistence safety check — the authoritative interaction store. For the real-time streamed gates, see the dedicated Streaming Prescription Extraction article.


The 6-Gate Streaming Pipeline (Pre-Persistence, Advisory)

Before a prescription is saved, the streaming extraction agent runs a 6-gate advisory pipeline. The gates are all advisory — even critical severity findings inform but do not block — per Lei 12.842/2013 and CFM Code of Ethics Articles 20-21.

GateName (canonical)ScopeBlocks streaming?
1Validação de Entrada (Input Validation)Per-itemOnly blocking gate (medication_name required)
2Resolução de Medicamento (CMED / ANVISA registry match)Per-itemAdvisory
3Interações Medicamentosas (drug-drug interactions)Cross-itemAdvisory
4Duplicidade Terapêutica (active ingredient + EPhMRA class)Cross-itemAdvisory
5Substâncias Controladas (Portaria 344/98 / RDC 20/2011)Per-itemAdvisory
6Cruzamento de Alergias (v1.1)Per-itemAdvisory (when shipped)

The streaming pipeline returns its results inline in the SSE stream (item_detected events carry gates 1, 2, 6; gates_complete carries gates 3, 4). They are diagnostic — to persist them, the doctor finalizes via POST /v1/prescriptions, after which the post-persistence safety check described below becomes the authoritative store.


Post-Persistence Safety Check

DELPHOS performs drug interaction analysis on prescription items using a three-tier cascading lookup. Results are attached to the prescription and must be reviewed — and critical interactions acknowledged — before a prescription can be signed.

Safety Check Endpoint

Run an on-demand interaction analysis on all items in a prescription. This operation is idempotent: any previously stored interactions are cleared and replaced with fresh results on each call.

POST /v1/prescriptions/{prescription_id}/safety-check

The prescription must not be in a terminal status (dispensed or cancelled).

Status codes

CodeMeaning
200Analysis complete — response contains interactions and summary
404Prescription not found
409Prescription is in a terminal status (dispensed or cancelled)
500Interaction service error
Terminal window
curl -X POST "https://your-instance.delphos.app/v1/prescriptions/PRESCRIPTION_ID/safety-check" \
-H "x-api-key: YOUR_API_KEY"

Response shape

{
"prescription_id": "a7b8c9d0-e1f2-3456-ab01-567890123456",
"interactions": [
{
"id": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
"drug_a": "VARFARINA SODICA",
"drug_b": "ASPIRINA",
"severity": "critical",
"interaction_type": "pharmacodynamic",
"description": "Increased bleeding risk due to combined anticoagulant effects",
"recommendation": "Avoid concomitant use; consider alternative analgesic",
"source": "tier1_matrix"
}
],
"safety_summary": {
"passed": false,
"critical_count": 1,
"contraindicated_count": 0,
"major_count": 0,
"moderate_count": 0,
"minor_count": 0
},
"items_checked": 3,
"ingredients_analyzed": ["VARFARINA SODICA", "ASPIRINA", "LOSARTANA POTASSICA"]
}

Response fields

InteractionResponse fields:

FieldTypeDescription
idUUID or nullUUID of the stored interaction record (null for unsaved results)
drug_astringFirst drug name in the interacting pair
drug_bstringSecond drug name in the interacting pair
severitystringSeverity level (see table below)
interaction_typestringPharmacological type, e.g. "pharmacodynamic"
descriptionstringHuman-readable description of the interaction
recommendationstringPrescriber guidance for managing the interaction
sourcestringWhich detection tier found this, e.g. "tier1_matrix"

Severity levels:

SeverityBlocks signingDescription
criticalYesPotentially life-threatening combination
contraindicatedYesCombination should never be used
majorNoSignificant risk; may require dose adjustment
moderateNoModerate risk; monitor closely
minorNoLow risk; usually manageable

Acknowledging Interactions

Before a prescription can be transitioned to signed, all critical and contraindicated interactions must be explicitly acknowledged by the prescribing physician.

Acknowledge a single interaction

PATCH /v1/prescriptions/{prescription_id}/interactions/{interaction_id}/acknowledge

Request body:

FieldTypeRequiredDescription
doctor_idUUIDYesUUID of the doctor acknowledging the interaction
Terminal window
curl -X PATCH "https://your-instance.delphos.app/v1/prescriptions/PRESCRIPTION_ID/interactions/INTERACTION_ID/acknowledge" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"doctor_id": "e5f6a7b8-c9d0-1234-efab-345678901234"}'

Returns 200 with the updated interaction record. Returns 404 if the prescription or interaction is not found, or if the interaction has already been acknowledged.

Acknowledge all interactions at once

POST /v1/prescriptions/{prescription_id}/interactions/acknowledge-all

Request body:

FieldTypeRequiredDescription
doctor_idUUIDYesUUID of the doctor acknowledging all interactions
Terminal window
curl -X POST "https://your-instance.delphos.app/v1/prescriptions/PRESCRIPTION_ID/interactions/acknowledge-all" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"doctor_id": "e5f6a7b8-c9d0-1234-efab-345678901234"}'

Returns 200 with { "acknowledged_count": N }. Returns 404 if the prescription is not found.


Checking Signing Readiness

After the safety check and acknowledgments, verify the prescription is ready to sign by fetching its detail:

GET /v1/prescriptions/{prescription_id}

The response includes:

FieldDescription
can_signtrue when no blocking interactions remain unacknowledged
blocking_interactions_countCount of unacknowledged critical/contraindicated interactions
pending_acknowledgements_countCount of all unacknowledged interactions (any severity)

When can_sign is true, the prescription can be transitioned to signed (see Creating Prescriptions).