08. Decision Support Systems
Clinical Decision Support Systems (CDSS) provide clinicians with knowledge and patient-specific information to improve decision-making. Rules-based systems have dominated for decades; AI-based systems offer greater flexibility but require careful validation.
Local deployment suits CDSS well because the "knowledge base" is prompt-based rather than encoded in separate systems. The LLM applies clinical knowledge to specific patient scenarios without external data transmission.
# decision_support.py
from dataclasses import dataclass
from typing import List, Optional, Dict
from enum import Enum
class AlertSeverity(Enum):
CRITICAL = "critical"
WARNING = "warning"
INFO = "info"
@dataclass
class DecisionSupportAlert:
alert_type: str
severity: AlertSeverity
message: str
supporting_evidence: List[str]
recommended_action: str
class ClinicalDecisionSupport:
"""Provide clinical decision support using local LLM."""
def __init__(self, ollama_client, clinical_guidelines: Dict):
self.ollama = ollama_client
self.guidelines = clinical_guidelines
def evaluate_patient(self, patient_data: dict,
context: str) -> List[DecisionSupportAlert]:
"""Evaluate patient data and generate relevant alerts."""
# Build patient summary for context
patient_summary = self._build_patient_summary(patient_data)
prompt = f"""You are a clinical decision support system.
Evaluate this patient case against established guidelines.
Generate alerts for:
1. Guideline deviations
2. Potential drug interactions
3. Abnormal lab values
4. Missing preventive care
Patient Summary:
{patient_summary}
Clinical Context: {context}
Guidelines to apply:
{self._format_guidelines()}
Return alerts as JSON array with severity (critical/warning/info).
Only generate alerts directly supported by the patient data."""
response = self.ollama.generate(prompt)
return self._parse_alerts(response)
def suggest_differential_diagnoses(self, presentation: dict,
relevant_history: List[dict]) -> List[dict]:
"""Generate differential diagnosis suggestions."""
prompt = f"""Generate differential diagnoses for this presentation.
Consider patient history when relevant.
Prioritize by likelihood given available information.
Chief Complaint: {presentation.get('chief_complaint')}
Associated Symptoms: {presentation.get('symptoms', [])}
Duration: {presentation.get('duration')}
Relevant History:
{self._format_history(relevant_history)}
Format as JSON array with diagnosis, likelihood (high/medium/low), and key supporting features."""
response = self.ollama.generate(prompt)
return json.loads(response)
def _build_patient_summary(self, patient_data: dict) -> str:
"""Create compact patient summary for prompts."""
sections = []
if patient_data.get("demographics"):
demo = patient_data["demographics"]
sections.append(f"Age: {demo.get('age')}, Sex: {demo.get('sex')}")
if patient_data.get("medications"):
sections.append(f"Medications: {', '.join(patient_data['medications'])}")
if patient_data.get("allergies"):
sections.append(f"Allergies: {', '.join(patient_data['allergies'])}")
if patient_data.get("conditions"):
sections.append(f"Active Conditions: {', '.join(patient_data['conditions'])}")
return "\n".join(sections)
def _format_guidelines(self) -> str:
return json.dumps(self.guidelines, indent=2)
def _parse_alerts(self, response: str) -> List[DecisionSupportAlert]:
try:
data = json.loads(response)
alerts = []
for item in data:
severity_map = {
"critical": AlertSeverity.CRITICAL,
"warning": AlertSeverity.WARNING,
"info": AlertSeverity.INFO
}
alerts.append(DecisionSupportAlert(
alert_type=item.get("type", "general"),
severity=severity_map.get(item.get("severity", "info")),
message=item.get("message", ""),
supporting_evidence=item.get("evidence", []),
recommended_action=item.get("action", "")
))
return alerts
except:
return []
def _format_history(self, history: List[dict]) -> str:
if not history:
return "No relevant history documented"
return "\n".join([
f"- {h.get('condition')}: {h.get('status')} (onset: {h.get('onset')})"
for h in history
])
CDSS alerts face alert fatigue problems: too many alerts cause clinicians to ignore them all. Local LLMs can generate highly specific alerts based on full patient context, but must be tuned to minimize false positives. Integration with existing CDSS infrastructure leverages established alert frameworks.
Define five patient scenarios spanning different chief complaints. Run each through the decision support system and evaluate alert relevance. Track false positive rate over 50 evaluations.