Skip to content

[ENG-485] feat: refactor ReportViewer and associated routes to use associatingId and reportType for improved report handling#16440

Open
abhimanyurajeesh wants to merge 8 commits into
developfrom
ENG-485
Open

[ENG-485] feat: refactor ReportViewer and associated routes to use associatingId and reportType for improved report handling#16440
abhimanyurajeesh wants to merge 8 commits into
developfrom
ENG-485

Conversation

@abhimanyurajeesh

@abhimanyurajeesh abhimanyurajeesh commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

Fixes ENG-485

This is a follow up PR #16418 (review)

All report view is moved to this
image

Replaced the generate sheet with new dropdown
image

A new dropdown has been added for generating reports in account
image

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

  • Account
  • Patient
  • Encounter

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

Summary by CodeRabbit

  • New Features

    • Added report viewing and generation routes for patient, encounter, and billing account contexts, with selectable report types.
    • Introduced template-driven “generate report” flows, including a billing account “Reports” dropdown with permission-gated template loading.
  • Bug Fixes / Improvements

    • Updated PDF actions in the file preview dialog to use “open in browser” instead of the prior print flow.
  • Refactor

    • Updated report preview/navigation to build links from report type and associating context, and switched header generation to a dropdown.
    • Enhanced multi-filter navigation with optional right-arrow hiding.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 400f05bb-3fec-4292-845c-11df29338e1b

📥 Commits

Reviewing files that changed from the base of the PR and between 7387bf9 and 35b2dc2.

📒 Files selected for processing (3)
  • src/components/Files/FilesTab.tsx
  • src/components/Files/ReportSubTab.tsx
  • src/pages/Facility/billing/account/AccountShow.tsx
💤 Files with no reviewable changes (2)
  • src/pages/Facility/billing/account/AccountShow.tsx
  • src/components/Files/FilesTab.tsx

Walkthrough

ReportViewer is refactored to generalize from encounter-specific to context-generic by accepting associatingId and optional reportType. Routes across consultation, patient, and facility billing account contexts now wire the updated component. Report generation replaces TemplateReportSheet with GenerateReportDropdown. AccountShow adds lazy-loaded template dropdown integration.

Changes

Report Viewer Generalization and Context-Aware Routes

Layer / File(s) Summary
ReportViewer core refactoring
src/pages/Encounters/ReportViewer.tsx
ReportViewer component signature and logic updated to accept associatingId and optional reportType (defaulting to DISCHARGE_SUMMARY) instead of encounterId. Query keys, request parameters, polling refresh, and report generation all use the new associatingId and dynamic reportType. Initial report loading state tracking added.
Route registration across contexts
src/Routers/routes/ConsultationRoutes.tsx, src/Routers/routes/PatientRoutes.tsx, src/Routers/routes/FacilityRoutes.tsx
ConsultationRoutes switched from encounterId to associatingId. PatientRoutes and FacilityRoutes routes added with context-specific reportType (PATIENT_SUMMARY and ACCOUNT_REPORT). All routes render ReportViewer with associatingId and templateSlug or reportId.
ReportSubTab and GenerateReportDropdown refactoring
src/components/Files/ReportSubTab.tsx, src/components/Files/FilesTab.tsx
ReportSubTab removes encounterId prop and updates report view navigation via getReportBasePath helper to route to context-specific preview URLs. TemplateReportSheet replaced with GenerateReportDropdown, which permission-gates template listing, lazy-fetches active templates, constructs per-template navigation URLs, and renders single button or dropdown menu. FilesTab prop reference updated.
AccountShow template dropdown and context passing
src/pages/Facility/billing/account/AccountShow.tsx
AccountShow introduces controlled dropdown state and lazy-loads account report templates via templateApi when dropdown opens. Permission-gates template access and renders template list with file icons and navigable links. Passes facilityId into ReportSubTab to enable billing account report context.
Supporting UI component updates
src/components/ui/multi-filter/utils/navigation-helper.tsx, src/components/Common/FilePreviewDialog.tsx
NavigationHelper accepts optional hideRightArrow prop to conditionally suppress right-arrow icon rendering. FilePreviewDialog removes PDF print button and related imports, replacing with conditional "open in browser" button for PDF files.

Suggested labels

Type Changes, needs testing, needs review

Suggested reviewers

  • gigincg
  • rithviknishad
  • Jacobjeevan
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main refactoring work: moving from encounterId-based to associatingId and reportType-based report handling across routes and components.
Description check ✅ Passed The description addresses the core issue (ENG-485), references the related PR, includes visual evidence via screenshots, identifies the three areas requiring testing, and is tagged for peer review. However, the merge checklist items remain mostly unchecked, indicating work still in progress.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR generalises ReportViewer from an encounter-only component to a multi-context one by replacing the encounterId prop with associatingId and an optional reportType (defaulting to DISCHARGE_SUMMARY). It adds new routes for patient-level and billing-account report viewing/generation, replaces the TemplateReportSheet slide-over with a lightweight GenerateReportDropdown, and adds an account-scoped Reports section to AccountShow's action dropdown.

  • Route additions: new /patient/:id/report/* and /billing/account/:id/report/* routes are wired correctly with matching associatingId and reportType, consistent with the URL patterns constructed by getReportBasePath.
  • ReportViewer loading fix: isLoadingInitialReport is now included in the early loading guard, preventing a "template not found" flash when navigating to a report by ID before the initial fetch resolves.
  • GenerateReportDropdown: fetches templates lazily (only when reportType and permissions allow), renders a spinner button for a single template and a full dropdown for multiple templates, and silently hides when zero templates are available.

Confidence Score: 5/5

Safe to merge — the generalisation is mechanically consistent across all three report contexts, URL construction matches the new routes, and the loading-state guard fix is correct.

The rename from encounterId to associatingId is applied uniformly in routes, components, query keys, and API call bodies. The three report-type paths (encounter, patient, account) each have matching route definitions and correct URL construction in getReportBasePath. The only open items are a dev-time diagnostic gap when basePath resolution silently discards templates and a pre-existing blob-URL cleanup pattern now duplicated in ReportViewer — neither affects correctness in production.

ReportSubTab.tsx — the GenerateReportDropdown silently shows nothing if getReportBasePath returns null for every template (e.g., missing patientId at a PATIENT_SUMMARY call site), which could be confusing during integration of future report types.

Important Files Changed

Filename Overview
src/pages/Encounters/ReportViewer.tsx Generalizes encounterId to associatingId and adds optional reportType (defaulting to DISCHARGE_SUMMARY); adds isLoadingInitialReport to the loading guard to prevent premature "template not found" flash.
src/components/Files/ReportSubTab.tsx Replaces TemplateReportSheet with a new GenerateReportDropdown; adds getReportBasePath helper to build context-aware navigation URLs across three report types; removes refetch callback as onSuccess is no longer needed.
src/pages/Facility/billing/account/AccountShow.tsx Adds lazy-loaded template dropdown inside the account actions menu; templates are only fetched when the dropdown is opened and the user has list-template permission.
src/Routers/routes/PatientRoutes.tsx Adds two new patient-level report routes (by reportId and by templateSlug) wiring ReportViewer with associatingId=patientId and reportType=PATIENT_SUMMARY.
src/Routers/routes/FacilityRoutes.tsx Adds two new billing-account report routes (by reportId and by templateSlug) wiring ReportViewer with associatingId=accountId and reportType=ACCOUNT_REPORT.
src/Routers/routes/ConsultationRoutes.tsx Renames encounterId prop to associatingId in existing ReportViewer invocations; no functional change since reportType defaults to DISCHARGE_SUMMARY.
src/components/Common/FilePreviewDialog.tsx Removes the print-via-hidden-iframe button for PDFs; the open-in-browser button remains as the primary action for PDFs.
src/components/Files/FilesTab.tsx Drops the now-removed encounterId prop from ReportSubTab; no other logic changes.
src/pages/Encounters/TemplateBuilder/TemplateReportSheet.tsx File deleted; functionality replaced by the new GenerateReportDropdown in ReportSubTab.tsx. No remaining imports found.
src/components/ui/multi-filter/utils/navigation-helper.tsx Adds a hideRightArrow prop to suppress the right-arrow navigation hint when the component is reused outside the multi-filter panel.

Reviews (3): Last reviewed commit: "refactor: remove unused encounterId and ..." | Re-trigger Greptile

Comment thread src/components/Files/ReportSubTab.tsx Outdated
Comment thread src/components/Files/ReportSubTab.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 report viewing/generation flows to key off a generic associatingId plus explicit ReportType, enabling consistent routing and filtering for encounter, patient, and billing-account reports.

Changes:

  • Updated ReportViewer API to use associatingId and reportType, and updated encounter/patient/account report routes accordingly.
  • Replaced the template sheet-based “generate report” UI with a template-driven dropdown in report listings and the account action menu.
  • Removed the PDF print action from the generic file preview dialog.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Routers/routes/PatientRoutes.tsx Adds patient report routes that render ReportViewer with associatingId and ReportType.PATIENT_SUMMARY.
src/Routers/routes/FacilityRoutes.tsx Adds billing account report routes that render ReportViewer with ReportType.ACCOUNT_REPORT.
src/Routers/routes/ConsultationRoutes.tsx Updates encounter report routes to pass associatingId into ReportViewer.
src/pages/Facility/billing/account/AccountShow.tsx Adds template-driven report links to the account actions dropdown; wires ReportSubTab with billing context.
src/pages/Encounters/TemplateBuilder/TemplateReportSheet.tsx Removes the old template sheet UI for report generation.
src/pages/Encounters/ReportViewer.tsx Switches to associatingId/reportType for listing/creating reports and refines loading behavior.
src/components/ui/multi-filter/utils/navigation-helper.tsx Adds hideRightArrow option for the navigation helper UI.
src/components/Files/ReportSubTab.tsx Adds route-aware navigation for report preview and a template dropdown for “Generate report”.
src/components/Common/FilePreviewDialog.tsx Removes the PDF print button from the generic file preview header actions.
Comments suppressed due to low confidence (1)

src/components/Common/FilePreviewDialog.tsx:252

  • This removes the PDF print action from the generic file preview dialog (added previously for PDF previews). That’s a functional regression for users previewing PDFs outside of the dedicated ReportViewer, and it’s not mentioned in this PR’s scope/description.
                {file_state.extension === "pdf" && fileUrl && (
                  <Button
                    variant="outline"
                    onClick={() => {
                      window.open(fileUrl, "_blank", "noopener,noreferrer");

Comment thread src/pages/Facility/billing/account/AccountShow.tsx
Comment thread src/components/Files/ReportSubTab.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: 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: Gate the templates query and the "Reports" dropdown UI
behind a template-read permission check: add a permission boolean (e.g.,
canReadTemplates via your existing permission hook) and change the useQuery
enabled flag to enabled: dropdownOpen && canReadTemplates so
query(templateApi.listTemplates, ...) only runs when allowed, and hide or
disable the "Reports" dropdown section (the UI that uses templatesData and
isLoadingTemplates) when canReadTemplates is false; apply the same pattern for
the other occurrence around ReportType.ACCOUNT_REPORT and the block at lines
~489-506.
🪄 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: d7a80a59-5216-4b5e-812b-5cb4e7414066

📥 Commits

Reviewing files that changed from the base of the PR and between d2607a4 and b53e6bf.

📒 Files selected for processing (9)
  • src/Routers/routes/ConsultationRoutes.tsx
  • src/Routers/routes/FacilityRoutes.tsx
  • src/Routers/routes/PatientRoutes.tsx
  • src/components/Common/FilePreviewDialog.tsx
  • src/components/Files/ReportSubTab.tsx
  • src/components/ui/multi-filter/utils/navigation-helper.tsx
  • src/pages/Encounters/ReportViewer.tsx
  • src/pages/Encounters/TemplateBuilder/TemplateReportSheet.tsx
  • src/pages/Facility/billing/account/AccountShow.tsx
💤 Files with no reviewable changes (2)
  • src/pages/Encounters/TemplateBuilder/TemplateReportSheet.tsx
  • src/components/Common/FilePreviewDialog.tsx

Comment thread src/pages/Facility/billing/account/AccountShow.tsx
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ✅ Passed
Test Shards: 3

Metric Count
Total Tests 321
✅ Passed 321
❌ Failed 0
⏭️ Skipped 0

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

Run: #9621

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: 35b2dc2
Status: ✅  Deploy successful!
Preview URL: https://49489c55.care-preview-a7w.pages.dev
Branch Preview URL: https://eng-485.care-preview-a7w.pages.dev

View logs

Comment thread src/components/Files/ReportSubTab.tsx Outdated
`/facility/${facilityId}/billing/account/${billingAccountId}/report/${report.id}`,
);
} else if (canNavigateToPatientPreview) {
const effectiveFacilityId = facilityId ?? facility?.id;

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.

we can move defining effectiveFacilityId to 116 and use it in other blocks as well; allows to remove the else block in 130.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

replacing with switch

Comment thread src/components/Files/ReportSubTab.tsx Outdated
facilityId?: string;
patientId?: string;
encounterId?: string;
billingAccountId?: string;

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.

Associating Id is encounterId, patientId or accountId based on report type, so we can derive the url based on that.

Remove patientId, encounterId and billingAccountId props.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cant remove patient id, can remove the encounter id and billingAccountID

</DropdownMenuItem>
{canListTemplates && isLoadingTemplates && (
<DropdownMenuItem disabled>
<Loader className="size-3 animate-spin" />

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.

this loading state is a bit weird since we are displaying it after the other dropdown items @nihal467

Ideally we should be moving this up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it looks okay to me, we shouldn't block the other for this to load

Copilot AI review requested due to automatic review settings June 19, 2026 06:47
@netlify

netlify Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 35b2dc2
🔍 Latest deploy log https://app.netlify.com/projects/care-ohc/deploys/6a34ec5618d79c000891b50f
😎 Deploy Preview https://deploy-preview-16440.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/pages/Facility/billing/account/AccountShow.tsx

@yash-learner yash-learner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is outdated with new approach, I think we can cleanup

associating_id: "{encounter_id}",

Comment thread src/components/Files/ReportSubTab.tsx
Comment thread src/components/Files/ReportSubTab.tsx
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.

5 participants