pediatric-ai-scribe-v3/docs/logic/bedside-and-calculators.md
2026-05-09 00:40:45 +02:00

71 lines
3.1 KiB
Markdown

# Bedside Tools And Calculators
This doc describes the current responsibilities of the bedside/reference area
without hardcoded line numbers. The source of truth is the code plus the
calculator test suite.
## Areas
| Area | Files | Notes |
|---|---|---|
| Bedside emergencies | `public/js/bedside/*` | ES-module pocket for emergency reference sections. |
| Core calculators | `public/js/calc-math.js`, `public/js/calculators.js`, `public/js/drugs-loader.js` | `calc-math.js` keeps a dual browser/CommonJS wrapper so tests can `require()` the same formulas used in browser. |
| Drug data | `public/data/drugs.json` | Loaded by `drugs-loader.js`; fallback constants remain in some UI modules for resilience. |
| PE Guide | `public/js/peGuide.js`, `src/routes/peGuide.js`, `public/components/pe-guide.html` | Structured PE reference plus AI narrative endpoint. |
| Well-visit schedule | `public/js/wellVisit/scheduleData.js`, `public/data/well-visit/schedule.json`, `public/js/wellVisit.js` | Schedule JSON is loaded and applied to legacy globals used by the UI. |
| Milestones | `public/js/milestonesData.js`, `public/js/milestones.js`, `src/routes/milestones.js`, `src/routes/adminMilestones.js` | DB-backed milestone data with static fallback. |
## Calculator Accuracy Rule
Do not change clinical formulas or reference data without tests. Add or update
test vectors first, then change data/code, then run `npm test`.
Protected examples include:
- APLS and Best Guess weights.
- Maintenance fluids.
- Parkland burn fluids and Lund-Browder TBSA.
- PRAM, Westley croup, GCS, Apgar, bilirubin, BMI, BP, growth, Fenton, and
equipment sizing.
- Emergency medication dosing in resuscitation, anaphylaxis, seizure,
sedation, agitation, emesis, trauma, and NRP modules.
## Schedule Data
Well-visit schedule data now lives in JSON:
- `public/data/well-visit/schedule.json`
- loader: `public/js/wellVisit/scheduleData.js`
- consumer: `public/js/wellVisit.js`
- server enrichment: `src/routes/wellVisit.js`
The loader exposes the legacy names expected by the existing UI, including
`VISIT_AGES`, `PERIODICITY`, `CATCH_UP_SCHEDULE`, `GROWTH_REFERENCE`, and BMI
classification data.
## Bedside ES Modules
The bedside tab is intentionally split by emergency/reference topic. Keep new
sections small and self-contained. Shared formatting/helpers should stay in the
bedside support modules rather than growing `calculators.js` again.
## PE Guide
The PE Guide is partly deterministic reference UI and partly AI-assisted
narrative generation:
- Browser code collects assessed systems, selected normals/abnormals, and
clinician notes.
- `POST /api/generate-pe-narrative` wraps user-derived text with
`wrapUserText` and applies `INJECTION_GUARD` before `callAI`.
- The route returns a generated narrative plus summary metadata.
## Extension Checklist
When adding or changing a bedside/calculator feature:
1. Add test vectors for any clinical formula or reference boundary.
2. Keep UI state local unless persistence is explicitly required.
3. Avoid PHI storage in reference/calculator-only areas.
4. Prefer small files for new bedside sections.
5. Run `node --check` on touched scripts and `npm test` before deploy.