// ============================================================ // WELL VISIT / PREVENTIVE CARE TAB // ============================================================ (function () { 'use strict'; // ─── Human-readable labels ───────────────────────────────────────────────── var SCREEN_LABELS = { maternalDepression: 'Maternal/Caregiver Depression Screen (Edinburgh/PHQ)', developmentalScreening: 'Developmental Screening (ASQ / PEDS)', autismScreening: 'Autism Screening (M-CHAT-R)', developmentalSurveillance:'Developmental Surveillance', behavioralScreening: 'Social-Emotional/Behavioral Screening (ASQ:SE)', tobaccoAlcoholDrugs: 'Tobacco / Alcohol / Drug Use Screening (CRAFFT/AUDIT)', depressionSuicideRisk: 'Depression & Suicide Risk Screening (PHQ-A)', }; var PROC_LABELS = { newbornBlood: 'Newborn Blood Spot Screening (NBS)', newbornBilirubin: 'Newborn Bilirubin (TcB or TSB)', criticalCHD: 'Critical CHD Screening (Pulse Ox)', immunization: 'Immunizations Review & Update', anemia: 'Anemia Screening (Hgb/Hct)', lead: 'Lead Exposure Risk / Blood Lead Level', tuberculosis: 'Tuberculosis / Latent TB Risk Assessment', dyslipidemia: 'Dyslipidemia Screening (lipid panel)', sti: 'STI Screening (gonorrhea / chlamydia / syphilis)', hiv: 'HIV Screening', hepB: 'Hepatitis B Screening (HBsAg)', hepC: 'Hepatitis C Screening (anti-HCV)', suddenCardiacArrest:'Sudden Cardiac Arrest Risk Assessment', cervicalDysplasia: 'Cervical Dysplasia Screening (Pap smear)', }; var MEASURE_LABELS = { lengthHeight: 'Length / Height', weight: 'Weight', headCircumference: 'Head Circumference', weightForLength: 'Weight-for-Length', bmi: 'BMI', bloodPressure: 'Blood Pressure', }; var ORAL_LABELS = { assessment: 'Oral Health Risk Assessment', fluorideVarnish: 'Fluoride Varnish Application', fluorideSupplementation:'Fluoride Supplementation (if water <0.6 ppm)', }; var SENSORY_LABELS = { vision: 'Vision Screening', hearing: 'Hearing Screening', }; var VACCINE_FULL_NAMES = { HepB: 'Hepatitis B (HepB)', RV: 'Rotavirus (RV)', DTaP: 'DTaP (Diphtheria, Tetanus, Pertussis)', Hib: 'Hib (Haemophilus influenzae type b)', PCV: 'Pneumococcal (PCV)', IPV: 'Polio (IPV)', Flu_IIV: 'Influenza (IIV)', MMR: 'MMR (Measles, Mumps, Rubella)', VAR: 'Varicella (VAR)', HepA: 'Hepatitis A (HepA)', Tdap: 'Tdap (Tetanus, Diphtheria, Pertussis booster)', HPV: 'HPV (Human Papillomavirus)', MenACWY: 'Meningococcal ACWY (MenACWY)', MenB: 'Meningococcal B (MenB)', RSV_mAb: 'RSV Monoclonal Antibody (Nirsevimab/Beyfortus)', COVID: 'COVID-19', Dengue: 'Dengue (DEN4CYD / Dengvaxia)', Mpox: 'Mpox (JYNNEOS)', }; // ─── Init ────────────────────────────────────────────────────────────────── function init() { populateVisitSelect(); renderCatchUp(); renderFullSchedule(); document.getElementById('wv-visit-select').addEventListener('change', onVisitChange); document.querySelectorAll('.wv-subtab-btn').forEach(function (btn) { btn.addEventListener('click', function () { switchSubtab(btn.dataset.subtab); }); }); // Show first real visit by default var sel = document.getElementById('wv-visit-select'); if (sel && sel.value) onVisitChange(); } function populateVisitSelect() { var sel = document.getElementById('wv-visit-select'); if (!sel || typeof VISIT_AGES === 'undefined') return; var grouped = {}; VISIT_AGES.forEach(function (v) { if (!grouped[v.era]) grouped[v.era] = []; grouped[v.era].push(v); }); var eraNames = { prenatal: 'Prenatal', infancy: 'Infancy (0–12 mo)', earlyChildhood: 'Early Childhood (1–5 y)', middleChildhood: 'Middle Childhood (6–11 y)', adolescence: 'Adolescence (11–21 y)', }; Object.keys(grouped).forEach(function (era) { var og = document.createElement('optgroup'); og.label = eraNames[era] || era; grouped[era].forEach(function (v) { var opt = document.createElement('option'); opt.value = v.id; opt.textContent = v.label; og.appendChild(opt); }); sel.appendChild(og); }); // select newborn by default sel.value = 'newborn'; } function onVisitChange() { var visitId = document.getElementById('wv-visit-select').value; if (!visitId) return; renderVisitPanel(visitId); } function switchSubtab(name) { document.querySelectorAll('.wv-subtab-btn').forEach(function (b) { b.classList.toggle('active', b.dataset.subtab === name); }); document.querySelectorAll('.wv-subpanel').forEach(function (p) { p.classList.toggle('hidden', p.id !== 'wv-panel-' + name); }); } // ─── BY VISIT panel ─────────────────────────────────────────────────────── function renderVisitPanel(visitId) { var data = (typeof PERIODICITY !== 'undefined') ? PERIODICITY[visitId] : null; var codes = (typeof WELL_VISIT_CODES !== 'undefined') ? WELL_VISIT_CODES[visitId] : null; var panel = document.getElementById('wv-visit-detail'); if (!panel) return; if (!data) { panel.innerHTML = '

No data for this visit.

'; return; } var html = ''; // ── Billing codes ── if (codes) { html += '
'; html += '

Billing Codes

'; html += '
'; html += '
ICD-10' + esc(codes.icd10) + '
'; html += '
CPT' + esc(codes.cpt) + '
'; html += '
' + esc(codes.description) + '
'; html += '
'; } // ── Measurements ── var measDue = Object.keys(data.measurements || {}).filter(function (k) { return data.measurements[k] === 'dot' || data.measurements[k] === 'range'; }); if (measDue.length) { html += '
'; html += '

Measurements

'; html += '
'; measDue.forEach(function (k) { var isRange = data.measurements[k] === 'range'; html += '' + esc(MEASURE_LABELS[k] || k) + (isRange ? ' (range)' : '') + ''; }); html += '
'; } // ── Vaccines ── if (data.vaccines && data.vaccines.length) { html += '
'; html += '

Vaccines Due

'; html += '
'; data.vaccines.forEach(function (v) { var fullName = VACCINE_FULL_NAMES[v.vaccine] || v.vaccine; html += '
'; html += '
' + esc(fullName) + '
'; if (v.dose) html += 'Dose ' + esc(String(v.dose)) + ''; if (v.notes) html += '
' + esc(v.notes) + '
'; html += '
'; }); html += '
'; } // ── Screenings: sensory ── var sensoryItems = buildStatusItems(data.sensory || {}, SENSORY_LABELS); if (sensoryItems.length) { html += '
'; html += '

Sensory Screens

'; html += renderScreenItems(sensoryItems); html += '
'; } // ── Screenings: developmental / behavioral ── var devItems = buildStatusItems(data.developmental || {}, SCREEN_LABELS); if (devItems.length) { html += '
'; html += '

Developmental / Behavioral Screens

'; html += renderScreenItems(devItems); html += '
'; } // ── Procedures ── var procItems = buildStatusItems(data.procedures || {}, PROC_LABELS, ['immunization']); if (procItems.length) { html += '
'; html += '

Labs & Procedures

'; html += renderScreenItems(procItems); html += '
'; } // ── Oral Health ── var oralItems = buildStatusItems(data.oralHealth || {}, ORAL_LABELS); if (oralItems.length) { html += '
'; html += '

Oral Health

'; html += renderScreenItems(oralItems); html += '
'; } // ── Notes ── if (data.notes) { html += '
' + esc(data.notes) + '
'; } panel.innerHTML = html || '

No specific recommendations found for this visit.

'; } function buildStatusItems(obj, labels, exclude) { exclude = exclude || []; return Object.keys(obj).filter(function (k) { return obj[k] && obj[k] !== '' && exclude.indexOf(k) === -1; }).map(function (k) { return { key: k, status: obj[k], label: labels[k] || k }; }); } function renderScreenItems(items) { var html = '
'; items.forEach(function (item) { var statusClass = item.status === 'dot' ? 'wv-status-dot' : item.status === 'range' ? 'wv-status-range' : 'wv-status-risk'; var statusText = item.status === 'dot' ? 'Recommended' : item.status === 'range' ? 'In Range' : 'If at Risk'; html += '
'; html += '' + statusText + ''; html += '' + esc(item.label) + ''; html += '
'; }); html += '
'; return html; } // ─── CATCH-UP panel ─────────────────────────────────────────────────────── function renderCatchUp() { var panel = document.getElementById('wv-panel-catchup'); if (!panel || typeof CATCH_UP_SCHEDULE === 'undefined') return; var html = '
CDC 2025 Catch-up Schedule — minimum ages and intervals for each vaccine series. Applies when a child is behind on routine immunizations.
'; Object.keys(CATCH_UP_SCHEDULE).forEach(function (vaxKey) { var v = CATCH_UP_SCHEDULE[vaxKey]; var fullName = VACCINE_FULL_NAMES[vaxKey] || vaxKey; html += '
'; html += '

' + esc(fullName) + '

'; if (v.minimumAgeForDose1) { html += '
Minimum age for dose 1: ' + esc(v.minimumAgeForDose1) + '
'; } if (v.series && v.series.length) { html += ''; v.series.forEach(function (s) { html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; }); html += '
DoseMin AgeMin Interval from PrevNotes
Dose ' + esc(String(s.dose)) + '' + esc(s.minimumAge || '—') + '' + esc(s.minimumIntervalToPrev || '—') + '' + esc(s.notes || '') + '
'; } if (v.catchUpNotes) { var notes = Array.isArray(v.catchUpNotes) ? v.catchUpNotes : [v.catchUpNotes]; html += ''; } html += '
'; }); panel.innerHTML = html; } // ─── FULL SCHEDULE table ────────────────────────────────────────────────── function renderFullSchedule() { var panel = document.getElementById('wv-panel-schedule'); if (!panel || typeof PERIODICITY === 'undefined' || typeof VISIT_AGES === 'undefined') return; // Collect all vaccine keys that appear in any visit var allVaxKeys = {}; var visitIds = VISIT_AGES.map(function (v) { return v.id; }).filter(function (id) { return PERIODICITY[id] && PERIODICITY[id].vaccines; }); visitIds.forEach(function (id) { PERIODICITY[id].vaccines.forEach(function (v) { allVaxKeys[v.vaccine] = true; }); }); var vaxKeys = Object.keys(allVaxKeys); var visitLabels = VISIT_AGES.filter(function (v) { return visitIds.indexOf(v.id) !== -1; }); var html = '
'; html += ''; html += ''; visitLabels.forEach(function (v) { html += ''; }); html += ''; vaxKeys.forEach(function (vaxKey) { var fullName = VACCINE_FULL_NAMES[vaxKey] || vaxKey; html += ''; visitLabels.forEach(function (visit) { var vaxData = PERIODICITY[visit.id] && PERIODICITY[visit.id].vaccines; var match = vaxData && vaxData.find(function (v) { return v.vaccine === vaxKey; }); if (match) { var dose = match.dose ? String(match.dose) : '•'; var label = (typeof match.dose === 'number') ? '#' + dose : dose; html += ''; } else { html += ''; } }); html += ''; }); html += '
Vaccine' + esc(v.label) + '
' + esc(fullName) + '' + esc(label) + '
'; html += '

Dose number shown. Hover cells for notes. "#N" = routine dose N. "annual" / "seasonal" = per CDC guidance. "catch-up" = as needed.

'; panel.innerHTML = html; } function esc(str) { if (!str) return ''; return String(str) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"'); } // ─── Wire up ─────────────────────────────────────────────────────────────── document.addEventListener('DOMContentLoaded', function () { // Run when tab becomes visible (lazy init) var initialized = false; document.addEventListener('tabChanged', function (e) { if (e.detail && e.detail.tab === 'wellvisit' && !initialized) { initialized = true; init(); } }); }); })();