Skip to content

Day 5:deterioration alert banner, HbA1c chart reference lines, priori…#5

Merged
deshanekanayaka merged 2 commits into
mainfrom
dev
Jun 4, 2026
Merged

Day 5:deterioration alert banner, HbA1c chart reference lines, priori…#5
deshanekanayaka merged 2 commits into
mainfrom
dev

Conversation

@deshanekanayaka

@deshanekanayaka deshanekanayaka commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Changes

backend/controllers/patientController.js

  • Fixed JSON_ARRAYAGG syntax error — moved ORDER BY into the inner
    subquery for MySQL 8 compatibility
  • Sparkline subquery added to getAllPatients — returns last 5 scored
    visits per patient as a JSON array (oldest→newest) for future use

frontend/src/pages/Dashboard.jsx

  • Added deterioration alert banner — appears when one or more patients
    have moved to a higher risk category since their previous visit
  • Banner is dismissible via an ✕ button and resets on every data refresh
  • worsening count derived from already-loaded patients state — no extra
    API call

frontend/src/components/PriorityTable.jsx

  • Removed TREND column (sparkline + arrow) — removed after review
  • Fixed RISK SCORE header alignment — changed px-4 to px-2 to match
    TableCell base padding

Summary by CodeRabbit

  • New Features
    • Added risk score sparkline visualization to track patient history trends
    • Introduced deterioration alert banner on dashboard with dismiss control
    • Included worsening patient count metric in stat cards for quick overview

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@deshanekanayaka, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44b18245-2fe2-43a9-9127-7f71b81ae2d8

📥 Commits

Reviewing files that changed from the base of the PR and between 1db2438 and 8512c2b.

📒 Files selected for processing (1)
  • frontend/src/pages/Dashboard.jsx
📝 Walkthrough

Walkthrough

The PR implements a patient deterioration alert by adding sparkline risk score aggregation in the backend, tracking worsening patient trends in the Dashboard frontend, and rendering a dismissible alert when deterioration is detected. Supporting styling adjustments are made to the PriorityTable component.

Changes

Patient Deterioration Alert Feature

Layer / File(s) Summary
Backend sparkline data aggregation
backend/controllers/patientController.js
SQL getAllPatients query extends projection with a sparkline JSON array aggregating up to 5 earliest risk scores per patient; results mapping parses the JSON string to array with fallback error handling.
Dashboard deterioration alert UI
frontend/src/pages/Dashboard.jsx
Dashboard adds alertDismissed state that resets when patients refresh, extends counts memo to compute worsening patient count, and renders a conditional deterioration alert banner (visible when counts.worsening > 0 and not dismissed) with dismiss control.
PriorityTable styling updates
frontend/src/components/PriorityTable.jsx
Helper functions are re-emitted unchanged; Risk Score column header styling is adjusted for alignment and text formatting; inline comment removed from actions section.

Sequence Diagram(s)

sequenceDiagram
  participant getAllPatients as getAllPatients Query
  participant Database
  participant ResultMapping as Result Mapping
  participant Dashboard
  participant AlertBanner as Alert Banner UI
  
  getAllPatients->>Database: SELECT with JSON_ARRAYAGG(risk_score)
  Database-->>ResultMapping: row.sparkline JSON string
  ResultMapping-->>Dashboard: parsed sparkline array
  Dashboard->>Dashboard: compute counts.worsening
  Dashboard->>AlertBanner: render if worsening > 0 && !dismissed
  AlertBanner->>Dashboard: dismiss button clicked
  Dashboard-->>AlertBanner: hide until next refresh
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • deshanekanayaka/diacify#3: Related rework of getAllPatients and per-patient trend computation for the same patient listing logic.
  • deshanekanayaka/diacify#4: Related changes to backend/controllers/patientController.js patient listing query and Dashboard integration at the controller/query level.

Poem

🐰 A sparkline twinkles bright,
Five risk scores held in light,
When trends begin to fall,
The alert answers the call,
Dismissible, yet ever in sight! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references deterioration alert banner and priority table (HbA1c reference), matching the actual changes across Dashboard and PriorityTable components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
frontend/src/pages/Dashboard.jsx (1)

23-26: ⚡ Quick win

Alert re-appears on every data refresh, even if user dismissed it.

The useEffect depends on [patients], so the alert will re-appear whenever the patients array reference changes—even if the worsening count hasn't increased or the same patients are still worsening. This creates poor UX: a user dismisses the alert, then the list auto-refreshes (or they add a non-worsening patient), and the alert pops back up.

Consider tracking dismissed state across refreshes unless the worsening count increases or specific worsening patient IDs change.

♻️ Proposed improvement to reset only when worsening count increases
+ const prevWorseningRef = useRef(0);
+
- // Reset dismissal whenever the patients list refreshes so the banner reappears if still relevant
  useEffect(() => {
-   setAlertDismissed(false);
- }, [patients]);
+   // Only reset if worsening count increased
+   const currentWorsening = patients.filter(p => p.trend === 'worsening').length;
+   if (currentWorsening > prevWorseningRef.current) {
+     setAlertDismissed(false);
+   }
+   prevWorseningRef.current = currentWorsening;
+ }, [patients]);

Alternatively, track a Set of worsening patient IDs to detect when new patients deteriorate.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/Dashboard.jsx` around lines 23 - 26, The effect that
resets alert dismissal (useEffect that calls setAlertDismissed(false)) runs on
any change to the patients array reference, causing the alert to reappear on
refresh; change the dependency and logic so dismissal is only reset when
worsening state actually increases or new worsening patients appear—compute a
derived value like worseningCount or a Set of worsening patient IDs (from
patients) and depend on that (e.g., worseningCount or worseningIds) in the
useEffect, or compare previous worseningIds to current and only call
setAlertDismissed(false) when the count increases or new IDs are present; update
the effect that currently depends on patients to use that derived worsening
indicator instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/controllers/patientController.js`:
- Around line 198-208: The sparkline SQL subquery currently selects the 5 oldest
visits (ORDER BY visit_date ASC LIMIT 5) instead of the 5 most recent; modify
the subquery used for the sparkline aggregation so it first selects the most
recent 5 rows (ORDER BY visit_date DESC LIMIT 5) for patient_id = p.patient_id
and then, if you need the array ordered oldest→newest, wrap that limited set in
a nested query that re-orders by visit_date ASC before JSON_ARRAYAGG; key
symbols: sparkline, visits, risk_score, visit_date, patient_id / p.patient_id.

In `@frontend/src/pages/Dashboard.jsx`:
- Around line 69-79: The counts computation in the useMemo (const counts)
assumes patient.trend always exists; update the patients.forEach block to
defensively handle missing/null trend by normalizing it before comparison (e.g.,
derive a local const trend = (patient.trend || '').toLowerCase() or use optional
chaining) and then test trend === 'worsening'; ensure you reference the same
pattern used for risk_category to avoid silent misses in worsening counts.

---

Nitpick comments:
In `@frontend/src/pages/Dashboard.jsx`:
- Around line 23-26: The effect that resets alert dismissal (useEffect that
calls setAlertDismissed(false)) runs on any change to the patients array
reference, causing the alert to reappear on refresh; change the dependency and
logic so dismissal is only reset when worsening state actually increases or new
worsening patients appear—compute a derived value like worseningCount or a Set
of worsening patient IDs (from patients) and depend on that (e.g.,
worseningCount or worseningIds) in the useEffect, or compare previous
worseningIds to current and only call setAlertDismissed(false) when the count
increases or new IDs are present; update the effect that currently depends on
patients to use that derived worsening indicator instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff694d16-7136-4e23-8a69-dc4f2f72e057

📥 Commits

Reviewing files that changed from the base of the PR and between 6b5f9b9 and 1db2438.

⛔ Files ignored due to path filters (1)
  • backend/logs/error.log is excluded by !**/*.log
📒 Files selected for processing (3)
  • backend/controllers/patientController.js
  • frontend/src/components/PriorityTable.jsx
  • frontend/src/pages/Dashboard.jsx

Comment thread backend/controllers/patientController.js
Comment thread frontend/src/pages/Dashboard.jsx
@deshanekanayaka deshanekanayaka merged commit 801b4c5 into main Jun 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant