PatientContext is the central data structure in ClinicalPilot. All input parsers (text, FHIR, EHR) produce a PatientContext, and all agents consume it.
PatientContext
Patient gender. One of: "male", "female", "other", "unknown"
Patient weight in kilograms
Patient height in centimeters
List of active medical conditions ICD-10 or SNOMED code (if available)
Human-readable condition name
Date condition started (ISO 8601 format)
Condition status. Default: "active"
List of current medications Medication name (generic or brand)
Dosage (e.g., “500mg”, “10 units”)
Frequency (e.g., “BID”, “once daily”, “PRN”)
Route of administration. Default: "oral"
Medication status. Default: "active"
Laboratory results Lab test name (e.g., “Hemoglobin A1c”, “Creatinine”)
Unit of measurement (e.g., ”%”, “mg/dL”)
Normal reference range (e.g., “4.0-6.0”)
Date test was performed (ISO 8601)
Abnormal flag: "high", "low", "critical", or ""
Vital signs Vital sign name (e.g., “blood_pressure”, “heart_rate”, “temperature”)
Unit (e.g., “mmHg”, “bpm”, “°C”)
Timestamp of measurement (ISO 8601)
Known allergies Allergen (drug, food, environmental)
Allergic reaction description
Severity: "mild", "moderate", "severe"
The current clinical question or presenting complaint
Full anonymized input text (for agents that need complete context)
Input source: "text", "fhir", "ehr_pdf", "ehr_csv"
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.