Examples
Real-world usage patterns for VitalClaw.
Basic: Ingest & Summarize
import { VitalClawEngine } from "@vitalclaw/sdk"; const engine = new VitalClawEngine({ userId: "user-001", providers: [], }); engine.ingest([ { id: "1", userId: "user-001", metric: "heart_rate", value: 72, unit: "bpm", timestamp: new Date().toISOString(), source: "manual" }, { id: "2", userId: "user-001", metric: "steps", value: 8432, unit: "steps", timestamp: new Date().toISOString(), source: "manual" }, { id: "3", userId: "user-001", metric: "sleep_duration", value: 450, unit: "minutes", timestamp: new Date().toISOString(), source: "manual" }, ]); const s = engine.getDailySummary(); console.log(`Score: ${s.wellnessScore}/100`);
Alert Monitoring with Notifications
const engine = new VitalClawEngine({ userId: "user-001", providers: [] }); // Custom rule: alert if RHR > 85 engine.addAlertRule({ id: "rhr-elevated", metric: "resting_heart_rate", condition: "above", threshold: 85, severity: "warning", message: "Resting heart rate elevated at {value} bpm.", cooldownMs: 3_600_000, // 1 hour }); // React to alerts engine.events.on("alert:triggered", (event) => { if (event.type === "alert:triggered") { sendPushNotification({ title: event.alert.title, body: event.alert.message, urgency: event.alert.severity === "critical" ? "high" : "normal", }); } });
FHIR Export for Healthcare Provider
import { VitalClawEngine, FHIRConverter } from "@vitalclaw/sdk"; const engine = new VitalClawEngine({ userId: "patient-123", providers: [] }); const fhir = new FHIRConverter(); // Get last 30 days of data const from = new Date(); from.setDate(from.getDate() - 30); const points = engine.query({ userId: "patient-123", from: from.toISOString(), metrics: ["heart_rate", "blood_pressure", "blood_oxygen", "blood_glucose"], }); // Export as FHIR Bundle const bundle = fhir.toBundle(points, "Patient/patient-123"); // Send to EHR system await fetch("https://ehr.hospital.org/fhir/Bundle", { method: "POST", headers: { "Content-Type": "application/fhir+json" }, body: JSON.stringify(bundle), });
ElizaOS Health Agent
import { createVitalClawPlugin, healthCompanionCharacter, } from "@vitalclaw/sdk"; // 1. Create plugin with Fitbit connected const plugin = createVitalClawPlugin({ userId: "user-001", providers: [{ provider: "fitbit", credentials: { provider: "fitbit", clientId: process.env.FITBIT_CLIENT_ID, clientSecret: process.env.FITBIT_SECRET, accessToken: process.env.FITBIT_TOKEN, }, }], }); // 2. Use Vita character with the plugin const agent = { ...healthCompanionCharacter, plugins: [plugin], }; // 3. User says: "check my vitals" // → Vita: "Wellness Score: 78/100 // Resting HR: 62 bpm, SpO2: 97%, Steps: 8,432, Sleep: 7.5h // Note: This is not medical advice."
Weekly Report Email
import { VitalClawEngine } from "@vitalclaw/sdk"; const engine = new VitalClawEngine({ userId: "user-001", providers: [] }); // Generate weekly summary every Monday const weekly = engine.getWeeklySummary(); const emailBody = ` Weekly Health Report (${weekly.weekStart} — ${weekly.weekEnd}) Overall Score: ${weekly.weeklyScore}/100 Trend: ${weekly.trends.overallDirection} Insights: ${weekly.insights.map(i => `• ${i}`).join("\\n")} `; await sendEmail({ to: "user@example.com", subject: `Weekly Health Report — Score: ${weekly.weeklyScore}/100`, body: emailBody, });