Skip to content

feat: refactor ReportViewer for Account report#16419

Closed
abhimanyurajeesh wants to merge 12 commits into
developfrom
ENG-485
Closed

feat: refactor ReportViewer for Account report#16419
abhimanyurajeesh wants to merge 12 commits into
developfrom
ENG-485

Conversation

@abhimanyurajeesh

@abhimanyurajeesh abhimanyurajeesh commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

This is a follow up PR #16418 (review)

image image

This PR matches the requested UI and made few fixes

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

  • New Features

    • View account- and patient-scoped reports and templates from facility, account, and patient sections.
    • Generate Report dropdown: on-demand template lists for creating reports.
  • Bug Fixes

    • Improved error handling for report download and print failures.
    • PDF preview now opens in a new browser tab instead of forcing print.
  • Improvements

    • Print action shows loading/disabled state while printing.
    • Report viewer supports multiple report types and customizable view links.
    • Navigation UI omits the right-arrow when not applicable.

@abhimanyurajeesh abhimanyurajeesh requested review from a team and Copilot June 2, 2026 18:20
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 2, 2026

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: 60945bd
Status: ✅  Deploy successful!
Preview URL: https://5c4301f7.care-preview-a7w.pages.dev
Branch Preview URL: https://eng-485.care-preview-a7w.pages.dev

View logs

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)

Walkthrough

ReportViewer generalized to accept associatingId and optional reportType; queries, creation payloads, and polling updated; print/download flows hardened with state and response checks; ReportSubTab supports custom view URLs; encounter, patient, and account report routes wired; FilePreviewDialog print action replaced by open-in-browser.

Changes

Report Viewer Generalization and Hardening

Layer / File(s) Summary
ReportViewer prop contract and print state management
src/pages/Encounters/ReportViewer.tsx
associatingId replaces encounterId; reportType?: ReportType added (default DISCHARGE_SUMMARY); isPrinting state added and print/download UI hardened.
Report queries and creation with new parameters
src/pages/Encounters/ReportViewer.tsx
React Query list keys, listing params, report creation/generate payloads, polling refresh logic, and hook dependencies updated to use associatingId and reportType.
Download and print error hardening
src/pages/Encounters/ReportViewer.tsx
handleDownload and handlePrint validate fetch response.ok, throw on failure, manage isPrinting, and clear state on both success and error.
ReportSubTab callback extension and generator component
src/components/Files/ReportSubTab.tsx, src/components/Files/GenerateReportDropdown.tsx
ReportTabProps adds optional getViewUrl(reportId); ReportSubTab.handleView prefers getViewUrl then falls back to built facility/patient/encounter preview or file view; GenerateReportDropdown added to fetch templates and build template links.
Route definitions for encounter, patient, and facility reports
src/Routers/routes/ConsultationRoutes.tsx, src/Routers/routes/FacilityRoutes.tsx
ConsultationRoutes now passes associatingId to ReportViewer for encounter routes and adds patient-scoped report routes; FacilityRoutes imports ReportViewer and ReportType and adds account report routes rendering ReportViewer with `{ associatingId: accountId, templateSlug
AccountShow templates dropdown and consumer wiring
src/pages/Facility/billing/account/AccountShow.tsx
Adds controlled dropdownOpen, queries active account_report templates when opened, renders template links under a "reports" dropdown, and supplies getViewUrl to ReportSubTab.
FilePreviewDialog PDF action simplified
src/components/Common/FilePreviewDialog.tsx
Removed print-related imports and replaced iframe-based print action with "open in browser" via window.open(fileUrl, "noopener,noreferrer").
NavigationHelper right-arrow control
src/components/ui/multi-filter/utils/navigation-helper.tsx
NavigationHelper now accepts hideRight?: boolean; right-arrow UI only renders when !isActiveFilter && !hideRight.

Possibly related PRs

  • ohcnetwork/care_fe#16418: #16418 modifies FilePreviewDialog PDF handling (adds iframe-based print), which is directly related to this PR's change to remove/replace that print flow.

Suggested labels

needs testing, needs review, Type Changes

Suggested reviewers

  • nihal467
  • Jacobjeevan
  • amjithtitus09
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning PR description is incomplete and lacks required detail. While it references the issue and includes screenshots, it provides minimal explanation of changes, missing structured information about what was changed and why. Add detailed bullet points explaining each major change (e.g., ReportViewer refactoring, new routes, component updates). Clarify the relationship to the prior PR and explain how these changes address the UI requirements shown in the screenshots.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly describes the main change: refactoring ReportViewer to support Account report functionality, which aligns with the substantial updates across routing, component props, and report type handling.

✏️ 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 ENG-485

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

@greptile-apps

greptile-apps Bot commented Jun 2, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors ReportViewer to be generic by replacing the encounterId prop with associatingId and adding a reportType prop, enabling the same component to serve both encounter discharge summaries and billing account reports. It also adds a dedicated route for account report viewing, wires up a getViewUrl callback in ReportSubTab, and moves the print loading state into ReportViewer (removing the duplicate print button from FilePreviewDialog).

  • ReportViewer is now reusable across entity types: a new reportType prop (defaulting to \"discharge_summary\") is passed through to all API calls, and a new /facility/:facilityId/billing/account/:accountId/reports/:reportId route renders it for account reports.
  • ReportSubTab gains an optional getViewUrl callback so callers can control where the "view" action navigates, with the existing encounter URL as the fallback.
  • The print button is removed from FilePreviewDialog (where it was duplicated) and consolidated in ReportViewer, gaining a spinner state and response.ok guards on fetch calls.

Confidence Score: 4/5

The change is well-scoped and the core routing and prop-threading logic is correct. The two findings are minor: a loose string type where the ReportType enum should be used, and an edge case where the print button could stay permanently disabled if the iframe never fires its load event.

The refactor correctly generalises ReportViewer for account reports without breaking existing encounter report flows. The reportType prop accepts a plain string instead of the ReportType enum, and isPrinting has no timeout safety net if iframe.onload never fires — both are small, addressable issues that don't affect the happy path.

src/pages/Encounters/ReportViewer.tsx — reportType typing and isPrinting reset safety.

Important Files Changed

Filename Overview
src/pages/Encounters/ReportViewer.tsx Renamed encounterId to associatingId to make the component generic; added reportType prop (default "discharge_summary"); added isPrinting spinner state and response.ok guards on fetch calls. Minor: reportType is typed as string instead of the ReportType enum, and isPrinting could get stuck if iframe.onload never fires.
src/components/Files/ReportSubTab.tsx Added optional getViewUrl prop; navigation logic refactored to prefer getViewUrl over the hardcoded encounter URL pattern. Clean and correct.
src/Routers/routes/FacilityRoutes.tsx Added new route /facility/:facilityId/billing/account/:accountId/reports/:reportId rendering ReportViewer with associatingId and reportType="account_report". Straightforward and correct.
src/Routers/routes/ConsultationRoutes.tsx Updated prop name from encounterId to associatingId in both existing ReportViewer usages to match the refactored interface.
src/components/Common/FilePreviewDialog.tsx Removed the print button (iframe-based print logic and unused imports) since printing is now handled inside ReportViewer directly.
src/pages/Facility/billing/account/AccountShow.tsx Passes getViewUrl to ReportSubTab so account report rows navigate to the new dedicated ReportViewer route. Correct integration.

Reviews (1): Last reviewed commit: "feat: refactor ReportViewer for Account ..." | Re-trigger Greptile

Comment thread src/pages/Encounters/ReportViewer.tsx
Comment thread src/pages/Encounters/ReportViewer.tsx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the existing encounter-focused ReportViewer so it can also be used to view Account reports from the billing flow, aligning the UI/UX with the follow-up PR feedback for ENG-485.

Changes:

  • Generalizes ReportViewer to use an associatingId and configurable reportType, and adds a printing/loading UI state.
  • Adds an account-report viewer route and wires the Account “Reports” tab to navigate to it.
  • Removes the PDF print button from the generic FilePreviewDialog (print is now handled in ReportViewer).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Routers/routes/FacilityRoutes.tsx Adds a new account report viewer route using ReportViewer.
src/Routers/routes/ConsultationRoutes.tsx Updates encounter report routes to the new ReportViewer prop name.
src/pages/Facility/billing/account/AccountShow.tsx Makes Account “Reports” tab navigate to the new report viewer route.
src/pages/Encounters/ReportViewer.tsx Refactors report querying/generation + adds print loading UX and fetch validation.
src/components/Files/ReportSubTab.tsx Adds getViewUrl to support custom “view report” navigation targets.
src/components/Common/FilePreviewDialog.tsx Removes PDF print button from the generic file preview dialog.
Comments suppressed due to low confidence (1)

src/pages/Encounters/ReportViewer.tsx:372

  • The print iframe is appended without being hidden/styled, so it can show up as a visible blank frame in the page layout on some browsers.
      const iframe = document.createElement("iframe");
      iframe.src = blobUrl;

Comment thread src/pages/Encounters/ReportViewer.tsx Outdated
Comment thread src/pages/Encounters/ReportViewer.tsx
Comment thread src/pages/Encounters/ReportViewer.tsx
Comment thread src/pages/Encounters/ReportViewer.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@src/pages/Encounters/ReportViewer.tsx`:
- Around line 120-131: The queryKey arrays for the report fetching queries (the
one using query(reportApi.listReports, ...) and the polling/"fresh" query) must
include the dynamic reportType so cache entries are unique per report_type;
update the queryKey values (the arrays referenced as queryKey: ["reports",
associatingId, "template", effectiveTSlug]) to include reportType (e.g., add
reportType into the array) for both the main query and the fresh/polling query
so associatingId + effectiveTSlug + reportType produce distinct cache keys.

In `@src/Routers/routes/FacilityRoutes.tsx`:
- Around line 108-117: Replace the hard-coded report type string in the route's
ReportViewer props with the shared enum constant: import ReportType and change
the reportType prop from "account_report" to ReportType.ACCOUNT_REPORT in the
route handler for
"/facility/:facilityId/billing/account/:accountId/reports/:reportId"; this
ensures type-safety and consistency with usages like AccountShow.tsx and avoids
mismatches if the constant changes.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f69fc122-c7e9-4f45-a1a7-217f404e22c0

📥 Commits

Reviewing files that changed from the base of the PR and between 87ee27c and c95a757.

📒 Files selected for processing (6)
  • src/Routers/routes/ConsultationRoutes.tsx
  • src/Routers/routes/FacilityRoutes.tsx
  • src/components/Common/FilePreviewDialog.tsx
  • src/components/Files/ReportSubTab.tsx
  • src/pages/Encounters/ReportViewer.tsx
  • src/pages/Facility/billing/account/AccountShow.tsx
💤 Files with no reviewable changes (1)
  • src/components/Common/FilePreviewDialog.tsx

Comment thread src/pages/Encounters/ReportViewer.tsx Outdated
Comment thread src/Routers/routes/FacilityRoutes.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/pages/Encounters/ReportViewer.tsx (1)

120-132: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

reportType is still missing from the query key.

report_type is a dynamic query param (Line 125), but the queryKey on Line 120 doesn't include reportType. Two report types sharing the same associatingId/effectiveTSlug would collide on the same cache entry. The same omission exists in the "fresh" polling key (Lines 204-210).

🐛 Proposed fix
-    queryKey: ["reports", associatingId, "template", effectiveTSlug],
+    queryKey: ["reports", associatingId, "template", effectiveTSlug, reportType],

And for the fresh query (Lines 204-210):

       queryKey: [
         "reports",
         associatingId,
         "template",
         effectiveTSlug,
+        reportType,
         "fresh",
       ],
🤖 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 `@src/pages/Encounters/ReportViewer.tsx` around lines 120 - 132, The queryKey
used for fetching reports (the array starting with "reports", associatingId,
"template", effectiveTSlug) omits the dynamic reportType, causing cache
collisions; update the queryKey to include reportType (same place where
queryParams sets report_type) so the key becomes unique per reportType, and make
the analogous change to the "fresh" polling key used later (the fresh
query/polling key array) to also include reportType; locate symbols queryKey,
associatingId, effectiveTSlug, reportType and the query(reportApi.listReports,
...) call to apply the fix.
🤖 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.

Duplicate comments:
In `@src/pages/Encounters/ReportViewer.tsx`:
- Around line 120-132: The queryKey used for fetching reports (the array
starting with "reports", associatingId, "template", effectiveTSlug) omits the
dynamic reportType, causing cache collisions; update the queryKey to include
reportType (same place where queryParams sets report_type) so the key becomes
unique per reportType, and make the analogous change to the "fresh" polling key
used later (the fresh query/polling key array) to also include reportType;
locate symbols queryKey, associatingId, effectiveTSlug, reportType and the
query(reportApi.listReports, ...) call to apply the fix.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 387abe64-7911-45c3-b8cb-e300f4cc2401

📥 Commits

Reviewing files that changed from the base of the PR and between c95a757 and e917f54.

📒 Files selected for processing (2)
  • src/Routers/routes/FacilityRoutes.tsx
  • src/pages/Encounters/ReportViewer.tsx

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 320
✅ Passed 319
❌ Failed 1
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #9459

Copilot AI review requested due to automatic review settings June 3, 2026 07:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

src/pages/Encounters/ReportViewer.tsx:372

  • The print iframe is appended without being hidden. This can cause a visible blank iframe to appear in the page layout during printing. Hide it like the previous implementation to avoid UI flicker/layout shifts.
      const blob = await response.blob();
      const blobUrl = window.URL.createObjectURL(blob);
      const iframe = document.createElement("iframe");
      iframe.src = blobUrl;

Comment thread src/pages/Encounters/ReportViewer.tsx
Comment thread src/pages/Encounters/ReportViewer.tsx
Comment thread src/pages/Encounters/ReportViewer.tsx
Comment thread src/pages/Encounters/ReportViewer.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@src/pages/Facility/billing/account/AccountShow.tsx`:
- Around line 173-183: Replace the raw string literals in the useQuery call with
the typed constants used elsewhere: use ReportType.ACCOUNT_REPORT for
template_type and, if available, the TemplateStatus enum/value for status (e.g.,
TemplateStatus.ACTIVE); update the queryParams passed to
templateApi.listTemplates accordingly and ensure types align with listTemplates'
request typing (adjust generics or casting if needed) so query params remain
consistent and type-safe.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d2b24e73-06a4-4e76-8036-b3dda6e6fd50

📥 Commits

Reviewing files that changed from the base of the PR and between e917f54 and 73c196c.

📒 Files selected for processing (2)
  • src/Routers/routes/FacilityRoutes.tsx
  • src/pages/Facility/billing/account/AccountShow.tsx

Comment thread src/pages/Facility/billing/account/AccountShow.tsx
Copilot AI review requested due to automatic review settings June 3, 2026 07:14

This comment was marked as resolved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pages/Encounters/ReportViewer.tsx (1)

348-348: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add report file extension to download filename in ReportViewer
ReportViewer’s handleDownload sets anchor.download = report.name || report.report_type || "report" without using ReportReadList.extension, so downloads may be saved without a proper suffix (e.g., “.pdf”). ReportReadList includes extension, and the preview download path already builds filenames as ${file_state.name}.${file_state.extension}, so update handleDownload to append .${report.extension} (only if report.name doesn’t already include it).

🤖 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 `@src/pages/Encounters/ReportViewer.tsx` at line 348, In ReportViewer's
handleDownload, ensure the downloaded filename includes the report file
extension from ReportReadList.extension: when building anchor.download replace
the current fallback (report.name || report.report_type || "report") with logic
that uses report.name if present but appends `.` + report.extension when the
name does not already end with that extension; otherwise use
`${report.report_type}.${report.extension}` or `"report.${report.extension}"` as
fallbacks, taking care not to duplicate the dot and to handle missing extension
gracefully.
🤖 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.

Outside diff comments:
In `@src/pages/Encounters/ReportViewer.tsx`:
- Line 348: In ReportViewer's handleDownload, ensure the downloaded filename
includes the report file extension from ReportReadList.extension: when building
anchor.download replace the current fallback (report.name || report.report_type
|| "report") with logic that uses report.name if present but appends `.` +
report.extension when the name does not already end with that extension;
otherwise use `${report.report_type}.${report.extension}` or
`"report.${report.extension}"` as fallbacks, taking care not to duplicate the
dot and to handle missing extension gracefully.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0edc8844-6890-4457-bee0-9251bdcf67f5

📥 Commits

Reviewing files that changed from the base of the PR and between 73c196c and bd7eea4.

📒 Files selected for processing (2)
  • src/pages/Encounters/ReportViewer.tsx
  • src/pages/Facility/billing/account/AccountShow.tsx

@nihal467

nihal467 commented Jun 3, 2026

Copy link
Copy Markdown
Member

once its done, mark it for testing @abhimanyurajeesh

…rtSubTab; update ConsultationRoutes for new report paths
Copilot AI review requested due to automatic review settings June 3, 2026 14:51
@abhimanyurajeesh

Copy link
Copy Markdown
Contributor Author

@nihal467 Need to test all the report view and generate flow

  • Account
  • Patient
  • Encounter

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@abhimanyurajeesh abhimanyurajeesh changed the title ENG-485 feat: refactor ReportViewer for Account report [ENG-485] feat: refactor ReportViewer for Account report Jun 4, 2026
Copilot AI review requested due to automatic review settings June 5, 2026 05:15

This comment was marked as resolved.

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@abhimanyurajeesh

abhimanyurajeesh commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

closing in fav of #16440

@abhimanyurajeesh abhimanyurajeesh changed the title [ENG-485] feat: refactor ReportViewer for Account report feat: refactor ReportViewer for Account report Jun 5, 2026
@abhimanyurajeesh abhimanyurajeesh deleted the ENG-485 branch June 5, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants