Building MEWS AI: Healthcare Integrity & Cryptographic Audit Trails
Clinical software systems demand absolute integrity. When an AI triages a patient or calculates health deterioration risks, the decision-making pipeline must be fully auditable, verifiable, and tamper-proof.
Here, we explore the architecture of MedOS AI, focusing on the integration of the Modified Early Warning Score (MEWS) engine, AI clinical notes triage, and a cryptographic audit log system.
The Core MEWS Algorithm
The Modified Early Warning Score (MEWS) is a simple, clinically-validated score computed from vital signs:
- Systolic Blood Pressure
- Heart Rate
- Respiratory Rate
- Temperature
- Consciousness Level (AVPU)
A score $\ge 5$ indicates high clinical risk, needing urgent clinical attention.
Here is the exact TypeScript implementation of the MEWS engine:
export interface Vitals {
systolicBP: number;
heartRate: number;
respiratoryRate: number;
temperature: number;
consciousLevel: "A" | "V" | "P" | "U"; // Alert, Voice, Pain, Unresponsive
}
export function calculateMEWS(vitals: Vitals): number {
let score = 0;
// Systolic Blood Pressure
if (vitals.systolicBP <= 70) score += 3;
else if (vitals.systolicBP <= 80) score += 2;
else if (vitals.systolicBP <= 100) score += 1;
else if (vitals.systolicBP >= 200) score += 2;
// Heart Rate
if (vitals.heartRate <= 40) score += 3;
else if (vitals.heartRate <= 50) score += 1;
else if (vitals.heartRate >= 101 && vitals.heartRate <= 110) score += 1;
else if (vitals.heartRate >= 111 && vitals.heartRate <= 129) score += 2;
else if (vitals.heartRate >= 130) score += 3;
// Respiratory Rate
if (vitals.respiratoryRate < 9) score += 3;
else if (vitals.respiratoryRate >= 15 && vitals.respiratoryRate <= 20) score += 1;
else if (vitals.respiratoryRate >= 21 && vitals.respiratoryRate <= 29) score += 2;
else if (vitals.respiratoryRate >= 30) score += 3;
// Temperature
if (vitals.temperature < 35.0) score += 2;
else if (vitals.temperature >= 38.5) score += 2;
// Conscious Level (AVPU)
if (vitals.consciousLevel === "V") score += 1;
else if (vitals.consciousLevel === "P") score += 2;
else if (vitals.consciousLevel === "U") score += 3;
return score;
}AI-Augmented Triage Integration
While the vitals yield a numeric MEWS score, doctors' notes contain unstructured insights (e.g., "patient shows signs of mild confusion", "intermittent chest pain").
We run these clinical notes through a lightweight classification model or structured LLM tool to identify underlying indicators:
interface ClinicalTriageResult {
criticalSymptoms: string[];
severity: "LOW" | "MEDIUM" | "HIGH";
suggestedDepartment: string;
reasoning: string;
}
// Structured output configuration using LangChain Zod schemas
const triageSchema = z.object({
criticalSymptoms: z.array(z.string()).describe("Symptoms suggesting urgent issues"),
severity: z.enum(["LOW", "MEDIUM", "HIGH"]),
suggestedDepartment: z.string(),
reasoning: z.string(),
});Cryptographic Audit Trails for Safety
To ensure that AI suggestions and MEWS inputs cannot be altered retrospectively (e.g., to shift liability after an adverse clinical event), every single decision is cryptographically chained.
We create a linear blockchain audit trail where each audit block includes:
- Timestamp of the decision.
- Patient Identifier.
- Input Data (vitals, notes).
- Calculated MEWS and AI triage decisions.
- Previous Block Hash.
- SHA-256 Hash of current block properties.
import { createHash } from "crypto";
export interface AuditBlock {
index: number;
timestamp: string;
patientId: string;
data: {
mewsScore: number;
aiSeverity: string;
vitals: Vitals;
};
previousHash: string;
hash: string;
}
export function calculateBlockHash(block: Omit<AuditBlock, "hash">): string {
const payload = JSON.stringify({
index: block.index,
timestamp: block.timestamp,
patientId: block.patientId,
data: block.data,
previousHash: block.previousHash,
});
return createHash("sha256").update(payload).digest("hex");
}Compliance & Integration
By combining numeric indicators with AI triage and pinning them down under cryptographic hashing, this system meets HIPAA audit logs standard and establishes complete trust in automated critical warning platforms.