Skip to main content
PatientContext is the central data structure in ClinicalPilot. All input parsers (text, FHIR, EHR) produce a PatientContext, and all agents consume it.

PatientContext

age
integer | null
Patient age in years
gender
string
Patient gender. One of: "male", "female", "other", "unknown"
weight_kg
number | null
Patient weight in kilograms
height_cm
number | null
Patient height in centimeters
conditions
array
List of active medical conditions
medications
array
List of current medications
labs
array
Laboratory results
vitals
array
Vital signs
allergies
array
Known allergies
current_prompt
string
The current clinical question or presenting complaint
raw_text
string
Full anonymized input text (for agents that need complete context)
source_type
string
Input source: "text", "fhir", "ehr_pdf", "ehr_csv"
timestamp
string
ISO 8601 timestamp when context was created

Example

{
  "age": 45,
  "gender": "male",
  "weight_kg": 85.0,
  "height_cm": 175.0,
  "conditions": [
    {
      "code": "I10",
      "display": "Essential hypertension",
      "onset_date": "2020-03-15",
      "status": "active"
    },
    {
      "code": "E11.9",
      "display": "Type 2 diabetes mellitus",
      "onset_date": "2018-06-01",
      "status": "active"
    }
  ],
  "medications": [
    {
      "name": "Metformin",
      "dose": "1000mg",
      "frequency": "BID",
      "route": "oral",
      "status": "active"
    },
    {
      "name": "Lisinopril",
      "dose": "20mg",
      "frequency": "once daily",
      "route": "oral",
      "status": "active"
    }
  ],
  "labs": [
    {
      "name": "Hemoglobin A1c",
      "value": "7.2",
      "unit": "%",
      "reference_range": "4.0-6.0",
      "date": "2026-02-15",
      "flag": "high"
    },
    {
      "name": "Creatinine",
      "value": "1.1",
      "unit": "mg/dL",
      "reference_range": "0.7-1.3",
      "date": "2026-02-15",
      "flag": ""
    }
  ],
  "vitals": [
    {
      "name": "blood_pressure",
      "value": "160/95",
      "unit": "mmHg",
      "date": "2026-03-03T10:30:00Z"
    },
    {
      "name": "heart_rate",
      "value": "110",
      "unit": "bpm",
      "date": "2026-03-03T10:30:00Z"
    }
  ],
  "allergies": [
    {
      "substance": "Penicillin",
      "reaction": "Rash",
      "severity": "moderate"
    }
  ],
  "current_prompt": "Patient presents with chest pain radiating to left arm, diaphoresis",
  "raw_text": "45yo male with HTN, DM2 presents with chest pain radiating to left arm...",
  "source_type": "text",
  "timestamp": "2026-03-03T10:30:00Z"
}

Methods

to_clinical_summary()

Returns a human-readable clinical summary string optimized for LLM prompts.
patient = PatientContext(age=45, gender="male", ...)
summary = patient.to_clinical_summary()
Returns:
45-year-old male patient
PMH: Essential hypertension, Type 2 diabetes mellitus
Medications: Metformin 1000mg BID, Lisinopril 20mg once daily
Allergies: Penicillin
Labs: Hemoglobin A1c: 7.2 %, Creatinine: 1.1 mg/dL
Vitals: blood_pressure: 160/95 mmHg, heart_rate: 110 bpm
Presenting complaint: Patient presents with chest pain radiating to left arm, diaphoresis

Usage

All input endpoints return a PatientContext:
  • POST /api/upload/fhir - Parses FHIR R4 Bundle → PatientContext
  • POST /api/upload/ehr - Parses PDF/CSV → PatientContext
  • Text input - Parsed via NLP → PatientContext
All agents accept PatientContext as input:
from backend.agents.clinical import run_clinical_agent
from backend.models.patient import PatientContext

patient = PatientContext(
    age=45,
    gender="male",
    current_prompt="Chest pain"
)

result = await run_clinical_agent(patient)
PatientContext is the “common currency” for all ClinicalPilot components. This unified schema allows FHIR, EHR, and free-text inputs to be processed identically by the agent pipeline.

Build docs developers (and LLMs) love