The user wants an antimicrobial exposure minimization dashboard. This is a medical/clinical dashboard that tracks:
I'll use CSS variables for theming and ensure everything is properly initialized before use.
A clinical-grade dashboard for tracking antibiotic usage and microbiome health indicators. Features real-time metrics, risk visualization, and temporal trend analysis.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Antimicrobial Exposure Tracker</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0f14;
--bg-elevated: #111921;
--bg-card: #151d27;
--fg: #e8edf3;
--fg-muted: #6b7d8f;
--accent: #00d4aa;
--accent-dim: rgba(0, 212, 170, 0.15);
--warning: #ff9f43;
--danger: #ff5757;
--border: #1e2a38;
--glow: rgba(0, 212, 170, 0.3);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
overflow-x: hidden;
}
.mono {
font-family: 'JetBrains Mono', monospace;
}
.bg-pattern {
position: fixed;
inset: 0;
background-image:
radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 212, 170, 0.08), transparent),
radial-gradient(ellipse 60% 40% at 100% 100%, rgba(0, 100, 180, 0.06), transparent),
linear-gradient(180deg, var(--bg) 0%, #0d1318 100%);
pointer-events: none;
z-index: -1;
}
.grid-overlay {
position: fixed;
inset: 0;
background-image:
linear-gradient(var(--border) 1px, transparent 1px),
linear-gradient(90deg, var(--border) 1px, transparent 1px);
background-size: 60px 60px;
opacity: 0.3;
pointer-events: none;
z-index: -1;
}
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
transition: all 0.3s ease;
}
.card:hover {
border-color: rgba(0, 212, 170, 0.3);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.metric-value {
font-weight: 700;
letter-spacing: -0.02em;
line-height: 1;
}
.progress-ring {
transform: rotate(-90deg);
}
.progress-ring-circle {
transition: stroke-dashoffset 1s ease-out;
}
.tab-btn {
position: relative;
padding: 0.75rem 1.25rem;
color: var(--fg-muted);
font-weight: 500;
transition: all 0.3s ease;
border-radius: 8px;
}
.tab-btn:hover {
color: var(--fg);
background: rgba(255, 255, 255, 0.05);
}
.tab-btn.active {
color: var(--accent);
background: var(--accent-dim);
}
.timeline-bar {
position: relative;
height: 100%;
border-radius: 4px 4px 0 0;
transition: all 0.3s ease;
cursor: pointer;
}
.timeline-bar:hover {
filter: brightness(1.2);
transform: scaleY(1.05);
transform-origin: bottom;
}
.tooltip {
position: absolute;
background: var(--bg-elevated);
border: 1px solid var(--border);
padding: 0.75rem 1rem;
border-radius: 8px;
font-size: 0.8rem;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s ease;
z-index: 100;
white-space: nowrap;
}
.timeline-bar:hover .tooltip {
opacity: 1;
}
.risk-indicator {
position: relative;
width: 100%;
height: 8px;
background: var(--bg);
border-radius: 4px;
overflow: hidden;
}
.risk-fill {
height: 100%;
border-radius: 4px;
transition: width 1s ease-out, background 0.5s ease;
}
.pulse {
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.fade-in {
animation: fadeIn 0.6s ease-out forwards;
}
.slide-up {
animation: slideUp 0.6s ease-out forwards;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.stagger-1 { animation-delay: 0.1s; opacity: 0; }
.stagger-2 { animation-delay: 0.2s; opacity: 0; }
.stagger-3 { animation-delay: 0.3s; opacity: 0; }
.stagger-4 { animation-delay: 0.4s; opacity: 0; }
.stagger-5 { animation-delay: 0.5s; opacity: 0; }
.drug-tag {
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.35rem 0.65rem;
background: rgba(255, 255, 255, 0.05);
border: 1px solid var(--border);
border-radius: 6px;
font-size: 0.75rem;
transition: all 0.2s ease;
}
.drug-tag:hover {
background: rgba(255, 255, 255, 0.1);
border-color: var(--accent);
}
.microbiome-bar {
height: 6px;
background: var(--bg);
border-radius: 3px;
overflow: hidden;
}
.microbiome-fill {
height: 100%;
border-radius: 3px;
transition: width 1.2s ease-out;
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
.scrollbar-thin::-webkit-scrollbar {
width: 6px;
}
.scrollbar-thin::-webkit-scrollbar-track {
background: var(--bg);
}
.scrollbar-thin::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 3px;
}
</style>
</head>
<body class="scrollbar-thin">
<div class="bg-pattern"></div>
<div class="grid-overlay"></div>
<div class="min-h-screen p-4 md:p-6 lg:p-8">
<!-- Header -->
<header class="mb-8 fade-in">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<div class="flex items-center gap-3 mb-2">
<div class="w-10 h-10 rounded-lg bg-gradient-to-br from-[var(--accent)] to-teal-600 flex items-center justify-center">
<svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
</svg>
</div>
<h1 class="text-2xl md:text-3xl font-bold tracking-tight">Antimicrobial Exposure Tracker</h1>
</div>
<p class="text-[var(--fg-muted)] text-sm md:text-base">Cumulative antibiotic days and microbiome health monitoring</p>
</div>
<div class="flex items-center gap-3">
<div class="px-3 py-1.5 bg-[var(--accent-dim)] border border-[var(--accent)] rounded-lg flex items-center gap-2">
<span class="w-2 h-2 bg-[var(--accent)] rounded-full pulse"></span>
<span class="text-sm text-[var(--accent)] font-medium">Active Monitoring</span>
</div>
<button id="refreshBtn" class="p-2.5 rounded-lg border border-[var(--border)] hover:border-[var(--accent)] hover:bg-[var(--accent-dim)] transition-all" aria-label="Refresh data">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
</button>
</div>
</div>
</header>
<!-- Main Metrics -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
<!-- Cumulative Days -->
<div class="card p-5 slide-up stagger-1">
<div class="flex items-start justify-between mb-4">
<div>
<p class="text-[var(--fg-muted)] text-xs uppercase tracking-wider mb-1">Cumulative Days</p>
<p class="metric-value text-4xl text-[var(--fg)]" id="cumulativeDays">0</p>
</div>
<div class="w-12 h-12 rounded-lg bg-[var(--warning)]/10 flex items-center justify-center">
<svg class="w-6 h-6 text-[var(--warning)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
</div>
<div class="flex items-center gap-2">
<span class="text-xs text-[var(--fg-muted)]">This month:</span>
<span class="mono text-sm text-[var(--warning)]" id="monthlyDays">0</span>
</div>
</div>
<!-- Microbiome Score -->
<div class="card p-5 slide-up stagger-2">
<div class="flex items-start justify-between mb-4">
<div>
<p class="text-[var(--fg-muted)] text-xs uppercase tracking-wider mb-1">Microbiome Score</p>
<p class="metric-value text-4xl text-[var(--accent)]" id="microbiomeScore">0</p>
</div>
<svg class="w-16 h-16 progress-ring" viewBox="0 0 64 64">
<circle cx="32" cy="32" r="28" fill="none" stroke="var(--border)" stroke-width="4"/>
<circle id="scoreRing" class="progress-ring-circle" cx="32" cy="32" r="28" fill="none" stroke="var(--accent)" stroke-width="4" stroke-linecap="round" stroke-dasharray="175.93" stroke-dashoffset="175.93"/>
</svg>
</div>
<div class="flex items-center gap-2">
<span class="text-xs text-[var(--fg-muted)]">Status:</span>
<span class="text-xs px-2 py-0.5 rounded bg-[var(--accent-dim)] text-[var(--accent)]" id="microbiomeStatus">Optimal</span>
</div>
</div>
<!-- Diversity Index -->
<div class="card p-5 slide-up stagger-3">
<div class="flex items-start justify-between mb-4">
<div>
<p class="text-[var(--fg-muted)] text-xs uppercase tracking-wider mb-1">Diversity Index</p>
<p class="metric-value text-4xl text-[var(--fg)]" id="diversityIndex">0</p>
</div>
<div class="w-12 h-12 rounded-lg bg-[var(--accent-dim)] flex items-center justify-center">
<svg class="w-6 h-6 text-[var(--accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/>
</svg>
</div>
</div>
<div class="flex items-center gap-2">
<span class="text-xs text-[var(--fg-muted)]">Change:</span>
<span class="mono text-sm text-[var(--accent)]" id="diversityChange">+0.0</span>
</div>
</div>
<!-- Risk Level -->
<div class="card p-5 slide-up stagger-4">
<div class="flex items-start justify-between mb-4">
<div>
<p class="text-[var(--fg-muted)] text-xs uppercase tracking-wider mb-1">Exposure Risk</p>
<p class="metric-value text-4xl" id="riskLevel">Low</p>
</div>
<div class="w-12 h-12 rounded-lg flex items-center justify-center" id="riskIcon">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
</div>
<div class="risk-indicator">
<div class="risk-fill" id="riskFill" style="width: 25%; background: var(--accent);"></div>
</div>
</div>
</div>
<!-- Tabs Navigation -->
<div class="flex gap-2 mb-6 overflow-x-auto pb-2 slide-up stagger-5">
<button class="tab-btn active" data-tab="timeline">Timeline</button>
<button class="tab-btn" data-tab="antibiotics">Antibiotics</button>
<button class="tab-btn" data-tab="microbiome">Microbiome</button>
<button class="tab-btn" data-tab="recommendations">Recommendations</button>
</div>
<!-- Tab Content -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Main Content Area -->
<div class="lg:col-span-2">
<!-- Timeline Tab -->
<div id="timelineTab" class="tab-content">
<div class="card p-6">
<div class="flex items-center justify-between mb-6">
<h3 class="font-semibold text-lg">Antibiotic Exposure Timeline</h3>
<div class="flex items-center gap-2">
<span class="text-xs text-[var(--fg-muted)]">Last 30 days</span>
</div>
</div>
<div class="relative h-64 mb-4" id="timelineChart">
<!-- Y-axis labels -->
<div class="absolute left-0 top-0 bottom-8 w-8 flex flex-col justify-between text-xs text-[var(--fg-muted)]">
<span>4</span>
<span>3</span>
<span>2</span>
<span>1</span>
<span>0</span>
</div>
<!-- Chart area -->
<div class="absolute left-10 right-0 top-0 bottom-8 flex items-end gap-1" id="barsContainer">
<!-- Bars will be generated by JS -->
</div>
<!-- X-axis -->
<div class="absolute left-10 right-0 bottom-0 h-8 flex items-center border-t border-[var(--border)]">
<div class="flex-1 flex justify-between px-1 text-xs text-[var(--fg-muted)]">
<span>1</span>
<span>5</span>
<span>10</span>
<span>15</span>
<span>20</span>
<span>25</span>
<span>30</span>
</div>
</div>
</div>
<!-- Legend -->
<div class="flex flex-wrap gap-4 pt-4 border-t border-[var(--border)]">
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded bg-[var(--accent)]"></span>
<span class="text-xs text-[var(--fg-muted)]">Low exposure</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded bg-[var(--warning)]"></span>
<span class="text-xs text-[var(--fg-muted)]">Moderate</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded bg-[var(--danger)]"></span>
<span class="text-xs text-[var(--fg-muted)]">High exposure</span>
</div>
</div>
</div>
</div>
<!-- Antibiotics Tab -->
<div id="antibioticsTab" class="tab-content hidden">
<div class="card p-6">
<div class="flex items-center justify-between mb-6">
<h3 class="font-semibold text-lg">Active Antibiotics</h3>
<button class="text-xs px-3 py-1.5 rounded-lg border border-[var(--border)] hover:border-[var(--accent)] transition-all">+ Add Entry</button>
</div>
<div class="space-y-4" id="antibioticsList">
<!-- Generated by JS -->
</div>
</div>
</div>
<!-- Microbiome Tab -->
<div id="microbiomeTab" class="tab-content hidden">
<div class="card p-6">
<h3 class="font-semibold text-lg mb-6">Microbiome Proxies</h3>
<div class="space-y-6" id="microbiomeProxies">
<!-- Generated by JS -->
</div>
</div>
</div>
<!-- Recommendations Tab -->
<div id="recommendationsTab" class="tab-content hidden">
<div class="card p-6">
<h3 class="font-semibold text-lg mb-6">Clinical Recommendations</h3>
<div class="space-y-4" id="recommendationsList">
<!-- Generated by JS -->
</div>
</div>
</div>
</div>
<!-- Sidebar -->
<div class="space-y-6">
<!-- Current Antibiotics -->
<div class="card p-5 slide-up stagger-3">
<h3 class="font-semibold mb-4 flex items-center gap-2">
<svg class="w-4 h-4 text-[var(--accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"/>
</svg>
Current Regimen
</h3>
<div class="space-y-3" id="currentRegimen">
<!-- Generated by JS -->
</div>
</div>
<!-- Beneficial Bacteria -->
<div class="card p-5 slide-up stagger-4">
<h3 class="font-semibold mb-4 flex items-center gap-2">
<svg class="w-4 h-4 text-[var(--accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/>
</svg>
Beneficial Bacteria
</h3>
<div class="space-y-4" id="beneficialBacteria">
<!-- Generated by JS -->
</div>
</div>
<!-- Alerts -->
<div class="card p-5 border-l-4 border-l-[var(--warning)] slide-up stagger-5">
<h3 class="font-semibold mb-3 flex items-center gap-2 text-[var(--warning)]">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
Alerts
</h3>
<div class="space-y-2 text-sm" id="alertsList">
<!-- Generated by JS -->
</div>
</div>
</div>
</div>
</div>
<script>
// Data Initialization - Must be before any function calls
const timelineData = [
{ day: 1, exposure: 0, drug: null },
{ day: 2, exposure: 1, drug: 'Amoxicillin' },
{ day: 3, exposure: 1, drug: 'Amoxicillin' },
{ day: 4, exposure: 2, drug: 'Amoxicillin' },
{ day: 5, exposure: 0, drug: null },
{ day: 6, exposure: 0, drug: null },
{ day: 7, exposure: 0, drug: null },
{ day: 8, exposure: 1, drug: 'Ciprofloxacin' },
{ day: 9, exposure: 1, drug: 'Ciprofloxacin' },
{ day: 10, exposure: 2, drug: 'Ciprofloxacin' },
{ day: 11, exposure: 1, drug: 'Ciprofloxacin' },
{ day: 12, exposure: 0, drug: null },
{ day: 13, exposure: 0, drug: null },
{ day: 14, exposure: 0, drug: null },
{ day: 15, exposure: 0, drug: null },
{ day: 16, exposure: 1, drug: 'Metronidazole' },
{ day: 17, exposure: 1, drug: 'Metronidazole' },
{ day: 18, exposure: 1, drug: 'Metronidazole' },
{ day: 19, exposure: 0, drug: null },
{ day: 20, exposure: 0, drug: null },
{ day: 21, exposure: 0, drug: null },
{ day: 22, exposure: 0, drug: null },
{ day: 23, exposure: 0, drug: null },
{ day: 24, exposure: 1, drug: 'Azithromycin' },
{ day: 25, exposure: 1, drug: 'Azithromycin' },
{ day: 26, exposure: 1, drug: 'Azithromycin' },
{ day: 27, exposure: 0, drug: null },
{ day: 28, exposure: 0, drug: null },
{ day: 29, exposure: 0, drug: null },
{ day: 30, exposure: 0, drug: null }
];
const antibiotics = [
{ name: 'Amoxicillin', dose: '500mg', frequency: 'TID', days: 7, remaining: 0, status: 'completed' },
{ name: 'Ciprofloxacin', dose: '500mg', frequency: 'BID', days: 5, remaining: 0, status: 'completed' },
{ name: 'Metronidazole', dose: '400mg', frequency: 'TID', days: 3, remaining: 0, status: 'completed' },
{ name: 'Azithromycin', dose: '250mg', frequency: 'QD', days: 3, remaining: 0, status: 'completed' }
];
const microbiomeProxies = [
{ name: 'Shannon Diversity Index', value: 3.2, min: 0, max: 5, optimal: '>=3', status: 'good' },
{ name: 'Firmicutes/Bacteroidetes Ratio', value: 0.8, min: 0, max: 2, optimal: '0.5-1.5', status: 'good' },
{ name: 'Lactobacillus spp.', value: 65, min: 0, max: 100, optimal: '>=50%', status: 'good', unit: '%' },
{ name: 'Bifidobacterium spp.', value: 42, min: 0, max: 100, optimal: '>=40%', status: 'moderate', unit: '%' },
{ name: 'Enterobacteriaceae', value: 8, min: 0, max: 100, optimal: '<10%', status: 'good', unit: '%' },
{ name: 'Clostridium difficile', value: 0, min: 0, max: 100, optimal: '0%', status: 'good', unit: '%' }
];
const beneficialBacteria = [
{ name: 'L. acidophilus', level: 72, trend: 'stable' },
{ name: 'B. longum', level: 58, trend: 'up' },
{ name: 'L. rhamnosus', level: 45, trend: 'down' },
{ name: 'B. breve', level: 61, trend: 'stable' }
];
const recommendations = [
{ priority: 'high', text: 'Consider probiotic supplementation during antibiotic courses', icon: 'probiotic' },
{ priority: 'medium', text: 'Monitor for C. difficile symptoms if exposure exceeds 14 days', icon: 'monitor' },
{ priority: 'low', text: 'Dietary fiber intake may support microbiome recovery', icon: 'diet' },
{ priority: 'medium', text: 'Review antibiotic necessity at next assessment', icon: 'review' },
{ priority: 'high', text: 'Consider narrow-spectrum alternatives when appropriate', icon: 'target' }
];
const alerts = [
{ type: 'warning', text: 'Cumulative exposure approaching threshold (14/21 days)' },
{ type: 'info', text: 'Bifidobacterium levels recovering after recent course' },
{ type: 'success', text: 'No resistance markers detected' }
];
// Calculate derived values
const cumulativeDays = timelineData.reduce((sum, d) => sum + d.exposure, 0);
const monthlyDays = timelineData.reduce((sum, d) => sum + d.exposure, 0);
// DOM Elements - Initialize after data
let cumulativeDaysEl, monthlyDaysEl, microbiomeScoreEl, diversityIndexEl;
let scoreRingEl, riskLevelEl, riskFillEl, riskIconEl, microbiomeStatusEl, diversityChangeEl;
let barsContainer, currentRegimenEl, beneficialBacteriaEl, antibioticsListEl;
let microbiomeProxiesEl, recommendationsListEl, alertsListEl;
// Initialize DOM references
function initDOMReferences() {
cumulativeDaysEl = document.getElementById('cumulativeDays');
monthlyDaysEl = document.getElementById('monthlyDays');
microbiomeScoreEl = document.getElementById('microbiomeScore');
diversityIndexEl = document.getElementById('diversityIndex');
scoreRingEl = document.getElementById('scoreRing');
riskLevelEl = document.getElementById('riskLevel');
riskFillEl = document.getElementById('riskFill');
riskIconEl = document.getElementById('riskIcon');
microbiomeStatusEl = document.getElementById('microbiomeStatus');
diversityChangeEl = document.getElementById('diversityChange');
barsContainer = document.getElementById('barsContainer');
currentRegimenEl = document.getElementById('currentRegimen');
beneficialBacteriaEl = document.getElementById('beneficialBacteria');
antibioticsListEl = document.getElementById('antibioticsList');
microbiomeProxiesEl = document.getElementById('microbiomeProxies');
recommendationsListEl = document.getElementById('recommendationsList');
alertsListEl = document.getElementById('alertsList');
}
// Utility Functions
function getBarColor(exposure) {
if (exposure >= 3) return 'var(--danger)';
if (exposure >= 2) return 'var(--warning)';
return 'var(--accent)';
}
function getRiskLevel(days) {
if (days <= 7) return { text: 'Low', color: 'var(--accent)', percent: 25 };
if (days <= 14) return { text: 'Moderate', color: 'var(--warning)', percent: 50 };
if (days <= 21) return { text: 'High', color: 'var(--warning)', percent: 75 };
return { text: 'Critical', color: 'var(--danger)', percent: 100 };
}
function animateValue(el, start, end, duration) {
const startTime = performance.now();
const isDecimal = String(end).includes('.');
function update(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const easeProgress = 1 - Math.pow(1 - progress, 3);
const current = start + (end - start) * easeProgress;
el.textContent = isDecimal ? current.toFixed(1) : Math.round(current);
if (progress < 1) {
requestAnimationFrame(update);
}
}
requestAnimationFrame(update);
}
// Render Functions
function renderTimeline() {
if (!barsContainer) return;
barsContainer.innerHTML = '';
const maxExposure = 4;
const safeMax = Math.max(maxExposure, 1);
timelineData.forEach((data, index) => {
const heightPercent = Math.max(0, Math.min(100, (data.exposure / safeMax) * 100));
const bar = document.createElement('div');
bar.className = 'timeline-bar flex-1';
bar.style.background = getBarColor(data.exposure);
bar.style.height = `${heightPercent}%`;
bar.style.animationDelay = `${index * 30}ms`;
if (data.drug) {
const tooltip = document.createElement('div');
tooltip.className = 'tooltip';
tooltip.style.bottom = '100%';
tooltip.style.left = '50%';
tooltip.style.transform = 'translateX(-50%)';
tooltip.style.marginBottom = '8px';
tooltip.innerHTML = `
<div class="font-medium text-[var(--fg)]">Day ${data.day}</div>
<div class="text-[var(--fg-muted)]">${data.drug}</div>
<div class="text-[var(--accent)]">${data.exposure} dose(s)</div>
`;
bar.appendChild(tooltip);
}
barsContainer.appendChild(bar);
});
}
function renderCurrentRegimen() {
if (!currentRegimenEl) return;
const activeDrugs = antibiotics.filter(a => a.status !== 'completed');
if (activeDrugs.length === 0) {
currentRegimenEl.innerHTML = `
<div class="text-center py-4 text-[var(--fg-muted)]">
<p class="text-sm">No active antibiotics</p>
<p class="text-xs mt-1">Last course completed 3 days ago</p>
</div>
`;
return;
}
currentRegimenEl.innerHTML = activeDrugs.map(drug => `
<div class="flex items-center justify-between p-3 rounded-lg bg-[var(--bg-elevated)]">
<div>
<p class="font-medium text-sm">${drug.name}</p>
<p class="text-xs text-[var(--fg-muted)]">${drug.dose} ${drug.frequency}</p>
</div>
<div class="text-right">
<p class="text-sm text-[var(--accent)]">${drug.remaining} days</p>
<p class="text-xs text-[var(--fg-muted)]">remaining</p>
</div>
</div>
`).join('');
}
function renderBeneficialBacteria() {
if (!beneficialBacteriaEl) return;
beneficialBacteriaEl.innerHTML = beneficialBacteria.map(bacteria => {
const trendIcon = bacteria.trend === 'up' ? '↑' : bacteria.trend === 'down' ? '↓' : '→';
const trendColor = bacteria.trend === 'up' ? 'var(--accent)' : bacteria.trend === 'down' ? 'var(--warning)' : 'var(--fg-muted)';
const safeLevel = Math.max(0, Math.min(100, bacteria.level));
return `
<div>
<div class="flex items-center justify-between mb-2">
<span class="text-sm">${bacteria.name}</span>
<span class="text-xs flex items-center gap-1" style="color: ${trendColor}">${trendIcon} ${bacteria.level}%</span>
</div>
<div class="microbiome-bar">
<div class="microbiome-fill" style="width: ${safeLevel}%; background: ${trendColor};"></div>
</div>
</div>
`;
}).join('');
}
function renderAntibioticsList() {
if (!antibioticsListEl) return;
antibioticsListEl.innerHTML = antibiotics.map(drug => {
const statusColor = drug.status === 'active' ? 'var(--accent)' : 'var(--fg-muted)';
const statusBg = drug.status === 'active' ? 'var(--accent-dim)' : 'rgba(255,255,255,0.05)';
return `
<div class="p-4 rounded-lg bg-[var(--bg-elevated)] border border-[var(--border)]">
<div class="flex items-start justify-between mb-3">
<div>
<h4 class="font-medium">${drug.name}</h4>
<p class="text-sm text-[var(--fg-muted)]">${drug.dose} - ${drug.frequency}</p>
</div>
<span class="text-xs px-2 py-1 rounded" style="background: ${statusBg}; color: ${statusColor};">${drug.status}</span>
</div>
<div class="flex items-center gap-4 text-sm">
<div>
<span class="text-[var(--fg-muted)]">Duration:</span>
<span class="ml-1">${drug.days} days</span>
</div>
<div>
<span class="text-[var(--fg-muted)]">Remaining:</span>
<span class="ml-1">${drug.remaining} days</span>
</div>
</div>
</div>
`;
}).join('');
}
function renderMicrobiomeProxies() {
if (!microbiomeProxiesEl) return;
microbiomeProxiesEl.innerHTML = microbiomeProxies.map(proxy => {
const statusColor = proxy.status === 'good' ? 'var(--accent)' : proxy.status === 'moderate' ? 'var(--warning)' : 'var(--danger)';
const range = Math.max(0.01, proxy.max - proxy.min);
const percent = Math.max(0, Math.min(100, ((proxy.value - proxy.min) / range) * 100));
const displayValue = proxy.unit ? `${proxy.value}${proxy.unit}` : proxy.value;
return `
<div>
<div class="flex items-center justify-between mb-2">
<span class="text-sm font-medium">${proxy.name}</span>
<span class="text-sm" style="color: ${statusColor}">${displayValue}</span>
</div>
<div class="microbiome-bar">
<div class="microbiome-fill" style="width: ${percent}%; background: ${statusColor};"></div>
</div>
<p class="text-xs text-[var(--fg-muted)] mt-1">Optimal: ${proxy.optimal}</p>
</div>
`;
}).join('');
}
function renderRecommendations() {
if (!recommendationsListEl) return;
const priorityColors = {
high: 'var(--danger)',
medium: 'var(--warning)',
low: 'var(--accent)'
};
recommendationsListEl.innerHTML = recommendations.map(rec => `
<div class="flex gap-3 p-3 rounded-lg bg-[var(--bg-elevated)] border-l-2" style="border-color: ${priorityColors[rec.priority]}">
<div class="w-5 h-5 rounded-full flex items-center justify-center flex-shrink-0 mt-0.5" style="background: ${priorityColors[rec.priority]}20">
<div class="w-2 h-2 rounded-full" style="background: ${priorityColors[rec.priority]}"></div>
</div>
<p class="text-sm">${rec.text}</p>
</div>
`).join('');
}
function renderAlerts() {
if (!alertsListEl) return;
const alertColors = {
warning: 'var(--warning)',
info: 'var(--accent)',
success: '#22c55e'
};
alertsListEl.innerHTML = alerts.map(alert => `
<div class="flex items-start gap-2">
<div class="w-1.5 h-1.5 rounded-full mt-1.5 flex-shrink-0" style="background: ${alertColors[alert.type]}"></div>
<p class="text-[var(--fg-muted)]">${alert.text}</p>
</div>
`).join('');
}
// Main Update Function
function updateDashboard() {
// Animate main metrics
animateValue(cumulativeDaysEl, 0, cumulativeDays, 1500);
animateValue(monthlyDaysEl, 0, monthlyDays, 1500);
animateValue(microbiomeScoreEl, 0, 78, 1500);
animateValue(diversityIndexEl, 0, 3.2, 1500);
// Animate score ring
const circumference = 2 * Math.PI * 28;
const score = 78;
const offset = circumference - (score / 100) * circumference;
setTimeout(() => {
if (scoreRingEl) scoreRingEl.style.strokeDashoffset = offset;
}, 500);
// Update risk level
const risk = getRiskLevel(cumulativeDays);
if (riskLevelEl) riskLevelEl.textContent = risk.text;
if (riskLevelEl) riskLevelEl.style.color = risk.color;
if (riskFillEl) {
riskFillEl.style.width = `${risk.percent}%`;
riskFillEl.style.background = risk.color;
}
if (riskIconEl) {
riskIconEl.style.background = `${risk.color}20`;
riskIconEl.querySelector('svg').style.color = risk.color;
}
// Update diversity change
if (diversityChangeEl) diversityChangeEl.textContent = '+0.3';
// Render all sections
renderTimeline();
renderCurrentRegimen();
renderBeneficialBacteria();
renderAntibioticsList();
renderMicrobiomeProxies();
renderRecommendations();
renderAlerts();
}
// Tab Switching
function initTabs() {
const tabBtns = document.querySelectorAll('.tab-btn');
const tabContents = document.querySelectorAll('.tab-content');
tabBtns.forEach(btn => {
btn.addEventListener('click', () => {
const tabName = btn.dataset.tab;
tabBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
tabContents.forEach(content => {
content.classList.add('hidden');
});
const targetTab = document.getElementById(`${tabName}Tab`);
if (targetTab) {
targetTab.classList.remove('hidden');
}
});
});
}
// Refresh Button
function initRefresh() {
const refreshBtn = document.getElementById('refreshBtn');
if (refreshBtn) {
refreshBtn.addEventListener('click', () => {
refreshBtn.classList.add('animate-spin');
setTimeout(() => {
refreshBtn.classList.remove('animate-spin');
updateDashboard();
}, 1000);
});
}
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
initDOMReferences();
initTabs();
initRefresh();
// Staggered entrance animation
setTimeout(() => {
updateDashboard();
}, 300);
});
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'Tab') {
document.body.classList.add('keyboard-nav');
}
});
document.addEventListener('mousedown', () => {
document.body.classList.remove('keyboard-nav');
});
</script>
</body>
</html>