Skip to content
GamerXVersePublic

About

Get your care you wanted, in time.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Clinic Ops — Task 1

Python operational scheduling engine and FastAPI API. Simulated clinic data; suggested operational priorities require staff confirmation. This is not a medical triage, diagnostic, or treatment system.

Status

The supplied workspace was empty. No source patient dataset or existing stack was available. data/demo_patients.json is explicitly generated demo data, not a replacement for the missing dataset. Integrating and validating the actual schema remains pending. Only Task 1 was included in the supplied instructions.

Run

Python 3.11+ recommended (verified with 3.14).

python3 -m venv .venv
.venv/bin/pip install -r requirements.lock.txt
.venv/bin/python -m pytest -q
.venv/bin/python -m clinic_ops --traffic SURGE
.venv/bin/uvicorn clinic_ops.api:app --host 127.0.0.1 --port 8000

API documentation: http://127.0.0.1:8000/docs

curl -s http://127.0.0.1:8000/session -H 'Content-Type: application/json' -d '{"traffic":"BUSY","rooms":2}'
curl -s http://127.0.0.1:8000/advance -H 'Content-Type: application/json' -d '{"minutes":15}'
curl -s http://127.0.0.1:8000/events -H 'Content-Type: application/json' -d '{"type":"override","id":"DEMO-004","priority":"PRIORITY","actor":"demo-staff","reason":"Staff review"}'
curl -s http://127.0.0.1:8000/compare -H 'Content-Type: application/json' -d '{"traffic":"SURGE","rooms":2}'

GET /state exposes queue, score components, patients, model recommendations, staff decisions, room occupancy, metrics and audit events. GET /evaluation returns synthetic holdout metrics. The CLI saves evaluation and comparison JSON under artifacts/. No performance improvement is hardcoded.

Input contract

Use a JSON array or { "patients": [...] }. Each record accepts id, name, age, arrivalTime, symptoms, summary, estimatedServiceMinutes, department, and vitals. Recognized model vitals are heartRate, oxygenSaturation (percent), and temperature (Celsius). Arrival must be HH:MM or ISO-8601. Session dates default to 2026-01-01, UTC. Naive timestamps assume UTC; aware timestamps convert to UTC. Invalid arrivals, non-object records, and duplicate IDs are reported and skipped. Missing age and service duration use explicit warned defaults; malformed vitals are omitted. Unknown fields are ignored. Source files are never rewritten.

.venv/bin/python -m clinic_ops --patients /absolute/path/patients.json --date 2026-09-29

API /session and /compare accept patients, session_date, and rooms. Use the default session date for built-in demo scenarios.

Model and scheduling

A depth-limited decision tree is used because its complete prediction path is inspectable. It is trained deterministically on 2,400 synthetic feature rows with heuristic labels; 600 held-out synthetic rows produce the recorded accuracy, per-class precision/recall/F1 and confusion matrix. These measure imitation of demo rules only. They provide no evidence of clinical accuracy. The API returns confidence: null; demoLeafClassShare is an uncalibrated leaf proportion. Missing vitals have explicit defaults and a missingness feature.

Queue score = urgency + wait + aging − service cost. Default urgency multipliers are 0/1/3/7 times 35. Wait adds 0.4 points/minute; aging adds (max(0, wait − 30)/10)^2; service costs 0.3 points/minute. Aging is unbounded, so it can eventually outweigh any finite urgency boost. This is an operational demo fairness policy, not a clinical escalation protocol. Weights are validated and configurable; positive aging is mandatory. Arrival time and ID break ties. Only arrived patients are eligible. Free enabled rooms take the next patient; consultations are non-preemptive. All rooms are interchangeable; department compatibility is not modeled.

POST /events supports:

  • confirm: id, actor, optional reason; retains original model recommendation.
  • override: id, actor, priority, optional reason; appends audit history.
  • service: id, minutes; updates a consultation that has not started.
  • room: room ID as string, enabled boolean; occupied rooms finish existing work.
  • arrival: patient object; unique ID, arrival at or after the current clock.
  • weights: object with urgency, wait, aging, service, aging_after.

Simulation processes arrivals/completions chronologically, recalculates the queue at dispatch and events, and advances deterministically. Staff decisions may be recorded for future arrivals. Already-started consultations are immutable. Automatic dispatch is simulated only; it does not represent staff confirmation.

FIFO comparison replays the same input arrivals, service durations and room capacity from the beginning, independently of a running session or its edits. Wait is measured at consultation start. Throughput uses completed visits divided by elapsed simulated hours. Queue history records event snapshots (including zero-time changes), suitable for a step chart. Estimated savings are FIFO mean wait minus optimized mean wait; negative values are retained.

Boundaries

Local, single-process demo with one shared in-memory session. Staff actor is an audit label, not authenticated identity. State resets on restart. Production use would require authentication, persistent audit storage, independently validated modeling and clinical governance. The engine never claims diagnosis, treatment determination, or guaranteed outcomes.

Task 2 dashboard

The dashboard is served by the same FastAPI process, with no separate frontend build or Node runtime required. Start it with:

.venv/bin/uvicorn clinic_ops.api:app --host 127.0.0.1 --port 8001

Open http://127.0.0.1:8001/ (API docs at /docs). JavaScript modules and CSS live in web/. All simulation state, recommendations, evaluation and comparisons come from the Python API. No patient or performance values are embedded in the UI.

  • Overview: current waiting population, suggested next, searchable and filterable queue, display sorting, rooms, queue trend, recent events.
  • Patient drawer: original recommendation, decision path, score components, staff decision and service estimate. Confirm/override requires a staff label.
  • Analytics: full-shift FIFO versus optimized replay using current patient service estimates and weights; average/median/maximum waits, priority-level waits, throughput and event-based queue charts. Negative savings remain visible.
  • Model Insights: actual synthetic holdout metrics, feature importance, confusion matrix and model limitations.
  • Settings: validated optimizer weights, defaults and room availability.

A fresh workspace opens paused at 09:30 in a BUSY demo, generated by advancing the real engine 30 minutes. Reloading resumes the existing session snapshot in a paused state. Start advances five simulated minutes per one-second interval; Pause stops new advances. +5 min advances once. Load changes and Reset start at 09:00 and clear staff decisions. Opening a patient or Settings pauses the simulation so staff can review a stable record. Rows animate their position changes, unless the browser requests reduced motion.

The top clinic status is calculated from live state: HIGH LOAD means at least 8 waiting or a longest wait of 30+ minutes; BUSY means at least 3 waiting; otherwise NORMAL. These are demo operational thresholds, not clinical thresholds. The selected traffic profile controls arrival spacing independently of live status.

Analytics replays the complete input cohort; it is not a measurement of time saved so far. Both policies receive identical patients, room counts and service durations. Live staff decisions and room availability changes are explicitly excluded from that replay. Model recommendations remain unmodified by review.

GET /session returns an optional session snapshot without creating state; GET /defaults exposes recommended weights. POST /session and POST /compare now accept a weights object. Metrics additionally expose currentAverageWait, currentLongestWait, waitingCount, and waitByPriority. State includes the traffic profile and actual consultation start/completion times.

Desktop and tablet layouts preserve a compact queue. Narrow screens scroll the table within its container. Native dialogs provide keyboard focus containment and Escape-to-close. Loading, empty, filtered-empty and error states are included.

Verification evidence is in artifacts/verification-task2.md; screenshots are in artifacts/. Task 3 instructions have not yet been supplied.

Task 3 intro, demo and visual refinement

Start the same server on port 8001. Routes now are:

  • /: Three.js product introduction with a working clinic model.
  • /dashboard: existing operational workspace, now in red, white and charcoal.
  • /dashboard#analytics, #model, #settings: existing dashboard views.
  • Old root hash links such as /#model redirect to the matching dashboard view.

The intro's patient tokens use the actual waiting cohort from a SURGE snapshot at 09:30. Arrival order and optimized order contain exactly the same IDs. The scene interpolates token positions; it does not simulate invented treatment or claim that reordering changes a patient's health. Visible token IDs and the HTML order strip correspond to the backend result.

GET /demo/intro calculates and caches read-only evidence from the existing engine, including both full-shift policy replays. It does not modify the live session. Proof shows average waiting, priority/urgent waiting and routine waiting so the trade-off is visible. Every number is derived from the replay.

Start the guided demo and Open this scenario in Analytics explicitly start a fresh SURGE scenario at 09:30 via POST /demo/start. The introductory snapshot and dashboard queue therefore match. This resets the shared in-memory session. Normal Open Dashboard links preserve the current session. The optional guide links Queue → Analytics → Model Insights, and can be dismissed or reopened without resetting state. Simulation pauses when the page is hidden.

The room rail contains one small Three.js staff-review clipboard. It is static at rest, with a tiny finite orientation change when room availability changes. The canvas is reused across queue updates, rather than rebuilding WebGL scenes.

Graphics and performance

  • Three.js is pinned in package-lock.json, bundled/minified with esbuild, and served locally from web/vendor/; no runtime CDN or external assets.
  • Pixel ratio is capped at 1.5. The scene uses simple geometry, one shadow light, a 1024px shadow map, and a fixed orthographic camera. No bloom or postprocessing.
  • Rendering is demand-driven. No continuous RAF runs at rest. Hidden/offscreen scenes stop requesting frames. Reduced motion applies queue positions directly.
  • WebGL-unavailable and lost-context states preserve the interactive HTML queue and real proof numbers. Three.js does not gate dashboard operations.
  • Textures, materials, geometry, observers and renderer resources are disposed on page exit. Three.js license is included in web/vendor/THREE-LICENSE.txt.

The bundled files are included, so Python alone still runs the application. To regenerate the bundle after updating frontend dependencies:

npm ci
npm run vendor
npm run check
.venv/bin/python -m pytest -q

Read artifacts/verification-task3.md for the final flow checks and design audit.

Vercel Drop package

releases/Clinic-Ops-Vercel.zip contains the complete project source and bundled frontend, excluding environments, installed dependencies and caches. Follow DEPLOY.md to upload it through Vercel Drop. The supported Vercel entry point is app.py (FastAPI); it enables per-browser-tab portable demo sessions. This supersedes the shared in-memory session limitation for hosted deployments.

The browser carries scenario inputs and an event journal between requests; Python reconstructs the state and computes every recommendation and metric. No database or additional service is required for this demo. The original clinic_ops.api:app entry point keeps the local shared-session behavior.

About

Get your care you wanted, in time.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages