Problem Statement
Clinicians routinely need to verify that a new prescription does not create dangerous drug interactions, contraindications, or dosing errors. A delay or omission can lead to medication errors that compromise patient safety. Documedic’s Drug Interaction feature aims to provide instant, evidence‑based recommendations as part of a larger Clinical Decision Support System (CDSS).
Architectural Overview
The feature is split into three layers:
- Data layer – PostgreSQL stores drug–drug interaction tables, drug properties, and patient‑specific contraindication flags.
- Service layer – FastAPI exposes a REST endpoint that accepts a patient profile, a list of prescribed drugs, and returns a structured JSON payload of interactions, contraindications, and dosing hints.
- Presentation layer – A React component renders the payload in a concise table, highlighting critical interactions and offering clickableഠ links to evidence sources.
The FastAPI service delegates the logical analysis to an AI reasoning engine. The engine is protected by authentication checks and safeguards, as detailed in recent commits.
Backend Implementation
A minimal FastAPI route shows how the service validates input, queries the database, and passes data to the reasoning engine:
from fastapi import FastAPI, Depends, HTTPException
from pydantic import BaseModel
from sqlalchemy.orm import Session
app = FastAPI()
class InteractionRequest(BaseModel):
patient_id: int
drugs: list[str]
@app.post("/interactions")
async def get_interactions(req: InteractionRequest, db: Session = Depends(get_db), user: User = Depends(auth)):
# Authentication guard – an unauthenticated request cannot consume memory
if not user.is_active:
raise HTTPException(status_code=401, detail="Unauthorized")
# Verify drugs exist in the catalog
catalog = db.query(Drug).filter(Drug.name.in_(req.drugs)).all()
if len(catalog) != len(req.drugs):
raise HTTPException(status_code=400, detail="Unknown drug(s) supplied")
# Delegate to reasoning engine (AI model)
results = reasoning_engine.evaluate(patient=req.patient_id, drugs=req.drugs)
return results
The routeંગ્ર uses a dependency‑injected auth guard that checks API key revocation, a fix introduced in commit 5e78ac7. The same guard also ensures that a revoked key does not report the engine as live.
Frontend Interaction
The React component fetches the endpoint and displays results in a user‑friendly table. A concise snippet illustrates the core logic:
import { useEffect, useState } from "react";
import axios from "axios";
interface Interaction { description: string; severity: string; evidence?: string; }
const InteractionTable = ({ patientId, drugs }: { patientId: number; drugs: string[]; }) => {
const [data, setData] = useState<Interaction[]>([]);
useEffect(() => {
axios.post('/interactions', { patient_id: patientId, drugs })
.then(res => setData(res.data))
.catch(err => console.error(err));
}, [patientId, drugs]);
return (
<table>
<thead>
<tr><th>Description</th><th>Severity</th></tr>
</thead>
<tbody>
{data.map((row, i) => (
<tr key={i} className={row.severity === "High" ? "critical" : ""}>
<td>{row.description}</td>
<td>{row.severity}</td>
</tr>
))}
</tbody>
</table>
);
};
The UI marks high‑severity interactions in red. Clicking a row opens a modal with evidence links, linking back to the CDSS’s evidence‑based medicine repository.
Data Model and Queries
A typical interaction table in PostgreSQL may look like this:
CREATE TABLE drug_interactions (
id SERIAL PRIMARY KEY,
drug_a VARCHAR NOT NULL,
drug_b VARCHAR NOT NULL,
interaction_type VARCHAR NOT NULL,
severity VARCHAR NOT NULL,
evidence_url TEXT
);
A query that aggregates interactions for a patient’s drug list is:
SELECT di.drug_a, di.drug_b, di.interaction_type, di.severity, di.evidence_url
FROM drug_interactions di
WHERE di.drug_a = ANY($1) AND di.drug_b = ANY($1);
The $1 placeholder receives the array of drug names supplied by the frontend.
Security & Safety
Recent commits introduced several safeguards:
-
Unauthenticated request memory leak – The
authdependency now rejects unauthenticated requests before they reach the reasoning engine, preventing excessive memory consumption. -
Revoked API key detection – A revoked key no longer reports the engine as live, as fixed in
5e78ac7. -
Safety corrections – The coagulation panel print logic now correctly resolves INR values, avoiding silent removal of liver scores (commit
5e78ac7). - Capital‑letter reference data – A block that previously turned a hard error into a warning when encountering a capital letter has been tightened.
- Session ownership checks – The engine now verifies session ownership before writing results, preventing orphaned outputs.
These changes collectively tighten the CDSS’s reliability and compliance with clinical safety standards.
Summary
Documedic’s drug interaction feature exemplifies a focused, engineer‑oriented clinical decision support component. Using FastAPI for secure, authenticated API handling, React for a responsive UI, and PostgreSQL for structured evidence storage, the system delivers rapid, evidence‑based dosing and interaction alerts. The recent commits demonstrate a commitment to safety and performance, ensuring that clinicians receive accurate information without compromising system resources or patient safety.
Top comments (0)